I am a beginner in SYCl/DPC++. I want to print multiples of 10 but, instead of that, I am getting 0's in place of that.
I am using the USM (Unified Shared Memory) and I am checking the data movement in the shared memory and host memory implicitly. So I have created two Arrays and I have initialized and performing the operation on them. I can see the same results for both of them.
Here is my code; I don't understand where I went wrong.
#include <CL/sycl.hpp>
#include<iostream>
using namespace std;
using namespace sycl;
constexpr int n = 10;
int main() {
queue q;
int *hostArray = malloc_host<int>(n, q);
int *sharedArray = malloc_shared<int>(n, q);
for (int i = 0; i < n; i++)
hostArray[i] = i;
q.submit([&](handler &h) {
h.parallel_for(n, [=](id<1> i) {
sharedArray[i] = hostArray[i] * 10;
});
});
for (int i = 0; i < n; i++) {
hostArray[i] = sharedArray[i];
cout<<hostArray[i]<<" "<<sharedArray[i];
cout<<"\n";
}
cout<<"\n";
return 0;
}
Expected Results:
0 0
10 10
20 20
30 30
40 40
50 50
60 60
70 70
80 80
90 90
Actual Output:
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0