-
Notifications
You must be signed in to change notification settings - Fork 86
Rework KernelInterface into a sibling package #733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vchuravy
wants to merge
5
commits into
main
Choose a base branch
from
vc/kernelinterface-sibling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4ef4772
Rework KernelInterface into a sibling package
vchuravy 3d4260e
Move host `_print` fallback into KernelInterface
vchuravy 908f82c
[KernelInterface] Terminate `localmemory` host fallback
vchuravy 996da41
[KernelInterface] Add a standalone test suite
vchuravy 417316b
[KernelInterface] Document the interface
vchuravy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| [deps] | ||
| Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
| KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" | ||
| KernelInterface = "4ee993da-d684-4d17-a7dd-4e58e78d92bf" | ||
|
|
||
| [compat] | ||
| Documenter = "1" | ||
|
|
||
| [sources] | ||
| KernelAbstractions = {path = ".."} | ||
| KernelInterface = {path = "../lib/KernelInterface"} |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # [KernelInterface](@id kernelinterface) | ||
|
|
||
| ```@meta | ||
| CurrentModule = KernelInterface | ||
| ``` | ||
|
|
||
| `KernelInterface` (conventionally imported as `KI`) is the low-level API that | ||
| backends implement, and that `KernelAbstractions` builds its higher-level kernel | ||
| language on top of. | ||
|
|
||
| It ships as a standalone package under `lib/KernelInterface` with **no | ||
| dependencies outside the standard library**, so a backend can implement the | ||
| interface without taking on `KernelAbstractions` or its compiler stack: | ||
|
|
||
| ```julia | ||
| using KernelInterface | ||
| const KI = KernelInterface | ||
| ``` | ||
|
|
||
| `KernelAbstractions` re-exports it, so `KernelAbstractions.KernelInterface` and | ||
| `KernelAbstractions.KI` refer to the same module. | ||
|
|
||
| !!! note | ||
| Most of the functions below are stubs with no methods. They exist so that | ||
| backends can add device-side implementations with | ||
| `GPUCompiler.@device_override`, and so kernels can call them generically. | ||
| Calling one without a backend that implements it is a `MethodError`. | ||
|
|
||
| ```@docs | ||
| KernelInterface | ||
| ``` | ||
|
|
||
| ## Device-side API | ||
|
|
||
| These are called from inside a kernel. A backend provides each one with | ||
|
|
||
| ```julia | ||
| @device_override KI.get_global_id() = ... | ||
| ``` | ||
|
|
||
| along with the corresponding on-device functionality. | ||
|
|
||
| ### Indexing | ||
|
|
||
| All index queries are **1-based** and return a named tuple of `x`, `y` and `z` | ||
| components. | ||
|
|
||
| ```@docs | ||
| get_global_size | ||
| get_global_id | ||
| get_local_size | ||
| get_local_id | ||
| get_num_groups | ||
| get_group_id | ||
| ``` | ||
|
|
||
| ### Sub-groups | ||
|
|
||
| ```@docs | ||
| get_sub_group_size | ||
| get_max_sub_group_size | ||
| get_num_sub_groups | ||
| get_sub_group_id | ||
| get_sub_group_local_id | ||
| ``` | ||
|
|
||
| ### Barriers | ||
|
|
||
| ```@docs | ||
| barrier | ||
| sub_group_barrier | ||
| ``` | ||
|
|
||
| ### Memory | ||
|
|
||
| ```@docs | ||
| localmemory | ||
| ``` | ||
|
|
||
| ### Communication | ||
|
|
||
| ```@docs | ||
| shfl_down | ||
| shfl_down_types | ||
| ``` | ||
|
|
||
| ### Printing | ||
|
|
||
| ```@docs | ||
| KernelInterface._print | ||
| ``` | ||
|
|
||
| `_print` is the one device-side function with a working host fallback: it prints | ||
| its arguments with `Base.print`, unwrapping any `Val`-wrapped literals. That is | ||
| what makes [`KernelAbstractions.@print`](@ref) usable outside of a kernel. | ||
|
|
||
| ## Host-side API | ||
|
|
||
| ### Backend queries | ||
|
|
||
| ```@docs | ||
| max_work_group_size | ||
| sub_group_size | ||
| multiprocessor_count | ||
| ``` | ||
|
|
||
| ### Compilation and launching | ||
|
|
||
| ```@docs | ||
| Kernel | ||
| kernel_function | ||
| kernel_max_work_group_size | ||
| check_launch_args | ||
| argconvert | ||
| KernelInterface.@kernel | ||
| ``` | ||
|
|
||
| !!! note | ||
| `KI.@kernel` is **not** `KernelAbstractions.@kernel`. `KI.@kernel` wraps a | ||
| backend's own compile-and-launch path — the equivalent of `@cuda` or | ||
| `@metal` — and prefixes a *call*. [`KernelAbstractions.@kernel`](@ref) | ||
| prefixes a *definition* and produces a kernel written in the higher-level | ||
| KernelAbstractions language. | ||
|
|
||
| ## Implementing a backend | ||
|
|
||
| A backend must, at minimum: | ||
|
|
||
| 1. `@device_override` the device-side functions it supports. The indexing | ||
| queries and [`barrier`](@ref) are required; sub-group and | ||
| [`shfl_down`](@ref) support is optional. | ||
| 2. Implement [`argconvert`](@ref) and [`kernel_function`](@ref) for its backend | ||
| type, returning a [`Kernel`](@ref). | ||
| 3. Make that `Kernel` callable, accepting `numworkgroups` and `workgroupsize` as | ||
| a scalar `Integer` or a 1-, 2- or 3-element tuple. Use | ||
| [`check_launch_args`](@ref) to validate them, or check them directly. | ||
| 4. Report its limits through [`kernel_max_work_group_size`](@ref) and, where | ||
| applicable, [`max_work_group_size`](@ref), [`sub_group_size`](@ref) and | ||
| [`multiprocessor_count`](@ref). | ||
|
|
||
| The PoCL backend in `src/pocl/backend.jl` is a complete worked example. | ||
|
|
||
| See also the [notes for backend implementations](@ref implementations_notes). |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name = "KernelInterface" | ||
| uuid = "4ee993da-d684-4d17-a7dd-4e58e78d92bf" | ||
| authors = ["Valentin Churavy <v.churavy@gmail.com> and contributors"] | ||
| version = "0.1.0" | ||
|
|
||
| [compat] | ||
| julia = "1.10" | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [deps] | ||
| Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
| KernelInterface = "4ee993da-d684-4d17-a7dd-4e58e78d92bf" | ||
| Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
|
||
| [compat] | ||
| Aqua = "0.8" |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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?