// 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 "RAJAStream.hpp" using RAJA::forall; using RAJA::RangeSegment; template RAJAStream::RAJAStream(const unsigned int ARRAY_SIZE, const int device_index) : array_size(ARRAY_SIZE) { RangeSegment seg(0, ARRAY_SIZE); index_set.push_back(seg); d_a = new T[ARRAY_SIZE]; d_b = new T[ARRAY_SIZE]; d_c = new T[ARRAY_SIZE]; } template RAJAStream::~RAJAStream() { delete[] d_a; delete[] d_b; delete[] d_c; } template void RAJAStream::write_arrays(const std::vector& a, const std::vector& b, const std::vector& c) { std::copy(a.begin(), a.end(), d_a); std::copy(b.begin(), b.end(), d_b); std::copy(c.begin(), c.end(), d_c); } template void RAJAStream::read_arrays(std::vector& a, std::vector& b, std::vector& c) { std::copy(d_a, d_a + array_size - 1, a.data()); std::copy(d_b, d_b + array_size - 1, b.data()); std::copy(d_c, d_c + array_size - 1, c.data()); } template void RAJAStream::copy() { forall(index_set, [=] RAJA_DEVICE (int index) { d_c[index] = d_a[index]; }); } template void RAJAStream::mul() { const T scalar = 3.0; forall(index_set, [=] RAJA_DEVICE (int index) { d_b[index] = scalar*d_c[index]; }); } template void RAJAStream::add() { forall(index_set, [=] RAJA_DEVICE (int index) { d_c[index] = d_a[index] + d_b[index]; }); } template void RAJAStream::triad() { const T scalar = 3.0; forall(index_set, [=] RAJA_DEVICE (int index) { d_a[index] = d_b[index] + scalar*d_c[index]; }); } void listDevices(void) { std::cout << "This is not the device you are looking for."; } std::string getDeviceName(const int device) { return "RAJA"; } std::string getDeviceDriver(const int device) { return "RAJA"; } template class RAJAStream; template class RAJAStream;