From dead6d0d44a4b7a24f99a1ad8296721c81ed7de3 Mon Sep 17 00:00:00 2001 From: Tom Deakin Date: Thu, 15 Feb 2018 03:32:27 +0000 Subject: [PATCH] [Kokkos] Use tempate type throughout instead of double Fixes #44. Also requires the typedef keyword in a few places. --- CHANGELOG.md | 1 + KokkosStream.cpp | 50 ++++++++++++++++++++++++------------------------ KokkosStream.hpp | 12 ++++++------ main.cpp | 3 --- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9765632..bc1d14d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Kokkos now compiles and links separately to fix complication with Kokkos 2.05.00. +- Kokkos can now instantiate single and double precision. - OpenMP 4.5 map and reduction clause order to ensure reduction result copied back. diff --git a/KokkosStream.cpp b/KokkosStream.cpp index 7054fba..19d4b24 100644 --- a/KokkosStream.cpp +++ b/KokkosStream.cpp @@ -14,12 +14,12 @@ KokkosStream::KokkosStream( { Kokkos::initialize(); - d_a = new Kokkos::View("d_a", ARRAY_SIZE); - d_b = new Kokkos::View("d_b", ARRAY_SIZE); - d_c = new Kokkos::View("d_c", ARRAY_SIZE); - hm_a = new Kokkos::View::HostMirror(); - hm_b = new Kokkos::View::HostMirror(); - hm_c = new Kokkos::View::HostMirror(); + d_a = new Kokkos::View("d_a", ARRAY_SIZE); + d_b = new Kokkos::View("d_b", ARRAY_SIZE); + d_c = new Kokkos::View("d_c", ARRAY_SIZE); + hm_a = new typename Kokkos::View::HostMirror(); + hm_b = new typename Kokkos::View::HostMirror(); + hm_c = new typename Kokkos::View::HostMirror(); *hm_a = create_mirror_view(*d_a); *hm_b = create_mirror_view(*d_b); *hm_c = create_mirror_view(*d_c); @@ -34,9 +34,9 @@ KokkosStream::~KokkosStream() template void KokkosStream::init_arrays(T initA, T initB, T initC) { - Kokkos::View a(*d_a); - Kokkos::View b(*d_b); - Kokkos::View c(*d_c); + Kokkos::View a(*d_a); + Kokkos::View b(*d_b); + Kokkos::View c(*d_c); Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index) { a[index] = initA; @@ -64,9 +64,9 @@ void KokkosStream::read_arrays( template void KokkosStream::copy() { - Kokkos::View a(*d_a); - Kokkos::View b(*d_b); - Kokkos::View c(*d_c); + Kokkos::View a(*d_a); + Kokkos::View b(*d_b); + Kokkos::View c(*d_c); Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index) { @@ -78,9 +78,9 @@ void KokkosStream::copy() template void KokkosStream::mul() { - Kokkos::View a(*d_a); - Kokkos::View b(*d_b); - Kokkos::View c(*d_c); + Kokkos::View a(*d_a); + Kokkos::View b(*d_b); + Kokkos::View c(*d_c); const T scalar = startScalar; Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index) @@ -93,9 +93,9 @@ void KokkosStream::mul() template void KokkosStream::add() { - Kokkos::View a(*d_a); - Kokkos::View b(*d_b); - Kokkos::View c(*d_c); + Kokkos::View a(*d_a); + Kokkos::View b(*d_b); + Kokkos::View c(*d_c); Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index) { @@ -107,9 +107,9 @@ void KokkosStream::add() template void KokkosStream::triad() { - Kokkos::View a(*d_a); - Kokkos::View b(*d_b); - Kokkos::View c(*d_c); + Kokkos::View a(*d_a); + Kokkos::View b(*d_b); + Kokkos::View c(*d_c); const T scalar = startScalar; Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index) @@ -122,12 +122,12 @@ void KokkosStream::triad() template T KokkosStream::dot() { - Kokkos::View a(*d_a); - Kokkos::View b(*d_b); + Kokkos::View a(*d_a); + Kokkos::View b(*d_b); T sum = 0.0; - Kokkos::parallel_reduce(array_size, KOKKOS_LAMBDA (const long index, double &tmp) + Kokkos::parallel_reduce(array_size, KOKKOS_LAMBDA (const long index, T &tmp) { tmp += a[index] * b[index]; }, sum); @@ -153,5 +153,5 @@ std::string getDeviceDriver(const int device) return "Kokkos"; } -//template class KokkosStream; +template class KokkosStream; template class KokkosStream; diff --git a/KokkosStream.hpp b/KokkosStream.hpp index 9ba6fea..1470cf4 100644 --- a/KokkosStream.hpp +++ b/KokkosStream.hpp @@ -25,12 +25,12 @@ class KokkosStream : public Stream unsigned int array_size; // Device side pointers to arrays - Kokkos::View* d_a; - Kokkos::View* d_b; - Kokkos::View* d_c; - Kokkos::View::HostMirror* hm_a; - Kokkos::View::HostMirror* hm_b; - Kokkos::View::HostMirror* hm_c; + typename Kokkos::View* d_a; + typename Kokkos::View* d_b; + typename Kokkos::View* d_c; + typename Kokkos::View::HostMirror* hm_a; + typename Kokkos::View::HostMirror* hm_b; + typename Kokkos::View::HostMirror* hm_c; public: diff --git a/main.cpp b/main.cpp index 97443d4..d35cc76 100644 --- a/main.cpp +++ b/main.cpp @@ -85,12 +85,9 @@ int main(int argc, char *argv[]) } else { - // TODO: Fix Kokkos to allow multiple template specializations -#ifndef KOKKOS if (use_float) run(); else -#endif run(); }