Skip to content

vtkm::cont::Initialize() throws/crashes if compiled with CUDA and ran on non-CUDA machine (Windows)

If vtk-m was compiled with CUDA support, but is ran on a machine without CUDA, vtkm::cont::initialize() throws.

Environment:

  • vtkm 2.0.0 (But the statement is the same in master, so I assume it occurs there as well)
  • on Windows MSVC,
  • using CUDA 11.8

Example:

int main(int argc, char** argv) {
    vtkm::cont::Initialize(argc, argv);
}

Details:: I tested this on two different machines,

  • Win 11 Pro with an AMD gfx card
  • Win 11 with Intel integrated gfx card

The throwing statement is: https://gitlab.kitware.com/vtk/vtk-m/-/blob/master/vtkm/cont/cuda/internal/RuntimeDeviceConfigurationCuda.h?ref_type=heads#L40

Since catching this exception in user code would skip runtime detection of other backends, I assume this is a bug.

To reproduce this bug it's sufficient to disable any Nvidia-Cards in Windows Device Manager.

Temporary fix:

My current ugly hack to fix this:

RuntimeDeviceConfiguration<vtkm::cont::DeviceAdapterTagCuda>()
  {
    int tmp;
    try
    {
      VTKM_CUDA_CALL(cudaGetDeviceCount(&tmp));
    }
    catch (...)
    {
      tmp = 0;
    }
    this->CudaDeviceCount = tmp;
    this->CudaProp.resize(this->CudaDeviceCount);
    for (int i = 0; i < this->CudaDeviceCount; ++i)
    {
      VTKM_CUDA_CALL(cudaGetDeviceProperties(&this->CudaProp[i], i));
    }
  }
Edited by B3nni