Skip to content

Commit

Permalink
util/all_gpus.cpp: throw custom exception instead of SEGV in select_g…
Browse files Browse the repository at this point in the history
…pu().

Application is expected to check for GPU availability prior to making any
calls, including the one in quesiton. In other word it shouldn't get here,
but if it did, make the failure more informative.
  • Loading branch information
dot-asm committed Jul 24, 2024
1 parent 0c2cb8f commit dd1d814
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions util/all_gpus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class gpus_t {
const gpu_t& select_gpu(int id)
{
auto& gpus = gpus_t::all();
if (gpus.size() == 0)
CUDA_OK(cudaErrorNoDevice);
if (id == -1) {
int cuda_id;
CUDA_OK(cudaGetDevice(&cuda_id));
Expand Down

0 comments on commit dd1d814

Please sign in to comment.