【发布时间】:2019-07-24 21:19:36
【问题描述】:
我正在尝试使用 OpenACC 将一些 C++ 应用程序移植到 GPU。尽可能 期望,C++代码有很多封装和抽象。记忆是 在一些类似矢量的类中分配,然后这个类在许多其他类中被重用 围绕应用程序的类。而且我在尝试正确操作时遇到了麻烦 将 OpenACC 编译指示插入代码中。这是我的代码的简化示例 工作:
#define DATASIZE 16
class Data {
float *arr;
public:
Data() {arr = new float[DATASIZE];}
~Data() { delete [] arr; }
float &get(int i) { return arr[i]; }
};
class DataKeeper {
Data a, b, c;
public:
void init() {
for (int i = 0; i < DATASIZE; ++i)
a.get(i) = 0.0;
}
};
int main() {
DataKeeper DK;
DK.init();
}
我插入了一些 OpenACC pragma 以将必要的数据发送到设备并结束 用这样的代码:
#define DATASIZE 16
class Data {
float *arr;
public:
Data() {
arr = new float[DATASIZE];
#pragma acc enter data copyin(this)
#pragma acc enter data create(arr[:DATASIZE])
}
~Data() {
#pragma acc exit data delete(arr)
#pragma acc exit data delete(this)
delete [] arr;
}
float &get(int i) { return arr[i]; }
};
class DataKeeper {
Data a, b, c;
public:
DataKeeper() {
#pragma acc enter data copyin(this)
}
~DataKeeper() {
#pragma acc exit data delete(this)
}
void init() {
#pragma acc parallel loop
for (int i = 0; i < DATASIZE; ++i) {
a.get(i) = 0.0;
}
}
};
int main() {
DataKeeper DK;
DK.init();
}
但是编译运行后出现如下错误:
$ pgc++ test.cc -acc -g
$ ./a.out
_T24395416_101 lives at 0x7fff49e03070 size 24 partially present
Present table dump for device[1]: NVIDIA Tesla GPU 0, compute capability 3.5, threadid=1
host:0x1ae6eb0 device:0xc05ca0200 size:64 presentcount:0+1 line:11 name:(null)
host:0x1f33620 device:0xc05ca0600 size:64 presentcount:0+1 line:11 name:(null)
host:0x1f33d10 device:0xc05ca0a00 size:64 presentcount:0+1 line:11 name:(null)
host:0x7fff49e03070 device:0xc05ca0000 size:8 presentcount:0+1 line:11 name:_T24395600_98
host:0x7fff49e03078 device:0xc05ca0400 size:8 presentcount:0+1 line:11 name:_T24395600_98
host:0x7fff49e03080 device:0xc05ca0800 size:8 presentcount:0+1 line:11 name:_T24395600_98
allocated block device:0xc05ca0000 size:512 thread:1
allocated block device:0xc05ca0200 size:512 thread:1
allocated block device:0xc05ca0400 size:512 thread:1
allocated block device:0xc05ca0600 size:512 thread:1
allocated block device:0xc05ca0800 size:512 thread:1
allocated block device:0xc05ca0a00 size:512 thread:1
FATAL ERROR: variable in data clause is partially present on the device: name=_T24395416_101
file:/home/bozhenovn/tst/test.cc _ZN10DataKeeperC1Ev line:27
我不知道代码有什么问题。对于如何修复代码或如何进一步调查问题的建议,我将不胜感激。谢谢!
【问题讨论】: