Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
cf5baca1
Commit
cf5baca1
authored
Jul 10, 2018
by
Paul
Browse files
Add tests for validate
parent
dd465fab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
16 deletions
+61
-16
src/include/migraph/builtin.hpp
src/include/migraph/builtin.hpp
+1
-1
src/include/migraph/instruction.hpp
src/include/migraph/instruction.hpp
+14
-8
src/program.cpp
src/program.cpp
+13
-7
test/validate.cpp
test/validate.cpp
+33
-0
No files found.
src/include/migraph/builtin.hpp
View file @
cf5baca1
...
...
@@ -19,7 +19,7 @@ struct outline
{
shape
s
;
std
::
string
name
()
const
{
return
"@outline"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
)
const
{
MIGRAPH_THROW
(
"builtin"
)
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
)
const
{
return
s
;
}
argument
compute
(
context
&
,
shape
,
std
::
vector
<
argument
>
)
const
{
MIGRAPH_THROW
(
"builtin"
);
}
};
...
...
src/include/migraph/instruction.hpp
View file @
cf5baca1
...
...
@@ -64,18 +64,24 @@ struct instruction
bool
valid
(
instruction_ref
start
)
const
{
std
::
vector
<
shape
>
shapes
(
arguments
.
size
());
std
::
transform
(
arguments
.
begin
(),
arguments
.
end
(),
shapes
.
begin
(),
[](
instruction_ref
ins
)
{
return
ins
->
result
;
});
shape
computed
;
try
if
(
op
.
name
()
==
"@literal"
)
{
computed
=
op
.
compute
_shape
(
shapes
);
computed
=
lit
.
get
_shape
();
}
catch
(
migraph
::
exception
&
)
else
if
(
op
.
name
()
==
"@param"
)
{
return
false
;
computed
=
result
;
}
else
{
try
{
computed
=
compute_shape
(
op
,
arguments
);
}
catch
(
migraph
::
exception
&
)
{
return
false
;
}
}
return
result
==
computed
&&
std
::
all_of
(
output
.
begin
(),
...
...
src/program.cpp
View file @
cf5baca1
...
...
@@ -129,28 +129,34 @@ instruction_ref program::validate() const
{
return
std
::
find_if
(
impl
->
instructions
.
begin
(),
impl
->
instructions
.
end
(),
[
&
](
const
instruction
&
i
)
{
return
i
.
valid
(
impl
->
instructions
.
begin
());
});
[
&
](
const
instruction
&
i
)
{
return
!
i
.
valid
(
impl
->
instructions
.
begin
());
});
}
void
program
::
compile
(
const
target
&
t
)
{
assert
(
this
->
validate
()
!
=
impl
->
instructions
.
end
());
assert
(
this
->
validate
()
=
=
impl
->
instructions
.
end
());
this
->
impl
->
ctx
=
t
.
get_context
();
for
(
auto
&&
p
:
t
.
get_passes
(
this
->
impl
->
ctx
))
{
p
.
apply
(
*
this
);
#ifndef NDEBUG
if
(
this
->
validate
()
==
impl
->
instructions
.
end
())
MIGRAPH_THROW
(
p
.
name
()
+
" pass produces invalid program"
);
auto
invalid
=
this
->
validate
();
if
(
invalid
!=
impl
->
instructions
.
end
())
{
auto
index
=
std
::
distance
(
impl
->
instructions
.
begin
(),
invalid
);
MIGRAPH_THROW
(
p
.
name
()
+
" pass produces invalid program at instruction "
+
std
::
to_string
(
index
));
}
#endif
}
if
(
this
->
validate
()
==
impl
->
instructions
.
end
())
MIGRAPH_THROW
(
"Invalid program from compilation"
);
auto
invalid
=
this
->
validate
();
if
(
invalid
!=
impl
->
instructions
.
end
())
{
auto
index
=
std
::
distance
(
impl
->
instructions
.
begin
(),
invalid
);
MIGRAPH_THROW
(
"Invalid program from compilation at instruction "
+
std
::
to_string
(
index
));
}
}
argument
program
::
eval
(
std
::
unordered_map
<
std
::
string
,
argument
>
params
)
const
{
assert
(
this
->
validate
()
!
=
impl
->
instructions
.
end
());
assert
(
this
->
validate
()
=
=
impl
->
instructions
.
end
());
std
::
unordered_map
<
const
instruction
*
,
argument
>
results
;
argument
result
;
for
(
auto
&
ins
:
impl
->
instructions
)
...
...
test/validate.cpp
0 → 100644
View file @
cf5baca1
#include <migraph/program.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
void
simple_test
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
std
::
cout
<<
std
::
distance
(
p
.
begin
(),
p
.
validate
())
<<
std
::
endl
;
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
out_of_order
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
ins
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
move_instruction
(
two
,
p
.
end
());
EXPECT
(
bool
{
p
.
validate
()
==
ins
});
}
int
main
()
{
simple_test
();
out_of_order
();
}
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