Skip to content

Commit

Permalink
Don't presume pointers are mutually exclusive for device/host.
Browse files Browse the repository at this point in the history
Here is the results of looking at the cudaPointerGetAttributes
of different allocation types. As we can see things like
cudaMallocManaged allow the same pointer to be both host and device.
```
cudaPointerGetAttributes attributes integer
  is_dev_ptr -> 0
  is_host_ptr -> 0

cudaPointerGetAttributes attributes std::vector<int> data
  is_dev_ptr -> 0
  is_host_ptr -> 0

cudaPointerGetAttributes attributes malloc ptr
  is_dev_ptr -> 0
  is_host_ptr -> 0

cudaPointerGetAttributes attributes cudaMalloc ptr
  is_dev_ptr -> 1
  is_host_ptr -> 0

cudaPointerGetAttributes attributes cudaMallocManaged cudaMemAttachGlobal ptr
  is_dev_ptr -> 1
  is_host_ptr -> 1

cudaPointerGetAttributes attributes cudaMallocManaged cudaMemAttachHost ptr
  is_dev_ptr -> 1
  is_host_ptr -> 1

cudaPointerGetAttributes attributes cudaMallocHost ptr
  is_dev_ptr -> 1
  is_host_ptr -> 1
```
  • Loading branch information
robertmaynard committed Oct 30, 2024
1 parent a5e35c5 commit 55e4190
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cpp/src/decisiontree/decisiontree.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ inline bool is_dev_ptr(const void* p)
}
}

inline bool is_host_ptr(const void* p)
{
cudaPointerAttributes pointer_attr;
cudaError_t err = cudaPointerGetAttributes(&pointer_attr, p);
if (err == cudaSuccess) {
return (pointer_attr.hostPointer != nullptr ||
pointer_attr.type == cudaMemoryTypeUnregistered);
} else {
err = cudaGetLastError();
return false;
}
}

template <typename T>
std::string to_string_high_precision(T x)
{
Expand Down Expand Up @@ -355,7 +368,7 @@ class DecisionTree {
int verbosity)
{
if (verbosity >= 0) { ML::Logger::get().setLevel(verbosity); }
ASSERT(!is_dev_ptr(rows) && !is_dev_ptr(predictions),
ASSERT(is_host_ptr(rows) && is_host_ptr(predictions),
"DT Error: Current impl. expects both input and predictions to be CPU "
"pointers.\n");

Expand Down

0 comments on commit 55e4190

Please sign in to comment.