Skip to content

Fix onnxruntime CUDA for non-cuda-support platform

Xiangyang Ju requested to merge xju/athena:mr_fix_onnxruntime_gpu into main

The recent merge request !64072 (merged) breaks the AthExOnnxRuntime in the clang16 nightlies Link to log file and the ARM/aarch64 nightlies Link to log file that both do not provide CUDA, reported by @elmsheus.

This MR fixes the issue and removes the obsolete function CreateORTSessionGPU spotted by @tadej.

This fix is generic for all CUDA-based developments. It can be added as a CMake function as follows, where target is the target object.

function (check_cuda_driver target)
  find_program(_nvidia_smi "nvidia-smi")
  if (_nvidia_smi)
     message(STATUS "Found nvidia-smi, enabling CUDA support")
     target_compile_definitions(target INTERFACE FOUND_CUDA_DRIVER)
  else()
     message(STATUS "nvidia-smi not found, disabling CUDA support")
  endif()
endfunction()

Then users can add in the CMakeLists.txt like check_cuda_driver(AthOnnxruntimeUtilsLib), and in the code use #ifdef FOUND_CUDA_DRIVER and #endif to hide the cuda-specific code blocks to bar them from being compiled.

Edited by Xiangyang Ju

Merge request reports