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
bc5d7f75
Commit
bc5d7f75
authored
Feb 15, 2019
by
Paul
Browse files
Merge from develop
parents
47c0854d
a5b0afa0
Changes
337
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
426 additions
and
176 deletions
+426
-176
test/output_alias.cpp
test/output_alias.cpp
+12
-12
test/program_test.cpp
test/program_test.cpp
+9
-9
test/py/CMakeLists.txt
test/py/CMakeLists.txt
+21
-0
test/py/cpu.py
test/py/cpu.py
+17
-0
test/py/gpu.py
test/py/gpu.py
+14
-0
test/shape_test.cpp
test/shape_test.cpp
+18
-18
test/simplify_algebra_test.cpp
test/simplify_algebra_test.cpp
+52
-52
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+76
-28
test/type_name.cpp
test/type_name.cpp
+5
-5
test/validate.cpp
test/validate.cpp
+12
-12
tools/generate.sh
tools/generate.sh
+1
-1
tools/include/concat_opt.hpp
tools/include/concat_opt.hpp
+9
-6
tools/include/context.hpp
tools/include/context.hpp
+7
-4
tools/include/operation.hpp
tools/include/operation.hpp
+146
-15
tools/include/pass.hpp
tools/include/pass.hpp
+7
-4
tools/include/target.hpp
tools/include/target.hpp
+9
-6
tools/te.py
tools/te.py
+11
-4
No files found.
test/output_alias.cpp
View file @
bc5d7f75
#include <migraph/program.hpp>
#include <migraph/instruction.hpp>
#include <migraph
x
/program.hpp>
#include <migraph
x
/instruction.hpp>
#include <test.hpp>
#include <basic_ops.hpp>
TEST_CASE
(
simple_alias
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
1
);
auto
p1
=
p
.
add_instruction
(
pass_op
{},
l
);
EXPECT
(
bool
{
migraph
::
instruction
::
get_output_alias
(
l
)
==
l
});
EXPECT
(
bool
{
migraph
::
instruction
::
get_output_alias
(
p1
)
==
l
});
EXPECT
(
bool
{
migraph
x
::
instruction
::
get_output_alias
(
l
)
==
l
});
EXPECT
(
bool
{
migraph
x
::
instruction
::
get_output_alias
(
p1
)
==
l
});
}
TEST_CASE
(
cascade_alias
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
1
);
auto
p1
=
p
.
add_instruction
(
pass_op
{},
l
);
auto
p2
=
p
.
add_instruction
(
pass_op
{},
p1
);
auto
p3
=
p
.
add_instruction
(
pass_op
{},
p2
);
EXPECT
(
bool
{
migraph
::
instruction
::
get_output_alias
(
l
)
==
l
});
EXPECT
(
bool
{
migraph
::
instruction
::
get_output_alias
(
p1
)
==
l
});
EXPECT
(
bool
{
migraph
::
instruction
::
get_output_alias
(
p2
)
==
l
});
EXPECT
(
bool
{
migraph
::
instruction
::
get_output_alias
(
p3
)
==
l
});
EXPECT
(
bool
{
migraph
x
::
instruction
::
get_output_alias
(
l
)
==
l
});
EXPECT
(
bool
{
migraph
x
::
instruction
::
get_output_alias
(
p1
)
==
l
});
EXPECT
(
bool
{
migraph
x
::
instruction
::
get_output_alias
(
p2
)
==
l
});
EXPECT
(
bool
{
migraph
x
::
instruction
::
get_output_alias
(
p3
)
==
l
});
}
TEST_CASE
(
no_alias
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
x
=
p
.
add_literal
(
1
);
auto
y
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
x
,
y
);
EXPECT
(
bool
{
migraph
::
instruction
::
get_output_alias
(
sum
)
==
sum
});
EXPECT
(
bool
{
migraph
x
::
instruction
::
get_output_alias
(
sum
)
==
sum
});
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/program_test.cpp
View file @
bc5d7f75
#include <migraph/program.hpp>
#include <migraph/iterator_for.hpp>
#include <migraph/instruction.hpp>
#include <migraph
x
/program.hpp>
#include <migraph
x
/iterator_for.hpp>
#include <migraph
x
/instruction.hpp>
#include <sstream>
#include "test.hpp"
#include <basic_ops.hpp>
migraph
::
program
create_program
()
migraph
x
::
program
create_program
()
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int64_type
});
auto
y
=
p
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int64_type
});
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int64_type
});
auto
y
=
p
.
add_parameter
(
"y"
,
{
migraph
x
::
shape
::
int64_type
});
auto
sum
=
p
.
add_instruction
(
sum_op
{},
x
,
y
);
auto
one
=
p
.
add_literal
(
1
);
...
...
@@ -22,8 +22,8 @@ migraph::program create_program()
TEST_CASE
(
program_equality
)
{
migraph
::
program
x
=
create_program
();
migraph
::
program
y
=
create_program
();
migraph
x
::
program
x
=
create_program
();
migraph
x
::
program
y
=
create_program
();
EXPECT
(
x
==
y
);
}
...
...
test/py/CMakeLists.txt
0 → 100644
View file @
bc5d7f75
find_package
(
PythonInterp
)
function
(
add_py_test NAME SCRIPT
)
set
(
ENV_COMMAND
${
CMAKE_COMMAND
}
-E env
"PYTHONPATH=$<TARGET_FILE_DIR:migraphx_py>"
)
add_test
(
NAME test_py_
${
NAME
}
COMMAND
${
ENV_COMMAND
}
${
PYTHON_EXECUTABLE
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCRIPT
}
${
ARGN
}
)
add_custom_target
(
test_py_
${
NAME
}
COMMAND
${
ENV_COMMAND
}
${
PYTHON_EXECUTABLE
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
SCRIPT
}
${
ARGN
}
COMMENT
"
${
PYTHON_EXECUTABLE
}
${
SCRIPT
}
"
)
endfunction
()
add_dependencies
(
tests migraphx_py
)
add_dependencies
(
check migraphx_py
)
add_py_test
(
cpu cpu.py WORKING_DIRECTORY
${
TEST_ONNX_DIR
}
)
if
(
MIGRAPHX_ENABLE_GPU
)
add_py_test
(
gpu gpu.py WORKING_DIRECTORY
${
TEST_ONNX_DIR
}
)
endif
()
test/py/cpu.py
0 → 100644
View file @
bc5d7f75
import
migraphx
p
=
migraphx
.
parse_onnx
(
"conv_relu_maxpool.onnx"
)
print
(
p
)
s1
=
p
.
get_shape
()
print
(
"Compiling ..."
)
p
.
compile
(
migraphx
.
get_target
(
"cpu"
))
print
(
p
)
s2
=
p
.
get_shape
()
assert
s1
==
s2
params
=
{}
for
key
,
value
in
p
.
get_parameter_shapes
().
items
():
print
(
"Parameter {} -> {}"
.
format
(
key
,
value
))
params
[
key
]
=
migraphx
.
generate_argument
(
value
)
r
=
p
.
run
(
params
)
print
(
r
)
test/py/gpu.py
0 → 100644
View file @
bc5d7f75
import
migraphx
p
=
migraphx
.
parse_onnx
(
"conv_relu_maxpool.onnx"
)
print
(
p
)
print
(
"Compiling ..."
)
p
.
compile
(
migraphx
.
get_target
(
"gpu"
))
print
(
p
)
params
=
{}
for
key
,
value
in
p
.
get_parameter_shapes
().
items
():
print
(
"Parameter {} -> {}"
.
format
(
key
,
value
))
params
[
key
]
=
migraphx
.
to_gpu
(
migraphx
.
generate_argument
(
value
))
r
=
migraphx
.
from_gpu
(
p
.
run
(
params
))
print
(
r
)
test/shape_test.cpp
View file @
bc5d7f75
#include <migraph/shape.hpp>
#include <migraph
x
/shape.hpp>
#include <array>
#include <algorithm>
#include <numeric>
...
...
@@ -7,22 +7,22 @@
TEST_CASE
(
test_shape_default
)
{
migraph
::
shape
s
{};
migraph
x
::
shape
s
{};
EXPECT
(
s
.
elements
()
==
0
);
EXPECT
(
s
.
bytes
()
==
0
);
}
TEST_CASE
(
test_shape_assign
)
{
migraph
::
shape
s1
{
migraph
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
migraph
::
shape
s2
=
s1
;
// NOLINT
migraph
x
::
shape
s1
{
migraph
x
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
migraph
x
::
shape
s2
=
s1
;
// NOLINT
EXPECT
(
s1
==
s2
);
EXPECT
(
!
(
s1
!=
s2
));
}
TEST_CASE
(
test_shape_packed_default
)
{
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
2
,
2
}};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
{
2
,
2
}};
EXPECT
(
s
.
standard
());
EXPECT
(
s
.
packed
());
EXPECT
(
not
s
.
transposed
());
...
...
@@ -31,7 +31,7 @@ TEST_CASE(test_shape_packed_default)
TEST_CASE
(
test_shape_packed
)
{
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
2
,
2
},
{
2
,
1
}};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
{
2
,
2
},
{
2
,
1
}};
EXPECT
(
s
.
standard
());
EXPECT
(
s
.
packed
());
EXPECT
(
not
s
.
transposed
());
...
...
@@ -40,7 +40,7 @@ TEST_CASE(test_shape_packed)
TEST_CASE
(
test_shape_transposed
)
{
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
2
,
2
},
{
1
,
2
}};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
{
2
,
2
},
{
1
,
2
}};
EXPECT
(
not
s
.
standard
());
EXPECT
(
s
.
packed
());
EXPECT
(
s
.
transposed
());
...
...
@@ -49,7 +49,7 @@ TEST_CASE(test_shape_transposed)
TEST_CASE
(
test_shape_broadcasted
)
{
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
2
,
2
},
{
1
,
0
}};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
{
2
,
2
},
{
1
,
0
}};
EXPECT
(
not
s
.
standard
());
EXPECT
(
not
s
.
packed
());
EXPECT
(
not
s
.
transposed
());
...
...
@@ -58,20 +58,20 @@ TEST_CASE(test_shape_broadcasted)
TEST_CASE
(
test_shape_default_copy
)
{
migraph
::
shape
s1
{};
migraph
::
shape
s2
{};
migraph
x
::
shape
s1
{};
migraph
x
::
shape
s2
{};
EXPECT
(
s1
==
s2
);
EXPECT
(
!
(
s1
!=
s2
));
}
TEST_CASE
(
test_shape4
)
{
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
EXPECT
(
s
.
standard
());
EXPECT
(
s
.
packed
());
EXPECT
(
not
s
.
transposed
());
EXPECT
(
not
s
.
broadcasted
());
EXPECT
(
s
.
type
()
==
migraph
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
==
migraph
x
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
EXPECT
(
s
.
lens
()[
2
]
==
8
);
...
...
@@ -99,12 +99,12 @@ TEST_CASE(test_shape4)
TEST_CASE
(
test_shape42
)
{
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
},
{
2048
,
64
,
8
,
1
}};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
},
{
2048
,
64
,
8
,
1
}};
EXPECT
(
s
.
standard
());
EXPECT
(
s
.
packed
());
EXPECT
(
not
s
.
transposed
());
EXPECT
(
not
s
.
broadcasted
());
EXPECT
(
s
.
type
()
==
migraph
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
==
migraph
x
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
EXPECT
(
s
.
lens
()[
2
]
==
8
);
...
...
@@ -132,12 +132,12 @@ TEST_CASE(test_shape42)
TEST_CASE
(
test_shape4_transposed
)
{
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
{
32
,
100
,
8
,
8
},
{
64
,
2048
,
8
,
1
}};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
{
32
,
100
,
8
,
8
},
{
64
,
2048
,
8
,
1
}};
EXPECT
(
s
.
transposed
());
EXPECT
(
s
.
packed
());
EXPECT
(
not
s
.
standard
());
EXPECT
(
not
s
.
broadcasted
());
EXPECT
(
s
.
type
()
==
migraph
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
==
migraph
x
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
32
);
EXPECT
(
s
.
lens
()[
1
]
==
100
);
EXPECT
(
s
.
lens
()[
2
]
==
8
);
...
...
@@ -179,12 +179,12 @@ TEST_CASE(test_shape4_nonpacked)
strides
.
rbegin
()
+
1
,
std
::
multiplies
<
std
::
size_t
>
());
migraph
::
shape
s
{
migraph
::
shape
::
float_type
,
lens
,
strides
};
migraph
x
::
shape
s
{
migraph
x
::
shape
::
float_type
,
lens
,
strides
};
EXPECT
(
not
s
.
standard
());
EXPECT
(
not
s
.
packed
());
EXPECT
(
not
s
.
transposed
());
EXPECT
(
not
s
.
broadcasted
());
EXPECT
(
s
.
type
()
==
migraph
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
==
migraph
x
::
shape
::
float_type
);
EXPECT
(
s
.
lens
()[
0
]
==
100
);
EXPECT
(
s
.
lens
()[
1
]
==
32
);
EXPECT
(
s
.
lens
()[
2
]
==
8
);
...
...
test/simplify_algebra_test.cpp
View file @
bc5d7f75
#include <migraph/simplify_algebra.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <migraph
x
/simplify_algebra.hpp>
#include <migraph
x
/dead_code_elimination.hpp>
#include <migraph
x
/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct
simplify_algebra_target
{
std
::
string
name
()
const
{
return
"simplify_algebra"
;
}
std
::
vector
<
migraph
::
pass
>
get_passes
(
migraph
::
context
&
)
const
std
::
vector
<
migraph
x
::
pass
>
get_passes
(
migraph
x
::
context
&
)
const
{
return
{
migraph
::
simplify_algebra
{},
migraph
::
dead_code_elimination
{}};
return
{
migraph
x
::
simplify_algebra
{},
migraph
x
::
dead_code_elimination
{}};
}
migraph
::
context
get_context
()
const
{
return
{};
}
migraph
x
::
context
get_context
()
const
{
return
{};
}
};
TEST_CASE
(
simplify_add1
)
{
migraph
::
program
p1
;
migraph
x
::
program
p1
;
{
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p1
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p1
.
add_parameter
(
"y"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p1
.
add_literal
(
1
);
auto
two
=
p1
.
add_literal
(
2
);
auto
sum1
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
x
,
one
);
auto
sum2
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
y
,
two
);
auto
sum3
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
sum1
,
sum2
);
auto
sum1
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
x
,
one
);
auto
sum2
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
y
,
two
);
auto
sum3
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum1
,
sum2
);
p1
.
add_instruction
(
pass_op
{},
sum3
);
}
p1
.
compile
(
simplify_algebra_target
{});
migraph
::
program
p2
;
migraph
x
::
program
p2
;
{
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p2
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p2
.
add_parameter
(
"y"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p2
.
add_literal
(
1
);
auto
two
=
p2
.
add_literal
(
2
);
auto
sum1
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
two
);
auto
sum2
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
x
,
y
);
auto
sum3
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
sum2
,
sum1
);
auto
sum1
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
two
);
auto
sum2
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
x
,
y
);
auto
sum3
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum2
,
sum1
);
p2
.
add_instruction
(
pass_op
{},
sum3
);
}
EXPECT
(
p1
==
p2
);
...
...
@@ -45,28 +45,28 @@ TEST_CASE(simplify_add1)
TEST_CASE
(
simplify_add2
)
{
migraph
::
program
p1
;
migraph
x
::
program
p1
;
{
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p1
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p1
.
add_parameter
(
"y"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p1
.
add_literal
(
1
);
auto
two
=
p1
.
add_literal
(
2
);
auto
sum1
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
two
,
y
);
auto
sum3
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
sum1
,
sum2
);
auto
sum1
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
two
,
y
);
auto
sum3
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum1
,
sum2
);
p1
.
add_instruction
(
pass_op
{},
sum3
);
}
p1
.
compile
(
simplify_algebra_target
{});
migraph
::
program
p2
;
migraph
x
::
program
p2
;
{
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p2
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p2
.
add_parameter
(
"y"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p2
.
add_literal
(
1
);
auto
two
=
p2
.
add_literal
(
2
);
auto
sum1
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
two
);
auto
sum2
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
x
,
y
);
auto
sum3
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
sum2
,
sum1
);
auto
sum1
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
two
);
auto
sum2
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
x
,
y
);
auto
sum3
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum2
,
sum1
);
p2
.
add_instruction
(
pass_op
{},
sum3
);
}
EXPECT
(
p1
==
p2
);
...
...
@@ -74,26 +74,26 @@ TEST_CASE(simplify_add2)
TEST_CASE
(
simplify_add3
)
{
migraph
::
program
p1
;
migraph
x
::
program
p1
;
{
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p1
.
add_literal
(
1
);
auto
two
=
p1
.
add_literal
(
2
);
auto
sum1
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
two
);
auto
sum3
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
sum1
,
sum2
);
auto
sum1
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
two
);
auto
sum3
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum1
,
sum2
);
p1
.
add_instruction
(
pass_op
{},
sum3
);
}
p1
.
compile
(
simplify_algebra_target
{});
migraph
::
program
p2
;
migraph
x
::
program
p2
;
{
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p2
.
add_literal
(
1
);
auto
two
=
p2
.
add_literal
(
2
);
auto
sum1
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
two
);
auto
sum3
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
sum1
,
sum2
);
auto
sum1
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
two
);
auto
sum3
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum1
,
sum2
);
p2
.
add_instruction
(
pass_op
{},
sum3
);
}
EXPECT
(
p1
==
p2
);
...
...
@@ -102,28 +102,28 @@ TEST_CASE(simplify_add3)
// TODO: Add test case
void
simplify_add4
()
{
migraph
::
program
p1
;
migraph
x
::
program
p1
;
{
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p1
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p1
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p1
.
add_parameter
(
"y"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p1
.
add_literal
(
1
);
auto
two
=
p1
.
add_literal
(
2
);
auto
sum1
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
sum1
,
y
);
auto
sum3
=
p1
.
add_instruction
(
migraph
::
op
::
add
{},
sum2
,
two
);
auto
sum1
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
x
);
auto
sum2
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum1
,
y
);
auto
sum3
=
p1
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum2
,
two
);
p1
.
add_instruction
(
pass_op
{},
sum3
);
}
p1
.
compile
(
simplify_algebra_target
{});
migraph
::
program
p2
;
migraph
x
::
program
p2
;
{
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p2
.
add_parameter
(
"y"
,
{
migraph
::
shape
::
int32_type
,
{
1
}});
auto
x
=
p2
.
add_parameter
(
"x"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
y
=
p2
.
add_parameter
(
"y"
,
{
migraph
x
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p2
.
add_literal
(
1
);
auto
two
=
p2
.
add_literal
(
2
);
auto
sum1
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
one
,
two
);
auto
sum2
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
x
,
y
);
auto
sum3
=
p2
.
add_instruction
(
migraph
::
op
::
add
{},
sum2
,
sum1
);
auto
sum1
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
one
,
two
);
auto
sum2
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
x
,
y
);
auto
sum3
=
p2
.
add_instruction
(
migraph
x
::
op
::
add
{},
sum2
,
sum1
);
p2
.
add_instruction
(
pass_op
{},
sum3
);
}
EXPECT
(
p1
==
p2
);
...
...
test/simplify_reshapes_test.cpp
View file @
bc5d7f75
#include <migraph/simplify_reshapes.hpp>
#include <migraph/dead_code_elimination.hpp>
#include <migraph/operators.hpp>
#include <migraph
x
/simplify_reshapes.hpp>
#include <migraph
x
/dead_code_elimination.hpp>
#include <migraph
x
/operators.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct
simplify_reshapes_target
{
std
::
string
name
()
const
{
return
"simplify_reshapes"
;
}
std
::
vector
<
migraph
::
pass
>
get_passes
(
migraph
::
context
&
)
const
std
::
vector
<
migraph
x
::
pass
>
get_passes
(
migraph
x
::
context
&
)
const
{
return
{
migraph
::
simplify_reshapes
{},
migraph
::
dead_code_elimination
{}};
return
{
migraph
x
::
simplify_reshapes
{},
migraph
x
::
dead_code_elimination
{}};
}
migraph
::
context
get_context
()
const
{
return
{};
}
migraph
x
::
context
get_context
()
const
{
return
{};
}
};
TEST_CASE
(
double_contig
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
::
op
::
contiguous
{},
t1
);
auto
c2
=
p
.
add_instruction
(
migraph
::
op
::
contiguous
{},
c1
);
auto
t1
=
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
x
::
op
::
contiguous
{},
t1
);
auto
c2
=
p
.
add_instruction
(
migraph
x
::
op
::
contiguous
{},
c1
);
p
.
add_instruction
(
pass_op
{},
c2
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
2
);
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
4
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
=
=
get_2x2
());
EXPECT
(
result
!
=
get_2x2
());
}
TEST_CASE
(
double_transpose
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
l
);
auto
t2
=
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
t1
);
auto
t1
=
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
l
);
auto
t2
=
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
t1
);
p
.
add_instruction
(
pass_op
{},
t2
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
...
...
@@ -51,12 +51,12 @@ TEST_CASE(double_transpose)
TEST_CASE
(
double_transpose_contig
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
::
op
::
contiguous
{},
t1
);
auto
t2
=
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
c1
);
auto
c2
=
p
.
add_instruction
(
migraph
::
op
::
contiguous
{},
t2
);
auto
t1
=
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
x
::
op
::
contiguous
{},
t1
);
auto
t2
=
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
c1
);
auto
c2
=
p
.
add_instruction
(
migraph
x
::
op
::
contiguous
{},
t2
);
p
.
add_instruction
(
pass_op
{},
c2
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
...
...
@@ -70,9 +70,9 @@ TEST_CASE(double_transpose_contig)
TEST_CASE
(
single_transpose
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
l
);
auto
t1
=
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
pass_op
{},
t1
);
EXPECT
(
not
p
.
get_shape
().
standard
());
EXPECT
(
p
.
get_shape
().
transposed
());
...
...
@@ -86,16 +86,15 @@ TEST_CASE(single_transpose)
TEST_CASE
(
double_transpose_sin_pass
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
t1
);
auto
t1
=
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
t1
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
transposed
());
// std::cout << p << std::endl;
// TODO: Fix this
// EXPECT(std::distance(p.begin(), p.end()) == 1);
auto
result
=
p
.
eval
({});
...
...
@@ -104,9 +103,9 @@ TEST_CASE(double_transpose_sin_pass)
TEST_CASE
(
single_transpose_sin_pass
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
p
.
add_instruction
(
migraph
::
op
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
migraph
x
::
op
::
transpose
{{
1
,
0
}},
l
);
EXPECT
(
not
p
.
get_shape
().
standard
());
EXPECT
(
p
.
get_shape
().
transposed
());
p
.
compile
(
simplify_reshapes_target
{});
...
...
@@ -117,4 +116,53 @@ TEST_CASE(single_transpose_sin_pass)
EXPECT
(
result
!=
get_2x2
());
}
TEST_CASE
(
reshape_transpose
)
{
migraphx
::
program
p
;
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
112
,
56
,
56
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
r1
=
p
.
add_instruction
(
migraphx
::
op
::
reshape
{{
1
,
4
,
28
,
56
,
56
}},
x
);
auto
t
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
2
,
1
,
3
,
4
}},
r1
);
auto
ct
=
p
.
add_instruction
(
migraphx
::
op
::
contiguous
{},
t
);
auto
r2
=
p
.
add_instruction
(
migraphx
::
op
::
reshape
{{
1
,
112
,
56
,
56
}},
ct
);
p
.
add_instruction
(
pass_op
{},
r2
);
EXPECT
(
p
.
get_shape
()
==
s
);
auto
n
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
()
==
s
);
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
n
);
}
TEST_CASE
(
transpose_contiguous
)
{
migraphx
::
program
p
;
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
4
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
t
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
1
,
0
}},
x
);
auto
c1
=
p
.
add_instruction
(
migraphx
::
op
::
contiguous
{},
t
);
p
.
add_instruction
(
pass_op
{},
c1
);
auto
out_shape
=
p
.
get_shape
();
auto
n
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
()
==
out_shape
);
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
n
);
}
TEST_CASE
(
transpose_double_contiguous
)
{
migraphx
::
program
p
;
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
4
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
t
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
1
,
0
}},
x
);
auto
c1
=
p
.
add_instruction
(
migraphx
::
op
::
contiguous
{},
t
);
auto
c2
=
p
.
add_instruction
(
migraphx
::
op
::
contiguous
{},
c1
);
p
.
add_instruction
(
pass_op
{},
c2
);
auto
out_shape
=
p
.
get_shape
();
auto
n
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
p
.
compile
(
simplify_reshapes_target
{});
EXPECT
(
p
.
get_shape
()
==
out_shape
);
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
n
-
1
);
EXPECT
(
p
.
has_instruction
(
t
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/type_name.cpp
View file @
bc5d7f75
#include <migraph/type_name.hpp>
#include <migraph
x
/type_name.hpp>
#include "test.hpp"
struct
global_class
...
...
@@ -21,8 +21,8 @@ struct ns_class
int
main
()
{
EXPECT
(
migraph
::
get_type_name
<
global_class
>
()
==
"global_class"
);
EXPECT
(
migraph
::
get_type_name
<
global_class
::
inner_class
>
()
==
"global_class::inner_class"
);
EXPECT
(
migraph
::
get_type_name
<
foo
::
ns_class
>
()
==
"foo::ns_class"
);
EXPECT
(
migraph
::
get_type_name
<
foo
::
ns_class
::
inner_class
>
()
==
"foo::ns_class::inner_class"
);
EXPECT
(
migraph
x
::
get_type_name
<
global_class
>
()
==
"global_class"
);
EXPECT
(
migraph
x
::
get_type_name
<
global_class
::
inner_class
>
()
==
"global_class::inner_class"
);
EXPECT
(
migraph
x
::
get_type_name
<
foo
::
ns_class
>
()
==
"foo::ns_class"
);
EXPECT
(
migraph
x
::
get_type_name
<
foo
::
ns_class
::
inner_class
>
()
==
"foo::ns_class::inner_class"
);
}
test/validate.cpp
View file @
bc5d7f75
#include <migraph/program.hpp>
#include <migraph/instruction.hpp>
#include <migraph
x
/program.hpp>
#include <migraph
x
/instruction.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
#include <rob.hpp>
TEST_CASE
(
simple_test
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
EXPECT
(
bool
{
p
.
validate
()
==
p
.
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
EXPECT
(
result
==
migraph
x
::
literal
{
3
});
EXPECT
(
result
!=
migraph
x
::
literal
{
4
});
}
TEST_CASE
(
out_of_order
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
...
...
@@ -30,7 +30,7 @@ TEST_CASE(out_of_order)
TEST_CASE
(
incomplete_args
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
...
...
@@ -39,14 +39,14 @@ TEST_CASE(incomplete_args)
EXPECT
(
bool
{
p
.
validate
()
==
ins
});
}
MIGRAPH_ROB
(
access_ins_arguments
,
std
::
vector
<
migraph
::
instruction_ref
>
,
migraph
::
instruction
,
arguments
)
MIGRAPH
X
_ROB
(
access_ins_arguments
,
std
::
vector
<
migraph
x
::
instruction_ref
>
,
migraph
x
::
instruction
,
arguments
)
TEST_CASE
(
invalid_args
)
{
migraph
::
program
p
;
migraph
x
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
...
...
tools/generate.sh
View file @
bc5d7f75
DIR
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
ls
-1
$DIR
/include/ | xargs
-n
1
-P
$(
nproc
)
-I
{}
-t
bash
-c
"python3.6
$DIR
/te.py
$DIR
/include/{} | clang-format-5.0 -style=file >
$DIR
/../src/include/migraph/{}"
ls
-1
$DIR
/include/ | xargs
-n
1
-P
$(
nproc
)
-I
{}
-t
bash
-c
"python3.6
$DIR
/te.py
$DIR
/include/{} | clang-format-5.0 -style=file >
$DIR
/../src/include/migraph
x
/{}"
tools/include/concat_opt.hpp
View file @
bc5d7f75
#ifndef MIGRAPH_GUARD_CONCAT_OPT_HPP
#define MIGRAPH_GUARD_CONCAT_OPT_HPP
#ifndef MIGRAPH
X
_GUARD_CONCAT_OPT_HPP
#define MIGRAPH
X
_GUARD_CONCAT_OPT_HPP
#include <cassert>
#include <string>
...
...
@@ -8,10 +8,12 @@
#include <type_traits>
#include <utility>
#include <migraph/operation.hpp>
#include <migraph/operators.hpp>
#include <migraphx/operation.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/config.hpp>
namespace
migraph
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
struct
program
;
...
...
@@ -40,6 +42,7 @@ interface('concat_optimization',
#endif
}
// namespace migraph
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
tools/include/context.hpp
View file @
bc5d7f75
#ifndef MIGRAPH_GUARD_CONTEXT_HPP
#define MIGRAPH_GUARD_CONTEXT_HPP
#ifndef MIGRAPH
X
_GUARD_CONTEXT_HPP
#define MIGRAPH
X
_GUARD_CONTEXT_HPP
#include <cassert>
#include <string>
...
...
@@ -7,8 +7,10 @@
#include <memory>
#include <type_traits>
#include <utility>
#include <migraphx/config.hpp>
namespace
migraph
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
#ifdef DOXYGEN
...
...
@@ -31,6 +33,7 @@ interface('context',
#endif
}
// namespace migraph
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
tools/include/operation.hpp
View file @
bc5d7f75
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_OPERAND_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_OPERAND_HPP
#ifndef MIGRAPH
X
_GUARD_MIGRAPHLIB_OPERAND_HPP
#define MIGRAPH
X
_GUARD_MIGRAPHLIB_OPERAND_HPP
#include <cassert>
#include <string>
...
...
@@ -7,14 +7,16 @@
#include <memory>
#include <type_traits>
#include <utility>
#include <migraph/shape.hpp>
#include <migraph/reflect.hpp>
#include <migraph/streamutils.hpp>
#include <migraph/argument.hpp>
#include <migraph/context.hpp>
#include <migraph/auto_any_cast.hpp>
#include <migraphx/reflect.hpp>
#include <migraphx/streamutils.hpp>
#include <migraphx/argument.hpp>
#include <migraphx/auto_any_cast.hpp>
#include <migraphx/config.hpp>
namespace
migraph
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
struct
context
;
#ifdef DOXYGEN
...
...
@@ -24,6 +26,8 @@ struct operation
{
/// A unique name identifying the operation
std
::
string
name
()
const
;
/// An optional method that can be used to finalize the operator before running
void
finalize
(
context
&
ctx
);
/// This is used to compute the resulting shape from an operation. If an
/// operation cannot be run with input shapes, then it should throw an
/// exception.
...
...
@@ -51,6 +55,11 @@ struct operation
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
operation
&
op
);
};
/// Returns true if operation does not require a context to run compute
bool
is_context_free
(
const
operation
&
x
);
/// Returns true if the operation has a finalize method
bool
has_finalize
(
const
operation
&
x
);
#else
namespace
operation_stream
{
...
...
@@ -87,7 +96,7 @@ auto operator==(const T& x, const U& y) -> decltype(x.name() == y.name())
}
// namespace operation_equal
template
<
class
T
>
auto
compute_op
(
rank
<
1
>
,
auto
compute_op
(
rank
<
2
>
,
const
T
&
x
,
context
&
ctx
,
const
shape
&
output_shape
,
...
...
@@ -97,18 +106,72 @@ auto compute_op(rank<1>,
return
x
.
compute
(
auto_any_cast
(
ctx
),
output_shape
,
input
);
}
template
<
class
T
>
auto
compute_op
(
rank
<
1
>
,
const
T
&
x
,
context
&
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
->
decltype
(
x
.
compute
(
output_shape
,
input
))
{
return
x
.
compute
(
output_shape
,
input
);
}
template
<
class
T
>
argument
compute_op
(
rank
<
0
>
,
const
T
&
x
,
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
{
std
::
string
name
=
x
.
name
();
MIGRAPH_THROW
(
"Not computable: "
+
name
);
MIGRAPH
X
_THROW
(
"Not computable: "
+
name
);
}
template
<
class
T
>
argument
compute_op
(
const
T
&
x
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
{
return
compute_op
(
rank
<
1
>
{},
x
,
ctx
,
output_shape
,
input
);
return
compute_op
(
rank
<
2
>
{},
x
,
ctx
,
output_shape
,
input
);
}
template
<
class
T
>
auto
compute_op
(
rank
<
2
>
,
const
T
&
x
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
->
decltype
(
x
.
compute
(
output_shape
,
input
))
{
return
x
.
compute
(
output_shape
,
input
);
}
template
<
class
T
>
auto
compute_op
(
rank
<
1
>
,
const
T
&
x
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
->
decltype
(
x
.
compute
(
auto_any_cast
(
std
::
declval
<
context
&>
()),
output_shape
,
input
))
{
std
::
string
name
=
x
.
name
();
MIGRAPHX_THROW
(
"Not computable without a context: "
+
name
);
}
template
<
class
T
>
argument
compute_op
(
rank
<
0
>
,
const
T
&
x
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
{
std
::
string
name
=
x
.
name
();
MIGRAPHX_THROW
(
"Not computable: "
+
name
);
}
template
<
class
T
>
argument
compute_op
(
const
T
&
x
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
{
return
compute_op
(
rank
<
2
>
{},
x
,
output_shape
,
input
);
}
template
<
class
T
>
auto
is_context_free_op
(
rank
<
1
>
,
const
T
&
x
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
input
)
->
decltype
(
x
.
compute
(
output_shape
,
input
),
std
::
true_type
{});
template
<
class
T
>
auto
is_context_free_op
(
rank
<
0
>
,
const
T
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
)
->
std
::
false_type
;
template
<
class
T
>
auto
is_context_free_op
(
const
T
&
x
)
->
decltype
(
is_context_free_op
(
rank
<
1
>
{},
x
,
std
::
declval
<
const
shape
&>
(),
std
::
declval
<
std
::
vector
<
argument
>>
()))
{
return
{};
}
template
<
class
T
>
...
...
@@ -130,15 +193,60 @@ int output_alias_op(const T& x, const std::vector<shape>& shapes)
return
output_alias_op
(
rank
<
1
>
{},
x
,
shapes
);
}
template
<
class
T
>
auto
finalize_op
(
rank
<
1
>
,
T
&
x
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
shape
>&
input
)
->
decltype
(
x
.
finalize
(
auto_any_cast
(
ctx
),
output_shape
,
input
),
void
())
{
x
.
finalize
(
auto_any_cast
(
ctx
),
output_shape
,
input
);
}
template
<
class
T
>
void
finalize_op
(
rank
<
0
>
,
T
&
,
context
&
,
const
shape
&
,
const
std
::
vector
<
shape
>&
)
{
}
template
<
class
T
>
void
finalize_op
(
T
&
x
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
shape
>&
input
)
{
finalize_op
(
rank
<
1
>
{},
x
,
ctx
,
output_shape
,
input
);
}
template
<
class
T
>
auto
has_finalize_op
(
rank
<
1
>
,
T
&
x
,
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
shape
>&
input
)
->
decltype
(
x
.
finalize
(
auto_any_cast
(
ctx
),
output_shape
,
input
),
std
::
true_type
{});
template
<
class
T
>
auto
has_finalize_op
(
rank
<
0
>
,
T
&
,
context
&
,
const
shape
&
,
const
std
::
vector
<
shape
>&
)
->
std
::
false_type
;
template
<
class
T
>
auto
has_finalize_op
(
const
T
&
)
->
decltype
(
has_finalize_op
(
rank
<
1
>
{},
std
::
declval
<
T
&>
(),
std
::
declval
<
context
&>
(),
std
::
declval
<
const
shape
&>
(),
std
::
declval
<
std
::
vector
<
shape
>>
()))
{
return
{};
}
<%
interface
(
'
operation
'
,
virtual
(
'
name
'
,
returns
=
'
std
::
string
'
,
const
=
True
),
virtual
(
'
is_context_free
'
,
returns
=
'
bool
'
,
const
=
True
,
default
=
'
is_context_free_op
'
),
virtual
(
'
has_finalize
'
,
returns
=
'
bool
'
,
const
=
True
,
default
=
'
has_finalize_op
'
),
virtual
(
'
output_alias
'
,
returns
=
'
int
'
,
input
=
'
const
std
::
vector
<
shape
>&
'
,
const
=
True
,
default
=
'
output_alias_op
'
),
virtual
(
'
finalize
'
,
ctx
=
'
context
&
'
,
output
=
'
const
shape
&
'
,
input
=
'
const
std
::
vector
<
shape
>&
'
,
default
=
'
finalize_op
'
),
virtual
(
'
compute_shape
'
,
returns
=
'
shape
'
,
input
=
'
const
std
::
vector
<
shape
>&
'
,
const
=
True
),
virtual
(
'
compute
'
,
returns
=
'
argument
'
,
...
...
@@ -147,24 +255,47 @@ int output_alias_op(const T& x, const std::vector<shape>& shapes)
input
=
'
const
std
::
vector
<
argument
>&
'
,
const
=
True
,
default
=
'
compute_op
'
),
virtual
(
'
compute
'
,
returns
=
'
argument
'
,
output
=
'
const
shape
&
'
,
input
=
'
const
std
::
vector
<
argument
>&
'
,
const
=
True
,
default
=
'
compute_op
'
),
friend
(
'
operator
<<
'
,
returns
=
'
std
::
ostream
&
'
,
os
=
'
std
::
ostream
&
'
,
op
=
'
const
operation
&
'
,
using
=
'
migraph
::
operation_stream
::
operator
<<
'
),
using
=
'
migraph
x
::
operation_stream
::
operator
<<
'
),
friend
(
'
operator
==
'
,
returns
=
'
bool
'
,
x
=
'
const
operation
&
'
,
y
=
'
const
operation
&
'
,
using
=
'
migraph
::
operation_equal
::
operator
==
'
))
%>
using
=
'
migraph
x
::
operation_equal
::
operator
==
'
))
%>
inline
bool
operator
!=
(
const
operation
&
x
,
const
operation
&
y
)
{
return
!
(
x
==
y
);
}
inline
bool
is_context_free
(
const
operation
&
op
)
{
return
op
.
is_context_free
();
}
template
<
class
T
>
bool
is_context_free
(
const
T
&
x
)
{
return
is_context_free_op
(
x
);
}
inline
bool
has_finalize
(
const
operation
&
op
)
{
return
op
.
has_finalize
();
}
template
<
class
T
>
bool
has_finalize
(
const
T
&
x
)
{
return
has_finalize_op
(
x
);
}
#endif
}
// namespace migraph
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
tools/include/pass.hpp
View file @
bc5d7f75
#ifndef MIGRAPH_GUARD_PASS_HPP
#define MIGRAPH_GUARD_PASS_HPP
#ifndef MIGRAPH
X
_GUARD_PASS_HPP
#define MIGRAPH
X
_GUARD_PASS_HPP
#include <cassert>
#include <string>
...
...
@@ -7,8 +7,10 @@
#include <memory>
#include <type_traits>
#include <utility>
#include <migraphx/config.hpp>
namespace
migraph
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
struct
program
;
...
...
@@ -35,6 +37,7 @@ interface('pass',
#endif
}
// namespace migraph
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
tools/include/target.hpp
View file @
bc5d7f75
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_TARGET_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_TARGET_HPP
#ifndef MIGRAPH
X
_GUARD_MIGRAPHLIB_TARGET_HPP
#define MIGRAPH
X
_GUARD_MIGRAPHLIB_TARGET_HPP
#include <cassert>
#include <string>
...
...
@@ -8,10 +8,12 @@
#include <type_traits>
#include <utility>
#include <vector>
#include <migraph/context.hpp>
#include <migraph/pass.hpp>
#include <migraphx/context.hpp>
#include <migraphx/pass.hpp>
#include <migraphx/config.hpp>
namespace
migraph
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
#ifdef DOXYGEN
...
...
@@ -48,6 +50,7 @@ interface('target',
#endif
}
// namespace migraph
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
tools/te.py
View file @
bc5d7f75
...
...
@@ -71,6 +71,11 @@ struct ${struct_name}
${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:
struct private_detail_te_handle_base_type
{
...
...
@@ -179,7 +184,7 @@ nonvirtual_member = string.Template('''
${friend} ${return_type} ${name}(${params}) ${const}
{
assert(${this}.private_detail_te_handle_mem_var);
return ${this}.private_detail_te_get_handle().${internal_name}(${member_args});
${
return
_}
${this}.private_detail_te_get_handle().${internal_name}(${member_args});
}
'''
)
...
...
@@ -189,7 +194,7 @@ virtual_member = string.Template('''
${return_type} ${internal_name}(${member_params}) ${member_const} override
{
${using}
return ${call};
${
return
_}
${call};
}
'''
)
...
...
@@ -240,7 +245,8 @@ def convert_member(d, struct_name):
'friend'
:
''
,
'this'
:
'(*this)'
,
'using'
:
''
,
'brief'
:
''
'brief'
:
''
,
'return_'
:
''
}
args
=
[]
params
=
[]
...
...
@@ -257,7 +263,8 @@ def convert_member(d, struct_name):
for
x
in
d
[
name
]:
t
=
d
[
name
][
x
]
if
x
==
'return'
:
member
[
'return_type'
]
=
t
member
[
'return_type'
]
=
t
if
t
else
'void'
if
member
[
'return_type'
]
!=
'void'
:
member
[
'return_'
]
=
'return'
elif
x
==
'const'
:
member
[
'const'
]
=
'const'
member
[
'member_const'
]
=
'const'
...
...
Prev
1
…
13
14
15
16
17
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