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
35bbdce5
Commit
35bbdce5
authored
Nov 20, 2018
by
Shucai Xiao
Browse files
Add two operators---cos and tan.
parent
1a56cbc1
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
266 additions
and
6 deletions
+266
-6
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+3
-0
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+4
-0
src/targets/gpu/cos.cpp
src/targets/gpu/cos.cpp
+26
-0
src/targets/gpu/device/cos.cpp
src/targets/gpu/device/cos.cpp
+18
-0
src/targets/gpu/device/tan.cpp
src/targets/gpu/device/tan.cpp
+18
-0
src/targets/gpu/include/migraphx/gpu/cos.hpp
src/targets/gpu/include/migraphx/gpu/cos.hpp
+38
-0
src/targets/gpu/include/migraphx/gpu/device/cos.hpp
src/targets/gpu/include/migraphx/gpu/device/cos.hpp
+21
-0
src/targets/gpu/include/migraphx/gpu/device/sin.hpp
src/targets/gpu/include/migraphx/gpu/device/sin.hpp
+2
-2
src/targets/gpu/include/migraphx/gpu/device/tan.hpp
src/targets/gpu/include/migraphx/gpu/device/tan.hpp
+21
-0
src/targets/gpu/include/migraphx/gpu/tan.hpp
src/targets/gpu/include/migraphx/gpu/tan.hpp
+39
-0
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+26
-4
src/targets/gpu/tan.cpp
src/targets/gpu/tan.cpp
+26
-0
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+24
-0
No files found.
src/onnx/onnx.cpp
View file @
35bbdce5
...
@@ -54,6 +54,9 @@ struct onnx_parser
...
@@ -54,6 +54,9 @@ struct onnx_parser
// disable dropout for inference
// disable dropout for inference
add_generic_op
(
"Dropout"
,
op
::
identity
{});
add_generic_op
(
"Dropout"
,
op
::
identity
{});
add_generic_op
(
"Identity"
,
op
::
identity
{});
add_generic_op
(
"Identity"
,
op
::
identity
{});
add_generic_op
(
"Sin"
,
op
::
sin
{});
add_generic_op
(
"Cos"
,
op
::
cos
{});
add_generic_op
(
"Tan"
,
op
::
tan
{});
add_broadcastable_binary_op
(
"Add"
,
op
::
add
{});
add_broadcastable_binary_op
(
"Add"
,
op
::
add
{});
add_broadcastable_binary_op
(
"Div"
,
op
::
div
{});
add_broadcastable_binary_op
(
"Div"
,
op
::
div
{});
...
...
src/targets/gpu/CMakeLists.txt
View file @
35bbdce5
...
@@ -13,6 +13,8 @@ endif()
...
@@ -13,6 +13,8 @@ endif()
add_library
(
migraphx_device
add_library
(
migraphx_device
device/add.cpp
device/add.cpp
device/sin.cpp
device/sin.cpp
device/cos.cpp
device/tan.cpp
device/add_relu.cpp
device/add_relu.cpp
device/contiguous.cpp
device/contiguous.cpp
device/mul.cpp
device/mul.cpp
...
@@ -40,6 +42,8 @@ add_library(migraphx_gpu
...
@@ -40,6 +42,8 @@ add_library(migraphx_gpu
leaky_relu.cpp
leaky_relu.cpp
add.cpp
add.cpp
sin.cpp
sin.cpp
cos.cpp
tan.cpp
mul.cpp
mul.cpp
batchnorm.cpp
batchnorm.cpp
write_literals.cpp
write_literals.cpp
...
...
src/targets/gpu/cos.cpp
0 → 100644
View file @
35bbdce5
#include <migraphx/gpu/cos.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/config.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
shape
hip_cos
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
);
return
inputs
.
at
(
0
);
}
argument
hip_cos
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
device
::
cos
(
ctx
.
get_stream
().
get
(),
args
[
1
],
args
[
0
]);
return
args
[
1
];
}
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
src/targets/gpu/device/cos.cpp
0 → 100644
View file @
35bbdce5
#include <migraphx/gpu/device/cos.hpp>
#include <migraphx/gpu/device/nary.hpp>
#include <migraphx/gpu/device/types.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
namespace
device
{
void
cos
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
)
{
nary
(
stream
,
result
,
arg
)([](
auto
x
)
{
return
::
cos
(
to_hip_type
(
x
));
});
}
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
src/targets/gpu/device/tan.cpp
0 → 100644
View file @
35bbdce5
#include <migraphx/gpu/device/tan.hpp>
#include <migraphx/gpu/device/nary.hpp>
#include <migraphx/gpu/device/types.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
namespace
device
{
void
tan
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
)
{
nary
(
stream
,
result
,
arg
)([](
auto
x
)
{
return
::
tan
(
to_hip_type
(
x
));
});
}
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
src/targets/gpu/include/migraphx/gpu/cos.hpp
0 → 100644
View file @
35bbdce5
#ifndef MIGRAPH_GUARD_RTGLIB_COS_HPP
#define MIGRAPH_GUARD_RTGLIB_COS_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/device/sin.hpp>
#include <migraphx/gpu/device/cos.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
MIGRAPH_INLINE_NS
{
namespace
gpu
{
struct
hip_cos
{
std
::
string
name
()
const
{
return
"gpu::cos"
;
}
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
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/device/cos.hpp
0 → 100644
View file @
35bbdce5
#ifndef MIGRAPH_GUARD_RTGLIB_DEVICE_COS_HPP
#define MIGRAPH_GUARD_RTGLIB_DEVICE_COS_HPP
#include <migraphx/argument.hpp>
#include <migraphx/config.hpp>
#include <hip/hip_runtime_api.h>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
namespace
device
{
void
cos
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
);
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/device/sin.hpp
View file @
35bbdce5
#ifndef MIGRAPH_GUARD_RTGLIB_DEVICE_
ADD
_HPP
#ifndef MIGRAPH_GUARD_RTGLIB_DEVICE_
SIN
_HPP
#define MIGRAPH_GUARD_RTGLIB_DEVICE_
ADD
_HPP
#define MIGRAPH_GUARD_RTGLIB_DEVICE_
SIN
_HPP
#include <migraphx/argument.hpp>
#include <migraphx/argument.hpp>
#include <migraphx/config.hpp>
#include <migraphx/config.hpp>
...
...
src/targets/gpu/include/migraphx/gpu/device/tan.hpp
0 → 100644
View file @
35bbdce5
#ifndef MIGRAPH_GUARD_RTGLIB_DEVICE_TAN_HPP
#define MIGRAPH_GUARD_RTGLIB_DEVICE_TAN_HPP
#include <migraphx/argument.hpp>
#include <migraphx/config.hpp>
#include <hip/hip_runtime_api.h>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
namespace
device
{
void
tan
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
);
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/tan.hpp
0 → 100644
View file @
35bbdce5
#ifndef MIGRAPH_GUARD_RTGLIB_TAN_HPP
#define MIGRAPH_GUARD_RTGLIB_TAN_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/device/sin.hpp>
#include <migraphx/gpu/device/cos.hpp>
#include <migraphx/gpu/device/tan.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
MIGRAPH_INLINE_NS
{
namespace
gpu
{
struct
hip_tan
{
std
::
string
name
()
const
{
return
"gpu::tan"
;
}
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
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/lowering.cpp
View file @
35bbdce5
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
#include <migraphx/gpu/softmax.hpp>
#include <migraphx/gpu/softmax.hpp>
#include <migraphx/gpu/add.hpp>
#include <migraphx/gpu/add.hpp>
#include <migraphx/gpu/sin.hpp>
#include <migraphx/gpu/sin.hpp>
#include <migraphx/gpu/cos.hpp>
#include <migraphx/gpu/tan.hpp>
#include <migraphx/gpu/mul.hpp>
#include <migraphx/gpu/mul.hpp>
#include <migraphx/gpu/batchnorm.hpp>
#include <migraphx/gpu/batchnorm.hpp>
#include <migraphx/gpu/pooling.hpp>
#include <migraphx/gpu/pooling.hpp>
...
@@ -68,10 +70,6 @@ struct miopen_apply
...
@@ -68,10 +70,6 @@ struct miopen_apply
{
{
check_shape
(
s
,
apply_add
(
it
));
check_shape
(
s
,
apply_add
(
it
));
}
}
else
if
(
it
->
name
()
==
"sin"
)
{
check_shape
(
s
,
apply_sin
(
it
));
}
else
if
(
it
->
name
()
==
"mul"
)
else
if
(
it
->
name
()
==
"mul"
)
{
{
check_shape
(
s
,
apply_mul
(
it
));
check_shape
(
s
,
apply_mul
(
it
));
...
@@ -80,6 +78,18 @@ struct miopen_apply
...
@@ -80,6 +78,18 @@ struct miopen_apply
{
{
check_shape
(
s
,
apply_gemm
(
it
));
check_shape
(
s
,
apply_gemm
(
it
));
}
}
else
if
(
it
->
name
()
==
"sin"
)
{
check_shape
(
s
,
apply_sin
(
it
));
}
else
if
(
it
->
name
()
==
"cos"
)
{
check_shape
(
s
,
apply_cos
(
it
));
}
else
if
(
it
->
name
()
==
"tan"
)
{
check_shape
(
s
,
apply_tan
(
it
));
}
else
if
(
it
->
name
()
==
"contiguous"
)
else
if
(
it
->
name
()
==
"contiguous"
)
{
{
check_shape
(
s
,
apply_contiguous
(
it
));
check_shape
(
s
,
apply_contiguous
(
it
));
...
@@ -176,6 +186,18 @@ struct miopen_apply
...
@@ -176,6 +186,18 @@ struct miopen_apply
return
prog
->
replace_instruction
(
ins
,
hip_sin
{},
ins
->
inputs
().
at
(
0
),
output
);
return
prog
->
replace_instruction
(
ins
,
hip_sin
{},
ins
->
inputs
().
at
(
0
),
output
);
}
}
instruction_ref
apply_cos
(
instruction_ref
ins
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
hip_cos
{},
ins
->
inputs
().
at
(
0
),
output
);
}
instruction_ref
apply_tan
(
instruction_ref
ins
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
hip_tan
{},
ins
->
inputs
().
at
(
0
),
output
);
}
instruction_ref
apply_mul
(
instruction_ref
ins
)
instruction_ref
apply_mul
(
instruction_ref
ins
)
{
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
...
...
src/targets/gpu/tan.cpp
0 → 100644
View file @
35bbdce5
#include <migraphx/gpu/tan.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/config.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
shape
hip_tan
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
2
);
return
inputs
.
at
(
0
);
}
argument
hip_tan
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
device
::
tan
(
ctx
.
get_stream
().
get
(),
args
[
1
],
args
[
0
]);
return
args
[
1
];
}
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
test/gpu/miopen.cpp
View file @
35bbdce5
...
@@ -215,6 +215,30 @@ struct test_sin
...
@@ -215,6 +215,30 @@ struct test_sin
}
}
};
};
struct
test_cos
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
double_type
,
{
8
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
p
.
add_instruction
(
migraphx
::
op
::
cos
{},
x
);
return
p
;
}
};
struct
test_tan
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
16
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
p
.
add_instruction
(
migraphx
::
op
::
tan
{},
x
);
return
p
;
}
};
struct
test_scale
struct
test_scale
{
{
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
...
...
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