Update OpenACC for Issue #80

This commit is contained in:
Tom Deakin 2020-12-07 11:50:20 +00:00
parent b00120d346
commit 5a93022fc1
3 changed files with 11 additions and 10 deletions

View File

@ -8,7 +8,7 @@
#include "ACCStream.h" #include "ACCStream.h"
template <class T> template <class T>
ACCStream<T>::ACCStream(const unsigned int ARRAY_SIZE, T *a, T *b, T *c, int device) ACCStream<T>::ACCStream(const unsigned int ARRAY_SIZE, int device)
{ {
acc_device_t device_type = acc_get_device_type(); acc_device_t device_type = acc_get_device_type();
acc_set_device_num(device, device_type); acc_set_device_num(device, device_type);
@ -16,9 +16,9 @@ ACCStream<T>::ACCStream(const unsigned int ARRAY_SIZE, T *a, T *b, T *c, int dev
array_size = ARRAY_SIZE; array_size = ARRAY_SIZE;
// Set up data region on device // Set up data region on device
this->a = a; a = new T[array_size];
this->b = b; b = new T[array_size];
this->c = c; c = new T[array_size];
#pragma acc enter data create(a[0:array_size], b[0:array_size], c[0:array_size]) #pragma acc enter data create(a[0:array_size], b[0:array_size], c[0:array_size])
{} {}
} }
@ -28,11 +28,12 @@ ACCStream<T>::~ACCStream()
{ {
// End data region on device // End data region on device
unsigned int array_size = this->array_size; unsigned int array_size = this->array_size;
T *a = this->a;
T *b = this->b;
T *c = this->c;
#pragma acc exit data delete(a[0:array_size], b[0:array_size], c[0:array_size]) #pragma acc exit data delete(a[0:array_size], b[0:array_size], c[0:array_size])
{} {}
delete[] a;
delete[] b;
delete[] c;
} }
template <class T> template <class T>

View File

@ -28,7 +28,7 @@ class ACCStream : public Stream<T>
T *c; T *c;
public: public:
ACCStream(const unsigned int, T*, T*, T*, int); ACCStream(const unsigned int, int);
~ACCStream(); ~ACCStream();
virtual void copy() override; virtual void copy() override;

View File

@ -162,7 +162,7 @@ void run()
#elif defined(ACC) #elif defined(ACC)
// Use the OpenACC implementation // Use the OpenACC implementation
stream = new ACCStream<T>(ARRAY_SIZE, a.data(), b.data(), c.data(), deviceIndex); stream = new ACCStream<T>(ARRAY_SIZE, deviceIndex);
#elif defined(SYCL) #elif defined(SYCL)
// Use the SYCL implementation // Use the SYCL implementation
@ -362,7 +362,7 @@ void run_triad()
#elif defined(ACC) #elif defined(ACC)
// Use the OpenACC implementation // Use the OpenACC implementation
stream = new ACCStream<T>(ARRAY_SIZE, a.data(), b.data(), c.data(), deviceIndex); stream = new ACCStream<T>(ARRAY_SIZE, deviceIndex);
#elif defined(STD) #elif defined(STD)
// Use the STD implementation // Use the STD implementation