Workflow for a CUDA* to SYCL* Migration
Overview
Use this basic workflow to migrate your entire code base for CUDA* applications to SYCL* and optimize the code for Intel® GPU kernels.
Target Audience
Software developers with CUDA software development background.
Prerequisites
The Intel® Developer Cloud provides access to a virtual sandbox with access to Intel CPUs and GPUs as well as Intel software developer tools, such as the Intel® oneAPI Base Toolkit (Base Kit).
Alternatively, to use a local development system, you must have access to the following:
- An Intel GPU. For developer guidance and best practices see the oneAPI GPU Optimization Guide.
- The Base Kit, which provides core tools and libraries to develop high-performance applications across diverse architectures.
- The Intel® DPC++ Compatibility Tool, which is available as a stand-alone component or as part of the Base Kit. The Intel DPC++ Compatibility Tool provides guided CUDA to SYCL source code migration.
For a complete set of migration resources, see Migrate from CUDA to C++ with SYCL.
To port your source code to C++ with SYCL, ensure you have a working CUDA application. You can migrate your CUDA sources by either:
- Auto-generating most of the SYCL code using the Intel DPC++ Compatibility Tool, which provides a side-by-side comparison of CUDA to SYCL code.
- Manually analyzing CUDA sources and replacing all specific CUDA calls with the equivalent SYCL calls.
The Intel DPC++ Compatibility Tool usually migrates 90%-95% of the code and generates warnings for code regions that need manual intervention to complete the migration.1
This tool uses helper functions defined in the <dpct/dpct.hpp> header file. This is due to some SYCL calls being wrapped in an extra layer to aid the dpct helper functions. The manually migrated SYCL code uses SYCL calls and syntax that map directly to CUDA calls.
Download and try a migration using the simple Vector Add sample.
1 Intel estimates are as of September 2021 and based on measurements on a set of 70 HPC benchmarks and samples, with examples such as Rodinia, Scalable Heterogeneous Computing (SHOC), and Pennant. Results may vary.
In this step, migrate your source code to SYCL using a manual or assisted method. After finishing the migration, continue your development work on the SYCL source code.
Assisted Migration
Migrate existing CUDA code to SYCL using the Intel DPC++ Compatibility Tool. The tool ports CUDA language kernels and library API calls, and migrates most of the CUDA code to architecture- and vendor-portable SYCL code.
Learn with a Code Sample
To become familiar with the migration process for your CUDA sources, use the following resources:
- Guide to migrating a Jacobi sample: CUDA to SYCL Migration–Jacobi Iterative Method.
This guide provides a detailed step-by-step analysis of the migration with explicit explanations of the migration process and CUDA to SYCL mappings. - Additional background and the associated source code for the ported examples using the Intel DPC++ Compatibility Tool as well as additional migration and optimization techniques are on GitHub*.
Manual Migration
The manually migrated SYCL code uses SYCL calls and syntax that directly map to CUDA calls. This approach produces cleaner migrated code that may be easier to maintain in the long term. The code functionality between the two is nearly identical.
For technical details between CUDA and SYCL mappings using the Jacobi sample, see the instructions in the CUDA to SYCL Migration–Jacobi Iterative Method. This guide explains the underlying concepts of CUDA and SYCL, and the essential terms for migrating the code.
Although there are common steps for offloading and setting up asynchronous streams and memory allocation and copy, the actual work happens in the offload computation. CUDA and SYCL share some basic concepts about creating offload kernels that run on a GPU. To efficiently understand the SYCL syntax, map many of these concepts by identifying the similarities and differences:
- CUDA thread block and SYCL work group
- Shared local memory (SLM) access
- CUDA thread block and SYCL barrier synchronization
- CUDA cooperative group and SYCL subgroup
- CUDA warp primitives and SYCL group algorithms
- CUDA and SYCL atomics
Resources
At this stage, you have working code that compiles and runs. Optimize the migrated code for Intel GPUs using Intel® tools such as Intel® VTune™ Profiler and Intel® Advisor. These tools help identify areas of code to improve for optimizing your application performance. Both tools include graphical user interfaces to help visualize your optimization strategy.
Performance Analysis with Intel® VTune™ Profiler
Use this profiler to create a snapshot of your application performance baseline and identify focus areas for further analysis.
Follow these steps:
Roofline Analysis with Intel® Advisor
Use this tool to measure the actual performance of offloaded code using the GPU Roofline Insights analysis. You can evaluate GPU code to see how close the performance is to hardware maximums.
Follow these steps:
- Set up your environment to analyze GPU kernels.
- Run Roofline Analysis.
- Review results to evaluate throughput based on hardware models.
Note For more information on the Jacobi sample, on GitHub, see the "Optimizations" section in Guided Jacobi CUDA Graphs SYCL Migration. The output of these optimization steps is in sycl_migrated_optimized.
Resources
- Optimize Your GPU Application with the Base Kit
- oneAPI GPU Optimization Guide
- Essentials of SYCL for Intel Developer Cloud (Training)