Skip to content

Commit

Permalink
Merge pull request UoB-HPC#58 from GeorgeWeb/sycl-compliant
Browse files Browse the repository at this point in the history
Making BabelStream's SYCL code compliant
  • Loading branch information
tomdeakin authored Jun 26, 2019
2 parents 289a2c2 + e657bfa commit 022793b
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions SYCLStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

using namespace cl::sycl;


// Cache list of devices
bool cached = false;
std::vector<device> devices;
Expand Down Expand Up @@ -67,16 +66,7 @@ SYCLStream<T>::SYCLStream(const unsigned int ARRAY_SIZE, const int device_index)
throw std::runtime_error("SYCL errors detected");
}
});

/* Pre-build the kernels */
p = new program(queue->get_context());
p->build_with_kernel_type<init_kernel>();
p->build_with_kernel_type<copy_kernel>();
p->build_with_kernel_type<mul_kernel>();
p->build_with_kernel_type<add_kernel>();
p->build_with_kernel_type<triad_kernel>();
p->build_with_kernel_type<dot_kernel>();


// Create buffers
d_a = new buffer<T>(array_size);
d_b = new buffer<T>(array_size);
Expand All @@ -91,7 +81,6 @@ SYCLStream<T>::~SYCLStream()
delete d_b;
delete d_c;
delete d_sum;

delete p;
delete queue;
devices.clear();
Expand All @@ -104,8 +93,7 @@ void SYCLStream<T>::copy()
{
auto ka = d_a->template get_access<access::mode::read>(cgh);
auto kc = d_c->template get_access<access::mode::write>(cgh);
cgh.parallel_for<copy_kernel>(p->get_kernel<copy_kernel>(),
range<1>{array_size}, [=](item<1> item)
cgh.parallel_for<copy_kernel>(range<1>{array_size}, [=](item<1> item)
{
auto id = item.get_id(0);
kc[id] = ka[id];
Expand All @@ -122,8 +110,7 @@ void SYCLStream<T>::mul()
{
auto kb = d_b->template get_access<access::mode::write>(cgh);
auto kc = d_c->template get_access<access::mode::read>(cgh);
cgh.parallel_for<mul_kernel>(p->get_kernel<mul_kernel>(),
range<1>{array_size}, [=](item<1> item)
cgh.parallel_for<mul_kernel>(range<1>{array_size}, [=](item<1> item)
{
auto id = item.get_id(0);
kb[id] = scalar * kc[id];
Expand All @@ -140,8 +127,7 @@ void SYCLStream<T>::add()
auto ka = d_a->template get_access<access::mode::read>(cgh);
auto kb = d_b->template get_access<access::mode::read>(cgh);
auto kc = d_c->template get_access<access::mode::write>(cgh);
cgh.parallel_for<add_kernel>(p->get_kernel<add_kernel>(),
range<1>{array_size}, [=](item<1> item)
cgh.parallel_for<add_kernel>(range<1>{array_size}, [=](item<1> item)
{
auto id = item.get_id(0);
kc[id] = ka[id] + kb[id];
Expand All @@ -159,8 +145,7 @@ void SYCLStream<T>::triad()
auto ka = d_a->template get_access<access::mode::write>(cgh);
auto kb = d_b->template get_access<access::mode::read>(cgh);
auto kc = d_c->template get_access<access::mode::read>(cgh);
cgh.parallel_for<triad_kernel>(p->get_kernel<triad_kernel>(),
range<1>{array_size}, [=](item<1> item)
cgh.parallel_for<triad_kernel>(range<1>{array_size}, [=](item<1> item)
{
auto id = item.get_id(0);
ka[id] = kb[id] + scalar * kc[id];
Expand All @@ -181,12 +166,10 @@ T SYCLStream<T>::dot()
auto wg_sum = accessor<T, 1, access::mode::read_write, access::target::local>(range<1>(dot_wgsize), cgh);

size_t N = array_size;

cgh.parallel_for<dot_kernel>(p->get_kernel<dot_kernel>(),
nd_range<1>(dot_num_groups*dot_wgsize, dot_wgsize), [=](nd_item<1> item)
cgh.parallel_for<dot_kernel>(nd_range<1>(dot_num_groups*dot_wgsize, dot_wgsize), [=](nd_item<1> item)
{
size_t i = item.get_global(0);
size_t li = item.get_local(0);
size_t i = item.get_global_id(0);
size_t li = item.get_local_id(0);
size_t global_size = item.get_global_range()[0];

wg_sum[li] = 0.0;
Expand Down Expand Up @@ -224,8 +207,7 @@ void SYCLStream<T>::init_arrays(T initA, T initB, T initC)
auto ka = d_a->template get_access<access::mode::write>(cgh);
auto kb = d_b->template get_access<access::mode::write>(cgh);
auto kc = d_c->template get_access<access::mode::write>(cgh);
cgh.parallel_for<init_kernel>(p->get_kernel<init_kernel>(),
range<1>{array_size}, [=](item<1> item)
cgh.parallel_for<init_kernel>(range<1>{array_size}, [=](item<1> item)
{
auto id = item.get_id(0);
ka[id] = initA;
Expand Down

0 comments on commit 022793b

Please sign in to comment.