如何针对自定义CUDA安装使用OpenCL构建GDAL?

问题描述

我正在尝试针对OpenCL构建GDAL,以获得GPU加速的光栅操作,具体取决于Cuda。我设法使./configure完成并开始使用make进行编译。但是,编译gdalinfo时,编译失败,因为找不到OpenCL符号。

我很确定这是因为某个地方缺少-lOpenCL标志,但是(1)我不知道在哪里; (2)我不知道该更改什么。所以我的问题是如何正确配置构建命令以使用OpenCL?

构建失败错误

echo '#!/bin/sh' > gdal-config
echo 'CONfig_LIBS="libgdal.la"' >> gdal-config
echo 'CONfig_DEP_LIBS=" -lcrypto -lpoppler -ljson-c -lfreexl -lqhull -lqhull -L/usr/lib/x86_64-linux-gnu -lgeos_c -lwebp -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator -lexpat -lxerces-c -lpthread -lopenjp2 -ljasper -L/usr/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lnetcdf -lhdf5_hl -lhdf5 -lpthread -lsz -lz -ldl -lm -lcurl -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lhdf5 -lmfhdfalt -ldfalt -logdi -lgif -ljpeg -lgeotiff -ltiff -lpng -L/usr/lib/x86_64-linux-gnu -lpq -lzstd -llzma -lz -lpthread -lm -lrt -ldl  -lspatialite -lsqlite3 -lpcre   -L/usr/lib/x86_64-linux-gnu -lcurl        cuda    -lxml2     "' >> gdal-config
echo 'CONfig_PREFIX="gdal-2.4.2"' >> gdal-config
echo 'CONfig_CFLAGS="-Iport -Igcore -Ialg -Iogr -Iogr/ogrsf_frmts -Ifrmts/vrt -Iapps"' >> gdal-config
echo 'CONfig_DATA="data"' >> gdal-config
echo 'CONfig_VERSION="'`cat ../VERSION`'"' >> gdal-config
echo 'CONfig_OGR_ENABLED=yes' >> gdal-config  # Deprecated.  Always true.
echo 'CONfig_GNM_ENABLED=yes' >> gdal-config
echo 'CONfig_FORMATS=" gxf gtiff hfa aigrid aaigrid ceos ceos2 iso8211 xpm sdts raw dted mem jdem envisat elas fit vrt usgsdem l1b nitf bmp airsar rs2 ilwis rmf leveller sgi srtmhgt idrisi gsg ingr ers jaxapalsar dimap gff cosar pds adrg coasp tsx terragen blx msgn til r northwood saga xyz hf2 kmlsuperoverlay ctg e00grid zmap ngsgeoid iris map cals safe sentinel2 derived prf sigdem ignfheightasciigrid mrf webp wcs wms plmosaic wmts rda eeda grib bsb openjpeg jpeg2000 netcdf hdf5 hdf4 gif jpeg png pcraster  pcidsk rik ozi pdf rasterlite mbtiles postgisraster arg"' >> gdal-config
cat gdal-config.in >> gdal-config
chmod a+x gdal-config
/bin/bash libtool --mode=compile --silent --tag=CXX g++ -std=c++11 -Iport -Igcore -Ialg -Iogr -Iogr/ogrsf_frmts -Ignm -Iapps -DHAVE_AVX_AT_COMPILE_TIME -DHAVE_SSSE3_AT_COMPILE_TIME -DHAVE_SSE_AT_COMPILE_TIME -g -O2  -Wall -Wextra -Winit-self -Wunused-parameter -Wformat -Werror=format-security -Wno-format-nonliteral -Wlogical-op -Wshadow -Werror=vla -Wdate-time -Wfloat-conversion -Wmissing-declarations -Wnon-virtual-dtor -Woverloaded-virtual -fno-operator-names -Wzero-as-null-pointer-constant -Wsuggest-override  -Ifrmts/vrt -DGNM_ENABLED -Iport -I/usr/include/openjpeg-2.1 -I/usr/include  -DGDAL_COMPILATION -DHAVE_XERCES -I/usr/include -I/usr/include/xercesc -Iport -I/usr/include/openjpeg-2.1 -I/usr/include  -DGDAL_COMPILATION -I/usr/include/json-c -Iogr/ogrsf_frmts/geojson -Iogr/ogrsf_frmts/generic -Ignm -DHAVE_GEOS=1 -I/usr/include -c -o gdalinfo_bin.lo gdalinfo_bin.cpp
/bin/bash libtool --mode=link --silent g++ -std=c++11  gdalinfo_bin.lo  libgdal.la  -o gdalinfo
.libs/libgdal.so: undefined reference to `clCreateProgramWithSource'
.libs/libgdal.so: undefined reference to `clReleaseKernel'
.libs/libgdal.so: undefined reference to `clGetSupportedImageFormats'
.libs/libgdal.so: undefined reference to `clGetKernelWorkGroupInfo'
.libs/libgdal.so: undefined reference to `clCreateImage2D'
.libs/libgdal.so: undefined reference to `clEnqueueMapBuffer'
.libs/libgdal.so: undefined reference to `clEnqueueNDRangeKernel'
.libs/libgdal.so: undefined reference to `clGetPlatformIDs'
.libs/libgdal.so: undefined reference to `clGetDeviceInfo'
.libs/libgdal.so: undefined reference to `clCreateBuffer'
.libs/libgdal.so: undefined reference to `clReleaseCommandQueue'
.libs/libgdal.so: undefined reference to `clReleaseContext'
.libs/libgdal.so: undefined reference to `clReleaseEvent'
.libs/libgdal.so: undefined reference to `clGetdeviceids'
.libs/libgdal.so: undefined reference to `clReleaseMemObject'
.libs/libgdal.so: undefined reference to `clCreateCommandQueue'
.libs/libgdal.so: undefined reference to `clBuildProgram'
.libs/libgdal.so: undefined reference to `clFinish'
.libs/libgdal.so: undefined reference to `clGetProgramBuildInfo'
.libs/libgdal.so: undefined reference to `clEnqueueReadBuffer'
.libs/libgdal.so: undefined reference to `clReleaseProgram'
.libs/libgdal.so: undefined reference to `clCreateContext'
.libs/libgdal.so: undefined reference to `clSetKernelArg'
.libs/libgdal.so: undefined reference to `clCreateKernel'
collect2: error: ld returned 1 exit status
GNUmakefile:82: recipe for target 'gdalinfo' Failed
make[1]: *** [gdalinfo] Error 1
make[1]: Leaving directory 'apps'
GNUmakefile:112: recipe for target 'apps-target' Failed
make: *** [apps-target] Error 2

我知道这些符号已正确安装,因为例如,如果列出了它们,则会列出它们:

$ export LD_LIBRARY_PATH=/usr/local/cuda/lib64   # Inform GDAL of Cuda
$ export PATH=/usr/local/cuda/bin:$PATH          # Inform GDAL of Cuda
$ cat /usr/local/cuda/include/CL/*  | grep -i clCreateProgramWithSource
clCreateProgramWithSource(cl_context        /* context */,... )

我还认为GDAL已正确配置以了解这些信息,因为./configure --with-opencl --with-opencl-include=/usr/local/cuda/include/ --with-opencl-lib=cuda可以找到OpenCL。

因此,我认为它会失败,因为以下命令没有添加-lOpenCL,而显然gdalinfo确实希望添加它。

/bin/bash libtool --mode=link --silent g++ -std=c++11  gdalinfo_bin.lo  libgdal.la  -o gdalinfo

所以我的最后一个问题是:如何修改构建配置以在更多地方包含-lOpenCL?

解决方法

您不需要修改任何GDAL makefile即可使用OpenCL-GDAL构建脚本非常适合查找所需的一切。您需要的configure脚本唯一的选择是--with-opencl=yes-此yes是必不可少的。选项--with-opencl-include=ARG--with-opencl-lib=ARG仅在您的OpenCL安装不是标准选项时才有用-我根本没有使用它们,并且使所有链接正确连接。

CUDA拥有自己的OpenCL标头和加载程序库版本,因此即使您的包装盒上没有标准的OpenCL(由Linux软件更新程序提供,例如apt),您也可以使用它们。如果CUDA安装在某些非标准位置(例如,在您的主目录中),则必须告知GDAL configure脚本:

./configure \
  --with-opencl=yes \
  --with-opencl-include=${HOME}/apps/cuda/targets/x86_64-linux/include \
  --with-opencl-lib="-L${HOME}/apps/cuda/targets/x86_64-linux/lib -lOpenCL" \
  <other options if needed>

此外,您无需向configure脚本讲任何有关CUDA的信息-OpenCL加载程序库应在运行时使用其内部机制来查找所有必需的CUDA库。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...