Skip to content

Instantly share code, notes, and snippets.

@al42and
Created May 27, 2022 16:42
Show Gist options
  • Save al42and/1bbaf3df22d1af5382cf9f40056cc5b2 to your computer and use it in GitHub Desktop.
Save al42and/1bbaf3df22d1af5382cf9f40056cc5b2 to your computer and use it in GitHub Desktop.
#include <CL/sycl.hpp>
#include <iostream>
#include <stdio.h>
void run_kernel(const sycl::device &syclDevice) {
constexpr int numThreads = 512;
try {
sycl::queue queue = sycl::queue(syclDevice);
sycl::buffer<int, 1> buffer(numThreads);
queue
.submit([&](sycl::handler &cgh) {
auto buffer_dev =
buffer.get_access<sycl::access::mode::discard_write>(cgh);
cgh.parallel_for<class Kernel>(
sycl::range<1>{numThreads}, [=](sycl::id<1> threadId) {
buffer_dev[threadId] = threadId.get(0);
});
})
.wait_and_throw();
const auto buffer_host = buffer.get_access<sycl::access::mode::read>();
for (int i = 0; i < numThreads; i++) {
if (buffer_host[i] != i) {
printf("Dummy kernel produced invalid values\n");
}
}
} catch (const std::exception &e) {
printf("Unable to run dummy kernel on device %s: %s\n",
syclDevice.get_info<sycl::info::device::name>().c_str(), e.what());
}
}
int main() {
std::vector<sycl::device> devices = sycl::device::get_devices();
for (const auto &dev : devices) {
for (int i = 0; i < 20; i++) {
run_kernel(dev);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment