// kernels-community/relu XPU backend kernel (SYCL parallel_for), torch-free. // Runs on whatever SYCL device is present (here: the i9 CPU via OpenCL). #include #include #include #include #include using namespace sycl; int main(){ queue q{default_selector_v}; printf("SYCL device: %s\n", q.get_device().get_info().c_str()); const size_t n = 256ull*1024*1024; // 1 GB/array float* in = malloc_shared(n, q); float* out = malloc_shared(n, q); for(size_t i=0;i(n),[=](id<1> i){ out[i]=in[i]>0.f?in[i]:0.f; }).wait(); }; for(int w=0;w<3;w++) run(); bool ok=true; for(size_t i=0;i0?in[i]:0; if(out[i]!=e) ok=false; } double best=1e30; for(int r=0;r<8;r++){ auto t0=std::chrono::high_resolution_clock::now(); run(); auto t1=std::chrono::high_resolution_clock::now(); best=std::min(best,std::chrono::duration(t1-t0).count()); } printf("SYCL relu (xpu backend): %.1f GB/s (%.2f ms) %s\n", gb/best, best*1e3, ok?"OK":"FAIL"); free(in,q); free(out,q); return 0; }