Use Predefined Macros for Specific Code for Intel® DPC++/C++ Compiler

ID 标签 660425
已更新 8/7/2023
版本 Latest
公共

author-image

作者

If you have installed Intel® oneAPI Base Toolkit, you now have DPC++/C++ compiler. 

Intel® C++ Compiler Classic has been deprecated and will be removed starting from version 2024.0.0. Users should use Intel® DPC++/C++ Compiler which is included in both Intel® oneAPI Base Toolkit and Intel® oneAPI HPC Toolkit. 

Different C++ Compilers and Drivers 

The following table provides the different compiler front-end information and drivers. 

Compiler Notes Linux* Driver Windows* Driver
Intel® DPC++/C++ Compiler (BaseKit)  A C++ compiler with a Clang front-end to compile SYCL source codes and offload kernels to various devices icpx -fsycl icx.exe
A C++ compiler with a Clang front-end, supporting OpenMP* offload icx icx.exe

 

 

 

Predefined Macros of Each Compiler

There are times that you may find the need to have specific code for the specific compiler above, it can be archieved by using the predefined macros provided by Intel Compilers. The differentiative predefined macros are included in the table below:  

Compiler  Predefined Macros to Differentiate from Other Compiler Notes
Intel® DPC++ Compiler SYCL_LANGUAGE_VERSION;  __INTEL_LLVM_COMPILER;  __VERSION  

SYCL_LANGUAGE_VERSION is defined in SYCL spec and should be defined by all SYCL compilers. 

__INTEL_LLVM_COMPILER can be used to differentiate Intel DPC++ compiler from others. 

Intel® C++ Compiler __INTEL_LLVM_COMPILER;  __VERSION  

 

 

 

 

Predefined Macros for Intel® DPC++ Compiler

To define code block specific to Intel® DPC++ compiler, see the example below by using "#if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)": 

// dpcpp only
#if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)
   // code specific for DPC++ compiler below
   // ... ...

   // example only
   std::cout << "SYCL_LANGUAGE_VERSION: " << SYCL_LANGUAGE_VERSION << std::endl;
   std::cout << "__INTEL_LLVM_COMPILER: " << __INTEL_LLVM_COMPILER << std::endl;
   std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif

Output of oneAPI Toolkits 2023.2.0:  

Windows Linux
SYCL_LANGUAGE_VERSION: 202001
__INTEL_LLVM_COMPILER: 20230200
__VERSION__: Intel(R) oneAPI DPC++/C++ Compiler 2023.2.0 (2023.2.0.20230627)
SYCL_LANGUAGE_VERSION: 202001
__INTEL_LLVM_COMPILER: 20230200
__VERSION__: Intel(R) oneAPI DPC++/C++ Compiler 2023.2.0 (2023.2.0.20230622)

 

Predefined Macros for Intel® C++ Compiler

To define code block specific to Intel® C++ Compiler, see the example below by using "#if !defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)": 

// icx only
#if !defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)
   // code specific for Intel C++ Compiler below
   // ... ...

   // example only
   std::cout << "__INTEL_LLVM_COMPILER: " << __INTEL_LLVM_COMPILER << std::endl;
   std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif

Output of oneAPI Toolkits 2023.2.0:  

Windows Linux

__INTEL_LLVM_COMPILER: 20230200

__VERSION__: Intel(R) oneAPI DPC++/C++ Compiler 2023.2.0 (2023.2.0.20230627)

__INTEL_LLVM_COMPILER: 20230200

__VERSION__: Intel(R) oneAPI DPC++/C++ Compiler 2023.2.0 (2023.2.0.20230622)