Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions src/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ static void quantize_fp8_wrap(program& prog, const target& t, quantize_fp8_optio
migraphx::quantize_fp8(prog, t, options.calibration);
}

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 get_onnx_operators().at(index).c_str();
}

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
Expand Down Expand Up @@ -2416,6 +2423,19 @@ extern "C" migraphx_status migraphx_quantize_fp8(migraphx_program_t prog,
return api_error_result;
}

extern "C" migraphx_status migraphx_get_onnx_operator_name_at_index(const char** out, size_t index)
{
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(size_t* out)
{
auto api_error_result = migraphx::try_([&] { *out = migraphx::get_onnx_operators_size(); });
return api_error_result;
}

extern "C" migraphx_status migraphx_context_finish(const_migraphx_context_t context)
{
auto api_error_result = migraphx::try_([&] {
Expand Down
5 changes: 5 additions & 0 deletions src/api/include/migraphx/migraphx.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ 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_onnx_operator_name_at_index(const char** out,
size_t index);

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);

MIGRAPHX_C_EXPORT migraphx_status migraphx_context_get_queue(void** out,
Expand Down
16 changes: 15 additions & 1 deletion src/api/include/migraphx/migraphx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@
};

/// 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())

Check warning on line 1463 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

expected ')' [clang-diagnostic-error]

Check warning on line 1463 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

expected ')' [clang-diagnostic-error]

Check warning on line 1463 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

expected ')' [clang-diagnostic-error]
{
return program(make<migraphx_program>(&migraphx_parse_tf, filename, options.get_handle_ptr()),
own{});
Expand Down Expand Up @@ -1643,6 +1643,20 @@
op.register_op();
}

std::vector<std::string> get_onnx_operators()
{
auto size = get_onnx_operators_size();

Check warning on line 1648 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

use of undeclared identifier 'get_onnx_operators_size'; did you mean 'get_onnx_operators'? [clang-diagnostic-error]

Check warning on line 1648 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

use of undeclared identifier 'get_onnx_operators_size'; did you mean 'get_onnx_operators'? [clang-diagnostic-error]

Check warning on line 1648 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

use of undeclared identifier 'get_onnx_operators_size'; did you mean 'get_onnx_operators'? [clang-diagnostic-error]
std::vector<std::string> result(size, "");

Check warning on line 1649 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

no matching constructor for initialization of 'std::vector<std::string>' (aka 'vector<basic_string<char>>') [clang-diagnostic-error]

Check warning on line 1649 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

no matching constructor for initialization of 'std::vector<std::string>' (aka 'vector<basic_string<char>>') [clang-diagnostic-error]

size_t index = 0;
for(auto &name: result)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the advantage of creating a (secondary) vector of pointers-to-c-strings which point to the (original) strings in another vector? Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We cant pass the vector across the binary boundary so we need to materialize another vector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lakhinderwalia this why I brought this up during yesturday's meeting since it wasn't obvious. It seems simple right why can't we just send back a vector, but since we're running this through C before it goes to the CPP api so you need to generate the list twice here

Copy link
Contributor

@lakhinderwalia lakhinderwalia Oct 7, 2025

Choose a reason for hiding this comment

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

Yes, but you are passing (pointers to the) old structures into the new one. If one can't pass std::vector across a binary boundary, then logically speaking, neither can would std::string, or anything inside it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We are passing a c-string, that doesnt have ABI issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

You have already commented elsewhere that a vector of strings should be created -- instead of a vector of char *. My comments above are aligned with that, if you look deeper. Thanks.

{
name = get_onnx_operator_name_at_index(index);

Check warning on line 1654 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

use of undeclared identifier 'get_onnx_operator_name_at_index' [clang-diagnostic-error]

Check warning on line 1654 in src/api/include/migraphx/migraphx.hpp

View workflow job for this annotation

GitHub Actions / tidy

use of undeclared identifier 'get_onnx_operator_name_at_index' [clang-diagnostic-error]
index++;
}
return result;
}

#ifndef DOXYGEN
} // namespace api
#endif
Expand Down
10 changes: 10 additions & 0 deletions src/api/migraphx.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,16 @@ def quantize_fp8_options(h):
options='migraphx::quantize_fp8_options'),
fname='migraphx::quantize_fp8_wrap')

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='size_t')



@auto_handle(ref=True)
def context(h):
Expand Down
2 changes: 1 addition & 1 deletion src/include/migraphx/onnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> get_onnx_operators();
MIGRAPHX_ONNX_EXPORT const std::vector<std::string>& get_onnx_operators();

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
Expand Down
6 changes: 5 additions & 1 deletion src/onnx/onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> get_onnx_operators() { return onnx::get_op_parsers(); }
const std::vector<std::string>& get_onnx_operators()
{
static std::vector<std::string> result = onnx::get_op_parsers();
return result;
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
1 change: 1 addition & 0 deletions src/py/migraphx_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ MIGRAPHX_PYBIND11_MODULE(migraphx, m)
py::arg("map_input_dims") = std::unordered_map<std::string, std::vector<std::size_t>>(),
py::arg("output_names") = std::vector<std::string>());

m.def("get_onnx_operators", []{return migraphx::get_onnx_operators();});
m.def(
"parse_onnx",
[](const std::string& filename,
Expand Down
10 changes: 10 additions & 0 deletions tools/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ static void quantize_fp8_wrap(program& prog, const target& t, quantize_fp8_optio
migraphx::quantize_fp8(prog, t, options.calibration);
}

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 get_onnx_operators().at(index).c_str();
}

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
Expand Down
Loading