Hello, I’m brand new to CUDA and GPU programming in general so bear with me.
Here’s what I am trying to do. I have a variable that is used by all my global functions.
The code is too large to post here, but this is the general idea:
I need there to be some variable float fMax that is used by all of my functions. Not only that but it can’t be constant because I will need to change it.
global foo1(void *A)
//The maximum value of A (a 1d array already copied to the GPU) is found. The average is stored in fMax. Basically, this function changes fMax.
global foo2(void *A, void *B)
//Operations on A and B (1d arrays already copied to the GPU) are performed. This function uses fMax to perform those operations, but does not need to change its value.
So where/how can I declare fMax so that these functions can use it like this since am under the impression that you can’t pass fMax by reference?
My first thought is that I would have to do this:
float * fMaxHost = 0;
float * fMax = (float )malloc(sizeof(float));
cudaMemcpy(fMax, fMaxHost, sizeof(float), cudaMemcpyHostToDevice);
And change the kernel functions to something like
global void foo1(void *A, float * fMax)
global void foo2(void *A, void *B, float * fMax)
But that seems like overkill for one float. Is there a better way to do this?
I know this seems like an inefficient use of the GPU, but just humor me. :)
Thanks for any help!