perf(metax): vectorize elementwise kernel for contiguous aligned tensors#1353
Open
LindseyMei wants to merge 1 commit into
Open
perf(metax): vectorize elementwise kernel for contiguous aligned tensors#1353LindseyMei wants to merge 1 commit into
LindseyMei wants to merge 1 commit into
Conversation
Add a 16-byte vector fast path to the shared MetaX elementwise template. When output and all inputs are contiguous, aligned, non-broadcasted, and share the same floating-point dtype, load/store packed values and apply the existing scalar Op functor per component. Falls back to the original scalar kernel for all other cases. Supported dtypes: float (float4), half (Pack<half,8>), cuda_bfloat16 (Pack<cuda_bfloat16,8>), double (double2). Integer/bool/fp8 and mixed-dtype ops continue to use the scalar path. Benchmark (silu, MetaX C500): - F32 16384x16384: ~59 Gelem/s -> ~177 Gelem/s (~3x) - F16 16384x16384: ~64 Gelem/s -> ~244 Gelem/s (~3.8x) - BF16 16384x16384: ~64 Gelem/s -> ~215 Gelem/s (~3.4x) Regression tests passed: silu, add, mul, reciprocal, gelu, swiglu, clip. Signed-off-by: LindseyMei <648816901@qq.com>
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.
MetaX Elementwise Vectorization Performance Report
Environment
src/infiniop/elementwise/metax/elementwise_metax.hvec_bench.py(silu, synchronized timing)What changed
Added a 16-byte contiguous vector fast path to the shared MetaX elementwise kernel. When output and all inputs are contiguous, aligned, non-broadcasted, and use the same floating-point dtype, the kernel loads/stores
float4/Pack<half,8>/Pack<cuda_bfloat16,8>/Pack<double,2>packs and applies the existing scalarOp{}per component. Strided, broadcasted, unaligned, integer, or mixed-dtype cases fall back to the original scalar kernel unchanged.Correctness
Regression tests passed on Metax:
tanh.pyfailed withINFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTEDbecause thetanh/operator.ccMetax registration is commented out on this branch; unrelated to this change.hardtanh.pyhas a pre-existing GPU crash on the scalar kernel; also unrelated.Performance (silu)
Scalar baseline (before vectorization)
Vectorized (after)
Observations
Known limitations
#pragma unrollbeing unable to unroll some loops; these are non-fatal and do not affect correctness or the measured speedup.Next steps
int32_t,int64_t) with 16-byte packs once validated.gelu,swiglu) can additionally benefit from vector ALU intrinsics (half2).