Skip to content

Commit b2c6998

Browse files
authored
Defer BroadcastStyle construction to back-ends. (#506)
1 parent effeef9 commit b2c6998

File tree

9 files changed

+37
-38
lines changed

9 files changed

+37
-38
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
version: ['1.8', '1.9', '1.10.0-beta2', 'nightly']
17+
version: ['1.8', '1.9', '1.10.0-rc2', 'nightly']
1818
os: [ubuntu-latest, macOS-latest, windows-latest]
1919
arch: [x64]
2020
steps:
2121
- uses: actions/checkout@v4
22-
- uses: julia-actions/setup-julia@latest
22+
- uses: julia-actions/setup-julia@v1
2323
with:
2424
version: ${{ matrix.version }}
2525
arch: ${{ matrix.arch }}
@@ -33,13 +33,17 @@ jobs:
3333
${{ runner.os }}-test-${{ env.cache-name }}-
3434
${{ runner.os }}-test-
3535
${{ runner.os }}-
36-
- uses: julia-actions/julia-buildpkg@latest
37-
- run: |
38-
git config --global user.name Tester
39-
git config --global user.email [email protected]
40-
- uses: julia-actions/julia-runtest@latest
36+
- name: Develop subpackages
37+
run: |
38+
julia --project -e "
39+
using Pkg
40+
Pkg.develop([PackageSpec(; name=basename(path), path) for path in ARGS])
41+
" lib/GPUArraysCore lib/JLArrays
42+
- uses: julia-actions/julia-runtest@v1
4143
continue-on-error: ${{ matrix.version == 'nightly' }}
4244
- uses: julia-actions/julia-processcoverage@v1
45+
with:
46+
directories: src,lib
4347
- uses: codecov/codecov-action@v3
4448
with:
4549
file: lcov.info
@@ -48,11 +52,17 @@ jobs:
4852
runs-on: ubuntu-latest
4953
steps:
5054
- uses: actions/checkout@v4
51-
- uses: julia-actions/setup-julia@latest
55+
- uses: julia-actions/setup-julia@v1
5256
with:
5357
version: '1.8'
58+
- name: Develop packages
59+
run: |
60+
julia -e "
61+
using Pkg
62+
Pkg.develop([PackageSpec(; name=basename(splitext(path)[1]), path) for path in ARGS])
63+
" ../GPUArrays.jl lib/GPUArraysCore
5464
- name: Install dependencies
55-
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
65+
run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate()'
5666
- name: Build and deploy
5767
env:
5868
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GPUArrays"
22
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
3-
version = "9.1.0"
3+
version = "10.0.0"
44

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

1616
[compat]
17-
Adapt = "2.0, 3.0"
18-
GPUArraysCore = "= 0.1.5"
17+
Adapt = "4.0"
18+
GPUArraysCore = "= 0.1.6"
1919
LLVM = "3.9, 4, 5, 6"
2020
LinearAlgebra = "1"
2121
Printf = "1"

lib/GPUArraysCore/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name = "GPUArraysCore"
22
uuid = "46192b85-c4d5-4398-a991-12ede77f4527"
33
authors = ["Tim Besard <[email protected]>"]
4-
version = "0.1.5"
4+
version = "0.1.6"
55

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

99
[compat]
10-
Adapt = "2.0, 3.0"
10+
Adapt = "4.0"
1111
julia = "1.6"

lib/GPUArraysCore/src/GPUArraysCore.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ end
217217
## other
218218

219219
"""
220-
backend(T::Type)
221220
backend(x)
221+
backend(T::Type)
222222
223223
Gets the GPUArrays back-end responsible for managing arrays of type `T`.
224224
"""
225225
backend(::Type) = error("This object is not a GPU array") # COV_EXCL_LINE
226226
backend(x) = backend(typeof(x))
227227

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

230231
end # module GPUArraysCore

lib/JLArrays/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name = "JLArrays"
22
uuid = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
33
authors = ["Tim Besard <[email protected]>"]
4-
version = "0.1.2"
4+
version = "0.1.3"
55

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

1111
[compat]
12-
Adapt = "2.0, 3.0"
13-
GPUArrays = "9"
12+
Adapt = "2.0, 3.0, 4.0"
13+
GPUArrays = "10"
1414
julia = "1.8"
1515
Random = "1"

lib/JLArrays/src/JLArrays.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,15 @@ Base.convert(::Type{T}, x::T) where T <: JLArray = x
311311
using Base.Broadcast: BroadcastStyle, Broadcasted
312312

313313
struct JLArrayStyle{N} <: AbstractGPUArrayStyle{N} end
314-
JLArrayStyle(::Val{N}) where N = JLArrayStyle{N}()
315314
JLArrayStyle{M}(::Val{N}) where {N,M} = JLArrayStyle{N}()
316315

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

319-
# Allocating the output container
320-
Base.similar(bc::Broadcasted{JLArrayStyle{N}}, ::Type{T}) where {N,T} =
321-
similar(JLArray{T}, axes(bc))
322-
Base.similar(bc::Broadcasted{JLArrayStyle{N}}, ::Type{T}, dims) where {N,T} =
323-
JLArray{T}(undef, dims)
320+
# allocation of output arrays
321+
Base.similar(bc::Broadcasted{JLArrayStyle{N}}, ::Type{T}, dims) where {T,N} =
322+
similar(JLArray{T}, dims)
324323

325324

326325
## memory operations

src/host/broadcast.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle, instanti
77
const BroadcastGPUArray{T} = Union{AnyGPUArray{T},
88
Base.RefValue{<:AbstractGPUArray{T}}}
99

10-
# Wrapper types otherwise forget that they are GPU compatible
11-
# NOTE: don't directly use GPUArrayStyle here not to lose downstream customizations.
12-
BroadcastStyle(W::Type{<:WrappedGPUArray})= BroadcastStyle(Adapt.parent(W){Adapt.eltype(W), Adapt.ndims(W)})
13-
backend(W::Type{<:WrappedGPUArray}) = backend(Adapt.parent(W){Adapt.eltype(W), Adapt.ndims(W)})
14-
1510
# Ref is special: it's not a real wrapper, so not part of Adapt,
1611
# but it is commonly used to bypass broadcasting of an argument
1712
# so we need to preserve its dimensionless properties.

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
3+
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
34
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
45
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
56
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

test/runtests.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ using GPUArrays, Test, Pkg
33
include("testsuite.jl")
44

55
@testset "JLArray" begin
6-
# install the JLArrays subpackage in a temporary environment
7-
old_project = Base.active_project()
8-
Pkg.activate(; temp=true)
9-
Pkg.develop(path=joinpath(dirname(@__DIR__), "lib", "JLArrays"))
10-
116
using JLArrays
127

138
jl([1])
149

1510
TestSuite.test(JLArray)
16-
17-
Pkg.activate(old_project)
1811
end
1912

2013
@testset "Array" begin

0 commit comments

Comments
 (0)