Migrating from CUDA to DPC++ Using the Intel® DPC++ Compatibility Tool
It’s Easier than Ever to Move to a Non-Proprietary Programming Language
It’s becoming apparent that future computing systems will be heterogeneous. The MAGMA project at the University of Tennessee is developing a dense linear algebra library similar to LAPACK but for heterogeneous architectures, like current CPU and GPU systems. I was looking for a sparse solver code sample that gives good performance across different architectures. MAGMA was an obvious candidate. This article describes my use of the Intel® DPC++ Compatibility Tool (DPCT) to migrate MAGMA CUDA code to Data Parallel C++ (DPC++).
Migration Steps and Hacks Required
Migration can happen in two ways. The first method is file-to-file manual migration, which is a good choice if you’re just migrating a few files. The second method is to create a .json file for projects that use make or cmake. MAGMA has a makefile, so let’s focus on the JSON approach.
The build options of input projects files (e.g., include path, macros definitions, etc.) are collected in a .json file. It is mainly generated using the intercept-build make command. (Be sure you’re using Make 4.0 or later.) Next, we run the dpct command, which has a handful of flags to help with migration. The command-line for migrating MAGMA was:
Table 1. Flags and functions
(See the documentation for additional flags.)
The next step is to interpret the output after running dpct on the application. The dpct annotates places in the code where modifications may be necessary to make the code DPC++ compliant or syntactically correct, e.g:
For large projects, it’s advisable to redirect the migration logs to a file. Learn how various error codes/diagnostics are reported by the tool here.
Figures 1 and 2 show a successful migration of a kernel call from the MAGMA library. Since the migration is done with the –keep-original-code flag, the original code is also present in the migrated file (Figure 2).
Figure 1. Original CUDA code
Figure 2. Migrated DPC++ code
Some manual effort is required to migrate functions that the tool can’t migrate, but annotations generated by the tool make this easier:
There are sometimes multiple annotations for a line of CUDA code:
Some CUDA libraries have equivalent functions in oneAPI libraries (e.g., oneMKL, oneDNN, oneVPL, etc.). The Intel DPC++ Compatibility Tool can migrate many CUDA library functions to their oneAPI equivalents. The tools will call out those that can’t be migrated directly. It’s often possible to manually implement the same functionality. For example, the CUDA cusparseDcsrmv function can be manually migrated using a combination of oneMKL mkl::sparse::gemv and mkl::sparse::set_csr_data functions.
The Intel DPC++ Compatibility Tool is evolving every day with input from users. Some of the known issues with the tool are stated in the Known Issues and Limitations Section of the release notes.
The Intel DPC++ Compatibility Tool reduces the time and effort required to migrate CUDA applications to DPC++. It gives helpful annotations and warnings to minimize the manual effort required for sections of code that are not migrated by the tool. Migrating MAGMA from CUDA to DPC++ would have been a tedious job without this tool.