onnxruntime
8941f8c1 - Fix build failure when both CUDA and MiGraphX execution providers are enabled (#27798)

Commit
16 days ago
Fix build failure when both CUDA and MiGraphX execution providers are enabled (#27798) ### Description `arena_extend_strategy` was defined in separate `#if defined(USE_CUDA)` and `#if defined(USE_MIGRAPHX)` preprocessor blocks, causing a redefinition error when both providers are enabled. Consolidates the definition and extern declaration into a single combined guard: ```cpp #if defined(USE_MIGRAPHX) || defined(USE_CUDA) || defined(USE_CUDA_PROVIDER_INTERFACE) onnxruntime::ArenaExtendStrategy arena_extend_strategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo; #endif ``` Both files updated: - `onnxruntime/python/onnxruntime_pybind_state_common.cc` — variable definition - `onnxruntime/python/onnxruntime_pybind_state_common.h` — extern declaration No other duplicate symbols found across CUDA/MiGraphX conditional blocks. ### Motivation and Context Building with `--use_cuda --use_migraphx` fails with: ``` error: redefinition of 'onnxruntime::ArenaExtendStrategy onnxruntime::python::arena_extend_strategy' ``` Both providers share this config variable; it just needs a unified guard. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[Build] Cannot build with cuda and migraphx</issue_title> > <issue_description>### Describe the issue > > My laptop has an nvidia dgpu and an amd igpg. To build with cuda and migraphx I had to edit onnxruntime/python/onnxruntime_pybind_state_common.cc to remove one of the two onnxruntime::ArenaExtendStrategy arena_extend_strategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo; > > ``` > #if defined(USE_CUDA) || defined(USE_CUDA_PROVIDER_INTERFACE) > // TODO remove deprecated global config > OrtCudnnConvAlgoSearch cudnn_conv_algo_search = OrtCudnnConvAlgoSearchExhaustive; > // TODO remove deprecated global config > bool do_copy_in_default_stream = true; > // TODO remove deprecated global config > onnxruntime::cuda::TunableOpInfo tunable_op{}; > onnxruntime::CUDAExecutionProviderExternalAllocatorInfo external_allocator_info{}; > // TODO remove deprecated global config > onnxruntime::ArenaExtendStrategy arena_extend_strategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo; > #endif > > #if defined(USE_MIGRAPHX) > // TODO remove deprecated global config > onnxruntime::ArenaExtendStrategy arena_extend_strategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo; > #endif > ``` > > I think it could be changed to > ``` > #if defined(USE_CUDA) || defined(USE_CUDA_PROVIDER_INTERFACE) > // TODO remove deprecated global config > OrtCudnnConvAlgoSearch cudnn_conv_algo_search = OrtCudnnConvAlgoSearchExhaustive; > // TODO remove deprecated global config > bool do_copy_in_default_stream = true; > // TODO remove deprecated global config > onnxruntime::cuda::TunableOpInfo tunable_op{}; > onnxruntime::CUDAExecutionProviderExternalAllocatorInfo external_allocator_info{}; > // TODO remove deprecated global config > #endif > > #if defined(USE_MIGRAPHX) || defined(USE_CUDA) || defined(USE_CUDA_PROVIDER_INTERFACE) > // TODO remove deprecated global config > onnxruntime::ArenaExtendStrategy arena_extend_strategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo; > #endif > ``` > > ### Urgency > > _No response_ > > ### Target platform > > AMD + Nvidia setups > > ### Build script > > ./build.sh --config Release --build_shared_lib --build_wheel --parallel 12 --skip_tests --use_cuda --cuda_home /opt/cuda --cudnn_home /opt/cuda --use_tensorrt --tensorrt_home /usr --use_openvino CPU --use_migraphx --migraphx_home /opt/rocm --cmake_extra_defines CMAKE_CXX_FLAGS="-Wno-maybe-uninitialized -Wno-free-nonheap-object" CMAKE_CUDA_ARCHITECTURES="120" > > ### Error / output > > /home/someone/onnxruntime-3.13/onnxruntime/onnxruntime/python/onnxruntime_pybind_state_common.cc:36:34: error: redefinition of ‘onnxruntime::ArenaExtendStrategy onnxruntime::python::arena_extend_strategy’ > 36 | onnxruntime::ArenaExtendStrategy arena_extend_strategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo; > | ^~~~~~~~~~~~~~~~~~~~~ > /home/someone/onnxruntime-3.13/onnxruntime/onnxruntime/python/onnxruntime_pybind_state_common.cc:31:34: note: ‘onnxruntime::ArenaExtendStrategy onnxruntime::python::arena_extend_strategy’ previously defined here > 31 | onnxruntime::ArenaExtendStrategy arena_extend_strategy = onnxruntime::ArenaExtendStrategy::kNextPowerOfTwo; > | ^~~~~~~~~~~~~~~~~~~~~ > > ### Visual Studio Version > > na > > ### GCC / Compiler Version > > gcc version 15.2.1 20260209 (GCC)</issue_description> > > <agent_instructions>Please create a pull request, and check whether there are other places that enabling both cuda and migraphx might cause build errors.</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes microsoft/onnxruntime#27797 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Author
Parents
Loading