I am new to cuda, so I hope my question isn't totally off base. I want to create an array on the global device memory but I will only know how large it will be in the middle of my main function (but before I ever access the device).
Because I don't know the size I can't declare before my code: device myArr[]
So I thought of creating a pointer in main, d_myArr, and then using cudaMalloc(d_myArr, arrSize) to allocate memory on the device but then I never really declare a variable on my device.
I do not see a reason to send d_Arr to my kernel as it will then only exist in that kernel (I think?), I just want the variable to exist on my device as a global variable in the first place, and be accessable by different kernels.
can I declare a device variable inside main? As in:
int main(){
.
.
__device__ myArr[size];
.
.
}
If so is it discoureged for some reason (because I can't find anyone doing so). If this isn't allowed what can I do instead? I saw people mentioning cudaMemcpyToSymbol but I couldn't figure out if it was relavent to what I wanted exactly, if it is I would be glad if someone could explain exactly how it can be used to achive what I need.
On a side question I also have a constant variable I want to exist on both my device and host. For now I just declaired it twice, once with device and once without, is there a better way of doing this?