Hi all,
I actually posted this question on the General GPU computing forum but then felt that it was more appropriate in the programming forum. Apologies for cross posting.
I am trying to compile and run a small program which will reverse an array. The kernel is supposed to transfer the array onto the shared memory and again onto the global memory in reversed order.
My code gets compiled. But when I run it… program executes and I get the reversed array printed out, but I also get the following error message.
“This application has requested the Runtime to terminate it in an unusual way. Please contact the application’s support team for more information” and also a pop-up message box saying “An exception unknown software exception has occured in the application at location 0x004…” The kernel code for this is[codebox]
global void reverse_array_shared(int* dev_arr1, int* dev_arr2, int array_size)
{
extern shared int sh_array;
int in_index = blockDim.x*blockIdx.x + threadIdx.x;
int out_index = array_size - 1 - in_index;
if(in_index < array_size)
{
/** Transferring data from Global memory into shared memory**/
sh_array[threadIdx.x] = dev_arr1[in_index];
/** Transfer it back into global memory but in a different order **/
dev_arr2[out_index] = sh_array[threadIdx.x];
}[/codebox]
I then tried randomly changin my code and I figured out what was causing the problem. The if statement inside the kernel… I put in that if statement in there to deal with the case if array_size is not a multiple of block size and prevent blank threads from executing. So i cannot understand why taking out the ‘if statement’ solved the problem…
[codebox]global void reverse_array_shared (int* dev_arr2, int* dev_arr1)
{
extern shared int sh_array;
int in_index = blockDim.x*blockIdx.x +threadIdx.x;
int out_index = gridDim.x*blockDim.x -1 - in_index;
sh_array[threadIdx.x] = dev_arr1[in_index];
dev_arr2[out_index] = sh_array[threadIdx.x];
}[/codebox]
I did read that using conditionals inside your kernel could slow down execution if the threads diverge. But nothing about causing the kernel to crash. Is there some other risk to using conditionals inside kernels that I should be aware of?? :unsure: I want to understand this problem properly so that I dont get stuck with this again… I would really appreciate it if someone could help me with this.
best,
Avinash