Module op_cache

Module op_cache 

Source
Expand description

OpCache — per-backend kernel handles and scratch buffers.

Kernel-launching ops memoize two things: the KernelHandle they resolve from the module registry, and any device scratch they grow on demand. Both were being cached in function-local static OnceLock / static Mutex, and both are owned by the model:

  • A KernelHandle is a raw CUfunction from an AtlasRegistry module. The registry unloads its modules on drop, so a handle cached in a static outlives the module it points into — a launch after a swap is a use-after-unload, not a stale value.
  • A scratch DevicePtr is an allocation in the model’s context. Cached in a static, the next model writes its activations through a pointer that was freed with the previous one.

Neither fails loudly. Both are the kind of defect that surfaces as corrupted output or an illegal address in an unrelated kernel.

An OpCache lives on the backend, so its lifetime is exactly the model’s: when the backend drops, the handles go with the registry that owns them and the scratch goes with the context that allocated it.

Structs§

OpCache
Memoized kernel handles and scratch allocations for one backend.