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
flash-attention
Commits
63b35c93
Commit
63b35c93
authored
Feb 13, 2024
by
skrider
Committed by
Woosuk Kwon
Mar 28, 2024
Browse files
compiles for all h but 128
parent
c29f7313
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
csrc/flash_attn/src/flash_fwd_kernel.h
csrc/flash_attn/src/flash_fwd_kernel.h
+16
-6
csrc/flash_attn/src/utils.h
csrc/flash_attn/src/utils.h
+8
-1
No files found.
csrc/flash_attn/src/flash_fwd_kernel.h
View file @
63b35c93
...
@@ -597,10 +597,15 @@ inline __device__ void compute_attn_1rowblock_splitkv(const Params ¶ms, cons
...
@@ -597,10 +597,15 @@ inline __device__ void compute_attn_1rowblock_splitkv(const Params ¶ms, cons
Tensor
tQgQ
=
gmem_thr_copy_Q
.
partition_S
(
gQ
);
Tensor
tQgQ
=
gmem_thr_copy_Q
.
partition_S
(
gQ
);
Tensor
tQsQ
=
gmem_thr_copy_Q
.
partition_D
(
sQ
);
Tensor
tQsQ
=
gmem_thr_copy_Q
.
partition_D
(
sQ
);
Tensor
tKgK
=
gmem_thr_copy_KV
.
partition_S
(
gK
);
// (KCPY, KCPY_N, KCPY_K)
Tensor
tKgK_
=
gmem_thr_copy_KV
.
partition_S
(
gK
);
// (KCPY, KCPY_N, KCPY_K)
Tensor
tKsK
=
gmem_thr_copy_KV
.
partition_D
(
sK
);
Tensor
tKsK_
=
gmem_thr_copy_KV
.
partition_D
(
sK
);
Tensor
tVgV
=
gmem_thr_copy_KV
.
partition_S
(
gV
);
// (VCPY, VCPY_N, VCPY_K)
Tensor
tVgV_
=
gmem_thr_copy_KV
.
partition_S
(
gV
);
// (VCPY, VCPY_N, VCPY_K)
Tensor
tVsV
=
gmem_thr_copy_KV
.
partition_D
(
sV
);
Tensor
tVsV_
=
gmem_thr_copy_KV
.
partition_D
(
sV
);
Tensor
tKgK
=
make_tensor
(
tKgK_
.
data
(),
unsqueeze
<
2
>
(
layout
<
0
>
(
tKgK_
.
layout
())));
Tensor
tKsK
=
make_tensor
(
tKsK_
.
data
(),
unsqueeze
<
2
>
(
layout
<
0
>
(
tKsK_
.
layout
())));
Tensor
tVgV
=
make_tensor
(
tVgV_
.
data
(),
unsqueeze
<
2
>
(
layout
<
0
>
(
tVgV_
.
layout
())));
Tensor
tVsV
=
make_tensor
(
tVsV_
.
data
(),
unsqueeze
<
2
>
(
layout
<
0
>
(
tVsV_
.
layout
())));
if
(
block_table
!=
nullptr
)
{
if
(
block_table
!=
nullptr
)
{
tKgK
.
data
()
=
gK
.
data
()
+
flash
::
init_thread_kv_page_slice_offset
<
Kernel_traits
>
(
tidx
,
n_block_max
,
params
.
page_block_size
,
tKgK
.
data
()
=
gK
.
data
()
+
flash
::
init_thread_kv_page_slice_offset
<
Kernel_traits
>
(
tidx
,
n_block_max
,
params
.
page_block_size
,
...
@@ -708,8 +713,13 @@ inline __device__ void compute_attn_1rowblock_splitkv(const Params ¶ms, cons
...
@@ -708,8 +713,13 @@ inline __device__ void compute_attn_1rowblock_splitkv(const Params ¶ms, cons
+
row_offset_vnew
-
binfo
.
seqlen_k_cache
*
params
.
vnew_row_stride
),
+
row_offset_vnew
-
binfo
.
seqlen_k_cache
*
params
.
vnew_row_stride
),
Shape
<
Int
<
kBlockN
>
,
Int
<
kHeadDim
>>
{},
Shape
<
Int
<
kBlockN
>
,
Int
<
kHeadDim
>>
{},
make_stride
(
params
.
vnew_row_stride
,
_1
{}));
make_stride
(
params
.
vnew_row_stride
,
_1
{}));
Tensor
tKgKnew
=
gmem_thr_copy_KV
.
partition_S
(
gKnew
);
// (KCPY, KCPY_N, KCPY_K)
typename
Kernel_traits
::
GmemTiledCopyQKVPaged
gmem_tiled_copy_KV_new
;
Tensor
tVgVnew
=
gmem_thr_copy_KV
.
partition_S
(
gVnew
);
// (VCPY, VCPY_N, VCPY_K)
auto
gmem_thr_copy_KV_new
=
gmem_tiled_copy_KV_new
.
get_thread_slice
(
tidx
);
Tensor
tKgKnew_
=
gmem_thr_copy_KV_new
.
partition_S
(
gKnew
);
// (KCPY, KCPY_N, KCPY_K)
Tensor
tVgVnew_
=
gmem_thr_copy_KV_new
.
partition_S
(
gVnew
);
// (VCPY, VCPY_N, VCPY_K)
auto
tKgKnew
=
make_tensor
(
tKgKnew_
.
data
(),
unsqueeze
<
2
>
(
layout
<
0
>
(
tKgKnew_
.
layout
())));
auto
tVgVnew
=
make_tensor
(
tVgVnew_
.
data
(),
unsqueeze
<
2
>
(
layout
<
0
>
(
tVgVnew_
.
layout
())));
const
int
n_block_copy_min
=
std
::
max
(
n_block_min
,
binfo
.
seqlen_k_cache
/
kBlockN
);
const
int
n_block_copy_min
=
std
::
max
(
n_block_min
,
binfo
.
seqlen_k_cache
/
kBlockN
);
auto
tKgK_data
=
tKgK
.
data
();
auto
tKgK_data
=
tKgK
.
data
();
...
...
csrc/flash_attn/src/utils.h
View file @
63b35c93
...
@@ -323,7 +323,6 @@ int advance_thread_kv_page_slice_offset(const int tidx, const int n_block, const
...
@@ -323,7 +323,6 @@ int advance_thread_kv_page_slice_offset(const int tidx, const int n_block, const
const
int
*
block_table
,
const
int
page_stride
,
const
int
row_stride
)
{
const
int
*
block_table
,
const
int
page_stride
,
const
int
row_stride
)
{
constexpr
int
kGmemThreadsPerRow
=
Kernel_traits
::
kGmemThreadsPerRow
;
constexpr
int
kGmemThreadsPerRow
=
Kernel_traits
::
kGmemThreadsPerRow
;
constexpr
int
kGmemRowsPerThread
=
Kernel_traits
::
kGmemRowsPerThread
;
constexpr
int
kGmemRowsPerThread
=
Kernel_traits
::
kGmemRowsPerThread
;
constexpr
int
kGmemElemsPerLoad
=
Kernel_traits
::
kGmemElemsPerLoad
;
constexpr
int
kBlockN
=
Kernel_traits
::
kBlockN
;
constexpr
int
kBlockN
=
Kernel_traits
::
kBlockN
;
const
int
block_row_offset
=
tidx
/
kGmemThreadsPerRow
*
kGmemRowsPerThread
;
const
int
block_row_offset
=
tidx
/
kGmemThreadsPerRow
*
kGmemRowsPerThread
;
...
@@ -345,6 +344,14 @@ int advance_thread_kv_page_slice_offset(const int tidx, const int n_block, const
...
@@ -345,6 +344,14 @@ int advance_thread_kv_page_slice_offset(const int tidx, const int n_block, const
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
template
<
int
N
,
class
Shape
,
class
Stride
>
__forceinline__
__device__
constexpr
auto
unsqueeze
(
Layout
<
Shape
,
Stride
>
l
)
{
return
make_layout
(
insert
<
N
>
(
l
.
shape
(),
Int
<
1
>
{}),
insert
<
N
>
(
l
.
stride
(),
Int
<
0
>
{}));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template
<
bool
Is_even_MN
=
true
,
bool
Is_even_K
=
true
,
bool
Clear_OOB_MN
=
false
,
bool
Clear_OOB_K
=
true
,
template
<
bool
Is_even_MN
=
true
,
bool
Is_even_K
=
true
,
bool
Clear_OOB_MN
=
false
,
bool
Clear_OOB_K
=
true
,
typename
TiledCopy
,
typename
Engine0
,
typename
Layout0
,
typename
Engine1
,
typename
Layout1
,
typename
TiledCopy
,
typename
Engine0
,
typename
Layout0
,
typename
Engine1
,
typename
Layout1
,
typename
Engine2
,
typename
Layout2
,
typename
Engine3
,
typename
Layout3
>
typename
Engine2
,
typename
Layout2
,
typename
Engine3
,
typename
Layout3
>
...
...
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