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
2ac066ef
Commit
2ac066ef
authored
Jan 17, 2019
by
Paul
Browse files
Add more tests for finalization
parent
645aa04f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
143 additions
and
3 deletions
+143
-3
src/include/migraphx/concat_opt.hpp
src/include/migraphx/concat_opt.hpp
+7
-0
src/include/migraphx/context.hpp
src/include/migraphx/context.hpp
+6
-0
src/include/migraphx/operation.hpp
src/include/migraphx/operation.hpp
+6
-0
src/include/migraphx/pass.hpp
src/include/migraphx/pass.hpp
+6
-0
src/include/migraphx/program.hpp
src/include/migraphx/program.hpp
+2
-0
src/include/migraphx/target.hpp
src/include/migraphx/target.hpp
+6
-0
src/program.cpp
src/program.cpp
+2
-0
test/eval_test.cpp
test/eval_test.cpp
+95
-1
test/include/test.hpp
test/include/test.hpp
+8
-2
tools/te.py
tools/te.py
+5
-0
No files found.
src/include/migraphx/concat_opt.hpp
View file @
2ac066ef
...
@@ -119,6 +119,13 @@ struct concat_optimization
...
@@ -119,6 +119,13 @@ struct concat_optimization
return
(
*
this
).
private_detail_te_get_handle
().
get_concat
(
op
);
return
(
*
this
).
private_detail_te_get_handle
().
get_concat
(
op
);
}
}
friend
bool
is_shared
(
const
concat_optimization
&
private_detail_x
,
const
concat_optimization
&
private_detail_y
)
{
return
private_detail_x
.
private_detail_te_handle_mem_var
==
private_detail_y
.
private_detail_te_handle_mem_var
;
}
private:
private:
struct
private_detail_te_handle_base_type
struct
private_detail_te_handle_base_type
{
{
...
...
src/include/migraphx/context.hpp
View file @
2ac066ef
...
@@ -98,6 +98,12 @@ struct context
...
@@ -98,6 +98,12 @@ struct context
(
*
this
).
private_detail_te_get_handle
().
finish
();
(
*
this
).
private_detail_te_get_handle
().
finish
();
}
}
friend
bool
is_shared
(
const
context
&
private_detail_x
,
const
context
&
private_detail_y
)
{
return
private_detail_x
.
private_detail_te_handle_mem_var
==
private_detail_y
.
private_detail_te_handle_mem_var
;
}
private:
private:
struct
private_detail_te_handle_base_type
struct
private_detail_te_handle_base_type
{
{
...
...
src/include/migraphx/operation.hpp
View file @
2ac066ef
...
@@ -367,6 +367,12 @@ struct operation
...
@@ -367,6 +367,12 @@ struct operation
return
x
.
private_detail_te_get_handle
().
operator
==
(
y
);
return
x
.
private_detail_te_get_handle
().
operator
==
(
y
);
}
}
friend
bool
is_shared
(
const
operation
&
private_detail_x
,
const
operation
&
private_detail_y
)
{
return
private_detail_x
.
private_detail_te_handle_mem_var
==
private_detail_y
.
private_detail_te_handle_mem_var
;
}
private:
private:
struct
private_detail_te_handle_base_type
struct
private_detail_te_handle_base_type
{
{
...
...
src/include/migraphx/pass.hpp
View file @
2ac066ef
...
@@ -108,6 +108,12 @@ struct pass
...
@@ -108,6 +108,12 @@ struct pass
(
*
this
).
private_detail_te_get_handle
().
apply
(
p
);
(
*
this
).
private_detail_te_get_handle
().
apply
(
p
);
}
}
friend
bool
is_shared
(
const
pass
&
private_detail_x
,
const
pass
&
private_detail_y
)
{
return
private_detail_x
.
private_detail_te_handle_mem_var
==
private_detail_y
.
private_detail_te_handle_mem_var
;
}
private:
private:
struct
private_detail_te_handle_base_type
struct
private_detail_te_handle_base_type
{
{
...
...
src/include/migraphx/program.hpp
View file @
2ac066ef
...
@@ -91,6 +91,8 @@ struct program
...
@@ -91,6 +91,8 @@ struct program
shape
get_shape
()
const
;
shape
get_shape
()
const
;
context
&
get_context
()
const
;
instruction_ref
validate
()
const
;
instruction_ref
validate
()
const
;
void
compile
(
const
target
&
t
,
tracer
trace
=
tracer
{});
void
compile
(
const
target
&
t
,
tracer
trace
=
tracer
{});
...
...
src/include/migraphx/target.hpp
View file @
2ac066ef
...
@@ -127,6 +127,12 @@ struct target
...
@@ -127,6 +127,12 @@ struct target
return
(
*
this
).
private_detail_te_get_handle
().
get_context
();
return
(
*
this
).
private_detail_te_get_handle
().
get_context
();
}
}
friend
bool
is_shared
(
const
target
&
private_detail_x
,
const
target
&
private_detail_y
)
{
return
private_detail_x
.
private_detail_te_handle_mem_var
==
private_detail_y
.
private_detail_te_handle_mem_var
;
}
private:
private:
struct
private_detail_te_handle_base_type
struct
private_detail_te_handle_base_type
{
{
...
...
src/program.cpp
View file @
2ac066ef
...
@@ -271,6 +271,8 @@ instruction_ref program::end() const { return impl->instructions.end(); }
...
@@ -271,6 +271,8 @@ instruction_ref program::end() const { return impl->instructions.end(); }
shape
program
::
get_shape
()
const
{
return
impl
->
instructions
.
back
().
get_shape
();
}
shape
program
::
get_shape
()
const
{
return
impl
->
instructions
.
back
().
get_shape
();
}
context
&
program
::
get_context
()
const
{
return
impl
->
ctx
;
}
instruction_ref
program
::
validate
()
const
instruction_ref
program
::
validate
()
const
{
{
return
std
::
find_if
(
impl
->
instructions
.
begin
(),
return
std
::
find_if
(
impl
->
instructions
.
begin
(),
...
...
test/eval_test.cpp
View file @
2ac066ef
...
@@ -8,9 +8,57 @@
...
@@ -8,9 +8,57 @@
struct
id_target
struct
id_target
{
{
struct
context
{
void
finish
()
const
{}
};
migraphx
::
context
ctx
=
context
{};
std
::
string
name
()
const
{
return
"id"
;
}
std
::
string
name
()
const
{
return
"id"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
{
return
{};
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
{
return
{};
}
migraphx
::
context
get_context
()
const
{
return
{};
}
migraphx
::
context
get_context
()
const
{
return
ctx
;
}
};
struct
id_ctx_op
{
std
::
string
name
()
const
{
return
"id_ctx_op"
;
}
migraphx
::
argument
compute
(
id_target
::
context
&
,
const
migraphx
::
shape
&
,
std
::
vector
<
migraphx
::
argument
>
args
)
const
{
if
(
args
.
empty
())
return
{};
return
args
.
front
();
}
migraphx
::
shape
compute_shape
(
std
::
vector
<
migraphx
::
shape
>
inputs
)
const
{
if
(
inputs
.
empty
())
return
{};
return
inputs
.
front
();
}
int
output_alias
(
const
std
::
vector
<
migraphx
::
shape
>&
)
const
{
return
0
;
}
};
struct
id_ctx_final_op
{
std
::
string
name
()
const
{
return
"id_ctx_final_op"
;
}
migraphx
::
argument
compute
(
const
migraphx
::
shape
&
,
std
::
vector
<
migraphx
::
argument
>
args
)
const
{
if
(
args
.
empty
())
return
{};
return
args
.
front
();
}
void
finalize
(
id_target
::
context
&
,
const
migraphx
::
shape
&
,
std
::
vector
<
migraphx
::
shape
>
)
{}
migraphx
::
shape
compute_shape
(
std
::
vector
<
migraphx
::
shape
>
inputs
)
const
{
if
(
inputs
.
empty
())
return
{};
return
inputs
.
front
();
}
int
output_alias
(
const
std
::
vector
<
migraphx
::
shape
>&
)
const
{
return
0
;
}
};
};
struct
reverse_pass
struct
reverse_pass
...
@@ -224,4 +272,50 @@ TEST_CASE(double_reverse_target_test)
...
@@ -224,4 +272,50 @@ TEST_CASE(double_reverse_target_test)
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
}
}
TEST_CASE
(
eval_context1
)
{
migraphx
::
program
p
;
id_target
t
{};
EXPECT
(
is_shared
(
t
.
ctx
,
t
.
get_context
()));
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
compile
(
t
);
EXPECT
(
is_shared
(
t
.
ctx
,
p
.
get_context
()));
p
.
eval
({});
EXPECT
(
is_shared
(
t
.
ctx
,
p
.
get_context
()));
}
TEST_CASE
(
eval_context2
)
{
migraphx
::
program
p
;
id_target
t
{};
EXPECT
(
is_shared
(
t
.
ctx
,
t
.
get_context
()));
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
id_ctx_op
{},
one
,
two
);
p
.
compile
(
t
);
EXPECT
(
is_shared
(
t
.
ctx
,
p
.
get_context
()));
p
.
eval
({});
// id_ctx_op will modify the context
EXPECT
(
not
is_shared
(
t
.
ctx
,
p
.
get_context
()));
}
TEST_CASE
(
eval_context3
)
{
migraphx
::
program
p
;
id_target
t
{};
EXPECT
(
is_shared
(
t
.
ctx
,
t
.
get_context
()));
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
id_ctx_final_op
{},
one
,
two
);
p
.
compile
(
t
);
// Finalizer will modify the context
EXPECT
(
not
is_shared
(
t
.
ctx
,
p
.
get_context
()));
auto
ctx
=
p
.
get_context
();
p
.
eval
({});
EXPECT
(
is_shared
(
ctx
,
p
.
get_context
()));
EXPECT
(
not
is_shared
(
t
.
ctx
,
p
.
get_context
()));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/include/test.hpp
View file @
2ac066ef
...
@@ -223,8 +223,14 @@ inline void run(int argc, const char* argv[])
...
@@ -223,8 +223,14 @@ inline void run(int argc, const char* argv[])
{
{
std
::
unordered_map
<
std
::
string
,
std
::
function
<
void
()
>>
m
(
get_test_cases
().
begin
(),
std
::
unordered_map
<
std
::
string
,
std
::
function
<
void
()
>>
m
(
get_test_cases
().
begin
(),
get_test_cases
().
end
());
get_test_cases
().
end
());
for
(
auto
&&
name
:
cases
)
for
(
auto
&&
name
:
cases
)
run_test_case
(
name
,
m
[
name
]);
{
auto
f
=
m
.
find
(
name
);
if
(
f
==
m
.
end
())
std
::
cout
<<
"[ ERROR ] Test case '"
<<
name
<<
"' not found."
<<
std
::
endl
;
else
run_test_case
(
name
,
f
->
second
);
}
}
}
}
}
...
...
tools/te.py
View file @
2ac066ef
...
@@ -71,6 +71,11 @@ struct ${struct_name}
...
@@ -71,6 +71,11 @@ struct ${struct_name}
${nonvirtual_members}
${nonvirtual_members}
friend bool is_shared(const ${struct_name} & private_detail_x, const ${struct_name} & private_detail_y)
{
return private_detail_x.private_detail_te_handle_mem_var == private_detail_y.private_detail_te_handle_mem_var;
}
private:
private:
struct private_detail_te_handle_base_type
struct private_detail_te_handle_base_type
{
{
...
...
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