使用NVIDIA GPU无法对Cygwin中的OpenCL库进行链接

我正在尝试构建这个小的OpenCL项目:

https://bitbucket.org/Anteru/opencltutorial/src

在Windows上,在Cygwin中为

。这是一个玩具项目,具有一个.cpp文件和一个内核,以演示OpenCL的用法。因此,我下载了软件包并cmake。我收到错误消息:

CMake Error at /usr/share/cmake-3.14.5/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find OpenCL (missing: OPENCL_libraRY)
Call Stack (most recent call first):
  /usr/share/cmake-3.14.5/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindOpenCL.cmake:35 (find_package_handle_standard_args)
  CMakeLists.txt:6 (FIND_PACKAGE)

我不会对此感到厌恶,而是继续更改我的CMakeCache.txt,以便代替:

OPENCL_libraRY:FILEPATH=OPENCL_libraRY-NOTFOUND

我做到了:

OPENCL_libraRY:FILEPATH=/cygdrive/c/Program Files/NVIDIA Corporation/OpenCL/OpenCL.dll

(这是NVIDIA OpenCL DLL的合法路径)好,所以现在CMake配置成功结束。 main.cpp文件已编译,但是链接失败!:

/usr/bin/c++.exe   -Wl,--enable-auto-import CMakeFiles/clTut.dir/main.cpp.o  -o clTut.exe -Wl,--out-implib,libclTut.dll.a -Wl,--major-image-version,--minor-image-version,0 "/cygdrive/c/Program Files/NVIDIA Corporation/OpenCL/OpenCL.dll"
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x610): undefined reference to `clGetPlatformInfo'
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x610): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `clGetPlatformInfo'
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x659): undefined reference to `clGetPlatformInfo'
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x659): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `clGetPlatformInfo'

等等,许多这样的错误。

为什么会出现这些错误,如何解决?是因为我使用Cygwin是ELF / WinPE不兼容的结果吗?

其他信息:

  • 我的机器同时集成了Intel Graphics(630-咖啡湖)和Quadro P1000。
  • 我已将CUDA 10.2和AMD CodeXL安装(默认情况下)到其默认位置。
  • 寻找一个OpenCL DLL文件,我发现:
    $ locate OpenCL.dll
    /cygdrive/c/Program Files (x86)/CodeXL/spies/OpenCL.dll
    /cygdrive/c/Program Files (x86)/CodeXL/spies64/OpenCL.dll
    /cygdrive/c/Program Files/NVIDIA Corporation/OpenCL/OpenCL.dll
    /cygdrive/c/Windows/LastGood/system32/OpenCL.dll
    /cygdrive/c/Windows/LastGood/SysWow64/OpenCL.dll
    /cygdrive/c/Windows/System32/OpenCL.dll
    /cygdrive/c/Windows/SysWOW64/OpenCL.dll
    
a6733525 回答:使用NVIDIA GPU无法对Cygwin中的OpenCL库进行链接

通常,Cygwin程序类似于Unix,并且不直接调用Windows DLL,它们使用 一个不同的天堂 例如,Cygwin cygwin1.dll提供了自己的C库,与 MS C库,这导致长大小不同的64位版本中特别引起共享数据问题。看到 https://cygwin.com/cygwin-ug-net/programming.html#gcc-64

您的教程示例可以使用适当的OpenCL库在Cygwin纯环境中构建

 $ cygcheck -cd | grep -i opencl
libOpenCL-devel                         2.2.12-1
libOpenCL1                              2.2.12-1

$ unzip Anteru-opencltutorial-cb1df4439f83.zip
Archive:  Anteru-opencltutorial-cb1df4439f83.zip
  inflating: Anteru-opencltutorial-cb1df4439f83/.hg_archival.txt
 ...
  inflating: Anteru-opencltutorial-cb1df4439f83/main.cpp
  inflating: Anteru-opencltutorial-cb1df4439f83/test.ppm

$ cd Anteru-opencltutorial-cb1df4439f83
/pub/tmp/Anteru-opencltutorial-cb1df4439f83

$ cmake .
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
...
-- Found OpenCL: /usr/lib/libOpenCL.dll.a
-- Configuring done
-- Generating done
-- Build files have been written to: /pub/tmp/Anteru-opencltutorial-cb1df4439f83

$ make
Scanning dependencies of target clTut
[ 50%] Building CXX object CMakeFiles/clTut.dir/main.cpp.o
/pub/tmp/Anteru-opencltutorial-cb1df4439f83/main.cpp: In function ‘int main()’:
/pub/tmp/Anteru-opencltutorial-cb1df4439f83/main.cpp:249:9: warning: ‘_cl_mem* clCreateImage2D(cl_context,cl_mem_flags,const cl_image_format*,size_t,void*,cl_int*)’ is deprecated [-Wdeprecated-declarations]
   &error);
         ^
In file included from /pub/tmp/Anteru-opencltutorial-cb1df4439f83/main.cpp:10:0:
                                           ~~~~~~~^~~~~~
...
[100%] Linking CXX executable clTut.exe
[100%] Built target clTut

内置程序运行正常

$ ./clTut.exe
Found 1 platform(s)
         (1) : Portable Computing Language
Found 1 device(s)
         (1) : pthread-Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Context created
本文链接:https://www.f2er.com/2953699.html

大家都在问