Commit 76dce45
committed
Calibrate raw buffers with an optional numba kernel
_mult_cal_one is 86-93% of the FIFF read loop (tag I/O is 7-13%, seek and
reshape are noise). It asks a single np.multiply to byte-swap, cast to float64,
transpose and scale at once. NumPy has no fused loop for that, so it falls back
to nditer buffering; a jitted loop does the same work in one pass.
raw.get_data(), interleaved cross-process medians:
main byteswap only + kernel
FIFF 133 MB int16 109.6 ms 91.4 (1.20x) 59.5 (1.84x)
FIFF 263 MB float32 99.5 ms 101.2 (0.98x) 65.2 (1.53x)
FIFF test_raw.fif 9.1 ms 7.7 (1.18x) 4.9 (1.87x)
CTF 1.34 ms 1.35 (0.99x) 1.03 (1.31x)
The kernel also rescues float32 FIFF, which the byte-order commit alone cannot
help: swapping floats in NumPy costs about what it saves, but numba refuses
byte-swapped input outright, so the swap becomes worthwhile once the kernel
follows it.
Follows the existing numba pattern: the jitted function lives in its own
lazily-imported module, is gated on has_numba, and falls back to the NumPy path
(kept intact, including its integer byte-order fix) when numba is missing or
MNE_USE_NUMBA=false.
TRADE-OFF for review: this puts numba on the raw-reading path, so the first
get_data() in a process pays ~0.09 s, which is almost entirely 'import numba'
-- the very cost mne/_numba.py's docstring says it keeps out of mne.fixes.
Break-even is roughly 200 MB of FIFF per session; below that it is a small
regression. MNE_USE_NUMBA=false opts out. Gating the kernel on total read size
would avoid the cost for small reads but needs a size hint threaded through
_read_segment_file, which touches every reader's signature.
Verified on both paths: 910 tests pass with and without numba, and get_data()
is bit-identical to main for 37/37 readable fixtures across 18 formats.1 parent 40149fe commit 76dce45
3 files changed
Lines changed: 60 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
74 | 92 | | |
75 | 93 | | |
76 | 94 | | |
| |||
89 | 107 | | |
90 | 108 | | |
91 | 109 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
104 | 131 | | |
105 | 132 | | |
106 | 133 | | |
| |||
0 commit comments