device SynapseType* SynapseArray;
global void kernel()
{
SynapseType* SynapsePtr=&(SynapseArray[1]);
SynapsePtr->element1=5;
Put SynapsePtr in a linked list in a device structure
}
main()
{
cudaMalloc((void**)&SynapseArray, NumberOfSynapses*sizeof(SynapseType));
kernel<<<1,1>();
}
Given that I have some code similar to the above, if I have a device array that is allocated in host code via cudaMalloc(), can a kernel access the array element by address, assign values to that address pointer element, and then use that pointer in a device structure that contains a linked list of pointers, that is only accessed by other kernels or device functions?
I am thinking I can, but I’m having strange behavior, including kernel sometimes failing to launch. I also get different results if the host passes the device array by address to the kernel such as:
global void kernel(SynapseType* synapsearray)
{
SynapseType * SynapsePtr=&(synapsearray[1]);
SynapsePtr->element1=5;
Put SynapsePtr in a linked list in a device structure
}
main()
{
cudaMalloc((void**)&SynapseArray, NumberOfSynapses*sizeof(SynapseType));
…
kernel<<<1,1>>>(SynapseArray);
}
This second method is better behaved, but still not working correctly in my program, which is much more complex. Would you expect these two uses of SynapseArray to behave differently? Are both uses valid? Is one preferable over the other?
I’m hoping I’ve done something dumb that someone will see.
Thanks,
Ken Chaffin