Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <CL/sycl.hpp>
#include <iostream>
#define SIZE 10
using namespace cl::sycl;
int main() {
float input[SIZE];
float output[SIZE];
// Initialize input array
for (int i = 0; i < SIZE; i++) {
input[i] = i + 1;
}
// Create SYCL queue
queue q;
// Submit command group for execution
q.submit([&](handler& cgh) {
// Create accessors for input and output buffers
accessor inputAccessor(input, range<1>(SIZE), cgh);
accessor outputAccessor(output, range<1>(SIZE), cgh);
// Define the kernel
cgh.parallel_for(range<1>(SIZE), [=](id<1> idx) {
outputAccessor[idx] = inputAccessor[idx] * inputAccessor[idx];
});
});
// Wait for the command group to finish
q.wait();
// Print the result
for (int i = 0; i < SIZE; i++) {
std::cout << output[i] << " ";
}
std::cout << std::endl;
return 0;
}