-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to KernelAbstractions.jl (#559)
Co-authored-by: James Schloss <[email protected]>
- Loading branch information
Showing
29 changed files
with
289 additions
and
691 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,53 +1,32 @@ | ||
# Interface | ||
|
||
To extend the above functionality to a new array type, you should use the types and | ||
implement the interfaces listed on this page. GPUArrays is design around having two | ||
different array types to represent a GPU array: one that only ever lives on the host, and | ||
implement the interfaces listed on this page. GPUArrays is designed around having two | ||
different array types to represent a GPU array: one that exists only on the host, and | ||
one that actually can be instantiated on the device (i.e. in kernels). | ||
Device functionality is then handled by [KernelAbstractions.jl](https://github.com/JuliaGPU/KernelAbstractions.jl). | ||
|
||
## Host abstractions | ||
|
||
## Device functionality | ||
|
||
Several types and interfaces are related to the device and execution of code on it. First of | ||
all, you need to provide a type that represents your execution back-end and a way to call | ||
kernels: | ||
You should provide an array type that builds on the `AbstractGPUArray` supertype, such as: | ||
|
||
```@docs | ||
GPUArrays.AbstractGPUBackend | ||
GPUArrays.AbstractKernelContext | ||
GPUArrays.gpu_call | ||
GPUArrays.thread_block_heuristic | ||
``` | ||
mutable struct CustomArray{T, N} <: AbstractGPUArray{T, N} | ||
data::DataRef{Vector{UInt8}} | ||
offset::Int | ||
dims::Dims{N} | ||
... | ||
end | ||
You then need to provide implementations of certain methods that will be executed on the | ||
device itself: | ||
|
||
```@docs | ||
GPUArrays.AbstractDeviceArray | ||
GPUArrays.LocalMemory | ||
GPUArrays.synchronize_threads | ||
GPUArrays.blockidx | ||
GPUArrays.blockdim | ||
GPUArrays.threadidx | ||
GPUArrays.griddim | ||
``` | ||
|
||
This will allow your defined type (in this case `JLArray`) to use the GPUArrays interface where available. | ||
To be able to actually use the functionality that is defined for `AbstractGPUArray`s, you need to define the backend, like so: | ||
|
||
## Host abstractions | ||
|
||
You should provide an array type that builds on the `AbstractGPUArray` supertype: | ||
|
||
```@docs | ||
AbstractGPUArray | ||
``` | ||
|
||
First of all, you should implement operations that are expected to be defined for any | ||
`AbstractArray` type. Refer to the Julia manual for more details, or look at the `JLArray` | ||
reference implementation. | ||
|
||
To be able to actually use the functionality that is defined for `AbstractGPUArray`s, you | ||
should provide implementations of the following interfaces: | ||
|
||
```@docs | ||
GPUArrays.backend | ||
import KernelAbstractions: Backend | ||
struct CustomBackend <: KernelAbstractions.GPU | ||
KernelAbstractions.get_backend(a::CA) where CA <: CustomArray = CustomBackend() | ||
``` | ||
|
||
There are numerous examples of potential interfaces for GPUArrays, such as with [JLArrays](https://github.com/JuliaGPU/GPUArrays.jl/blob/master/lib/JLArrays/src/JLArrays.jl), [CuArrays](https://github.com/JuliaGPU/CUDA.jl/blob/master/src/gpuarrays.jl), and [ROCArrays](https://github.com/JuliaGPU/AMDGPU.jl/blob/master/src/gpuarrays.jl). |
This file contains 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,7 +1,7 @@ | ||
name = "GPUArraysCore" | ||
uuid = "46192b85-c4d5-4398-a991-12ede77f4527" | ||
authors = ["Tim Besard <[email protected]>"] | ||
version = "0.1.6" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
This file contains 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 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 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
Oops, something went wrong.
2769d6b
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.
@JuliaRegistrator register subdir="lib/GPUArraysCore"
2769d6b
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.
Registration pull request created: JuliaRegistries/General/117484
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
2769d6b
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.
@JuliaRegistrator register
2769d6b
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.
Registration pull request created: JuliaRegistries/General/117486
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: