Skip to content

Keep the legacy MIGraphX provider mapped on Linux - #253

Draft
varyagnord wants to merge 1 commit into
ROCm:gpuep-releases/gpuep-rel-2611-legacy-epfrom
varyagnord:fix/migraphx-provider-unload
Draft

varyagnord wants to merge 1 commit into
ROCm:gpuep-releases/gpuep-rel-2611-legacy-epfrom
varyagnord:fix/migraphx-provider-unload

Conversation

@varyagnord

@varyagnord varyagnord commented Nov 22, 2026 •

Copy link
Copy Markdown

Description

Keep the built-in MIGraphX provider shared library mapped on Linux after ONNX Runtime shuts down its execution provider. This uses the provider bridge's existing unload=false behavior, as used by CUDA and CANN. Provider shutdown and session destruction still run. Windows and separately registered plugin EPs are outside this change.

Motivation and context

With the built-in shared MIGraphX EP, a small Conv + Relu model completes successfully and its session and environment are destroyed in the expected order. The process then receives SIGSEGV. The loader trace shows that libmigraphx.so.2015000 was unmapped. The exit backtrace enters the cleanup of MIGraphX's process-static dynamic target loader vector after that unload.

Keeping a reference to the EP shared library prevents the loader from unmapping the dependency while exit callbacks can still execute. Preserving the mapping increases the memory retained after the last environment is destroyed. The library is still loaded lazily on first use.

The target branch is the ROCm legacy GPU EP release. The failing configuration was Fedora's ONNX Runtime 1.26.0 shared MIGraphX build with ROCm 7.2.2 / MIGraphX 2.15.0 on Radeon 890M (gfx1150).

Verification

Standalone Conv + Relu Output Process status
Default provider unload All 36 values equal to 2.25 139 (SIGSEGV after session and environment teardown)
Hold a loader reference to the same shared provider through process exit All 36 values equal to 2.25 0

The second test uses Linux dlopen(..., RTLD_NOLOAD) to validate the library-lifetime change against the same Fedora binary. It is a behavioral A/B test; it does not represent a full build of the target ROCm release branch. A separate downstream test held just the MIGraphX dependency mapped and also exited successfully. The original failure needs no OBS process or segmentation model.

Standalone reproducer

Generate a small model with the Python onnx package:

from onnx import TensorProto as T, helper as h, save

x = h.make_tensor_value_info("input", T.FLOAT, [1, 1, 8, 8])
y = h.make_tensor_value_info("output", T.FLOAT, [1, 1, 6, 6])
w = h.make_tensor("weights", T.FLOAT, [1, 1, 3, 3], [0.25] * 9)
nodes = [h.make_node("Conv", ["input", "weights"], ["conv"]),
         h.make_node("Relu", ["conv"], ["output"])]
model = h.make_model(h.make_graph(nodes, "conv-relu", [x], [y], [w]),
                     ir_version=9, opset_imports=[h.make_opsetid("", 18)])
save(model, "mini.onnx")

Save the following as reproduce.cpp:

#include <onnxruntime_cxx_api.h>

#include <algorithm>
#include <array>
#include <dlfcn.h>
#include <iostream>
#include <stdexcept>
#include <string_view>

void run(const char* model, const char* keep_provider)
{
  Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "migraphx-unload");
  Ort::SessionOptions options;
  options.SetIntraOpNumThreads(1);
  Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_MIGraphX(options, 0));
  Ort::Session session(env, model, options);

  if (keep_provider) {
    // Preserve one reference to ORT's already-loaded provider until process exit.
    if (!dlopen(keep_provider, RTLD_NOW | RTLD_NOLOAD)) {
      throw std::runtime_error(dlerror());
    }
  }

  constexpr std::array<int64_t, 4> shape = {1, 1, 8, 8};
  std::array<float, 64> data;
  data.fill(1.0f);
  auto memory = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
  auto input = Ort::Value::CreateTensor<float>(memory, data.data(), data.size(), shape.data(), shape.size());
  const char* input_names[] = {"input"};
  const char* output_names[] = {"output"};
  auto outputs = session.Run(Ort::RunOptions{nullptr}, input_names, &input, 1, output_names, 1);
  const float* values = outputs.front().GetTensorData<float>();
  if (outputs.front().GetTensorTypeAndShapeInfo().GetElementCount() != 36 ||
      !std::all_of(values, values + 36, [](float value) { return value == 2.25f; })) {
    throw std::runtime_error("Unexpected Conv + Relu output");
  }
  std::cerr << "Inference passed (36 values equal to 2.25)\n";
}

int main(int argc, char** argv)
{
  if (argc != 2 && argc != 3) return 2;
  run(argv[1], argc == 3 ? argv[2] : nullptr);
  std::cerr << "Session and environment destroyed\n";
}

Build against an ONNX Runtime distribution with the legacy shared MIGraphX EP:

c++ -std=c++17 -I"$ORT_INCLUDE" reproduce.cpp -L"$ORT_LIB" \
    -Wl,-rpath,"$ORT_LIB" -lonnxruntime -ldl -o reproduce
./reproduce mini.onnx
./reproduce mini.onnx "$ORT_LIB/libonnxruntime_providers_migraphx.so"

Prepared with OpenAI Codex assistance.

Preserve the shared library mapping through process exit so MIGraphX callbacks can complete after the ONNX Runtime environment has shut down. Keep provider shutdown and lazy loading in place.

Verified the lifetime behavior with a standalone Conv + Relu model on Fedora ONNX Runtime 1.26.0 and Radeon gfx1150. Both runs returned the correct tensor. The default unload exited 139 and holding a loader reference exited 0.

Assisted-by: OpenAI Codex
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.

1 participant