Languages
CMake Integration
Link MIGraphX into a C++ project and choose CUDA/TensorRT or HIP/MIGraphX backends cleanly.
Use explicit backend selection in CMake. Auto-detection is useful as a convenience, but production builds should be reproducible.
Simple MIGraphX Target
cmake_minimum_required(VERSION 3.23)
project(migraphx_app LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(migraphx REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE migraphx::c)Depending on your ROCm package layout, the exported CMake target name can vary. If migraphx::c is not found, inspect the installed package config:
find /opt/rocm -name '*migraphx*Config.cmake' -o -name '*MIGraphX*Config.cmake'Backend Option Pattern
set(ARGUS_BACKEND "auto" CACHE STRING "Inference backend: auto, tensorrt, migraphx")
set_property(CACHE ARGUS_BACKEND PROPERTY STRINGS auto tensorrt migraphx)
if(ARGUS_BACKEND STREQUAL "migraphx")
find_package(migraphx REQUIRED)
target_sources(argus PRIVATE src/engine_migraphx.cxx)
target_link_libraries(argus PRIVATE migraphx::c)
target_compile_definitions(argus PRIVATE ARGUS_BACKEND_MIGRAPHX=1)
elseif(ARGUS_BACKEND STREQUAL "tensorrt")
find_package(CUDAToolkit REQUIRED)
target_sources(argus PRIVATE src/engine_tensorrt.cxx)
target_link_libraries(argus PRIVATE CUDA::cudart nvinfer nvonnxparser)
target_compile_definitions(argus PRIVATE ARGUS_BACKEND_TENSORRT=1)
else()
message(FATAL_ERROR "Select -DARGUS_BACKEND=tensorrt or -DARGUS_BACKEND=migraphx")
endif()Why Not Silent GPU Detection?
Build machines and runtime machines are often different. CMake can see installed libraries, but it cannot reliably tell which GPU will be present in production.
Prefer:
cmake -B build-amd -DARGUS_BACKEND=migraphx
cmake -B build-nvidia -DARGUS_BACKEND=tensorrtYou can still add an auto mode for local development:
if MIGraphX package exists, choose migraphx
else if TensorRT package exists, choose tensorrt
else fail with an actionable messageBut keep the explicit override.