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
15385fb1
Commit
15385fb1
authored
May 05, 2019
by
Shucai Xiao
Browse files
merge changes from develop branch
parents
f7f02979
b606ed4f
Changes
123
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
134 additions
and
53 deletions
+134
-53
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/common.hpp
src/include/migraphx/op/common.hpp
+2
-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/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
src/include/migraphx/op/max.hpp
src/include/migraphx/op/max.hpp
+5
-2
src/include/migraphx/op/min.hpp
src/include/migraphx/op/min.hpp
+5
-2
src/include/migraphx/op/mul.hpp
src/include/migraphx/op/mul.hpp
+5
-2
src/include/migraphx/op/multibroadcast.hpp
src/include/migraphx/op/multibroadcast.hpp
+2
-2
No files found.
src/include/migraphx/op/atan.hpp
View file @
15385fb1
...
...
@@ -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 @
15385fb1
#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 @
15385fb1
...
...
@@ -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/common.hpp
View file @
15385fb1
...
...
@@ -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/cos.hpp
View file @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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/load.hpp
View file @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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 @
15385fb1
...
...
@@ -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
{
...
...
src/include/migraphx/op/max.hpp
View file @
15385fb1
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
max
:
binary
struct
max
:
binary
<
max
>
{
std
::
string
name
()
const
{
return
"max"
;
}
auto
apply
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
std
::
max
(
x
,
y
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/min.hpp
View file @
15385fb1
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
min
:
binary
struct
min
:
binary
<
min
>
{
std
::
string
name
()
const
{
return
"min"
;
}
auto
apply
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
std
::
min
(
x
,
y
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/mul.hpp
View file @
15385fb1
...
...
@@ -17,9 +17,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
mul
:
binary
struct
mul
:
binary
<
mul
>
{
std
::
string
name
()
const
{
return
"mul"
;
}
auto
apply
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
x
*
y
;
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/multibroadcast.hpp
View file @
15385fb1
...
...
@@ -42,7 +42,7 @@ struct multibroadcast
std
::
vector
<
size_t
>
bcast_strides
(
output_lens
.
size
(),
0
);
auto
offset
=
output_lens
.
size
()
-
input
.
lens
().
size
();
for
(
in
t
i
=
input
.
lens
().
size
()
-
1
;
i
>=
0
;
i
--
)
for
(
std
::
ptrdiff_
t
i
=
input
.
lens
().
size
()
-
1
;
i
>=
0
;
i
--
)
{
if
(
output_lens
[
i
+
offset
]
==
input
.
lens
()[
i
])
{
...
...
@@ -55,7 +55,7 @@ struct multibroadcast
{
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
...
...
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