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

Defer BroadcastStyle construction to back-ends. #506

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ['1.8', '1.9', '1.10.0-beta2', 'nightly']
version: ['1.8', '1.9', '1.10.0-rc2', 'nightly']
os: [ubuntu-latest, macOS-latest, windows-latest]
arch: [x64]
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
Expand All @@ -33,13 +33,17 @@ jobs:
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@latest
- run: |
git config --global user.name Tester
git config --global user.email [email protected]
- uses: julia-actions/julia-runtest@latest
- name: Develop subpackages
run: |
julia --project -e "
using Pkg
Pkg.develop([PackageSpec(; name=basename(path), path) for path in ARGS])
" lib/GPUArraysCore lib/JLArrays
- uses: julia-actions/julia-runtest@v1
continue-on-error: ${{ matrix.version == 'nightly' }}
- uses: julia-actions/julia-processcoverage@v1
with:
directories: src,lib
- uses: codecov/codecov-action@v3
with:
file: lcov.info
Expand All @@ -48,11 +52,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
- uses: julia-actions/setup-julia@v1
with:
version: '1.8'
- name: Develop packages
run: |
julia -e "
using Pkg
Pkg.develop([PackageSpec(; name=basename(splitext(path)[1]), path) for path in ARGS])
" ../GPUArrays.jl lib/GPUArraysCore
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GPUArrays"
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
version = "9.1.0"
version = "10.0.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -14,8 +14,8 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
Adapt = "2.0, 3.0"
GPUArraysCore = "= 0.1.5"
Adapt = "4.0"
GPUArraysCore = "= 0.1.6"
LLVM = "3.9, 4, 5, 6"
LinearAlgebra = "1"
Printf = "1"
Expand Down
4 changes: 2 additions & 2 deletions lib/GPUArraysCore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name = "GPUArraysCore"
uuid = "46192b85-c4d5-4398-a991-12ede77f4527"
authors = ["Tim Besard <[email protected]>"]
version = "0.1.5"
version = "0.1.6"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

[compat]
Adapt = "2.0, 3.0"
Adapt = "4.0"
julia = "1.6"
5 changes: 3 additions & 2 deletions lib/GPUArraysCore/src/GPUArraysCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,15 @@ end
## other

"""
backend(T::Type)
backend(x)
backend(T::Type)

Gets the GPUArrays back-end responsible for managing arrays of type `T`.
"""
backend(::Type) = error("This object is not a GPU array") # COV_EXCL_LINE
backend(x) = backend(typeof(x))

backend(::Type{WA}) where WA<:WrappedArray = backend(parent(WA)) # WrappedArray from Adapt for Base wrappers.
# WrappedArray from Adapt for Base wrappers.
backend(::Type{WA}) where WA<:WrappedArray = backend(unwrap_type(WA))

end # module GPUArraysCore
6 changes: 3 additions & 3 deletions lib/JLArrays/Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name = "JLArrays"
uuid = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
authors = ["Tim Besard <[email protected]>"]
version = "0.1.2"
version = "0.1.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
Adapt = "2.0, 3.0"
GPUArrays = "9"
Adapt = "2.0, 3.0, 4.0"
GPUArrays = "10"
julia = "1.8"
Random = "1"
13 changes: 6 additions & 7 deletions lib/JLArrays/src/JLArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,15 @@ Base.convert(::Type{T}, x::T) where T <: JLArray = x
using Base.Broadcast: BroadcastStyle, Broadcasted

struct JLArrayStyle{N} <: AbstractGPUArrayStyle{N} end
JLArrayStyle(::Val{N}) where N = JLArrayStyle{N}()
JLArrayStyle{M}(::Val{N}) where {N,M} = JLArrayStyle{N}()

BroadcastStyle(::Type{JLArray{T,N}}) where {T,N} = JLArrayStyle{N}()
# identify the broadcast style of a (wrapped) array
BroadcastStyle(::Type{<:JLArray{T,N}}) where {T,N} = JLArrayStyle{N}()
BroadcastStyle(::Type{<:AnyJLArray{T,N}}) where {T,N} = JLArrayStyle{N}()

# Allocating the output container
Base.similar(bc::Broadcasted{JLArrayStyle{N}}, ::Type{T}) where {N,T} =
similar(JLArray{T}, axes(bc))
Base.similar(bc::Broadcasted{JLArrayStyle{N}}, ::Type{T}, dims) where {N,T} =
JLArray{T}(undef, dims)
# allocation of output arrays
Base.similar(bc::Broadcasted{JLArrayStyle{N}}, ::Type{T}, dims) where {T,N} =
similar(JLArray{T}, dims)


## memory operations
Expand Down
5 changes: 0 additions & 5 deletions src/host/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle, instanti
const BroadcastGPUArray{T} = Union{AnyGPUArray{T},
Base.RefValue{<:AbstractGPUArray{T}}}

# Wrapper types otherwise forget that they are GPU compatible
# NOTE: don't directly use GPUArrayStyle here not to lose downstream customizations.
BroadcastStyle(W::Type{<:WrappedGPUArray})= BroadcastStyle(Adapt.parent(W){Adapt.eltype(W), Adapt.ndims(W)})
backend(W::Type{<:WrappedGPUArray}) = backend(Adapt.parent(W){Adapt.eltype(W), Adapt.ndims(W)})

# Ref is special: it's not a real wrapper, so not part of Adapt,
# but it is commonly used to bypass broadcasting of an argument
# so we need to preserve its dimensionless properties.
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
7 changes: 0 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ using GPUArrays, Test, Pkg
include("testsuite.jl")

@testset "JLArray" begin
# install the JLArrays subpackage in a temporary environment
old_project = Base.active_project()
Pkg.activate(; temp=true)
Pkg.develop(path=joinpath(dirname(@__DIR__), "lib", "JLArrays"))

using JLArrays

jl([1])

TestSuite.test(JLArray)

Pkg.activate(old_project)
end

@testset "Array" begin
Expand Down
Loading