I’m trying to use the CUDA Driver API to construct a texture object but I keep getting an invalid value error. The texture will be indexed in the kernel code without needing any interpolation. The code I’m using is
CUDA_ARRAY_DESCRIPTOR array_desc;
array_desc.Width = size;
array_desc.Height = 1;
array_desc.Format = CU_AD_FORMAT_FLOAT;
array_desc.NumChannels = 1;
CUDA_RESOURCE_DESC resource_desc;
CUDA_TEXTURE_DESC texture_desc;
memset(&resource_desc, 0, sizeof(CUDA_RESOURCE_DESC));
memset(&texture_desc, 0, sizeof(CUDA_TEXTURE_DESC));
resource_desc.resType = CU_RESOURCE_TYPE_ARRAY;
texture_desc.addressMode[0] = CU_TR_ADDRESS_MODE_BORDER;
texture_desc.addressMode[1] = CU_TR_ADDRESS_MODE_BORDER;
texture_desc.addressMode[2] = CU_TR_ADDRESS_MODE_BORDER;
cuArrayCreate(&resource_desc.res.array.hArray, &array_desc);
CUtexObject tex;
cuTexObjectCreate(&tex, &resource_desc, &texture_desc, NULL); // This is giving me an invalid argument error.
When I run this cuTexObjectCreate
gives me an CUDA_ERROR_INVALID_VALUE
error.
An additional question are:
When I destruct this object, do I need to explicit destruct the CUArray
object also?
Why are the CUDA_RESOURCE_DESC
and CUDA_TEXTURE_DESC
passed by pointers instead of value or references? Is it ok if these objects go out of scope or do I need to keep them in memory for the life time off the CUtexObject
?