Introductory SYCL examples inside ROOT’s interpreter.
- Note
- This tutorial requires ROOT to be built with SYCL support enabled. Configure CMake with: -Dexperimental_adaptivecpp=ON to enable SYCL support in the interpreter.
This tutorial contains two examples:
- sycladd(): a minimal kernel computing a sum of two integers
- syclvectoradd(): adding two vectors
#include <sycl/sycl.hpp>
#include <iostream>
#include <vector>
void sycladd()
{
sycl::queue
q{sycl::cpu_selector_v};
std::cout <<
"Running on: " <<
q.get_device().get_info<sycl::info::device::name>() <<
"\n";
int *
sum = sycl::malloc_shared<int>(1,
q);
q.single_task([=] { *
sum =
a +
b; }).wait();
std::cout <<
"Sum = " << *
sum <<
'\n';
}
void syclvectoradd()
{
sycl::queue
q{sycl::default_selector_v};
std::vector<int> A(
N, 1), B(
N, 2),
C(
N);
int *
a = sycl::malloc_shared<int>(
N,
q);
int *
b = sycl::malloc_shared<int>(
N,
q);
int *
c = sycl::malloc_shared<int>(
N,
q);
std::copy(A.begin(), A.end(),
a);
std::copy(B.begin(), B.end(),
b);
q.parallel_for(
N, [=](sycl::id<1> i) {
c[i] =
a[i] +
b[i]; }).wait();
std::copy(
c,
c +
N,
C.begin());
std::cout <<
"C[0] = " <<
C[0] <<
", C[N-1] = " <<
C[
N - 1] <<
"\n";
}
void syclintro()
{
sycladd();
syclvectoradd();
}
constexpr Double_t C()
Velocity of light in .
static uint64_t sum(uint64_t i)
- Author
- Devajith Valaparambil Sreeramaswamy (CERN)
Definition in file syclintro.C.