admin管理员组

文章数量:1122846

How to enable syntax highlighting and syntax checking of kernels written in OpenCL C (in *.cl files) in Visual Studio 2019 IDE?

See the example below:

The *.cl files use the OpenCL C syntax that is similar to the C99 syntax, but which has some features that don't exist in C, for example built-in vector types like:

char2, char4, char8, char16
uchar2, uchar4, uchar8, uchar16
short2, short4, short8, short16
ushort2, ushort4, ushort8, ushort16
int2, int4, int8, int16
uint2, uint4, uint8, uint16
long2, long4, long8, long16
ulong2, ulong4, ulong8, ulong16
half2, half4, half8, half16
float2, float4, float8, float16
double2, double4, double8, double16

Furthermore, each of these vectors types can be subdivided using the type.sn syntax, for example: half8.s3 is legal ( but half8.s9 is illegal, because half8 is too small to contain s9 ).

Obviously Open CL Chas additional built-in keywords like: __kernel, __global, __local, __private ...and many more.

More differences are listed here.

How to enable syntax highlighting and syntax checking of kernels written in OpenCL C (in *.cl files) in Visual Studio 2019 IDE?

See the example below:

The *.cl files use the OpenCL C syntax that is similar to the C99 syntax, but which has some features that don't exist in C, for example built-in vector types like:

char2, char4, char8, char16
uchar2, uchar4, uchar8, uchar16
short2, short4, short8, short16
ushort2, ushort4, ushort8, ushort16
int2, int4, int8, int16
uint2, uint4, uint8, uint16
long2, long4, long8, long16
ulong2, ulong4, ulong8, ulong16
half2, half4, half8, half16
float2, float4, float8, float16
double2, double4, double8, double16

Furthermore, each of these vectors types can be subdivided using the type.sn syntax, for example: half8.s3 is legal ( but half8.s9 is illegal, because half8 is too small to contain s9 ).

Obviously Open CL Chas additional built-in keywords like: __kernel, __global, __local, __private ...and many more.

More differences are listed here.

Share Improve this question edited Nov 23, 2024 at 4:42 George Robinson asked Nov 22, 2024 at 3:39 George RobinsonGeorge Robinson 2,09514 silver badges32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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 manually set the environment variable INTELOCLSDKROOT to the expanded installation path above.

These Intel tools add new project types 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 syntax of *.cl files 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.

If any OpenCL C syntax errors are detected, they are signaled in the usual manner inside the Visual Studio's IDE. You can jump to the source code, that caused the error in the .cl file, interactively by double clicking the error in the error-list or in the output window.

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® CPU Runtime for OpenCL™ Applications that contains a GPU emulator for Intel CPUs ( warning: this runtime is bloated - over 80MB !!! ).

2) Patch the %INTELOCLSDKROOT%\bin\x64\ioc64.exe and/or the %INTELOCLSDKROOT%\bin\x86\ioc32.exe to circumvent this restriction and force these compilers to compile the *.cl files with 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.

本文标签: