gobackend: SIMD FusedSDPA, Where implicit broadcast & AVX, and attention/matmul optimizations - #37
Merged
Merged
Conversation
AVX2 and AVX512 implementations for `Where`.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR introduces substantial performance optimizations and feature improvements across the pure Go backend (
compute/internal/gobackend), with a major focus on attention workloads (Scaled Dot-Product Attention), operator SIMD vectorization and parallelization, implicit broadcasting forWhere, and MatMul assembly enhancements:1. SIMD Fused Scaled Dot-Product Attention (SDPA)
SDPAFloat32ArchFnand registered architecture-specific dispatchers (SetSDPAArchDispatcher,GetSDPAArchDispatcher) ininternal/gobackend/sdpa_arch.go.batchSize * numKVHeads) with dedicated per-worker scratchpad buffer reuse.internal/gobackend/fusedops/avx2/sdpa.goandinternal/gobackend/fusedops/avx512/sdpa.go.exp256/exp512), maximum reduction, and vector reciprocal normalization.2.
WhereOperator: Implicit Broadcasting & SIMD AccelerationWhereandshapeinference.Whereto support standard implicit broadcasting across all three operands (condition,onTrue,onFalse), supporting scalars as well as size-1 dimension expansions across matching ranks.ImplicitBroadcastFusiongraph pass (internal/gobackend/passes/implicitbroadcast.go) to fuseBroadcastInDimdirectly intoWhere.StandardOps.Where.Wherewhen tensor size exceeds single-threaded thresholds (totalElements > 16384).internal/gobackend/ops/where_amd64.s) for contiguous and trailing broadcast evaluation under AVX2 and AVX-512.where_amd64.go,where_other.go) and comprehensive unit tests (where_test.go,shapeinference_test.go).3. MatMul Packing & Epilogue Optimizations
PackLHSassembly routines ininternal/gobackend/dot/matmul/avx512/pack_amd64_float32.sandpacking.go.epilogue_amd64.s,epilogue_amd64.go,epilogue_generic.go) and unit tests.4. Fast-Paths and Intra-Op Parallelization for Transpose, SoftMax & Activations
(0, 2, 1, 3)([batch, seq, heads, dim] <-> [batch, heads, seq, dim]) ininternal/gobackend/ops/transpose.go.fusedops/softmax.goacross worker pools for multi-head and batch dimensions.internal/gobackend/activations/activations.go.5. Runtime Hardware Capabilities
IsAVX2AllowedandIsAVX512Allowedininternal/gobackend/capabilities.goto mutable boolean variables, allowing runtime toggling and fine-grained SIMD test validation across environments.