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
6529e7c9
Commit
6529e7c9
authored
Feb 18, 2022
by
Shucai Xiao
Browse files
Merge branch 'alias_0_as_ret_value' into print_matmul_perf_flops
parents
1c425f14
65de331e
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
24 deletions
+94
-24
test/print_graph_test.cpp
test/print_graph_test.cpp
+6
-6
test/ref_ops_nonstd_shape_test.cpp
test/ref_ops_nonstd_shape_test.cpp
+79
-16
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+1
-0
tools/api.py
tools/api.py
+6
-2
tools/generate.sh
tools/generate.sh
+2
-0
No files found.
test/print_graph_test.cpp
View file @
6529e7c9
...
@@ -34,12 +34,12 @@ TEST_CASE(basic_graph_test)
...
@@ -34,12 +34,12 @@ TEST_CASE(basic_graph_test)
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@0
\"
[label=
\"
@literal
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@0
\"
[label=
\"
@literal
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
y
\"
[label=
\"
@param:y
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
y
\"
[label=
\"
@param:y
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
x
\"
[label=
\"
@param:x
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
x
\"
[label=
\"
@param:x
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@
1
\"
[label=
\"
sum
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@
3
\"
[label=
\"
sum
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@
2
\"
[label=
\"
sum
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@
4
\"
[label=
\"
sum
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
x
\"
->
\"
main:@
1
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
x
\"
->
\"
main:@
3
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
y
\"
->
\"
main:@
1
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
y
\"
->
\"
main:@
3
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@
1
\"
->
\"
main:@
2
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@
3
\"
->
\"
main:@
4
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@0
\"
->
\"
main:@
2
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"
\"
main:@0
\"
->
\"
main:@
4
\"
"
));
EXPECT
(
migraphx
::
contains
(
test
,
"[label=
\"
int64_type, {1}, {0}
\"
]"
));
EXPECT
(
migraphx
::
contains
(
test
,
"[label=
\"
int64_type, {1}, {0}
\"
]"
));
}
}
...
...
test/ref_ops_nonstd_shape_test.cpp
View file @
6529e7c9
...
@@ -57,14 +57,15 @@ TEST_CASE(squeeze_transpose_test)
...
@@ -57,14 +57,15 @@ TEST_CASE(squeeze_transpose_test)
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
2
,
3
,
0
,
4
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
2
,
3
,
0
,
4
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_trans
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_trans
);
auto
p_uncompiled
=
p
;
auto
p_uncompiled
=
p
;
// contiguous is required to read the values in standard shaped order
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
// contiguous is required to read the values in standard shaped order
auto
tr_op
=
migraphx
::
make_op
(
"contiguous"
);
auto
std_expected_result
=
tr_op
.
compute
(
result
.
get_shape
(),
{
expected_result
});
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
3
}});
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
3
}});
EXPECT
(
result
==
std_
expected_result
);
EXPECT
(
result
==
expected_result
);
}
}
TEST_CASE
(
squeeze_multibroadcast_test
)
TEST_CASE
(
squeeze_multibroadcast_test
)
...
@@ -76,14 +77,15 @@ TEST_CASE(squeeze_multibroadcast_test)
...
@@ -76,14 +77,15 @@ TEST_CASE(squeeze_multibroadcast_test)
auto
l0_brcst
=
mm
->
add_instruction
(
auto
l0_brcst
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
4
,
1
,
3
,
4
,
3
}}}),
l0
);
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
4
,
1
,
3
,
4
,
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_brcst
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_brcst
);
auto
p_uncompiled
=
p
;
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
auto
tr_op
=
migraphx
::
make_op
(
"contiguous"
);
auto
std_expected_result
=
tr_op
.
compute
(
result
.
get_shape
(),
{
expected_result
});
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
4
,
3
}});
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
4
,
3
}});
EXPECT
(
result
==
std_
expected_result
);
EXPECT
(
result
==
expected_result
);
}
}
TEST_CASE
(
squeeze_slice_test
)
TEST_CASE
(
squeeze_slice_test
)
...
@@ -95,14 +97,75 @@ TEST_CASE(squeeze_slice_test)
...
@@ -95,14 +97,75 @@ TEST_CASE(squeeze_slice_test)
auto
l0_slice
=
mm
->
add_instruction
(
auto
l0_slice
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
2
}},
{
"ends"
,
{
3
}}}),
l0
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
2
}},
{
"ends"
,
{
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_slice
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_slice
);
auto
p_uncompiled
=
p
;
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
auto
tr_op
=
migraphx
::
make_op
(
"contiguous"
);
auto
std_expected_result
=
tr_op
.
compute
(
result
.
get_shape
(),
{
expected_result
});
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}});
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}});
EXPECT
(
result
==
std_expected_result
);
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
unsqueeze_transpose_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
3
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
s1
));
auto
l0_trans
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
1
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
l0_trans
);
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
1
,
3
}});
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
unsqueeze_multibroadcast_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
4
,
1
,
3
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
s1
));
auto
l0_brcst
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
4
,
4
,
3
,
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
l0_brcst
);
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
4
,
1
,
3
,
3
}});
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
unsqueeze_slice_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
s1
));
auto
l0_slice
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
3
}},
{
"starts"
,
{
2
}},
{
"ends"
,
{
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
}}}),
l0_slice
);
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
1
,
3
,
4
,
1
}});
EXPECT
(
result
==
expected_result
);
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/simplify_reshapes_test.cpp
View file @
6529e7c9
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/instruction.hpp>
...
...
tools/api.py
View file @
6529e7c9
...
@@ -15,7 +15,7 @@ c_api_body_preamble: List[str] = []
...
@@ -15,7 +15,7 @@ c_api_body_preamble: List[str] = []
cpp_header_preamble
:
List
[
str
]
=
[]
cpp_header_preamble
:
List
[
str
]
=
[]
def
bad_param_error
(
msg
):
def
bad_param_error
(
msg
:
str
):
return
'throw std::runtime_error("{}")'
.
format
(
msg
)
return
'throw std::runtime_error("{}")'
.
format
(
msg
)
...
@@ -89,7 +89,7 @@ class Type:
...
@@ -89,7 +89,7 @@ class Type:
else
:
else
:
return
t
.
remove_const
()
return
t
.
remove_const
()
def
const_compatible
(
self
,
t
):
def
const_compatible
(
self
,
t
:
'Type'
):
if
t
.
is_const
():
if
t
.
is_const
():
return
self
.
add_const
()
return
self
.
add_const
()
return
self
return
self
...
@@ -720,6 +720,7 @@ def add_handle(name: str,
...
@@ -720,6 +720,7 @@ def add_handle(name: str,
destroy
:
Optional
[
str
]
=
None
,
destroy
:
Optional
[
str
]
=
None
,
ref
:
Optional
[
bool
]
=
None
)
->
None
:
ref
:
Optional
[
bool
]
=
None
)
->
None
:
opaque_type
=
ctype
+
'_t'
opaque_type
=
ctype
+
'_t'
const_opaque_type
=
'const_'
+
opaque_type
def
handle_wrap
(
p
):
def
handle_wrap
(
p
):
t
=
Type
(
opaque_type
)
t
=
Type
(
opaque_type
)
...
@@ -747,6 +748,9 @@ def add_handle(name: str,
...
@@ -747,6 +748,9 @@ def add_handle(name: str,
add_function
(
destroy
or
ctype
+
'_'
+
'destroy'
,
add_function
(
destroy
or
ctype
+
'_'
+
'destroy'
,
params
({
name
:
opaque_type
}),
params
({
name
:
opaque_type
}),
fname
=
'destroy'
)
fname
=
'destroy'
)
add_function
(
ctype
+
'_'
+
'assign_to'
,
params
(
output
=
opaque_type
,
input
=
const_opaque_type
),
invoke
=
'*output = *input'
)
add_handle_preamble
()
add_handle_preamble
()
c_header_preamble
.
append
(
handle_typedef
.
substitute
(
locals
()))
c_header_preamble
.
append
(
handle_typedef
.
substitute
(
locals
()))
c_api_body_preamble
.
append
(
handle_definition
.
substitute
(
locals
()))
c_api_body_preamble
.
append
(
handle_definition
.
substitute
(
locals
()))
...
...
tools/generate.sh
View file @
6529e7c9
...
@@ -14,4 +14,6 @@ function api {
...
@@ -14,4 +14,6 @@ function api {
}
}
api
$DIR
/api/migraphx.h
$SRC_DIR
/api/include/migraphx/migraphx.h
api
$DIR
/api/migraphx.h
$SRC_DIR
/api/include/migraphx/migraphx.h
echo
"Finished generating header migraphx.h"
api
$DIR
/api/api.cpp
$SRC_DIR
/api/api.cpp
api
$DIR
/api/api.cpp
$SRC_DIR
/api/api.cpp
echo
"Finished generating source api.cpp "
Prev
1
2
Next
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