-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Refactor attention kernels #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e1b1303
Use reduced precision for attention computation
WoosukKwon b576e46
Code cleaning
WoosukKwon 8bdb09c
Create attention dir
WoosukKwon 4b10136
Refactor attention_utils
WoosukKwon c25cea4
Move
WoosukKwon 8ad2170
Move blocksum to attention
WoosukKwon 3a2337b
Refactor attention kernel
WoosukKwon f299f32
Move vector data types
WoosukKwon e500681
Remove cuda_primitives
WoosukKwon cd82a10
Change .h to .cuh
WoosukKwon beb21bf
Minor fix
WoosukKwon 48f0d87
[Minor] Fix indentation
WoosukKwon ddc4d81
[Minor] Code formatting
WoosukKwon b3f4c38
Replace pragma once with header guard
WoosukKwon a5c02e9
Revert "Replace pragma once with header guard"
WoosukKwon e84bf29
Remove test for multi_query_cached_kv
WoosukKwon 725d735
Merge branch 'main' into dtype
WoosukKwon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include "attention_generic.cuh" | ||
#include "dtype_float16.cuh" | ||
#include "dtype_float32.cuh" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
namespace cacheflow { | ||
|
||
// A vector type to store Q, K, V elements. | ||
template<typename T, int VEC_SIZE> | ||
struct Vec {}; | ||
|
||
// A vector type to store FP32 accumulators. | ||
template<typename T> | ||
struct FloatVec {}; | ||
|
||
// Template vector operations. | ||
template<typename Acc, typename A, typename B> | ||
inline __device__ Acc mul(A a, B b); | ||
|
||
template<typename T> | ||
inline __device__ float sum(T v); | ||
|
||
template<typename T> | ||
inline __device__ float dot(T a, T b) { | ||
return sum(mul<T, T, T>(a, b)); | ||
} | ||
|
||
template<typename A, typename T> | ||
inline __device__ float dot(T a, T b) { | ||
return sum(mul<A, T, T>(a, b)); | ||
} | ||
|
||
template<typename T> | ||
inline __device__ void zero(T& dst) { | ||
constexpr int WORDS = sizeof(T) / 4; | ||
union { | ||
T raw; | ||
uint32_t words[WORDS]; | ||
} tmp; | ||
|
||
#pragma unroll | ||
for (int ii = 0; ii < WORDS; ++ii) { | ||
tmp.words[ii] = 0u; | ||
} | ||
dst = tmp.raw; | ||
} | ||
|
||
} // namespace cacheflow |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the define guard instead of
#pragma once
per Google's C++ style guide :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either options have pros and cons. I think it's safe to use
#pragma once
, because it is commonly used in DL projects such as PyTorch and FasterTransformer.