From 7cbe5cee7ea5d8026698e9626be565252594145c Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Tue, 30 Sep 2025 17:47:03 -0400 Subject: [PATCH 1/6] Breakout get onnx op list in MIGraphX API --- src/api/api.cpp | 2 ++ tools/api/api.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/api/api.cpp b/src/api/api.cpp index 30d27a11e22..54f063aca7f 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -396,6 +396,8 @@ static void register_custom_op(const CustomOp& op) static migraphx::context get_context(const program& p) { return p.get_context(); } +static std::vector get_supported_onnx_operators() { return get_onnx_operators(); } + } // namespace migraphx template > diff --git a/tools/api/api.cpp b/tools/api/api.cpp index 07165236d28..7f07c9d4c47 100644 --- a/tools/api/api.cpp +++ b/tools/api/api.cpp @@ -396,6 +396,8 @@ static void register_custom_op(const CustomOp& op) static migraphx::context get_context(const program& p) { return p.get_context(); } +static std::vector get_supported_onnx_operators() { return get_onnx_operators(); } + } // namespace migraphx <% generate_c_api_body() %> From 0b33dbf1a12390e48d4ec8f8078a5161945e1949 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Tue, 30 Sep 2025 23:05:48 -0400 Subject: [PATCH 2/6] Initial changes to API to get onnx names out --- src/api/api.cpp | 42 +++++++++++++++++++++++++++ src/api/include/migraphx/migraphx.h | 14 +++++++++ src/api/include/migraphx/migraphx.hpp | 14 +++++++++ src/api/migraphx.py | 5 ++++ src/py/migraphx_py.cpp | 1 + tools/api/api.cpp | 5 ++++ 6 files changed, 81 insertions(+) diff --git a/src/api/api.cpp b/src/api/api.cpp index 54f063aca7f..09c6766532a 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -289,6 +289,11 @@ static void quantize_fp8_wrap(program& prog, const target& t, quantize_fp8_optio migraphx::quantize_fp8(prog, t, options.calibration); } +static std::vector get_supported_onnx_operators() +{ + return migraphx::get_onnx_operators(); +} + #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-nonliteral" @@ -733,6 +738,17 @@ struct migraphx_quantize_fp8_options migraphx::quantize_fp8_options object; }; +extern "C" struct migraphx_get_supported_onnx_operators; +struct migraphx_get_supported_onnx_operators +{ + template + migraphx_get_supported_onnx_operators(Ts&&... xs) + : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) + { + } + migraphx::get_supported_onnx_operators object; +}; + extern "C" struct migraphx_context; struct migraphx_context { @@ -2418,6 +2434,32 @@ extern "C" migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, return api_error_result; } +extern "C" migraphx_status migraphx_get_supported_onnx_operators_destroy( + migraphx_get_supported_onnx_operators_t get_supported_onnx_operators) +{ + auto api_error_result = migraphx::try_([&] { destroy((get_supported_onnx_operators)); }); + return api_error_result; +} + +extern "C" migraphx_status +migraphx_get_supported_onnx_operators_assign_to(migraphx_get_supported_onnx_operators_t output, + const_migraphx_get_supported_onnx_operators_t input) +{ + auto api_error_result = migraphx::try_([&] { *output = *input; }); + return api_error_result; +} + +extern "C" migraphx_status migraphx_get_supported_onnx_operators_create( + migraphx_get_supported_onnx_operators_t* get_supported_onnx_operators) +{ + auto api_error_result = migraphx::try_([&] { + *get_supported_onnx_operators = object_cast( + allocate( + migraphx::get_supported_onnx_operators())); + }); + return api_error_result; +} + extern "C" migraphx_status migraphx_context_finish(const_migraphx_context_t context) { auto api_error_result = migraphx::try_([&] { diff --git a/src/api/include/migraphx/migraphx.h b/src/api/include/migraphx/migraphx.h index d1fb5ed316b..77aa869932b 100644 --- a/src/api/include/migraphx/migraphx.h +++ b/src/api/include/migraphx/migraphx.h @@ -145,6 +145,10 @@ typedef const struct migraphx_quantize_int8_options* const_migraphx_quantize_int typedef struct migraphx_quantize_fp8_options* migraphx_quantize_fp8_options_t; typedef const struct migraphx_quantize_fp8_options* const_migraphx_quantize_fp8_options_t; +typedef struct migraphx_get_supported_onnx_operators* migraphx_get_supported_onnx_operators_t; +typedef const struct migraphx_get_supported_onnx_operators* + const_migraphx_get_supported_onnx_operators_t; + typedef struct migraphx_context* migraphx_context_t; typedef const struct migraphx_context* const_migraphx_context_t; @@ -659,6 +663,16 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, migraphx_target_t target, migraphx_quantize_fp8_options_t options); +MIGRAPHX_C_EXPORT migraphx_status migraphx_get_supported_onnx_operators_destroy( + migraphx_get_supported_onnx_operators_t get_supported_onnx_operators); + +MIGRAPHX_C_EXPORT migraphx_status migraphx_get_supported_onnx_operators_assign_to( + migraphx_get_supported_onnx_operators_t output, + const_migraphx_get_supported_onnx_operators_t input); + +MIGRAPHX_C_EXPORT migraphx_status migraphx_get_supported_onnx_operators_create( + migraphx_get_supported_onnx_operators_t* get_supported_onnx_operators); + MIGRAPHX_C_EXPORT migraphx_status migraphx_context_finish(const_migraphx_context_t context); MIGRAPHX_C_EXPORT migraphx_status migraphx_context_get_queue(void** out, diff --git a/src/api/include/migraphx/migraphx.hpp b/src/api/include/migraphx/migraphx.hpp index 4fc2b202a95..7c36fd6cf50 100644 --- a/src/api/include/migraphx/migraphx.hpp +++ b/src/api/include/migraphx/migraphx.hpp @@ -1603,6 +1603,19 @@ quantize_fp8(const program& prog, const target& ptarget, const quantize_fp8_opti options.get_handle_ptr()); } +struct supported_onnx_ops_options : MIGRPAHX_HANDLE_BASE(supported_onnx_ops_options) +{ + supported_onnx_ops-options() {this->make_handle(&migraphx_supported_onnx_ops_options_create); } + + MIGRAPHX_HANDLE_CONSTRUCTOR(supported_onnx_op_options) +}; + +inline void get_supported_onnx_operators(supported_onnx_ops_options& options) +{ + call(&migraphx_get_onnx_operators, + options.get_handle_ptr()); +} + struct experimental_custom_op_base { experimental_custom_op_base() = default; @@ -1618,6 +1631,7 @@ struct experimental_custom_op_base virtual bool runs_on_offload_target() const = 0; }; + struct experimental_custom_op : interface_base { template diff --git a/src/api/migraphx.py b/src/api/migraphx.py index 13810b747d1..85a8414d839 100644 --- a/src/api/migraphx.py +++ b/src/api/migraphx.py @@ -510,6 +510,11 @@ def quantize_fp8_options(h): options='migraphx::quantize_fp8_options'), fname='migraphx::quantize_fp8_wrap') +@auto_handle() +def get_supported_onnx_operators(h): + h.constructor('create', + fname='migraphx::get_supported_onnx_operators') + @auto_handle(ref=True) def context(h): diff --git a/src/py/migraphx_py.cpp b/src/py/migraphx_py.cpp index 9739733ae23..7ac676222f3 100644 --- a/src/py/migraphx_py.cpp +++ b/src/py/migraphx_py.cpp @@ -621,6 +621,7 @@ MIGRAPHX_PYBIND11_MODULE(migraphx, m) py::arg("map_input_dims") = std::unordered_map>(), py::arg("output_names") = std::vector()); + m.def("get_supported_onnx_operators", []{return migraphx::get_onnx_operators();}); m.def( "parse_onnx", [](const std::string& filename, diff --git a/tools/api/api.cpp b/tools/api/api.cpp index 7f07c9d4c47..b42731c6cb1 100644 --- a/tools/api/api.cpp +++ b/tools/api/api.cpp @@ -289,6 +289,11 @@ static void quantize_fp8_wrap(program& prog, const target& t, quantize_fp8_optio migraphx::quantize_fp8(prog, t, options.calibration); } +static std::vector get_supported_onnx_operators() +{ + return migraphx::get_onnx_operators(); +} + #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-nonliteral" From 4b318f396c01fe699a5199005f2b6e1899c50e67 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Wed, 1 Oct 2025 09:53:46 -0400 Subject: [PATCH 3/6] Update Api --- src/api/api.cpp | 35 ++------------------------- src/api/include/migraphx/migraphx.h | 14 +---------- src/api/include/migraphx/migraphx.hpp | 2 +- src/api/migraphx.py | 8 +++--- tools/api/api.cpp | 2 -- 5 files changed, 8 insertions(+), 53 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 09c6766532a..83969651bda 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -401,8 +401,6 @@ static void register_custom_op(const CustomOp& op) static migraphx::context get_context(const program& p) { return p.get_context(); } -static std::vector get_supported_onnx_operators() { return get_onnx_operators(); } - } // namespace migraphx template > @@ -738,17 +736,6 @@ struct migraphx_quantize_fp8_options migraphx::quantize_fp8_options object; }; -extern "C" struct migraphx_get_supported_onnx_operators; -struct migraphx_get_supported_onnx_operators -{ - template - migraphx_get_supported_onnx_operators(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::get_supported_onnx_operators object; -}; - extern "C" struct migraphx_context; struct migraphx_context { @@ -2434,28 +2421,10 @@ extern "C" migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, return api_error_result; } -extern "C" migraphx_status migraphx_get_supported_onnx_operators_destroy( - migraphx_get_supported_onnx_operators_t get_supported_onnx_operators) -{ - auto api_error_result = migraphx::try_([&] { destroy((get_supported_onnx_operators)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_get_supported_onnx_operators_assign_to(migraphx_get_supported_onnx_operators_t output, - const_migraphx_get_supported_onnx_operators_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_get_supported_onnx_operators_create( - migraphx_get_supported_onnx_operators_t* get_supported_onnx_operators) +extern "C" migraphx_status get_supported_onnx_operators(migraphx_quantize_op_names_t* out) { auto api_error_result = migraphx::try_([&] { - *get_supported_onnx_operators = object_cast( - allocate( - migraphx::get_supported_onnx_operators())); + *out = allocate(migraphx::get_supported_onnx_operators()); }); return api_error_result; } diff --git a/src/api/include/migraphx/migraphx.h b/src/api/include/migraphx/migraphx.h index 77aa869932b..e31115d3a7c 100644 --- a/src/api/include/migraphx/migraphx.h +++ b/src/api/include/migraphx/migraphx.h @@ -145,10 +145,6 @@ typedef const struct migraphx_quantize_int8_options* const_migraphx_quantize_int typedef struct migraphx_quantize_fp8_options* migraphx_quantize_fp8_options_t; typedef const struct migraphx_quantize_fp8_options* const_migraphx_quantize_fp8_options_t; -typedef struct migraphx_get_supported_onnx_operators* migraphx_get_supported_onnx_operators_t; -typedef const struct migraphx_get_supported_onnx_operators* - const_migraphx_get_supported_onnx_operators_t; - typedef struct migraphx_context* migraphx_context_t; typedef const struct migraphx_context* const_migraphx_context_t; @@ -663,15 +659,7 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, migraphx_target_t target, migraphx_quantize_fp8_options_t options); -MIGRAPHX_C_EXPORT migraphx_status migraphx_get_supported_onnx_operators_destroy( - migraphx_get_supported_onnx_operators_t get_supported_onnx_operators); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_get_supported_onnx_operators_assign_to( - migraphx_get_supported_onnx_operators_t output, - const_migraphx_get_supported_onnx_operators_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_get_supported_onnx_operators_create( - migraphx_get_supported_onnx_operators_t* get_supported_onnx_operators); +MIGRAPHX_C_EXPORT migraphx_status get_supported_onnx_operators(migraphx_quantize_op_names_t* out); MIGRAPHX_C_EXPORT migraphx_status migraphx_context_finish(const_migraphx_context_t context); diff --git a/src/api/include/migraphx/migraphx.hpp b/src/api/include/migraphx/migraphx.hpp index 7c36fd6cf50..2f3e3b5b6cb 100644 --- a/src/api/include/migraphx/migraphx.hpp +++ b/src/api/include/migraphx/migraphx.hpp @@ -1612,7 +1612,7 @@ struct supported_onnx_ops_options : MIGRPAHX_HANDLE_BASE(supported_onnx_ops_opti inline void get_supported_onnx_operators(supported_onnx_ops_options& options) { - call(&migraphx_get_onnx_operators, + call(&migraphx_get_supported_onnx_operators, options.get_handle_ptr()); } diff --git a/src/api/migraphx.py b/src/api/migraphx.py index 85a8414d839..27b6d53dc6b 100644 --- a/src/api/migraphx.py +++ b/src/api/migraphx.py @@ -510,10 +510,10 @@ def quantize_fp8_options(h): options='migraphx::quantize_fp8_options'), fname='migraphx::quantize_fp8_wrap') -@auto_handle() -def get_supported_onnx_operators(h): - h.constructor('create', - fname='migraphx::get_supported_onnx_operators') +api.add_function('get_supported_onnx_operators', + fname='migraphx::get_supported_onnx_operators', + returns='std::vector') + @auto_handle(ref=True) diff --git a/tools/api/api.cpp b/tools/api/api.cpp index b42731c6cb1..d0b204f0449 100644 --- a/tools/api/api.cpp +++ b/tools/api/api.cpp @@ -401,8 +401,6 @@ static void register_custom_op(const CustomOp& op) static migraphx::context get_context(const program& p) { return p.get_context(); } -static std::vector get_supported_onnx_operators() { return get_onnx_operators(); } - } // namespace migraphx <% generate_c_api_body() %> From 853c379fa72d0f280932bed68c58b9f2b5e69fb2 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Wed, 1 Oct 2025 11:31:44 -0400 Subject: [PATCH 4/6] WIP need to sort outputs out for API call for vec output --- src/api/api.cpp | 7 +++++-- src/api/include/migraphx/migraphx.h | 2 +- src/api/include/migraphx/migraphx.hpp | 9 ++++++--- src/api/migraphx.py | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 83969651bda..bef71f60f46 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -2421,10 +2421,13 @@ extern "C" migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, return api_error_result; } -extern "C" migraphx_status get_supported_onnx_operators(migraphx_quantize_op_names_t* out) +extern "C" migraphx_status get_supported_onnx_operators(const char** out) { auto api_error_result = migraphx::try_([&] { - *out = allocate(migraphx::get_supported_onnx_operators()); + if(out == nullptr) + MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); + auto&& api_result = migraphx::get_supported_onnx_operators(); + std::copy(api_result.begin(), api_result.end(), out); }); return api_error_result; } diff --git a/src/api/include/migraphx/migraphx.h b/src/api/include/migraphx/migraphx.h index e31115d3a7c..e503ac1a8a3 100644 --- a/src/api/include/migraphx/migraphx.h +++ b/src/api/include/migraphx/migraphx.h @@ -659,7 +659,7 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, migraphx_target_t target, migraphx_quantize_fp8_options_t options); -MIGRAPHX_C_EXPORT migraphx_status get_supported_onnx_operators(migraphx_quantize_op_names_t* out); +MIGRAPHX_C_EXPORT migraphx_status get_supported_onnx_operators(const char** out); MIGRAPHX_C_EXPORT migraphx_status migraphx_context_finish(const_migraphx_context_t context); diff --git a/src/api/include/migraphx/migraphx.hpp b/src/api/include/migraphx/migraphx.hpp index 2f3e3b5b6cb..aee7664431b 100644 --- a/src/api/include/migraphx/migraphx.hpp +++ b/src/api/include/migraphx/migraphx.hpp @@ -1610,10 +1610,13 @@ struct supported_onnx_ops_options : MIGRPAHX_HANDLE_BASE(supported_onnx_ops_opti MIGRAPHX_HANDLE_CONSTRUCTOR(supported_onnx_op_options) }; -inline void get_supported_onnx_operators(supported_onnx_ops_options& options) +inline std::vector get_supported_onnx_operators(supported_onnx_ops_options& options) { + const char ** output; call(&migraphx_get_supported_onnx_operators, - options.get_handle_ptr()); + output); + + return std::vector(output) } struct experimental_custom_op_base @@ -1621,7 +1624,7 @@ struct experimental_custom_op_base experimental_custom_op_base() = default; experimental_custom_op_base(const experimental_custom_op_base&) = default; experimental_custom_op_base& operator=(const experimental_custom_op_base&) = default; - virtual ~experimental_custom_op_base() = default; + virtual ~experimental_custom_op_tDase() = default; virtual std::string name() const = 0; virtual argument compute(context ctx, shape output, arguments inputs) const = 0; diff --git a/src/api/migraphx.py b/src/api/migraphx.py index 27b6d53dc6b..53b0bc0e9c8 100644 --- a/src/api/migraphx.py +++ b/src/api/migraphx.py @@ -512,7 +512,7 @@ def quantize_fp8_options(h): api.add_function('get_supported_onnx_operators', fname='migraphx::get_supported_onnx_operators', - returns='std::vector') + returns='std::vector') From 2e4b4a0bcc6291cb7d882294d634a1896e349228 Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Mon, 6 Oct 2025 16:12:55 -0400 Subject: [PATCH 5/6] Update changes based on pair programmed output --- src/api/api.cpp | 22 ++++++++++------- src/api/include/migraphx/migraphx.h | 5 +++- src/api/include/migraphx/migraphx.hpp | 35 ++++++++++++--------------- src/api/migraphx.py | 11 ++++++--- src/include/migraphx/onnx.hpp | 2 +- src/onnx/onnx.cpp | 6 ++++- src/py/migraphx_py.cpp | 2 +- tools/api/api.cpp | 9 +++++-- 8 files changed, 55 insertions(+), 37 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index bef71f60f46..452cafd04a7 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -289,9 +289,11 @@ static void quantize_fp8_wrap(program& prog, const target& t, quantize_fp8_optio migraphx::quantize_fp8(prog, t, options.calibration); } -static std::vector get_supported_onnx_operators() +static size_t get_onnx_operators_size() { return migraphx::get_onnx_operators().size(); } + +static const char* get_onnx_operator_name_at_index(std::size_t index) { - return migraphx::get_onnx_operators(); + return get_onnx_operators().at(index).c_str(); } #ifdef __clang__ @@ -2421,14 +2423,16 @@ extern "C" migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, return api_error_result; } -extern "C" migraphx_status get_supported_onnx_operators(const char** out) +extern "C" migraphx_status migraphx_get_onnx_operator_name_at_index(const char** out, size_t index) { - auto api_error_result = migraphx::try_([&] { - if(out == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); - auto&& api_result = migraphx::get_supported_onnx_operators(); - std::copy(api_result.begin(), api_result.end(), out); - }); + auto api_error_result = + migraphx::try_([&] { *out = migraphx::get_onnx_operator_name_at_index((index)); }); + return api_error_result; +} + +extern "C" migraphx_status migraphx_get_onnx_operators_size(std::size_t* out) +{ + auto api_error_result = migraphx::try_([&] { *out = migraphx::get_onnx_operators_size(); }); return api_error_result; } diff --git a/src/api/include/migraphx/migraphx.h b/src/api/include/migraphx/migraphx.h index e503ac1a8a3..b2f74f7da3e 100644 --- a/src/api/include/migraphx/migraphx.h +++ b/src/api/include/migraphx/migraphx.h @@ -659,7 +659,10 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, migraphx_target_t target, migraphx_quantize_fp8_options_t options); -MIGRAPHX_C_EXPORT migraphx_status get_supported_onnx_operators(const char** out); +MIGRAPHX_C_EXPORT migraphx_status migraphx_get_onnx_operator_name_at_index(const char** out, + size_t index); + +MIGRAPHX_C_EXPORT migraphx_status migraphx_get_onnx_operators_size(std::size_t* out); MIGRAPHX_C_EXPORT migraphx_status migraphx_context_finish(const_migraphx_context_t context); diff --git a/src/api/include/migraphx/migraphx.hpp b/src/api/include/migraphx/migraphx.hpp index aee7664431b..d6a41040049 100644 --- a/src/api/include/migraphx/migraphx.hpp +++ b/src/api/include/migraphx/migraphx.hpp @@ -1460,7 +1460,7 @@ struct tf_options : MIGRAPHX_HANDLE_BASE(tf_options) }; /// Parse a tf file into a migraphx program -inline program parse_tf(const char* filename, const migraphx::tf_options& options) +inline program parse_tf(const char* filename, const migraphx::tf_options& options->data()) { return program(make(&migraphx_parse_tf, filename, options.get_handle_ptr()), own{}); @@ -1603,28 +1603,12 @@ quantize_fp8(const program& prog, const target& ptarget, const quantize_fp8_opti options.get_handle_ptr()); } -struct supported_onnx_ops_options : MIGRPAHX_HANDLE_BASE(supported_onnx_ops_options) -{ - supported_onnx_ops-options() {this->make_handle(&migraphx_supported_onnx_ops_options_create); } - - MIGRAPHX_HANDLE_CONSTRUCTOR(supported_onnx_op_options) -}; - -inline std::vector get_supported_onnx_operators(supported_onnx_ops_options& options) -{ - const char ** output; - call(&migraphx_get_supported_onnx_operators, - output); - - return std::vector(output) -} - struct experimental_custom_op_base { experimental_custom_op_base() = default; experimental_custom_op_base(const experimental_custom_op_base&) = default; experimental_custom_op_base& operator=(const experimental_custom_op_base&) = default; - virtual ~experimental_custom_op_tDase() = default; + virtual ~experimental_custom_op_base() = default; virtual std::string name() const = 0; virtual argument compute(context ctx, shape output, arguments inputs) const = 0; @@ -1634,7 +1618,6 @@ struct experimental_custom_op_base virtual bool runs_on_offload_target() const = 0; }; - struct experimental_custom_op : interface_base { template @@ -1660,6 +1643,20 @@ void register_experimental_custom_op(T& obj) op.register_op(); } +std::vector get_onnx_operators() +{ + auto size = get_onnx_operators_size(); + std::vector result(size, ""); + + size_t index = 0; + for(auto &name: result) + { + name= get_onnx_operator_name_at_index(index); + index++; + } + return result; +} + #ifndef DOXYGEN } // namespace api #endif diff --git a/src/api/migraphx.py b/src/api/migraphx.py index 53b0bc0e9c8..e5ced659976 100644 --- a/src/api/migraphx.py +++ b/src/api/migraphx.py @@ -510,9 +510,14 @@ def quantize_fp8_options(h): options='migraphx::quantize_fp8_options'), fname='migraphx::quantize_fp8_wrap') -api.add_function('get_supported_onnx_operators', - fname='migraphx::get_supported_onnx_operators', - returns='std::vector') +api.add_function('migraphx_get_onnx_operator_name_at_index', + api.params(index='size_t'), + fname='migraphx::get_onnx_operator_name_at_index', + returns='const char *') + +api.add_function('migraphx_get_onnx_operators_size', + fname='migraphx::get_onnx_operators_size', + returns='std::size_t') diff --git a/src/include/migraphx/onnx.hpp b/src/include/migraphx/onnx.hpp index b9bf42a4f0e..5f6b3067fd9 100644 --- a/src/include/migraphx/onnx.hpp +++ b/src/include/migraphx/onnx.hpp @@ -76,7 +76,7 @@ MIGRAPHX_ONNX_EXPORT program parse_onnx_buffer(const void* data, std::size_t size, const onnx_options& options); -MIGRAPHX_ONNX_EXPORT std::vector get_onnx_operators(); +MIGRAPHX_ONNX_EXPORT const std::vector& get_onnx_operators(); } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/src/onnx/onnx.cpp b/src/onnx/onnx.cpp index efc1d0a7fa7..89aa6f8168a 100644 --- a/src/onnx/onnx.cpp +++ b/src/onnx/onnx.cpp @@ -109,7 +109,11 @@ program parse_onnx_buffer(const void* data, std::size_t size, const onnx_options return parse_onnx_from(options, data, size); } -std::vector get_onnx_operators() { return onnx::get_op_parsers(); } +const std::vector& get_onnx_operators() +{ + static std::vector result = onnx::get_op_parsers(); + return result; +} } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/src/py/migraphx_py.cpp b/src/py/migraphx_py.cpp index 7ac676222f3..335353c933e 100644 --- a/src/py/migraphx_py.cpp +++ b/src/py/migraphx_py.cpp @@ -621,7 +621,7 @@ MIGRAPHX_PYBIND11_MODULE(migraphx, m) py::arg("map_input_dims") = std::unordered_map>(), py::arg("output_names") = std::vector()); - m.def("get_supported_onnx_operators", []{return migraphx::get_onnx_operators();}); + m.def("get_onnx_operators", []{return migraphx::get_onnx_operators();}); m.def( "parse_onnx", [](const std::string& filename, diff --git a/tools/api/api.cpp b/tools/api/api.cpp index d0b204f0449..80319b06f98 100644 --- a/tools/api/api.cpp +++ b/tools/api/api.cpp @@ -289,9 +289,14 @@ static void quantize_fp8_wrap(program& prog, const target& t, quantize_fp8_optio migraphx::quantize_fp8(prog, t, options.calibration); } -static std::vector get_supported_onnx_operators() +static size_t get_onnx_operators_size() { - return migraphx::get_onnx_operators(); + return migraphx::get_onnx_operators().size(); +} + +static const char * get_onnx_operator_name_at_index(std::size_t index) +{ + return get_onnx_operators().at(index).c_str(); } #ifdef __clang__ From 93ce6fd43f42945e349165c20980826e38ffdb5b Mon Sep 17 00:00:00 2001 From: Ted Themistokleous Date: Tue, 21 Oct 2025 16:56:57 -0400 Subject: [PATCH 6/6] backup --- src/api/api.cpp | 2 +- src/api/include/migraphx/migraphx.h | 2 +- src/api/include/migraphx/migraphx.hpp | 6 +++--- src/api/migraphx.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 452cafd04a7..db7cf49b056 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -2430,7 +2430,7 @@ extern "C" migraphx_status migraphx_get_onnx_operator_name_at_index(const char** return api_error_result; } -extern "C" migraphx_status migraphx_get_onnx_operators_size(std::size_t* out) +extern "C" migraphx_status migraphx_get_onnx_operators_size(size_t* out) { auto api_error_result = migraphx::try_([&] { *out = migraphx::get_onnx_operators_size(); }); return api_error_result; diff --git a/src/api/include/migraphx/migraphx.h b/src/api/include/migraphx/migraphx.h index b2f74f7da3e..3a44132e444 100644 --- a/src/api/include/migraphx/migraphx.h +++ b/src/api/include/migraphx/migraphx.h @@ -662,7 +662,7 @@ MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, MIGRAPHX_C_EXPORT migraphx_status migraphx_get_onnx_operator_name_at_index(const char** out, size_t index); -MIGRAPHX_C_EXPORT migraphx_status migraphx_get_onnx_operators_size(std::size_t* out); +MIGRAPHX_C_EXPORT migraphx_status migraphx_get_onnx_operators_size(size_t* out); MIGRAPHX_C_EXPORT migraphx_status migraphx_context_finish(const_migraphx_context_t context); diff --git a/src/api/include/migraphx/migraphx.hpp b/src/api/include/migraphx/migraphx.hpp index d6a41040049..d5a40c528f1 100644 --- a/src/api/include/migraphx/migraphx.hpp +++ b/src/api/include/migraphx/migraphx.hpp @@ -1643,15 +1643,15 @@ void register_experimental_custom_op(T& obj) op.register_op(); } -std::vector get_onnx_operators() +std::vector get_onnx_operators() { auto size = get_onnx_operators_size(); - std::vector result(size, ""); + std::vector result(size, ""); size_t index = 0; for(auto &name: result) { - name= get_onnx_operator_name_at_index(index); + name = get_onnx_operator_name_at_index(index); index++; } return result; diff --git a/src/api/migraphx.py b/src/api/migraphx.py index e5ced659976..bed9996d901 100644 --- a/src/api/migraphx.py +++ b/src/api/migraphx.py @@ -517,7 +517,7 @@ def quantize_fp8_options(h): api.add_function('migraphx_get_onnx_operators_size', fname='migraphx::get_onnx_operators_size', - returns='std::size_t') + returns='size_t')