Skip to content

Commit

Permalink
Don't presume pointers location infers usability. (#2480)
Browse files Browse the repository at this point in the history
Here is the results of looking at the cudaPointerGetAttributes of different allocation types on Grace + Hopper. Allocations of `malloc` are still usable on the GPU.
```
ccudaPointerGetAttributes attributes malloc ptr
  is_dev_ptr  -> 1
  is_host_ptr -> 1
  memory loc  -> unregistered

cudaPointerGetAttributes attributes cudaMalloc ptr
  is_dev_ptr  -> 1
  is_host_ptr -> 0
  memory loc  -> device

cudaPointerGetAttributes attributes cudaMallocManaged cudaMemAttachGlobal ptr
  is_dev_ptr  -> 1
  is_host_ptr -> 1
  memory loc  -> managed

```

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Micka (https://github.com/lowener)

URL: #2480
  • Loading branch information
robertmaynard authored Nov 6, 2024
1 parent 45f24ab commit 53b9caa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 3 additions & 8 deletions cpp/include/raft/spatial/knn/detail/ann_utils.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ struct pointer_residency_count<Type, Types...> {
auto [on_device, on_host] = pointer_residency_count<Types...>::run(ptrs...);
cudaPointerAttributes attr;
RAFT_CUDA_TRY(cudaPointerGetAttributes(&attr, ptr));
switch (attr.type) {
case cudaMemoryTypeUnregistered: return std::make_tuple(on_device, on_host + 1);
case cudaMemoryTypeHost:
return std::make_tuple(on_device + int(attr.devicePointer == ptr), on_host + 1);
case cudaMemoryTypeDevice: return std::make_tuple(on_device + 1, on_host);
case cudaMemoryTypeManaged: return std::make_tuple(on_device + 1, on_host + 1);
default: return std::make_tuple(on_device, on_host);
}
if (attr.devicePointer || attr.type == cudaMemoryTypeDevice) { ++on_device; }
if (attr.hostPointer || attr.type == cudaMemoryTypeUnregistered) { ++on_host; }
return std::make_tuple(on_device, on_host);
}
};

Expand Down
5 changes: 3 additions & 2 deletions cpp/include/raft/util/cudart_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,13 @@ void print_vector(const char* variable_name, const T* ptr, size_t componentsCoun
{
cudaPointerAttributes attr;
RAFT_CUDA_TRY(cudaPointerGetAttributes(&attr, ptr));
if (attr.hostPointer != nullptr) {
if (attr.hostPointer) {
print_host_vector(variable_name, reinterpret_cast<T*>(attr.hostPointer), componentsCount, out);
} else if (attr.type == cudaMemoryTypeUnregistered) {
print_host_vector(variable_name, ptr, componentsCount, out);
} else {
print_device_vector(variable_name, ptr, componentsCount, out);
print_device_vector(
variable_name, reinterpret_cast<T*>(attr.devicePointer), componentsCount, out);
}
}
/** @} */
Expand Down

0 comments on commit 53b9caa

Please sign in to comment.