39 lines
742 B
C++
39 lines
742 B
C++
#include <iostream>
|
|
|
|
#include <CL/sycl.hpp>
|
|
|
|
using namespace cl::sycl;
|
|
|
|
auto main(int argc, char **argv) -> int {
|
|
|
|
queue q;
|
|
|
|
std::cout << "Using device: " << q.get_device().get_info<info::device::name>()
|
|
<< "\n";
|
|
|
|
int hostArray[42];
|
|
auto deviceArray = static_cast<int *>(malloc_device(42 * sizeof(int), q));
|
|
|
|
for (int i = 0; i < 42; i++) {
|
|
hostArray[i] = i;
|
|
}
|
|
|
|
q.memcpy(deviceArray, hostArray, 42 * sizeof(int));
|
|
q.wait();
|
|
|
|
q.submit([&](handler &h) {
|
|
h.parallel_for(range<1>(42), [=](auto ID) { deviceArray[ID]++; });
|
|
});
|
|
|
|
q.wait();
|
|
|
|
q.memcpy(hostArray, deviceArray, 42 * sizeof(int));
|
|
q.wait();
|
|
|
|
for (int i = 0; i < 42; i++) {
|
|
std::cout << hostArray[i] << " ";
|
|
}
|
|
|
|
std::cout << "\n";
|
|
}
|