Repository navigation
Use NPY_METH_get_loop for within-dtype and SIMD cross-dtype casts. - #462
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1034591161
branch
4 times, most recently
from
December 2, 2026 20:33
5312eee to
6b715c8
Compare
Move byte-order swap checks, stride dispatch, `copyswapn` indirection, and CPU SIMD target selection out of the per-chunk inner loop into once-per-operation `get_loop` callbacks (`WithinDTypeGetLoop` and `BitwiseCastGetLoop`). Also add fragmented boolean-mask, `np.where`, strided-copy, and masked-cast benchmarks to `benchmarks/benchmark.py`. Benchmark diff (`n = 262144`, AMD EPYC 7B13, 6 runs): name cpu/op cpu/op vs base INSTRUCTIONS/op vs base fill_nonzero_bf16/n:16384 908.7n ± 3% 901.8n ± 3% ~ (p=0.818 n=6) 6.03k -> 5.96k -1.16% mask_read_bf16/n:262144 1.731m ± 3% 1.339m ± 1% -22.66% (p=0.002 n=6) 10.51M -> 5.94M -43.44% mask_fill_zero_bf16/n:262144 1.724m ± 1% 1.299m ± 1% -24.64% (p=0.002 n=6) 11.69M -> 7.21M -38.34% mask_fill_nonzero_bf16/n:262144 1.701m ± 1% 1.302m ± 14% -23.44% (p=0.002 n=6) 12.40M -> 7.21M -41.88% mask_read_e4m3fn/n:262144 1.690m ± 2% 1.352m ± 3% -19.99% (p=0.002 n=6) 9.65M -> 5.91M -38.79% mask_fill_zero_e4m3fn/n:262144 1.698m ± 0% 1.313m ± 0% -22.71% (p=0.002 n=6) 10.66M -> 6.52M -38.84% mask_fill_nonzero_e4m3fn/n:262144 1.696m ± 1% 1.319m ± 1% -22.24% (p=0.002 n=6) 10.66M -> 6.52M -38.84% mask_read_complex32/n:262144 1.713m ± 1% 1.343m ± 2% -21.58% (p=0.002 n=6) 10.58M -> 6.01M -43.16% mask_fill_zero_complex32/n:262144 1.753m ± 1% 1.315m ± 1% -24.95% (p=0.002 n=6) 11.67M -> 7.21M -38.24% mask_fill_nonzero_complex32/n:262144 1.709m ± 1% 1.314m ± 1% -23.10% (p=0.002 n=6) 12.40M -> 7.21M -41.88% cast_mask_bf16_to_f32/n:262144 1.403m ± 1% 1.337m ± 1% -4.67% (p=0.002 n=6) 8.03M -> 7.18M -10.64% cast_mask_f32_to_bf16/n:262144 1.470m ± 0% 1.437m ± 0% -2.22% (p=0.002 n=6) 8.96M -> 8.10M -9.53% cast_mask_f32_to_e4m3fn/n:262144 1.834m ± 0% 1.792m ± 1% -2.28% (p=0.002 n=6) 14.18M -> 13.33M -6.02% cast_mask_int32_to_int4/n:262144 1.451m ± 1% 1.345m ± 0% -7.29% (p=0.002 n=6) 8.03M -> 7.17M -10.64% PiperOrigin-RevId: 1034706204
copybara-service
Bot
force-pushed
the
test_1034591161
branch
from
December 2, 2026 20:44
6b715c8 to
9cad2fd
Compare
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.
Use NPY_METH_get_loop for within-dtype and SIMD cross-dtype casts.
Move byte-order swap checks, stride dispatch,
copyswapnindirection, and CPU SIMD target selection out of the per-chunk inner loop into once-per-operationget_loopcallbacks (WithinDTypeGetLoopandBitwiseCastGetLoop). Also add fragmented boolean-mask,np.where, strided-copy, and masked-cast benchmarks tobenchmarks/benchmark.py.Benchmark diff (
n = 262144, AMD EPYC 7B13, 6 runs):name cpu/op cpu/op vs base INSTRUCTIONS/op vs base
fill_nonzero_bf16/n:16384 908.7n ± 3% 901.8n ± 3% ~ (p=0.818 n=6) 6.03k -> 5.96k -1.16%
mask_read_bf16/n:262144 1.731m ± 3% 1.339m ± 1% -22.66% (p=0.002 n=6) 10.51M -> 5.94M -43.44%
mask_fill_zero_bf16/n:262144 1.724m ± 1% 1.299m ± 1% -24.64% (p=0.002 n=6) 11.69M -> 7.21M -38.34%
mask_fill_nonzero_bf16/n:262144 1.701m ± 1% 1.302m ± 14% -23.44% (p=0.002 n=6) 12.40M -> 7.21M -41.88%
mask_read_e4m3fn/n:262144 1.690m ± 2% 1.352m ± 3% -19.99% (p=0.002 n=6) 9.65M -> 5.91M -38.79%
mask_fill_zero_e4m3fn/n:262144 1.698m ± 0% 1.313m ± 0% -22.71% (p=0.002 n=6) 10.66M -> 6.52M -38.84%
mask_fill_nonzero_e4m3fn/n:262144 1.696m ± 1% 1.319m ± 1% -22.24% (p=0.002 n=6) 10.66M -> 6.52M -38.84%
mask_read_complex32/n:262144 1.713m ± 1% 1.343m ± 2% -21.58% (p=0.002 n=6) 10.58M -> 6.01M -43.16%
mask_fill_zero_complex32/n:262144 1.753m ± 1% 1.315m ± 1% -24.95% (p=0.002 n=6) 11.67M -> 7.21M -38.24%
mask_fill_nonzero_complex32/n:262144 1.709m ± 1% 1.314m ± 1% -23.10% (p=0.002 n=6) 12.40M -> 7.21M -41.88%
cast_mask_bf16_to_f32/n:262144 1.403m ± 1% 1.337m ± 1% -4.67% (p=0.002 n=6) 8.03M -> 7.18M -10.64%
cast_mask_f32_to_bf16/n:262144 1.470m ± 0% 1.437m ± 0% -2.22% (p=0.002 n=6) 8.96M -> 8.10M -9.53%
cast_mask_f32_to_e4m3fn/n:262144 1.834m ± 0% 1.792m ± 1% -2.28% (p=0.002 n=6) 14.18M -> 13.33M -6.02%
cast_mask_int32_to_int4/n:262144 1.451m ± 1% 1.345m ± 0% -7.29% (p=0.002 n=6) 8.03M -> 7.17M -10.64%