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
25597e6b
Commit
25597e6b
authored
Nov 28, 2018
by
Khalique
Browse files
added gpu version of max and min
parent
15f23855
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
238 additions
and
0 deletions
+238
-0
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+4
-0
src/targets/gpu/device/max.cpp
src/targets/gpu/device/max.cpp
+18
-0
src/targets/gpu/device/min.cpp
src/targets/gpu/device/min.cpp
+18
-0
src/targets/gpu/include/migraphx/gpu/device/max.hpp
src/targets/gpu/include/migraphx/gpu/device/max.hpp
+27
-0
src/targets/gpu/include/migraphx/gpu/device/min.hpp
src/targets/gpu/include/migraphx/gpu/device/min.hpp
+27
-0
src/targets/gpu/include/migraphx/gpu/max.hpp
src/targets/gpu/include/migraphx/gpu/max.hpp
+37
-0
src/targets/gpu/include/migraphx/gpu/min.hpp
src/targets/gpu/include/migraphx/gpu/min.hpp
+37
-0
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+18
-0
src/targets/gpu/max.cpp
src/targets/gpu/max.cpp
+26
-0
src/targets/gpu/min.cpp
src/targets/gpu/min.cpp
+26
-0
No files found.
src/targets/gpu/CMakeLists.txt
View file @
25597e6b
...
@@ -17,6 +17,8 @@ add_library(migraphx_device
...
@@ -17,6 +17,8 @@ add_library(migraphx_device
device/contiguous.cpp
device/contiguous.cpp
device/mul.cpp
device/mul.cpp
device/concat.cpp
device/concat.cpp
device/max.cpp
device/min.cpp
)
)
set_target_properties
(
migraphx_device PROPERTIES EXPORT_NAME device
)
set_target_properties
(
migraphx_device PROPERTIES EXPORT_NAME device
)
rocm_clang_tidy_check
(
migraphx_device
)
rocm_clang_tidy_check
(
migraphx_device
)
...
@@ -48,6 +50,8 @@ add_library(migraphx_gpu
...
@@ -48,6 +50,8 @@ add_library(migraphx_gpu
tanh.cpp
tanh.cpp
abs.cpp
abs.cpp
elu.cpp
elu.cpp
max.cpp
min.cpp
)
)
set_target_properties
(
migraphx_gpu PROPERTIES EXPORT_NAME gpu
)
set_target_properties
(
migraphx_gpu PROPERTIES EXPORT_NAME gpu
)
rocm_clang_tidy_check
(
migraphx_gpu
)
rocm_clang_tidy_check
(
migraphx_gpu
)
...
...
src/targets/gpu/device/max.cpp
0 → 100644
View file @
25597e6b
#include <migraphx/gpu/device/max.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
max
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
)
{
nary
(
stream
,
result
,
arg1
,
arg2
)([](
auto
x
,
auto
y
)
{
return
std
::
max
(
to_hip_type
(
x
),
to_hip_type
(
y
));
});
}
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
src/targets/gpu/device/min.cpp
0 → 100644
View file @
25597e6b
#include <migraphx/gpu/device/min.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
min
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
)
{
nary
(
stream
,
result
,
arg1
,
arg2
)([](
auto
x
,
auto
y
)
{
return
std
::
min
(
to_hip_type
(
x
),
to_hip_type
(
y
));
});
}
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
src/targets/gpu/include/migraphx/gpu/device/max.hpp
0 → 100644
View file @
25597e6b
#ifndef MIGRAPH_GUARD_RTGLIB_DEVICE_MAX_HPP
#define MIGRAPH_GUARD_RTGLIB_DEVICE_MAX_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
max
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
);
void
max
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
,
const
argument
&
arg3
);
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/device/min.hpp
0 → 100644
View file @
25597e6b
#ifndef MIGRAPH_GUARD_RTGLIB_DEVICE_MIN_HPP
#define MIGRAPH_GUARD_RTGLIB_DEVICE_MIN_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
min
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
);
void
min
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
,
const
argument
&
arg3
);
}
// namespace device
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
#endif
src/targets/gpu/include/migraphx/gpu/max.hpp
0 → 100644
View file @
25597e6b
#ifndef MIGRAPH_GUARD_RTGLIB_MAX_HPP
#define MIGRAPH_GUARD_RTGLIB_MAX_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/config.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/max.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/rocblas.hpp>
#include <migraphx/gpu/context.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
struct
hip_max
{
std
::
string
name
()
const
{
return
"gpu::max"
;
}
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/min.hpp
0 → 100644
View file @
25597e6b
#ifndef MIGRAPH_GUARD_RTGLIB_MIN_HPP
#define MIGRAPH_GUARD_RTGLIB_MIN_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/config.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/min.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/rocblas.hpp>
#include <migraphx/gpu/context.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
struct
hip_min
{
std
::
string
name
()
const
{
return
"gpu::min"
;
}
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 @
25597e6b
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
#include <migraphx/gpu/add.hpp>
#include <migraphx/gpu/add.hpp>
#include <migraphx/gpu/sin.hpp>
#include <migraphx/gpu/sin.hpp>
#include <migraphx/gpu/mul.hpp>
#include <migraphx/gpu/mul.hpp>
#include <migraphx/gpu/max.hpp>
#include <migraphx/gpu/min.hpp>
#include <migraphx/gpu/batchnorm.hpp>
#include <migraphx/gpu/batchnorm.hpp>
#include <migraphx/gpu/pooling.hpp>
#include <migraphx/gpu/pooling.hpp>
#include <migraphx/gpu/gemm.hpp>
#include <migraphx/gpu/gemm.hpp>
...
@@ -63,6 +65,8 @@ struct miopen_apply
...
@@ -63,6 +65,8 @@ struct miopen_apply
apply_map
[
"add"
]
=
&
miopen_apply
::
apply_add
;
apply_map
[
"add"
]
=
&
miopen_apply
::
apply_add
;
apply_map
[
"sin"
]
=
&
miopen_apply
::
apply_sin
;
apply_map
[
"sin"
]
=
&
miopen_apply
::
apply_sin
;
apply_map
[
"mul"
]
=
&
miopen_apply
::
apply_mul
;
apply_map
[
"mul"
]
=
&
miopen_apply
::
apply_mul
;
apply_map
[
"max"
]
=
&
miopen_apply
::
apply_max
;
apply_map
[
"min"
]
=
&
miopen_apply
::
apply_min
;
apply_map
[
"dot"
]
=
&
miopen_apply
::
apply_dot
;
apply_map
[
"dot"
]
=
&
miopen_apply
::
apply_dot
;
apply_map
[
"contiguous"
]
=
&
miopen_apply
::
apply_contiguous
;
apply_map
[
"contiguous"
]
=
&
miopen_apply
::
apply_contiguous
;
apply_map
[
"concat"
]
=
&
miopen_apply
::
apply_concat
;
apply_map
[
"concat"
]
=
&
miopen_apply
::
apply_concat
;
...
@@ -204,6 +208,20 @@ struct miopen_apply
...
@@ -204,6 +208,20 @@ struct miopen_apply
ins
,
hip_mul
{},
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
output
);
ins
,
hip_mul
{},
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
output
);
}
}
instruction_ref
apply_max
(
instruction_ref
ins
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
hip_max
{},
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
output
);
}
instruction_ref
apply_min
(
instruction_ref
ins
)
{
auto
output
=
insert_allocation
(
ins
,
ins
->
get_shape
());
return
prog
->
replace_instruction
(
ins
,
hip_min
{},
ins
->
inputs
().
at
(
0
),
ins
->
inputs
().
at
(
1
),
output
);
}
instruction_ref
apply_dot
(
instruction_ref
ins
)
instruction_ref
apply_dot
(
instruction_ref
ins
)
{
{
auto
&&
op
=
any_cast
<
op
::
dot
>
(
ins
->
get_operator
());
auto
&&
op
=
any_cast
<
op
::
dot
>
(
ins
->
get_operator
());
...
...
src/targets/gpu/max.cpp
0 → 100644
View file @
25597e6b
#include <migraphx/gpu/max.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
shape
hip_max
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
// check_shapes{inputs, *this}.has(3).standard();
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
return
inputs
.
at
(
0
);
}
argument
hip_max
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
device
::
max
(
ctx
.
get_stream
().
get
(),
args
[
2
],
args
[
0
],
args
[
1
]);
return
args
[
2
];
}
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
src/targets/gpu/min.cpp
0 → 100644
View file @
25597e6b
#include <migraphx/gpu/min.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPH_INLINE_NS
{
namespace
gpu
{
shape
hip_min
::
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
// check_shapes{inputs, *this}.has(3).standard();
check_shapes
{
inputs
,
*
this
}.
has
(
3
);
return
inputs
.
at
(
0
);
}
argument
hip_min
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
device
::
min
(
ctx
.
get_stream
().
get
(),
args
[
2
],
args
[
0
],
args
[
1
]);
return
args
[
2
];
}
}
// namespace gpu
}
// namespace MIGRAPH_INLINE_NS
}
// namespace migraphx
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