Hi I have a relatively simple question that maybe someone can answer for me.
how can I store a gpu memory address in my .cpp main(). is there any problem with storing gpu memory addresses in the c part of the code?
basically I want to do something like the following. so I want to allocate the memory for some data at startup but keep the same data through the loop where the kernel is executed each time. this is just a shortened example not the actual code.
sorry if I sound like a newbi… I am in many ways ;-)
Cheers
[codebox]main()
{
float3* d_m1,d_m2;
float3* h_m1,h_m2
copyM(d_m1,d_m2,h_m1,h_m2);
while(1)
{
t1 = getT1();
t2 = getT2();
runTest(d_m1,d_m2,t1,t2);
}
}
extern “C” void runTest(float3* d_m1,float3* d_m2,float3 t1,float3 t2)
{
float3 d_t1;
float3 d_t2;
float3* d_results;
CUDA_SAFE_CALL( cudaMalloc( (void**) &d_t1, sizeof(float3) ) );
CUDA_SAFE_CALL( cudaMalloc( (void**) &d_t2, sizeof(float3) ) );
CUDA_SAFE_CALL( cudaMemcpy( d_t1, t1, sizeof(float3), cudaMemcpyHostToDevice) );
CUDA_SAFE_CALL( cudaMemcpy( d_t2, t2, sizeof(float3), cudaMemcpyHostToDevice) );
CUDA_SAFE_CALL( cudaMalloc( (void**) &d_results, sizeof(float3) *s1*s2) );
int gx = (int)s1/12;
int gy = (int)s2/12;
if(gx<1)gx=1;
if(gy<1)gy=1;
dim3 grid( gx, gy, 1);
dim3 threads( 12, 12, 1);
kernel<<< grid, threads>>>(d_m1, d_m2, d_t1, d_t2, d_results);
}
extern “C” void copyM(float3* d_m1,float3* d_m2, float3* h_m1, float3* h_m2,int s1, int s2)
{
CUDA_SAFE_CALL(cudaMalloc((void**) &d_m1, sizeof(float3)*s1));
CUDA_SAFE_CALL(cudaMalloc((void**) &d_m2, sizeof(float3)*s2));
CUDA_SAFE_CALL(cudaMemcpy(d_m1,h_m1, sizeof(float3)*s1 ,cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpy(d_m2,h_m2, sizeof(float3)*s2 ,cudaMemcpyHostToDevice));
}[/codebox]