gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:22:54 24 4
gpt4 key购买 nike

我正在尝试针对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已正确配置为了解这些信息,因为o​​jit_code可以找到OpenCL。
因此,我认为它失败了,因为下面的命令没有添加 ./configure --with-opencl --with-opencl-include=/usr/local/cuda/include/ --with-opencl-lib=cuda,而 -lOpenCL显然想要它。
/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是必不可少的。仅当您的OpenCL安装不是标准选项时,选项--with-opencl-include=ARG--with-opencl-lib=ARG才有用-我根本没有使用它们,并且使所有链接正确连接。
CUDA具有自己的OpenCL header 和加载程序库版本,因此即使您的包装箱上没有标准的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库。

关于c++ - 如何针对自定义CUDA安装使用OpenCL构建GDAL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64558912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com