Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ cc_library(
textual_hdrs = [
"gemma/gemma-inl.h",
"gemma/flash_attention_arm-inl.h",
"gemma/flash_attention_amx-inl.h",
],
deps = [
":activations",
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if(GEMMA_ONEDNN_BRGEMM OR GEMMA_ONEDNN_MATMUL)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/cmake/GemmaFetch.cmake)

gemma_fetch(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 71d029bc9e1d27f8e231b2502e240ae89b8ee7bc EXCLUDE_FROM_ALL)
gemma_fetch(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 97a5dd1af1a43a8b2ccbd31e556b4139bffbdafd EXCLUDE_FROM_ALL)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bazel_dep(name = "google_benchmark", version = "1.8.5")
# Require a more recent version.
git_override(
module_name = "highway",
commit = "71d029bc9e1d27f8e231b2502e240ae89b8ee7bc",
commit = "97a5dd1af1a43a8b2ccbd31e556b4139bffbdafd",
remote = "https://github.com/google/highway",
)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ FetchContent_MakeAvailable(sentencepiece)
FetchContent_Declare(gemma GIT_REPOSITORY https://github.com/google/gemma.cpp GIT_TAG origin/main)
FetchContent_MakeAvailable(gemma)

FetchContent_Declare(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 71d029bc9e1d27f8e231b2502e240ae89b8ee7bc)
FetchContent_Declare(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 97a5dd1af1a43a8b2ccbd31e556b4139bffbdafd)
FetchContent_MakeAvailable(highway)
```

Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else()
endfunction()
endif()

gemma_fetch(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 71d029bc9e1d27f8e231b2502e240ae89b8ee7bc)
gemma_fetch(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 97a5dd1af1a43a8b2ccbd31e556b4139bffbdafd)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
target_compile_definitions(hwy PUBLIC HWY_DISABLED_TARGETS=HWY_AVX10_2)
Expand Down
2 changes: 1 addition & 1 deletion examples/simplified_gemma/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else()
endfunction()
endif()

gemma_fetch(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 71d029bc9e1d27f8e231b2502e240ae89b8ee7bc)
gemma_fetch(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG 97a5dd1af1a43a8b2ccbd31e556b4139bffbdafd)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
target_compile_definitions(hwy PUBLIC HWY_DISABLED_TARGETS=HWY_AVX10_2)
Expand Down
1 change: 1 addition & 0 deletions gemma/configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ constexpr std::pair<const char*, AttentionImpl> kAttentionImplNameToEnum[] = {
{"flash_transposed_qs_int8", AttentionImpl::kFlashTransposedQsInt8},
{"flash_matrix_accumulation", AttentionImpl::kFlashMatrixAccumulation},
{"int8_matrix_accumulation", AttentionImpl::kInt8MatrixAccumulation},
{"flash_amx", AttentionImpl::kFlashAMX},
};

std::string GetAttentionImplName(AttentionImpl impl) {
Expand Down
16 changes: 16 additions & 0 deletions gemma/configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,28 @@ enum class AttentionImpl {
kFlashMatrixAccumulation,
kInt8MatrixAccumulation,
kFlashTransposedQsInt8,
kFlashAMX,
kSentinel,
};

std::string GetAttentionImplName(AttentionImpl impl);
AttentionImpl GetAttentionImpl(const std::string& impl);

static inline bool IsTiledAttention(AttentionImpl impl) {
return impl == AttentionImpl::kFlashTransposedQs ||
impl == AttentionImpl::kFlashTransposedQsBF16 ||
impl == AttentionImpl::kFlashTransposedQsInt16 ||
impl == AttentionImpl::kFlashTransposedQsInt8 ||
impl == AttentionImpl::kInt8MatrixAccumulation ||
impl == AttentionImpl::kFlashMatrixAccumulation ||
impl == AttentionImpl::kFlashAMX;
}

static inline bool IsBF16TransposedQsAttention(AttentionImpl impl) {
return impl == AttentionImpl::kFlashTransposedQsBF16 ||
impl == AttentionImpl::kFlashAMX;
}

// Post attention and ffw normalization type.
enum class PostNormType {
None,
Expand Down
13 changes: 13 additions & 0 deletions gemma/flash_attention.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "compression/compress-inl.h"
#include "gemma/attention.h"
#include "gemma/flash_attention.h"
#include "gemma/flash_attention_amx-inl.h"
#include "gemma/flash_attention_arm-inl.h"
#include "ops/matmul-inl.h"
#include "ops/ops-inl.h"
Expand Down Expand Up @@ -1866,6 +1867,18 @@ void DispatchTileFlashAttentionReturnExpSumsAndMaxLogitsBF16(
});
}

void DispatchTileFlashAttentionReturnExpSumsAndMaxLogitsAMX(
hwy::Span<const MatPtr> kvs, size_t q_count,
const BF16* HWY_RESTRICT q_base,
hwy::Span<const size_t> start_pos_per_query,
hwy::Span<const size_t> last_pos_per_query, const float att_cap,
MatPtrT<float>& att_out, float* HWY_RESTRICT exp_denominator_sums,
float* HWY_RESTRICT max_logits) {
TileFlashAttentionReturnExpSumsAndMaxLogitsAMX(
kvs, q_count, q_base, start_pos_per_query, last_pos_per_query, att_cap,
att_out, exp_denominator_sums, max_logits);
}

void DispatchTileFlashAttentionReturnExpSumsAndMaxLogitsInt16(
hwy::Span<const MatPtr> kvs, size_t q_count,
const int16_t* HWY_RESTRICT q_base, const hwy::Span<const float> q_scales,
Expand Down
8 changes: 8 additions & 0 deletions gemma/flash_attention.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ namespace gcpp {
float* HWY_RESTRICT max_logits, \
hwy::AlignedVector<uint8_t>* worker_workspace); \
\
void DispatchTileFlashAttentionReturnExpSumsAndMaxLogitsAMX( \
hwy::Span<const MatPtr> kvs, size_t q_count, \
const BF16* HWY_RESTRICT q_base, \
hwy::Span<const size_t> start_pos_per_query, \
hwy::Span<const size_t> last_pos_per_query, const float att_cap, \
MatPtrT<float>& att_out, float* HWY_RESTRICT exp_denominator_sums, \
float* HWY_RESTRICT max_logits); \
\
void DispatchTileFlashAttentionReturnExpSumsAndMaxLogitsInt16( \
hwy::Span<const MatPtr> kvs, size_t q_count, \
const int16_t* HWY_RESTRICT q_base, hwy::Span<const float> q_scales, \
Expand Down
Loading
Loading