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
composable_kernel
Commits
4388b767
Commit
4388b767
authored
Jun 27, 2023
by
danyao12
Browse files
optimize fwd v2 dropout to eliminate scratch
parent
00cb7e41
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
127 deletions
+160
-127
include/ck/tensor_operation/gpu/block/blockwise_dropout.hpp
include/ck/tensor_operation/gpu/block/blockwise_dropout.hpp
+12
-26
include/ck/tensor_operation/gpu/grid/gridwise_batched_mha_fwd_xdl_cshuffle_v2.hpp
...ion/gpu/grid/gridwise_batched_mha_fwd_xdl_cshuffle_v2.hpp
+148
-101
No files found.
include/ck/tensor_operation/gpu/block/blockwise_dropout.hpp
View file @
4388b767
...
@@ -198,55 +198,41 @@ struct BlockwiseDropout
...
@@ -198,55 +198,41 @@ struct BlockwiseDropout
});
});
}
}
template
<
typename
CThreadBuffer
,
typename
ZThreadBuffer
,
bool
using_sign_bit
=
fal
se
>
template
<
typename
CThreadBuffer
,
typename
ZThreadBuffer
,
typename
Step
,
typename
Off
se
t
>
__host__
__device__
void
ApplyDropoutWithZ
(
CThreadBuffer
&
in_thread_buf
,
__host__
__device__
void
ApplyDropoutWithZ
(
CThreadBuffer
&
in_thread_buf
,
ZThreadBuffer
&
z_thread_buf
)
ZThreadBuffer
&
z_thread_buf
)
{
{
auto
execute_dropout
=
[
&
](
bool
keep
,
DataType
val
)
{
auto
execute_dropout
=
[
&
](
bool
keep
,
DataType
val
)
{
if
constexpr
(
using_sign_bit
)
return
keep
?
val
*
p_dropout_rescale
:
float
(
0
);
return
keep
?
val
:
-
val
;
else
return
keep
?
val
*
p_dropout_rescale
:
float
(
0
);
};
};
int
tmp_index
=
0
;
constexpr
int
tmp_size
=
MRepeat
*
KRepeat
/
Step
{}.
value
;
static_for
<
0
,
MRepeat
,
1
>
{}([
&
](
auto
iM
)
{
static_for
<
0
,
tmp_size
,
1
>
{}([
&
](
auto
i
)
{
static_for
<
0
,
KRepeat
,
1
>
{}([
&
](
auto
iK
)
{
in_thread_buf
(
i
+
Offset
{})
=
auto
offset
=
Number
<
ThreadSliceDesc_M_K
{}.
CalculateOffset
(
make_tuple
(
iM
,
iK
))
>
{};
execute_dropout
(
z_thread_buf
(
i
)
<=
p_dropout_16bits
,
in_thread_buf
(
i
+
Offset
{}));
in_thread_buf
(
offset
)
=
execute_dropout
(
z_thread_buf
(
offset
)
<=
p_dropout_16bits
,
in_thread_buf
(
offset
));
tmp_index
=
tmp_index
+
1
;
});
});
});
}
}
// get raw z matrix with random number for shuffle
// get raw z matrix with random number for shuffle
template
<
typename
ZThreadBuffer
>
template
<
typename
ZThreadBuffer
,
typename
Step
,
typename
Offset
>
// N3*N4=8
__host__
__device__
void
GenerateZMatrixAttnFwd
(
ck
::
philox
&
ph
,
__host__
__device__
void
GenerateZMatrixAttnFwd
(
ck
::
philox
&
ph
,
index_t
element_global_1d_id
,
index_t
element_global_1d_id
,
ZThreadBuffer
&
z_thread_buf
)
ZThreadBuffer
&
z_thread_buf
)
{
{
constexpr
int
tmp_size
=
MRepeat
*
KRepeat
;
constexpr
int
tmp_size
=
MRepeat
*
KRepeat
/
Step
{}.
value
;
int
philox_calls
=
tmp_size
/
4
;
int
philox_calls
=
tmp_size
/
4
;
ushort
tmp
[
tmp_size
];
ushort
tmp
[
tmp_size
];
for
(
int
i
=
0
;
i
<
philox_calls
;
i
++
)
for
(
int
i
=
0
;
i
<
philox_calls
;
i
++
)
{
{
ph
.
get_random_4x16
((
tmp
+
i
*
4
),
element_global_1d_id
+
i
*
8
);
ph
.
get_random_4x16
((
tmp
+
i
*
4
),
element_global_1d_id
+
i
*
Offset
{}
);
}
}
block_sync_lds
();
static_for
<
0
,
tmp_size
,
1
>
{}([
&
](
auto
i
)
{
z_thread_buf
(
i
)
=
tmp
[
i
.
value
];
});
int
tmp_index
=
0
;
static_for
<
0
,
MRepeat
,
1
>
{}([
&
](
auto
iM
)
{
static_for
<
0
,
KRepeat
,
1
>
{}([
&
](
auto
iK
)
{
auto
offset
=
Number
<
ThreadSliceDesc_M_K
{}.
CalculateOffset
(
make_tuple
(
iM
,
iK
))
>
{};
z_thread_buf
(
offset
)
=
tmp
[
tmp_index
];
tmp_index
=
tmp_index
+
1
;
});
});
}
}
ushort
p_dropout_16bits
;
ushort
p_dropout_16bits
;
...
...
include/ck/tensor_operation/gpu/grid/gridwise_batched_mha_fwd_xdl_cshuffle_v2.hpp
View file @
4388b767
This diff is collapsed.
Click to expand it.
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