Skip to content

Cluster Launch Control: hardware work-stealing exists in cuda-oxide and pipeline::run schedules statically #88

Closed

Description

@feitreim

pipeline::run schedules statically: item = cluster_idx(), then
item += num_clusters(). Every cluster takes a fixed share, decided before the
kernel starts. cuda-oxide already exposes Blackwell's hardware alternative and
nothing here references it.

cuda_device::clc — Cluster Launch Control:

  • clc_try_cancel(response, mbar) and clc_try_cancel_multicast (the
    cluster form, which is the one this repo's 2-CTA kernels need)
  • clc_query_is_canceled, clc_query_get_first_ctaid_{x,y,z}

Its own module doc: "CLC replaces software atomic counters for persistent
kernel tile scheduling. Instead of a fixed number of persistent CTAs competing
on a global counter, CLC uses hardware-managed work-stealing: launch a full grid
(one CTA per tile), and running CTAs call try_cancel to steal not-yet-launched
tiles."
The response is a 16-byte value delivered through an mbarrier,
which is sync::Semaphore — the machinery is already here.

cuda_device::atomic also has fetch_add / compare_exchange, so a software
counter is available as a fallback and as a control to measure CLC against.

What it is worth, quantified before anyone builds it

The static stride's loss is the ragged last wave. At MAX_CLUSTERS = 222 with
[256, 128] tiles:

shape tiles waves wave efficiency
2048³ 128 1 57.7%
4096³ 512 3 76.9%
8192³ 2048 10 92.3%
16384³ 8192 37 99.7%

So the ceiling on this is about 8% at 8192³, 23% at 4096³, and nothing at
16384³.
State that plainly up front, because it cuts against the headline
ambition: at the sizes that will define a peak-throughput claim the static
stride is already 99.7% efficient. CLC is a fix for mid-sized problems and
ragged tails, not a route to peak.
It is worth doing anyway for the second
reason below, but a measurement showing ~0 at 16384³ is a success, not a
failure, and should not be tuned against.

The other reason, which may matter more

It deletes the tuning constants. #83 had to hand-pick SMS = 148 and
CTAS_PER_SM = 3, and its own doc concedes a device with a different SM count
computes the same GEMM off a wave that is not quite a wave. #84 then showed
CTAS_PER_SM is a measured property that no query in the table reports, so it
cannot be derived at compile time and cannot be right on unseen hardware. Under
CLC the hardware decides and both constants go away.

That also makes the persistent scaffold portable rather than B200-shaped, which
is the difference between an example and a library feature.

Scope

  • A CLC-backed item source for pipeline::run, sitting behind the same Job
    interface so gemm.rs does not care which scheduler it got. The existing
    static stride stays as the fallback and as the control to measure against —
    this is one of the few places keeping two paths is justified, and only until
    the comparison is done.
  • Use clc_try_cancel_multicast for cluster jobs. A 2-CTA cluster stealing per
    CTA would split a pair across two output tiles, which is pipeline::run cannot schedule a cluster: work items are blockIdx.x-strided #51's bug again.
  • The response arrives on an mbarrier, so the steal can be prefetched — issue
    the try_cancel for the next item while the current one's MMA is still
    running, and the latency hides. A steal on the critical path would be a
    regression; say which one was measured.
  • Tile coordinates come back as grid coordinates, so an L2-aware traversal
    composes with this rather than conflicting — see the traversal issue.

Acceptance

gemm exact at every size, and a before/after against the static stride at
2048³, 4096³, 8192³ and 16384³ — the sizes are the point, since the predicted
gain varies from 23% to nothing across them. Report the ragged-wave prediction
beside the measurement.

Related: #83 (the constants and the static stride), #84 (why CTAS_PER_SM
cannot be derived), #86 (the bound), #51.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:scaffolding

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions