Rework KernelInterface into a sibling package - #733
Open
vchuravy wants to merge 5 commits into
Open
Conversation
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" |
Member
There was a problem hiding this comment.
Should this match the KA version?
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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? |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracts the
KernelInterfacesubmodule (src/interface.jl) into a standalone sibling subpackage underlib/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
lib/KernelInterface/subpackage with its ownProject.toml. It has no non-stdlib dependencies.split_kwargs/assign_args!, now vendored verbatim into the package.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 neighbouringmultiprocessor_count(_) = 0.KernelInterfacevia[sources] = {path = "lib/KernelInterface"}and keeps re-exportingKernelInterface/KI, so all existingKernelAbstractions.KernelInterfacereferences (POCL backend, tests, examples) work unchanged.Testing
KernelInterfaceprecompiles and loads standalone with zero dependencies.split_kwargs/assign_args!verified to produce identical output on@kernel-style inputs.🤖 Generated with Claude Code