Skip to content

Commit

Permalink
Fixes #698:
Browse files Browse the repository at this point in the history
* Added a `device::default_()` function for obtaining the default CUDA device
* Added a bit of code using `device::default_()` to the `device_management` example program
  • Loading branch information
eyalroz committed Nov 18, 2024
1 parent 7efdbab commit 685088c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/by_api_module/device_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ void basics(cuda::device::id_t device_id)
die_("The device's reported ID and the ID for which we created the device differ: "
+ std::to_string(device.id()) + " !=" + std::to_string(device_id));
}

if (device.id() == cuda::device::default_device_id) {
auto default_device = cuda::device::default_();
if (device != default_device) {
die_("A device with the default device ID was not equal to the default CUDA device");
}
}
}

void attributes_and_properties()
Expand Down
5 changes: 5 additions & 0 deletions src/cuda/api/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ inline device_t get(id_t id)
return wrap(id);
}

inline device_t default_()
{
return get(cuda::device::default_device_id);
}

/**
* A named constructor idiom for a "dummy" CUDA device representing the CPU.
*
Expand Down

0 comments on commit 685088c

Please sign in to comment.