"host/vscode:/vscode.git/clone" did not exist on "245f741457a7f258c74168992efa9f0683e24753"
Unverified Commit 31dc067e authored by Umang Yadav's avatar Umang Yadav Committed by GitHub
Browse files

Make `file_options` an opaque object for ABI compatibility (#953)



make file_options struct an opaque object for ABI compatibility, uses make generate to auto-generate and includes  modified tests.
Co-authored-by: default avatarPaul Fultz II <pfultz2@yahoo.com>
parent a275f590
#include <migraphx/operation.hpp>
#include <migraphx/migraphx.h> #include <migraphx/migraphx.h>
#include <migraphx/rank.hpp> #include <migraphx/rank.hpp>
#include <migraphx/shape.hpp> #include <migraphx/shape.hpp>
...@@ -81,12 +82,7 @@ migraphx::compile_options to_compile_options(const migraphx_compile_options& opt ...@@ -81,12 +82,7 @@ migraphx::compile_options to_compile_options(const migraphx_compile_options& opt
return result; return result;
} }
migraphx::file_options to_file_options(const migraphx_file_options& options) void set_file_format(file_options& options, const char* format) { options.format = format; }
{
migraphx::file_options result{};
result.format = options.format;
return result;
}
void set_default_dim_value(onnx_options& options, size_t value) void set_default_dim_value(onnx_options& options, size_t value)
{ {
...@@ -325,6 +321,16 @@ struct migraphx_onnx_options ...@@ -325,6 +321,16 @@ struct migraphx_onnx_options
migraphx::onnx_options object; migraphx::onnx_options object;
}; };
extern "C" struct migraphx_file_options;
struct migraphx_file_options
{
template <class... Ts>
migraphx_file_options(Ts&&... xs) : object(std::forward<Ts>(xs)...)
{
}
migraphx::file_options object;
};
extern "C" struct migraphx_tf_options; extern "C" struct migraphx_tf_options;
struct migraphx_tf_options struct migraphx_tf_options
{ {
...@@ -791,25 +797,24 @@ migraphx_operation_name(char* out, size_t out_size, migraphx_operation_t operati ...@@ -791,25 +797,24 @@ migraphx_operation_name(char* out, size_t out_size, migraphx_operation_t operati
} }
extern "C" migraphx_status extern "C" migraphx_status
migraphx_load(migraphx_program_t* out, const char* name, migraphx_file_options* options) migraphx_load(migraphx_program_t* out, const char* name, migraphx_file_options_t options)
{ {
return migraphx::try_([&] { return migraphx::try_([&] {
*out = allocate<migraphx_program_t>(migraphx::load( if(options == nullptr)
(name), MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer");
(options == nullptr ? migraphx::file_options{} : migraphx::to_file_options(*options)))); *out = allocate<migraphx_program_t>(migraphx::load((name), (options->object)));
}); });
} }
extern "C" migraphx_status extern "C" migraphx_status
migraphx_save(migraphx_program_t p, const char* name, migraphx_file_options* options) migraphx_save(migraphx_program_t p, const char* name, migraphx_file_options_t options)
{ {
return migraphx::try_([&] { return migraphx::try_([&] {
if(p == nullptr) if(p == nullptr)
MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter p: Null pointer"); MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter p: Null pointer");
migraphx::save( if(options == nullptr)
(p->object), MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter options: Null pointer");
(name), migraphx::save((p->object), (name), (options->object));
(options == nullptr ? migraphx::file_options{} : migraphx::to_file_options(*options)));
}); });
} }
...@@ -848,6 +853,28 @@ migraphx_onnx_options_set_default_dim_value(migraphx_onnx_options_t onnx_options ...@@ -848,6 +853,28 @@ migraphx_onnx_options_set_default_dim_value(migraphx_onnx_options_t onnx_options
}); });
} }
extern "C" migraphx_status migraphx_file_options_destroy(migraphx_file_options_t file_options)
{
return migraphx::try_([&] { destroy((file_options)); });
}
extern "C" migraphx_status migraphx_file_options_create(migraphx_file_options_t* file_options)
{
return migraphx::try_([&] {
*file_options = object_cast<migraphx_file_options_t>(allocate<migraphx::file_options>());
});
}
extern "C" migraphx_status
migraphx_file_options_set_file_format(migraphx_file_options_t file_options, const char* format)
{
return 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));
});
}
extern "C" migraphx_status extern "C" migraphx_status
migraphx_onnx_options_set_default_loop_iterations(migraphx_onnx_options_t onnx_options, migraphx_onnx_options_set_default_loop_iterations(migraphx_onnx_options_t onnx_options,
int64_t value) int64_t value)
......
...@@ -54,13 +54,6 @@ typedef struct ...@@ -54,13 +54,6 @@ typedef struct
bool fast_math; bool fast_math;
} migraphx_compile_options; } migraphx_compile_options;
/// Options for saving and loading files
typedef struct
{
/// Format to be used for file. It can either be json or msgpack
const char* format;
} migraphx_file_options;
typedef struct migraphx_shape* migraphx_shape_t; typedef struct migraphx_shape* migraphx_shape_t;
typedef const struct migraphx_shape* const_migraphx_shape_t; typedef const struct migraphx_shape* const_migraphx_shape_t;
...@@ -94,6 +87,9 @@ typedef const struct migraphx_operation* const_migraphx_operation_t; ...@@ -94,6 +87,9 @@ typedef const struct migraphx_operation* const_migraphx_operation_t;
typedef struct migraphx_onnx_options* migraphx_onnx_options_t; typedef struct migraphx_onnx_options* migraphx_onnx_options_t;
typedef const struct migraphx_onnx_options* const_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_tf_options* migraphx_tf_options_t; typedef struct migraphx_tf_options* migraphx_tf_options_t;
typedef const struct migraphx_tf_options* const_migraphx_tf_options_t; typedef const struct migraphx_tf_options* const_migraphx_tf_options_t;
...@@ -228,10 +224,10 @@ migraphx_status migraphx_operation_create(migraphx_operation_t* operation, ...@@ -228,10 +224,10 @@ migraphx_status migraphx_operation_create(migraphx_operation_t* operation,
migraphx_status migraphx_operation_name(char* out, size_t out_size, migraphx_operation_t operation); migraphx_status migraphx_operation_name(char* out, size_t out_size, migraphx_operation_t operation);
migraphx_status migraphx_status
migraphx_load(migraphx_program_t* out, const char* name, migraphx_file_options* options); migraphx_load(migraphx_program_t* out, const char* name, migraphx_file_options_t options);
migraphx_status migraphx_status
migraphx_save(migraphx_program_t p, const char* name, migraphx_file_options* options); migraphx_save(migraphx_program_t p, const char* name, migraphx_file_options_t options);
migraphx_status migraphx_onnx_options_destroy(migraphx_onnx_options_t onnx_options); migraphx_status migraphx_onnx_options_destroy(migraphx_onnx_options_t onnx_options);
...@@ -243,6 +239,13 @@ migraphx_status migraphx_onnx_options_set_input_parameter_shape( ...@@ -243,6 +239,13 @@ migraphx_status migraphx_onnx_options_set_input_parameter_shape(
migraphx_status migraphx_onnx_options_set_default_dim_value(migraphx_onnx_options_t onnx_options, migraphx_status migraphx_onnx_options_set_default_dim_value(migraphx_onnx_options_t onnx_options,
size_t value); size_t value);
migraphx_status migraphx_file_options_destroy(migraphx_file_options_t file_options);
migraphx_status migraphx_file_options_create(migraphx_file_options_t* file_options);
migraphx_status migraphx_file_options_set_file_format(migraphx_file_options_t file_options,
const char* format);
migraphx_status migraphx_status
migraphx_onnx_options_set_default_loop_iterations(migraphx_onnx_options_t onnx_options, migraphx_onnx_options_set_default_loop_iterations(migraphx_onnx_options_t onnx_options,
int64_t value); int64_t value);
......
...@@ -584,28 +584,45 @@ struct operation : MIGRAPHX_HANDLE_BASE(operation) ...@@ -584,28 +584,45 @@ struct operation : MIGRAPHX_HANDLE_BASE(operation)
} }
}; };
// options for migraphx file format options
struct file_options : MIGRAPHX_HANDLE_BASE(file_options)
{
file_options() { this->make_handle(&migraphx_file_options_create); }
file_options(migraphx_file_options* p, own) { this->set_handle(p, own()); }
// set file format
void set_file_format(const char* format)
{
call(&migraphx_file_options_set_file_format, this->get_handle_ptr(), format);
}
};
/// Load a saved migraphx program from a file /// Load a saved migraphx program from a file
inline program load(const char* filename, migraphx_file_options options) inline program load(const char* filename, const file_options& options)
{ {
return program(make<migraphx_program>(&migraphx_load, filename, &options), own{}); return program(make<migraphx_program>(&migraphx_load, filename, options.get_handle_ptr()),
own{});
} }
/// Load a saved migraphx program from a file /// Load a saved migraphx program from a file
inline program load(const char* filename) inline program load(const char* filename)
{ {
return program(make<migraphx_program>(&migraphx_load, filename, nullptr), own{}); return program(
make<migraphx_program>(&migraphx_load, filename, migraphx::file_options{}.get_handle_ptr()),
own{});
} }
/// Save a program to a file /// Save a program to a file
inline void save(const program& p, const char* filename, migraphx_file_options options) inline void save(const program& p, const char* filename, const file_options& options)
{ {
call(&migraphx_save, p.get_handle_ptr(), filename, &options); call(&migraphx_save, p.get_handle_ptr(), filename, options.get_handle_ptr());
} }
/// Save a program to a file /// Save a program to a file
inline void save(const program& p, const char* filename) inline void save(const program& p, const char* filename)
{ {
call(&migraphx_save, p.get_handle_ptr(), filename, nullptr); call(&migraphx_save, p.get_handle_ptr(), filename, migraphx::file_options{}.get_handle_ptr());
} }
/// Options for parsing onnx options /// Options for parsing onnx options
......
...@@ -250,6 +250,14 @@ def onnx_options(h): ...@@ -250,6 +250,14 @@ def onnx_options(h):
) )
@auto_handle()
def file_options(h):
h.constructor('create')
h.method('set_file_format',
api.params(format='const char*'),
invoke='migraphx::set_file_format($@)')
api.add_function('migraphx_parse_onnx', api.add_function('migraphx_parse_onnx',
api.params(name='const char*', api.params(name='const char*',
options='migraphx::onnx_options'), options='migraphx::onnx_options'),
......
...@@ -22,8 +22,8 @@ TEST_CASE(load_save_json) ...@@ -22,8 +22,8 @@ TEST_CASE(load_save_json)
std::string filename = "migraphx_api_load_save.json"; std::string filename = "migraphx_api_load_save.json";
auto p1 = migraphx::parse_onnx("conv_relu_maxpool_test.onnx"); auto p1 = migraphx::parse_onnx("conv_relu_maxpool_test.onnx");
auto s1 = p1.get_output_shapes(); auto s1 = p1.get_output_shapes();
migraphx_file_options options; migraphx::file_options options;
options.format = "json"; options.set_file_format("json");
migraphx::save(p1, filename.c_str(), options); migraphx::save(p1, filename.c_str(), options);
auto p2 = migraphx::load(filename.c_str(), options); auto p2 = migraphx::load(filename.c_str(), options);
......
#include <migraphx/operation.hpp>
#include <migraphx/migraphx.h> #include <migraphx/migraphx.h>
#include <migraphx/rank.hpp> #include <migraphx/rank.hpp>
#include <migraphx/shape.hpp> #include <migraphx/shape.hpp>
...@@ -81,12 +82,7 @@ migraphx::compile_options to_compile_options(const migraphx_compile_options& opt ...@@ -81,12 +82,7 @@ migraphx::compile_options to_compile_options(const migraphx_compile_options& opt
return result; return result;
} }
migraphx::file_options to_file_options(const migraphx_file_options& options) void set_file_format(file_options& options, const char* format) { options.format = format; }
{
migraphx::file_options result{};
result.format = options.format;
return result;
}
void set_default_dim_value(onnx_options& options, size_t value) void set_default_dim_value(onnx_options& options, size_t value)
{ {
......
...@@ -54,13 +54,6 @@ typedef struct ...@@ -54,13 +54,6 @@ typedef struct
bool fast_math; bool fast_math;
} migraphx_compile_options; } migraphx_compile_options;
/// Options for saving and loading files
typedef struct
{
/// Format to be used for file. It can either be json or msgpack
const char* format;
} migraphx_file_options;
<% generate_c_header() %> <% generate_c_header() %>
#ifdef __cplusplus #ifdef __cplusplus
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment