Skip to content

Commit ddedadb

Browse files
authored
Merge pull request #2 from thustorage/worktree-blake3-hwaccel
build: enable hardware-accelerated BLAKE3 in cas_core
2 parents e645373 + e11a778 commit ddedadb

9 files changed

Lines changed: 3392 additions & 7 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
./build/cas_test_fh_lifecycle /tmp /tmp/test.sock || true
3131
./build/cas_test_branch_merge_daemon || true
3232
./build/cas_test_branch_persistence || true
33+
./build/cas_test_blake3_simd
3334
./build/cas_test_telemetry_event
3435
./build/cas_test_telemetry_registry
3536
@@ -56,6 +57,7 @@ jobs:
5657
./build/cas_test_branch_context
5758
./build/cas_test_branch_merge
5859
./build/cas_test_branch_merge_commit
60+
./build/cas_test_blake3_simd
5961
./build/cas_test_telemetry_event
6062
./build/cas_test_telemetry_registry
6163
@@ -83,6 +85,7 @@ jobs:
8385
.\build\Release\cas_test_write_buffer.exe
8486
.\build\Release\cas_test_branch_context.exe
8587
.\build\Release\cas_test_branch_merge.exe
88+
.\build\Release\cas_test_blake3_simd.exe
8689
.\build\Release\cas_test_telemetry_event.exe
8790
8891
windows-daemon:

‎CMakeLists.txt‎

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,65 @@ set(CAS_CORE_PORTABLE_SOURCES
148148
set(CAS_CORE_POSIX_SOURCES
149149
src/cas/control_socket.cpp
150150
)
151+
152+
option(AGENTVFS_BLAKE3_SIMD "Enable runtime-dispatched BLAKE3 SIMD paths" ON)
153+
151154
add_library(cas_core STATIC ${CAS_CORE_PORTABLE_SOURCES})
152155
if(UNIX)
153156
target_sources(cas_core PRIVATE ${CAS_CORE_POSIX_SOURCES})
154157
endif()
155158
target_include_directories(cas_core PUBLIC src/cas include include/blake3)
156-
target_compile_definitions(cas_core PRIVATE
157-
BLAKE3_NO_AVX512 BLAKE3_NO_AVX2 BLAKE3_NO_SSE41 BLAKE3_NO_SSE2
158-
# On aarch64 the vendored blake3 auto-enables NEON, but we only
159-
# compile blake3_portable.c — link would fail with an unresolved
160-
# blake3_hash_many_neon. Force the portable path on every arch.
161-
BLAKE3_USE_NEON=0)
159+
160+
if(AGENTVFS_BLAKE3_SIMD)
161+
set(_blake3_amd64_names amd64 AMD64 x86_64)
162+
set(_blake3_arm64_names aarch64 AArch64 arm64 ARM64 armv8 armv8a)
163+
164+
if(CMAKE_SYSTEM_PROCESSOR IN_LIST _blake3_amd64_names)
165+
target_sources(cas_core PRIVATE
166+
include/blake3/blake3_sse2.c
167+
include/blake3/blake3_sse41.c
168+
include/blake3/blake3_avx2.c
169+
include/blake3/blake3_avx512.c)
170+
if(MSVC)
171+
# MSVC has no dedicated /arch:SSE4.1 — /arch:AVX is the
172+
# narrowest flag that turns on SSE4.1 codegen. /arch:SSE2 is
173+
# x86-only; on x64 SSE2 is the implicit baseline and MSVC
174+
# silently ignores the flag, which is harmless.
175+
set_source_files_properties(include/blake3/blake3_sse2.c
176+
PROPERTIES COMPILE_OPTIONS "/arch:SSE2")
177+
set_source_files_properties(include/blake3/blake3_sse41.c
178+
PROPERTIES COMPILE_OPTIONS "/arch:AVX")
179+
set_source_files_properties(include/blake3/blake3_avx2.c
180+
PROPERTIES COMPILE_OPTIONS "/arch:AVX2")
181+
set_source_files_properties(include/blake3/blake3_avx512.c
182+
PROPERTIES COMPILE_OPTIONS "/arch:AVX512")
183+
else()
184+
set_source_files_properties(include/blake3/blake3_sse2.c
185+
PROPERTIES COMPILE_OPTIONS "-msse2")
186+
set_source_files_properties(include/blake3/blake3_sse41.c
187+
PROPERTIES COMPILE_OPTIONS "-msse4.1")
188+
set_source_files_properties(include/blake3/blake3_avx2.c
189+
PROPERTIES COMPILE_OPTIONS "-mavx2")
190+
set_source_files_properties(include/blake3/blake3_avx512.c
191+
PROPERTIES COMPILE_OPTIONS "-mavx512f;-mavx512vl")
192+
endif()
193+
elseif(CMAKE_SYSTEM_PROCESSOR IN_LIST _blake3_arm64_names)
194+
target_sources(cas_core PRIVATE include/blake3/blake3_neon.c)
195+
# 64-bit aarch64 has NEON unconditionally; no -mfpu flag needed.
196+
# blake3_dispatch.c picks NEON automatically when BLAKE3_USE_NEON
197+
# is unset (the upstream default).
198+
else()
199+
# Unknown arch — fall back to portable, same as
200+
# AGENTVFS_BLAKE3_SIMD=OFF.
201+
target_compile_definitions(cas_core PRIVATE
202+
BLAKE3_NO_AVX512 BLAKE3_NO_AVX2 BLAKE3_NO_SSE41 BLAKE3_NO_SSE2
203+
BLAKE3_USE_NEON=0)
204+
endif()
205+
else()
206+
target_compile_definitions(cas_core PRIVATE
207+
BLAKE3_NO_AVX512 BLAKE3_NO_AVX2 BLAKE3_NO_SSE41 BLAKE3_NO_SSE2
208+
BLAKE3_USE_NEON=0)
209+
endif()
162210
if(NOT MSVC)
163211
target_compile_options(cas_core PRIVATE -Wall -Wextra -Wpedantic)
164212
endif()
@@ -523,6 +571,11 @@ target_include_directories(cas_test_telemetry_registry PRIVATE include src src/c
523571
target_compile_features(cas_test_telemetry_registry PRIVATE cxx_std_17)
524572
endif()
525573

574+
if(AGENTVFS_BLAKE3_SIMD)
575+
add_executable(cas_test_blake3_simd tests/cas/test_blake3_simd.cpp)
576+
target_link_libraries(cas_test_blake3_simd PRIVATE cas_core)
577+
endif()
578+
526579
if(LINUX)
527580
add_executable(cas_test_ebpf_backend
528581
tests/cas/test_ebpf_backend.cpp

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ cmake --build build -j
103103
```
104104

105105
```powershell
106-
# Windows — requires WinFsp 2.0+ from https://winfsp.dev
106+
# Windows — requires WinFsp 2.0+ from https://winfsp.dev,
107+
# and MSVC v141 (Visual Studio 2017 15.3) or newer for /arch:AVX512
108+
# codegen on the BLAKE3 SIMD path (current VS releases all qualify).
107109
cmake -B build -DAGENTVFS_EBPF=OFF -DAGENTVFS_WINFSP=ON
108110
cmake --build build --config Release -j
109111
.\build\Release\agentvfs.exe --source C:\some\dir --mountpoint Z:

0 commit comments

Comments
 (0)