-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add int4 & uint4 types to MigraphX #3378
base: develop
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,9 @@ struct MIGRAPHX_EXPORT shape | |
#define MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES(x, t) x, | ||
enum type_t | ||
{ | ||
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES) tuple_type | ||
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES) tuple_type, | ||
uint4_type, | ||
int4_type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a macro to list these types. |
||
}; | ||
#undef MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES | ||
|
||
|
@@ -381,6 +383,8 @@ struct MIGRAPHX_EXPORT shape | |
{ | ||
switch(t) | ||
{ | ||
case uint4_type: | ||
case int4_type: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tuple visitor should not be called for these types. It should throw an error. |
||
case tuple_type: { | ||
tv(); | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,20 +48,20 @@ | |
|
||
shape_impl(shape::type_t t) : m_type(t), m_lens({1}), m_strides({0}), m_standard(true) | ||
{ | ||
assert(t != shape::tuple_type); | ||
assert(t != shape::tuple_type && t != shape::uint4_type && t != shape::int4_type); | ||
} | ||
|
||
shape_impl(shape::type_t t, std::vector<std::size_t> l) | ||
: m_type(t), m_lens(std::move(l)), m_standard(true) | ||
{ | ||
assert(t != shape::tuple_type); | ||
assert(t != shape::tuple_type && t != shape::uint4_type && t != shape::int4_type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assert shouldn't be changed here. It should be valid to construct a shape of int4_type otherwise whats the point of adding this type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. This one is definitely required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant you are correct. This constructor code, as you suggest, is definitely required for correct functioning. |
||
this->calculate_strides(); | ||
} | ||
|
||
shape_impl(shape::type_t t, std::vector<std::size_t> l, std::vector<std::size_t> s) | ||
: m_type(t), m_lens(std::move(l)), m_strides(std::move(s)) | ||
{ | ||
assert(t != shape::tuple_type); | ||
assert(t != shape::tuple_type && t != shape::uint4_type && t != shape::int4_type); | ||
assert(m_lens.size() == m_strides.size()); | ||
m_standard = this->elements() == this->element_space() and not skips() and | ||
std::is_sorted(m_strides.rbegin(), m_strides.rend()); | ||
|
@@ -122,7 +122,7 @@ | |
{ | ||
if(not m_dyn_dims.empty()) | ||
{ | ||
auto maxes = max_lens(); | ||
auto maxes = max_lens(); | ||
std::size_t max_val = std::numeric_limits<std::size_t>::max(); | ||
|
||
return std::accumulate( | ||
|
@@ -224,7 +224,9 @@ | |
{ | ||
static const std::vector<shape::type_t> result = { | ||
#define MIGRAPHX_GENERATE_TYPE_VECTOR(x, t) x, | ||
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_GENERATE_TYPE_VECTOR) tuple_type}; | ||
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_GENERATE_TYPE_VECTOR) tuple_type, | ||
int4_type, | ||
uint4_type}; | ||
return result; | ||
} | ||
|
||
|
@@ -233,6 +235,8 @@ | |
switch(t) | ||
{ | ||
case tuple_type: return "tuple_type"; | ||
case int4_type: return "int4_type"; | ||
case uint4_type: return "uint4_type"; | ||
#define MIGRAPHX_SHAPE_GENERATE_TYPE_NAME_CASE(x, t) \ | ||
case x: return #x; | ||
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_TYPE_NAME_CASE) | ||
|
@@ -246,6 +250,8 @@ | |
switch(t) | ||
{ | ||
case tuple_type: MIGRAPHX_THROW("No C++ type for tuple"); | ||
case int4_type: MIGRAPHX_THROW("No C++ type for int4_type"); | ||
case uint4_type: MIGRAPHX_THROW("No C++ type for uint4_type"); | ||
#define MIGRAPHX_SHAPE_GENERATE_CPP_TYPE_CASE(x, t) \ | ||
case x: return #t; | ||
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_CPP_TYPE_CASE) | ||
|
@@ -728,7 +734,9 @@ | |
#define MIGRAPHX_SHAPE_GENERATE_TYPE_STRING_MAP(x, t) {#x, x}, {#t, x}, | ||
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_TYPE_STRING_MAP){"tuple_type", | ||
tuple_type}, | ||
{"tuple", tuple_type}}; | ||
{"tuple", tuple_type}, | ||
{"int4_type", int4_type}, | ||
{"uint4_type", uint4_type}}; | ||
return m.at(s); | ||
} | ||
|
||
|
@@ -744,7 +752,7 @@ | |
auto subs = flatten(s.sub_shapes()); | ||
result.insert(result.end(), subs.begin(), subs.end()); | ||
} | ||
else | ||
else if(s.type() != shape::uint4_type && s.type() != shape::int4_type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be changed, we should still be able to flatten an tuples of int4_type. |
||
{ | ||
result.push_back(s); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wrong, the enum values should be exposed in the API and not throw an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.