Error accesing pointer not allocated in the same method
Hi,

I have class, which members are pointers to device space:
[code]private:
int *m_d_ptr;[/code]

In many kernel invocations I will use this memory, but I can determine needed memory space in constructor.
So I call in constructor:
[code]cudaMalloc( (void**) &m_d_ptr, needed_size*sizeof(int));[/code]
But in class method on [i]cudaMemcpy[/i] I've got:
[code]Cuda error in file 'kernel.cu' in line 208 : unknown error.[/code]
but if I do [i]cudaMalloc[/i] in method just before copy, anythink works fine.

Why? I have no idea what am I doing wrong.
Hi,



I have class, which members are pointers to device space:

private:

int *m_d_ptr;




In many kernel invocations I will use this memory, but I can determine needed memory space in constructor.

So I call in constructor:

cudaMalloc( (void**) &m_d_ptr, needed_size*sizeof(int));


But in class method on cudaMemcpy I've got:

Cuda error in file 'kernel.cu' in line 208 : unknown error.


but if I do cudaMalloc in method just before copy, anythink works fine.



Why? I have no idea what am I doing wrong.

#1
Posted 04/25/2012 10:30 AM   
Hard to say, can't say what's wrong without seeing your code. How did you pass the variable?
Hard to say, can't say what's wrong without seeing your code. How did you pass the variable?

#2
Posted 04/25/2012 11:14 AM   
Just a blind guess: a miss-definition of the copy-constructor and/or operator=
Just a blind guess: a miss-definition of the copy-constructor and/or operator=

#3
Posted 04/25/2012 11:25 AM   
[quote name='shinkee' date='25 April 2012 - 11:14 AM' timestamp='1335352454' post='1400771']
Hard to say, can't say what's wrong without seeing your code. How did you pass the variable?
[/quote]

I have variable as class member.
Upper class creates my class and then calls from time to time computing function.
Computing function takes pointer from class member and operates on it.

I think that CUDA frees resource, when routine ends in constructor and returns to pure C++ class. Is there any way to tell driver, to do not release this resource, because I will need it later?
[quote name='shinkee' date='25 April 2012 - 11:14 AM' timestamp='1335352454' post='1400771']

Hard to say, can't say what's wrong without seeing your code. How did you pass the variable?





I have variable as class member.

Upper class creates my class and then calls from time to time computing function.

Computing function takes pointer from class member and operates on it.



I think that CUDA frees resource, when routine ends in constructor and returns to pure C++ class. Is there any way to tell driver, to do not release this resource, because I will need it later?

#4
Posted 04/25/2012 01:08 PM   
Scroll To Top