簡體   English   中英

如何針對自定義 CUDA 安裝使用 OpenCL 構建 GDAL?

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

我正在嘗試針對 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 生成文件即可使用 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>

此外,您無需將有關 CUDA 的任何信息告知configure腳本 - OpenCL 加載程序庫應在運行時使用其內部機制找到所有必需的 CUDA 庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM