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
c7ec2c82
Commit
c7ec2c82
authored
Jul 09, 2019
by
Khalique
Browse files
add rsqrt and tests
parent
ebfe9735
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
130 additions
and
0 deletions
+130
-0
src/include/migraphx/op/rsqrt.hpp
src/include/migraphx/op/rsqrt.hpp
+23
-0
src/include/migraphx/operators.hpp
src/include/migraphx/operators.hpp
+1
-0
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+1
-0
src/targets/gpu/device/rsqrt.cpp
src/targets/gpu/device/rsqrt.cpp
+18
-0
src/targets/gpu/include/migraphx/gpu/device/rsqrt.hpp
src/targets/gpu/include/migraphx/gpu/device/rsqrt.hpp
+20
-0
src/targets/gpu/include/migraphx/gpu/rsqrt.hpp
src/targets/gpu/include/migraphx/gpu/rsqrt.hpp
+19
-0
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+2
-0
src/tf/tf.cpp
src/tf/tf.cpp
+1
-0
test/cpu_ops_test.cpp
test/cpu_ops_test.cpp
+14
-0
test/gpu/miopen.cpp
test/gpu/miopen.cpp
+13
-0
test/tf/rsqrt_test.pb
test/tf/rsqrt_test.pb
+8
-0
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+10
-0
No files found.
src/include/migraphx/op/rsqrt.hpp
0 → 100644
View file @
c7ec2c82
#ifndef MIGRAPHX_GUARD_OPERATORS_RSQRT_HPP
#define MIGRAPHX_GUARD_OPERATORS_RSQRT_HPP
#include <migraphx/op/unary.hpp>
#include <cmath>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
rsqrt
:
unary
<
rsqrt
>
{
auto
apply
()
const
{
return
[](
auto
x
)
{
return
1
/
std
::
sqrt
(
x
);
};
}
};
}
// namespace op
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/include/migraphx/operators.hpp
View file @
c7ec2c82
...
...
@@ -51,6 +51,7 @@
#include <migraphx/op/rnn.hpp>
#include <migraphx/op/rnn_last_cell_output.hpp>
#include <migraphx/op/rnn_last_output.hpp>
#include <migraphx/op/rsqrt.hpp>
#include <migraphx/op/scalar.hpp>
#include <migraphx/op/sigmoid.hpp>
#include <migraphx/op/sinh.hpp>
...
...
src/targets/gpu/CMakeLists.txt
View file @
c7ec2c82
...
...
@@ -39,6 +39,7 @@ add_library(migraphx_device
device/sub.cpp
device/clip.cpp
device/reduce_sum.cpp
device/rsqrt.cpp
)
set_target_properties
(
migraphx_device PROPERTIES EXPORT_NAME device
)
rocm_clang_tidy_check
(
migraphx_device
)
...
...
src/targets/gpu/device/rsqrt.cpp
0 → 100644
View file @
c7ec2c82
#include <migraphx/gpu/device/rsqrt.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
rsqrt
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
)
{
nary
(
stream
,
result
,
arg
)([](
auto
x
)
{
return
1
/
::
sqrt
(
to_hip_type
(
x
));
});
}
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/include/migraphx/gpu/device/rsqrt.hpp
0 → 100644
View file @
c7ec2c82
#ifndef MIGRAPHX_GUARD_RTGLIB_DEVICE_RSQRT_HPP
#define MIGRAPHX_GUARD_RTGLIB_DEVICE_RSQRT_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
rsqrt
(
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/rsqrt.hpp
0 → 100644
View file @
c7ec2c82
#ifndef MIGRAPHX_GUARD_RTGLIB_RSQRT_HPP
#define MIGRAPHX_GUARD_RTGLIB_RSQRT_HPP
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/rsqrt.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
hip_rsqrt
:
unary_device
<
hip_rsqrt
,
device
::
rsqrt
>
{
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/lowering.cpp
View file @
c7ec2c82
...
...
@@ -51,6 +51,7 @@
#include <migraphx/gpu/convert.hpp>
#include <migraphx/gpu/clip.hpp>
#include <migraphx/gpu/reduce_sum.hpp>
#include <migraphx/gpu/rsqrt.hpp>
#include <utility>
#include <functional>
#include <algorithm>
...
...
@@ -100,6 +101,7 @@ struct miopen_apply
add_generic_op
<
hip_mul
>
(
"mul"
);
add_generic_op
<
hip_max
>
(
"max"
);
add_generic_op
<
hip_min
>
(
"min"
);
add_generic_op
<
hip_rsqrt
>
(
"rsqrt"
);
add_extend_op
<
miopen_gemm
,
op
::
dot
>
(
"dot"
);
add_extend_op
<
miopen_contiguous
,
op
::
contiguous
>
(
"contiguous"
);
...
...
src/tf/tf.cpp
View file @
c7ec2c82
...
...
@@ -153,6 +153,7 @@ struct tf_parser
add_generic_op
(
"Identity"
,
op
::
identity
{});
add_generic_op
(
"Relu"
,
op
::
relu
{});
add_generic_op
(
"Relu6"
,
op
::
clip
{
6.0
,
0.0
});
add_generic_op
(
"Rsqrt"
,
op
::
rsqrt
{});
add_generic_op
(
"Tanh"
,
op
::
tanh
{});
add_binary_op
(
"Add"
,
op
::
add
{});
...
...
test/cpu_ops_test.cpp
View file @
c7ec2c82
...
...
@@ -1778,4 +1778,18 @@ TEST_CASE(reduce_sum_test12)
EXPECT
(
results_vector
==
gold
);
}
TEST_CASE
(
rsqrt_test
)
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
}};
auto
l
=
p
.
add_literal
(
migraphx
::
literal
{
s
,
{
4.0
,
16.0
,
64.0
}});
p
.
add_instruction
(
migraphx
::
op
::
rsqrt
{},
l
);
p
.
compile
(
migraphx
::
cpu
::
target
{});
auto
result
=
p
.
eval
({});
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0.5
,
0.25
,
0.125
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/gpu/miopen.cpp
View file @
c7ec2c82
...
...
@@ -3511,4 +3511,17 @@ struct test_reduce_sum_half : verify_program<test_reduce_sum_half>
};
};
struct
test_rsqrt
:
verify_program
<
test_rsqrt
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
16
,
16
}};
auto
x
=
p
.
add_parameter
(
"x"
,
s
);
auto
l0
=
p
.
add_instruction
(
migraphx
::
op
::
clip
{
std
::
numeric_limits
<
float
>::
max
(),
1.0
},
x
);
p
.
add_instruction
(
migraphx
::
op
::
rsqrt
{},
l0
);
return
p
;
};
};
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/tf/rsqrt_test.pb
0 → 100644
View file @
c7ec2c82
:
0Placeholder*
shape:*
dtype0
rsqrtRsqrt0*
T0"
\ No newline at end of file
test/tf/tf_test.cpp
View file @
c7ec2c82
...
...
@@ -326,6 +326,16 @@ TEST_CASE(reshape_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
rsqrt_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
16
,
16
}});
p
.
add_instruction
(
migraphx
::
op
::
rsqrt
{},
l0
);
auto
prog
=
optimize_tf
(
"rsqrt_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
softmax_test
)
{
migraphx
::
program
p
;
...
...
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