Uh oh!
There was an error while loading. Please reload this page.
Integrate oneDNN matmul threadpool backend - #970
Open
romirdes wants to merge 7 commits into
Open
Conversation
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sign up for freeto 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
Adds an optional oneDNN matmul-primitive backend for
MatMul, built against oneDNN's THREADPOOL CPU runtime so oneDNN parallelizes by calling back into gemma.cpp's existing thread pool instead of spawning its own threads.The backend is opt-in and off by default:
bazel build --define gemma_onednn_matmul=1 ...cmake -DGEMMA_ONEDNN_MATMUL=ON ...It is mutually exclusive with the existing BRGeMM backend (
GEMMA_ONEDNN_BRGEMM), because oneDNN's CPU runtime (SEQ vs THREADPOOL) is a whole-library compile-time choice. Enabling both fails fast: a CMakeFATAL_ERROR, an ambiguousselect()in Bazel, and an#errorguard inops/onednn_matmul.h.The path engages only for BF16×BF16 with
M > 1(M == 1 measured slower than stock gemma for some shapes) and falls through to the standard MatMul whenever oneDNN declines or fails, so behavior is unchanged when the flag is off.Changes
ops/onednn_matmul.h#error, and the threadpool adapter that lets oneDNN dispatch work onto gemma.cpp's thread pool.ops/onednn_matmul-inl.hDoMatMul_OneDnn()implementation: builds/caches the matmul primitive and reordered weights, applies scale andadd, returns false to decline unsupported cases.ops/matmul-inl.hM > 1, guarded byGEMMA_ONEDNN_MATMUL, with fall-through to the existing MatMul.ops/matmul.hops/onednn_matmul.h; addMMPerKey::onednn_builtto record that the oneDNN path handled a shape.ops/bench_matmul.ccutil/zones.hCallers::kOneDnnMatMulprofiler zone.util/zones.cc"OneDnnMatMul"name.BUILD.bazelgemma_onednn_matmulconfig setting,GEMMA_ONEDNN_MATMUL=1define, new headers, and the@onednn_tpdependency.MODULE.bazel@onednn_tparchive — same oneDNN v3.11 tarball/sha256 as@onednn(shared download cache), differentbuild_filefor the THREADPOOL runtime.bazel/onednn.bzlonednn_targets(cpu_runtime)derives the runtime-dependent config lines and conditional copt from its argument.bazel/onednn.BUILDonednn_targets(cpu_runtime = "SEQ")call.bazel/onednn_threadpool.BUILDonednn_targets(cpu_runtime = "THREADPOOL")call.CMakeLists.txtGEMMA_ONEDNN_MATMULoption, the mutual-exclusionFATAL_ERROR, and aFetchContentoneDNN v3.11 build configured withDNNL_CPU_RUNTIME=THREADPOOL.Testing
Built and benchmarked with
ops/bench_matmulunder both Bazel and CMake, against the stock MatMul and the BRGeMM backend. Default (flag-off) builds are unaffected.