1

I'm trying to build this small OpenCL project:

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

on Windows, within Cygwin. It is a toy project with one .cpp file and one kernel to demonstrate the use of OpenCL. So, I download the package and cmake it. I get the error message:

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)

I do not balk at this, and proceed to change my CMakeCache.txt so that instead of:

OPENCL_LIBRARY:FILEPATH=OPENCL_LIBRARY-NOTFOUND

I make it:

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

(this is the legit path of NVIDIA's OpenCL DLL) Ok, so now CMake configuration concludes successfully. The main.cpp file compiles, but linking fails!:

/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,0,--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'

and so on, dozens of such errors.

Why am I getting these errors and how can I fix them? Is it a result of ELF/WinPE incompatibility because I'm using Cygwin?

Additional info:

  • My machine has both integrated Intel Graphics (630 - coffee lake), and a Quadro P1000.
  • I 've installed CUDA 10.2 and AMD CodeXL installed (never mind why) to their default locations.
  • Looking for An OpenCL DLL file, I find:
    $ 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
    
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • building with Cygwin you should use the opencl coming with it. Have you installed the `libOpenCL-devel` package ? For info on the package see https://cygwin.com/packages/summary/libOpenCL-devel.html – matzeri Dec 26 '19 at 18:34
  • @matzeri: Cygwin doesn't bundle an NVIDIA-compatible OpenCL driver - that I know of. – einpoklum Dec 26 '19 at 20:07
  • Than do no use Cygwin compiler and tool. Or you use NVidia library or you build on Cygwin. Both can not work. – matzeri Dec 26 '19 at 20:23
  • @matzeri: Can you make this into an answer? – einpoklum Dec 26 '19 at 21:29
  • I will do. However if you need to compile using the NVidia library, one solution is to use Mingw https://stackoverflow.com/questions/15185955/compile-opencl-on-mingw-nvidia-sdk – matzeri Dec 28 '19 at 11:14

1 Answers1

0

Usually Cygwin programs are Unix like and do not call directly Windows DLLs, that use a different paragdim. For example the Cygwin cygwin1.dll provides its own C library different from the MS C library, this cause the sharing the data problematic specially in the 64bit version where the size of long is different. See https://cygwin.com/cygwin-ug-net/programming.html#gcc-64

Your Tutorial example can be built in a Cygwin pure enviroment, with the proper OpenCL library

 $ 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, size_t, 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

The built program seems to run fine

$ ./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
matzeri
  • 8,062
  • 2
  • 15
  • 16
  • That OpenCL library doesn't support NVIDIA GPUs, AFAICT. Clarified this in the question. – einpoklum Dec 28 '19 at 12:39
  • Of course not, as I wrote it is a pure Cygwin enviroment. To link to the Nvidia you need to use a different enviroment like mingw as shown for example at https://stackoverflow.com/questions/15185955/compile-opencl-on-mingw-nvidia-sdk – matzeri Dec 28 '19 at 13:44