diff --git a/CMakeLists.txt b/CMakeLists.txt index 206b5a18764..013899f6ca3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,8 +87,10 @@ endif() option(MIGRAPHX_USE_ROCBLAS "Enable MIGraphX to use rocBLAS" ON) option(MIGRAPHX_USE_HIPBLASLT "Enable MIGraphX to use hipBLASLt" ON) -option(MIGRAPHX_ENABLE_PYTHON "Enable python bindings" ON) option(MIGRAPHX_USE_MIOPEN "Enable MIGraphX to use MIOpen" ON) +option(MIGRAPHX_ENABLE_PYTHON "Enable python bindings" ON) +option(MIGRAPHX_ENABLE_TENSORFLOW "Enable TensorFlow integration" ON) +option(MIGRAPHX_ENABLE_ONNX "Enable ONNX model import" ON) if(MIGRAPHX_USE_HIPBLASLT AND NOT MIGRAPHX_USE_ROCBLAS) message(FATAL_ERROR "hipBLASLt requires rocBLAS, but MIGRAPHX_USE_ROCBLAS is OFF") @@ -406,7 +408,6 @@ if(BUILD_TESTING) rocm_enable_test_package(migraphx) add_subdirectory(test) endif() -add_subdirectory(tools) set(DEST_DIR ${CMAKE_BINARY_DIR}) file(GLOB backend_files ${CMAKE_SOURCE_DIR}/src/py/backend/*.py) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67cadd37609..06de014b0f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -163,6 +163,8 @@ if(WIN32) target_compile_options(migraphx PUBLIC "SHELL:-Xclang -cfguard") endif() +configure_file(config.h.in include/migraphx/config.h) + configure_file(version.h.in include/migraphx/version.h) add_library(migraphx_version INTERFACE) rocm_install_targets( @@ -398,12 +400,18 @@ target_link_libraries(migraphx PRIVATE msgpack-cxx) target_link_libraries(migraphx INTERFACE $) add_library(migraphx_all_targets INTERFACE) +add_library(migraphx_all_frontends INTERFACE) add_subdirectory(api) add_subdirectory(driver) +if(MIGRAPHX_ENABLE_ONNX) add_subdirectory(onnx) +target_link_libraries(migraphx_all_frontends INTERFACE migraphx_onnx) +endif() +if(MIGRAPHX_ENABLE_TENSORFLOW) add_subdirectory(tf) - +target_link_libraries(migraphx_all_frontends INTERFACE migraphx_tf) +endif() if(MIGRAPHX_ENABLE_PYTHON) add_subdirectory(py) endif() @@ -445,6 +453,7 @@ if(BUILD_DEV) endif() target_compile_definitions(migraphx PUBLIC MIGRAPHX_CXX_COMPILER="${CMAKE_CXX_COMPILER}") +add_dependencies(migraphx generate) rocm_export_targets( TARGETS migraphx::migraphx_c diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 9e83fc6b240..5cae62e1817 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -1,7 +1,7 @@ ##################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -22,9 +22,37 @@ # THE SOFTWARE. ##################################################################################### -add_library(migraphx_c - api.cpp -) +find_package(Python 3 REQUIRED COMPONENTS Interpreter) +find_program(CLANG_FORMAT clang-format PATHS /opt/rocm/llvm ENV HIP_PATH PATH_SUFFIXES bin) + +set(TOOLS_DIR "${PROJECT_SOURCE_DIR}/tools") +set(BIN_DIR "${PROJECT_BINARY_DIR}/src/api") +set(SRC_DIR "${PROJECT_SOURCE_DIR}/src/api") + +set(GENERATE_COMMAND ${Python_EXECUTABLE} generate.py) +if (CLANG_FORMAT) + list(APPEND GENERATE_COMMAND -f ${CLANG_FORMAT}) +endif() +if(MIGRAPHX_ENABLE_ONNX) + list(APPEND GENERATE_COMMAND -Denable_onnx) +endif() +if(MIGRAPHX_ENABLE_TENSORFLOW) + list(APPEND GENERATE_COMMAND -Denable_tensorflow) +endif() +list(APPEND GENERATE_COMMAND -o ${PROJECT_BINARY_DIR}/src) + +add_custom_command( + OUTPUT ${BIN_DIR}/api.cpp + COMMAND ${GENERATE_COMMAND} + DEPENDS ${TOOLS_DIR}/generate.py ${TOOLS_DIR}/api.py ${TOOLS_DIR}/te.py ${SRC_DIR}/migraphx.py + WORKING_DIRECTORY ${TOOLS_DIR} + COMMENT "Generate MIGraphX C API source files...") + +add_custom_target(generate DEPENDS ${BIN_DIR}/api.cpp) + +add_library(migraphx_c ${BIN_DIR}/api.cpp) +add_dependencies(migraphx_c generate) + set_target_properties(migraphx_c PROPERTIES EXPORT_NAME c) migraphx_generate_export_header(migraphx_c DIRECTORY migraphx/api) @@ -37,7 +65,7 @@ if(BUILD_TESTING) endif() rocm_clang_tidy_check(migraphx_c) -target_link_libraries(migraphx_c PRIVATE migraphx migraphx_tf migraphx_onnx) +target_link_libraries(migraphx_c PRIVATE migraphx migraphx_all_frontends) target_link_libraries(migraphx_c PUBLIC migraphx_version) rocm_install_targets( diff --git a/src/api/api.cpp b/src/api/api.cpp deleted file mode 100644 index f6115375e08..00000000000 --- a/src/api/api.cpp +++ /dev/null @@ -1,2644 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace migraphx { - -#ifdef MIGRAPHX_BUILD_TESTING -static thread_local bool disable_exception_catch = false; // NOLINT - -extern "C" MIGRAPHX_C_EXPORT void migraphx_test_private_disable_exception_catch(bool b) -{ - disable_exception_catch = b; -} -#endif - -template -migraphx_status -try_(F f, bool output = true, source_location llc = source_location::current()) // NOLINT -{ -#ifdef MIGRAPHX_BUILD_TESTING - if(disable_exception_catch) - { - f(); - } - else - { -#endif - try - { - f(); - } - catch(const migraphx::exception& ex) - { - if(output) - std::cerr << llc.function_name() << ": Error: " << ex.what() << std::endl; - if(ex.error > 0) - return migraphx_status(ex.error); - else - return migraphx_status_unknown_error; - } - catch(const std::exception& ex) - { - if(output) - std::cerr << llc.function_name() << ": Error: " << ex.what() << std::endl; - return migraphx_status_unknown_error; - } - catch(...) - { - return migraphx_status_unknown_error; - } -#ifdef MIGRAPHX_BUILD_TESTING - } -#endif - return migraphx_status_success; -} - -static shape::type_t to_shape_type(migraphx_shape_datatype_t t) -{ - switch(t) - { - case migraphx_shape_tuple_type: return shape::tuple_type; - case migraphx_shape_fp4x2_type: return shape::fp4x2_type; -#define MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT(x, y) \ - case migraphx_shape_##x: return shape::x; - MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT) -#undef MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT - } - MIGRAPHX_THROW(migraphx_status_bad_param, "Unknown type"); -} - -static migraphx_shape_datatype_t to_shape_type(shape::type_t t) -{ - switch(t) - { - case shape::tuple_type: return migraphx_shape_tuple_type; - case shape::fp4x2_type: return migraphx_shape_fp4x2_type; -#define MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT(x, y) \ - case shape::x: return migraphx_shape_##x; - MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT) -#undef MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT - } - MIGRAPHX_THROW(migraphx_status_bad_param, "Unknown type"); -} - -template -static auto to_obj_vector(const T* x, std::size_t n) -{ - std::vectorobject)> result; - std::transform(x, x + n, std::back_inserter(result), [&](auto&& y) { return y->object; }); - return result; -} - -template -static auto to_objptr_vector(const U* x, std::size_t n) -{ - std::vector result; - std::transform( - x, x + n, std::back_inserter(result), [&](auto&& y) { return std::addressof(y->object); }); - return result; -} - -static target get_target(const std::string& name) { return make_target(name); } - -static void set_offload_copy(compile_options& options, bool value) { options.offload_copy = value; } - -static void set_fast_math(compile_options& options, bool value) { options.fast_math = value; } - -static void set_exhaustive_tune_flag(compile_options& options, bool value) -{ - options.exhaustive_tune = value; -} - -static void set_file_format(file_options& options, const char* format) { options.format = format; } - -static void set_default_dim_value(onnx_options& options, size_t value) -{ - options.default_dim_value = value; -} - -static void set_default_dyn_dim_value(onnx_options& options, const shape::dynamic_dimension& dd) -{ - options.default_dyn_dim_value = dd; -} - -static void set_default_loop_iterations(onnx_options& options, int64_t value) -{ - options.max_loop_iterations = value; -} - -static void set_external_data_path(onnx_options& options, const char* external_data_path) -{ - options.external_data_path = std::string(external_data_path); -} - -static void set_limit_loop_iterations(onnx_options& options, int64_t value) -{ - options.limit_max_iterations = value; -} - -static void set_use_debug_symbols(onnx_options& options, bool value) -{ - options.use_debug_symbols = value; -} - -static void set_nhwc(tf_options& options, bool is_nhwc) { options.is_nhwc = is_nhwc; } - -static void set_default_dim_value(tf_options& options, size_t value) { options.batch_size = value; } - -static void -set_input_parameter_shape(onnx_options& options, const char* name, std::vector dims) -{ - options.map_input_dims[std::string(name)] = std::move(dims); -} - -static void set_dyn_input_parameter_shape(onnx_options& options, - const char* name, - std::vector dyn_dims) -{ - options.map_dyn_input_dims[std::string(name)] = std::move(dyn_dims); -} - -static void -set_input_parameter_shape(tf_options& options, const char* name, std::vector dims) -{ - options.map_input_dims[std::string(name)] = std::move(dims); -} - -static void set_output_names(tf_options& options, std::vector names) -{ - options.output_node_names = std::vector(names.begin(), names.end()); -} - -static std::vector -run_async(program& p, const parameter_map& params, void* s, std::string_view name) -{ - execution_environment exec_env{any_ptr(s, name), true}; - return p.eval(params, exec_env); -} - -template -static std::vector get_names(const std::unordered_map& m) -{ - std::vector result; - std::transform( - m.begin(), m.end(), std::back_inserter(result), [](auto&& p) { return p.first.c_str(); }); - return result; -} - -template -static std::set make_set(const T* x, std::size_t n) -{ - return {x, x + n}; -} - -static void quantize_fp16_with_op_names(program& prog, std::vector& names) -{ - if(names.empty()) - { - names = {"all"}; - } - - migraphx::quantize_fp16(prog, names); -} - -static void quantize_bf16_with_op_names(program& prog, std::vector& names) -{ - if(names.empty()) - { - names = {"all"}; - } - - migraphx::quantize_bf16(prog, names); -} - -struct quantize_int8_options -{ - std::vector calibration = {}; - std::unordered_set op_names = {}; -}; - -static void add_op_name(quantize_int8_options& options, const char* name) -{ - options.op_names.insert(name); -} - -static void add_calibration_data(quantize_int8_options& options, const parameter_map& data) -{ - options.calibration.push_back(data); -} - -static void quantize_int8_wrap(program& prog, const target& t, quantize_int8_options& options) -{ - if(options.op_names.empty()) - { - options.op_names = {"dot", "convolution"}; - } - - migraphx::quantize_int8(prog, t, options.calibration, options.op_names); -} - -struct quantize_fp8_options -{ - std::vector calibration = {}; -}; - -static void add_calibration_data(quantize_fp8_options& options, const parameter_map& data) -{ - options.calibration.push_back(data); -} - -static void quantize_fp8_wrap(program& prog, const target& t, quantize_fp8_options& options) -{ - migraphx::quantize_fp8(prog, t, options.calibration); -} - -static size_t get_onnx_operators_size() { return migraphx::get_onnx_operators().size(); } - -static char* get_onnx_operator_name_at_index(std::size_t index) -{ - return const_cast(get_onnx_operators().at(index).c_str()); // NOLINT -} - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wformat-nonliteral" -#endif - -static operation create_op(const char* name, const char* attributes, va_list vlist) -{ - std::string sattributes = attributes == nullptr ? "" : attributes; - std::vector buffer(sattributes.size() * 2); - std::vsnprintf(buffer.data(), buffer.size(), sattributes.c_str(), vlist); - value v = value::object{}; - if(attributes != nullptr) - { - v = from_json_string(convert_to_json(std::string(buffer.data()))); - } - auto op = make_op(name, v); - - return op; -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -template -static bool equal(const T& x, const T& y) -{ - return x == y; -} - -static std::vector run(program& p, const parameter_map& params) { return p.eval(params); } - -static std::vector get_output_shapes(program& p) { return p.get_output_shapes(); } - -static void print_program(const program& p) { std::cout << p << std::endl; } - -static void print_module(const module& m) { std::cout << m << std::endl; } - -static migraphx::instruction_ref add_allocation(module& m, const migraphx::shape& s) -{ - return m.add_instruction(migraphx::make_op("allocate", {{"shape", migraphx::to_value(s)}}), {}); -} - -struct experimental_custom_op -{ - std::string name; - experimental_custom_op() = default; - - experimental_custom_op(std::string pname) : name(std::move(pname)) {} -}; - -template -struct custom_operation -{ - - template - static auto reflect(Self&, F) - { - return pack(); - } - - value attributes() const - { - return {{"custom_op", true}, {"target", op.runs_on_offload_target() ? "gpu" : "cpu"}}; - } - - CustomOp op; - std::string name() const { return op.xobject.name; } - - shape compute_shape(std::vector inputs) const - { - return op.compute_shape(std::move(inputs)); - } - - // TODO: Compute method with module_args - argument - compute(migraphx::context ctx, migraphx::shape output_shape, std::vector inputs) const - { - return op.compute(std::move(ctx), std::move(output_shape), std::move(inputs)); - } - - std::vector output_alias(std::vector inputs) const - { - return op.output_alias(std::move(inputs)); - } - - bool runs_on_offload_target() const { return op.runs_on_offload_target(); } -}; - -template -static void register_custom_op(const CustomOp& op) -{ - register_op(custom_operation{op}); -} - -static migraphx::context get_context(const program& p) { return p.get_context(); } - -static std::vector -run_trace(program& p, const parameter_map& params, const std::function& callback) -{ - execution_environment exec_env; - const auto* mm = p.get_main_module(); - exec_env.trace = [&, mm](instruction_ref ins, const argument& output) { - auto idx = std::distance(mm->begin(), ins); - std::ostringstream oss; - oss << ins->get_operator(); - callback(trace_info{static_cast(idx), oss.str(), output}); - }; - return p.eval(params, exec_env); -} - -} // namespace migraphx - -template > -static Target* object_cast(U* x) -{ - return reinterpret_cast(x); -} -template > -static const Target* object_cast(const U* x) -{ - return reinterpret_cast(x); -} - -template > -static Target* allocate(Ts&&... xs) -{ - if constexpr(std::is_aggregate{}) - return new Target{std::forward(xs)...}; // NOLINT - else - return new Target(std::forward(xs)...); // NOLINT -} - -template -static void destroy(T* x) -{ - delete x; // NOLINT -} - -// TODO: Move to interface preamble -template -struct manage_generic_ptr -{ - manage_generic_ptr() = default; - - manage_generic_ptr(std::nullptr_t) {} - - manage_generic_ptr(void* pdata, const char* obj_tname, C pcopier, D pdeleter) - : data(nullptr), obj_typename(obj_tname), copier(pcopier), deleter(pdeleter) - { - copier(&data, pdata); - } - - manage_generic_ptr(const manage_generic_ptr& rhs) - : data(nullptr), obj_typename(rhs.obj_typename), copier(rhs.copier), deleter(rhs.deleter) - { - if(copier) - copier(&data, rhs.data); - } - - manage_generic_ptr(manage_generic_ptr&& other) noexcept - : data(other.data), - obj_typename(other.obj_typename), - copier(other.copier), - deleter(other.deleter) - { - other.data = nullptr; - other.obj_typename = ""; - other.copier = nullptr; - other.deleter = nullptr; - } - - manage_generic_ptr& operator=(manage_generic_ptr rhs) - { - std::swap(data, rhs.data); - std::swap(obj_typename, rhs.obj_typename); - std::swap(copier, rhs.copier); - std::swap(deleter, rhs.deleter); - return *this; - } - - ~manage_generic_ptr() - { - if(data != nullptr) - deleter(data); - } - - void* data = nullptr; - const char* obj_typename = ""; - C copier = nullptr; - D deleter = nullptr; -}; - -extern "C" struct migraphx_optimals; -struct migraphx_optimals -{ - template - migraphx_optimals(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::set object; -}; - -extern "C" struct migraphx_dynamic_dimension; -struct migraphx_dynamic_dimension -{ - template - migraphx_dynamic_dimension(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::shape::dynamic_dimension object; -}; - -extern "C" struct migraphx_dynamic_dimensions; -struct migraphx_dynamic_dimensions -{ - template - migraphx_dynamic_dimensions(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::vector object; -}; - -extern "C" struct migraphx_shape; -struct migraphx_shape -{ - template - migraphx_shape(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::shape object; -}; - -extern "C" struct migraphx_argument; -struct migraphx_argument -{ - template - migraphx_argument(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::argument object; -}; - -extern "C" struct migraphx_target; -struct migraphx_target -{ - template - migraphx_target(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::target object; -}; - -extern "C" struct migraphx_program_parameter_shapes; -struct migraphx_program_parameter_shapes -{ - template - migraphx_program_parameter_shapes(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::unordered_map object; -}; - -extern "C" struct migraphx_program_parameters; -struct migraphx_program_parameters -{ - template - migraphx_program_parameters(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::unordered_map object; -}; - -extern "C" struct migraphx_arguments; -struct migraphx_arguments -{ - template - migraphx_arguments(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::vector object; -}; - -extern "C" struct migraphx_shapes; -struct migraphx_shapes -{ - template - migraphx_shapes(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::vector object; -}; - -extern "C" struct migraphx_instruction; -struct migraphx_instruction -{ - template - migraphx_instruction(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::instruction_ref object; -}; - -extern "C" struct migraphx_instructions; -struct migraphx_instructions -{ - template - migraphx_instructions(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::vector object; -}; - -extern "C" struct migraphx_modules; -struct migraphx_modules -{ - template - migraphx_modules(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::vector object; -}; - -extern "C" struct migraphx_module; -struct migraphx_module -{ - template - migraphx_module(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::module object; -}; - -extern "C" struct migraphx_trace_info; -struct migraphx_trace_info -{ - template - migraphx_trace_info(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::trace_info object; -}; - -extern "C" struct migraphx_program; -struct migraphx_program -{ - template - migraphx_program(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::program object; -}; - -extern "C" struct migraphx_operation; -struct migraphx_operation -{ - template - migraphx_operation(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::operation object; -}; - -extern "C" struct migraphx_onnx_options; -struct migraphx_onnx_options -{ - template - migraphx_onnx_options(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::onnx_options object; -}; - -extern "C" struct migraphx_file_options; -struct migraphx_file_options -{ - template - migraphx_file_options(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::file_options object; -}; - -extern "C" struct migraphx_compile_options; -struct migraphx_compile_options -{ - template - migraphx_compile_options(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::compile_options object; -}; - -extern "C" struct migraphx_tf_options; -struct migraphx_tf_options -{ - template - migraphx_tf_options(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::tf_options object; -}; - -extern "C" struct migraphx_quantize_op_names; -struct migraphx_quantize_op_names -{ - template - migraphx_quantize_op_names(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - std::vector object; -}; - -extern "C" struct migraphx_quantize_int8_options; -struct migraphx_quantize_int8_options -{ - template - migraphx_quantize_int8_options(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::quantize_int8_options object; -}; - -extern "C" struct migraphx_quantize_fp8_options; -struct migraphx_quantize_fp8_options -{ - template - migraphx_quantize_fp8_options(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::quantize_fp8_options object; -}; - -extern "C" struct migraphx_context; -struct migraphx_context -{ - template - migraphx_context(Ts&&... xs) - : object(std::forward(xs)...) // NOLINT(readability-redundant-member-init) - { - } - migraphx::context object; -}; - -extern "C" struct migraphx_experimental_custom_op; -struct migraphx_experimental_custom_op -{ - template - migraphx_experimental_custom_op(void* p, - migraphx_experimental_custom_op_copy c, - migraphx_experimental_custom_op_delete d, - const char* obj_typename, - Ts&&... xs) - : object_ptr(p, obj_typename, c, d), xobject(std::forward(xs)...) - { - } - manage_generic_ptr - object_ptr = nullptr; - migraphx::experimental_custom_op xobject; - migraphx_experimental_custom_op_compute compute_f = nullptr; - migraphx::argument compute(migraphx::context ctx, - migraphx::shape output, - std::vector inputs) const - { - if(compute_f == nullptr) - throw std::runtime_error("compute function is missing."); - std::remove_pointer_t out; - std::array exception_msg; - exception_msg.front() = '\0'; - auto api_error_result = compute_f(&out, - object_ptr.data, - exception_msg.data(), - exception_msg.size(), - object_cast(&(ctx)), - object_cast(&(output)), - object_cast(&(inputs))); - if(api_error_result != migraphx_status_success) - { - const std::string exception_str(exception_msg.data()); - throw std::runtime_error("Error in compute of: " + - std::string(object_ptr.obj_typename) + ": " + exception_str); - } - return (&out)->object; - } - - migraphx_experimental_custom_op_compute_shape compute_shape_f = nullptr; - migraphx::shape compute_shape(std::vector inputs) const - { - if(compute_shape_f == nullptr) - throw std::runtime_error("compute_shape function is missing."); - std::remove_pointer_t out; - std::array exception_msg; - exception_msg.front() = '\0'; - auto api_error_result = compute_shape_f(&out, - object_ptr.data, - exception_msg.data(), - exception_msg.size(), - object_cast(&(inputs))); - if(api_error_result != migraphx_status_success) - { - const std::string exception_str(exception_msg.data()); - throw std::runtime_error("Error in compute_shape of: " + - std::string(object_ptr.obj_typename) + ": " + exception_str); - } - return (&out)->object; - } - - migraphx_experimental_custom_op_output_alias output_alias_f = nullptr; - std::vector output_alias(std::vector inputs) const - { - if(output_alias_f == nullptr) - throw std::runtime_error("output_alias function is missing."); - std::array out; - std::remove_pointer_t out_size = 1024; - std::array exception_msg; - exception_msg.front() = '\0'; - auto api_error_result = output_alias_f(out.data(), - &out_size, - object_ptr.data, - exception_msg.data(), - exception_msg.size(), - object_cast(&(inputs))); - if(api_error_result != migraphx_status_success) - { - const std::string exception_str(exception_msg.data()); - throw std::runtime_error("Error in output_alias of: " + - std::string(object_ptr.obj_typename) + ": " + exception_str); - } - return {out.begin(), out.begin() + out_size}; // cppcheck-suppress returnDanglingLifetime; - } - - migraphx_experimental_custom_op_runs_on_offload_target runs_on_offload_target_f = nullptr; - bool runs_on_offload_target() const - { - if(runs_on_offload_target_f == nullptr) - throw std::runtime_error("runs_on_offload_target function is missing."); - std::remove_pointer_t out; - std::array exception_msg; - exception_msg.front() = '\0'; - auto api_error_result = runs_on_offload_target_f( - &out, object_ptr.data, exception_msg.data(), exception_msg.size()); - if(api_error_result != migraphx_status_success) - { - const std::string exception_str(exception_msg.data()); - throw std::runtime_error("Error in runs_on_offload_target of: " + - std::string(object_ptr.obj_typename) + ": " + exception_str); - } - return out; - } -}; - -extern "C" migraphx_status migraphx_optimals_destroy(migraphx_optimals_t optimals) -{ - auto api_error_result = migraphx::try_([&] { destroy((optimals)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_optimals_assign_to(migraphx_optimals_t output, - const_migraphx_optimals_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_optimals_create(migraphx_optimals_t* optimals, const size_t* ptr, size_t size) -{ - auto api_error_result = migraphx::try_([&] { - *optimals = object_cast( - allocate>(migraphx::make_set((ptr), (size)))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimension_destroy(migraphx_dynamic_dimension_t dynamic_dimension) -{ - auto api_error_result = migraphx::try_([&] { destroy((dynamic_dimension)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimension_assign_to(migraphx_dynamic_dimension_t output, - const_migraphx_dynamic_dimension_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_dynamic_dimension_create_min_max( - migraphx_dynamic_dimension_t* dynamic_dimension, size_t min, size_t max) -{ - auto api_error_result = migraphx::try_([&] { - *dynamic_dimension = object_cast( - allocate((min), (max))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimension_create_min_max_optimals(migraphx_dynamic_dimension_t* dynamic_dimension, - size_t min, - size_t max, - migraphx_optimals_t optimals) -{ - auto api_error_result = migraphx::try_([&] { - if(optimals == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter optimals: Null pointer"); - *dynamic_dimension = object_cast( - allocate((min), (max), (optimals->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimension_is_fixed(bool* out, const_migraphx_dynamic_dimension_t dynamic_dimension) -{ - auto api_error_result = migraphx::try_([&] { - if(dynamic_dimension == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter dynamic_dimension: Null pointer"); - *out = (dynamic_dimension->object).is_fixed(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimension_equal(bool* out, - const_migraphx_dynamic_dimension_t dynamic_dimension, - const_migraphx_dynamic_dimension_t x) -{ - auto api_error_result = migraphx::try_([&] { - if(dynamic_dimension == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter dynamic_dimension: Null pointer"); - if(x == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter x: Null pointer"); - *out = migraphx::equal((dynamic_dimension->object), (x->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimensions_destroy(migraphx_dynamic_dimensions_t dynamic_dimensions) -{ - auto api_error_result = migraphx::try_([&] { destroy((dynamic_dimensions)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimensions_assign_to(migraphx_dynamic_dimensions_t output, - const_migraphx_dynamic_dimensions_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimensions_create(migraphx_dynamic_dimensions_t* dynamic_dimensions, - const const_migraphx_dynamic_dimension_t* ptr, - size_t size) -{ - auto api_error_result = migraphx::try_([&] { - *dynamic_dimensions = object_cast( - allocate>( - migraphx::to_obj_vector((ptr), (size)))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimensions_size(size_t* out, migraphx_dynamic_dimensions_t dynamic_dimensions) -{ - auto api_error_result = migraphx::try_([&] { - if(dynamic_dimensions == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter dynamic_dimensions: Null pointer"); - *out = (dynamic_dimensions->object).size(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_dynamic_dimensions_get(const_migraphx_dynamic_dimension_t* out, - migraphx_dynamic_dimensions_t dynamic_dimensions, - size_t idx) -{ - auto api_error_result = migraphx::try_([&] { - if(dynamic_dimensions == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter dynamic_dimensions: Null pointer"); - *out = object_cast( - &((dynamic_dimensions->object).at((idx)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_destroy(migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { destroy((shape)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_assign_to(migraphx_shape_t output, - const_migraphx_shape_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_create(migraphx_shape_t* shape, - migraphx_shape_datatype_t type, - size_t* lengths, - size_t lengths_size) -{ - auto api_error_result = migraphx::try_([&] { - if(lengths == nullptr and lengths_size != 0) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter lengths: Null pointer"); - *shape = object_cast( - allocate((migraphx::to_shape_type(type)), - (std::vector(lengths, lengths + lengths_size)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_create_with_strides(migraphx_shape_t* shape, - migraphx_shape_datatype_t type, - size_t* lengths, - size_t lengths_size, - size_t* strides, - size_t strides_size) -{ - auto api_error_result = migraphx::try_([&] { - if(lengths == nullptr and lengths_size != 0) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter lengths: Null pointer"); - if(strides == nullptr and strides_size != 0) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter strides: Null pointer"); - *shape = object_cast( - allocate((migraphx::to_shape_type(type)), - (std::vector(lengths, lengths + lengths_size)), - (std::vector(strides, strides + strides_size)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_create_scalar(migraphx_shape_t* shape, - migraphx_shape_datatype_t type) -{ - auto api_error_result = migraphx::try_([&] { - *shape = object_cast( - allocate((migraphx::to_shape_type(type)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_create_dynamic(migraphx_shape_t* shape, - migraphx_shape_datatype_t type, - migraphx_dynamic_dimensions_t dims) -{ - auto api_error_result = migraphx::try_([&] { - if(dims == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter dims: Null pointer"); - *shape = object_cast( - allocate((migraphx::to_shape_type(type)), (dims->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_shape_lengths(const size_t** out, size_t* out_size, const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(out == nullptr or out_size == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - auto&& api_result = (shape->object).lens(); - *out = api_result.data(); - *out_size = api_result.size(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_shape_strides(const size_t** out, size_t* out_size, const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(out == nullptr or out_size == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - auto&& api_result = (shape->object).strides(); - *out = api_result.data(); - *out_size = api_result.size(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_dyn_dims(migraphx_dynamic_dimensions_t* out, - const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = allocate((shape->object).dyn_dims()); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_type(migraphx_shape_datatype_t* out, - const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(out == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = migraphx::to_shape_type((shape->object).type()); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_elements(size_t* out, const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = (shape->object).elements(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_bytes(size_t* out, const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = (shape->object).bytes(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_ndim(size_t* out, const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = (shape->object).ndim(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_shape_equal(bool* out, const_migraphx_shape_t shape, const_migraphx_shape_t x) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - if(x == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter x: Null pointer"); - *out = migraphx::equal((shape->object), (x->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_standard(bool* out, const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = (shape->object).standard(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_dynamic(bool* out, const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = (shape->object).dynamic(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shape_index(size_t* out, const_migraphx_shape_t shape, size_t i) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = (shape->object).index((i)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_argument_destroy(migraphx_argument_t argument) -{ - auto api_error_result = migraphx::try_([&] { destroy((argument)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_argument_assign_to(migraphx_argument_t output, - const_migraphx_argument_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_argument_create(migraphx_argument_t* argument, const_migraphx_shape_t shape, void* buffer) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *argument = object_cast( - allocate((shape->object), (buffer))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_argument_create_empty(migraphx_argument_t* argument, - const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *argument = object_cast(allocate((shape->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_argument_shape(const_migraphx_shape_t* out, - const_migraphx_argument_t argument) -{ - auto api_error_result = migraphx::try_([&] { - if(argument == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter argument: Null pointer"); - *out = object_cast(&((argument->object).get_shape())); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_argument_buffer(char** out, const_migraphx_argument_t argument) -{ - auto api_error_result = migraphx::try_([&] { - if(argument == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter argument: Null pointer"); - *out = (argument->object).data(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_argument_equal(bool* out, const_migraphx_argument_t argument, const_migraphx_argument_t x) -{ - auto api_error_result = migraphx::try_([&] { - if(argument == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter argument: Null pointer"); - if(x == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter x: Null pointer"); - *out = migraphx::equal((argument->object), (x->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_argument_save(const_migraphx_argument_t a, const char* filename) -{ - auto api_error_result = migraphx::try_([&] { - if(a == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter a: Null pointer"); - migraphx::save_argument((a->object), (filename)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_argument_load(migraphx_argument_t* out, const char* filename) -{ - auto api_error_result = migraphx::try_( - [&] { *out = allocate(migraphx::load_argument((filename))); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_argument_generate(migraphx_argument_t* out, const_migraphx_shape_t s, size_t seed) -{ - auto api_error_result = migraphx::try_([&] { - if(s == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter s: Null pointer"); - *out = allocate(migraphx::generate_argument((s->object), (seed))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_target_destroy(migraphx_target_t target) -{ - auto api_error_result = migraphx::try_([&] { destroy((target)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_target_assign_to(migraphx_target_t output, - const_migraphx_target_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_target_create(migraphx_target_t* target, const char* name) -{ - auto api_error_result = migraphx::try_([&] { - *target = object_cast( - allocate(migraphx::get_target((name)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_parameter_shapes_destroy( - migraphx_program_parameter_shapes_t program_parameter_shapes) -{ - auto api_error_result = migraphx::try_([&] { destroy((program_parameter_shapes)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_parameter_shapes_assign_to(migraphx_program_parameter_shapes_t output, - const_migraphx_program_parameter_shapes_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_parameter_shapes_size(size_t* out, - migraphx_program_parameter_shapes_t program_parameter_shapes) -{ - auto api_error_result = migraphx::try_([&] { - if(program_parameter_shapes == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter program_parameter_shapes: Null pointer"); - *out = (program_parameter_shapes->object).size(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_parameter_shapes_get(const_migraphx_shape_t* out, - migraphx_program_parameter_shapes_t program_parameter_shapes, - const char* name) -{ - auto api_error_result = migraphx::try_([&] { - if(program_parameter_shapes == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter program_parameter_shapes: Null pointer"); - *out = - object_cast(&((program_parameter_shapes->object).at((name)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_parameter_shapes_names( - const char** out, migraphx_program_parameter_shapes_t program_parameter_shapes) -{ - auto api_error_result = migraphx::try_([&] { - if(out == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); - if(program_parameter_shapes == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter program_parameter_shapes: Null pointer"); - auto&& api_result = migraphx::get_names((program_parameter_shapes->object)); - std::copy(api_result.begin(), api_result.end(), out); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_parameters_destroy(migraphx_program_parameters_t program_parameters) -{ - auto api_error_result = migraphx::try_([&] { destroy((program_parameters)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_parameters_assign_to(migraphx_program_parameters_t output, - const_migraphx_program_parameters_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_parameters_create(migraphx_program_parameters_t* program_parameters) -{ - auto api_error_result = migraphx::try_([&] { - *program_parameters = object_cast( - allocate>()); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_parameters_add(migraphx_program_parameters_t program_parameters, - const char* name, - const_migraphx_argument_t argument) -{ - auto api_error_result = migraphx::try_([&] { - if(program_parameters == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter program_parameters: Null pointer"); - if(argument == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter argument: Null pointer"); - (program_parameters->object)[(name)] = (argument->object); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_arguments_destroy(migraphx_arguments_t arguments) -{ - auto api_error_result = migraphx::try_([&] { destroy((arguments)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_arguments_assign_to(migraphx_arguments_t output, - const_migraphx_arguments_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_arguments_size(size_t* out, migraphx_arguments_t arguments) -{ - auto api_error_result = migraphx::try_([&] { - if(arguments == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter arguments: Null pointer"); - *out = (arguments->object).size(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_arguments_get(const_migraphx_argument_t* out, migraphx_arguments_t arguments, size_t idx) -{ - auto api_error_result = migraphx::try_([&] { - if(arguments == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter arguments: Null pointer"); - *out = object_cast(&((arguments->object).at((idx)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shapes_destroy(migraphx_shapes_t shapes) -{ - auto api_error_result = migraphx::try_([&] { destroy((shapes)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shapes_assign_to(migraphx_shapes_t output, - const_migraphx_shapes_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_shapes_size(size_t* out, migraphx_shapes_t shapes) -{ - auto api_error_result = migraphx::try_([&] { - if(shapes == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shapes: Null pointer"); - *out = (shapes->object).size(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_shapes_get(const_migraphx_shape_t* out, migraphx_shapes_t shapes, size_t idx) -{ - auto api_error_result = migraphx::try_([&] { - if(shapes == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shapes: Null pointer"); - *out = object_cast(&((shapes->object).at((idx)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_instruction_destroy(migraphx_instruction_t instruction) -{ - auto api_error_result = migraphx::try_([&] { destroy((instruction)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_instruction_assign_to(migraphx_instruction_t output, - const_migraphx_instruction_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_instructions_destroy(migraphx_instructions_t instructions) -{ - auto api_error_result = migraphx::try_([&] { destroy((instructions)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_instructions_assign_to(migraphx_instructions_t output, - const_migraphx_instructions_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_instructions_create(migraphx_instructions_t* instructions, - const const_migraphx_instruction_t* ptr, - size_t size) -{ - auto api_error_result = migraphx::try_([&] { - *instructions = - object_cast(allocate>( - migraphx::to_obj_vector((ptr), (size)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_modules_destroy(migraphx_modules_t modules) -{ - auto api_error_result = migraphx::try_([&] { destroy((modules)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_modules_assign_to(migraphx_modules_t output, - const_migraphx_modules_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_modules_create(migraphx_modules_t* modules, migraphx_module_t* ptr, size_t size) -{ - auto api_error_result = migraphx::try_([&] { - *modules = object_cast(allocate>( - migraphx::to_objptr_vector((ptr), (size)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_module_create(migraphx_module_t* module, char* name) -{ - auto api_error_result = migraphx::try_([&] { - if(name == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter name: Null pointer"); - *module = object_cast(allocate((std::string(name)))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_module_print(const_migraphx_module_t module) -{ - auto api_error_result = migraphx::try_([&] { - if(module == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module: Null pointer"); - migraphx::print_module((module->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_module_add_instruction(migraphx_instruction_t* out, - migraphx_module_t module, - migraphx_operation_t op, - migraphx_instructions_t args) -{ - auto api_error_result = migraphx::try_([&] { - if(module == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module: Null pointer"); - if(op == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter op: Null pointer"); - if(args == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter args: Null pointer"); - *out = allocate( - (module->object).add_instruction((op->object), (args->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_module_add_instruction_with_mod_args(migraphx_instruction_t* out, - migraphx_module_t module, - migraphx_operation_t op, - migraphx_instructions_t args, - migraphx_modules_t module_refs) -{ - auto api_error_result = migraphx::try_([&] { - if(module == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module: Null pointer"); - if(op == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter op: Null pointer"); - if(args == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter args: Null pointer"); - if(module_refs == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module_refs: Null pointer"); - *out = allocate( - (module->object).add_instruction((op->object), (args->object), (module_refs->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_module_add_literal(migraphx_instruction_t* out, - migraphx_module_t module, - const_migraphx_shape_t shape, - const char* buffer) -{ - auto api_error_result = migraphx::try_([&] { - if(module == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module: Null pointer"); - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = allocate( - (module->object).add_literal((shape->object), (buffer))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_module_add_parameter(migraphx_instruction_t* out, - migraphx_module_t module, - const char* name, - const_migraphx_shape_t shape) -{ - auto api_error_result = migraphx::try_([&] { - if(module == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module: Null pointer"); - if(shape == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter shape: Null pointer"); - *out = allocate( - (module->object).add_parameter((name), (shape->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_module_add_return(migraphx_instruction_t* out, - migraphx_module_t module, - migraphx_instructions_t args) -{ - auto api_error_result = migraphx::try_([&] { - if(module == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module: Null pointer"); - if(args == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter args: Null pointer"); - *out = allocate((module->object).add_return((args->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_module_add_allocation(migraphx_instruction_t* out, - migraphx_module_t module, - const_migraphx_shape_t s) -{ - auto api_error_result = migraphx::try_([&] { - if(module == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter module: Null pointer"); - if(s == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter s: Null pointer"); - *out = allocate( - migraphx::add_allocation((module->object), (s->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_trace_info_destroy(migraphx_trace_info_t trace_info) -{ - auto api_error_result = migraphx::try_([&] { destroy((trace_info)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_trace_info_assign_to(migraphx_trace_info_t output, - const_migraphx_trace_info_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_trace_info_create(migraphx_trace_info_t* trace_info) -{ - auto api_error_result = migraphx::try_([&] { - *trace_info = object_cast(allocate()); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_trace_info_get_index(size_t* out, - const_migraphx_trace_info_t trace_info) -{ - auto api_error_result = migraphx::try_([&] { - if(trace_info == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter trace_info: Null pointer"); - *out = (trace_info->object).index; - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_trace_info_get_name(const char** out, - const_migraphx_trace_info_t trace_info) -{ - auto api_error_result = migraphx::try_([&] { - if(out == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); - if(trace_info == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter trace_info: Null pointer"); - *out = (trace_info->object).name.c_str(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_trace_info_get_result(const_migraphx_argument_t* out, - const_migraphx_trace_info_t trace_info) -{ - auto api_error_result = migraphx::try_([&] { - if(trace_info == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter trace_info: Null pointer"); - *out = object_cast(&((trace_info->object).result)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_destroy(migraphx_program_t program) -{ - auto api_error_result = migraphx::try_([&] { destroy((program)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_assign_to(migraphx_program_t output, - const_migraphx_program_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_create(migraphx_program_t* program) -{ - auto api_error_result = migraphx::try_( - [&] { *program = object_cast(allocate()); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_get_main_module(migraphx_module_t* out, - migraphx_program_t program) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - *out = object_cast((program->object).get_main_module()); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_create_module(migraphx_module_t* out, migraphx_program_t program, const char* name) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - *out = object_cast((program->object).create_module((name))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_compile(migraphx_program_t program, - migraphx_target_t target, - migraphx_compile_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - if(target == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter target: Null pointer"); - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - (program->object).compile((target->object), (options->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_get_parameter_shapes(migraphx_program_parameter_shapes_t* out, - migraphx_program_t program) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - *out = - allocate((program->object).get_parameter_shapes()); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_get_output_shapes(migraphx_shapes_t* out, - migraphx_program_t program) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - *out = allocate(migraphx::get_output_shapes((program->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_print(const_migraphx_program_t program) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - migraphx::print_program((program->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_sort(migraphx_program_t program) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - (program->object).sort(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_run(migraphx_arguments_t* out, - migraphx_program_t program, - migraphx_program_parameters_t params) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - if(params == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter params: Null pointer"); - *out = allocate(migraphx::run((program->object), (params->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_run_async(migraphx_arguments_t* out, - migraphx_program_t program, - migraphx_program_parameters_t params, - void* s, - const char* name) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - if(params == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter params: Null pointer"); - *out = allocate( - migraphx::run_async((program->object), (params->object), (s), (name))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_program_run_trace(migraphx_arguments_t* out, - migraphx_program_t program, - migraphx_program_parameters_t params, - migraphx_trace_callback_t callback, - void* data) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - if(params == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter params: Null pointer"); - *out = allocate( - migraphx::run_trace(((program->object)), - ((params->object)), - [callback, data](const migraphx::trace_info& info) { - migraphx_trace_info handle{info}; - auto status = callback(&handle, data); - if(status != migraphx_status_success) - MIGRAPHX_THROW(status, "Trace callback returned an error"); - })); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_equal(bool* out, const_migraphx_program_t program, const_migraphx_program_t x) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - if(x == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter x: Null pointer"); - *out = migraphx::equal((program->object), (x->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_program_experimental_get_context(migraphx_context_t* out, const_migraphx_program_t program) -{ - auto api_error_result = migraphx::try_([&] { - if(program == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter program: Null pointer"); - *out = allocate(migraphx::get_context((program->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_operation_destroy(migraphx_operation_t operation) -{ - auto api_error_result = migraphx::try_([&] { destroy((operation)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_operation_assign_to(migraphx_operation_t output, - const_migraphx_operation_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_operation_create(migraphx_operation_t* operation, - const char* name, - const char* attributes, - ...) -{ - va_list vlist; - va_start(vlist, attributes); - auto api_error_result = migraphx::try_([&] { - *operation = object_cast( - allocate(migraphx::create_op((name), (attributes), (vlist)))); - }); - va_end(vlist); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_operation_name(char* out, size_t out_size, migraphx_operation_t operation) -{ - auto api_error_result = migraphx::try_([&] { - if(out == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter out: Null pointer"); - if(operation == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter operation: Null pointer"); - auto&& api_result = (operation->object).name(); - auto* it = std::copy_n(api_result.begin(), std::min(api_result.size(), out_size - 1), out); - *it = '\0'; - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_load(migraphx_program_t* out, const char* name, migraphx_file_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - *out = allocate(migraphx::load((name), (options->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_save(migraphx_program_t p, const char* name, migraphx_file_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(p == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter p: Null pointer"); - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - migraphx::save((p->object), (name), (options->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_onnx_options_destroy(migraphx_onnx_options_t onnx_options) -{ - auto api_error_result = migraphx::try_([&] { destroy((onnx_options)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_onnx_options_assign_to(migraphx_onnx_options_t output, - const_migraphx_onnx_options_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_onnx_options_create(migraphx_onnx_options_t* onnx_options) -{ - auto api_error_result = migraphx::try_([&] { - *onnx_options = object_cast(allocate()); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_onnx_options_set_input_parameter_shape( - migraphx_onnx_options_t onnx_options, const char* name, size_t* dims, size_t dims_size) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - if(dims == nullptr and dims_size != 0) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter dims: Null pointer"); - migraphx::set_input_parameter_shape( - (onnx_options->object), (name), (std::vector(dims, dims + dims_size))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_onnx_options_set_dyn_input_parameter_shape( - migraphx_onnx_options_t onnx_options, const char* name, migraphx_dynamic_dimensions_t dims) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - if(dims == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter dims: Null pointer"); - migraphx::set_dyn_input_parameter_shape((onnx_options->object), (name), (dims->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_onnx_options_set_default_dim_value(migraphx_onnx_options_t onnx_options, size_t value) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - migraphx::set_default_dim_value((onnx_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_onnx_options_set_default_dyn_dim_value(migraphx_onnx_options_t onnx_options, - const_migraphx_dynamic_dimension_t dd) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - if(dd == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter dd: Null pointer"); - migraphx::set_default_dyn_dim_value((onnx_options->object), (dd->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_onnx_options_set_default_loop_iterations(migraphx_onnx_options_t onnx_options, - int64_t value) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - migraphx::set_default_loop_iterations((onnx_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_onnx_options_set_limit_loop_iterations(migraphx_onnx_options_t onnx_options, int64_t value) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - migraphx::set_limit_loop_iterations((onnx_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_onnx_options_set_external_data_path(migraphx_onnx_options_t onnx_options, - const char* external_data_path) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - migraphx::set_external_data_path((onnx_options->object), (external_data_path)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_onnx_options_set_use_debug_symbols(migraphx_onnx_options_t onnx_options, bool value) -{ - auto api_error_result = migraphx::try_([&] { - if(onnx_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter onnx_options: Null pointer"); - migraphx::set_use_debug_symbols((onnx_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_file_options_destroy(migraphx_file_options_t file_options) -{ - auto api_error_result = migraphx::try_([&] { destroy((file_options)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_file_options_assign_to(migraphx_file_options_t output, - const_migraphx_file_options_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_file_options_create(migraphx_file_options_t* file_options) -{ - auto api_error_result = migraphx::try_([&] { - *file_options = object_cast(allocate()); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_file_options_set_file_format(migraphx_file_options_t file_options, const char* format) -{ - auto api_error_result = migraphx::try_([&] { - if(file_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter file_options: Null pointer"); - migraphx::set_file_format((file_options->object), (format)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_compile_options_destroy(migraphx_compile_options_t compile_options) -{ - auto api_error_result = migraphx::try_([&] { destroy((compile_options)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_compile_options_assign_to(migraphx_compile_options_t output, - const_migraphx_compile_options_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_compile_options_create(migraphx_compile_options_t* compile_options) -{ - auto api_error_result = migraphx::try_([&] { - *compile_options = - object_cast(allocate()); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_compile_options_set_offload_copy(migraphx_compile_options_t compile_options, bool value) -{ - auto api_error_result = migraphx::try_([&] { - if(compile_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter compile_options: Null pointer"); - migraphx::set_offload_copy((compile_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_compile_options_set_fast_math(migraphx_compile_options_t compile_options, bool value) -{ - auto api_error_result = migraphx::try_([&] { - if(compile_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter compile_options: Null pointer"); - migraphx::set_fast_math((compile_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_compile_options_set_exhaustive_tune_flag(migraphx_compile_options_t compile_options, - bool value) -{ - auto api_error_result = migraphx::try_([&] { - if(compile_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter compile_options: Null pointer"); - migraphx::set_exhaustive_tune_flag((compile_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_parse_onnx(migraphx_program_t* out, const char* name, migraphx_onnx_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - *out = allocate(migraphx::parse_onnx((name), (options->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_parse_onnx_buffer(migraphx_program_t* out, - const void* data, - size_t size, - migraphx_onnx_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - *out = allocate( - migraphx::parse_onnx_buffer((data), (size), (options->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_tf_options_destroy(migraphx_tf_options_t tf_options) -{ - auto api_error_result = migraphx::try_([&] { destroy((tf_options)); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_tf_options_assign_to(migraphx_tf_options_t output, - const_migraphx_tf_options_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_tf_options_create(migraphx_tf_options_t* tf_options) -{ - auto api_error_result = migraphx::try_([&] { - *tf_options = object_cast(allocate()); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_tf_options_set_nhwc(migraphx_tf_options_t tf_options, - bool is_nhwc) -{ - auto api_error_result = migraphx::try_([&] { - if(tf_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter tf_options: Null pointer"); - migraphx::set_nhwc((tf_options->object), (is_nhwc)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_tf_options_set_input_parameter_shape( - migraphx_tf_options_t tf_options, const char* name, size_t* dims, size_t dims_size) -{ - auto api_error_result = migraphx::try_([&] { - if(tf_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter tf_options: Null pointer"); - if(dims == nullptr and dims_size != 0) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter dims: Null pointer"); - migraphx::set_input_parameter_shape( - (tf_options->object), (name), (std::vector(dims, dims + dims_size))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_tf_options_set_default_dim_value(migraphx_tf_options_t tf_options, size_t value) -{ - auto api_error_result = migraphx::try_([&] { - if(tf_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter tf_options: Null pointer"); - migraphx::set_default_dim_value((tf_options->object), (value)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_tf_options_set_output_names(migraphx_tf_options_t tf_options, - const char** names, - size_t names_size) -{ - auto api_error_result = migraphx::try_([&] { - if(tf_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter tf_options: Null pointer"); - if(names == nullptr and names_size != 0) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter names: Null pointer"); - migraphx::set_output_names((tf_options->object), - (std::vector(names, names + names_size))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_parse_tf(migraphx_program_t* out, const char* name, migraphx_tf_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - *out = allocate(migraphx::parse_tf((name), (options->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_parse_tf_buffer(migraphx_program_t* out, - const void* data, - size_t size, - migraphx_tf_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - *out = allocate( - migraphx::parse_tf_buffer((data), (size), (options->object))); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_op_names_destroy(migraphx_quantize_op_names_t quantize_op_names) -{ - auto api_error_result = migraphx::try_([&] { destroy((quantize_op_names)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_op_names_assign_to(migraphx_quantize_op_names_t output, - const_migraphx_quantize_op_names_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_op_names_create(migraphx_quantize_op_names_t* quantize_op_names) -{ - auto api_error_result = migraphx::try_([&] { - *quantize_op_names = - object_cast(allocate>()); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_op_names_add(migraphx_quantize_op_names_t quantize_op_names, const char* name) -{ - auto api_error_result = migraphx::try_([&] { - if(quantize_op_names == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter quantize_op_names: Null pointer"); - (quantize_op_names->object).push_back((name)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_fp16_with_op_names(migraphx_program_t prog, - migraphx_quantize_op_names_t name) -{ - auto api_error_result = migraphx::try_([&] { - if(prog == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter prog: Null pointer"); - if(name == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter name: Null pointer"); - migraphx::quantize_fp16_with_op_names((prog->object), (name->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_fp16(migraphx_program_t prog) -{ - auto api_error_result = migraphx::try_([&] { - if(prog == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter prog: Null pointer"); - migraphx::quantize_fp16((prog->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_bf16_with_op_names(migraphx_program_t prog, - migraphx_quantize_op_names_t name) -{ - auto api_error_result = migraphx::try_([&] { - if(prog == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter prog: Null pointer"); - if(name == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter name: Null pointer"); - migraphx::quantize_bf16_with_op_names((prog->object), (name->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_bf16(migraphx_program_t prog) -{ - auto api_error_result = migraphx::try_([&] { - if(prog == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter prog: Null pointer"); - migraphx::quantize_bf16((prog->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_int8_options_destroy(migraphx_quantize_int8_options_t quantize_int8_options) -{ - auto api_error_result = migraphx::try_([&] { destroy((quantize_int8_options)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_int8_options_assign_to(migraphx_quantize_int8_options_t output, - const_migraphx_quantize_int8_options_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_int8_options_create(migraphx_quantize_int8_options_t* quantize_int8_options) -{ - auto api_error_result = migraphx::try_([&] { - *quantize_int8_options = object_cast( - allocate()); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_int8_options_add_op_name(migraphx_quantize_int8_options_t quantize_int8_options, - const char* name) -{ - auto api_error_result = migraphx::try_([&] { - if(quantize_int8_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter quantize_int8_options: Null pointer"); - migraphx::add_op_name((quantize_int8_options->object), (name)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_int8_options_add_calibration_data( - migraphx_quantize_int8_options_t quantize_int8_options, migraphx_program_parameters_t data) -{ - auto api_error_result = migraphx::try_([&] { - if(quantize_int8_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter quantize_int8_options: Null pointer"); - if(data == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter data: Null pointer"); - migraphx::add_calibration_data((quantize_int8_options->object), (data->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_int8(migraphx_program_t prog, - migraphx_target_t target, - migraphx_quantize_int8_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(prog == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter prog: Null pointer"); - if(target == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter target: Null pointer"); - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - migraphx::quantize_int8_wrap((prog->object), (target->object), (options->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_fp8_options_destroy(migraphx_quantize_fp8_options_t quantize_fp8_options) -{ - auto api_error_result = migraphx::try_([&] { destroy((quantize_fp8_options)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_fp8_options_assign_to(migraphx_quantize_fp8_options_t output, - const_migraphx_quantize_fp8_options_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_quantize_fp8_options_create(migraphx_quantize_fp8_options_t* quantize_fp8_options) -{ - auto api_error_result = migraphx::try_([&] { - *quantize_fp8_options = object_cast( - allocate()); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_fp8_options_add_calibration_data( - migraphx_quantize_fp8_options_t quantize_fp8_options, migraphx_program_parameters_t data) -{ - auto api_error_result = migraphx::try_([&] { - if(quantize_fp8_options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter quantize_fp8_options: Null pointer"); - if(data == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter data: Null pointer"); - migraphx::add_calibration_data((quantize_fp8_options->object), (data->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_quantize_fp8(migraphx_program_t prog, - migraphx_target_t target, - migraphx_quantize_fp8_options_t options) -{ - auto api_error_result = migraphx::try_([&] { - if(prog == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter prog: Null pointer"); - if(target == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter target: Null pointer"); - if(options == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer"); - migraphx::quantize_fp8_wrap((prog->object), (target->object), (options->object)); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_get_onnx_operator_name_at_index(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_([&] { - if(context == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter context: Null pointer"); - (context->object).finish(); - }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_context_get_queue(void** out, migraphx_context_t context) -{ - auto api_error_result = migraphx::try_([&] { - if(context == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter context: Null pointer"); - *out = (context->object).get_queue().unsafe_get(); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_experimental_custom_op_destroy(migraphx_experimental_custom_op_t experimental_custom_op) -{ - auto api_error_result = migraphx::try_([&] { destroy((experimental_custom_op)); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_experimental_custom_op_assign_to(migraphx_experimental_custom_op_t output, - const_migraphx_experimental_custom_op_t input) -{ - auto api_error_result = migraphx::try_([&] { *output = *input; }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_experimental_custom_op_create(migraphx_experimental_custom_op_t* experimental_custom_op, - void* obj, - migraphx_experimental_custom_op_copy c, - migraphx_experimental_custom_op_delete d, - const char* obj_typename, - const char* name) -{ - auto api_error_result = migraphx::try_([&] { - *experimental_custom_op = - allocate((obj), (c), (d), (obj_typename), (name)); - }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_experimental_custom_op_set_compute(migraphx_experimental_custom_op_t obj, - migraphx_experimental_custom_op_compute input) -{ - auto api_error_result = migraphx::try_([&] { (obj)->compute_f = (input); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_experimental_custom_op_set_compute_shape( - migraphx_experimental_custom_op_t obj, migraphx_experimental_custom_op_compute_shape input) -{ - auto api_error_result = migraphx::try_([&] { (obj)->compute_shape_f = (input); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_experimental_custom_op_set_output_alias(migraphx_experimental_custom_op_t obj, - migraphx_experimental_custom_op_output_alias input) -{ - auto api_error_result = migraphx::try_([&] { (obj)->output_alias_f = (input); }); - return api_error_result; -} - -extern "C" migraphx_status migraphx_experimental_custom_op_set_runs_on_offload_target( - migraphx_experimental_custom_op_t obj, - migraphx_experimental_custom_op_runs_on_offload_target input) -{ - auto api_error_result = migraphx::try_([&] { (obj)->runs_on_offload_target_f = (input); }); - return api_error_result; -} - -extern "C" migraphx_status -migraphx_experimental_custom_op_register(migraphx_experimental_custom_op_t experimental_custom_op) -{ - auto api_error_result = migraphx::try_([&] { - if(experimental_custom_op == nullptr) - MIGRAPHX_THROW(migraphx_status_bad_param, - "Bad parameter experimental_custom_op: Null pointer"); - migraphx::register_custom_op((*experimental_custom_op)); - }); - return api_error_result; -} diff --git a/src/api/include/migraphx/migraphx.h b/src/api/include/migraphx/migraphx.h deleted file mode 100644 index 254c8282672..00000000000 --- a/src/api/include/migraphx/migraphx.h +++ /dev/null @@ -1,736 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef MIGRAPHX_GUARD_C_API_MIGRAPHX_H -#define MIGRAPHX_GUARD_C_API_MIGRAPHX_H - -#include -#include -#include - -#include - -// Add new types here -// clang-format off -#define MIGRAPHX_SHAPE_VISIT_TYPES(m) \ - m(bool_type, bool) \ - m(half_type, half) \ - m(float_type, float) \ - m(double_type, double) \ - m(uint8_type, uint8_t) \ - m(int8_type, int8_t) \ - m(uint16_type, uint16_t) \ - m(int16_type, int16_t) \ - m(int32_type, int32_t) \ - m(int64_type, int64_t) \ - m(uint32_type, uint32_t) \ - m(uint64_type, uint64_t) \ - m(fp8e4m3fnuz_type, migraphx::fp8::fp8e4m3fnuz) \ - m(fp8e4m3fn_type, migraphx::fp8::fp8e4m3fn) \ - m(fp8e5m2_type, migraphx::fp8::fp8e5m2) \ - m(bf16_type, bf16) \ - m(fp8e5m2fnuz_type, migraphx::fp8::fp8e5m2fnuz) -// clang-format on - -#ifdef __cplusplus -extern "C" { -#endif - -// return code, more to be added later -typedef enum -{ - migraphx_status_success = 0, - migraphx_status_bad_param = 1, - migraphx_status_unknown_target = 3, - migraphx_status_unknown_error = 4, - -} migraphx_status; - -#define MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES(x, t) migraphx_shape_##x, -/// An enum to represent the different data type inputs -typedef enum -{ - migraphx_shape_tuple_type, - migraphx_shape_fp4x2_type, - MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES) -} migraphx_shape_datatype_t; -#undef MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES - -typedef struct migraphx_optimals* migraphx_optimals_t; -typedef const struct migraphx_optimals* const_migraphx_optimals_t; - -typedef struct migraphx_dynamic_dimension* migraphx_dynamic_dimension_t; -typedef const struct migraphx_dynamic_dimension* const_migraphx_dynamic_dimension_t; - -typedef struct migraphx_dynamic_dimensions* migraphx_dynamic_dimensions_t; -typedef const struct migraphx_dynamic_dimensions* const_migraphx_dynamic_dimensions_t; - -typedef struct migraphx_shape* migraphx_shape_t; -typedef const struct migraphx_shape* const_migraphx_shape_t; - -typedef struct migraphx_argument* migraphx_argument_t; -typedef const struct migraphx_argument* const_migraphx_argument_t; - -typedef struct migraphx_target* migraphx_target_t; -typedef const struct migraphx_target* const_migraphx_target_t; - -typedef struct migraphx_program_parameter_shapes* migraphx_program_parameter_shapes_t; -typedef const struct migraphx_program_parameter_shapes* const_migraphx_program_parameter_shapes_t; - -typedef struct migraphx_program_parameters* migraphx_program_parameters_t; -typedef const struct migraphx_program_parameters* const_migraphx_program_parameters_t; - -typedef struct migraphx_arguments* migraphx_arguments_t; -typedef const struct migraphx_arguments* const_migraphx_arguments_t; - -typedef struct migraphx_shapes* migraphx_shapes_t; -typedef const struct migraphx_shapes* const_migraphx_shapes_t; - -typedef struct migraphx_instruction* migraphx_instruction_t; -typedef const struct migraphx_instruction* const_migraphx_instruction_t; - -typedef struct migraphx_instructions* migraphx_instructions_t; -typedef const struct migraphx_instructions* const_migraphx_instructions_t; - -typedef struct migraphx_modules* migraphx_modules_t; -typedef const struct migraphx_modules* const_migraphx_modules_t; - -typedef struct migraphx_module* migraphx_module_t; -typedef const struct migraphx_module* const_migraphx_module_t; - -typedef struct migraphx_trace_info* migraphx_trace_info_t; -typedef const struct migraphx_trace_info* const_migraphx_trace_info_t; - -typedef migraphx_status (*migraphx_trace_callback_t)(migraphx_trace_info_t info, void* data); - -typedef struct migraphx_program* migraphx_program_t; -typedef const struct migraphx_program* const_migraphx_program_t; - -typedef struct migraphx_operation* migraphx_operation_t; -typedef const struct migraphx_operation* const_migraphx_operation_t; - -typedef struct migraphx_onnx_options* migraphx_onnx_options_t; -typedef const struct migraphx_onnx_options* const_migraphx_onnx_options_t; - -typedef struct migraphx_file_options* migraphx_file_options_t; -typedef const struct migraphx_file_options* const_migraphx_file_options_t; - -typedef struct migraphx_compile_options* migraphx_compile_options_t; -typedef const struct migraphx_compile_options* const_migraphx_compile_options_t; - -typedef struct migraphx_tf_options* migraphx_tf_options_t; -typedef const struct migraphx_tf_options* const_migraphx_tf_options_t; - -typedef struct migraphx_quantize_op_names* migraphx_quantize_op_names_t; -typedef const struct migraphx_quantize_op_names* const_migraphx_quantize_op_names_t; - -typedef struct migraphx_quantize_int8_options* migraphx_quantize_int8_options_t; -typedef const struct migraphx_quantize_int8_options* const_migraphx_quantize_int8_options_t; - -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_context* migraphx_context_t; -typedef const struct migraphx_context* const_migraphx_context_t; - -typedef struct migraphx_experimental_custom_op* migraphx_experimental_custom_op_t; -typedef const struct migraphx_experimental_custom_op* const_migraphx_experimental_custom_op_t; - -typedef migraphx_status (*migraphx_experimental_custom_op_compute)(migraphx_argument_t out, - void* obj, - char* exception_msg, - size_t exception_msg_size, - migraphx_context_t ctx, - migraphx_shape_t output, - migraphx_arguments_t inputs); - -typedef migraphx_status (*migraphx_experimental_custom_op_compute_shape)(migraphx_shape_t out, - void* obj, - char* exception_msg, - size_t exception_msg_size, - migraphx_shapes_t inputs); - -typedef migraphx_status (*migraphx_experimental_custom_op_output_alias)(size_t* out, - size_t* out_size, - void* obj, - char* exception_msg, - size_t exception_msg_size, - migraphx_shapes_t inputs); - -typedef migraphx_status (*migraphx_experimental_custom_op_runs_on_offload_target)( - bool* out, void* obj, char* exception_msg, size_t exception_msg_size); - -typedef migraphx_status (*migraphx_experimental_custom_op_copy)(void** out, void* input); - -typedef migraphx_status (*migraphx_experimental_custom_op_delete)(void* input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_optimals_destroy(migraphx_optimals_t optimals); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_optimals_assign_to(migraphx_optimals_t output, - const_migraphx_optimals_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_optimals_create(migraphx_optimals_t* optimals, - const size_t* ptr, - size_t size); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_dynamic_dimension_destroy(migraphx_dynamic_dimension_t dynamic_dimension); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_dynamic_dimension_assign_to( - migraphx_dynamic_dimension_t output, const_migraphx_dynamic_dimension_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_dynamic_dimension_create_min_max( - migraphx_dynamic_dimension_t* dynamic_dimension, size_t min, size_t max); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_dynamic_dimension_create_min_max_optimals(migraphx_dynamic_dimension_t* dynamic_dimension, - size_t min, - size_t max, - migraphx_optimals_t optimals); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_dynamic_dimension_is_fixed( - bool* out, const_migraphx_dynamic_dimension_t dynamic_dimension); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_dynamic_dimension_equal(bool* out, - const_migraphx_dynamic_dimension_t dynamic_dimension, - const_migraphx_dynamic_dimension_t x); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_dynamic_dimensions_destroy(migraphx_dynamic_dimensions_t dynamic_dimensions); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_dynamic_dimensions_assign_to( - migraphx_dynamic_dimensions_t output, const_migraphx_dynamic_dimensions_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_dynamic_dimensions_create(migraphx_dynamic_dimensions_t* dynamic_dimensions, - const const_migraphx_dynamic_dimension_t* ptr, - size_t size); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_dynamic_dimensions_size(size_t* out, migraphx_dynamic_dimensions_t dynamic_dimensions); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_dynamic_dimensions_get(const_migraphx_dynamic_dimension_t* out, - migraphx_dynamic_dimensions_t dynamic_dimensions, - size_t idx); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_destroy(migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_assign_to(migraphx_shape_t output, - const_migraphx_shape_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_create(migraphx_shape_t* shape, - migraphx_shape_datatype_t type, - size_t* lengths, - size_t lengths_size); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_create_with_strides(migraphx_shape_t* shape, - migraphx_shape_datatype_t type, - size_t* lengths, - size_t lengths_size, - size_t* strides, - size_t strides_size); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_create_scalar(migraphx_shape_t* shape, - migraphx_shape_datatype_t type); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_create_dynamic(migraphx_shape_t* shape, - migraphx_shape_datatype_t type, - migraphx_dynamic_dimensions_t dims); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_lengths(const size_t** out, - size_t* out_size, - const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_strides(const size_t** out, - size_t* out_size, - const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_dyn_dims(migraphx_dynamic_dimensions_t* out, - const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_type(migraphx_shape_datatype_t* out, - const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_elements(size_t* out, - const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_bytes(size_t* out, const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_ndim(size_t* out, const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_equal(bool* out, - const_migraphx_shape_t shape, - const_migraphx_shape_t x); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_standard(bool* out, const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_dynamic(bool* out, const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shape_index(size_t* out, - const_migraphx_shape_t shape, - size_t i); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_destroy(migraphx_argument_t argument); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_assign_to(migraphx_argument_t output, - const_migraphx_argument_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_create(migraphx_argument_t* argument, - const_migraphx_shape_t shape, - void* buffer); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_create_empty(migraphx_argument_t* argument, - const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_shape(const_migraphx_shape_t* out, - const_migraphx_argument_t argument); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_buffer(char** out, - const_migraphx_argument_t argument); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_equal(bool* out, - const_migraphx_argument_t argument, - const_migraphx_argument_t x); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_save(const_migraphx_argument_t a, - const char* filename); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_load(migraphx_argument_t* out, - const char* filename); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_argument_generate(migraphx_argument_t* out, - const_migraphx_shape_t s, - size_t seed); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_target_destroy(migraphx_target_t target); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_target_assign_to(migraphx_target_t output, - const_migraphx_target_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_target_create(migraphx_target_t* target, - const char* name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_parameter_shapes_destroy( - migraphx_program_parameter_shapes_t program_parameter_shapes); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_parameter_shapes_assign_to( - migraphx_program_parameter_shapes_t output, const_migraphx_program_parameter_shapes_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_parameter_shapes_size( - size_t* out, migraphx_program_parameter_shapes_t program_parameter_shapes); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_program_parameter_shapes_get(const_migraphx_shape_t* out, - migraphx_program_parameter_shapes_t program_parameter_shapes, - const char* name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_parameter_shapes_names( - const char** out, migraphx_program_parameter_shapes_t program_parameter_shapes); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_program_parameters_destroy(migraphx_program_parameters_t program_parameters); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_parameters_assign_to( - migraphx_program_parameters_t output, const_migraphx_program_parameters_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_program_parameters_create(migraphx_program_parameters_t* program_parameters); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_program_parameters_add(migraphx_program_parameters_t program_parameters, - const char* name, - const_migraphx_argument_t argument); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_arguments_destroy(migraphx_arguments_t arguments); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_arguments_assign_to(migraphx_arguments_t output, - const_migraphx_arguments_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_arguments_size(size_t* out, - migraphx_arguments_t arguments); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_arguments_get(const_migraphx_argument_t* out, - migraphx_arguments_t arguments, - size_t idx); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shapes_destroy(migraphx_shapes_t shapes); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shapes_assign_to(migraphx_shapes_t output, - const_migraphx_shapes_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shapes_size(size_t* out, migraphx_shapes_t shapes); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_shapes_get(const_migraphx_shape_t* out, - migraphx_shapes_t shapes, - size_t idx); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_instruction_destroy(migraphx_instruction_t instruction); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_instruction_assign_to(migraphx_instruction_t output, const_migraphx_instruction_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_instructions_destroy(migraphx_instructions_t instructions); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_instructions_assign_to( - migraphx_instructions_t output, const_migraphx_instructions_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_instructions_create( - migraphx_instructions_t* instructions, const const_migraphx_instruction_t* ptr, size_t size); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_modules_destroy(migraphx_modules_t modules); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_modules_assign_to(migraphx_modules_t output, - const_migraphx_modules_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_modules_create(migraphx_modules_t* modules, - migraphx_module_t* ptr, - size_t size); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_module_create(migraphx_module_t* module, char* name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_module_print(const_migraphx_module_t module); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_module_add_instruction(migraphx_instruction_t* out, - migraphx_module_t module, - migraphx_operation_t op, - migraphx_instructions_t args); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_module_add_instruction_with_mod_args(migraphx_instruction_t* out, - migraphx_module_t module, - migraphx_operation_t op, - migraphx_instructions_t args, - migraphx_modules_t module_refs); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_module_add_literal(migraphx_instruction_t* out, - migraphx_module_t module, - const_migraphx_shape_t shape, - const char* buffer); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_module_add_parameter(migraphx_instruction_t* out, - migraphx_module_t module, - const char* name, - const_migraphx_shape_t shape); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_module_add_return(migraphx_instruction_t* out, - migraphx_module_t module, - migraphx_instructions_t args); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_module_add_allocation(migraphx_instruction_t* out, - migraphx_module_t module, - const_migraphx_shape_t s); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_trace_info_destroy(migraphx_trace_info_t trace_info); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_trace_info_assign_to(migraphx_trace_info_t output, - const_migraphx_trace_info_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_trace_info_create(migraphx_trace_info_t* trace_info); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_trace_info_get_index(size_t* out, const_migraphx_trace_info_t trace_info); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_trace_info_get_name(const char** out, const_migraphx_trace_info_t trace_info); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_trace_info_get_result( - const_migraphx_argument_t* out, const_migraphx_trace_info_t trace_info); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_destroy(migraphx_program_t program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_assign_to(migraphx_program_t output, - const_migraphx_program_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_create(migraphx_program_t* program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_get_main_module(migraphx_module_t* out, - migraphx_program_t program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_create_module(migraphx_module_t* out, - migraphx_program_t program, - const char* name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_compile(migraphx_program_t program, - migraphx_target_t target, - migraphx_compile_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_get_parameter_shapes( - migraphx_program_parameter_shapes_t* out, migraphx_program_t program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_get_output_shapes(migraphx_shapes_t* out, - migraphx_program_t program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_print(const_migraphx_program_t program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_sort(migraphx_program_t program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_run(migraphx_arguments_t* out, - migraphx_program_t program, - migraphx_program_parameters_t params); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_run_async(migraphx_arguments_t* out, - migraphx_program_t program, - migraphx_program_parameters_t params, - void* s, - const char* name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_run_trace(migraphx_arguments_t* out, - migraphx_program_t program, - migraphx_program_parameters_t params, - migraphx_trace_callback_t callback, - void* data); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_equal(bool* out, - const_migraphx_program_t program, - const_migraphx_program_t x); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_program_experimental_get_context( - migraphx_context_t* out, const_migraphx_program_t program); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_operation_destroy(migraphx_operation_t operation); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_operation_assign_to(migraphx_operation_t output, - const_migraphx_operation_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_operation_create(migraphx_operation_t* operation, - const char* name, - const char* attributes, - ...); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_operation_name(char* out, - size_t out_size, - migraphx_operation_t operation); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_load(migraphx_program_t* out, - const char* name, - migraphx_file_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_save(migraphx_program_t p, - const char* name, - migraphx_file_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_onnx_options_destroy(migraphx_onnx_options_t onnx_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_onnx_options_assign_to( - migraphx_onnx_options_t output, const_migraphx_onnx_options_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_onnx_options_create(migraphx_onnx_options_t* onnx_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_onnx_options_set_input_parameter_shape( - migraphx_onnx_options_t onnx_options, const char* name, size_t* dims, size_t dims_size); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_onnx_options_set_dyn_input_parameter_shape( - migraphx_onnx_options_t onnx_options, const char* name, migraphx_dynamic_dimensions_t dims); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_onnx_options_set_default_dim_value(migraphx_onnx_options_t onnx_options, size_t value); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_onnx_options_set_default_dyn_dim_value( - migraphx_onnx_options_t onnx_options, const_migraphx_dynamic_dimension_t dd); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_onnx_options_set_default_loop_iterations( - migraphx_onnx_options_t onnx_options, int64_t value); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_onnx_options_set_limit_loop_iterations( - migraphx_onnx_options_t onnx_options, int64_t value); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_onnx_options_set_external_data_path( - migraphx_onnx_options_t onnx_options, const char* external_data_path); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_onnx_options_set_use_debug_symbols(migraphx_onnx_options_t onnx_options, bool value); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_file_options_destroy(migraphx_file_options_t file_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_file_options_assign_to( - migraphx_file_options_t output, const_migraphx_file_options_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_file_options_create(migraphx_file_options_t* file_options); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_file_options_set_file_format(migraphx_file_options_t file_options, const char* format); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_compile_options_destroy(migraphx_compile_options_t compile_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_compile_options_assign_to( - migraphx_compile_options_t output, const_migraphx_compile_options_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_compile_options_create(migraphx_compile_options_t* compile_options); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_compile_options_set_offload_copy(migraphx_compile_options_t compile_options, bool value); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_compile_options_set_fast_math(migraphx_compile_options_t compile_options, bool value); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_compile_options_set_exhaustive_tune_flag( - migraphx_compile_options_t compile_options, bool value); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_parse_onnx(migraphx_program_t* out, - const char* name, - migraphx_onnx_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_parse_onnx_buffer(migraphx_program_t* out, - const void* data, - size_t size, - migraphx_onnx_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_tf_options_destroy(migraphx_tf_options_t tf_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_tf_options_assign_to(migraphx_tf_options_t output, - const_migraphx_tf_options_t input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_tf_options_create(migraphx_tf_options_t* tf_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_tf_options_set_nhwc(migraphx_tf_options_t tf_options, - bool is_nhwc); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_tf_options_set_input_parameter_shape( - migraphx_tf_options_t tf_options, const char* name, size_t* dims, size_t dims_size); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_tf_options_set_default_dim_value(migraphx_tf_options_t tf_options, size_t value); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_tf_options_set_output_names( - migraphx_tf_options_t tf_options, const char** names, size_t names_size); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_parse_tf(migraphx_program_t* out, - const char* name, - migraphx_tf_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_parse_tf_buffer(migraphx_program_t* out, - const void* data, - size_t size, - migraphx_tf_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_op_names_destroy(migraphx_quantize_op_names_t quantize_op_names); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_op_names_assign_to( - migraphx_quantize_op_names_t output, const_migraphx_quantize_op_names_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_op_names_create(migraphx_quantize_op_names_t* quantize_op_names); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_op_names_add(migraphx_quantize_op_names_t quantize_op_names, const char* name); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_fp16_with_op_names(migraphx_program_t prog, migraphx_quantize_op_names_t name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp16(migraphx_program_t prog); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_bf16_with_op_names(migraphx_program_t prog, migraphx_quantize_op_names_t name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_bf16(migraphx_program_t prog); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_int8_options_destroy(migraphx_quantize_int8_options_t quantize_int8_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_int8_options_assign_to( - migraphx_quantize_int8_options_t output, const_migraphx_quantize_int8_options_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_int8_options_create(migraphx_quantize_int8_options_t* quantize_int8_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_int8_options_add_op_name( - migraphx_quantize_int8_options_t quantize_int8_options, const char* name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_int8_options_add_calibration_data( - migraphx_quantize_int8_options_t quantize_int8_options, migraphx_program_parameters_t data); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_int8(migraphx_program_t prog, - migraphx_target_t target, - migraphx_quantize_int8_options_t options); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_fp8_options_destroy(migraphx_quantize_fp8_options_t quantize_fp8_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp8_options_assign_to( - migraphx_quantize_fp8_options_t output, const_migraphx_quantize_fp8_options_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_quantize_fp8_options_create(migraphx_quantize_fp8_options_t* quantize_fp8_options); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_quantize_fp8_options_add_calibration_data( - migraphx_quantize_fp8_options_t quantize_fp8_options, migraphx_program_parameters_t data); - -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(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, - migraphx_context_t context); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_experimental_custom_op_destroy(migraphx_experimental_custom_op_t experimental_custom_op); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_experimental_custom_op_assign_to( - migraphx_experimental_custom_op_t output, const_migraphx_experimental_custom_op_t input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_experimental_custom_op_create(migraphx_experimental_custom_op_t* experimental_custom_op, - void* obj, - migraphx_experimental_custom_op_copy c, - migraphx_experimental_custom_op_delete d, - const char* obj_typename, - const char* name); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_experimental_custom_op_set_compute( - migraphx_experimental_custom_op_t obj, migraphx_experimental_custom_op_compute input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_experimental_custom_op_set_compute_shape( - migraphx_experimental_custom_op_t obj, migraphx_experimental_custom_op_compute_shape input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_experimental_custom_op_set_output_alias( - migraphx_experimental_custom_op_t obj, migraphx_experimental_custom_op_output_alias input); - -MIGRAPHX_C_EXPORT migraphx_status migraphx_experimental_custom_op_set_runs_on_offload_target( - migraphx_experimental_custom_op_t obj, - migraphx_experimental_custom_op_runs_on_offload_target input); - -MIGRAPHX_C_EXPORT migraphx_status -migraphx_experimental_custom_op_register(migraphx_experimental_custom_op_t experimental_custom_op); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/api/include/migraphx/migraphx.hpp b/src/api/include/migraphx/migraphx.hpp index beeebf20b86..36778ad03bf 100644 --- a/src/api/include/migraphx/migraphx.hpp +++ b/src/api/include/migraphx/migraphx.hpp @@ -24,7 +24,6 @@ #ifndef MIGRAPHX_GUARD_API_RTGLIB_MIGRAPHX_HPP #define MIGRAPHX_GUARD_API_RTGLIB_MIGRAPHX_HPP -#include "migraphx.h" #include #include #include @@ -1364,6 +1363,8 @@ inline void save(const program& p, const char* filename) call(&migraphx_save, p.get_handle_ptr(), filename, migraphx::file_options{}.get_handle_ptr()); } +#ifdef MIGRAPHX_ENABLE_ONNX + /// Options for parsing onnx options struct onnx_options : MIGRAPHX_HANDLE_BASE(onnx_options) { @@ -1481,6 +1482,10 @@ inline program parse_onnx_buffer(const std::string& buffer) own{}); } +#endif + +#ifdef MIGRAPHX_ENABLE_TENSORFLOW + /// Options for parsing tf options struct tf_options : MIGRAPHX_HANDLE_BASE(tf_options) { @@ -1571,6 +1576,8 @@ inline program parse_tf_buffer(const std::string& buffer) own{}); } +#endif + struct quantize_op_names : MIGRAPHX_HANDLE_BASE(quantize_op_names) { quantize_op_names() { this->make_handle(&migraphx_quantize_op_names_create); } diff --git a/src/api/migraphx.py b/src/api/migraphx.py index 50ac934925a..b38e2a7ee38 100644 --- a/src/api/migraphx.py +++ b/src/api/migraphx.py @@ -364,51 +364,66 @@ def operation(h): options='migraphx::file_options'), fname='migraphx::save') - -@auto_handle() -def onnx_options(h): - h.constructor('create') - h.method( - 'set_input_parameter_shape', - api.params(name='const char*', dims='std::vector'), - invoke='migraphx::set_input_parameter_shape($@)', - ) - h.method( - 'set_dyn_input_parameter_shape', - api.params(name='const char*', - dims='std::vector'), - invoke='migraphx::set_dyn_input_parameter_shape($@)', - ) - h.method( - 'set_default_dim_value', - api.params(value='size_t'), - invoke='migraphx::set_default_dim_value($@)', - ) - h.method( - 'set_default_dyn_dim_value', - api.params(dd='const migraphx::shape::dynamic_dimension&'), - invoke='migraphx::set_default_dyn_dim_value($@)', - ) - h.method( - 'set_default_loop_iterations', - api.params(value='int64_t'), - invoke='migraphx::set_default_loop_iterations($@)', - ) - h.method( - 'set_limit_loop_iterations', - api.params(value='int64_t'), - invoke='migraphx::set_limit_loop_iterations($@)', - ) - h.method( - 'set_external_data_path', - api.params(external_data_path='const char*'), - invoke='migraphx::set_external_data_path($@)', - ) - h.method( - 'set_use_debug_symbols', - api.params(value='bool'), - invoke='migraphx::set_use_debug_symbols($@)', - ) +if 'enable_onnx' in globals(): + @auto_handle() + def onnx_options(h): + h.constructor('create') + h.method( + 'set_input_parameter_shape', + api.params(name='const char*', dims='std::vector'), + invoke='migraphx::set_input_parameter_shape($@)', + ) + h.method( + 'set_dyn_input_parameter_shape', + api.params(name='const char*', + dims='std::vector'), + invoke='migraphx::set_dyn_input_parameter_shape($@)', + ) + h.method( + 'set_default_dim_value', + api.params(value='size_t'), + invoke='migraphx::set_default_dim_value($@)', + ) + h.method( + 'set_default_dyn_dim_value', + api.params(dd='const migraphx::shape::dynamic_dimension&'), + invoke='migraphx::set_default_dyn_dim_value($@)', + ) + h.method( + 'set_default_loop_iterations', + api.params(value='int64_t'), + invoke='migraphx::set_default_loop_iterations($@)', + ) + h.method( + 'set_limit_loop_iterations', + api.params(value='int64_t'), + invoke='migraphx::set_limit_loop_iterations($@)', + ) + h.method( + 'set_external_data_path', + api.params(external_data_path='const char*'), + invoke='migraphx::set_external_data_path($@)', + ) + h.method( + 'set_use_debug_symbols', + api.params(value='bool'), + invoke='migraphx::set_use_debug_symbols($@)', + ) + + + api.add_function('migraphx_parse_onnx', + api.params(name='const char*', + options='migraphx::onnx_options'), + fname='migraphx::parse_onnx', + returns='migraphx::program') + + + api.add_function('migraphx_parse_onnx_buffer', + api.params(data='const void*', + size='size_t', + options='migraphx::onnx_options'), + fname='migraphx::parse_onnx_buffer', + returns='migraphx::program') @auto_handle() @@ -433,57 +448,45 @@ def compile_options(h): invoke='migraphx::set_exhaustive_tune_flag($@)') -api.add_function('migraphx_parse_onnx', - api.params(name='const char*', - options='migraphx::onnx_options'), - fname='migraphx::parse_onnx', - returns='migraphx::program') - -api.add_function('migraphx_parse_onnx_buffer', - api.params(data='const void*', - size='size_t', - options='migraphx::onnx_options'), - fname='migraphx::parse_onnx_buffer', - returns='migraphx::program') - - -@auto_handle() -def tf_options(h): - h.constructor('create') - h.method( - 'set_nhwc', - api.params(is_nhwc='bool'), - invoke='migraphx::set_nhwc($@)', - ) - h.method( - 'set_input_parameter_shape', - api.params(name='const char*', dims='std::vector'), - invoke='migraphx::set_input_parameter_shape($@)', - ) - h.method( - 'set_default_dim_value', - api.params(value='size_t'), - invoke='migraphx::set_default_dim_value($@)', - ) - h.method( - 'set_output_names', - api.params(names='std::vector'), - invoke='migraphx::set_output_names($@)', - ) - - -api.add_function('migraphx_parse_tf', - api.params(name='const char*', - options='migraphx::tf_options'), - fname='migraphx::parse_tf', - returns='migraphx::program') - -api.add_function('migraphx_parse_tf_buffer', - api.params(data='const void*', - size='size_t', - options='migraphx::tf_options'), - fname='migraphx::parse_tf_buffer', - returns='migraphx::program') +if 'enable_tensorflow' in globals(): + @auto_handle() + def tf_options(h): + h.constructor('create') + h.method( + 'set_nhwc', + api.params(is_nhwc='bool'), + invoke='migraphx::set_nhwc($@)', + ) + h.method( + 'set_input_parameter_shape', + api.params(name='const char*', dims='std::vector'), + invoke='migraphx::set_input_parameter_shape($@)', + ) + h.method( + 'set_default_dim_value', + api.params(value='size_t'), + invoke='migraphx::set_default_dim_value($@)', + ) + h.method( + 'set_output_names', + api.params(names='std::vector'), + invoke='migraphx::set_output_names($@)', + ) + + + api.add_function('migraphx_parse_tf', + api.params(name='const char*', + options='migraphx::tf_options'), + fname='migraphx::parse_tf', + returns='migraphx::program') + + + api.add_function('migraphx_parse_tf_buffer', + api.params(data='const void*', + size='size_t', + options='migraphx::tf_options'), + fname='migraphx::parse_tf_buffer', + returns='migraphx::program') @api.handle('migraphx_quantize_op_names', 'std::vector') diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 00000000000..061994f08ac --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,30 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MIGRAPHX_GUARD_CONFIG_H +#define MIGRAPHX_GUARD_CONFIG_H + +#cmakedefine MIGRAPHX_ENABLE_ONNX +#cmakedefine MIGRAPHX_ENABLE_TENSORFLOW + +#endif // MIGRAPHX_GUARD_CONFIG_H diff --git a/src/driver/CMakeLists.txt b/src/driver/CMakeLists.txt index b48205d46fe..c65e14dba66 100644 --- a/src/driver/CMakeLists.txt +++ b/src/driver/CMakeLists.txt @@ -50,7 +50,7 @@ rocm_clang_tidy_check(driver) file(STRINGS "${CMAKE_SOURCE_DIR}/test/onnx/.onnxrt-commit" String_output) target_compile_definitions(driver PUBLIC MIGRAPHX_ORT_SHA1="${String_output}") -target_link_libraries(driver migraphx_all_targets migraphx_onnx migraphx_tf) +target_link_libraries(driver migraphx_all_targets migraphx_all_frontends) if(MIGRAPHX_ENABLE_PYTHON) target_link_libraries(driver migraphx_py) diff --git a/src/driver/main.cpp b/src/driver/main.cpp index 5f1ed5669f3..a08554e5723 100644 --- a/src/driver/main.cpp +++ b/src/driver/main.cpp @@ -35,8 +35,12 @@ #include "models.hpp" #include "marker_roctx.hpp" +#ifdef MIGRAPHX_ENABLE_TENSORFLOW #include +#endif +#ifdef MIGRAPHX_ENABLE_ONNX #include +#endif #ifdef MIGRAPHX_ENABLE_PYTHON #include #endif @@ -201,8 +205,12 @@ struct loader ap.help("Run a single GEMM to test MIGraphX"), ap.set_value(true), ap.group("input")); +#ifdef MIGRAPHX_ENABLE_ONNX ap(file_type, {"--onnx"}, ap.help("Load as onnx"), ap.set_value("onnx")); +#endif +#ifdef MIGRAPHX_ENABLE_TENSORFLOW ap(file_type, {"--tf"}, ap.help("Load as tensorflow"), ap.set_value("tf")); +#endif ap(file_type, {"--migraphx"}, ap.help("Load as MIGraphX"), ap.set_value("migraphx")); ap(file_type, {"--migraphx-json"}, ap.help("Load as MIGraphX JSON"), ap.set_value("json")); ap(batch, @@ -383,6 +391,7 @@ struct loader return output_node_names; } +#ifdef MIGRAPHX_ENABLE_TENSORFLOW tf_options get_tf_options() const { auto map_input_dims = parse_param_dims(param_dims); @@ -394,7 +403,9 @@ struct loader options.output_node_names = output_node_names; return options; } +#endif +#ifdef MIGRAPHX_ENABLE_ONNX onnx_options get_onnx_options() const { auto map_input_dims = parse_param_dims(param_dims); @@ -418,17 +429,24 @@ struct loader options.dim_params = map_dim_params; return options; } +#endif static std::string get_file_type(const std::string& file) { - if(ends_with(file, ".onnx")) + if(ends_with(file, ".json")) + return "json"; +#ifdef MIGRAPHX_ENABLE_ONNX + else if(ends_with(file, ".onnx")) return "onnx"; +#endif +#ifdef MIGRAPHX_ENABLE_TENSORFLOW else if(ends_with(file, ".pb")) return "tf"; - else if(ends_with(file, ".json")) - return "json"; +#endif +#ifdef MIGRAPHX_ENABLE_PYTHON else if(ends_with(file, ".py")) return "py"; +#endif else return "migraphx"; } @@ -447,20 +465,24 @@ struct loader file_type = get_file_type(file); } log::info() << "Reading: " << file; - if(file_type == "onnx") + if(file_type == "json") + { + file_options options; + options.format = "json"; + p = migraphx::load(file, options); + } +#ifdef MIGRAPHX_ENABLE_ONNX + else if(file_type == "onnx") { p = parse_onnx(file, get_onnx_options()); } +#endif +#ifdef MIGRAPHX_ENABLE_TENSORFLOW else if(file_type == "tf") { p = parse_tf(file, get_tf_options()); } - else if(file_type == "json") - { - file_options options; - options.format = "json"; - p = migraphx::load(file, options); - } +#endif #ifdef MIGRAPHX_ENABLE_PYTHON else if(file_type == "py") { @@ -985,6 +1007,8 @@ struct op : command } }; +#ifdef MIGRAPHX_ENABLE_ONNX + struct onnx : command { bool show_ops = false; @@ -1005,6 +1029,10 @@ struct onnx : command } }; +#endif + +#ifdef MIGRAPHX_ENABLE_TENSORFLOW + struct tf : command { bool show_ops = false; @@ -1025,6 +1053,8 @@ struct tf : command } }; +#endif + struct main_command { static std::string get_command_help(const std::string& title = colorize(color::fg_yellow, diff --git a/src/include/migraphx/config.hpp b/src/include/migraphx/config.hpp index aba8cee534b..6e36a7a6d2d 100644 --- a/src/include/migraphx/config.hpp +++ b/src/include/migraphx/config.hpp @@ -24,6 +24,7 @@ #ifndef MIGRAPHX_GUARD_CONFIG_HPP #define MIGRAPHX_GUARD_CONFIG_HPP +#include #include #include diff --git a/src/py/CMakeLists.txt b/src/py/CMakeLists.txt index 32da2c08bea..e3e4ed567ef 100644 --- a/src/py/CMakeLists.txt +++ b/src/py/CMakeLists.txt @@ -1,7 +1,7 @@ ##################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -32,7 +32,7 @@ include(PythonModules) foreach(PYTHON_VERSION ${PYTHON_VERSIONS}) py_add_module(migraphx_pybind_${PYTHON_VERSION} migraphx_py.cpp PYTHON_VERSION ${PYTHON_VERSION} PYTHON_MODULE migraphx) - target_link_libraries(migraphx_pybind_${PYTHON_VERSION} PRIVATE migraphx migraphx_tf migraphx_onnx migraphx_all_targets) + target_link_libraries(migraphx_pybind_${PYTHON_VERSION} PRIVATE migraphx migraphx_all_frontends migraphx_all_targets) rocm_install_targets(TARGETS migraphx_pybind_${PYTHON_VERSION}) add_dependencies(migraphx_py migraphx_pybind_${PYTHON_VERSION}) diff --git a/src/py/migraphx_py.cpp b/src/py/migraphx_py.cpp index ccd4321028a..abdd37b6224 100644 --- a/src/py/migraphx_py.cpp +++ b/src/py/migraphx_py.cpp @@ -35,8 +35,6 @@ #include #include #include -#include -#include #include #include #include @@ -50,6 +48,12 @@ #ifdef HAVE_GPU #include #endif +#ifdef MIGRAPHX_ENABLE_TENSORFLOW +#include +#endif +#ifdef MIGRAPHX_ENABLE_ONNX +#include +#endif using half = migraphx::half; namespace py = pybind11; @@ -655,6 +659,7 @@ MIGRAPHX_PYBIND11_MODULE(migraphx, m) py::arg("shape"), py::arg("address")); +#ifdef MIGRAPHX_ENABLE_TENSORFLOW m.def( "parse_tf", [](const std::string& filename, @@ -671,7 +676,9 @@ MIGRAPHX_PYBIND11_MODULE(migraphx, m) py::arg("batch_size") = 1, py::arg("map_input_dims") = std::unordered_map>(), py::arg("output_names") = std::vector()); +#endif +#ifdef MIGRAPHX_ENABLE_ONNX m.def("get_onnx_operators", [] { return migraphx::get_onnx_operators(); }); m.def( "parse_onnx", @@ -749,6 +756,7 @@ MIGRAPHX_PYBIND11_MODULE(migraphx, m) py::arg("print_program_on_error") = false, py::arg("external_data_path") = "", py::arg("use_debug_symbols") = false); +#endif m.def( "load", diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 458c2426c34..619cf839e67 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,7 +25,7 @@ cmake_policy(SET CMP0057 NEW) find_package(Threads REQUIRED) -rocm_test_link_libraries(Threads::Threads migraphx migraphx_onnx migraphx_tf) +rocm_test_link_libraries(Threads::Threads migraphx migraphx_all_frontends) rocm_test_include_directories(include) set(MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS Off CACHE BOOL "") @@ -99,12 +99,16 @@ if(MIGRAPHX_ENABLE_FPGA) endif() # Onnx test +if(MIGRAPHX_ENABLE_ONNX) set(TEST_ONNX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/onnx) add_subdirectory(onnx) +endif() # tf test +if(MIGRAPHX_ENABLE_TENSORFLOW) set(TEST_TF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tf) add_subdirectory(tf) +endif() add_subdirectory(api) add_subdirectory(verify) @@ -128,7 +132,7 @@ if(MIGRAPHX_ENABLE_GPU AND MIGRAPHX_ENABLE_CPU AND MIGRAPHX_ENABLE_FPGA) set(TEST_NAME test_${BASE_NAME}) add_executable(${TEST_NAME} ${MULTI_TARGET_TEST}) rocm_clang_tidy_check(${TEST_NAME}) - target_link_libraries(${TEST_NAME} migraphx migraphx_onnx migraphx_tf migraphx_all_targets register_targets) + target_link_libraries(${TEST_NAME} migraphx migraphx_all_frontends migraphx_all_targets register_targets) target_include_directories(${TEST_NAME} PUBLIC include) add_test(NAME ${TEST_NAME} COMMAND $ WORKING_DIRECTORY ${TEST_MULTI_TARGET_DIR}) rocm_mark_as_test(${TEST_NAME}) @@ -161,12 +165,18 @@ function(test_headers PREFIX) ${CMAKE_SOURCE_DIR}/src/targets/gpu/include/migraphx/gpu/ck.hpp) endif() list(REMOVE_ITEM HEADERS ${CMAKE_SOURCE_DIR}/src/include/migraphx/float8_impl.hpp) + if(NOT MIGRAPHX_ENABLE_TENSORFLOW) + list(REMOVE_ITEM HEADERS ${CMAKE_SOURCE_DIR}/src/include/migraphx/tf.hpp) + endif() + if(NOT MIGRAPHX_ENABLE_ONNX) + list(REMOVE_ITEM HEADERS ${CMAKE_SOURCE_DIR}/src/include/migraphx/onnx.hpp) + endif() foreach(HEADER ${HEADERS}) file(RELATIVE_PATH HEADER_REL ${CMAKE_SOURCE_DIR} ${HEADER}) string(MAKE_C_IDENTIFIER ${HEADER_REL} TEST_NAME) get_filename_component(BASE_NAME ${HEADER} NAME_WE) test_header(header_${TEST_NAME} ${PREFIX}/${BASE_NAME}.hpp) - target_link_libraries(header_${TEST_NAME} migraphx migraphx_onnx migraphx_tf migraphx_all_targets register_targets) + target_link_libraries(header_${TEST_NAME} migraphx migraphx_all_frontends migraphx_all_targets register_targets) endforeach() endfunction() diff --git a/test/api/CMakeLists.txt b/test/api/CMakeLists.txt index 61d4211b576..eadbf99b2d2 100644 --- a/test/api/CMakeLists.txt +++ b/test/api/CMakeLists.txt @@ -25,8 +25,14 @@ function(add_api_test TEST_NAME TEST_SRC TEST_DIR) set(NAME test_api_${TEST_NAME}) add_executable(${NAME} EXCLUDE_FROM_ALL ${TEST_SRC}) rocm_clang_tidy_check(${NAME}) - target_link_libraries(${NAME} migraphx_c migraphx migraphx_all_targets onnx_files pb_files) - target_include_directories(${NAME} PUBLIC ../include include) + target_link_libraries(${NAME} migraphx_c migraphx migraphx_all_targets) + if(MIGRAPHX_ENABLE_ONNX) + target_link_libraries(${NAME} onnx_files) + endif() + if(MIGRAPHX_ENABLE_TENSORFLOW) + target_link_libraries(${NAME} pb_files) + endif() + target_include_directories(${NAME} PUBLIC ../include include ${PROJECT_BINARY_DIR}/src/include) add_test(NAME ${NAME} COMMAND $ WORKING_DIRECTORY ${TEST_DIR}) add_dependencies(tests ${NAME}) add_dependencies(check ${NAME}) @@ -43,7 +49,7 @@ function(add_c_api_test TEST_NAME TEST_SRC TEST_DIR) set(NAME test_api_${TEST_NAME}) add_executable(${NAME} EXCLUDE_FROM_ALL ${TEST_SRC}) target_link_libraries(${NAME} migraphx_c) - target_include_directories(${NAME} PUBLIC ../include) + target_include_directories(${NAME} PUBLIC ../include ${PROJECT_BINARY_DIR}/src/include) add_test(NAME ${NAME} COMMAND $ WORKING_DIRECTORY ${TEST_DIR}) add_dependencies(tests ${NAME}) add_dependencies(check ${NAME}) @@ -53,6 +59,7 @@ function(add_c_api_test TEST_NAME TEST_SRC TEST_DIR) endif() endfunction() +if(MIGRAPHX_ENABLE_ONNX) add_api_test(array_base test_array_base.cpp ${TEST_ONNX_DIR}) add_api_test(assign test_assign.cpp ${TEST_ONNX_DIR}) add_api_test(compile_options test_compile_options.cpp ${TEST_ONNX_DIR}) @@ -64,11 +71,14 @@ add_api_test(save_load test_save_load.cpp ${TEST_ONNX_DIR}) add_api_test(op test_op_construct.cpp ${TEST_ONNX_DIR}) add_c_api_test(c_op test_c_op_construct.c ${TEST_ONNX_DIR}) add_api_test(custom_op test_custom_op.cpp ${TEST_ONNX_DIR}) -add_api_test(tf_parser test_tf_parser.cpp ${TEST_TF_DIR}) add_api_test(onnx_op_list test_onnx_op_list.cpp ${TEST_ONNX_DIR}) add_api_test(trace_callback test_trace_callback.cpp ${TEST_ONNX_DIR}) +endif() +if(MIGRAPHX_ENABLE_PYTHON AND MIGRAPHX_ENABLE_TENSORFLOW) +add_api_test(tf_parser test_tf_parser.cpp ${TEST_TF_DIR}) +endif() # GPU-based tests -if(MIGRAPHX_ENABLE_GPU) +if(MIGRAPHX_ENABLE_GPU AND MIGRAPHX_ENABLE_ONNX) add_api_test(gpu test_gpu.cpp ${TEST_ONNX_DIR}) add_api_test(custom_op_gpu test_custom_op_gpu.cpp ${TEST_ONNX_DIR}) endif() diff --git a/test/py/CMakeLists.txt b/test/py/CMakeLists.txt index 68354f111a4..7d7da7cc0db 100644 --- a/test/py/CMakeLists.txt +++ b/test/py/CMakeLists.txt @@ -31,6 +31,10 @@ set(PYTHON_VERSION_TO_DISABLE_ONNX 3.6) option(MIGRAPHX_DISABLE_VIRTUAL_ENV "Disable python virtual environments" OFF) option(MIGRAPHX_DISABLE_ONNX_TESTS "Disable Onnx backend tests" OFF) +if(NOT MIGRAPHX_ENABLE_ONNX AND NOT MIGRAPHX_DISABLE_ONNX_TESTS) + message(NOTICE "ONNX frontend disabled, hence turning off building the tests") + set(MIGRAPHX_DISABLE_ONNX_TESTS ON CACHE BOOL "" FORCE) +endif() function(add_py_venv_fixture FIXTURE_NAME VIRTUAL_ENV_DIR REQUIREMENTS_FILE) foreach(PYTHON_VERSION ${PYTHON_VERSIONS}) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt deleted file mode 100644 index 00a2a34fbb9..00000000000 --- a/tools/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -##################################################################################### -# The MIT License (MIT) -# -# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -##################################################################################### - -find_package(Python 3 COMPONENTS Interpreter) -if(NOT Python_EXECUTABLE) - message(WARNING "Python 3 interpreter not found - skipping 'generate' target!") - return() -endif() - -find_program(CLANG_FORMAT clang-format PATHS /opt/rocm/llvm ENV HIP_PATH PATH_SUFFIXES bin) -if(NOT CLANG_FORMAT) - message(WARNING "clang-format not found - skipping 'generate' target!") - return() -endif() - -add_custom_target(generate ${Python_EXECUTABLE} generate.py -f ${CLANG_FORMAT} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tools/api/api.cpp b/tools/api/api.cpp index 79f5785357e..8c250e396ff 100644 --- a/tools/api/api.cpp +++ b/tools/api/api.cpp @@ -27,8 +27,6 @@ #include #include #include -#include -#include #include #include #include @@ -46,6 +44,13 @@ #include #include +#ifdef MIGRAPHX_ENABLE_ONNX +#include +#endif +#ifdef MIGRAPHX_ENABLE_TENSORFLOW +#include +#endif + namespace migraphx { #ifdef MIGRAPHX_BUILD_TESTING @@ -156,6 +161,8 @@ static void set_exhaustive_tune_flag(compile_options& options, bool value) static void set_file_format(file_options& options, const char* format) { options.format = format; } +#ifdef MIGRAPHX_ENABLE_ONNX + static void set_default_dim_value(onnx_options& options, size_t value) { options.default_dim_value = value; @@ -186,10 +193,18 @@ static void set_use_debug_symbols(onnx_options& options, bool value) options.use_debug_symbols = value; } +#endif + +#ifdef MIGRAPHX_ENABLE_TENSORFLOW + static void set_nhwc(tf_options& options, bool is_nhwc) { options.is_nhwc = is_nhwc; } static void set_default_dim_value(tf_options& options, size_t value) { options.batch_size = value; } +#endif + +#ifdef MIGRAPHX_ENABLE_ONNX + static void set_input_parameter_shape(onnx_options& options, const char* name, std::vector dims) { @@ -203,6 +218,10 @@ static void set_dyn_input_parameter_shape(onnx_options& options, options.map_dyn_input_dims[std::string(name)] = std::move(dyn_dims); } +#endif + +#ifdef MIGRAPHX_ENABLE_TENSORFLOW + static void set_input_parameter_shape(tf_options& options, const char* name, std::vector dims) { @@ -214,6 +233,8 @@ static void set_output_names(tf_options& options, std::vector names options.output_node_names = std::vector(names.begin(), names.end()); } +#endif + static std::vector run_async(program& p, const parameter_map& params, void* s, std::string_view name) { diff --git a/tools/api/migraphx.h b/tools/api/migraphx.h index 263dacd0160..e33dce1b49f 100644 --- a/tools/api/migraphx.h +++ b/tools/api/migraphx.h @@ -29,6 +29,7 @@ #include #include +#include // Add new types here // clang-format off diff --git a/tools/generate.py b/tools/generate.py index c776cbc0399..924f221b8cd 100644 --- a/tools/generate.py +++ b/tools/generate.py @@ -1,7 +1,7 @@ ##################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -21,32 +21,36 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. ##################################################################################### -import api, argparse, os, runpy, subprocess, sys, te +import api, argparse, runpy, subprocess, sys, te from pathlib import Path -clang_format_path = Path('clang-format.exe' if os.name == - 'nt' else '/opt/rocm/llvm/bin/clang-format') +clang_format_path = None + work_dir = Path().cwd() -src_dir = (work_dir / '../src').absolute() +src_dir = work_dir.parent / 'src' migraphx_py_path = src_dir / 'api/migraphx.py' def clang_format(buffer, **kwargs): - return subprocess.run(f'{clang_format_path} -style=file', - capture_output=True, - shell=True, - check=True, - input=buffer.encode('utf-8'), - cwd=work_dir, - **kwargs).stdout.decode('utf-8') + if clang_format_path is not None: + return subprocess.run(f'{clang_format_path} -style=file', + capture_output=True, + shell=True, + check=True, + input=buffer.encode('utf-8'), + cwd=work_dir, + **kwargs).stdout.decode('utf-8') + return buffer def api_generate(input_path: Path, output_path: Path): + output_path.parent.mkdir(parents=True, exist_ok=True) with open(output_path, 'w') as f: f.write(clang_format(api.run(input_path))) def te_generate(input_path: Path, output_path: Path): + output_path.parent.mkdir(parents=True, exist_ok=True) with open(output_path, 'w') as f: f.write(clang_format(te.run(input_path))) @@ -54,26 +58,40 @@ def te_generate(input_path: Path, output_path: Path): def main(): parser = argparse.ArgumentParser() parser.add_argument('-f', '--clang-format', type=Path) + parser.add_argument('-D', '--define', type=str, action='append', choices=['enable_onnx', 'enable_tensorflow'] ) + parser.add_argument('-o', '--output-directory', type=Path) args = parser.parse_args() + output_dir = args.output_directory \ + if args.output_directory is not None else src_dir + global clang_format_path if args.clang_format: clang_format_path = args.clang_format - if not clang_format_path.is_file(): + if clang_format_path is not None and not clang_format_path.is_file(): print(f"{clang_format_path}: invalid path or not installed", file=sys.stderr) return + defines = {} + if args.define is not None: + for d in args.define: + if '=' in d: + p = d.split('=') + defines[p[0]] = p[1] + else: + defines[d] = '' + try: files = Path('include').absolute().iterdir() for f in [f for f in files if f.is_file()]: - te_generate(f, src_dir / f'include/migraphx/{f.name}') - runpy.run_path(str(migraphx_py_path)) + te_generate(f, output_dir / f'include/migraphx/{f.name}') + runpy.run_path(str(migraphx_py_path), init_globals=defines) api_generate(work_dir / 'api/migraphx.h', - src_dir / 'api/include/migraphx/migraphx.h') + output_dir / 'include/migraphx/migraphx.h') print('Finished generating header migraphx.h') - api_generate(work_dir / 'api/api.cpp', src_dir / 'api/api.cpp') + api_generate(work_dir / 'api/api.cpp', output_dir / 'api/api.cpp') print('Finished generating source api.cpp') except subprocess.CalledProcessError as ex: if ex.stdout: