Skip to content

Perf phase 1: pre-warm, fewer blocking round trips, bounded JIT cache - #14

Open
AdvaitTahilyani wants to merge 14 commits into
gpu-backendfrom
perf-phase1
Open

AdvaitTahilyani wants to merge 14 commits into
gpu-backendfrom
perf-phase1

Conversation

@AdvaitTahilyani

Copy link
Copy Markdown

Needs UIUC-PPL/charmtyles#7.

  • Pre-warm: after "CCS server ready", each PE creates its cuBLAS/cuSOLVER handles and loads recently used cached kernels (CNUM_PREWARM, CNUM_PREWARM_MS). It never aborts the server. The first linalg call is about 3x faster (cholesky 24 → 7.7 ms, svd 59 → 18 ms at default sizes).
  • Fewer blocking round trips: the nonzero count of a reused boolean mask and repeat's count sum are cached and invalidated on write. indexing_routines goes from 212 to 12 blocking gets, and its default size runs 832 → 609 ms.
  • Bounded JIT disk cache: one directory per GPU target and host. Eviction runs only in marked cache roots and deletes only cache files (CNUM_JIT_CACHE_MAX_FILES, CNUM_JIT_CACHE_DAYS, CNUM_JIT_CACHE_EVICT=0). Only invalid entries are removed on load failure.
  • Benchmark shim: the timer synchronizes at start, as upstream's does.

Tested: CPU +p1/+p2 (15/15, 25/25, 25/25 ops); A100 +p1 (15/15, 25/25); eviction-safety and fault-injection tests.

🤖 Generated with Claude Code

AdvaitTahilyani and others added 9 commits October 27, 2026 21:19
Work recorded before timer.start() (input setup, earlier phases) is no
longer counted, so warm times compare with cuPyNumeric's legate.timing.time().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
x[m] = v, x[m] and m-in-a-key each fetched count_nonzero(m) with a blocking
get. The count is now kept on m's root array, keyed by the view region and
dtype, and is valid only for the root's write version: every in-place write
(set_region, SCATTER, MASK_SCATTER, linked-copy refresh) bumps the version and
drops the cache in _wrote. Linked copies are refreshed before the lookup.
test_mask.py reuses masks across each kind of write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After "CCS server ready", ArrayDAGGroup::prewarm runs on every PE: GPU
builds create the cuBLAS/cuSOLVER handles and run a first GEMM, and every
build loads the most recently used kernels of the disk cache for its target
for up to CNUM_PREWARM_MS (default 250 ms). Requests that arrive meanwhile
wait in the scheduler queue; CNUM_PREWARM=0 skips it.

The disk cache now has one subdirectory per GPU target and host CPU, so a
shared cache never preloads another architecture's kernels. Cache hits touch
the entry so recency orders the preload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
repeat(a, R) with a device R fetched sum(R) with a blocking get on every
call; indexing_routines' repeat loop made 110 of them. The mask count cache
now takes a kind ("nonzero" or "sum") and serves both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_mask.py now also writes through a view of a view of the mask, through
a view of a linked copy, and reuses a folded (>3-D) mask after a write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pre-warm:
- cuBLAS/cuSOLVER handles are created with status checks; on failure nothing
  is kept and later lazy creation behaves as before. The BLAS part is skipped
  below 1 GiB free GPU memory, and all GPU parts unless this thread's current
  device is the one Kokkos uses (no context on another GPU).
- CNUM_PREWARM_MS bounds the whole pre-warm, directory listing included
  (at most 1024 entries are examined); an invalid value means the default.
- Cached kernels load with CUDA failures recorded instead of fatal, and any
  entry that fails to load (object, link, symbol or constructor) is removed.

Cache:
- jit_cache_maintain (PE 0, background thread, one completed pass an hour
  per cache, lock file while a pass runs) removes build/target directories
  unused for CNUM_JIT_CACHE_DAYS (7), stale *.tmp and the pre-target-directory
  *.o, then the oldest entries over CNUM_JIT_CACHE_MAX_FILES (5000).
- Cache hits refresh an entry's mtime at most hourly.
- A store recreates its target directory if eviction removed it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…de them

evictCache treated every child of the cache root as a build directory and
removed stale ones recursively, so a CNUM_JIT_CACHE_DIR pointing at a shared
directory could lose unrelated files. Now:
- the root gets a .cnum-jit-cache marker when it is new, empty or holds only
  cache entries; eviction runs only on marked, absolute roots other than / and
  $HOME, and CNUM_JIT_CACHE_EVICT=0 turns it off
- only build-id and target-tag directories are entered, only .o/.cubin/.tmp
  files are deleted, and directories are removed only once empty (rmdir)
- the /tmp/cnum-jit-<uid> fallback is created 0700 and must be ours
- thread creation and the pass are exception-safe; the signal mask is always
  restored

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pre-warm (soft) loads removed a cache entry on any failure, including out of
memory or no current context. Now only invalid entries go: object/link/lookup
errors and CUDA_ERROR_INVALID_IMAGE, NO_BINARY_FOR_GPU, INVALID_PTX; the same
for cubin hits in mgpuModuleLoadJIT. Modules loaded before a failing one are
unloaded, and GetFunction/Unload accept a null module. (The generated
constructors only load modules; GetFunction runs at launch.)
- cubin hits refresh the entry's mtime hourly, like .o hits
- pre-warm skips kernels too without the device or 1 GiB free, and kernels
  keep a fifth of the budget when the BLAS part overran
- document that the 1024-entry scan is in directory order

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-shaped roots

Review follow-up to the eviction safety change:
- only <sha256>.o / <sha256>.cubin entries, their cacheTmpName temporaries and
  <sha256>.o.lock claims are ever deleted; build ids must be 16/32/40/64 hex
  digits (or <size>-<mtime>) and target tags the exact targetCacheDir form
- entries of the pre-target layout are aged like other entries, not deleted
  outright; cubin/ is removed once unused for the age limit
- a pre-existing non-empty root is marked only if its whole tree has the cache
  layout (or with CNUM_JIT_CACHE_ADOPT=1); an unmarked root is reported once
- the root is normalized (absolute, no dots or trailing separator), and the
  current build directory is recognized by name, so it is never rmdir'ed
- an own /tmp/cnum-jit-<uid> with group/other bits is chmod'ed 0700
- INVALID_SOURCE and UNSUPPORTED_PTX_VERSION count as invalid entries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@adityapb adityapb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve with nits.

This is a static review. Line numbers are at this PR's head.

These hold up:

  • Count cache invalidation: it is cleared on every write path I traced (set_region, in-place ops, scatter and mask-scatter, and linked and lazy copies).
  • Eviction: it deletes only cache files under marked roots.
  • Pre-warm: it never aborts.
  1. [minor] The disk-cache key covers the host CPU name but not its features.
    • Where: jit.cpp:2397-2398 and :2425.
    • Objects are compiled for the CPU name plus its features. Two node types that share a cache dir under the same CPU name, for example with AVX-512 disabled in the BIOS or a VM, can load an object with unsupported instructions and hit SIGILL.
    • This predates the PR, but the PR restructures the key. Hashing getHostCPUFeatures() as well would close it.
    • Still at #44.
  2. Nit: pre-warmed kernels that are never requested keep their LLJIT and CUmodule until the process exits (jit.cpp:2590, :2698-2735).
  3. Nit: touchCacheEntry (jit.cpp:119-125) uses utimes, which fails silently on another user's files. In a group-shared cache, hot entries can therefore be evicted as stale.

… shared caches

Pre-warmed kernels still unrequested after CNUM_JIT_PRELOAD_TTL_S (default 300 s)
release their LLJIT and CUmodules. When utimes fails on an entry owned by another
user, touchCacheEntry replaces it with a fresh copy so it is not evicted as stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AdvaitTahilyani

Copy link
Copy Markdown
Author
  1. CPU features in the cache key: not changed: another agent fixes it on GPU backend, NumPy-compatible ops, and cuPyNumeric example ports #10.
  2. Pre-warmed kernels never requested: fixed in 4daf01f (unloaded after CNUM_JIT_PRELOAD_TTL_S, default 300 s; their CUmodules are unloaded too).
  3. touchCacheEntry on another user's file: fixed in 4daf01f (when utimes fails, the entry is replaced by a fresh copy we own).

Validated: nc build of this head; CPU regress at +p1: orig 15/15, ports 25/25, ops 24/24, no problems. The unload path is GPU-only and was not run on a GPU.

AdvaitTahilyani and others added 4 commits November 10, 2026 15:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants