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
c3edd50e
Commit
c3edd50e
authored
Jul 08, 2022
by
Ted Themistokleous
Browse files
Revert "Remove check for div zero, push this to be detected in a seperate pass"
This reverts commit
fcc84214
.
parent
f0e84612
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
src/simplify_algebra.cpp
src/simplify_algebra.cpp
+15
-0
test/simplify_algebra_test.cpp
test/simplify_algebra_test.cpp
+22
-0
No files found.
src/simplify_algebra.cpp
View file @
c3edd50e
...
@@ -851,6 +851,20 @@ struct find_div_const
...
@@ -851,6 +851,20 @@ struct find_div_const
}
}
};
};
struct
find_zero_div_const
{
auto
matcher
()
const
{
return
match
::
name
(
"div"
)(
match
::
arg
(
1
)(
match
::
skip_broadcasts_converts
(
match
::
has_value
(
0.0
f
))));
}
[[
noreturn
]]
void
apply
(
module
&
,
const
match
::
matcher_result
&
)
const
{
MIGRAPHX_THROW
(
"ERROR: Matched division by zero in pass"
);
}
};
struct
find_unit_ops
struct
find_unit_ops
{
{
auto
matcher
()
const
auto
matcher
()
const
...
@@ -1118,6 +1132,7 @@ void simplify_algebra::apply(module& m) const
...
@@ -1118,6 +1132,7 @@ void simplify_algebra::apply(module& m) const
find_unit_ops
{},
find_unit_ops
{},
find_neg_unit_ops
{},
find_neg_unit_ops
{},
find_zero_ops
{},
find_zero_ops
{},
find_zero_div_const
{},
find_div_const
{},
find_div_const
{},
find_sub_const
{},
find_sub_const
{},
find_rsqrt
{},
find_rsqrt
{},
...
...
test/simplify_algebra_test.cpp
View file @
c3edd50e
...
@@ -1096,6 +1096,28 @@ TEST_CASE(simplify_sub_neg_zero_const_vec)
...
@@ -1096,6 +1096,28 @@ TEST_CASE(simplify_sub_neg_zero_const_vec)
EXPECT
(
m1
==
m2
);
EXPECT
(
m1
==
m2
);
}
}
TEST_CASE
(
simplify_div_zero_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
unit
=
m1
.
add_literal
(
0
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
x
,
unit
);
}
bool
result
=
false
;
try
{
run_pass
(
m1
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
(
void
)
e
;
result
=
true
;
}
EXPECT
(
result
);
}
TEST_CASE
(
simplify_sub_const
)
TEST_CASE
(
simplify_sub_const
)
{
{
migraphx
::
module
m1
;
migraphx
::
module
m1
;
...
...
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