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
c0154dca
Commit
c0154dca
authored
May 16, 2019
by
Shucai Xiao
Browse files
merge changes from the develop branch
parents
ca170b5c
b93f5320
Changes
140
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
187 additions
and
53 deletions
+187
-53
src/include/migraphx/op/asin.hpp
src/include/migraphx/op/asin.hpp
+5
-2
src/include/migraphx/op/atan.hpp
src/include/migraphx/op/atan.hpp
+5
-2
src/include/migraphx/op/binary.hpp
src/include/migraphx/op/binary.hpp
+35
-14
src/include/migraphx/op/broadcast.hpp
src/include/migraphx/op/broadcast.hpp
+12
-14
src/include/migraphx/op/clip.hpp
src/include/migraphx/op/clip.hpp
+51
-0
src/include/migraphx/op/common.hpp
src/include/migraphx/op/common.hpp
+2
-0
src/include/migraphx/op/concat.hpp
src/include/migraphx/op/concat.hpp
+7
-0
src/include/migraphx/op/cos.hpp
src/include/migraphx/op/cos.hpp
+5
-2
src/include/migraphx/op/cosh.hpp
src/include/migraphx/op/cosh.hpp
+5
-2
src/include/migraphx/op/div.hpp
src/include/migraphx/op/div.hpp
+5
-2
src/include/migraphx/op/exp.hpp
src/include/migraphx/op/exp.hpp
+5
-2
src/include/migraphx/op/flatten.hpp
src/include/migraphx/op/flatten.hpp
+1
-1
src/include/migraphx/op/gather.hpp
src/include/migraphx/op/gather.hpp
+8
-1
src/include/migraphx/op/gru.hpp
src/include/migraphx/op/gru.hpp
+10
-0
src/include/migraphx/op/identity.hpp
src/include/migraphx/op/identity.hpp
+1
-1
src/include/migraphx/op/leaky_relu.hpp
src/include/migraphx/op/leaky_relu.hpp
+7
-6
src/include/migraphx/op/load.hpp
src/include/migraphx/op/load.hpp
+1
-1
src/include/migraphx/op/log.hpp
src/include/migraphx/op/log.hpp
+5
-2
src/include/migraphx/op/logsoftmax.hpp
src/include/migraphx/op/logsoftmax.hpp
+8
-1
src/include/migraphx/op/lstm.hpp
src/include/migraphx/op/lstm.hpp
+9
-0
No files found.
src/include/migraphx/op/asin.hpp
View file @
c0154dca
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
asin
:
unary
struct
asin
:
unary
<
asin
>
{
std
::
string
name
()
const
{
return
"asin"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
asin
(
x
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/atan.hpp
View file @
c0154dca
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
atan
:
unary
struct
atan
:
unary
<
atan
>
{
std
::
string
name
()
const
{
return
"atan"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
atan
(
x
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/binary.hpp
View file @
c0154dca
#ifndef MIGRAPHX_GUARD_OPERATORS_BINARY_HPP
#define MIGRAPHX_GUARD_OPERATORS_BINARY_HPP
#include <array>
#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>
#include <migraphx/op/name.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
binary
template
<
class
Derived
>
struct
binary
:
op_name
<
Derived
>
{
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
}.
has
(
2
).
same_type
().
same_dims
();
auto
t
=
inputs
.
at
(
0
).
type
();
auto
lens
=
inputs
.
at
(
0
).
lens
();
return
{
t
,
lens
};
auto
s0
=
inputs
.
at
(
0
);
auto
s1
=
inputs
.
at
(
1
);
if
(
s0
==
s1
and
s0
.
packed
())
{
return
s0
;
}
else
{
return
{
s0
.
type
(),
s0
.
lens
()};
}
}
argument
compute
(
const
shape
&
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
argument
result
{
output_shape
};
visit_all
(
result
,
args
[
0
],
args
[
1
])([
&
](
auto
output
,
auto
input1
,
auto
input2
)
{
if
(
input1
.
get_shape
().
standard
()
and
input2
.
get_shape
().
standard
())
{
std
::
transform
(
input1
.
begin
(),
input1
.
end
(),
input2
.
begin
(),
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
()(
input1
(
idx
.
begin
(),
idx
.
end
()),
input2
(
idx
.
begin
(),
idx
.
end
()));
});
}
});
return
result
;
}
};
...
...
src/include/migraphx/op/broadcast.hpp
View file @
c0154dca
...
...
@@ -27,45 +27,43 @@ namespace op {
struct
broadcast
{
uint64_t
axis
=
0
;
std
::
vector
<
std
::
size_t
>
broadcast_lens
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
axis
,
"axis"
));
return
pack
(
f
(
self
.
axis
,
"axis"
)
,
f
(
self
.
broadcast_lens
,
"dims"
)
);
}
shape
broadcast_shape
;
std
::
string
name
()
const
{
return
"broadcast"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
auto
t
=
inputs
.
at
(
0
).
type
();
auto
input
=
inputs
.
at
(
0
);
std
::
vector
<
size_t
>
bcast_strides
(
broadcast_
shape
.
lens
()
.
size
(),
0
);
std
::
vector
<
size_t
>
bcast_strides
(
broadcast_lens
.
size
(),
0
);
if
(
std
::
all_of
(
broadcast_shape
.
lens
().
cbegin
(),
broadcast_shape
.
lens
().
cend
(),
[
&
](
auto
x
)
{
return
x
==
1
;
}))
if
(
std
::
all_of
(
broadcast_lens
.
cbegin
(),
broadcast_lens
.
cend
(),
[
&
](
auto
x
)
{
return
x
==
1
;
}))
{
if
(
axis
!=
0
)
MIGRAPHX_THROW
(
"when broadcasting tensor of size 1, axis should be 0"
);
return
{
t
,
broadcast_
shape
.
lens
()
,
std
::
move
(
bcast_strides
)};
MIGRAPHX_THROW
(
"
BROADCAST:
when broadcasting tensor of size 1, axis should be 0"
);
return
{
t
,
broadcast_lens
,
std
::
move
(
bcast_strides
)};
}
else
{
assert
(
broadcast_shape
.
lens
().
size
()
-
axis
>=
input
.
lens
().
size
());
if
(
!
std
::
equal
(
input
.
lens
().
begin
(),
input
.
lens
().
end
(),
broadcast_shape
.
lens
().
begin
()
+
axis
))
MIGRAPHX_THROW
(
"when broadcasting success sizes must match"
);
assert
(
broadcast_lens
.
size
()
-
axis
>=
input
.
lens
().
size
());
if
(
!
std
::
equal
(
input
.
lens
().
begin
(),
input
.
lens
().
end
(),
broadcast_lens
.
begin
()
+
axis
))
MIGRAPHX_THROW
(
"BROADCAST: when broadcasting success sizes must match"
);
std
::
copy
(
input
.
strides
().
begin
(),
input
.
strides
().
end
(),
bcast_strides
.
begin
()
+
axis
);
return
{
t
,
broadcast_
shape
.
lens
()
,
std
::
move
(
bcast_strides
)};
return
{
t
,
broadcast_lens
,
std
::
move
(
bcast_strides
)};
}
}
argument
compute
(
shape
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
return
{
std
::
move
(
output_shape
),
std
::
move
(
args
.
at
(
0
).
data
)};
}
in
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
std
::
ptrdiff_
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
};
}
// namespace op
...
...
src/include/migraphx/op/clip.hpp
0 → 100644
View file @
c0154dca
#ifndef MIGRAPHX_GUARD_OPERATORS_CLIP_HPP
#define MIGRAPHX_GUARD_OPERATORS_CLIP_HPP
#include <array>
#include <migraphx/op/unary.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>
#include <limits>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
clip
:
unary
<
clip
>
{
float
max_val
=
std
::
numeric_limits
<
float
>::
max
();
float
min_val
=
std
::
numeric_limits
<
float
>::
min
();
clip
()
{}
clip
(
float
max
,
float
min
)
:
max_val
(
max
),
min_val
(
min
)
{}
auto
apply
()
const
{
auto
max
=
max_val
;
auto
min
=
min_val
;
return
[
max
,
min
](
auto
x
)
{
using
type
=
decltype
(
x
);
return
std
::
min
(
std
::
max
(
type
(
min
),
x
),
type
(
max
));
};
}
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
max_val
,
"max"
),
f
(
self
.
min_val
,
"min"
));
}
};
}
// namespace op
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/include/migraphx/op/common.hpp
View file @
c0154dca
...
...
@@ -31,6 +31,8 @@ enum class rnn_direction
bidirectional
,
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
rnn_direction
v
);
}
// namespace op
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
...
...
src/include/migraphx/op/concat.hpp
View file @
c0154dca
...
...
@@ -19,6 +19,13 @@ namespace op {
struct
concat
{
std
::
size_t
axis
=
0
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
axis
,
"axis"
));
}
std
::
string
name
()
const
{
return
"concat"
;
}
std
::
vector
<
std
::
size_t
>
compute_offsets
(
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
...
...
src/include/migraphx/op/cos.hpp
View file @
c0154dca
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
cos
:
unary
struct
cos
:
unary
<
cos
>
{
std
::
string
name
()
const
{
return
"cos"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
cos
(
x
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/cosh.hpp
View file @
c0154dca
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
cosh
:
unary
struct
cosh
:
unary
<
cosh
>
{
std
::
string
name
()
const
{
return
"cosh"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
cosh
(
x
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/div.hpp
View file @
c0154dca
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
div
:
binary
struct
div
:
binary
<
div
>
{
std
::
string
name
()
const
{
return
"div"
;
}
auto
apply
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
/
y
;
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/exp.hpp
View file @
c0154dca
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
exp
:
unary
struct
exp
:
unary
<
exp
>
{
std
::
string
name
()
const
{
return
"exp"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
exp
(
x
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/flatten.hpp
View file @
c0154dca
...
...
@@ -46,7 +46,7 @@ struct flatten
{
return
{
std
::
move
(
output_shape
),
std
::
move
(
args
.
front
().
data
)};
}
in
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
std
::
ptrdiff_
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
};
}
// namespace op
...
...
src/include/migraphx/op/gather.hpp
View file @
c0154dca
...
...
@@ -19,11 +19,18 @@ namespace op {
struct
gather
{
int
axis
=
0
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
axis
,
"axis"
));
}
std
::
string
name
()
const
{
return
"gather"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
);
check_shapes
{
inputs
,
*
this
}.
has
(
2
)
.
standard
()
;
auto
lens
=
inputs
[
0
].
lens
();
int
n_dim
=
static_cast
<
int
>
(
lens
.
size
());
if
(
axis
>=
n_dim
||
axis
<
-
n_dim
)
...
...
src/include/migraphx/op/gru.hpp
View file @
c0154dca
...
...
@@ -27,6 +27,16 @@ struct gru
float
clip
=
0.0
f
;
int
linear_before_reset
=
0
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
hidden_size
,
"hidden_size"
),
f
(
self
.
actv_funcs
,
"actv_func"
),
f
(
self
.
direction
,
"direction"
),
f
(
self
.
clip
,
"clip"
),
f
(
self
.
linear_before_reset
,
"linear_before_reset"
));
}
std
::
string
name
()
const
{
return
"gru"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
...
...
src/include/migraphx/op/identity.hpp
View file @
c0154dca
...
...
@@ -24,7 +24,7 @@ struct identity
{
return
{
std
::
move
(
output_shape
),
std
::
move
(
args
.
at
(
0
).
data
)};
}
in
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
std
::
ptrdiff_
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
};
}
// namespace op
...
...
src/include/migraphx/op/leaky_relu.hpp
View file @
c0154dca
...
...
@@ -18,19 +18,20 @@ namespace op {
struct
leaky_relu
{
std
::
string
name
()
const
{
return
"leaky_relu"
;
}
float
alpha
;
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
return
inputs
.
front
();
}
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
alpha
,
"alpha"
));
}
std
::
string
name
()
const
{
return
"leaky_relu"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
return
inputs
.
front
();
}
};
}
// namespace op
...
...
src/include/migraphx/op/load.hpp
View file @
c0154dca
...
...
@@ -39,7 +39,7 @@ struct load
MIGRAPHX_THROW
(
"Load access is out of bounds"
);
return
{
s
,
args
[
0
].
data
()
+
offset
};
}
in
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
std
::
ptrdiff_
t
output_alias
(
const
std
::
vector
<
shape
>&
)
const
{
return
0
;
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
load
&
op
)
{
...
...
src/include/migraphx/op/log.hpp
View file @
c0154dca
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
log
:
unary
struct
log
:
unary
<
log
>
{
std
::
string
name
()
const
{
return
"log"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
log
(
x
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/logsoftmax.hpp
View file @
c0154dca
...
...
@@ -19,10 +19,17 @@ namespace op {
struct
logsoftmax
{
int
axis
=
1
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
axis
,
"axis"
));
}
std
::
string
name
()
const
{
return
"logsoftmax"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
}.
has
(
1
);
check_shapes
{
inputs
}.
has
(
1
)
.
standard
()
;
if
(
axis
<
0
||
axis
>
inputs
[
0
].
lens
().
size
())
{
MIGRAPHX_THROW
(
"LogSoftMax: input axis value "
+
std
::
to_string
(
axis
)
+
...
...
src/include/migraphx/op/lstm.hpp
View file @
c0154dca
...
...
@@ -25,6 +25,15 @@ struct lstm
float
clip
=
0.0
f
;
int
input_forget
=
0
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
hidden_size
,
"hidden_size"
),
f
(
self
.
actv_funcs
,
"actv_func"
),
f
(
self
.
direction
,
"direction"
),
f
(
self
.
input_forget
,
"input_forget"
));
}
std
::
string
name
()
const
{
return
"lstm"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
...
...
Prev
1
2
3
4
5
6
7
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