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
524c86ff
Unverified
Commit
524c86ff
authored
Jul 16, 2019
by
mvermeulen
Committed by
GitHub
Jul 16, 2019
Browse files
Merge pull request #315 from ROCmSoftwarePlatform/sqdiff_op
SquaredDifference op
parents
9680c147
9894a970
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
122 additions
and
0 deletions
+122
-0
src/include/migraphx/op/sqdiff.hpp
src/include/migraphx/op/sqdiff.hpp
+22
-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/sqdiff.cpp
src/targets/gpu/device/sqdiff.cpp
+17
-0
src/targets/gpu/include/migraphx/gpu/device/sqdiff.hpp
src/targets/gpu/include/migraphx/gpu/device/sqdiff.hpp
+21
-0
src/targets/gpu/include/migraphx/gpu/sqdiff.hpp
src/targets/gpu/include/migraphx/gpu/sqdiff.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
+15
-0
test/tf/sqdiff_test.pb
test/tf/sqdiff_test.pb
+12
-0
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+11
-0
No files found.
src/include/migraphx/op/sqdiff.hpp
0 → 100644
View file @
524c86ff
#ifndef MIGRAPHX_GUARD_OPERATORS_SQDIFF_HPP
#define MIGRAPHX_GUARD_OPERATORS_SQDIFF_HPP
#include <migraphx/op/binary.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
sqdiff
:
binary
<
sqdiff
>
{
auto
apply
()
const
{
return
[](
auto
x
,
auto
y
)
{
return
(
x
-
y
)
*
(
x
-
y
);
};
}
};
}
// namespace op
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/include/migraphx/operators.hpp
View file @
524c86ff
...
...
@@ -58,6 +58,7 @@
#include <migraphx/op/sin.hpp>
#include <migraphx/op/slice.hpp>
#include <migraphx/op/softmax.hpp>
#include <migraphx/op/sqdiff.hpp>
#include <migraphx/op/squeeze.hpp>
#include <migraphx/op/sub.hpp>
#include <migraphx/op/tanh.hpp>
...
...
src/targets/gpu/CMakeLists.txt
View file @
524c86ff
...
...
@@ -41,6 +41,7 @@ add_library(migraphx_device
device/clip.cpp
device/reduce_sum.cpp
device/reduce_mean.cpp
device/sqdiff.cpp
)
set_target_properties
(
migraphx_device PROPERTIES EXPORT_NAME device
)
rocm_clang_tidy_check
(
migraphx_device
)
...
...
src/targets/gpu/device/sqdiff.cpp
0 → 100644
View file @
524c86ff
#include <migraphx/gpu/device/sqdiff.hpp>
#include <migraphx/gpu/device/nary.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
namespace
device
{
void
sqdiff
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
)
{
nary
(
stream
,
result
,
arg1
,
arg2
)([](
auto
x
,
auto
y
)
{
return
(
x
-
y
)
*
(
x
-
y
);
});
}
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/include/migraphx/gpu/device/sqdiff.hpp
0 → 100644
View file @
524c86ff
#ifndef MIGRAPHX_GUARD_RTGLIB_DEVICE_SQDIFF_HPP
#define MIGRAPHX_GUARD_RTGLIB_DEVICE_SQDIFF_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
sqdiff
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
);
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/sqdiff.hpp
0 → 100644
View file @
524c86ff
#ifndef MIGRAPHX_GUARD_RTGLIB_SQDIFF_HPP
#define MIGRAPHX_GUARD_RTGLIB_SQDIFF_HPP
#include <migraphx/gpu/oper.hpp>
#include <migraphx/gpu/device/sqdiff.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
hip_sqdiff
:
binary_device
<
hip_sqdiff
,
device
::
sqdiff
>
{
};
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/lowering.cpp
View file @
524c86ff
...
...
@@ -53,6 +53,7 @@
#include <migraphx/gpu/clip.hpp>
#include <migraphx/gpu/reduce_sum.hpp>
#include <migraphx/gpu/reduce_mean.hpp>
#include <migraphx/gpu/sqdiff.hpp>
#include <utility>
#include <functional>
#include <algorithm>
...
...
@@ -103,6 +104,7 @@ struct miopen_apply
add_generic_op
<
hip_div
>
(
"div"
);
add_generic_op
<
hip_max
>
(
"max"
);
add_generic_op
<
hip_min
>
(
"min"
);
add_generic_op
<
hip_sqdiff
>
(
"sqdiff"
);
add_extend_op
<
miopen_gemm
,
op
::
dot
>
(
"dot"
);
add_extend_op
<
miopen_contiguous
,
op
::
contiguous
>
(
"contiguous"
);
...
...
src/tf/tf.cpp
View file @
524c86ff
...
...
@@ -159,6 +159,7 @@ struct tf_parser
add_binary_op
(
"Add"
,
op
::
add
{});
add_binary_op
(
"Mul"
,
op
::
mul
{});
add_binary_op
(
"SquaredDifference"
,
op
::
sqdiff
{});
add_binary_op
(
"Sub"
,
op
::
sub
{});
add_mem_op
(
"AvgPool"
,
&
tf_parser
::
parse_pooling
);
...
...
test/cpu_ops_test.cpp
View file @
524c86ff
...
...
@@ -1853,4 +1853,19 @@ TEST_CASE(reduce_mean_int)
EXPECT
(
results_vector
==
gold
);
}
TEST_CASE
(
sqdiff_test
)
{
migraphx
::
program
p
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
}};
auto
l1
=
p
.
add_literal
(
migraphx
::
literal
{
s
,
{
-
1
,
0
,
1
}});
auto
l2
=
p
.
add_literal
(
migraphx
::
literal
{
s
,
{
1
,
2
,
3
}});
p
.
add_instruction
(
migraphx
::
op
::
sqdiff
{},
l1
,
l2
);
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
=
{
4
,
4
,
4
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/tf/sqdiff_test.pb
0 → 100644
View file @
524c86ff
:
0Placeholder*
dtype0*
shape:
:
1Placeholder*
dtype0*
shape:
*
sqdiffSquaredDifference01*
T0"
\ No newline at end of file
test/tf/tf_test.cpp
View file @
524c86ff
...
...
@@ -364,6 +364,17 @@ TEST_CASE(softmax_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
sqdiff_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
2
,
3
}});
auto
l1
=
p
.
add_parameter
(
"1"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
2
,
3
}});
p
.
add_instruction
(
migraphx
::
op
::
sqdiff
{},
l0
,
l1
);
auto
prog
=
optimize_tf
(
"sqdiff_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
squeeze_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