简体   繁体   English

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

[英]How do I build GDAL with OpenCL against a custom CUDA installation?

I am trying to build GDAL against OpenCL to get GPU accelerated raster operations, depending on Cuda. I managed to get ./configure to complete and start compiling with make .我正在尝试针对 OpenCL 构建 GDAL 以获得 GPU 加速光栅操作,具体取决于 Cuda。我设法让./configure完成并开始使用make编译。 However, when compiling gdalinfo , the compilation fails because it can't find the OpenCL symbols.但是,在编译gdalinfo时,编译失败,因为找不到 OpenCL 符号。

I'm pretty sure it is because a -lOpenCL flag is missing somewhere, but (1) I don't know where;我很确定这是因为某处缺少-lOpenCL标志,但是(1)我不知道在哪里; and (2) I don't know what to change. (2) 我不知道要改变什么。 So my question is how to correctly configure the build commands to use OpenCL?所以我的问题是如何正确配置构建命令以使用 OpenCL?

The build failure error:构建失败错误:

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

I know these symbols are correctly installed, because they are listed if I do for example:我知道这些符号已正确安装,因为如果我这样做,它们会被列出,例如:

$ 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 */,
    ... )

I also think GDAL is correctly configured to know about these, because ./configure --with-opencl --with-opencl-include=/usr/local/cuda/include/ --with-opencl-lib=cuda can find OpenCL.我还认为 GDAL 已正确配置以了解这些,因为./configure --with-opencl --with-opencl-include=/usr/local/cuda/include/ --with-opencl-lib=cuda可以找到 OpenCL .

Therefore, I think it fails because the following command doesn't have -lOpenCL added to it, while apparently gdalinfo does want it.因此,我认为它失败是因为以下命令没有添加-lOpenCL ,而显然gdalinfo确实需要它。

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

So my final question is: How can I modify the build configuration to include -lOpenCL in more places?所以我的最后一个问题是:如何修改构建配置以在更多地方包含 -lOpenCL?

You don't need to modify any GDAL makefiles to use the OpenCL - the GDAL build script is pretty good in finding everything you need for that.您无需修改任何 GDAL 生成文件即可使用 OpenCL - GDAL 构建脚本非常适合查找所需的一切。 The only option for the configure script you need is --with-opencl=yes - this yes is essential.您需要的configure脚本的唯一选项是--with-opencl=yes yes这个是必不可少的。 The options --with-opencl-include=ARG and --with-opencl-lib=ARG are useful only when your OpenCL installation is not standard - I didn't use them at all and got everything linked correctly.选项--with-opencl-include=ARG--with-opencl-lib=ARG仅在您的 OpenCL 安装不是标准时才有用 - 我根本没有使用它们并正确链接了所有内容。

The CUDA has its own version of OpenCL headers and the loader library, so you can use them even when there are no standard OpenCL (provided by a Linux software updater, for example - the apt ) on your box. CUDA 有自己版本的 OpenCL 标头和加载程序库,因此即使您的盒子上没有标准 OpenCL(由 Linux 软件更新程序提供,例如 - apt ),您也可以使用它们。 In case of the CUDA was installed in some non-standard location (for example - in your home directory) you have to tell the GDAL configure script about that:如果 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>

Also, you don't need to tell anything to the configure script about your CUDA - the OpenCL loader library should find all the necessary CUDA libraries at run time using its internal mechanics.此外,您无需将有关 CUDA 的任何信息告知configure脚本 - OpenCL 加载程序库应在运行时使用其内部机制找到所有必需的 CUDA 库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM