Skip to content

Rework KernelInterface into a sibling package - #733

Open
vchuravy wants to merge 5 commits into
mainfrom
vc/kernelinterface-sibling
Open

Rework KernelInterface into a sibling package#733
vchuravy wants to merge 5 commits into
mainfrom
vc/kernelinterface-sibling

Conversation

@vchuravy

Copy link
Copy Markdown
Member

Extracts the KernelInterface submodule (src/interface.jl) into a standalone sibling subpackage under lib/KernelInterface, depended on by KernelAbstractions via a path source.

Motivation

KernelInterface (KI) is the low-level API that backends implement against. Living inside KernelAbstractions, it couldn't be depended on independently and dragged the full KernelAbstractions/GPUCompiler stack along. Making it a lightweight sibling package lets backends target the interface directly.

Changes

  • New lib/KernelInterface/ subpackage with its own Project.toml. It has no non-stdlib dependencies.
  • Dropped the GPUCompiler dependency. The only symbols used were the small macro helpers split_kwargs/assign_args!, now vendored verbatim into the package.
  • Decoupled from KernelAbstractions.Backend. The single interface stub that referenced it (shfl_down_types(::Backend) = DataType[]) now uses an untyped fallback (shfl_down_types(_)), consistent with the neighbouring multiprocessor_count(_) = 0.
  • KernelAbstractions now depends on KernelInterface via [sources] = {path = "lib/KernelInterface"} and keeps re-exporting KernelInterface/KI, so all existing KernelAbstractions.KernelInterface references (POCL backend, tests, examples) work unchanged.

Testing

  • KernelInterface precompiles and loads standalone with zero dependencies.
  • Vendored split_kwargs/assign_args! verified to produce identical output on @kernel-style inputs.

🤖 Generated with Claude Code

Extract the `KernelInterface` submodule (`src/interface.jl`) into a
standalone subpackage under `lib/KernelInterface`, depended on by
KernelAbstractions via a path source. KernelAbstractions keeps
re-exporting `KernelInterface`/`KI` so existing references continue to
work unchanged.

KernelInterface no longer depends on GPUCompiler: the only two symbols
used (`split_kwargs`, `assign_args!`) are small macro helpers, now
vendored, leaving the interface package free of non-stdlib dependencies.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
name = "KernelInterface"
uuid = "4ee993da-d684-4d17-a7dd-4e58e78d92bf"
authors = ["Valentin Churavy <v.churavy@gmail.com> and contributors"]
version = "0.1.0"

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.

Should this match the KA version?

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.20%. Comparing base (65690fd) to head (417316b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #733      +/-   ##
==========================================
- Coverage   64.77%   63.20%   -1.57%     
==========================================
  Files          24       22       -2     
  Lines        2024     1938      -86     
==========================================
- Hits         1311     1225      -86     
  Misses        713      713              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@christiangnrd

Copy link
Copy Markdown
Member

Is the goal for backends to not share the fragile deps with the backend or for end-user packages to only need to depend on KernelInterface?

vchuravy and others added 4 commits July 27, 2026 10:57
Now that `KernelInterface` is a separate package, defining
`KI._print(items...)` in KernelAbstractions is type piracy: neither the
function nor any of the argument types are owned by KernelAbstractions,
and Aqua's piracy check flags it.

Move the generated host fallback next to the `_print` interface stub in
KernelInterface, where it is a normal generic fallback. Backends keep
overriding it with `@device_override _print(args...)`, unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`localmemory(::Type{T}, dims) where {T}` forwards to `localmemory(T, Val(dims))`,
but `dims` is untyped, so the `Val` call matches the same method again. Backends
only supply the `Val` form via `@device_override`, which lives in the overlay
method table, so in a kernel the override terminates the recursion -- but off
device it recurses until the stack overflows and the process segfaults.

This is reachable from the host: `KernelAbstractions.SharedMemory` passes a `Val`
straight to `KI.localmemory`, so `@localmem` used outside a kernel segfaults
rather than erroring.

Add a terminating `Val` method that errors, matching `barrier()`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Tests the sibling package on its own, without KernelAbstractions or a backend,
which also guards the claim that it stays dependency-free.

Covers the vendored `split_kwargs`/`assign_args!` helpers, the host fallbacks
(`barrier`, `shfl_down_types`, `multiprocessor_count`, `localmemory`, `_print`),
`check_launch_args`, and drives `KI.@kernel` end to end against a mock backend,
including its expansion-time error paths. Also asserts that the interface stubs
have no methods, so a backend that forgets one gets a MethodError.

Run in CI by a new `KernelInterface` job.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Adds a KernelInterface manual page covering the device-side API, the host-side
API, and what a backend has to implement, with `@docs` blocks for every
KernelInterface docstring.

Fixes #730.

Co-Authored-By: Claude Opus 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