Skip to content

Fix build failure when both CUDA and MiGraphX execution providers are enabled#27798

Merged
tianleiwu merged 2 commits intomainfrom
copilot/fix-cuda-migraphx-build-issue
Apr 7, 2026
Merged

Fix build failure when both CUDA and MiGraphX execution providers are enabled#27798
tianleiwu merged 2 commits intomainfrom
copilot/fix-cuda-migraphx-build-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 21, 2026

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:

#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.

Original prompt

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)


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…h CUDA and MiGraphX

Move arena_extend_strategy variable definition and extern declaration from
separate CUDA-only and MiGraphX-only preprocessor blocks into a combined
block: #if defined(USE_MIGRAPHX) || defined(USE_CUDA) || defined(USE_CUDA_PROVIDER_INTERFACE)

This fixes a redefinition error when building with both --use_cuda and
--use_migraphx enabled.

Fixes #25193

Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/onnxruntime/sessions/6edbd6b9-8180-470c-baa7-1c7947f7803a
Copilot AI changed the title [WIP] Fix build issue with cuda and migraphx Fix build failure when both CUDA and MiGraphX execution providers are enabled Mar 21, 2026
Copilot AI requested a review from tianleiwu March 21, 2026 16:57
@tianleiwu
Copy link
Copy Markdown
Contributor

/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Windows ARM64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline

@tianleiwu tianleiwu marked this pull request as ready for review March 21, 2026 17:49
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@tianleiwu tianleiwu merged commit 8941f8c into main Apr 7, 2026
91 checks passed
@tianleiwu tianleiwu deleted the copilot/fix-cuda-migraphx-build-issue branch April 7, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Build] Cannot build with cuda and migraphx

3 participants