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
08c3a87f
"examples/vscode:/vscode.git/clone" did not exist on "bc3c64aa786dcfc0e2a68c26bed5ba66b74488af"
Commit
08c3a87f
authored
Apr 09, 2019
by
Paul
Browse files
Update unary operator
parent
79b2b1fc
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
102 additions
and
58 deletions
+102
-58
src/include/migraphx/op/abs.hpp
src/include/migraphx/op/abs.hpp
+6
-2
src/include/migraphx/op/acos.hpp
src/include/migraphx/op/acos.hpp
+5
-2
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
+2
-17
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/exp.hpp
src/include/migraphx/op/exp.hpp
+5
-2
src/include/migraphx/op/log.hpp
src/include/migraphx/op/log.hpp
+5
-2
src/include/migraphx/op/neg.hpp
src/include/migraphx/op/neg.hpp
+5
-2
src/include/migraphx/op/relu.hpp
src/include/migraphx/op/relu.hpp
+5
-2
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/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
No files found.
src/include/migraphx/op/abs.hpp
View file @
08c3a87f
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include <migraphx/literal.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <migraphx/config.hpp>
#include <migraphx/make_signed.hpp>
#include <cmath>
#include <cmath>
#include <utility>
#include <utility>
...
@@ -17,9 +18,12 @@ namespace migraphx {
...
@@ -17,9 +18,12 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
namespace
op
{
struct
abs
:
unary
struct
abs
:
unary
<
abs
>
{
{
std
::
string
name
()
const
{
return
"abs"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
abs
(
make_signed
(
x
));
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/acos.hpp
View file @
08c3a87f
...
@@ -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
acos
:
unary
struct
acos
:
unary
<
acos
>
{
{
std
::
string
name
()
const
{
return
"acos"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
acos
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/asin.hpp
View file @
08c3a87f
...
@@ -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
asin
:
unary
struct
asin
:
unary
<
asin
>
{
{
std
::
string
name
()
const
{
return
"asin"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
asin
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/atan.hpp
View file @
08c3a87f
...
@@ -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
atan
:
unary
struct
atan
:
unary
<
atan
>
{
{
std
::
string
name
()
const
{
return
"atan"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
atan
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/binary.hpp
View file @
08c3a87f
#ifndef MIGRAPHX_GUARD_OPERATORS_BINARY_HPP
#ifndef MIGRAPHX_GUARD_OPERATORS_BINARY_HPP
#define MIGRAPHX_GUARD_OPERATORS_BINARY_HPP
#define MIGRAPHX_GUARD_OPERATORS_BINARY_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/type_name.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
{
template
<
class
Derived
>
template
<
class
Derived
>
struct
binary
struct
binary
:
op_name
<
Derived
>
{
{
std
::
string
name
()
const
{
static
const
std
::
string
&
name
=
get_type_name
<
Derived
>
();
return
name
.
substr
(
name
.
rfind
(
"::"
)
+
2
);
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
{
check_shapes
{
inputs
}.
has
(
2
).
same_type
().
same_dims
();
check_shapes
{
inputs
}.
has
(
2
).
same_type
().
same_dims
();
...
...
src/include/migraphx/op/cos.hpp
View file @
08c3a87f
...
@@ -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
cos
:
unary
struct
cos
:
unary
<
cos
>
{
{
std
::
string
name
()
const
{
return
"cos"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
cos
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/cosh.hpp
View file @
08c3a87f
...
@@ -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
cosh
:
unary
struct
cosh
:
unary
<
cosh
>
{
{
std
::
string
name
()
const
{
return
"cosh"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
cosh
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/exp.hpp
View file @
08c3a87f
...
@@ -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
exp
:
unary
struct
exp
:
unary
<
exp
>
{
{
std
::
string
name
()
const
{
return
"exp"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
exp
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/log.hpp
View file @
08c3a87f
...
@@ -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
log
:
unary
struct
log
:
unary
<
log
>
{
{
std
::
string
name
()
const
{
return
"log"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
log
(
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/neg.hpp
View file @
08c3a87f
...
@@ -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
neg
:
unary
struct
neg
:
unary
<
neg
>
{
{
std
::
string
name
()
const
{
return
"neg"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
-
x
;
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/relu.hpp
View file @
08c3a87f
...
@@ -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
relu
:
unary
struct
relu
:
unary
<
relu
>
{
{
std
::
string
name
()
const
{
return
"relu"
;
}
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
max
(
decltype
(
x
){
0
},
x
);
};
}
};
};
}
// namespace op
}
// namespace op
...
...
src/include/migraphx/op/sigmoid.hpp
View file @
08c3a87f
...
@@ -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 @
08c3a87f
...
@@ -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 @
08c3a87f
...
@@ -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/tan.hpp
View file @
08c3a87f
...
@@ -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 @
08c3a87f
...
@@ -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 @
08c3a87f
#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
...
...
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