// Copyright (c) 2015-16 Tom Deakin, Simon McIntosh-Smith, // University of Bristol HPC // // For full license terms please see the LICENSE file distributed with this // source code #include "SYCLStream.h" #include using namespace cl::sycl; #define WGSIZE 64 template SYCLStream::SYCLStream(const unsigned int ARRAY_SIZE, const int device_index) { array_size = ARRAY_SIZE; // Create buffers d_a = new buffer(array_size); d_b = new buffer(array_size); d_c = new buffer(array_size); } template SYCLStream::~SYCLStream() { delete d_a; delete d_b; delete d_c; } template void SYCLStream::copy() { queue.submit([&](handler &cgh) { auto ka = d_a->template get_access(cgh); auto kc = d_c->template get_access(cgh); cgh.parallel_for(nd_range<1>{array_size, WGSIZE}, [=](nd_item<1> item) { kc[item.get_global()] = ka[item.get_global()]; }); }); queue.wait(); } template void SYCLStream::mul() { const T scalar = 3.0; queue.submit([&](handler &cgh) { auto kb = d_b->template get_access(cgh); auto kc = d_c->template get_access(cgh); cgh.parallel_for(nd_range<1>{array_size, WGSIZE}, [=](nd_item<1> item) { kb[item.get_global()] = scalar * kc[item.get_global()]; }); }); queue.wait(); } template void SYCLStream::add() { queue.submit([&](handler &cgh) { auto ka = d_a->template get_access(cgh); auto kb = d_b->template get_access(cgh); auto kc = d_c->template get_access(cgh); cgh.parallel_for(nd_range<1>{array_size, WGSIZE}, [=](nd_item<1> item) { kc[item.get_global()] = ka[item.get_global()] + kb[item.get_global()]; }); }); queue.wait(); } template void SYCLStream::triad() { const T scalar = 3.0; queue.submit([&](handler &cgh) { auto ka = d_a->template get_access(cgh); auto kb = d_b->template get_access(cgh); auto kc = d_c->template get_access(cgh); cgh.parallel_for(nd_range<1>{array_size, WGSIZE}, [=](nd_item<1> item) { ka[item.get_global()] = kb[item.get_global()] + scalar * kc[item.get_global()]; }); }); queue.wait(); } template void SYCLStream::write_arrays(const std::vector& a, const std::vector& b, const std::vector& c) { auto _a = d_a->template get_access(); auto _b = d_b->template get_access(); auto _c = d_c->template get_access(); for (int i = 0; i < array_size; i++) { _a[i] = a[i]; _b[i] = b[i]; _c[i] = c[i]; } } template void SYCLStream::read_arrays(std::vector& a, std::vector& b, std::vector& c) { auto _a = d_a->template get_access(); auto _b = d_b->template get_access(); auto _c = d_c->template get_access(); for (int i = 0; i < array_size; i++) { a[i] = _a[i]; b[i] = _b[i]; c[i] = _c[i]; } } void listDevices(void) { // TODO: Get actual list of devices std::cout << std::endl; std::cout << "Devices:" << std::endl; std::cout << "0: " << "triSYCL" << std::endl; std::cout << std::endl; } std::string getDeviceName(const int device) { // TODO: Implement properly return "triSYCL"; } std::string getDeviceDriver(const int device) { // TODO: Implement properly return "triSCYL"; } // TODO: Fix kernel names to allow multiple template specializations //template class SYCLStream; template class SYCLStream;