// 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 "KOKKOSStream.hpp" using Kokkos::parallel_for; template KOKKOSStream::KOKKOSStream( const unsigned int ARRAY_SIZE, const int device_index) : array_size(ARRAY_SIZE) { Kokkos::initialize(); new(d_a) Kokkos::View("d_a", ARRAY_SIZE); new(d_b) Kokkos::View("d_b", ARRAY_SIZE); new(d_c) Kokkos::View("d_c", ARRAY_SIZE); new(hm_a) Kokkos::View::HostMirror(); new(hm_b) Kokkos::View::HostMirror(); new(hm_c) Kokkos::View::HostMirror(); hm_a = Kokkos::create_mirror_view(d_a); hm_b = Kokkos::create_mirror_view(d_b); hm_c = Kokkos::create_mirror_view(d_c); } template KOKKOSStream::~KOKKOSStream() { Kokkos::finalize(); } template void KOKKOSStream::write_arrays( const std::vector& a, const std::vector& b, const std::vector& c) { for(int ii = 0; ii < array_size; ++ii) { hm_a(ii) = a[ii]; hm_b(ii) = b[ii]; hm_c(ii) = c[ii]; } Kokkos::deep_copy(hm_a, d_a); Kokkos::deep_copy(hm_b, d_b); Kokkos::deep_copy(hm_c, d_c); } template void KOKKOSStream::read_arrays( std::vector& a, std::vector& b, std::vector& c) { Kokkos::deep_copy(d_a, hm_a); Kokkos::deep_copy(d_a, hm_b); Kokkos::deep_copy(d_a, hm_c); for(int ii = 0; ii < array_size; ++ii) { a[ii] = hm_a(ii); b[ii] = hm_b(ii); c[ii] = hm_c(ii); } } template void KOKKOSStream::copy() { Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const int index) { d_c[index] = d_a[index]; }); } template void KOKKOSStream::mul() { const T scalar = 3.0; parallel_for(array_size, KOKKOS_LAMBDA (const int index) { d_b[index] = scalar*d_c[index]; }); } template void KOKKOSStream::add() { parallel_for(array_size, KOKKOS_LAMBDA (const int index) { d_c[index] = d_a[index] + d_b[index]; }); } template void KOKKOSStream::triad() { const T scalar = 3.0; parallel_for(array_size, KOKKOS_LAMBDA (const 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 "Kokkos"; } std::string getDeviceDriver(const int device) { return "Kokkos"; } template class KOKKOSStream; template class KOKKOSStream;