Search code examples
cudacuda-driver

What are the types of these CUDA pointer attributes?


The cuGetPointerAttribute() is passed a pointer to one of multiple types, filled according to the actual attribute requested. Some of those types are stated explicitly or may be deduced implicitly to deduce, but some - not so much. Specifically... what are the types to which a pointer must be passed for the attributes:

  • CU_POINTER_ATTRIBUTE_BUFFER_ID - probably a numeric ID, but what's its type?
  • CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES - a bitmask, supposedly, but how wide?

The CUDA driver API doesn't seem to answer these questions.

PS - Even for the boolean attributes it's not made clear enough whether you should pass an int* or a bool*.


Solution

  • According to the documentation, the buffer id is stored as unsigned long long:

    CU_POINTER_ATTRIBUTE_BUFFER_ID: Returns in *data a buffer ID which is guaranteed to be unique within the process. data must point to an unsigned long long.

    When I try to pass a char* with CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES, valgrind reports an invalid write of size 8. Passing std::size_t* does not cause errors.

    Similarly, using char* with CU_POINTER_ATTRIBUTE_IS_LEGACY_CUDA_IPC_CAPABLE, reports an invalid write of size 4, which is not the case with int*

    (using NVCC V11.5.119)