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
9e610129
Commit
9e610129
authored
Feb 26, 2022
by
Shucai Xiao
Browse files
reimplement mul_add kernel in a simple way
parent
cd0a4aa5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
src/targets/gpu/device/mul_add.cpp
src/targets/gpu/device/mul_add.cpp
+28
-2
No files found.
src/targets/gpu/device/mul_add.cpp
View file @
9e610129
#include <migraphx/gpu/device/mul_add.hpp>
#include <migraphx/gpu/device/nary.hpp>
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
namespace
device
{
__global__
void
mul_add_kernel
(
void
*
a
,
void
*
x
,
void
*
b
,
void
*
r
,
int
n
)
{
int
id
=
blockDim
.
x
*
blockIdx
.
x
+
threadIdx
.
x
;
__half
*
ha
=
reinterpret_cast
<
__half
*>
(
a
);
__half
*
hb
=
reinterpret_cast
<
__half
*>
(
b
);
__half
*
hx
=
reinterpret_cast
<
__half
*>
(
x
);
__half
*
hr
=
reinterpret_cast
<
__half
*>
(
r
);
if
(
id
<
n
)
{
hr
[
id
]
=
__float2half
(
__half2float
(
ha
[
id
])
*
__half2float
(
hx
[
id
])
+
__half2float
(
hb
[
id
]));
}
}
void
mul_add
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg1
,
const
argument
&
arg2
,
const
argument
&
arg3
)
{
nary
(
stream
,
result
,
arg1
,
arg2
,
arg3
)([](
auto
x
,
auto
a
,
auto
b
)
__device__
{
return
a
*
x
+
b
;
});
auto
elem_num
=
result
.
get_shape
().
elements
();
auto
type
=
result
.
get_shape
().
type
();
if
(
type
==
shape
::
half_type
)
{
int
block_size
=
256
;
int
block_num
=
(
elem_num
+
block_size
-
1
)
/
block_size
;
mul_add_kernel
<<<
block_num
,
block_size
>>>
(
arg1
.
data
(),
arg2
.
data
(),
arg3
.
data
(),
result
.
data
(),
elem_num
);
}
else
{
nary
(
stream
,
result
,
arg1
,
arg2
,
arg3
)([](
auto
x
,
auto
a
,
auto
b
)
__device__
{
return
a
*
x
+
b
;
});
}
}
}
// namespace device
...
...
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