Easy CUDA* to SYCL* Migration

How the Intel® DPC++ Compatibility Tool Makes Code Migration an Easy, One-Time Process

Get the Latest on All Things CODE



Code reuse is an increasingly important consideration—even requirement—when programming applications for heterogeneous computing. Using the same code base for CPU and GPU, for example, saves development time and resources and can easily increase time-to-market. In many cases, this means code migration from proprietary, vendor-locked solutions such as CUDA* to open, multi-vendor, standards-based solutions such as SYCL*.  

The Intel® DPC++ Compatibility Tool and its open-source counterpart SYCLomatic are purpose-built to do exactly that: migrate CUDA to SYCL quickly and easily.  

In this blog, we unpack how the tools work and the advantages you can reap when utilizing them. [Note that both tools work the same way. For simplicity, we mention only the DPC++ Compatibility Tool.]  

So, first things first …  

What is the Intel® DPC++ Compatibility Tool? 

It’s a one-time migration utility for migrating existing CUDA code to SYCL code, an industry-standard C++ code-compliant extension of the C++ standard for efficient multi-architecture, data-parallel programming.  

DPC++ is the oneAPI Implementation of SYCL. Check it out here

The compatibility tool automatically migrates the majority of the code sections, including CUDA language kernels and library API calls, thereby reducing migration time and effort. Its seamless integration with popular IDEs such as Microsoft Visual Studio* and Eclipse*, as well as cross-architecture support of the resultant code, add to its advantages.  

What Are the Advantages of SYCL? 

In a word (ok, 3 words), performance and code portability. 

SYCL is a scalable, cross-platform abstraction layer based on open standards for heterogenous device programming. Its combined benefit of performance and code portability allows the same code base to be used on diverse platform configurations.  

It accomplishes this by: 

  • Enabling code for heterogenous and offload processors to be written using modern ISO C++ standards (at least C++17), 
  • Providing APIs and abstractions to find devices (CPUs, GPUs, and FPGAs) on which the code can be executed, and 
  • Managing data resources and code execution across a variety of devices. 

All of this gives the developer greater choice in which platform configuration to use. Put another way, all of this frees developers from proprietary vendor lock-in.  

Now let’s jump into the brass-tacks of how it all works. 

How the Intel DPC++ Compatibility Tool Works 

The complete migration of CUDA code to SYCL is a sequential process:

Figure 1. Code migration flow for simple to complex projects 

Let us understand what each step in the above flow-diagram does. 

  1. The first step requires you to verify the build environment and prepare for migration by identifying the CUDA source files. 
  2. Using the intercept-build† tool available as a part of the Intel® oneAPI Base Toolkit, you can create a compilation database in JSON format that captures the compilation options, settings, macro definitions, and include paths used by your existing build environment. Having this JSON file available helps the migration tool to make the best decisions when replacing CUDA syntax with SYCL syntax in the code base.  
  3. The Intel DPC++ Compatibility Tool then migrates the CUDA files to oneAPI’s implementation of SYCL. Other non-CUDA files are migrated as is.  
  4. The resultant C/C++ with SYCL source files likely require some additional code review to ensure completeness and functional correctness of the migrated code. The Intel® DPC++ Compatibility Tool provides embedded hints and inline comments that help you to identify which parts of the original code were not migrated correctly or were not migrated at all and need manual intervention.  

In addition, a detailed diagnostic message reference that explains the inline comments in the migrated code is available as part of the Developer Guide and Reference Manual.  

†The Intel® DPC++ Compatibility Tool provides a utility script called intercept-build. As the name suggests, it intercepts the build process and writes the compilation options, macro definitions and include-paths to a JSON file called compilation database. The compilation database provides the exact build settings and eases the understanding of dependencies for the migration tool. The tool then parses the compilation database and applies the necessary options when migrating the source files. 

NOTE: The use of intercept-build is optional, but it is recommended for projects using Make or CMake build environments. If not used, the absence of compilation database can make it a bit harder to exactly match all the call parameters and hence, may result in less accurate code migration. 

A One-Time Process 

Code migration is a one-time process. The migrated code can be kept under version control and the finished code can then be tuned to the required level of performance for executing across heterogeneous architectures such as CPUs, GPUs, and FPGAs.  

The following diagram shows where the Intel DPC++ Compatibility Tool fits in the code-migration process. 

Figure 2. CUDA to SYCL Code Migration Workflow 

Examine the Code-Migration Results 

The migration output produced by the Compatibility Tool warns you about scenarios such as error code logic that got commented out during migration and unavailability of a DPC++ API equivalent to the CUDA source. Such hints are provided in the form of diagnostic reference numbers, each of which signifies a particular concern. For instance, DPCT1007 means that migration of the mentioned API is not supported.   

The oneAPI community maintains a diagnostic reference webpage that can help you interpret the message conveyed by each diagnostic reference number as well as provide detailed help in that regard and suggestions to fix the issue. 

Once the code migration is complete, it is easy to see how CUDA and SYCL code map to each other. The main difference is that SYCL code can be executed on multiple different GPUs and accelerators. 

Figure 3. Example of GPU Offload Vector-Add routine migrated from CUDA to SYCL 

Running on a Variety of Hardware 

To compile and execute your freshly migrated SYCL code on Intel hardware, all that is needed is to use the Intel® oneAPI DPC++/C++ Compiler included in the Intel oneAPI Base Toolkit. It will implicitly use the Intel® Graphics Compute Runtime for oneAPI Level Zero and OpenCL™ Driver, also included with the compiler distribution to target Intel® architecture and x86-compatible CPUs and Intel GPUs. 

To target NVIDIA or AMD GPUs with your new SYCL codebase, you can use the Codeplay oneAPI Plugin for NVIDIA GPUs or Codeplay oneAPI Plugin for AMD GPUs respectively. 

What’s Next? 

We encourage you to Get Started with the Intel DPC++ Compatibility Tool for efficient CUDA-to-SYCL code migration. 

Check out this extensive list of migrated code samples with detailed guidance and before/after comparison. They can all be found on the Migrate from CUDA to C++ with SYCL Portal.  

Explore some more additional useful resources to start your journey from CUDA to SYCL: 

We also encourage you to know about other AI, HPC, and Rendering tools in Intel’s oneAPI-powered software portfolio. 

Get The Software 

You can get the Intel DPC++ Compatibility Tool included as a part of the Intel oneAPI Base Toolkit


We would like to thank Chandan Damannagari for his contribution to this blog.