Here is my code:
struct S {
int a, b;
float c, d;
};
class A {
private:
S* d;
S h[3];
public:
A() {
cutilSafeCall(cudaMalloc((void**)&d, sizeof(S)*3));
}
void Init();
};
void A::Init() {
for (int i=0;i<3;i++) {
h[i].a = 0;
h[i].b = 1;
h[i].c = 2;
h[i].d = 3;
}
cutilSafeCall(cudaMemcpy(d, h, 3*sizeof(S), cudaMemcpyHostToDevice));
}
A a;
This is actually a complex program that contains CUDA and OpenGL. When I debug this program, it does not work when running cudaMemcpy with error information
cudaSafeCall () Runtime 11 API error: invalid argument.
Actually, this program is converted from another, which may work correctly. But in this I used two variables S * d and S h [3] in the main function, and not in the class. What is weirder is that I implement this class A in a small program, it works fine. And I updated my driver, the error still exists.
Can someone give me a clue why this is happening and how to solve it. Thank.
source
share