Skip to content

Commit

Permalink
Move datatype parsing to its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
gussmith23 committed May 10, 2019
1 parent 478b649 commit d554a58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
18 changes: 2 additions & 16 deletions include/tvm/runtime/packed_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ namespace runtime {

// Datatype utilities needed at runtime. See src/runtime/custom_datatype_util.cc.
TVM_DLL std::string GetCustomTypeName(uint8_t type_code);
TVM_DLL uint8_t GetCustomTypeCode(const std::string& type_name);
TVM_DLL bool GetCustomTypeRegistered(uint8_t type_code);
TVM_DLL uint8_t ParseCustomDatatype(std::string s);

// forward declarations
class TVMArgs;
Expand Down Expand Up @@ -1009,21 +1009,7 @@ inline TVMType String2TVMType(std::string s) {
t.lanes = 1;
return t;
} else if (s.substr(0, 6) == "custom") {
// TODO(gus): too much hardcoding here.
scan = s.c_str() + 6;
if (*scan != '[')
LOG(FATAL) << "expected opening brace after 'custom' type in" << s;
++scan;
size_t custom_name_len = 0;
while (scan + custom_name_len <= s.c_str() + s.length() &&
*(scan + custom_name_len) != ']')
++custom_name_len;
if (*(scan + custom_name_len) != ']')
LOG(FATAL) << "expected closing brace after 'custom' type in" << s;
scan += custom_name_len + 1;

auto type_name = s.substr(7, custom_name_len);
t.code = GetCustomTypeCode(type_name);
t.code = ParseCustomDatatype(s);
} else {
scan = s.c_str();
LOG(FATAL) << "unknown type " << s;
Expand Down
17 changes: 17 additions & 0 deletions src/runtime/c_runtime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ TVM_DLL bool GetCustomTypeRegistered(uint8_t type_code) {
return (*f)(type_code).operator bool();
}

TVM_DLL uint8_t ParseCustomDatatype(std::string s) {
// TODO(gus): too much hardcoding here.
// TODO(gus) possibly replace with a regex.
auto scan = s.c_str() + 6;
if (*scan != '[') LOG(FATAL) << "expected opening brace after 'custom' type in" << s;
++scan;
size_t custom_name_len = 0;
while (scan + custom_name_len <= s.c_str() + s.length() && *(scan + custom_name_len) != ']')
++custom_name_len;
if (*(scan + custom_name_len) != ']')
LOG(FATAL) << "expected closing brace after 'custom' type in" << s;
scan += custom_name_len + 1;

auto type_name = s.substr(7, custom_name_len);
return GetCustomTypeCode(type_name);
}

class DeviceAPIManager {
public:
static const int kMaxDeviceAPI = 32;
Expand Down

0 comments on commit d554a58

Please sign in to comment.