#include "example_utils.hpp"
#include "oneapi/dnnl/dnnl_sycl.hpp"
#include <CL/sycl.hpp>
#include <cassert>
#include <iostream>
#include <numeric>
class kernel_tag;
void sycl_interop_buffer_tutorial(
engine::kind engine_kind) {
const size_t N = std::accumulate(tz_dims.begin(), tz_dims.end(), (size_t)1,
std::multiplies<size_t>());
auto sycl_buf = sycl_interop::get_buffer<float>(mem);
q.submit([&](handler &cgh) {
auto a = sycl_buf.get_access<access::mode::write>(cgh);
cgh.parallel_for<kernel_tag>(range<1>(N), [=](id<1> i) {
int idx = (int)i[0];
a[idx] = (idx % 2) ? -idx : idx;
});
});
strm.wait();
auto host_acc = sycl_buf.get_access<access::mode::read>();
for (size_t i = 0; i < N; i++) {
float exp_value = (i % 2) ? 0.0f : i;
if (host_acc[i] != (float)exp_value)
throw std::string(
"Unexpected output, find a negative value after the ReLU "
"execution.");
}
}
int main(int argc, char **argv) {
int exit_code = 0;
try {
sycl_interop_buffer_tutorial(engine_kind);
std::cout << "oneDNN error caught: " << std::endl
<<
"\tStatus: " << dnnl_status2str(e.
status) << std::endl
<<
"\tMessage: " << e.
what() << std::endl;
exit_code = 1;
} catch (std::string &e) {
std::cout << "Error in the example: " << e << "." << std::endl;
exit_code = 2;
}
std::cout << "Example " << (exit_code ? "failed" : "passed") << " on "
<< engine_kind2str_upper(engine_kind) << "." << std::endl;
return exit_code;
}