Skip to content

Order @cuda backend=cuTile stream=s launches with other uses of their arrays - #396

Open
maleadt wants to merge 1 commit into
mainfrom
tb/launch-stream-order
Open

maleadt wants to merge 1 commit into
mainfrom
tb/launch-stream-order

Conversation

@maleadt

@maleadt maleadt commented Dec 3, 2026

Copy link
Copy Markdown
Member

A cuTile launch on a stream other than the task's wasn't ordered with other work on its arrays. With a written by a kernel on the task's stream, @cuda backend=cuTile stream=s copy(b, a) read the old contents of a in every trial; with a copy on a busy s, reading b on the task's stream (Array(b)) returned the old contents too. A CUDA.jl @cuda launch orders both.

Converting an array took its pointer with pointer, which, outside an operation CUDACore submits, takes ownership of the memory for the task's stream and marks it escaped, so CUDACore never synchronizes it with the launch's stream. (Memory last used on a third stream did get ordered, but by blocking the host in the conversion until that stream finished: 350 ms in the test.)

The conversion now does what CUDACore's conversion of a CuArray for its own kernels does: kernel_convert(::TileBackend, x, managed) records the memory of CuArrays and their strided views in managed and computes their address without taking ownership, and CUDACore's launch acquires that memory on the launch's stream. cuTile.launch(...; stream=s) had the same problem and now launches through the same pipeline as @cuda.

Not covered: arrays that a user's Adapt rule converts by calling TileArray(x) directly rather than Adapt.adapt(to, x), and arrays wrapped in something other than a strided view, still take their pointer as before. Tiled broadcast and mapreduce convert their arrays up front and launch on the task's stream; #394 moves them onto this path.

check_capture, which the conversion calls as CUDACore's own does, needs CUDACore 6.5, so this raises the lower bound.

Converting an array for a launch took its pointer with `pointer`, which,
outside an operation that CUDACore submits, takes ownership of the memory
for the task's stream and marks it escaped. A launch on another stream
(`@cuda backend=cuTile stream=s`, or `cuTile.launch` with `stream=s`) was
then not ordered after work on the task's stream that used the array, and
later work on the task's stream was not ordered after the launch: both
read stale data. Only memory last used on a third stream was ordered, by
blocking the host until that stream finished.

Do what CUDACore's conversion of a `CuArray` for its own kernels does:
`kernel_convert(::TileBackend, x, managed)` converts with a
`KernelAdaptor` that records the memory of `CuArray`s and their strided
views in `managed` and computes their address without taking ownership,
and CUDACore's launch acquires that memory on the launch's stream.
`cuTile.launch` now launches through the same pipeline as `@cuda`.
`cuTileconvert` and other arrays take their pointer as before.

CUDACore's `check_capture`, which the conversion uses as CUDACore's own
does, needs CUDACore 6.5.

This branch has not been deployed

No deployments
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.

1 participant