"docs/en_US/Tutorial/Nnictl.md" did not exist on "a656bba5161b32080d2dc71c2ff331f34e183485"
Commit 2ecf0dd2 authored by umangyadav's avatar umangyadav
Browse files

let auto-gen decompose string type to const char* and use format strings

parent 995d68e4
...@@ -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;
} }
......
...@@ -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)
......
...@@ -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()
......
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