Easily Migrate CMake Scripts from CUDA* to SYCL*

with Intel® DPC++ Compatibility Tool

Get the Latest on All Things CODE

author-image

By

The Intel® DPC++ Compatibility Tool helps users streamline and simplify migrating original CUDA* projects to C++ projects with SYCL*.

With release 2024.1 and newer, it now supports the migration of CMake build scripts by migrating CUDA specific CMake syntax to a SYCL version. Two command line options are provided to trigger the migration of CMake build scripts:

  • --migrate-build-script=CMake         - EXPERIMENTAL: Migrate the CMake file(s).
  • --migrate-build-script-only           - EXPERIMENTAL: Only migrate the build script(s). Default: off.

Example of CMake Build Script Migration

This example uses the Velocity Bench BitCracker workload to demonstrate the migration of CMake build script, following three high-level steps:

  1. Create the Compilation Database from the Original CMake-based Project.
  2. Migrate the project and CMake Build Script with the Migration Tool.
  3. Verify the Migrated Source and CMake Build Script.

You can access the reference source code project here

Step 1: Create the Compilation Database from the Original CMake-based Project

  1. Get the Velocity Bench BitCracker code from GitHub*.
  2. Before running intercept-build, configure and generate your Makefile out of the original CMakeLists.txt by following the build instructions for CUDA.
$ cd Velocity-Bench/bitcracker/CUDA
$ mkdir build
$ cd build
$ CXX=nvcc cmake -DUSE_SM=80 ..
  1. Invoke the build command, prepending it with intercept-build.
$ make clean
$ intercept-build make

This creates the file compile_commands.json in the working directory.

The intercept-build script runs your project’s build command without building the original program. It records all the compiler invocations and stores the names of the input files and the compiler options in the compilation database file compile_commands.json.

Step 2: Migrate the Project and CMake Build Script with the Migration Tool

By default, Intel® DPC++ Compatibility Tool looks for the compile_commands.json file in the current directory and uses its compiler options for each input file.

The following command migrates the CUDA code and CMake build script using the compilation database generated in the previous step:

$ dpct  -p ./compile_commands.json --in-root=../ --out-root= dpct_output --migrate-build-script=CMake

The “--migrate-build-script=CMake” option makes the migration tool migrate both the project and CMake build script. If only the CMake build script migration is required, it can be replaced with option “--migrate-build-script-only”.

After running the migration command, you should see the following files in the dpct_output output folder:

dpct_output
└── CMakeLists.txt
└── MainSourceFiles.yaml
└── src
 

Step 3: Verify the Migrated Source and CMake Build Script

  1. Configure and generate your Makefile out of the migrated CMakeLists.txt.
$ cd dpct_output
$ mkdir build
$ cd build
$ cmake -DCMAKE_CXX_COMPILER=icpx ..
  1. Build the migrated source
$ make

Migrate your CMake Build Script from CUDA to SYCL Today

Porting complete CMake based projects from CUDA to SYCL just got easier. Join us on the journey towards multiarchitecture performance portability.

Get the stand-alone version of the Intel DPC++ Compatibility Tool or as part of the Intel® oneAPI Base Toolkit—a core set of tools and libraries for developing high-performance, data-centric applications across diverse architectures.

Additional Resources