Repository navigation
Plan: device memory, copies on other devices, accounting and spilling (#469, #387) - #511
berkgeveci wants to merge 1 commit into
Conversation
…Kitware#469, Kitware#387) Replaces the wiki's device memory plan: spilling becomes dropping a device copy of an array whose host copy is current, the accounting is Kitware#462's made public, and Jeff Lee's review on Kitware#387 is answered decision by decision.
| device if it can address every array, else on the arrays' device. Two memory | ||
| domains raise `ValueError`. `with device:` changes the default, but the arrays | ||
| still win: inside `with tack.device("cpu")`, a kernel given CUDA arrays runs on | ||
| CUDA. Library code relies on this (`on_inputs_device`, and about fifteen `with |
There was a problem hiding this comment.
Main has 24 with device: blocks in tack-dataset, and 86 counting with blocks.device(g): and with piece.device:. D3's conclusion stands, more strongly.
| plan's "a copy into pageable memory waits for the queued work" holds for the | ||
| legacy default stream, not necessarily for Tack's.) | ||
| - Host reads (`numpy()`, `read_range`, `a[i]`) read the host copy, and leave the | ||
| array spilled. Host writes write the host copy and bump the revision, so the |
There was a problem hiding this comment.
This writes through a copy, which D1 rules out ("a write goes to the home buffer"). Say that a spilled array's home is its host copy until it is restored, so D1's rule still holds.
| past it. | ||
|
|
||
| **What is never spilled:** the memory Tack cannot move, and the arrays of the | ||
| operation being prepared (held under D6's lock while it allocates the others). |
There was a problem hiding this comment.
A reentrant lock doesn't stop the thread holding it from spilling. If restoring argument 3 of a launch allocates, it can spill argument 1, whose pointer was already read. The spiller needs to skip the operation's arrays: a pin count on the root, or restoring every argument before any pointer is read.
|
|
||
| ### D8. The budget: Tack's arrays, in bytes or as a fraction | ||
|
|
||
| `tack.set_memory_budget(limit, device=None)` limits what **Tack's arrays** hold |
There was a problem hiding this comment.
What does a budget do on Metal and integrated devices, where spilling is off? Raise, or only report?
| writes through a copy, so there is never more than one buffer to reconcile. | ||
| - **A copy is made on first use and refreshed when stale.** Refreshing copies | ||
| the whole allocation again. Tracking dirty ranges is not worth it yet. | ||
| - **A view reads its root's copy** at its own offset, so views need no table of |
There was a problem hiding this comment.
Copies are per root, so on("cpu") of one AMR box copies the whole level, and a write to any box makes every box's copy stale. That's fine for #451, but worth a line, since D5 cites the AMR level buffers.
| snapshot. Read-only arrays and their checks exist already (`array_from_ptr`'s | ||
| default): a kernel that may store to one raises. | ||
|
|
||
| - `a.on(home)` is `a` itself, as `to_device` returns `a` when its memory is |
There was a problem hiding this comment.
Nit: a.on(home) returns a, which is writable, but D2 says on returns a read-only array. Return a read-only view, or say this case is the exception.
|
Copies are a better model than the wiki's spilling, and the plan covers every point of my #387 review. Its account of today's code matches main, except the count in "What happens today". A few points inline. |
The plan for #469 (copies of an array on other devices) and #387 (accounting and spilling), as
docs/design/plans/device-memory.md. It replaces the wiki's Device memory plan, which #469 changed and which could not take line comments.The model. Each allocation may keep read-only copies on other devices, each stamped with the revision it copied (
DeviceBuffer.version, which Tack already counts). Three things follow:a.on("cpu"), a read-only snapshot of the current copy, andwith tack.run_on("cpu"):, which runs launches on a device that is not the arrays' home, binding copies, including the arrays inside datasets and locators. This is The advection kernel is slower on Metal than on the CPU #451's CPU tail without a second dataset and locator.Decisions D1-D10, each with a recommendation; reply per decision. Of note:
tack.run_on), notwith device:, which about fifteen tack-dataset blocks rely on to let the arrays decide.tack.memory_info).@jlee-kitware, the section "Jeff's review" maps each point of your review on #387 to the decision that answers it.
Docs only:
mkdocs build --strictis clean, and every in-page anchor resolves.This plan will be merged (accepted) after the 0.8 release.
🤖 Generated with Claude Code