[Kokkos] Use tempate type throughout instead of double

Fixes #44. Also requires the typedef keyword in a few places.
This commit is contained in:
Tom Deakin 2018-02-15 03:32:27 +00:00
parent 6803a141ee
commit dead6d0d44
4 changed files with 32 additions and 34 deletions

View File

@ -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.

View File

@ -14,12 +14,12 @@ KokkosStream<T>::KokkosStream(
{
Kokkos::initialize();
d_a = new Kokkos::View<double*>("d_a", ARRAY_SIZE);
d_b = new Kokkos::View<double*>("d_b", ARRAY_SIZE);
d_c = new Kokkos::View<double*>("d_c", ARRAY_SIZE);
hm_a = new Kokkos::View<double*>::HostMirror();
hm_b = new Kokkos::View<double*>::HostMirror();
hm_c = new Kokkos::View<double*>::HostMirror();
d_a = new Kokkos::View<T*>("d_a", ARRAY_SIZE);
d_b = new Kokkos::View<T*>("d_b", ARRAY_SIZE);
d_c = new Kokkos::View<T*>("d_c", ARRAY_SIZE);
hm_a = new typename Kokkos::View<T*>::HostMirror();
hm_b = new typename Kokkos::View<T*>::HostMirror();
hm_c = new typename Kokkos::View<T*>::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<T>::~KokkosStream()
template <class T>
void KokkosStream<T>::init_arrays(T initA, T initB, T initC)
{
Kokkos::View<double*> a(*d_a);
Kokkos::View<double*> b(*d_b);
Kokkos::View<double*> c(*d_c);
Kokkos::View<T*> a(*d_a);
Kokkos::View<T*> b(*d_b);
Kokkos::View<T*> c(*d_c);
Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index)
{
a[index] = initA;
@ -64,9 +64,9 @@ void KokkosStream<T>::read_arrays(
template <class T>
void KokkosStream<T>::copy()
{
Kokkos::View<double*> a(*d_a);
Kokkos::View<double*> b(*d_b);
Kokkos::View<double*> c(*d_c);
Kokkos::View<T*> a(*d_a);
Kokkos::View<T*> b(*d_b);
Kokkos::View<T*> c(*d_c);
Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index)
{
@ -78,9 +78,9 @@ void KokkosStream<T>::copy()
template <class T>
void KokkosStream<T>::mul()
{
Kokkos::View<double*> a(*d_a);
Kokkos::View<double*> b(*d_b);
Kokkos::View<double*> c(*d_c);
Kokkos::View<T*> a(*d_a);
Kokkos::View<T*> b(*d_b);
Kokkos::View<T*> c(*d_c);
const T scalar = startScalar;
Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index)
@ -93,9 +93,9 @@ void KokkosStream<T>::mul()
template <class T>
void KokkosStream<T>::add()
{
Kokkos::View<double*> a(*d_a);
Kokkos::View<double*> b(*d_b);
Kokkos::View<double*> c(*d_c);
Kokkos::View<T*> a(*d_a);
Kokkos::View<T*> b(*d_b);
Kokkos::View<T*> c(*d_c);
Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index)
{
@ -107,9 +107,9 @@ void KokkosStream<T>::add()
template <class T>
void KokkosStream<T>::triad()
{
Kokkos::View<double*> a(*d_a);
Kokkos::View<double*> b(*d_b);
Kokkos::View<double*> c(*d_c);
Kokkos::View<T*> a(*d_a);
Kokkos::View<T*> b(*d_b);
Kokkos::View<T*> c(*d_c);
const T scalar = startScalar;
Kokkos::parallel_for(array_size, KOKKOS_LAMBDA (const long index)
@ -122,12 +122,12 @@ void KokkosStream<T>::triad()
template <class T>
T KokkosStream<T>::dot()
{
Kokkos::View<double*> a(*d_a);
Kokkos::View<double*> b(*d_b);
Kokkos::View<T*> a(*d_a);
Kokkos::View<T*> 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<float>;
template class KokkosStream<float>;
template class KokkosStream<double>;

View File

@ -25,12 +25,12 @@ class KokkosStream : public Stream<T>
unsigned int array_size;
// Device side pointers to arrays
Kokkos::View<double*>* d_a;
Kokkos::View<double*>* d_b;
Kokkos::View<double*>* d_c;
Kokkos::View<double*>::HostMirror* hm_a;
Kokkos::View<double*>::HostMirror* hm_b;
Kokkos::View<double*>::HostMirror* hm_c;
typename Kokkos::View<T*>* d_a;
typename Kokkos::View<T*>* d_b;
typename Kokkos::View<T*>* d_c;
typename Kokkos::View<T*>::HostMirror* hm_a;
typename Kokkos::View<T*>::HostMirror* hm_b;
typename Kokkos::View<T*>::HostMirror* hm_c;
public:

View File

@ -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<float>();
else
#endif
run<double>();
}