Hello all.
This is my first post here.
I’m a beginner with CUDA and I need an advice regarding Array Initialization. Let’s take an short example :
__global__ kernel_1 (bool* Value)
{
int offset = blockDim.x * blockIdx.x + threadIdx.x;
int myArray [7] = {0} ;
if( myArray[0] == 0)
Value[offset] = true;
else
Value[offset] = false;
}
If I launch the kernel, and then retrieve the booleans, 99% of the time, myArray[0] is different from 0.
My question is : Is it normal or did I make a mistake ?
Thank you in advance.
Alice.
tera
March 27, 2011, 12:05pm
2
Looking at the .ptx file generated (after inserting the missing [font=“Courier New”]void[/font] declaration, the compiler optimizes this to
__global__ void kernel_1 (bool* Value)
{
int offset = blockDim.x * blockIdx.x + threadIdx.x;
Value[offset] = true;
}
so there should be no doubt that [font=“Courier New”]Value[/font] gets set to [font=“Courier New”]true[/font] if the kernel executes at all. Do you check return codes for errors?
Looking at the .ptx file generated (after inserting the missing [font=“Courier New”]void[/font] declaration, the compiler optimizes this to
__global__ void kernel_1 (bool* Value)
{
int offset = blockDim.x * blockIdx.x + threadIdx.x;
Value[offset] = true;
}
so there should be no doubt that [font=“Courier New”]Value[/font] gets set to [font=“Courier New”]true[/font] if the kernel executes at all. Do you check return codes for errors?
I’m sorry for the missing ‘void’, I have re-written the code directly in the post.
‘cudaMemCpy’ returns 0 when I execute the program…