Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
syclintro.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_heterogeneous
3/// Introductory SYCL examples inside ROOT’s interpreter.
4///
5/// \note This tutorial requires ROOT to be built with **SYCL support** enabled.
6/// Configure CMake with:
7/// `-Dexperimental_adaptivecpp=ON`
8/// to enable SYCL support in the interpreter.
9///
10/// This tutorial contains two examples:
11/// - `sycladd()`: a minimal kernel computing a sum of two integers
12/// - `syclvectoradd()`: adding two vectors
13///
14/// \macro_code
15///
16/// \author Devajith Valaparambil Sreeramaswamy (CERN)
17
18#include <sycl/sycl.hpp>
19#include <iostream>
20#include <vector>
21
22void sycladd()
23{
24 sycl::queue q{sycl::cpu_selector_v}; // Use openMP CPU backend
25 std::cout << "Running on: " << q.get_device().get_info<sycl::info::device::name>() << "\n";
26
27 int a = 2, b = 3;
28 int *sum = sycl::malloc_shared<int>(1, q);
29
30 q.single_task([=] { *sum = a + b; }).wait();
31 std::cout << "Sum = " << *sum << '\n';
32
33 sycl::free(sum, q);
34}
35
36void syclvectoradd()
37{
38 sycl::queue q{sycl::default_selector_v}; // Portable backend choice
39 const size_t N = 16;
40 std::vector<int> A(N, 1), B(N, 2), C(N);
41
42 int *a = sycl::malloc_shared<int>(N, q);
43 int *b = sycl::malloc_shared<int>(N, q);
44 int *c = sycl::malloc_shared<int>(N, q);
45
46 std::copy(A.begin(), A.end(), a);
47 std::copy(B.begin(), B.end(), b);
48
49 q.parallel_for(N, [=](sycl::id<1> i) { c[i] = a[i] + b[i]; }).wait();
50
51 std::copy(c, c + N, C.begin());
52
53 std::cout << "C[0] = " << C[0] << ", C[N-1] = " << C[N - 1] << "\n";
54
55 sycl::free(a, q);
56 sycl::free(b, q);
57 sycl::free(c, q);
58}
59
60void syclintro()
61{
62 sycladd();
64}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define N
float * q
const_iterator begin() const
constexpr Double_t C()
Velocity of light in .
Definition TMath.h:117
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2339