To enable OpenCL syntax highlighting in Visual Studio 2019 IDE, install the Intel VisualStudioTools2019_vs16.vsix
addin:
(Size=82458 bytes, MD5=c55b3bfa14257cfe136e07c3ba83fe68)
…and to enable the syntax checking of OpenCL C files (*.cl) in Visual Studio’s IDE, install this or the intel_sdk_for_opencl_2020_x64_setup.msi
package:
(Size=41279488 bytes, MD5=92d65c87f7965e706950bba543b13e7d)
This installs the Intel OpenCL SDK headers, Code Builder and OpenCL compilers in %ProgramFiles(x86)%\Intel\OpenCL SDK\7.0\
IMPORTANT: You must set the environment variable INTELOCLSDKROOT
to this expanded path manually.
These Intel tools add a new project type to the Visual Studio’s menu File-->New-->Project
:
Creating a new GPU OpenCL project for Windows
adds the %INTELOCLSDKROOT%\IntelOpenCL.props
and %INTELOCLSDKROOT%\IntelOpenCL.targets
references to the main .vcxproj
file and this causes either the %INTELOCLSDKROOT%\bin\x64\ioc64.exe
or the %INTELOCLSDKROOT%\bin\x86\ioc32.exe
to be executed with an undocumented switch -VS
which checks the *.cl
files syntax and generates the following output in Visual Studio’s IDE when the project is built:
Build started...
1>------ Build started: Project: OpenCL_GPU, Configuration: Debug x64 ------
1>Preprocessingg: Template.cl
1>Using build options: -I "C:\src\OpenCL_GPU"
1>Platform name: AMD Accelerated Parallel Processing
1>Device name: Hawaii
1>Device version: OpenCL 2.0 AMD-APP (3188.4)
1>Device vendor: Advanced Micro Devices, Inc.
1>Device profile: FULL_PROFILE
1>
1>'AddVec' kernel info:
1> Maximum work-group size: 256
1> Compiler work-group size: (0, 0, 0)
1> Local memory size: 0
1> Preferred multiple of work-group size: 64
1> Minimum amount of private memory: 0
1>
1>Build succeeded!
1>
1>GPUOpenCLProjectforWindows.cpp
1>utils.cpp
1>Generating Code...
1>OpenCL_GPU.vcxproj -> C:\src\OpenCL_GPU\x64\Debug\OpenCL_GPU.exe
1>Template.cl
1> 1 file(s) copied.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
The %INTELOCLSDKROOT%\bin\x64\ioc64.exe
and %INTELOCLSDKROOT%\bin\x86\ioc32.exe
are the OpenCL C compilers which are capable of checking the syntax of the *.cl
files and generating LLVM, SPIR and SPIR-V files for Intel GPUs.
This also adds the following project properties to the Visual Studio’s IDE:
Notice the Device: Intel(R) Graphics (-device=GPU)
property.
This is bad news for non-Intel GPU owners because this locks these tools to Intel GPUs only and causes the error message error CL: Failed to get platform id...
for non-Intel GPUs. There are two workarounds this problem:
1) Set the project property Device: Intel(R) CPU (-device=CPU)
and install the Intel OpenCL CPU runtime
that installs a GPU emulator for Intel CPUs (warning: this runtime is bloated, over 250MB !!!).
2) Patch %INTELOCLSDKROOT%\bin\x64\ioc64.exe
and/or %INTELOCLSDKROOT%\bin\x86\ioc32.exe
to ignore this restriction and compile the *.cl
files by the installed GPU driver (e.g. the AMD’s OpenCL GPU driver). This is the only way for systems with non-Intel CPUs and non-Intel GPUs. Fortunately this patch is very easy.