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
03f5c679
Unverified
Commit
03f5c679
authored
Jul 16, 2019
by
mvermeulen
Committed by
GitHub
Jul 16, 2019
Browse files
Merge pull request #316 from ROCmSoftwarePlatform/sqrt_operator
Sqrt operator
parents
524c86ff
007aa61f
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
136 additions
and
0 deletions
+136
-0
src/include/migraphx/op/sqrt.hpp
src/include/migraphx/op/sqrt.hpp
+23
-0
src/include/migraphx/operators.hpp
src/include/migraphx/operators.hpp
+1
-0
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+1
-0
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+1
-0
src/targets/gpu/device/sqrt.cpp
src/targets/gpu/device/sqrt.cpp
+18
-0
src/targets/gpu/include/migraphx/gpu/device/sqrt.hpp
src/targets/gpu/include/migraphx/gpu/device/sqrt.hpp
+20
-0
src/targets/gpu/include/migraphx/gpu/sqrt.hpp
src/targets/gpu/include/migraphx/gpu/sqrt.hpp
+19
-0
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+2
-0
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+15
-0
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+13
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+10
-0
test/onnx/sqrt_test.onnx
test/onnx/sqrt_test.onnx
+13
-0
No files found.
src/include/migraphx/op/sqrt.hpp
0 → 100644
View file @
03f5c679
#ifndef MIGRAPHX_GUARD_OPERATORS_SQRT_HPP
#define MIGRAPHX_GUARD_OPERATORS_SQRT_HPP
#include <migraphx/op/unary.hpp>
#include <migraphx/config.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
sqrt
:
unary
<
sqrt
>
{
auto
apply
()
const
{
return
[](
auto
x
)
{
return
std
::
sqrt
(
x
);
};
}
};
}
// namespace op
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/include/migraphx/operators.hpp
View file @
03f5c679
...
@@ -58,6 +58,7 @@
...
@@ -58,6 +58,7 @@
#include <migraphx/op/sin.hpp>
#include <migraphx/op/sin.hpp>
#include <migraphx/op/slice.hpp>
#include <migraphx/op/slice.hpp>
#include <migraphx/op/softmax.hpp>
#include <migraphx/op/softmax.hpp>
#include <migraphx/op/sqrt.hpp>
#include <migraphx/op/sqdiff.hpp>
#include <migraphx/op/sqdiff.hpp>
#include <migraphx/op/squeeze.hpp>
#include <migraphx/op/squeeze.hpp>
#include <migraphx/op/sub.hpp>
#include <migraphx/op/sub.hpp>
...
...
src/onnx/onnx.cpp
View file @
03f5c679
...
@@ -54,6 +54,7 @@ struct onnx_parser
...
@@ -54,6 +54,7 @@ struct onnx_parser
add_generic_op
(
"Asin"
,
op
::
asin
{});
add_generic_op
(
"Asin"
,
op
::
asin
{});
add_generic_op
(
"Acos"
,
op
::
acos
{});
add_generic_op
(
"Acos"
,
op
::
acos
{});
add_generic_op
(
"Atan"
,
op
::
atan
{});
add_generic_op
(
"Atan"
,
op
::
atan
{});
add_generic_op
(
"Sqrt"
,
op
::
sqrt
{});
add_binary_op
(
"Add"
,
op
::
add
{});
add_binary_op
(
"Add"
,
op
::
add
{});
add_binary_op
(
"Div"
,
op
::
div
{});
add_binary_op
(
"Div"
,
op
::
div
{});
...
...
src/targets/gpu/CMakeLists.txt
View file @
03f5c679
...
@@ -40,6 +40,7 @@ add_library(migraphx_device
...
@@ -40,6 +40,7 @@ add_library(migraphx_device
device/div.cpp
device/div.cpp
device/clip.cpp
device/clip.cpp
device/reduce_sum.cpp
device/reduce_sum.cpp
device/sqrt.cpp
device/reduce_mean.cpp
device/reduce_mean.cpp
device/sqdiff.cpp
device/sqdiff.cpp
)
)
...
...
src/targets/gpu/device/sqrt.cpp
0 → 100644
View file @
03f5c679
#include <migraphx/gpu/device/sqrt.hpp>
#include <migraphx/gpu/device/nary.hpp>
#include <migraphx/gpu/device/types.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
namespace
device
{
void
sqrt
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
)
{
nary
(
stream
,
result
,
arg
)([](
auto
x
)
{
return
::
sqrt
(
to_hip_type
(
x
));
});
}
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/include/migraphx/gpu/device/sqrt.hpp
0 → 100644
View file @
03f5c679
#ifndef MIGRAPHX_GUARD_RTGLIB_DEVICE_SQRT_HPP
#define MIGRAPHX_GUARD_RTGLIB_DEVICE_SQRT_HPP
#include <migraphx/argument.hpp>
#include <migraphx/config.hpp>
#include <hip/hip_runtime_api.h>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
namespace
device
{
void
sqrt
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
);
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/sqrt.hpp
0 → 100644
View file @
03f5c679
#ifndef MIGRAPHX_GUARD_RTGLIB_SQRT_HPP
#define MIGRAPHX_GUARD_RTGLIB_SQRT_HPP
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/sqrt.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
hip_sqrt
:
unary_device
<
hip_sqrt
,
device
::
sqrt
>
{
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/lowering.cpp
View file @
03f5c679
...
@@ -52,6 +52,7 @@
...
@@ -52,6 +52,7 @@
#include <migraphx/gpu/convert.hpp>
#include <migraphx/gpu/convert.hpp>
#include <migraphx/gpu/clip.hpp>
#include <migraphx/gpu/clip.hpp>
#include <migraphx/gpu/reduce_sum.hpp>
#include <migraphx/gpu/reduce_sum.hpp>
#include <migraphx/gpu/sqrt.hpp>
#include <migraphx/gpu/reduce_mean.hpp>
#include <migraphx/gpu/reduce_mean.hpp>
#include <migraphx/gpu/sqdiff.hpp>
#include <migraphx/gpu/sqdiff.hpp>
#include <utility>
#include <utility>
...
@@ -100,6 +101,7 @@ struct miopen_apply
...
@@ -100,6 +101,7 @@ struct miopen_apply
add_generic_op
<
hip_asin
>
(
"asin"
);
add_generic_op
<
hip_asin
>
(
"asin"
);
add_generic_op
<
hip_acos
>
(
"acos"
);
add_generic_op
<
hip_acos
>
(
"acos"
);
add_generic_op
<
hip_atan
>
(
"atan"
);
add_generic_op
<
hip_atan
>
(
"atan"
);
add_generic_op
<
hip_sqrt
>
(
"sqrt"
);
add_generic_op
<
hip_mul
>
(
"mul"
);
add_generic_op
<
hip_mul
>
(
"mul"
);
add_generic_op
<
hip_div
>
(
"div"
);
add_generic_op
<
hip_div
>
(
"div"
);
add_generic_op
<
hip_max
>
(
"max"
);
add_generic_op
<
hip_max
>
(
"max"
);
...
...
test/cpu_ops_test.cpp
View file @
03f5c679
...
@@ -542,6 +542,21 @@ TEST_CASE(erf_test)
...
@@ -542,6 +542,21 @@ TEST_CASE(erf_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
sqrt_test
)
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
5
}};
auto
l
=
p
.
add_literal
(
migraphx
::
literal
{
s
,
{
1.02481645
,
0.85643062
,
0.03404123
,
0.92791926
,
0.10569184
}});
p
.
add_instruction
(
migraphx
::
op
::
sqrt
{},
l
);
p
.
compile
(
migraphx
::
cpu
::
target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
1.01233218
,
0.92543537
,
0.18450265
,
0.96328566
,
0.32510282
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
log_test
)
TEST_CASE
(
log_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
test/gpu/miopen.cpp
View file @
03f5c679
...
@@ -255,6 +255,19 @@ struct test_erf : verify_program<test_erf>
...
@@ -255,6 +255,19 @@ struct test_erf : verify_program<test_erf>
}
}
};
};
struct
test_sqrt
:
verify_program
<
test_sqrt
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
6
}};
auto
param
=
p
.
add_parameter
(
"x"
,
s
);
auto
param_abs
=
p
.
add_instruction
(
migraphx
::
op
::
abs
{},
param
);
p
.
add_instruction
(
migraphx
::
op
::
sqrt
{},
param_abs
);
return
p
;
}
};
struct
test_log
:
verify_program
<
test_log
>
struct
test_log
:
verify_program
<
test_log
>
{
{
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
...
...
test/onnx/onnx_test.cpp
View file @
03f5c679
...
@@ -202,6 +202,16 @@ TEST_CASE(erf_test)
...
@@ -202,6 +202,16 @@ TEST_CASE(erf_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
sqrt_test
)
{
migraphx
::
program
p
;
auto
input
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
10
,
15
}});
p
.
add_instruction
(
migraphx
::
op
::
sqrt
{},
input
);
auto
prog
=
migraphx
::
parse_onnx
(
"sqrt_test.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
log_test
)
TEST_CASE
(
log_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
test/onnx/sqrt_test.onnx
0 → 100644
View file @
03f5c679
sqrt-example:C
xy"Sqrt test_sqrtZ
x
b
y
B
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