#include <sycl/sycl.hpp>
#include <sycl/sycl.hpp>
void scale(float a, float* x, int n) {
int i = item.get_group(0) * item.get_local_range() + item.get_local_id();
if (i < n) {
x[i] *= a;
}
}
void add(const float* x, const float* y, float* out, int n) {
int i = item.get_group(0) * item.get_local_range() + item.get_local_id();
if (i < n) {
out[i] = x[i] + y[i];
}
item.barrier(sycl::access::fence_space::global_space);
}
int main(void) {
const int N = 1 << 16;
float *dx = nullptr, *dy = nullptr, *dz = nullptr;
cudaMalloc((void**)&dx, N * sizeof(float));
cudaMalloc((void**)&dy, N * sizeof(float));
cudaMalloc((void**)&dz, N * sizeof(float));
sycl::queue() s1, s2;
cudaStreamCreate(&s1);
cudaStreamCreate(&s2);
sycl::event() e1, e2;
cudaEventCreate(&e1);
cudaEventCreate(&e2);
dim3 grid(N / 256);
dim3 block(256);
cudaMemcpyAsync(dx, dy, N * sizeof(float), cudaMemcpyDeviceToDevice, s1);
{ }); }); smem=0 stream=s1 args=2.0f, dx, N };
cudaEventRecord(e1, s1);
cudaEventSynchronize(e1);
{ }); }); smem=128 stream=s2 args=dx, dy, dz, N };
cudaEventRecord(e2, s2);
cudaStreamSynchronize(s1);
cudaStreamSynchronize(s2);
cudaEventDestroy(e1);
cudaEventDestroy(e2);
cudaStreamDestroy(s1);
cudaStreamDestroy(s2);
cudaFree(dx);
cudaFree(dy);
cudaFree(dz);
return 0;
}