Get Started with the Intel® DPC++ Compatibility Tool

ID 768915
Date 3/31/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Get Started with Intel® DPC++ Compatibility Tool

Intel® DPC++ Compatibility Tool assists in the migration of a developer’s program that is written in CUDA* to a program written in Data Parallel C++ (DPC++), which is based on modern C++ and incorporates portable industry standards such as SYCL*.

NOTE:
Use of Intel® DPC++ Compatibility Tool will result in a project that is not entirely migrated. Additional work, as outlined by the output of Intel® DPC++ Compatibility Tool, is required to complete the migration.

Before You Begin

Intel® DPC++ Compatibility Tool is included in the Intel® oneAPI Base Toolkit. If you have not installed the Intel® oneAPI Base Toolkit, follow the instructions in the Installation Guide.

Certain CUDA header files (specific to your project) may need to be accessible to Intel® DPC++ Compatibility Tool. Intel® DPC++ Compatibility Tool looks for these CUDA header files in the default locations:

  • /usr/local/cuda/include

  • /usr/local/cuda-x.y/include, where x.y is one of these values: 8.0, 9.x, 10.x, 11.x, and 12.0.

You can reference custom locations by pointing to them with the --cuda-include-path=<path/to/cuda/include> option in Intel® DPC++ Compatibility Tool command line.

NOTE:
The CUDA include path should not be the same as, or a child path of, the directory where the source code that needs to be migrated is located.

Currently, Intel® DPC++ Compatibility Tool supports the migration of programs implemented with CUDA versions 8.0, 9.x, 10.x, 11.x, and 12.0. The list of supported languages and versions may be extended in the future.

To set up the Intel® DPC++ Compatibility Tool environment, run the following:

  • On Linux (sudo): source /opt/intel/oneapi/setvars.sh

  • On Linux (user): source ~/intel/oneapi/setvars.sh

  • On Windows: Drive:\Program Files (x86)\Intel\oneAPI\setvars.bat

Invoke the Tool

The general invocation syntax from the operating system shell is:

dpct [options] [<source0>... <sourceN>]
NOTE:
c2s is an alias to the dpct command and may be used in it’s place.

To see the list of Intel® DPC++ Compatibility Tool–specific options, use --help:

dpct --help

To see the list of the language parser (Clang*) options, pass -help as the Clang option:

dpct -- -help

Specify Files to Migrate

If no directory or file is specified for migration, the tool will try to migrate source files found in the current directory. The default output directory is dpct_output. Use the --out-root option to specify an output directory.

You can optionally provide file paths for source files that should be migrated. The paths can be found in the compilation database. The following examples show ways to specify a file or directory for migration.

Migrate single source file:

dpct source.cpp

Migrate all files available in compilation database:

dpct -p=<path to location of compilation database file>

Migrate one file in compilation database:

dpct -p=<path to location of compilation database file> source.cpp

Migrate source files in the directory specified by the --in-root option and place generated files in the directory specified by the --out-root option:

dpct --in-root=foo --out-root=bar

Emitted Warnings

Intel® DPC++ Compatibility Tool identifies the places in the code that may require your attention during the migration of the files in order to make the code SYCL compliant or correct.

Comments are inserted into the generated source files and displayed as warnings in the output. For example:

/path/to/file.hpp:26:1: warning: DPCT1003:0: Migrated API does not return error code. (*,0) is inserted. You may need to rewrite this code.
// source code line for which warning was generated
^

For more details on what a specific warning means, refer to the Diagnostic Reference.

Migrate a Simple Test Project

Several sample projects for Intel® DPC++ Compatibility Tool are available to explore the tool and familiarize yourself with how it functions.

To access the samples

  • use the oneapi-cli utility to select a sample from the Intel® DPC++ Compatibility Tool

    category, or

  • download the samples from

    GitHub*.

For more detailed information on how to download and access the samples, visit the Intel® oneAPI Base Toolkit Get Started Guides:

Sample Project

Description

Vector Add

  • vector_add.cu

The Vector Add sample demonstrates how to migrate a simple program from CUDA* to SYCL*. Vector Add provides an easy way to verify that your development environment is setup correctly to use Intel® DPC++ Compatibility Tool.

Folder Options

  • main.cu

  • bar/util.cu

  • bar/util.h

The Folder Options sample shows how to migrate more complex projects and to use options.

Rodinia needleman-wunsch

  • needle.cu

  • needle.h

  • needle_kernel.cu

The Rodinia needleman-wunsch sample demonstrates how to migrate a Make/CMake* project from CUDA to SYCL.

Review the README file provided with each sample for more detailed information about the purpose and usage of the sample project.

Try a Sample Project

The following steps show how to migrate the Vector Add sample using Intel® DPC++ Compatibility Tool:

  1. Download the Vector Add sample.

  2. Navigate to the root of the Vector Add sample. The sample contains a single CUDA file, vector_add.cu, located in the src folder.

  3. From the root folder of the sample project, run Intel® DPC++ Compatibility Tool:

    dpct --in-root=. src/vector_add.cu

    The --in-root option specifies the root location of the program sources that should be migrated. Only files and folders located within the --in-root directory will be considered for migration by the tool. Files located outside the --in-root directory will not be migrated, even if they are included by a source file located within the --in-root directory. By default, the migrated files are created in a new folder named dpct_output.

  4. As a result of the migration command, you should see the new SYCL source file in the output folder:

    dpct_output
    └── src
        └── vector_add.dp.cpp

    The relative paths of the migrated files are maintained.

  5. Navigate to the new SYCL source file:

    cd dpct_output/src

    Verify the migrated source code and fix any code that Intel® DPC++ Compatibility Tool was unable to migrate. (The code used in this example is simple, so manual changes may not be needed).

    For the most accurate and detailed instructions on addressing warnings emitted from Intel® DPC++ Compatibility Tool, see the Addressing Warnings in Migrated Code section of the README files.

    NOTE:
    To compile the migrated sample, add -I<dpct_root_folder>/include to your compile command.

For more complex sample instructions, refer to the Migrate a Project section of the Intel® DPC++ Compatibility Tool Developer Guide and Reference.

Find More

Content

Description

Intel® DPC++ Compatibility Tool Developer Guide and Reference

Detailed overview of Intel® DPC++ Compatibility Tool features, workflow, and use.

On-Demand Webinar: Migrating Your Existing CUDA Code to DPC++ Code

How to migrate CUDA code to Data Parallel C++ (DPC++) using Intel® DPC++ Compatibility Tool,

a one-time migration engine that ports both kernels and API calls.

Installation Guides for Intel® oneAPI Toolkits

Detailed instructions on how to get and install Intel® oneAPI packages

using different installer modes and package managers.

SYCL specification version 1.2.1 PDF

The SYCL Specification PDF. Explains how SYCL integrates OpenCL devices

with modern C++.

SYCL 2020 Specification

The SYCL 2020 Specification PDF.

Khronos* SYCL overview

An overview of SYCL provided by the Khronos Group.

Compiling CUDA with clang

Description of CUDA support in clang.

Intel LLVM SYCL extensions

Proposed extensions to the SYCL specification.

Layers for Yocto* Project

Add oneAPI components to a Yocto project build using the meta-intel layers.

* SYCL is a registered trademark of the Kronos Group, Inc.