-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[CPU][ARM] Fixed cvt_copy fast path for mha_single_token_kernel #28265
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
dmitry-gorokhov
merged 2 commits into
openvinotoolkit:master
from
dmitry-gorokhov:feature/fix_mha_single_token_kernel
Jan 8, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -62,31 +62,50 @@ void cvt_copy(TA* dst, TB* src, size_t n) { | |
auto vb = mm256_uni_loadu_ps(src + i); | ||
mm256_uni_storeu_ps(dst + i, vb); | ||
} | ||
#elif defined(OPENVINO_ARCH_ARM64) | ||
#endif | ||
for (; i < n; i++) { | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
#if defined(OPENVINO_ARCH_ARM64) | ||
# if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) | ||
if (std::is_same<TA, ov::float16>::value && std::is_same<TB, ov::float16>::value) { | ||
# if defined(HAVE_SVE) | ||
size_t inc = vec_len_f16_sve(); | ||
svbool_t pg = svptrue_b16(); | ||
template <> | ||
void cvt_copy(ov::float16* dst, ov::float16* src, size_t n) { | ||
size_t i = 0; | ||
size_t inc = vec_len_f16_sve(); | ||
svbool_t pg = svptrue_b16(); | ||
|
||
while (i < n) { | ||
if (n - i < vec_len_f16_sve()) { | ||
inc = n - i; | ||
pg = svwhilelt_b16(0, static_cast<int>(inc)); | ||
} | ||
svfloat16_t b1 = svld1_f16(pg, reinterpret_cast<const float16_t*>(src + i)); | ||
svst1_f16(pg, reinterpret_cast<float16_t*>(dst + i), b1); | ||
i += inc; | ||
} | ||
# else | ||
for (; i + vec_len_f16_neon <= n; i += vec_len_f16_neon) { | ||
auto vb1 = vld1q_f16(reinterpret_cast<const float16_t*>(src + i)); | ||
vst1q_f16(reinterpret_cast<float16_t*>(dst + i), vb1); | ||
while (i < n) { | ||
if (n - i < vec_len_f16_sve()) { | ||
inc = n - i; | ||
pg = svwhilelt_b16(0, static_cast<int>(inc)); | ||
} | ||
# endif | ||
svfloat16_t b1 = svld1_f16(pg, reinterpret_cast<const float16_t*>(src + i)); | ||
svst1_f16(pg, reinterpret_cast<float16_t*>(dst + i), b1); | ||
i += inc; | ||
} | ||
# else | ||
# if defined(HAVE_SVE) | ||
} | ||
# else // NEON | ||
template <> | ||
void cvt_copy(ov::float16* dst, ov::float16* src, size_t n) { | ||
size_t i = 0; | ||
for (; i + vec_len_f16_neon <= n; i += vec_len_f16_neon) { | ||
auto vb1 = vld1q_f16(reinterpret_cast<const float16_t*>(src + i)); | ||
vst1q_f16(reinterpret_cast<float16_t*>(dst + i), vb1); | ||
} | ||
for (; i < n; i++) { | ||
dst[i] = src[i]; | ||
} | ||
} | ||
# endif // defined(HAVE_SVE) | ||
# endif // defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) | ||
|
||
# if defined(HAVE_SVE) | ||
template <> | ||
void cvt_copy(float* dst, float* src, size_t n) { | ||
size_t i = 0; | ||
auto _dst = reinterpret_cast<float32_t*>(dst); | ||
size_t inc = vec_len_f32_sve(); | ||
svbool_t pg = svptrue_b32(); | ||
|
@@ -100,20 +119,21 @@ void cvt_copy(TA* dst, TB* src, size_t n) { | |
svst1_f32(pg, _dst + i, b1); | ||
i += inc; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comment applied here. |
||
# else | ||
if (std::is_same<TA, float>::value && std::is_same<TB, float>::value) { | ||
for (; i + vec_len_f32_neon <= n; i += vec_len_f32_neon) { | ||
float32x4_t vb1 = __vld1q_f32(src + i); | ||
__vst1q_f32(dst + i, vb1); | ||
} | ||
} | ||
# else // NEON | ||
template <> | ||
void cvt_copy(float* dst, float* src, size_t n) { | ||
size_t i = 0; | ||
for (; i + vec_len_f32_neon <= n; i += vec_len_f32_neon) { | ||
float32x4_t vb1 = __vld1q_f32(src + i); | ||
__vst1q_f32(dst + i, vb1); | ||
} | ||
# endif | ||
# endif | ||
#endif | ||
for (; i < n; i++) { | ||
dst[i] = src[i]; | ||
} | ||
} | ||
# endif // defined(HAVE_SVE) | ||
#endif // defined(OPENVINO_ARCH_ARM64) | ||
|
||
template <typename T> | ||
static void attn_acc_value(float* out, float weight, T* v, size_t S, float* scale, float* zp) { | ||
|
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
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
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
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.
Shouldn't we add this loop in
HAVE_SVE
branch?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.
We shouldn't, because SVE handles tiles inside vector loop:

In fact this is one the major concepts of SVE: generilized tiles handling.