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
c4494293
Commit
c4494293
authored
Jul 19, 2022
by
Ted Themistokleous
Browse files
fixup! Initial working commit of tested compile trap of detected divzero instructions
parent
938792b0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
9 deletions
+64
-9
src/module.cpp
src/module.cpp
+9
-6
src/program.cpp
src/program.cpp
+1
-3
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+54
-0
No files found.
src/module.cpp
View file @
c4494293
...
@@ -628,14 +628,17 @@ instruction_ref module::find_dangling_reference() const
...
@@ -628,14 +628,17 @@ instruction_ref module::find_dangling_reference() const
return
end
();
return
end
();
}
}
// bool is_div_zero(instruction_ref ins) {return
// instruction::get_output_alias(ins)->get_operator().name() == "divzero";}
bool
is_div_zero
(
instruction
ins
)
{
return
ins
.
name
()
==
"divzero"
;
}
instruction_ref
module
::
flag_division_by_zero
()
const
instruction_ref
module
::
flag_division_by_zero
()
const
{
{
auto
last
=
std
::
prev
(
end
());
auto
divzero
=
std
::
count_if
(
begin
(),
end
(),
[](
auto
x
)
{
return
is_div_zero
(
x
);
});
auto
ins
=
end
();
if
(
divzero
>
0
)
if
(
last
->
name
()
==
"divzero"
)
{
return
begin
();
ins
=
begin
();
}
return
end
();
return
ins
;
}
}
void
module
::
finalize
(
context
&
ctx
)
void
module
::
finalize
(
context
&
ctx
)
...
...
src/program.cpp
View file @
c4494293
...
@@ -198,9 +198,7 @@ void program::compile(const target& t, compile_options options)
...
@@ -198,9 +198,7 @@ void program::compile(const target& t, compile_options options)
auto
divide_by_zero
=
mod
->
flag_division_by_zero
();
auto
divide_by_zero
=
mod
->
flag_division_by_zero
();
if
(
divide_by_zero
!=
mod
->
end
())
if
(
divide_by_zero
!=
mod
->
end
())
{
{
auto
index
=
std
::
distance
(
mod
->
begin
(),
divide_by_zero
);
MIGRAPHX_THROW
(
"Division by zero reference in module "
+
mod
->
name
()
+
""
);
MIGRAPHX_THROW
(
"Division by zero reference in module "
+
mod
->
name
()
+
" from instruction "
+
std
::
to_string
(
index
));
}
}
mod
->
finalize
(
this
->
impl
->
ctx
);
mod
->
finalize
(
this
->
impl
->
ctx
);
...
...
test/ref_ops_test.cpp
View file @
c4494293
...
@@ -1360,6 +1360,32 @@ TEST_CASE(div_zero_compile_trap_after_no_passes)
...
@@ -1360,6 +1360,32 @@ TEST_CASE(div_zero_compile_trap_after_no_passes)
EXPECT(result);
EXPECT(result);
}
}
TEST_CASE(div_zero_compile_trap_long_program_no_passes)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto zero = mm->add_literal(0);
auto one = mm->add_literal(1);
auto x = mm->add_parameter("x", {migraphx::shape::int32_type, {1}});
auto y = mm->add_parameter("y", {migraphx::shape::int32_type, {1}});
auto div0 = mm->add_instruction(migraphx::make_op("divzero"), x, zero);
auto mul = mm->add_instruction(migraphx::make_op("mul"), one, div0);
auto add = mm->add_instruction(migraphx::make_op("add"), y, mul);
mm->add_instruction(migraphx::make_op("sub"), y, add);
bool result = false;
try
{
p.compile(migraphx::ref::target{});
}
catch(const std::runtime_error& e)
{
(void)e;
result = true;
}
EXPECT(result);
}
TEST_CASE(div_zero_compile_trap_after_passes)
TEST_CASE(div_zero_compile_trap_after_passes)
{
{
migraphx::program p;
migraphx::program p;
...
@@ -1382,6 +1408,34 @@ TEST_CASE(div_zero_compile_trap_after_passes)
...
@@ -1382,6 +1408,34 @@ TEST_CASE(div_zero_compile_trap_after_passes)
EXPECT(result);
EXPECT(result);
}
}
TEST_CASE(div_zero_compile_trap_long_program_after_passes)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto zero = mm->add_literal(0);
auto two = mm->add_literal(2);
auto x = mm->add_parameter("x", {migraphx::shape::int32_type, {1}});
auto y = mm->add_parameter("y", {migraphx::shape::int32_type, {1}});
auto div0 = mm->add_instruction(migraphx::make_op("div"), x, zero);
auto mul = mm->add_instruction(migraphx::make_op("mul"), two, div0);
auto add = mm->add_instruction(migraphx::make_op("add"), y, mul);
mm->add_instruction(migraphx::make_op("sub"), y, add);
run_pass(*mm);
bool result = false;
try
{
p.compile(migraphx::ref::target{});
}
catch(const std::runtime_error& e)
{
(void)e;
result = true;
}
EXPECT(result);
}
TEST_CASE(elu_test)
TEST_CASE(elu_test)
{
{
migraphx::program p;
migraphx::program p;
...
...
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