Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7c3d02a
Add groupnorm contrib operator
TedThemistokleous Feb 13, 2025
3836f43
Add support for NhwcConv Contrib Operator
TedThemistokleous Feb 10, 2025
a5ce8dc
Gate fp8e5m2fnuz_type to ROCm 6.4 builds
TedThemistokleous Feb 10, 2025
1f43e34
inline
apwojcik Feb 5, 2025
ebb5583
check symbol (#84)
apwojcik Feb 13, 2025
8e1ce14
Rename HIPPinnedAllocator to MIGraphXPinnedAllocator (#83)
apwojcik Feb 4, 2025
cd24224
Fix build error CK_BUFFER_RESOURCE_3RD_DWORD (#97)
jagadish-amd Feb 21, 2025
867e216
Add Attention and SkipLayerNormalization Contrib op support
Mar 7, 2025
e04609f
Align path for fused_ops cpp extension to resolve discrapency between…
amd-mipantic Apr 22, 2025
da8e778
Update patch for gfx 1151 targets
TedThemistokleous May 7, 2025
526d27a
Move provider option names to header file (#86)
apwojcik Feb 13, 2025
8150cce
Rename HIPPinnedAllocator to MIGraphXPinnedAllocator (#83)
apwojcik Feb 4, 2025
a908755
Support for saving and loading mxr files in MGX EP (#105)
TedThemistokleous Jul 9, 2025
6fe613e
Fix pybind input for calibration table loading
TedThemistokleous Apr 12, 2025
9202f06
Adding hash input names and shapes to get unique graphx hash (#112)
urpetkov-amd Apr 17, 2025
1a63b95
Add null check for unique graphx hash (#121)
pnikolic-amd May 23, 2025
10e5eec
Align path for fused_ops cpp extension to resolve discrapency between…
amd-mipantic Apr 22, 2025
8fca486
Add in BF16 datatype and quantization support to MIGraphX EP (#117)
TedThemistokleous Jun 3, 2025
dbbd483
ROCm: add python arg to pass DCMAKE_HIP_ARCHITECTURES
jagadish-amd Mar 4, 2025
9d930a2
Use SHARED lib not MODULE for MIGraphX EP (#134)
apwojcik Jul 8, 2025
af57264
Correct tidy warnings on MIGraphXAllocator (#134)
TedThemistokleous Jul 9, 2025
02ff9cc
Change from 'bool' to 'int' for C interface (#143)
apwojcik Jul 9, 2025
b1f603f
Changing ifdef order for MGX and Dml
Jul 8, 2025
72fe23b
Default submission to compute Q
hisham-hchowdhu Sep 7, 2024
5adc480
Clang Tidy suggestions for the MIGraphX execution provider classes (#…
apwojcik Jul 9, 2025
17308b9
Simlify MIGraphX EP CMake (#146)
apwojcik Jul 9, 2025
9a5ad86
Changing ifdef order for MGX and Dml
Jul 8, 2025
e24ac6c
Change to OrtDevice::DeviceId (#147)
apwojcik Jul 9, 2025
57e0a0c
Lintrunner pass applied to patches
Jul 9, 2025
dbb89fb
Use #ifdef instead of #if (#149)
apwojcik Jul 10, 2025
0ed6013
use MIGraphX ONNXRT DLL location to search for MIGX and HIP DLLs (#150)
apwojcik Jul 10, 2025
8c91aeb
change to INFO to reduce logs produced by default (#151)
apwojcik Jul 10, 2025
071ca51
Implement Clang-Tidy suggestions for MIGraphX provider factory (#148)
apwojcik Jul 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ include(CheckLanguage)
include(CMakeDependentOption)
include(FetchContent)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(GNUInstallDirs) # onnxruntime_providers_* require CMAKE_INSTALL_* variables

# TODO: update this once all system adapt c++20
Expand Down
5 changes: 3 additions & 2 deletions cmake/external/composable_kernel.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
set(PATCH_CLANG ${PROJECT_SOURCE_DIR}/patches/composable_kernel/Fix_Clang_Build.patch)
set(PATCH_GFX12X ${PROJECT_SOURCE_DIR}/patches/composable_kernel/Add_gfx12x_support.patch)
set(PATCH_GFX950 ${PROJECT_SOURCE_DIR}/patches/composable_kernel/Add_gfx950.patch)

include(FetchContent)
onnxruntime_fetchcontent_declare(composable_kernel
URL ${DEP_URL_composable_kernel}
URL_HASH SHA1=${DEP_SHA1_composable_kernel}
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PATCH_CLANG} &&
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PATCH_GFX12X}
EXCLUDE_FROM_ALL
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PATCH_GFX12X} &&
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PATCH_GFX950}
)

FetchContent_GetProperties(composable_kernel)
Expand Down
59 changes: 25 additions & 34 deletions cmake/onnxruntime_providers_migraphx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@
# Licensed under the MIT License.

add_definitions(-DUSE_MIGRAPHX=1)
set(BUILD_LIBRARY_ONLY 1)
add_definitions("-DONNX_ML=1")
add_definitions("-DONNX_NAMESPACE=onnx")
include_directories(${protobuf_SOURCE_DIR} ${eigen_SOURCE_DIR})
set(MIGRAPHX_ROOT ${onnxruntime_MIGRAPHX_HOME})
include_directories(${onnx_SOURCE_DIR})
include_directories(${protobuf_SOURCE_DIR} ${eigen_SOURCE_DIR} ${onnx_SOURCE_DIR})
set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
if ( CMAKE_COMPILER_IS_GNUCC )
if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-missing-field-initializers")
endif()
set(CXX_VERSION_DEFINED TRUE)
set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS})
if ( CMAKE_COMPILER_IS_GNUCC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
endif()

# Add search paths for default rocm installation
list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hcc /opt/rocm/hip /opt/rocm $ENV{HIP_PATH})
Expand All @@ -33,26 +23,24 @@
find_package(hip REQUIRED)
find_package(migraphx REQUIRED PATHS ${AMD_MIGRAPHX_HOME})

set(migraphx_libs migraphx::c hip::host)

file(GLOB_RECURSE onnxruntime_providers_migraphx_cc_srcs CONFIGURE_DEPENDS
"${ONNXRUNTIME_ROOT}/core/providers/migraphx/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/migraphx/*.cc"
"${ONNXRUNTIME_ROOT}/core/providers/shared_library/*.h"
"${ONNXRUNTIME_ROOT}/core/providers/shared_library/*.cc"
)
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_migraphx_cc_srcs})
onnxruntime_add_shared_library_module(onnxruntime_providers_migraphx ${onnxruntime_providers_migraphx_cc_srcs})
onnxruntime_add_shared_library(onnxruntime_providers_migraphx ${onnxruntime_providers_migraphx_cc_srcs})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change it from onnxruntime_add_shared_library_module to onnxruntime_add_shared_library ? A Module Library is a plugin that may not be linked by other targets, but may be dynamically loaded at runtime using dlopen-like functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed due to development for our windows side run. Is there one way or the other preferred here? let me know so I can flow this back to the ROCm internal branch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should not be made, since nobody would link to this library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a use case which does link to this. Hence why this was added and integrated back on the ROCm side. Let me know whats the optimal way to handle this. Looks like I'll need to handle the integration work on this. Appreciate your comments sand insights btw @snnn

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then where are the header files of this library? I need to know more background.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, different link type results different construction/destruction order for global vars, which is common source of crashes. It's not just a build type thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree with you. Unfortunately this was pushed from windows side changes since the original interface was changed. Seems like a better solution is to keep the old flags then (save/load) and add the newer one (model cache) so that we don't break abi compatibility then and just extend it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed to onnxruntime_add_shared_library because onnxruntime_add_shared_library_module puts the provider DLL in lib directory when installing with cmake --install ..., and we need the DLL in bin directory, and onnxruntime_add_shared_library does precisely that. The side effects are the header and interface library installed alongside.

onnxruntime_add_include_to_target(onnxruntime_providers_migraphx onnxruntime_common onnx flatbuffers::flatbuffers Boost::mp11 safeint_interface)
add_dependencies(onnxruntime_providers_migraphx onnxruntime_providers_shared ${onnxruntime_EXTERNAL_DEPENDENCIES})
target_link_libraries(onnxruntime_providers_migraphx PRIVATE ${migraphx_libs} ${ONNXRUNTIME_PROVIDERS_SHARED} onnx flatbuffers::flatbuffers Boost::mp11 safeint_interface)
target_include_directories(onnxruntime_providers_migraphx PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/onnxruntime)
add_dependencies(onnxruntime_providers_migraphx ${onnxruntime_EXTERNAL_DEPENDENCIES})
target_link_libraries(onnxruntime_providers_migraphx PRIVATE migraphx::c hip::host ${ONNXRUNTIME_PROVIDERS_SHARED} onnx flatbuffers::flatbuffers Boost::mp11 safeint_interface)
target_include_directories(onnxruntime_providers_migraphx PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/migraphx/onnxruntime)
set_target_properties(onnxruntime_providers_migraphx PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(onnxruntime_providers_migraphx PROPERTIES FOLDER "ONNXRuntime")
target_compile_definitions(onnxruntime_providers_migraphx PRIVATE ONNXIFI_BUILD_LIBRARY=1)
if(MSVC)
target_compile_definitions(onnxruntime_providers_migraphx PRIVATE ONNXIFI_BUILD_LIBRARY=1 ONNX_ML=1 ONNX_NAMESPACE=onnx)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_property(TARGET onnxruntime_providers_migraphx APPEND_STRING PROPERTY LINK_FLAGS /DEF:${ONNXRUNTIME_ROOT}/core/providers/migraphx/symbols.def)
target_link_libraries(onnxruntime_providers_migraphx PRIVATE ws2_32)
target_link_libraries(onnxruntime_providers_migraphx PRIVATE ws2_32 shlwapi)
else()
target_compile_options(onnxruntime_providers_migraphx PRIVATE -Wno-error=sign-compare)
set_property(TARGET onnxruntime_providers_migraphx APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations")
Expand All @@ -62,6 +50,15 @@
target_link_libraries(onnxruntime_providers_migraphx PRIVATE stdc++fs)
endif()

set(CMAKE_REQUIRED_LIBRARIES migraphx::c)

check_symbol_exists(migraphx_onnx_options_set_external_data_path
"migraphx/migraphx.h" HAVE_MIGRAPHX_API_ONNX_OPTIONS_SET_EXTERNAL_DATA_PATH)

if(HAVE_MIGRAPHX_API_ONNX_OPTIONS_SET_EXTERNAL_DATA_PATH)
target_compile_definitions(onnxruntime_providers_migraphx PRIVATE HAVE_MIGRAPHX_API_ONNX_OPTIONS_SET_EXTERNAL_DATA_PATH=1)
endif()

if (onnxruntime_ENABLE_TRAINING_OPS)
onnxruntime_add_include_to_target(onnxruntime_providers_migraphx onnxruntime_training)
target_link_libraries(onnxruntime_providers_migraphx PRIVATE onnxruntime_training)
Expand All @@ -70,16 +67,10 @@
endif()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
install(TARGETS onnxruntime_providers_migraphx
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
else()
install(TARGETS onnxruntime_providers_migraphx
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
install(TARGETS onnxruntime_providers_migraphx
EXPORT onnxruntime_providers_migraphxTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}
)
4 changes: 0 additions & 4 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,6 @@ endif()

if(onnxruntime_USE_MIGRAPHX)
list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_migraphx)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_migraphx onnxruntime_providers_shared)
endif()

if(onnxruntime_USE_COREML)
Expand Down Expand Up @@ -691,9 +690,6 @@ endif()

if(onnxruntime_USE_MIGRAPHX)
list(APPEND onnxruntime_test_framework_src_patterns ${TEST_SRC_DIR}/providers/migraphx/*)
list(APPEND onnxruntime_test_framework_src_patterns "${ONNXRUNTIME_ROOT}/core/providers/migraphx/migraphx_execution_provider_utils.h")
list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_migraphx)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_migraphx onnxruntime_providers_shared)
endif()

if(onnxruntime_USE_NNAPI_BUILTIN)
Expand Down
6 changes: 4 additions & 2 deletions cmake/patches/composable_kernel/Add_gfx12x_support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ index bc326c8b5..db5ad5052 100644
@@ -127,8 +127,10 @@ else()
rocm_check_target_ids(DEFAULT_GPU_TARGETS TARGETS "gfx1030")
elseif(GPU_ARCH MATCHES "gfx11")
rocm_check_target_ids(DEFAULT_GPU_TARGETS TARGETS "gfx1100;gfx1101;gfx1102")
- rocm_check_target_ids(DEFAULT_GPU_TARGETS TARGETS "gfx1100;gfx1101;gfx1102")
+ rocm_check_target_ids(DEFAULT_GPU_TARGETS TARGETS "gfx1100;gfx1101;gfx1102;gfx1151")
+ elseif(GPU_ARCH MATCHES "gfx12")
+ rocm_check_target_ids(DEFAULT_GPU_TARGETS TARGETS "gfx1200;gfx1201")
else()
Expand Down Expand Up @@ -259,7 +260,8 @@ index 55f562061..69a7abf62 100644
--- a/include/ck/ck.hpp
+++ b/include/ck/ck.hpp
@@ -69,6 +69,9 @@ CK_DECLARE_ENV_VAR_BOOL(CK_LOGGING)
#if defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1103__)
- #if defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1103__)
+ #if defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1103__) || defined(__gfx1151__)
#define __gfx11__
#endif
+#if defined(__gfx1200__) || defined(__gfx1201__)
Expand Down
14 changes: 14 additions & 0 deletions cmake/patches/composable_kernel/Add_gfx950.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/include/ck/ck.hpp b/include/ck/ck.hpp
index 55f562061..ee340eba1 100644
--- a/include/ck/ck.hpp
+++ b/include/ck/ck.hpp
@@ -53,7 +53,7 @@ CK_DECLARE_ENV_VAR_BOOL(CK_LOGGING)

// define general macros for various architectures
#if defined(__gfx908__) || defined(__gfx90a__) || defined(__gfx940__) || defined(__gfx941__) || \
- defined(__gfx942__)
+ defined(__gfx942__) || defined(__gfx950__)
#define __gfx9__
#endif
#if defined(__gfx940__) || defined(__gfx941__) || defined(__gfx942__)

10 changes: 4 additions & 6 deletions include/onnxruntime/core/session/onnxruntime_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,15 +711,13 @@ typedef struct OrtTensorRTProviderOptions {
typedef struct OrtMIGraphXProviderOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. ONNX Runtime maintains ABI backwards compatibility. Certainly, this change breaks that. As it will only impact the MIGraphX EP, I could accept this change. So, ORT's ABI backwards compatibility promise becomes if ORT provides ABI backwards compatibility if you don't use the functions that are not backwards compatible. (A little bit funny)

The correct way of doing this is to move the whole data structure out of this header file and make it opaque(invisible), and use getters/setters to access the fields.

https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was added in an earlier commit and I assume moving forward anyone using OnnxRT will be using the latest release supported with their ROCm install since we have a mapping in the docs.

https://onnxruntime.ai/docs/execution-providers/MIGraphX-ExecutionProvider.html#requirements

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is part of ORT's public API that everyone uses, no matter if MIGRAPHX EP is used or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pad this instead if this is a concern then? We're already using this internally for our builds and release, adding two padding vars should keep things consistent since we're missing a char* and int no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it better to have these items but tie them to nothing in the EP then and have a /*depricated */ comment for sunset flags.?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Padding is also a breaking change. Because clients built with older ORT versions will end-up with garbage data for the new fields. Please try to minimize the number of changes of this struct. Going forward you should move it to an opaque type like what CUDA EP did.

int device_id; // hip device id.
int migraphx_fp16_enable; // MIGraphX FP16 precision. Default 0 = false, nonzero = true
int migraphx_bf16_enable; // MIGraphX BF16 precision. Default 0 = false, nonzero = true
int migraphx_fp8_enable; // MIGraphX FP8 precision. Default 0 = false, nonzero = true
int migraphx_int8_enable; // MIGraphX INT8 precision. Default 0 = false, nonzero = true
int migraphx_use_native_calibration_table; // MIGraphx INT8 cal table. Default 0 = false, noznero = true
int migraphx_use_native_calibration_table; // MIGraphx INT8 cal table. Default 0 = false, nonzero = true
const char* migraphx_int8_calibration_table_name; // MIGraphx INT8 calibration table name
int migraphx_save_compiled_model; // migraphx save compiled model. Default 0 = false, noznero = true
const char* migraphx_save_model_path; // migraphx model path name
int migraphx_load_compiled_model; // migraphx int8 cal table. Default 0 = false, noznero = true
const char* migraphx_load_model_path; // migraphx model path name
bool migraphx_exhaustive_tune; // migraphx tuned compile Default = false
const char* migraphx_cache_dir; // MIGraphX model cache directory
int migraphx_exhaustive_tune; // MIGraphX tuned compile. Default = false, nonzero = true

/** \brief MIGraphX memory limit (To use all possible memory pass in maximum size_t)
* Defaults to SIZE_MAX.
Expand Down
5 changes: 4 additions & 1 deletion onnxruntime/core/providers/dml/dml_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,10 @@ static D3D12_COMMAND_LIST_TYPE CalculateCommandListType(ID3D12Device* d3d12_devi
sizeof(feature_levels)
));

auto use_compute_command_list = (feature_levels.MaxSupportedFeatureLevel <= D3D_FEATURE_LEVEL_1_0_CORE);
// Use compute queue whenever possible on supported hardware to avoid TDR and maintain UI QoS
// Core and generic devices only have compute queues, DX11 has "immediate" submission, DX12 has both
auto use_compute_command_list = (feature_levels.MaxSupportedFeatureLevel <= D3D_FEATURE_LEVEL_1_0_CORE) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it relate to MIGRAPHX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a bunch of changes that are being integrated on the ROCm side for our EPs we maintain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who made this change? Was someone from AMD or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From AMD

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to split this change to a separate PR? I need to find someone from the directml team to review this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can pull this one out. I'm getting back to the other devs responsible for these to make sure these are up to standard to merge back upstream

(feature_levels.MaxSupportedFeatureLevel >= D3D_FEATURE_LEVEL_12_0);

if (use_compute_command_list)
{
Expand Down
26 changes: 13 additions & 13 deletions onnxruntime/core/providers/migraphx/migraphx_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ void MIGraphXAllocator::CheckDevice() const {
#endif
}

void* MIGraphXAllocator::Alloc(size_t size) {
void* MIGraphXAllocator::Alloc(const size_t size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to add const here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ran this through clang-tidy

Copy link
Contributor

@snnn snnn Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our clang-tidy configs need to be improve. Our coding style is inherited from Google's coding style See https://github.com/microsoft/onnxruntime/blob/main/docs/Coding_Conventions_and_Standards.md. The document is the golden standard.

CheckDevice();
void* p = nullptr;
if (size > 0) {
HIP_CALL_THROW(hipMalloc((void**)&p, size));
HIP_CALL_THROW(hipMalloc(&p, size));
}
return p;
}
Expand All @@ -37,7 +37,7 @@ void MIGraphXAllocator::Free(void* p) {
(void)hipFree(p); // do not throw error since it's OK for hipFree to fail during shutdown
}

void* MIGraphXExternalAllocator::Alloc(size_t size) {
void* MIGraphXExternalAllocator::Alloc(const size_t size) {
void* p = nullptr;
if (size > 0) {
p = alloc_(size);
Expand All @@ -51,27 +51,27 @@ void* MIGraphXExternalAllocator::Alloc(size_t size) {

void MIGraphXExternalAllocator::Free(void* p) {
free_(p);
std::lock_guard<std::mutex> lock(lock_);
auto it = reserved_.find(p);
if (it != reserved_.end()) {
std::lock_guard lock(lock_);
if (const auto it = reserved_.find(p); it != reserved_.end()) {
reserved_.erase(it);
if (empty_cache_) empty_cache_();
}
}

void* MIGraphXExternalAllocator::Reserve(size_t size) {
void* MIGraphXExternalAllocator::Reserve(const size_t size) {
void* p = Alloc(size);
if (!p) return nullptr;
std::lock_guard<std::mutex> lock(lock_);
ORT_ENFORCE(reserved_.find(p) == reserved_.end());
reserved_.insert(p);
if (p != nullptr) {
std::lock_guard lock(lock_);
ORT_ENFORCE(reserved_.find(p) == reserved_.end());
reserved_.insert(p);
}
return p;
}

void* MIGraphXPinnedAllocator::Alloc(size_t size) {
void* MIGraphXPinnedAllocator::Alloc(const size_t size) {
void* p = nullptr;
if (size > 0) {
HIP_CALL_THROW(hipHostMalloc((void**)&p, size));
HIP_CALL_THROW(hipHostMalloc(&p, size));
}
return p;
}
Expand Down
16 changes: 8 additions & 8 deletions onnxruntime/core/providers/migraphx/migraphx_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ namespace onnxruntime {

class MIGraphXAllocator : public IAllocator {
public:
MIGraphXAllocator(int device_id, const char* name)
MIGraphXAllocator(const OrtDevice::DeviceId device_id, const char* name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your linter and tidy said otherwise. These were ran through clang-tidy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I think we do not have good clang-tidy config here.

: IAllocator(
OrtMemoryInfo(name, OrtAllocatorType::OrtDeviceAllocator,
OrtDevice(OrtDevice::GPU, OrtDevice::MemType::DEFAULT, OrtDevice::VendorIds::AMD,
static_cast<OrtDevice::DeviceId>(device_id)),
device_id),
OrtMemTypeDefault)) {}

virtual void* Alloc(size_t size) override;
virtual void Free(void* p) override;
void* Alloc(size_t size) override;
void Free(void* p) override;

private:
void CheckDevice() const;
};

class MIGraphXExternalAllocator : public MIGraphXAllocator {
class MIGraphXExternalAllocator final : public MIGraphXAllocator {
typedef void* (*ExternalAlloc)(size_t size);
typedef void (*ExternalFree)(void* p);
typedef void (*ExternalEmptyCache)();

public:
MIGraphXExternalAllocator(OrtDevice::DeviceId device_id, const char* name, void* alloc, void* free, void* empty_cache)
MIGraphXExternalAllocator(const OrtDevice::DeviceId device_id, const char* name, void* alloc, void* free, void* empty_cache)
: MIGraphXAllocator(device_id, name) {
alloc_ = reinterpret_cast<ExternalAlloc>(alloc);
free_ = reinterpret_cast<ExternalFree>(free);
Expand All @@ -52,11 +52,11 @@ class MIGraphXExternalAllocator : public MIGraphXAllocator {

class MIGraphXPinnedAllocator final : public IAllocator {
public:
MIGraphXPinnedAllocator(const int device_id, const char* name)
MIGraphXPinnedAllocator(const OrtDevice::DeviceId device_id, const char* name)
: IAllocator(
OrtMemoryInfo(name, OrtDeviceAllocator,
OrtDevice(OrtDevice::GPU, OrtDevice::MemType::HOST_ACCESSIBLE, OrtDevice::VendorIds::AMD,
static_cast<OrtDevice::DeviceId>(device_id)),
device_id),
OrtMemTypeCPUOutput)) {}

void* Alloc(size_t size) override;
Expand Down
Loading
Loading