Skip to content
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

Backends are adaptors #364

Merged
merged 10 commits into from
Mar 9, 2023
6 changes: 2 additions & 4 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ steps:
- "1.6"
- "1.7"
- "1.8"
cuda:
- "vc/ka_transition"
env:
KERNELABSTRACTIONS_TEST_BACKEND: "CUDA"
plugins:
Expand All @@ -19,10 +17,10 @@ steps:
- src
commands:
- |
julia -e 'using Pkg
julia --project=test/projects/cuda -e 'using Pkg
println("--- :julia: Instantiating project")
Pkg.instantiate()
Pkg.develop(; path=pwd())
Pkg.add(; name="CUDA", rev="{{matrix.cuda}}")
println("+++ :julia: Running tests")
Pkg.test("CUDA"; coverage=true, test_args=["kernelabstractions"])'
agents:
Expand Down
5 changes: 5 additions & 0 deletions src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ get_backend(A::Tridiagonal) = get_backend(A.d)

get_backend(::Array) = CPU()

# Define:
# adapt_storage(::Backend, a::Array) = adapt(BackendArray, a)
# adapt_storage(::Backend, a::BackendArray) = a
Adapt.adapt_storage(::CPU, a::Array) = a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the instance and not the type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the ::Type{CPU}< I thought we defined adaptors over the instance. The user might not have the backend type around, but they should always have an instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, for CuArray we do adapt(CuArray, obj), i.e., specifying the type because that's likely the only thing you have at that point. If users don't explicitly mention the backend types I guess it would be fine to use the instance here.


"""
allocate(::Backend, Type, dims...)

Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
Loading