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
2ecf0dd2
"docs/en_US/Tutorial/Nnictl.md" did not exist on "a656bba5161b32080d2dc71c2ff331f34e183485"
Commit
2ecf0dd2
authored
May 02, 2022
by
umangyadav
Browse files
let auto-gen decompose string type to const char* and use format strings
parent
995d68e4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
23 deletions
+20
-23
src/api/api.cpp
src/api/api.cpp
+10
-4
src/api/include/migraphx/migraphx.hpp
src/api/include/migraphx/migraphx.hpp
+5
-9
src/api/migraphx.py
src/api/migraphx.py
+5
-10
No files found.
src/api/api.cpp
View file @
2ecf0dd2
...
@@ -1313,16 +1313,22 @@ extern "C" migraphx_status migraphx_value_get_float(double* out, const_migraphx_
...
@@ -1313,16 +1313,22 @@ extern "C" migraphx_status migraphx_value_get_float(double* out, const_migraphx_
extern
"C"
migraphx_status
migraphx_value_create_string
(
migraphx_value_t
*
value
,
const
char
*
i
)
extern
"C"
migraphx_status
migraphx_value_create_string
(
migraphx_value_t
*
value
,
const
char
*
i
)
{
{
auto
api_error_result
=
migraphx
::
try_
(
auto
api_error_result
=
migraphx
::
try_
([
&
]
{
[
&
]
{
*
value
=
object_cast
<
migraphx_value_t
>
(
allocate
<
migraphx
::
value
>
((
i
)));
});
if
(
i
==
nullptr
)
MIGRAPHX_THROW
(
migraphx_status_bad_param
,
"Bad parameter i: Null pointer"
);
*
value
=
object_cast
<
migraphx_value_t
>
(
allocate
<
migraphx
::
value
>
((
std
::
string
(
i
))));
});
return
api_error_result
;
return
api_error_result
;
}
}
extern
"C"
migraphx_status
extern
"C"
migraphx_status
migraphx_value_create_string_with_key
(
migraphx_value_t
*
value
,
const
char
*
pkey
,
const
char
*
i
)
migraphx_value_create_string_with_key
(
migraphx_value_t
*
value
,
const
char
*
pkey
,
const
char
*
i
)
{
{
auto
api_error_result
=
migraphx
::
try_
(
auto
api_error_result
=
migraphx
::
try_
([
&
]
{
[
&
]
{
*
value
=
object_cast
<
migraphx_value_t
>
(
allocate
<
migraphx
::
value
>
((
pkey
),
(
i
)));
});
if
(
i
==
nullptr
)
MIGRAPHX_THROW
(
migraphx_status_bad_param
,
"Bad parameter i: Null pointer"
);
*
value
=
object_cast
<
migraphx_value_t
>
(
allocate
<
migraphx
::
value
>
((
pkey
),
(
std
::
string
(
i
))));
});
return
api_error_result
;
return
api_error_result
;
}
}
...
...
src/api/include/migraphx/migraphx.hpp
View file @
2ecf0dd2
...
@@ -869,6 +869,9 @@ struct value : MIGRAPHX_HANDLE_BASE(value)
...
@@ -869,6 +869,9 @@ struct value : MIGRAPHX_HANDLE_BASE(value)
return
result
;
return
result
;
}
}
// TODO(umang): need to return pointer to make it consistent across all data types, or make all
// data type return value instead of pointers
// TODO(umang): need to check if size of 1024 holds for serialization
std
::
string
get_string
()
const
std
::
string
get_string
()
const
{
{
std
::
array
<
char
,
1024
>
str_array
;
std
::
array
<
char
,
1024
>
str_array
;
...
@@ -876,14 +879,9 @@ struct value : MIGRAPHX_HANDLE_BASE(value)
...
@@ -876,14 +879,9 @@ struct value : MIGRAPHX_HANDLE_BASE(value)
return
{
str_array
.
data
()};
return
{
str_array
.
data
()};
}
}
// TODO(umang): need to return pointer to make it consistent across all data types, or make all
// data type return value instead of pointers
// TODO(umang): need to check if size of 1024 holds for serialization
std
::
string
if_string
()
const
std
::
string
if_string
()
const
{
{
std
::
array
<
char
,
1024
>
str_array
;
return
this
->
is_string
()
?
this
->
get_string
()
:
""
;
call
(
&
migraphx_value_if_string
,
str_array
.
data
(),
1024
,
this
->
get_handle_ptr
());
return
{
str_array
.
data
()};
}
}
#define MIGRAPHX_VISIT_VALUE_TYPES(m) \
#define MIGRAPHX_VISIT_VALUE_TYPES(m) \
...
@@ -909,9 +907,7 @@ struct value : MIGRAPHX_HANDLE_BASE(value)
...
@@ -909,9 +907,7 @@ struct value : MIGRAPHX_HANDLE_BASE(value)
} \
} \
const cpp_type* if_##vt() const \
const cpp_type* if_##vt() const \
{ \
{ \
const cpp_type* ret_value = nullptr; \
return this->is_##vt() ? &(this->get_##vt()) : nullptr; \
call(&migraphx_value_if_##vt, &ret_value, this->get_handle_ptr()); \
return ret_value; \
}
}
MIGRAPHX_VISIT_VALUE_TYPES
(
MIGRAPHX_VALUE_GENERATE_DEFINE_METHODS
)
MIGRAPHX_VISIT_VALUE_TYPES
(
MIGRAPHX_VALUE_GENERATE_DEFINE_METHODS
)
...
...
src/api/migraphx.py
View file @
2ecf0dd2
...
@@ -231,17 +231,12 @@ def value(h):
...
@@ -231,17 +231,12 @@ def value(h):
cpp_types
=
[
'int64_t'
,
'uint64_t'
,
'double'
,
'std::string'
,
'bool'
]
cpp_types
=
[
'int64_t'
,
'uint64_t'
,
'double'
,
'std::string'
,
'bool'
]
vt
=
[
'int64'
,
'uint64'
,
'float'
,
'string'
,
'bool'
]
vt
=
[
'int64'
,
'uint64'
,
'float'
,
'string'
,
'bool'
]
for
vt
,
cpp_type
in
zip
(
vt
,
cpp_types
):
for
vt
,
cpp_type
in
zip
(
vt
,
cpp_types
):
if
(
vt
==
'string'
):
h
.
constructor
(
'create_{}'
.
format
(
vt
),
api
.
params
(
i
=
cpp_type
))
h
.
constructor
(
'create_'
+
vt
,
api
.
params
(
i
=
'const char*'
))
h
.
constructor
(
'create_{}_with_key'
.
format
(
vt
),
h
.
constructor
(
'create_'
+
vt
+
'_with_key'
,
api
.
params
(
pkey
=
'const char*'
,
i
=
'const char*'
))
else
:
h
.
constructor
(
'create_'
+
vt
,
api
.
params
(
i
=
cpp_type
))
h
.
constructor
(
'create_'
+
vt
+
'_with_key'
,
api
.
params
(
pkey
=
'const char*'
,
i
=
cpp_type
))
api
.
params
(
pkey
=
'const char*'
,
i
=
cpp_type
))
h
.
method
(
'if_
'
+
vt
,
returns
=
'const '
+
cpp_type
+
'*'
,
const
=
True
)
h
.
method
(
'if_
{}'
.
format
(
vt
)
,
returns
=
'const '
+
cpp_type
+
'*'
,
const
=
True
)
h
.
method
(
'is_
'
+
vt
,
returns
=
'bool'
,
const
=
True
)
h
.
method
(
'is_
{}'
.
format
(
vt
)
,
returns
=
'bool'
,
const
=
True
)
h
.
method
(
'get_
'
+
vt
,
returns
=
cpp_type
,
const
=
True
)
h
.
method
(
'get_
{}'
.
format
(
vt
)
,
returns
=
cpp_type
,
const
=
True
)
@
auto_handle
()
@
auto_handle
()
...
...
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