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
3e0b715a
"docs/source/misc/kd_example.rst" did not exist on "5bf5e46c69328444ac777cabd8ddf5b412230771"
Commit
3e0b715a
authored
Apr 29, 2019
by
Khalique
Browse files
manual merge
parents
f4178abd
6f115a0f
Changes
40
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
386 additions
and
37 deletions
+386
-37
src/include/migraphx/op/sigmoid.hpp
src/include/migraphx/op/sigmoid.hpp
+5
-2
src/include/migraphx/op/sin.hpp
src/include/migraphx/op/sin.hpp
+5
-2
src/include/migraphx/op/sinh.hpp
src/include/migraphx/op/sinh.hpp
+5
-2
src/include/migraphx/op/sub.hpp
src/include/migraphx/op/sub.hpp
+5
-2
src/include/migraphx/op/tan.hpp
src/include/migraphx/op/tan.hpp
+5
-2
src/include/migraphx/op/tanh.hpp
src/include/migraphx/op/tanh.hpp
+5
-2
src/include/migraphx/op/unary.hpp
src/include/migraphx/op/unary.hpp
+24
-11
src/include/migraphx/propagate_constant.hpp
src/include/migraphx/propagate_constant.hpp
+4
-4
src/propagate_constant.cpp
src/propagate_constant.cpp
+44
-0
src/targets/cpu/lowering.cpp
src/targets/cpu/lowering.cpp
+1
-0
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+1
-0
src/targets/gpu/abs.cpp
src/targets/gpu/abs.cpp
+1
-1
src/targets/gpu/adjust_allocation.cpp
src/targets/gpu/adjust_allocation.cpp
+38
-0
src/targets/gpu/include/migraphx/gpu/adjust_allocation.hpp
src/targets/gpu/include/migraphx/gpu/adjust_allocation.hpp
+23
-0
src/targets/gpu/include/migraphx/gpu/oper.hpp
src/targets/gpu/include/migraphx/gpu/oper.hpp
+2
-2
src/targets/gpu/tanh.cpp
src/targets/gpu/tanh.cpp
+1
-1
src/targets/gpu/target.cpp
src/targets/gpu/target.cpp
+5
-2
test/gpu/adjust_allocation.cpp
test/gpu/adjust_allocation.cpp
+69
-0
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+28
-4
test/propagate_constant_test.cpp
test/propagate_constant_test.cpp
+115
-0
No files found.
src/include/migraphx/op/sigmoid.hpp
View file @
3e0b715a
...
@@ -17,9 +17,12 @@ namespace migraphx {
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
sigmoid
:
unary
struct
sigmoid
:
unary
<
sigmoid
>
{
{
std
::
string
name
()
const
{
return
"sigmoid"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
1.
f
/
(
1.
f
+
std
::
exp
(
-
x
));
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/sin.hpp
View file @
3e0b715a
...
@@ -17,9 +17,12 @@ namespace migraphx {
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
sin
:
unary
struct
sin
:
unary
<
sin
>
{
{
std
::
string
name
()
const
{
return
"sin"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
sin
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/sinh.hpp
View file @
3e0b715a
...
@@ -17,9 +17,12 @@ namespace migraphx {
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
sinh
:
unary
struct
sinh
:
unary
<
sinh
>
{
{
std
::
string
name
()
const
{
return
"sinh"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
sinh
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/sub.hpp
View file @
3e0b715a
...
@@ -17,9 +17,12 @@ namespace migraphx {
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
sub
:
binary
struct
sub
:
binary
<
sub
>
{
{
std
::
string
name
()
const
{
return
"sub"
;
}
auto
apply
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
-
y
;
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/tan.hpp
View file @
3e0b715a
...
@@ -17,9 +17,12 @@ namespace migraphx {
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
tan
:
unary
struct
tan
:
unary
<
tan
>
{
{
std
::
string
name
()
const
{
return
"tan"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
tan
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/tanh.hpp
View file @
3e0b715a
...
@@ -17,9 +17,12 @@ namespace migraphx {
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
tanh
:
unary
struct
tanh
:
unary
<
tanh
>
{
{
std
::
string
name
()
const
{
return
"tanh"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
tanh
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/unary.hpp
View file @
3e0b715a
#ifndef MIGRAPHX_GUARD_OPERATORS_UNARY_HPP
#ifndef MIGRAPHX_GUARD_OPERATORS_UNARY_HPP
#define MIGRAPHX_GUARD_OPERATORS_UNARY_HPP
#define MIGRAPHX_GUARD_OPERATORS_UNARY_HPP
#include <array>
#include <migraphx/op/name.hpp>
#include <migraphx/operation.hpp>
#include <migraphx/check_shapes.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/streamutils.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <cmath>
#include <utility>
namespace
migraphx
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
unary
template
<
class
Derived
>
struct
unary
:
op_name
<
Derived
>
{
{
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
{
check_shapes
{
inputs
}.
has
(
1
);
check_shapes
{
inputs
}.
has
(
1
);
return
inputs
.
at
(
0
);
return
inputs
.
at
(
0
);
}
}
argument
compute
(
const
shape
&
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
argument
result
{
output_shape
};
visit_all
(
result
,
args
[
0
])([
&
](
auto
output
,
auto
input
)
{
if
(
input
.
get_shape
().
standard
())
{
std
::
transform
(
input
.
begin
(),
input
.
end
(),
output
.
begin
(),
static_cast
<
const
Derived
&>
(
*
this
).
apply
());
}
else
{
shape_for_each
(
output
.
get_shape
(),
[
&
](
const
auto
&
idx
)
{
output
(
idx
.
begin
(),
idx
.
end
())
=
static_cast
<
const
Derived
&>
(
*
this
).
apply
()(
input
(
idx
.
begin
(),
idx
.
end
()));
});
}
});
return
result
;
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/
constant_
propagate.hpp
→
src/include/migraphx/propagate
_constant
.hpp
View file @
3e0b715a
#ifndef MIGRAPHX_GUARD_RTGLIB_
CONSTANT_
PROPAGATE_HPP
#ifndef MIGRAPHX_GUARD_RTGLIB_PROPAGATE
_CONSTANT
_HPP
#define MIGRAPHX_GUARD_RTGLIB_
CONSTANT_
PROPAGATE_HPP
#define MIGRAPHX_GUARD_RTGLIB_PROPAGATE
_CONSTANT
_HPP
#include <string>
#include <string>
#include <migraphx/config.hpp>
#include <migraphx/config.hpp>
...
@@ -12,9 +12,9 @@ struct program;
...
@@ -12,9 +12,9 @@ struct program;
/**
/**
* Replace instructions which take all literals with a literal of the computation.
* Replace instructions which take all literals with a literal of the computation.
*/
*/
struct
constant_
propagate
struct
propagate
_constant
{
{
std
::
string
name
()
const
{
return
"
constant_
propagate"
;
}
std
::
string
name
()
const
{
return
"propagate
_constant
"
;
}
void
apply
(
program
&
p
)
const
;
void
apply
(
program
&
p
)
const
;
};
};
...
...
src/propagate_constant.cpp
0 → 100644
View file @
3e0b715a
#include <migraphx/propagate_constant.hpp>
#include <migraphx/program.hpp>
#include <migraphx/matcher.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/functional.hpp>
#include <unordered_set>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
bool
skip_propogate
(
instruction_ref
ins
)
{
if
(
ins
->
name
()
==
"@literal"
)
return
true
;
auto
&&
s
=
ins
->
get_shape
();
if
(
s
.
broadcasted
()
and
not
s
.
scalar
())
return
true
;
if
(
s
.
scalar
()
and
s
.
elements
()
!=
1
)
return
true
;
return
false
;
}
void
propagate_constant
::
apply
(
program
&
p
)
const
{
fix
([
&
](
auto
self
,
auto
ins
)
{
if
(
not
skip_propogate
(
ins
))
{
auto
r
=
ins
->
eval
();
if
(
not
r
.
empty
())
{
assert
(
r
.
get_shape
()
==
ins
->
get_shape
());
auto
l
=
p
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
p
.
replace_instruction
(
ins
,
l
);
return
;
}
}
std
::
unordered_set
<
instruction_ref
>
children
(
ins
->
inputs
().
begin
(),
ins
->
inputs
().
end
());
for
(
auto
child
:
children
)
self
(
child
);
})(
std
::
prev
(
p
.
end
()));
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/cpu/lowering.cpp
View file @
3e0b715a
...
@@ -614,6 +614,7 @@ struct cpu_unary
...
@@ -614,6 +614,7 @@ struct cpu_unary
std
::
transform
(
input
.
begin
(),
input
.
end
(),
output
.
begin
(),
op
.
fcn
());
std
::
transform
(
input
.
begin
(),
input
.
end
(),
output
.
begin
(),
op
.
fcn
());
});
});
});
});
return
result
;
return
result
;
}
}
};
};
...
...
src/targets/gpu/CMakeLists.txt
View file @
3e0b715a
...
@@ -66,6 +66,7 @@ add_library(migraphx_gpu
...
@@ -66,6 +66,7 @@ add_library(migraphx_gpu
gather.cpp
gather.cpp
lrn.cpp
lrn.cpp
schedule_model.cpp
schedule_model.cpp
adjust_allocation.cpp
clip.cpp
clip.cpp
)
)
set_target_properties
(
migraphx_gpu PROPERTIES EXPORT_NAME gpu
)
set_target_properties
(
migraphx_gpu PROPERTIES EXPORT_NAME gpu
)
...
...
src/targets/gpu/abs.cpp
View file @
3e0b715a
...
@@ -8,7 +8,7 @@ namespace gpu {
...
@@ -8,7 +8,7 @@ namespace gpu {
shape
miopen_abs
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
shape
miopen_abs
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
not_broadcasted
();
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
not_broadcasted
();
return
inputs
.
at
(
1
);
return
inputs
.
at
(
0
);
}
}
argument
miopen_abs
::
compute
(
context
&
ctx
,
argument
miopen_abs
::
compute
(
context
&
ctx
,
...
...
src/targets/gpu/adjust_allocation.cpp
0 → 100644
View file @
3e0b715a
#include <migraphx/gpu/adjust_allocation.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/program.hpp>
#include <migraphx/iterator_for.hpp>
#include <algorithm>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
void
adjust_allocation
::
apply
(
program
&
p
)
const
{
for
(
auto
ins
:
iterator_for
(
p
))
{
// skip instruction with no input
if
(
ins
->
inputs
().
empty
())
continue
;
if
(
ins
->
name
()
==
"load"
)
continue
;
auto
alias_ins
=
instruction
::
get_output_alias
(
ins
,
true
);
if
(
alias_ins
->
name
()
==
"hip::allocate"
)
{
// shape allocated is different from actual shape
// of the instruction, reallocate and replace the previous one
if
(
alias_ins
->
get_shape
()
!=
ins
->
get_shape
())
{
auto
alloc_ins
=
p
.
insert_instruction
(
ins
,
hip_allocate
{
ins
->
get_shape
()});
p
.
replace_instruction
(
alias_ins
,
alloc_ins
);
}
}
}
}
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/include/migraphx/gpu/adjust_allocation.hpp
0 → 100644
View file @
3e0b715a
#ifndef MIGRAPHX_GUARD_RTGLIB_ADJUST_ALLOCATION_HPP
#define MIGRAPHX_GUARD_RTGLIB_ADJUST_ALLOCATION_HPP
#include <migraphx/program.hpp>
#include <migraphx/config.hpp>
#include <migraphx/gpu/context.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
adjust_allocation
{
std
::
string
name
()
const
{
return
"gpu::adjust_allocation"
;
}
void
apply
(
program
&
p
)
const
;
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/oper.hpp
View file @
3e0b715a
...
@@ -45,7 +45,7 @@ struct unary_device : oper<Derived>
...
@@ -45,7 +45,7 @@ struct unary_device : oper<Derived>
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
);
check_shapes
{
inputs
,
*
this
}.
has
(
2
);
return
inputs
.
at
(
0
);
return
inputs
.
at
(
1
);
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
...
@@ -63,7 +63,7 @@ struct binary_device : oper<Derived>
...
@@ -63,7 +63,7 @@ struct binary_device : oper<Derived>
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
{
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
return
inputs
.
at
(
0
);
return
inputs
.
at
(
2
);
}
}
argument
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
...
...
src/targets/gpu/tanh.cpp
View file @
3e0b715a
...
@@ -8,7 +8,7 @@ namespace gpu {
...
@@ -8,7 +8,7 @@ namespace gpu {
shape
miopen_tanh
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
shape
miopen_tanh
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
not_broadcasted
();
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
not_broadcasted
();
return
inputs
.
at
(
1
);
return
inputs
.
at
(
0
);
}
}
argument
miopen_tanh
::
compute
(
context
&
ctx
,
argument
miopen_tanh
::
compute
(
context
&
ctx
,
...
...
src/targets/gpu/target.cpp
View file @
3e0b715a
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/simplify_algebra.hpp>
#include <migraphx/simplify_algebra.hpp>
#include <migraphx/
constant_
propagate.hpp>
#include <migraphx/propagate
_constant
.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/common_subexpression_elimination.hpp>
#include <migraphx/common_subexpression_elimination.hpp>
#include <migraphx/fwd_conv_batchnorm_rewrite.hpp>
#include <migraphx/fwd_conv_batchnorm_rewrite.hpp>
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/gpu/concat_gpu_opt.hpp>
#include <migraphx/gpu/concat_gpu_opt.hpp>
#include <migraphx/gpu/schedule_model.hpp>
#include <migraphx/gpu/schedule_model.hpp>
#include <migraphx/gpu/adjust_allocation.hpp>
#include <migraphx/eliminate_pad.hpp>
#include <migraphx/eliminate_pad.hpp>
#include <migraphx/schedule.hpp>
#include <migraphx/schedule.hpp>
...
@@ -47,7 +48,7 @@ std::vector<pass> target::get_passes(migraphx::context& gctx) const
...
@@ -47,7 +48,7 @@ std::vector<pass> target::get_passes(migraphx::context& gctx) const
//dead_code_elimination{},
//dead_code_elimination{},
simplify_algebra
{},
simplify_algebra
{},
dead_code_elimination
{},
dead_code_elimination
{},
constant_
propagate
{},
propagate
_constant
{},
dead_code_elimination
{},
dead_code_elimination
{},
auto_contiguous
{},
auto_contiguous
{},
//simplify_reshapes{},
//simplify_reshapes{},
...
@@ -57,6 +58,8 @@ std::vector<pass> target::get_passes(migraphx::context& gctx) const
...
@@ -57,6 +58,8 @@ std::vector<pass> target::get_passes(migraphx::context& gctx) const
dead_code_elimination
{},
dead_code_elimination
{},
eliminate_contiguous
{},
eliminate_contiguous
{},
dead_code_elimination
{},
dead_code_elimination
{},
adjust_allocation
{},
dead_code_elimination
{},
fuse_ops
{
&
ctx
},
fuse_ops
{
&
ctx
},
dead_code_elimination
{},
dead_code_elimination
{},
write_literals
{
&
ctx
},
write_literals
{
&
ctx
},
...
...
test/gpu/adjust_allocation.cpp
0 → 100644
View file @
3e0b715a
#include <migraphx/gpu/adjust_allocation.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/op/add.hpp>
#include <migraphx/op/transpose.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/op/tanh.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
struct
lowering_target
{
std
::
string
name
()
const
{
return
"gpu::lowering"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
gctx
)
const
{
auto
&
ctx
=
migraphx
::
any_cast
<
migraphx
::
gpu
::
context
>
(
gctx
);
return
{
migraphx
::
auto_contiguous
{},
migraphx
::
gpu
::
lowering
{
ctx
},
migraphx
::
dead_code_elimination
{},
migraphx
::
eliminate_contiguous
{},
migraphx
::
dead_code_elimination
{}};
}
migraphx
::
gpu
::
context
get_context
()
const
{
return
migraphx
::
gpu
::
context
{};
}
};
TEST_CASE
(
tanh_shape
)
{
auto
create_program
=
[]
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
tx
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
1
,
0
}},
x
);
auto
txh
=
p
.
add_instruction
(
migraphx
::
op
::
tanh
{},
tx
);
p
.
add_instruction
(
migraphx
::
op
::
add
{},
txh
,
txh
);
return
p
;
};
auto
p1
=
create_program
();
auto
p2
=
create_program
();
EXPECT
(
p1
==
p2
);
p1
.
compile
(
lowering_target
{});
p2
.
compile
(
lowering_target
());
EXPECT
(
p1
==
p2
);
for
(
auto
ins
:
iterator_for
(
p1
))
{
if
(
ins
->
name
()
==
"hip::allocate"
)
{
migraphx
::
shape
wrong_s
{
migraphx
::
shape
::
float_type
,
{
3
,
2
},
{
1
,
3
}};
ins
->
replace
(
wrong_s
);
}
}
EXPECT
(
p1
!=
p2
);
migraphx
::
run_passes
(
p2
,
{
migraphx
::
gpu
::
adjust_allocation
{},
migraphx
::
dead_code_elimination
{}});
EXPECT
(
p1
==
p2
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/gpu/miopen.cpp
View file @
3e0b715a
...
@@ -236,8 +236,7 @@ struct test_exp : verify_program<test_exp>
...
@@ -236,8 +236,7 @@ struct test_exp : verify_program<test_exp>
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
6
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
6
}};
std
::
vector
<
float
>
data
{
0.1
f
,
0.2
f
,
1.
f
,
2.
f
,
0.6
f
,
10.
f
};
auto
x
=
p
.
add_instruction
(
migraphx
::
op
::
abs
{},
p
.
add_parameter
(
"x"
,
s
));
auto
x
=
p
.
add_literal
(
s
,
data
);
p
.
add_instruction
(
migraphx
::
op
::
exp
{},
x
);
p
.
add_instruction
(
migraphx
::
op
::
exp
{},
x
);
return
p
;
return
p
;
}
}
...
@@ -249,8 +248,7 @@ struct test_log : verify_program<test_log>
...
@@ -249,8 +248,7 @@ struct test_log : verify_program<test_log>
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
6
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
6
}};
std
::
vector
<
float
>
data
{
0.1
f
,
0.2
f
,
1.
f
,
2.
f
,
0.6
f
,
100.
f
};
auto
x
=
p
.
add_instruction
(
migraphx
::
op
::
abs
{},
p
.
add_parameter
(
"x"
,
s
));
auto
x
=
p
.
add_literal
(
s
,
data
);
p
.
add_instruction
(
migraphx
::
op
::
log
{},
x
);
p
.
add_instruction
(
migraphx
::
op
::
log
{},
x
);
return
p
;
return
p
;
}
}
...
@@ -327,6 +325,19 @@ struct test_tanh : verify_program<test_tanh>
...
@@ -327,6 +325,19 @@ struct test_tanh : verify_program<test_tanh>
}
}
};
};
struct
test_trans_tanh
:
verify_program
<
test_trans_tanh
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
tx
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
1
,
3
,
2
}},
x
);
auto
tanhx
=
p
.
add_instruction
(
migraphx
::
op
::
tanh
{},
tx
);
p
.
add_instruction
(
migraphx
::
op
::
add
{},
tanhx
,
tanhx
);
return
p
;
}
};
struct
test_asin
:
verify_program
<
test_asin
>
struct
test_asin
:
verify_program
<
test_asin
>
{
{
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
...
@@ -674,6 +685,19 @@ struct test_abs : verify_program<test_abs>
...
@@ -674,6 +685,19 @@ struct test_abs : verify_program<test_abs>
}
}
};
};
struct
test_trans_abs
:
verify_program
<
test_trans_abs
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
3
,
3
}});
auto
tx
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
1
,
3
,
2
}},
x
);
auto
tanhx
=
p
.
add_instruction
(
migraphx
::
op
::
abs
{},
tx
);
p
.
add_instruction
(
migraphx
::
op
::
add
{},
tanhx
,
tanhx
);
return
p
;
}
};
struct
test_leaky_relu
:
verify_program
<
test_leaky_relu
>
struct
test_leaky_relu
:
verify_program
<
test_leaky_relu
>
{
{
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
...
...
test/
constant_
propagate_test.cpp
→
test/propagate
_constant
_test.cpp
View file @
3e0b715a
#include <migraphx/
constant_
propagate.hpp>
#include <migraphx/propagate
_constant
.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/op/add.hpp>
#include <migraphx/op/add.hpp>
#include <migraphx/op/scalar.hpp>
#include <migraphx/op/mul.hpp>
#include <basic_ops.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
#include <test.hpp>
...
@@ -9,12 +11,12 @@ struct const_prop_target
...
@@ -9,12 +11,12 @@ struct const_prop_target
std
::
string
name
()
const
{
return
"const_prop"
;
}
std
::
string
name
()
const
{
return
"const_prop"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
)
const
{
{
return
{
migraphx
::
constant_
propagate
{},
migraphx
::
dead_code_elimination
{}};
return
{
migraphx
::
propagate
_constant
{},
migraphx
::
dead_code_elimination
{}};
}
}
migraphx
::
context
get_context
()
const
{
return
{};
}
migraphx
::
context
get_context
()
const
{
return
{};
}
};
};
TEST_CASE
(
const_add
1
)
TEST_CASE
(
const_add
)
{
{
migraphx
::
program
p1
;
migraphx
::
program
p1
;
auto
one
=
p1
.
add_literal
(
1
);
auto
one
=
p1
.
add_literal
(
1
);
...
@@ -29,7 +31,7 @@ TEST_CASE(const_add1)
...
@@ -29,7 +31,7 @@ TEST_CASE(const_add1)
EXPECT
(
p1
==
p2
);
EXPECT
(
p1
==
p2
);
}
}
TEST_CASE
(
const_add
2
)
TEST_CASE
(
const_add
_parameter
)
{
{
migraphx
::
program
p1
;
migraphx
::
program
p1
;
auto
one
=
p1
.
add_parameter
(
"one"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
one
=
p1
.
add_parameter
(
"one"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
...
@@ -44,7 +46,7 @@ TEST_CASE(const_add2)
...
@@ -44,7 +46,7 @@ TEST_CASE(const_add2)
EXPECT
(
p1
!=
p2
);
EXPECT
(
p1
!=
p2
);
}
}
TEST_CASE
(
const_add
3
)
TEST_CASE
(
const_
multi
add
)
{
{
migraphx
::
program
p1
;
migraphx
::
program
p1
;
auto
one
=
p1
.
add_literal
(
1
);
auto
one
=
p1
.
add_literal
(
1
);
...
@@ -60,4 +62,54 @@ TEST_CASE(const_add3)
...
@@ -60,4 +62,54 @@ TEST_CASE(const_add3)
EXPECT
(
p1
==
p2
);
EXPECT
(
p1
==
p2
);
}
}
TEST_CASE
(
const_add_mul
)
{
migraphx
::
program
p1
;
auto
one
=
p1
.
add_literal
(
1
);
auto
two
=
p1
.
add_literal
(
2
);
auto
mul
=
p1
.
add_instruction
(
migraphx
::
op
::
mul
{},
two
,
two
);
auto
sum1
=
p1
.
add_instruction
(
migraphx
::
op
::
add
{},
one
,
mul
);
auto
sum2
=
p1
.
add_instruction
(
migraphx
::
op
::
add
{},
sum1
,
two
);
p1
.
add_instruction
(
pass_op
{},
sum2
);
p1
.
compile
(
const_prop_target
{});
migraphx
::
program
p2
;
auto
total
=
p2
.
add_literal
(
7
);
p2
.
add_instruction
(
pass_op
{},
total
);
EXPECT
(
p1
==
p2
);
}
TEST_CASE
(
const_add_scalar
)
{
migraphx
::
program
p1
;
auto
one
=
p1
.
add_instruction
(
migraphx
::
op
::
scalar
{{
2
,
2
}},
p1
.
add_literal
(
1
));
auto
two
=
p1
.
add_instruction
(
migraphx
::
op
::
scalar
{{
2
,
2
}},
p1
.
add_literal
(
2
));
auto
sum
=
p1
.
add_instruction
(
migraphx
::
op
::
add
{},
one
,
two
);
p1
.
add_instruction
(
pass_op
{},
sum
);
p1
.
compile
(
const_prop_target
{});
migraphx
::
program
p2
;
auto
total
=
p2
.
add_literal
(
migraphx
::
literal
{{
migraphx
::
shape
::
int32_type
,
{
2
,
2
}},
{
3
,
3
,
3
,
3
}});
p2
.
add_instruction
(
pass_op
{},
total
);
EXPECT
(
p1
==
p2
);
}
TEST_CASE
(
const_scalar
)
{
migraphx
::
program
p1
;
{
auto
one
=
p1
.
add_instruction
(
migraphx
::
op
::
scalar
{{
2
,
2
}},
p1
.
add_literal
(
1
));
p1
.
add_instruction
(
pass_op
{},
one
);
}
p1
.
compile
(
const_prop_target
{});
migraphx
::
program
p2
;
{
auto
one
=
p2
.
add_instruction
(
migraphx
::
op
::
scalar
{{
2
,
2
}},
p2
.
add_literal
(
1
));
p2
.
add_instruction
(
pass_op
{},
one
);
}
EXPECT
(
p1
==
p2
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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