Skip to content

hotkernels 0.3.1

Choose a tag to compare

@github-actions github-actions released this 19 Nov 13:58
· 647 commits to main since this release
13008c4

hotkernels 0.3.1

Highlights

On Apple Silicon, the eight kernels that 0.3.0 added for Linux x86-64 now have ARM64 assembly of their own. In 0.3.0 those calls ran on a Mac as compiled C; one of them, np.fmax.reduceat, was slower than NumPy there beyond a few thousand elements. Nothing changes on x86-64. Every figure below is from Python on an Apple M1 Pro, against plain NumPy.

  • Boolean masks. np.cumsum(mask) is 12x faster than NumPy at 4,096 elements and 19x at a million. m.any(axis=1) on a matrix of 22 columns is 11x faster at 4,096 elements and 24x at a million, and rows of every other width were given paths of their own: a matrix of one column, which was slower than NumPy, is now 1.4x faster.
  • Running maxima. np.maximum.accumulate on int64 is 18x faster at 4,096 elements and 14x at a million. np.fmax.accumulate on float64 is 19x and 13x, where 0.3.0 had it at 1.2x.
  • np.fmax.reduceat on runs of 16 elements is 3.6x faster at 4,096 elements and 3.1x at a million, where 0.3.0 was 0.8x and 0.7x of NumPy. On long runs it is still slower than NumPy on Apple Silicon: 0.6x to 0.8x for runs of 256 elements or more in arrays of 262,144 elements and up, and level with it at 4,096 elements. The package reads the array once for signalling NaNs before the kernel reads it, and NumPy reads it once.
  • np.bincount on int16 is 9.4x faster at a million elements and on int64 4.3x, on codes from 0 to 63.
  • np.where(mask, a, b) on float64 or int64 is 3.3x faster at 4,096 elements and 1.6x at a million with half the mask True.
  • One more case that stays behind NumPy on Apple Silicon: m.any(axis=1) on rows of about 1,000 columns that each hold a True runs at about 0.6x of NumPy, which stops at the first True of a row while the package first reads every byte.

No wrong result was fixed in this release.

What is installed. Unchanged: 31 kernels for 21 NumPy operations, 29 of them by install() and two more by install(inexact=True). On Apple Silicon 30 of the 31 are now assembly and one, x.astype(np.float32) on uint8, is compiled C because the judge found no assembly faster; on x86-64 all 31 are assembly, as before.

Checked against NumPy itself. On Apple Silicon, 166,029 NumPy calls give the same result, exceptions and warnings with hotkernels as without, and NumPy's own test suite gives the same outcome for each of its 47,234 tests. The specifications of np.fmax.accumulate and np.fmax.reduceat were narrowed to the inputs the package sends to their kernels (it already left the others to NumPy), and the x86-64 kernels pass the judge under them: 20,368 and 20,313 cases on Linux x86-64.

Where it runs. Unchanged: macOS on Apple Silicon and Linux on x86-64 (glibc, x86-64-v3), Python 3.11 to 3.14, NumPy 2.3 or a later NumPy 2.

Measured from Python with uv run delivery time, one line per machine:

  • Apple M1 Pro, NumPy 2.5.5, Python 3.12.7, with no CI job running (load average 2.2), at revision ede46d1, whose package and kernels are those of this release: delivery/results/apple-m1-pro.md. The figures for long runs of np.fmax.reduceat and for other row widths of m.any(axis=1) are from timeit on the same machine.
  • Intel Core i5-14600KF: not measured for this release. No x86-64 kernel changed, and the package's changes are in code compiled only for ARM64, so delivery/results/intel-r-core-tm-i5-14600kf.md is the run recorded for 0.3.0, at revision 52c1abc.

Faster

  • np.maximum.accumulate and np.fmax.accumulate on int64 are served by assembly on Apple Silicon as well: about 14x faster than NumPy at a million elements on an Apple M1 Pro. (#163)
  • np.cumsum on a boolean array is served by assembly on Apple Silicon as well: about 19x faster than NumPy at a million elements on an Apple M1 Pro. (#164)
  • m.any(axis=1) and np.any(m, axis=1) on a two-dimensional boolean array are served by assembly on Apple Silicon as well: on rows of 22 columns about 24x faster than NumPy at a million elements on an Apple M1 Pro, where the kernel alone is 8.7x faster than the compiled C loop that served the call before. (#165)
  • np.bincount on int16 and int64 arrays is served by assembly on Apple Silicon as well: on int16 codes from 0 to 63 about 9x faster than NumPy at a million elements on an Apple M1 Pro, and on int64 about 4x, where the kernels alone are 2.95x and 1.54x faster than the compiled C loops that served the calls before. (#168)
  • np.where(c, a, b) on float64 and int64 arrays is served by assembly on Apple Silicon as well: about 1.7x faster than NumPy at a million elements on an Apple M1 Pro, where the kernel alone is 1.36x faster than the compiled C loop that served the call before. (#170)
  • m.any(axis=1) on Apple Silicon is faster for rows of other widths than 4, 22 and 64 as well: rows of 8 columns, for example, about 3.7x faster than before at a million elements on an Apple M1 Pro, and a matrix of one column now faster than NumPy. (#171)
  • np.fmax.reduceat on float64 is served by assembly on Apple Silicon: on runs of 16 elements it is about 2.4x faster than NumPy at a million elements on an Apple M1 Pro, where it was 0.7x, slower than NumPy. On runs of 256 elements or more it is still slower than NumPy there, about half its speed. (#179)
  • np.fmax.accumulate on float64 is served by assembly on Apple Silicon as well: about 7x faster than NumPy at 4,096 elements and at a million on an Apple M1 Pro, where it was 1.2x. (#180)
  • On Apple Silicon, np.fmax.accumulate on float64 and np.fmax.reduceat read the array more cheaply before the kernel: on an Apple M1 Pro np.fmax.accumulate is about 18x faster than NumPy at 4,096 elements (was 7.5x) and np.fmax.reduceat on runs of 16 about 3x at a million (was 2.3x). np.bincount on 16 int16 elements also gets faster, 4.5x where it was 3.2x. (#181)