I just want to check how the texture is working and I tried the following code. My purpose is to bind an array of lines which contains 4 coordinates to a texture.
I can not get the some results. Maybe the texture is not bounded with the array, I am so sure. Can anyone help me? Thanks.
I see you’re allocating an array (ScrCoords) on the device first and afterwards you’re using the host to fill out the values for ScrCoords. This is not how CUDA works. The host (CPU) does not have direct access to device memory, so you need to create an array on the host side first, then fill out the values using host code and finally upload the host array to the device array(ScrCoords) using cudaMemCpy.
So the ScrCoords = make_float4() is host code. But when I debug it, I saw the values were stored in the ScrCoords. Is it still in the host memory? And actually is there nothing in the device memory after that?
Nico correctly,
you can not directly fill data to device memory. for (int i=0; i < NumOfLines; i++)
ScrCoords[i] = make_float4(Lines[i].x1, Lines[i].y1, Lines[i].x2, Lines[i].y2);
you can not use printf() with device memory for (int i = 0; i < NumOfScreens; i++)
{
printf(“\nOri: %f,%f,%f,%f”, ScrCoords[i].x, ScrCoords[i].y, ScrCoords[i].z, ScrCoords[i].w);
printf(“\nTex: %f,%f,%f,%f”, d_testing[i].x, d_testing[i].y, d_testing[i].z, d_testing[i].w);
}
you has to create data from host-> copy to device memory and bind to texture (in cuda2.2 you can bind host memory to texture directly, read guide for more detail).
if you want to see the result, you need to copy back data from device to host memory.