0

Following this issue, I'm trying to compile the clifo tool using the MSVC toolchain. I use this CMakeLists.txt file which successfully finds NVIDIA's OpenCL SDK:

Found OpenCL: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v3.2/lib/Win32/OpenCL.lib (found version "1.1")

However when compiling with cmake --build . I get many errors, from which the first one is:

c:\path\to\clinfo\src\info_ret.h(43): error C2061: syntax error: identifier 'cl_device_affinity_domain' [C:\path\to\clinfo\build\clinfo.vcxproj]

I tried defining the cl_device_affinity_domain enumerate type explicitly in the ext.h header file:

#ifndef CL_VERSION_1_1

#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0)
#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1)
#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2)
#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3)
#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4)
#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5)

typedef enum
{
    CL_DEVICE_AFFINITY_DOMAIN_NUMA,
    CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE,
    CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE,
    CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE,
    CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE,
    CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE
} cl_device_affinity_domain;

#endif

with no avail and sadly the clinfo developer is also hesitant to help! I wonder if this error has anything to do with the CMake file I have used? otherwise I would appreciate it if you could help me understand what is the problem and how I can resolve it.

P.S.1. Maybe I should use nvcc instead? I have the below version available:

...> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Thu_Nov__4_13:45:48_PDT_2010
Cuda compilation tools, release 3.2, V0.2.1221

P.S.2. OK, it turns out that I had a very outdated NVIDIA CUDA toolkit installed!

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
  • The behavior of enum is to replace names with integer values 0, 1, 2, but your values are, by virtue of #define preprocessing, not valid names. – David G. Pickett Jun 07 '20 at 21:37
  • I'm not into MSVC, but I have been able to compile clinfo on Windows with MinGW-w64 against Khronos' OpenCL ICD Loader (https://github.com/KhronosGroup/OpenCL-ICD-Loader). – Brecht Sanders Jun 07 '20 at 22:01
  • @DavidG.Pickett I'm not sure if that's the issue. if there was a syntax error I should have received one from the compiler. I suspect that the compiler doesn't even read inside the `CL_VERSION_1_1` if statement. – Foad S. Farimani Jun 08 '20 at 08:18
  • @BrechtSanders I'm sure there is a way to compile it with MinGW GNU compilers. But that's kind of the whole point. I want to know if I can just compile with MSVC plus CMake. – Foad S. Farimani Jun 08 '20 at 08:19
  • 1
    @Foad What I really wanted to point out that it may be worth building against Khronos' OpenCL ICD Loader. If you build clinfo against NVIDIA's OpenCL, will it even work for non-NVIDIA hardware? – Brecht Sanders Jun 08 '20 at 08:25
  • @BrechtSanders that's is also what Peter Žužek said [here](https://github.com/Oblomov/clinfo/issues/49#issuecomment-640447463). Could you be kind to elaborate and maybe mention a step by step instruction? – Foad S. Farimani Jun 08 '20 at 08:53
  • 2
    @Foad First get the OpenCL C headers from https://github.com/KhronosGroup/OpenCL-Headers/. Then get the Khronos OpenCL Installable Client Driver (ICD) Loader from https://github.com/KhronosGroup/OpenCL-ICD-Loader/ and build with CMake and make sure to include these options: `-DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL= -DOPENCL_ICD_LOADER_HEADERS_DIR:PATH=/include -DOPENCL_ICD_LOADER_REQUIRE_WDK:BOOL=OFF -DBUILD_TESTING:BOOL=OFF`. Again, I used MSYS/MinGW-w64 (works for both static and shared). No idea if it works in MSVC. – Brecht Sanders Jun 08 '20 at 10:01
  • @BrechtSanders It is very cumbersome and error-prone to add all these options in the command line. Is it possible to change [the above mentioned `CMakeLists.txt` file](https://github.com/ProGTX/clinfo/blob/master/CMakeLists.txt) in a way that it automatically looks for these headers and libraries? Also if it is possible to install the Khronos dependencies using Conan, `vcpkg` or any other package manager? – Foad S. Farimani Jun 08 '20 at 10:16
  • 1
    @Foad Sorry I don't have an MSVC background. I stick to MSYS2 and MinGW-w64. In my opinion using command line options isn't error-prone at all (as long as you don't type it all by hand). In fact it's the most reproducible way to get the same result every time. I am working on a different packaging system for my http://winlibs.com/ project, which will also have Khronos OpenCL packages once its ready. – Brecht Sanders Jun 08 '20 at 11:20
  • @BrechtSanders check [this](https://stackoverflow.com/q/62261869/4999991) out. – Foad S. Farimani Jun 08 '20 at 16:11

0 Answers0