Tested Standard C++ APIs

The basic functionality for several C++ standard APIs has been tested for use in SYCL* kernels. These APIs can be employed in device kernels similarly to how they are employed in code for a typical CPU-based platform. The Tested Standard C++ APIs are added to the namespace oneapi::dpl. The corresponding headers have been added in the oneAPI DPC++ Library (oneDPL) package. In order to use these APIs via the namespace oneapi::dpl, the headers in <oneapi/dpl/...> must be included. Currently, Tested Standard C++ APIs can be used in two ways:

  1. Via the namespace std:: and standard headers (for example: <utility>...)

  2. Via the namespace oneapi::dpl and oneDPL headers (for example: <oneapi/dpl/utility>...)

Below is an example code that shows how to use oneapi::dpl::swap in SYCL device code:

#include <sycl/sycl.hpp>
#include <oneapi/dpl/utility>
#include <iostream>
constexpr sycl::access::mode sycl_read_write = sycl::access::mode::read_write;
class KernelSwap;
void kernel_test() {
  sycl::queue deviceQueue;
  sycl::range<1> numOfItems{2};
  sycl::cl_int swap_num[2] = {4, 5};
  std::cout << swap_num[0] << ", " << swap_num[1] << std::endl;
  {
  sycl::buffer<sycl::cl_int, 1> swap_buffer
  (swap_num, numOfItems);
  deviceQueue.submit([&](sycl::handler &cgh) {
  auto swap_accessor = swap_buffer.get_access<sycl_read_write>(cgh);
  cgh.single_task<class KernelSwap>([=]() {
      int & num1 = swap_accessor[0];
      int & num2 = swap_accessor[1];
      oneapi::dpl::swap(num1, num2);
      });
  });
  }
  std::cout << swap_num[0] << ", " << swap_num[1] << std::endl;
}
int main() {
    kernel_test();
    return 0;
}

Use the following command to build and run the program (assuming it resides in the kernel_swap.cpp file):

dpcpp kernel_swap.cpp -o kernel_swap.exe

./kernel_swap.exe

The printed result is:

4, 5

5, 4

Tested Standard C++ API Reference

These tests were done for the following versions of the standard C++ library:

libstdc++(GNU)

Provided with GCC*-7.5.0, GCC*-9.3.0

libc++(LLVM)

Provided with Clang*-11.0

Microsoft Visual C++* (MSVC) Standard Library

Provided with Microsoft Visual Studio* 2017; Microsoft Visual Studio 2019; and Microsoft Visual Studio 2022, version 17.0, preview 4.1.

Note

Support for Microsoft Visual Studio 2017 is deprecated as of the Intel® oneAPI 2022.1 release, and will be removed in a future release.