Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
ecb1545c
"include/vscode:/vscode.git/clone" did not exist on "56532f77101dfc0fd376dd741d86b1302fbf1761"
Unverified
Commit
ecb1545c
authored
Feb 16, 2022
by
kahmed10
Committed by
GitHub
Feb 16, 2022
Browse files
Add assign_to method for C++ API (#1075)
parent
48585bad
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
201 additions
and
7 deletions
+201
-7
src/api/api.cpp
src/api/api.cpp
+110
-0
src/api/include/migraphx/migraphx.h
src/api/include/migraphx/migraphx.h
+44
-0
src/api/include/migraphx/migraphx.hpp
src/api/include/migraphx/migraphx.hpp
+13
-5
test/api/CMakeLists.txt
test/api/CMakeLists.txt
+1
-0
test/api/test_assign.cpp
test/api/test_assign.cpp
+25
-0
tools/api.py
tools/api.py
+6
-2
tools/generate.sh
tools/generate.sh
+2
-0
No files found.
src/api/api.cpp
View file @
ecb1545c
...
...
@@ -385,6 +385,13 @@ extern "C" migraphx_status migraphx_shape_destroy(migraphx_shape_t 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
,
...
...
@@ -502,6 +509,13 @@ extern "C" migraphx_status migraphx_argument_destroy(migraphx_argument_t argumen
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
)
{
...
...
@@ -565,6 +579,13 @@ extern "C" migraphx_status migraphx_target_destroy(migraphx_target_t 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_
([
&
]
{
...
...
@@ -581,6 +602,14 @@ extern "C" migraphx_status migraphx_program_parameter_shapes_destroy(
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
)
...
...
@@ -631,6 +660,14 @@ migraphx_program_parameters_destroy(migraphx_program_parameters_t program_parame
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
)
{
...
...
@@ -663,6 +700,13 @@ extern "C" migraphx_status migraphx_arguments_destroy(migraphx_arguments_t argum
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_
([
&
]
{
...
...
@@ -690,6 +734,13 @@ extern "C" migraphx_status migraphx_shapes_destroy(migraphx_shapes_t 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_
([
&
]
{
...
...
@@ -727,6 +778,13 @@ extern "C" migraphx_status migraphx_program_destroy(migraphx_program_t 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_get_main_module
(
migraphx_module_t
*
out
,
migraphx_program_t
program
)
{
...
...
@@ -831,6 +889,13 @@ extern "C" migraphx_status migraphx_operation_destroy(migraphx_operation_t opera
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
,
...
...
@@ -891,6 +956,13 @@ extern "C" migraphx_status migraphx_onnx_options_destroy(migraphx_onnx_options_t
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_
([
&
]
{
...
...
@@ -942,6 +1014,13 @@ extern "C" migraphx_status migraphx_file_options_destroy(migraphx_file_options_t
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_
([
&
]
{
...
...
@@ -968,6 +1047,14 @@ migraphx_compile_options_destroy(migraphx_compile_options_t 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
)
{
...
...
@@ -1033,6 +1120,13 @@ extern "C" migraphx_status migraphx_tf_options_destroy(migraphx_tf_options_t tf_
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_
([
&
]
{
...
...
@@ -1110,6 +1204,14 @@ migraphx_quantize_op_names_destroy(migraphx_quantize_op_names_t quantize_op_name
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
)
{
...
...
@@ -1162,6 +1264,14 @@ migraphx_quantize_int8_options_destroy(migraphx_quantize_int8_options_t quantize
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
)
{
...
...
src/api/include/migraphx/migraphx.h
View file @
ecb1545c
...
...
@@ -91,6 +91,8 @@ typedef const struct migraphx_quantize_int8_options* const_migraphx_quantize_int
migraphx_status
migraphx_shape_destroy
(
migraphx_shape_t
shape
);
migraphx_status
migraphx_shape_assign_to
(
migraphx_shape_t
output
,
const_migraphx_shape_t
input
);
migraphx_status
migraphx_shape_create
(
migraphx_shape_t
*
shape
,
migraphx_shape_datatype_t
type
,
size_t
*
lengths
,
...
...
@@ -121,6 +123,9 @@ migraphx_shape_equal(bool* out, const_migraphx_shape_t shape, const_migraphx_sha
migraphx_status
migraphx_argument_destroy
(
migraphx_argument_t
argument
);
migraphx_status
migraphx_argument_assign_to
(
migraphx_argument_t
output
,
const_migraphx_argument_t
input
);
migraphx_status
migraphx_argument_create
(
migraphx_argument_t
*
argument
,
const_migraphx_shape_t
shape
,
void
*
buffer
);
...
...
@@ -137,11 +142,17 @@ migraphx_argument_generate(migraphx_argument_t* out, const_migraphx_shape_t s, s
migraphx_status
migraphx_target_destroy
(
migraphx_target_t
target
);
migraphx_status
migraphx_target_assign_to
(
migraphx_target_t
output
,
const_migraphx_target_t
input
);
migraphx_status
migraphx_target_create
(
migraphx_target_t
*
target
,
const
char
*
name
);
migraphx_status
migraphx_program_parameter_shapes_destroy
(
migraphx_program_parameter_shapes_t
program_parameter_shapes
);
migraphx_status
migraphx_program_parameter_shapes_assign_to
(
migraphx_program_parameter_shapes_t
output
,
const_migraphx_program_parameter_shapes_t
input
);
migraphx_status
migraphx_program_parameter_shapes_size
(
size_t
*
out
,
migraphx_program_parameter_shapes_t
program_parameter_shapes
);
...
...
@@ -156,6 +167,9 @@ migraphx_status migraphx_program_parameter_shapes_names(
migraphx_status
migraphx_program_parameters_destroy
(
migraphx_program_parameters_t
program_parameters
);
migraphx_status
migraphx_program_parameters_assign_to
(
migraphx_program_parameters_t
output
,
const_migraphx_program_parameters_t
input
);
migraphx_status
migraphx_program_parameters_create
(
migraphx_program_parameters_t
*
program_parameters
);
...
...
@@ -165,6 +179,9 @@ migraphx_status migraphx_program_parameters_add(migraphx_program_parameters_t pr
migraphx_status
migraphx_arguments_destroy
(
migraphx_arguments_t
arguments
);
migraphx_status
migraphx_arguments_assign_to
(
migraphx_arguments_t
output
,
const_migraphx_arguments_t
input
);
migraphx_status
migraphx_arguments_size
(
size_t
*
out
,
migraphx_arguments_t
arguments
);
migraphx_status
...
...
@@ -172,6 +189,8 @@ migraphx_arguments_get(const_migraphx_argument_t* out, migraphx_arguments_t argu
migraphx_status
migraphx_shapes_destroy
(
migraphx_shapes_t
shapes
);
migraphx_status
migraphx_shapes_assign_to
(
migraphx_shapes_t
output
,
const_migraphx_shapes_t
input
);
migraphx_status
migraphx_shapes_size
(
size_t
*
out
,
migraphx_shapes_t
shapes
);
migraphx_status
...
...
@@ -181,6 +200,9 @@ migraphx_status migraphx_module_print(const_migraphx_module_t module);
migraphx_status
migraphx_program_destroy
(
migraphx_program_t
program
);
migraphx_status
migraphx_program_assign_to
(
migraphx_program_t
output
,
const_migraphx_program_t
input
);
migraphx_status
migraphx_program_get_main_module
(
migraphx_module_t
*
out
,
migraphx_program_t
program
);
...
...
@@ -207,6 +229,9 @@ migraphx_program_equal(bool* out, const_migraphx_program_t program, const_migrap
migraphx_status
migraphx_operation_destroy
(
migraphx_operation_t
operation
);
migraphx_status
migraphx_operation_assign_to
(
migraphx_operation_t
output
,
const_migraphx_operation_t
input
);
migraphx_status
migraphx_operation_create
(
migraphx_operation_t
*
operation
,
const
char
*
name
,
const
char
*
attributes
,
...
...
@@ -222,6 +247,9 @@ migraphx_save(migraphx_program_t p, const char* name, migraphx_file_options_t op
migraphx_status
migraphx_onnx_options_destroy
(
migraphx_onnx_options_t
onnx_options
);
migraphx_status
migraphx_onnx_options_assign_to
(
migraphx_onnx_options_t
output
,
const_migraphx_onnx_options_t
input
);
migraphx_status
migraphx_onnx_options_create
(
migraphx_onnx_options_t
*
onnx_options
);
migraphx_status
migraphx_onnx_options_set_input_parameter_shape
(
...
...
@@ -236,6 +264,9 @@ migraphx_onnx_options_set_default_loop_iterations(migraphx_onnx_options_t onnx_o
migraphx_status
migraphx_file_options_destroy
(
migraphx_file_options_t
file_options
);
migraphx_status
migraphx_file_options_assign_to
(
migraphx_file_options_t
output
,
const_migraphx_file_options_t
input
);
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
,
...
...
@@ -243,6 +274,9 @@ migraphx_status migraphx_file_options_set_file_format(migraphx_file_options_t fi
migraphx_status
migraphx_compile_options_destroy
(
migraphx_compile_options_t
compile_options
);
migraphx_status
migraphx_compile_options_assign_to
(
migraphx_compile_options_t
output
,
const_migraphx_compile_options_t
input
);
migraphx_status
migraphx_compile_options_create
(
migraphx_compile_options_t
*
compile_options
);
migraphx_status
...
...
@@ -261,6 +295,9 @@ migraphx_status migraphx_parse_onnx_buffer(migraphx_program_t* out,
migraphx_status
migraphx_tf_options_destroy
(
migraphx_tf_options_t
tf_options
);
migraphx_status
migraphx_tf_options_assign_to
(
migraphx_tf_options_t
output
,
const_migraphx_tf_options_t
input
);
migraphx_status
migraphx_tf_options_create
(
migraphx_tf_options_t
*
tf_options
);
migraphx_status
migraphx_tf_options_set_nhwc
(
migraphx_tf_options_t
tf_options
,
bool
is_nhwc
);
...
...
@@ -282,6 +319,9 @@ migraphx_parse_tf(migraphx_program_t* out, const char* name, migraphx_tf_options
migraphx_status
migraphx_quantize_op_names_destroy
(
migraphx_quantize_op_names_t
quantize_op_names
);
migraphx_status
migraphx_quantize_op_names_assign_to
(
migraphx_quantize_op_names_t
output
,
const_migraphx_quantize_op_names_t
input
);
migraphx_status
migraphx_quantize_op_names_create
(
migraphx_quantize_op_names_t
*
quantize_op_names
);
migraphx_status
migraphx_quantize_op_names_add
(
migraphx_quantize_op_names_t
quantize_op_names
,
...
...
@@ -295,6 +335,10 @@ migraphx_status migraphx_quantize_fp16(migraphx_program_t prog);
migraphx_status
migraphx_quantize_int8_options_destroy
(
migraphx_quantize_int8_options_t
quantize_int8_options
);
migraphx_status
migraphx_quantize_int8_options_assign_to
(
migraphx_quantize_int8_options_t
output
,
const_migraphx_quantize_int8_options_t
input
);
migraphx_status
migraphx_quantize_int8_options_create
(
migraphx_quantize_int8_options_t
*
quantize_int8_options
);
...
...
src/api/include/migraphx/migraphx.hpp
View file @
ecb1545c
...
...
@@ -159,7 +159,7 @@ struct borrow
{
};
template
<
class
T
,
class
D
,
D
Deleter
>
template
<
class
T
,
class
D
,
D
Deleter
,
class
A
,
A
Assigner
>
struct
handle_base
{
handle_base
()
:
m_handle
(
nullptr
)
{}
...
...
@@ -190,6 +190,12 @@ struct handle_base
m_handle
=
std
::
shared_ptr
<
U
>
{
ptr
,
[](
U
*
)
{}};
}
template
<
class
U
>
void
assign_to_handle
(
U
*
x
)
{
Assigner
(
x
,
this
->
get_handle_ptr
());
}
protected:
std
::
shared_ptr
<
T
>
m_handle
;
};
...
...
@@ -197,10 +203,12 @@ struct handle_base
#ifdef DOXYGEN
#define MIGRAPHX_DETAIL_HANDLE_BASE(name, const_) handle_base<>
#else
#define MIGRAPHX_DETAIL_HANDLE_BASE(name, const_) \
handle_base<const_ migraphx_##name, \
decltype(&migraphx_##name##_destroy), \
migraphx_##name##_destroy>
#define MIGRAPHX_DETAIL_HANDLE_BASE(name, const_) \
handle_base<const_ migraphx_##name, \
decltype(&migraphx_##name##_destroy), \
migraphx_##name##_destroy, \
decltype(&migraphx_##name##_assign_to), \
migraphx_##name##_assign_to>
#endif
// NOLINTNEXTLINE
#define MIGRAPHX_HANDLE_BASE(name) MIGRAPHX_DETAIL_HANDLE_BASE(name, )
...
...
test/api/CMakeLists.txt
View file @
ecb1545c
...
...
@@ -10,6 +10,7 @@ function(add_api_test TEST_NAME TEST_SRC TEST_DIR)
add_dependencies
(
check
${
NAME
}
)
endfunction
()
add_api_test
(
assign test_assign.cpp
${
TEST_ONNX_DIR
}
)
add_api_test
(
compile_options test_compile_options.cpp
${
TEST_ONNX_DIR
}
)
add_api_test
(
ref test_cpu.cpp
${
TEST_ONNX_DIR
}
)
add_api_test
(
save_load test_save_load.cpp
${
TEST_ONNX_DIR
}
)
...
...
test/api/test_assign.cpp
0 → 100644
View file @
ecb1545c
#include <migraphx/migraphx.h>
#include <migraphx/migraphx.hpp>
#include "test.hpp"
TEST_CASE
(
shape_assign
)
{
auto
s1_cpp
=
migraphx
::
shape
{
migraphx_shape_float_type
,
{
1
,
3
}};
std
::
vector
<
size_t
>
lens
{
2
,
3
};
// handle ptr is const, workaround to construct shape using C API
migraphx_shape_t
s2
;
migraphx_shape_create
(
&
s2
,
migraphx_shape_float_type
,
lens
.
data
(),
lens
.
size
());
auto
s2_cpp
=
migraphx
::
shape
(
s2
,
migraphx
::
own
{});
CHECK
(
bool
{
s1_cpp
!=
s2_cpp
});
// use C++ API for assignment
s1_cpp
.
assign_to_handle
(
s2
);
CHECK
(
bool
{
s1_cpp
==
s2_cpp
});
auto
s3_cpp
=
migraphx
::
shape
{
migraphx_shape_float_type
,
lens
};
// use C API for assignment
migraphx_shape_assign_to
(
s2
,
s3_cpp
.
get_handle_ptr
());
CHECK
(
bool
{
s2_cpp
==
s3_cpp
});
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
tools/api.py
View file @
ecb1545c
...
...
@@ -15,7 +15,7 @@ c_api_body_preamble: List[str] = []
cpp_header_preamble
:
List
[
str
]
=
[]
def
bad_param_error
(
msg
):
def
bad_param_error
(
msg
:
str
):
return
'throw std::runtime_error("{}")'
.
format
(
msg
)
...
...
@@ -89,7 +89,7 @@ class Type:
else
:
return
t
.
remove_const
()
def
const_compatible
(
self
,
t
):
def
const_compatible
(
self
,
t
:
'Type'
):
if
t
.
is_const
():
return
self
.
add_const
()
return
self
...
...
@@ -720,6 +720,7 @@ def add_handle(name: str,
destroy
:
Optional
[
str
]
=
None
,
ref
:
Optional
[
bool
]
=
None
)
->
None
:
opaque_type
=
ctype
+
'_t'
const_opaque_type
=
'const_'
+
opaque_type
def
handle_wrap
(
p
):
t
=
Type
(
opaque_type
)
...
...
@@ -747,6 +748,9 @@ def add_handle(name: str,
add_function
(
destroy
or
ctype
+
'_'
+
'destroy'
,
params
({
name
:
opaque_type
}),
fname
=
'destroy'
)
add_function
(
ctype
+
'_'
+
'assign_to'
,
params
(
output
=
opaque_type
,
input
=
const_opaque_type
),
invoke
=
'*output = *input'
)
add_handle_preamble
()
c_header_preamble
.
append
(
handle_typedef
.
substitute
(
locals
()))
c_api_body_preamble
.
append
(
handle_definition
.
substitute
(
locals
()))
...
...
tools/generate.sh
View file @
ecb1545c
...
...
@@ -14,4 +14,6 @@ function api {
}
api
$DIR
/api/migraphx.h
$SRC_DIR
/api/include/migraphx/migraphx.h
echo
"Finished generating header migraphx.h"
api
$DIR
/api/api.cpp
$SRC_DIR
/api/api.cpp
echo
"Finished generating source api.cpp "
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment