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
087c205e
Commit
087c205e
authored
Mar 04, 2019
by
Paul
Browse files
Merge from develop
parents
a3a9e469
e15b8333
Changes
255
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
486 additions
and
242 deletions
+486
-242
src/targets/gpu/include/migraphx/gpu/oper.hpp
src/targets/gpu/include/migraphx/gpu/oper.hpp
+82
-0
src/targets/gpu/include/migraphx/gpu/pad.hpp
src/targets/gpu/include/migraphx/gpu/pad.hpp
+28
-0
src/targets/gpu/include/migraphx/gpu/pooling.hpp
src/targets/gpu/include/migraphx/gpu/pooling.hpp
+3
-14
src/targets/gpu/include/migraphx/gpu/relu.hpp
src/targets/gpu/include/migraphx/gpu/relu.hpp
+3
-15
src/targets/gpu/include/migraphx/gpu/rocblas.hpp
src/targets/gpu/include/migraphx/gpu/rocblas.hpp
+0
-1
src/targets/gpu/include/migraphx/gpu/sigmoid.hpp
src/targets/gpu/include/migraphx/gpu/sigmoid.hpp
+27
-0
src/targets/gpu/include/migraphx/gpu/sin.hpp
src/targets/gpu/include/migraphx/gpu/sin.hpp
+2
-20
src/targets/gpu/include/migraphx/gpu/sinh.hpp
src/targets/gpu/include/migraphx/gpu/sinh.hpp
+19
-0
src/targets/gpu/include/migraphx/gpu/softmax.hpp
src/targets/gpu/include/migraphx/gpu/softmax.hpp
+3
-15
src/targets/gpu/include/migraphx/gpu/sub.hpp
src/targets/gpu/include/migraphx/gpu/sub.hpp
+19
-0
src/targets/gpu/include/migraphx/gpu/tan.hpp
src/targets/gpu/include/migraphx/gpu/tan.hpp
+19
-0
src/targets/gpu/include/migraphx/gpu/tanh.hpp
src/targets/gpu/include/migraphx/gpu/tanh.hpp
+27
-0
src/targets/gpu/leaky_relu.cpp
src/targets/gpu/leaky_relu.cpp
+3
-5
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+149
-136
src/targets/gpu/lrn.cpp
src/targets/gpu/lrn.cpp
+38
-0
src/targets/gpu/mul.cpp
src/targets/gpu/mul.cpp
+0
-26
src/targets/gpu/pad.cpp
src/targets/gpu/pad.cpp
+22
-0
src/targets/gpu/pooling.cpp
src/targets/gpu/pooling.cpp
+3
-5
src/targets/gpu/relu.cpp
src/targets/gpu/relu.cpp
+3
-5
src/targets/gpu/sigmoid.cpp
src/targets/gpu/sigmoid.cpp
+36
-0
No files found.
src/targets/gpu/include/migraphx/gpu/oper.hpp
0 → 100644
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_UNARY_HPP
#define MIGRAPHX_GUARD_RTGLIB_UNARY_HPP
#include <migraphx/gpu/hip.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/argument.hpp>
#include <migraphx/config.hpp>
#include <migraphx/type_name.hpp>
#include <utility>
#include <iostream>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
template
<
class
Derived
>
struct
oper
{
std
::
string
name
()
const
{
const
std
::
string
&
name
=
get_type_name
<
Derived
>
();
// search the namespace gpu (::gpu::)
auto
pos_ns
=
name
.
find
(
"::gpu::"
);
if
(
pos_ns
!=
std
::
string
::
npos
)
{
auto
pos_name
=
name
.
find
(
"hip_"
,
pos_ns
+
std
::
string
(
"::gpu::"
).
length
());
if
(
pos_name
!=
std
::
string
::
npos
)
{
return
std
::
string
(
"gpu::"
)
+
name
.
substr
(
pos_name
+
4
);
}
else
{
return
name
.
substr
(
pos_ns
+
2
);
}
}
return
"unknown"
;
}
};
template
<
class
Derived
,
void
(
*
F
)(
hipStream_t
,
const
argument
&
,
const
argument
&
)>
struct
unary_device
:
oper
<
Derived
>
{
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
);
return
inputs
.
at
(
0
);
}
argument
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
F
(
ctx
.
get_stream
().
get
(),
args
[
1
],
args
[
0
]);
return
args
[
1
];
}
int
output_alias
(
const
std
::
vector
<
shape
>&
shapes
)
const
{
return
shapes
.
size
()
-
1
;
}
};
template
<
class
Derived
,
void
(
*
F
)(
hipStream_t
,
const
argument
&
,
const
argument
&
,
const
argument
&
)>
struct
binary_device
:
oper
<
Derived
>
{
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
return
inputs
.
at
(
0
);
}
argument
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
F
(
ctx
.
get_stream
().
get
(),
args
[
2
],
args
[
1
],
args
[
0
]);
return
args
[
2
];
}
int
output_alias
(
const
std
::
vector
<
shape
>&
shapes
)
const
{
return
shapes
.
size
()
-
1
;
}
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/pad.hpp
0 → 100644
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_PAD_HPP
#define MIGRAPHX_GUARD_RTGLIB_PAD_HPP
#include <migraphx/shape.hpp>
#include <migraphx/operators.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
context
;
struct
hip_pad
{
op
::
pad
op
;
std
::
string
name
()
const
{
return
"gpu::pad"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
;
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
;
int
output_alias
(
const
std
::
vector
<
shape
>&
shapes
)
const
{
return
shapes
.
size
()
-
1
;
}
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/pooling.hpp
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_POOLING_HPP
#define MIGRAPHX_GUARD_RTGLIB_POOLING_HPP
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/dfor.hpp>
#include <migraphx/gpu/device/contiguous.hpp>
#include <migraphx/gpu/device/add.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/rocblas.hpp>
#include <migraphx/gpu/context.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
context
;
struct
miopen_pooling
{
op
::
pooling
op
;
...
...
src/targets/gpu/include/migraphx/gpu/relu.hpp
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_RELU_HPP
#define MIGRAPHX_GUARD_RTGLIB_RELU_HPP
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/dfor.hpp>
#include <migraphx/gpu/device/contiguous.hpp>
#include <migraphx/gpu/device/add.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/rocblas.hpp>
#include <migraphx/gpu/context.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
context
;
struct
miopen_relu
{
shared
<
activation_descriptor
>
ad
;
...
...
src/targets/gpu/include/migraphx/gpu/rocblas.hpp
View file @
087c205e
...
...
@@ -2,7 +2,6 @@
#define MIGRAPHX_GUARD_MIGRAPHLIB_ROCBLAS_HPP
#include <migraphx/manage_ptr.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/config.hpp>
#include <rocblas.h>
...
...
src/targets/gpu/include/migraphx/gpu/sigmoid.hpp
0 → 100644
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_SIGMOID_HPP
#define MIGRAPHX_GUARD_RTGLIB_SIGMOID_HPP
#include <migraphx/shape.hpp>
#include <migraphx/gpu/miopen.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
context
;
struct
miopen_sigmoid
{
shared
<
activation_descriptor
>
ad
;
std
::
string
name
()
const
{
return
"gpu::sigmoid"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
;
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
;
int
output_alias
(
const
std
::
vector
<
shape
>&
shapes
)
const
{
return
shapes
.
size
()
-
1
;
}
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/sin.hpp
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_SIN_HPP
#define MIGRAPHX_GUARD_RTGLIB_SIN_HPP
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/dfor.hpp>
#include <migraphx/gpu/device/contiguous.hpp>
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/sin.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/rocblas.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/config.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
hip_sin
struct
hip_sin
:
unary_device
<
hip_sin
,
device
::
sin
>
{
std
::
string
name
()
const
{
return
"gpu::sin"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
;
argument
compute
(
context
&
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
;
int
output_alias
(
const
std
::
vector
<
shape
>&
shapes
)
const
{
return
shapes
.
size
()
-
1
;
}
};
}
// namespace gpu
...
...
src/targets/gpu/include/migraphx/gpu/sinh.hpp
0 → 100644
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_SINH_HPP
#define MIGRAPHX_GUARD_RTGLIB_SINH_HPP
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/sinh.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
hip_sinh
:
unary_device
<
hip_sinh
,
device
::
sinh
>
{
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/softmax.hpp
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_SOFTMAX_HPP
#define MIGRAPHX_GUARD_RTGLIB_SOFTMAX_HPP
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/dfor.hpp>
#include <migraphx/gpu/device/contiguous.hpp>
#include <migraphx/gpu/device/add.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/rocblas.hpp>
#include <migraphx/gpu/context.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
context
;
struct
miopen_softmax
{
op
::
softmax
op
;
...
...
src/targets/gpu/include/migraphx/gpu/sub.hpp
0 → 100644
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_SUB_HPP
#define MIGRAPHX_GUARD_RTGLIB_SUB_HPP
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/sub.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
hip_sub
:
binary_device
<
hip_sub
,
device
::
sub
>
{
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/tan.hpp
0 → 100644
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_TAN_HPP
#define MIGRAPHX_GUARD_RTGLIB_TAN_HPP
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/tan.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
hip_tan
:
unary_device
<
hip_tan
,
device
::
tan
>
{
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/tanh.hpp
0 → 100644
View file @
087c205e
#ifndef MIGRAPHX_GUARD_RTGLIB_TANH_HPP
#define MIGRAPHX_GUARD_RTGLIB_TANH_HPP
#include <migraphx/shape.hpp>
#include <migraphx/gpu/miopen.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
context
;
struct
miopen_tanh
{
shared
<
activation_descriptor
>
ad
;
std
::
string
name
()
const
{
return
"gpu::tanh"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
;
argument
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
;
int
output_alias
(
const
std
::
vector
<
shape
>&
shapes
)
const
{
return
shapes
.
size
()
-
1
;
}
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/leaky_relu.cpp
View file @
087c205e
#include <migraphx/gpu/leaky_relu.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
#include <migraphx/gpu/context.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
...
@@ -18,7 +15,8 @@ argument miopen_leaky_relu::compute(context& ctx,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
float
alpha
=
1
,
beta
=
0
;
float
alpha
=
1
;
float
beta
=
0
;
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
y_desc
=
make_tensor
(
output_shape
);
miopenActivationForward
(
ctx
.
get_stream
().
get_miopen
(),
...
...
src/targets/gpu/lowering.cpp
View file @
087c205e
...
...
@@ -16,16 +16,37 @@
#include <migraphx/gpu/convolution.hpp>
#include <migraphx/gpu/contiguous.hpp>
#include <migraphx/gpu/relu.hpp>
#include <migraphx/gpu/sigmoid.hpp>
#include <migraphx/gpu/abs.hpp>
#include <migraphx/gpu/leaky_relu.hpp>
#include <migraphx/gpu/elu.hpp>
#include <migraphx/gpu/softmax.hpp>
#include <migraphx/gpu/add.hpp>
#include <migraphx/gpu/sub.hpp>
#include <migraphx/gpu/exp.hpp>
#include <migraphx/gpu/log.hpp>
#include <migraphx/gpu/sin.hpp>
#include <migraphx/gpu/cos.hpp>
#include <migraphx/gpu/tan.hpp>
#include <migraphx/gpu/sinh.hpp>
#include <migraphx/gpu/cosh.hpp>
#include <migraphx/gpu/tanh.hpp>
#include <migraphx/gpu/asin.hpp>
#include <migraphx/gpu/acos.hpp>
#include <migraphx/gpu/atan.hpp>
#include <migraphx/gpu/mul.hpp>
#include <migraphx/gpu/max.hpp>
#include <migraphx/gpu/min.hpp>
#include <migraphx/gpu/batchnorm.hpp>
#include <migraphx/gpu/pooling.hpp>
#include <migraphx/gpu/gemm.hpp>
#include <migraphx/gpu/concat.hpp>
#include <migraphx/gpu/pad.hpp>
#include <migraphx/gpu/gather.hpp>
#include <migraphx/gpu/lrn.hpp>
#include <utility>
#include <functional>
#include <algorithm>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
...
@@ -35,6 +56,8 @@ struct miopen_apply
{
program
*
prog
=
nullptr
;
context
ctx
{};
std
::
unordered_map
<
std
::
string
,
std
::
function
<
instruction_ref
(
instruction_ref
)
>>
apply_map
{};
instruction_ref
last
{};
void
check_shape
(
shape
x
,
instruction_ref
i
)
{
...
...
@@ -43,190 +66,180 @@ struct miopen_apply
(
void
)
i
;
}
void
init
()
{
this
->
last
=
instruction
::
get_output_alias
(
std
::
prev
(
prog
->
end
()));
add_miopen_simple_op
<
miopen_relu
>
(
"relu"
,
make_relu
);
add_miopen_simple_op
<
miopen_sigmoid
>
(
"sigmoid"
,
make_sigmoid
);
add_miopen_simple_op
<
miopen_abs
>
(
"abs"
,
make_abs
);
add_miopen_simple_op
<
miopen_tanh
>
(
"tanh"
,
make_tanh
);
add_miopen_extend_op
<
miopen_leaky_relu
,
op
::
leaky_relu
>
(
"leaky_relu"
,
make_leaky_relu
);
add_miopen_extend_op
<
miopen_elu
,
op
::
elu
>
(
"elu"
,
make_elu
);
add_generic_op
<
hip_add
>
(
"add"
);
add_generic_op
<
hip_sub
>
(
"sub"
);
add_generic_op
<
hip_exp
>
(
"exp"
);
add_generic_op
<
hip_log
>
(
"log"
);
add_generic_op
<
hip_sin
>
(
"sin"
);
add_generic_op
<
hip_cos
>
(
"cos"
);
add_generic_op
<
hip_tan
>
(
"tan"
);
add_generic_op
<
hip_sinh
>
(
"sinh"
);
add_generic_op
<
hip_cosh
>
(
"cosh"
);
add_generic_op
<
hip_asin
>
(
"asin"
);
add_generic_op
<
hip_acos
>
(
"acos"
);
add_generic_op
<
hip_atan
>
(
"atan"
);
add_generic_op
<
hip_mul
>
(
"mul"
);
add_generic_op
<
hip_max
>
(
"max"
);
add_generic_op
<
hip_min
>
(
"min"
);
add_extend_op
<
miopen_gemm
,
op
::
dot
>
(
"dot"
);
add_extend_op
<
miopen_contiguous
,
op
::
contiguous
>
(
"contiguous"
);
add_extend_op
<
hip_concat
,
op
::
concat
>
(
"concat"
);
add_extend_op
<
miopen_softmax
,
op
::
softmax
>
(
"softmax"
);
add_extend_op
<
hip_gather
,
op
::
gather
>
(
"gather"
);
add_extend_op
<
hip_pad
,
op
::
pad
>
(
"pad"
);
add_lrn_op
();
add_convolution_op
();
add_pooling_op
();
add_batch_norm_inference_op
();
}
void
apply
()
{
init
();
for
(
auto
it
=
prog
->
begin
();
it
!=
prog
->
end
();
it
++
)
{
auto
s
=
it
->
get_shape
();
if
(
it
->
name
()
==
"convolution"
)
{
check_shape
(
s
,
apply_convolution
(
it
));
}
else
if
(
it
->
name
()
==
"relu"
)
{
check_shape
(
s
,
apply_relu
(
it
));
}
else
if
(
it
->
name
()
==
"leaky_relu"
)
{
check_shape
(
s
,
apply_leaky_relu
(
it
));
}
else
if
(
it
->
name
()
==
"pooling"
)
{
check_shape
(
s
,
apply_pooling
(
it
));
}
else
if
(
it
->
name
()
==
"add"
)
{
check_shape
(
s
,
apply_add
(
it
));
}
else
if
(
it
->
name
()
==
"sin"
)
{
check_shape
(
s
,
apply_sin
(
it
));
}
else
if
(
it
->
name
()
==
"mul"
)
{
check_shape
(
s
,
apply_mul
(
it
));
}
else
if
(
it
->
name
()
==
"dot"
)
{
check_shape
(
s
,
apply_gemm
(
it
));
}
else
if
(
it
->
name
()
==
"contiguous"
)
if
(
apply_map
.
count
(
it
->
name
())
>
0
)
{
check_shape
(
s
,
apply_contiguous
(
it
));
}
else
if
(
it
->
name
()
==
"concat"
)
{
check_shape
(
s
,
apply_concat
(
it
));
}
else
if
(
it
->
name
()
==
"batch_norm_inference"
)
{
check_shape
(
s
,
apply_batch_norm_inference
(
it
));
}
else
if
(
it
->
name
()
==
"softmax"
)
{
check_shape
(
s
,
apply_softmax
(
it
));
check_shape
(
s
,
apply_map
.
at
(
it
->
name
())(
it
));
}
}
}
instruction_ref
insert_allocation
(
instruction_ref
ins
,
const
shape
&
s
,
std
::
string
tag
=
""
)
{
if
(
ins
==
--
prog
->
end
()
and
tag
.
empty
())
if
(
ins
==
last
and
tag
.
empty
())
{
return
prog
->
add_parameter
(
"output"
,
s
);
}
else
{
auto
is
=
prog
->
add_outline
(
s
);
auto
result
=
prog
->
insert_instruction
(
ins
,
hip_allocate
{
std
::
move
(
tag
)},
is
);
auto
result
=
prog
->
insert_instruction
(
ins
,
hip_allocate
{
s
,
std
::
move
(
tag
)});
return
result
;
}
}
instruction_ref
apply_convolution
(
instruction_ref
ins
)
void
add_convolution_op
(
)
{
auto
&&
op
=
any_cast
<
op
::
convolution
>
(
ins
->
get_operator
());
apply_map
.
emplace
(
"convolution"
,
[
=
](
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
op
::
convolution
>
(
ins
->
get_operator
());
auto
conv
=
miopen_convolution
{
op
,
make_conv
(
op
)};
auto
ws
=
conv
.
compile
(
ctx
,
ins
->
get_shape
(),
ins
->
inputs
());
auto
conv
=
miopen_convolution
{
op
,
make_conv
(
op
)};
auto
ws
=
conv
.
compile
(
ctx
,
ins
->
get_shape
(),
to_shapes
(
ins
->
inputs
())
)
;
auto
workspace
=
insert_allocation
(
ins
,
ws
,
"workspace"
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
auto
workspace
=
insert_allocation
(
ins
,
ws
,
"workspace"
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
conv
,
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
workspace
,
output
);
return
prog
->
replace_instruction
(
ins
,
conv
,
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
workspace
,
output
);
});
}
instruction_ref
apply_pooling
(
instruction_ref
ins
)
void
add_pooling_op
(
)
{
auto
&&
op
=
any_cast
<
op
::
pooling
>
(
ins
->
get_operator
());
auto
pd
=
make_pooling
(
op
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_pooling
{
op
,
std
::
move
(
pd
)},
ins
->
inputs
().
at
(
0
),
output
);
apply_map
.
emplace
(
"pooling"
,
[
=
](
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
op
::
pooling
>
(
ins
->
get_operator
());
auto
pd
=
make_pooling
(
op
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_pooling
{
op
,
std
::
move
(
pd
)},
ins
->
inputs
().
at
(
0
),
output
);
});
}
instruction_ref
apply_relu
(
instruction_ref
ins
)
void
add_lrn_op
(
)
{
auto
ad
=
make_relu
();
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_relu
{
std
::
move
(
ad
)},
ins
->
inputs
().
at
(
0
),
output
);
apply_map
.
emplace
(
"lrn"
,
[
=
](
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
op
::
lrn
>
(
ins
->
get_operator
());
auto
ldesc
=
make_lrn
(
op
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_lrn
{
std
::
move
(
ldesc
)},
ins
->
inputs
().
at
(
0
),
output
);
});
}
instruction_ref
apply_leaky_relu
(
instruction_ref
ins
)
template
<
class
T
>
void
add_generic_op
(
std
::
string
name
)
{
auto
&&
op
=
any_cast
<
op
::
leaky_relu
>
(
ins
->
get_operator
());
auto
ad
=
make_leaky_relu
(
op
.
alpha
);
apply_map
.
emplace
(
name
,
[
=
](
instruction_ref
ins
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
std
::
vector
<
instruction_ref
>
refs
=
ins
->
inputs
();
refs
.
push_back
(
output
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_leaky_relu
{
std
::
move
(
ad
)},
ins
->
inputs
().
at
(
0
),
output
);
return
prog
->
replace_instruction
(
ins
,
T
{},
refs
);
});
}
instruction_ref
apply_softmax
(
instruction_ref
ins
)
template
<
class
T
,
class
Op
>
void
add_extend_op
(
std
::
string
name
)
{
auto
&&
op
=
any_cast
<
op
::
softmax
>
(
ins
->
get_operator
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_softmax
{
op
},
ins
->
inputs
().
at
(
0
),
output
);
apply_map
.
emplace
(
name
,
[
=
](
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
Op
>
(
ins
->
get_operator
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
std
::
vector
<
instruction_ref
>
refs
=
ins
->
inputs
();
refs
.
push_back
(
output
);
return
prog
->
replace_instruction
(
ins
,
T
{
op
},
refs
);
});
}
instruction_ref
apply_add
(
instruction_ref
ins
)
template
<
class
T
,
class
Op
,
class
F
>
void
add_miopen_extend_op
(
std
::
string
name
,
F
f
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
hip_add
{},
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
output
);
}
apply_map
.
emplace
(
name
,
[
=
](
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
Op
>
(
ins
->
get_operator
());
auto
ad
=
f
(
op
.
alpha
);
instruction_ref
apply_sin
(
instruction_ref
ins
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
hip_sin
{},
ins
->
inputs
().
at
(
0
),
output
);
}
instruction_ref
apply_mul
(
instruction_ref
ins
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
hip_mul
{},
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
output
);
}
instruction_ref
apply_gemm
(
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
op
::
dot
>
(
ins
->
get_operator
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_gemm
{
op
},
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
output
);
}
instruction_ref
apply_contiguous
(
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
op
::
contiguous
>
(
ins
->
get_operator
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
miopen_contiguous
{
op
},
ins
->
inputs
().
at
(
0
),
output
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
T
{
std
::
move
(
ad
)},
ins
->
inputs
().
at
(
0
),
output
);
});
}
instruction_ref
apply_concat
(
instruction_ref
ins
)
template
<
class
T
,
class
F
>
void
add_miopen_simple_op
(
std
::
string
name
,
F
f
)
{
a
uto
&&
op
=
any_cast
<
op
::
concat
>
(
ins
->
get_operator
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
()
);
std
::
vector
<
instruction_ref
>
refs
=
ins
->
inputs
(
);
refs
.
push_back
(
output
);
return
prog
->
replace_instruction
(
ins
,
hip_concat
{
op
},
refs
);
a
pply_map
.
emplace
(
name
,
[
=
](
instruction_ref
ins
)
{
auto
ad
=
f
(
);
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
()
);
return
prog
->
replace_instruction
(
ins
,
T
{
std
::
move
(
ad
)},
ins
->
inputs
().
at
(
0
),
output
);
}
);
}
instruction_ref
apply
_batch_norm_inference
(
instruction_ref
ins
)
void
add
_batch_norm_inference
_op
(
)
{
auto
&&
op
=
any_cast
<
op
::
batch_norm_inference
>
(
ins
->
get_operator
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
shape
old_shape
=
ins
->
inputs
().
at
(
1
)
->
get_shape
();
std
::
vector
<
int64_t
>
new_shape
{
1
,
static_cast
<
int64_t
>
(
old_shape
.
elements
()),
1
,
1
};
auto
reshape_op
=
op
::
reshape
{
new_shape
};
std
::
vector
<
instruction_ref
>
reshapes
;
std
::
transform
(
ins
->
inputs
().
begin
()
+
1
,
ins
->
inputs
().
end
(),
std
::
back_inserter
(
reshapes
),
[
&
](
auto
i
)
{
return
prog
->
insert_instruction
(
ins
,
reshape_op
,
i
);
});
return
prog
->
replace_instruction
(
ins
,
miopen_batch_norm_inference
{
op
},
ins
->
inputs
().
at
(
0
),
reshapes
[
0
],
reshapes
[
1
],
reshapes
[
2
],
reshapes
[
3
],
output
);
apply_map
.
emplace
(
"batch_norm_inference"
,
[
=
](
instruction_ref
ins
)
{
auto
&&
op
=
any_cast
<
op
::
batch_norm_inference
>
(
ins
->
get_operator
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
shape
old_shape
=
ins
->
inputs
().
at
(
1
)
->
get_shape
();
std
::
vector
<
int64_t
>
new_shape
{
1
,
static_cast
<
int64_t
>
(
old_shape
.
elements
()),
1
,
1
};
auto
reshape_op
=
op
::
reshape
{
new_shape
};
std
::
vector
<
instruction_ref
>
reshapes
;
std
::
transform
(
ins
->
inputs
().
begin
()
+
1
,
ins
->
inputs
().
end
(),
std
::
back_inserter
(
reshapes
),
[
&
](
auto
i
)
{
return
prog
->
insert_instruction
(
ins
,
reshape_op
,
i
);
});
return
prog
->
replace_instruction
(
ins
,
miopen_batch_norm_inference
{
op
},
ins
->
inputs
().
at
(
0
),
reshapes
[
0
],
reshapes
[
1
],
reshapes
[
2
],
reshapes
[
3
],
output
);
});
}
};
...
...
src/targets/gpu/lrn.cpp
0 → 100644
View file @
087c205e
#include <migraphx/gpu/lrn.hpp>
#include <migraphx/gpu/context.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
shape
miopen_lrn
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
not_broadcasted
();
return
inputs
.
at
(
1
);
}
argument
miopen_lrn
::
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
float
alpha
=
1
;
float
beta
=
0
;
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
y_desc
=
make_tensor
(
output_shape
);
miopenLRNForward
(
ctx
.
get_stream
().
get_miopen
(),
ldesc
.
get
(),
&
alpha
,
x_desc
.
get
(),
args
[
0
].
implicit
(),
&
beta
,
y_desc
.
get
(),
args
[
1
].
implicit
(),
false
,
nullptr
);
return
args
[
1
];
}
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/mul.cpp
deleted
100644 → 0
View file @
a3a9e469
#include <migraphx/gpu/mul.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
shape
hip_mul
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
// check_shapes{inputs, *this}.has(3).standard();
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
return
inputs
.
at
(
0
);
}
argument
hip_mul
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
device
::
mul
(
ctx
.
get_stream
().
get
(),
args
[
2
],
args
[
0
],
args
[
1
]);
return
args
[
2
];
}
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/pad.cpp
0 → 100644
View file @
087c205e
#include <migraphx/gpu/pad.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/device/pad.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
shape
hip_pad
::
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
inputs
.
pop_back
();
return
op
.
compute_shape
(
inputs
);
}
argument
hip_pad
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
return
device
::
pad
(
ctx
.
get_stream
().
get
(),
args
.
back
(),
args
.
front
(),
op
.
value
,
op
.
pads
);
}
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/pooling.cpp
View file @
087c205e
#include <migraphx/gpu/pooling.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
#include <migraphx/gpu/context.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
...
@@ -20,7 +17,8 @@ argument miopen_pooling::compute(context& ctx,
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
y_desc
=
make_tensor
(
output_shape
);
float
alpha
=
1
,
beta
=
0
;
float
alpha
=
1
;
float
beta
=
0
;
miopenPoolingForward
(
ctx
.
get_stream
().
get_miopen
(),
pd
.
get
(),
...
...
src/targets/gpu/relu.cpp
View file @
087c205e
#include <migraphx/gpu/relu.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
#include <migraphx/gpu/context.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
...
@@ -18,7 +15,8 @@ argument miopen_relu::compute(context& ctx,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
float
alpha
=
1
,
beta
=
0
;
float
alpha
=
1
;
float
beta
=
0
;
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
y_desc
=
make_tensor
(
output_shape
);
miopenActivationForward
(
ctx
.
get_stream
().
get_miopen
(),
...
...
src/targets/gpu/sigmoid.cpp
0 → 100644
View file @
087c205e
#include <migraphx/gpu/sigmoid.hpp>
#include <migraphx/gpu/context.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
shape
miopen_sigmoid
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
).
not_broadcasted
();
return
inputs
.
at
(
1
);
}
argument
miopen_sigmoid
::
compute
(
context
&
ctx
,
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
{
float
alpha
=
1
;
float
beta
=
0
;
auto
x_desc
=
make_tensor
(
args
[
0
].
get_shape
());
auto
y_desc
=
make_tensor
(
output_shape
);
miopenActivationForward
(
ctx
.
get_stream
().
get_miopen
(),
ad
.
get
(),
&
alpha
,
x_desc
.
get
(),
args
[
0
].
implicit
(),
&
beta
,
y_desc
.
get
(),
args
[
1
].
implicit
());
return
args
[
1
];
}
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
Prev
1
…
3
4
5
6
7
8
9
10
11
…
13
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