Skip to content

Commit

Permalink
Update for StaticArrayInterface and ArrayInterface7
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Mar 13, 2023
1 parent f99a5a7 commit c69b4d1
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StrideArrays"
uuid = "d1fa6d79-ef01-42a6-86c9-f7c551f8593b"
authors = ["Chris Elrod <[email protected]> and contributors"]
version = "0.1.23"
version = "0.1.24"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand All @@ -11,6 +11,7 @@ Octavian = "6fd5a793-0b7e-452c-907f-f8bfe9c57db4"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SLEEFPirates = "476501e8-09a2-5ece-8869-fb82de89a1fa"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
StaticArrayInterface = "0d7ed370-da01-4f52-bd93-41d350b8b718"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"
Expand All @@ -19,11 +20,12 @@ VectorizedRNG = "33b4df10-0173-11e9-2a0c-851a7edac40e"
VectorizedStatistics = "3b853605-1c98-4422-8364-4bd93ee0529e"

[compat]
ArrayInterface = "6"
ArrayInterface = "7"
LoopVectorization = "0.12.131"
Octavian = "0.3"
SLEEFPirates = "0.6.13"
Static = "0.3, 0.4, 0.6, 0.7, 0.8"
StaticArrayInterface = "1"
StaticArraysCore = "1"
StrideArraysCore = "0.4.3"
VectorizationBase = "0.21"
Expand Down
11 changes: 6 additions & 5 deletions src/StrideArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module StrideArrays
# Write your package code here.

using VectorizationBase,
ArrayInterface,
StaticArrayInterface,
SLEEFPirates,
VectorizedRNG,
LoopVectorization,
Expand All @@ -23,16 +23,17 @@ using VectorizationBase:
preserve_buffer
using LoopVectorization: CloseOpen
using Static: StaticInt, Zero, One, StaticBool, True, False, known, static
using ArrayInterface:
size,
strides,
using StaticArrayInterface:
static_size,
static_strides,
offsets,
indices,
static_length,
axes,
static_axes,
dense_dims,
stride_rank,
StrideIndex
const ArrayInterface = StaticArrayInterface
using StrideArraysCore:
AbstractStrideArray,
AbstractStrideMatrix,
Expand Down
4 changes: 2 additions & 2 deletions src/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
A::AbstractStrideMatrix{TA},
B::AbstractStrideMatrix{TB}
) where {TA<:Base.HWReal,TB<:Base.HWReal}
M, KA = size(A)
KB, N = size(B)
M, KA = static_size(A)
KB, N = static_size(B)
@assert KA == KB "Size mismatch."
K = Octavian._select(KA, KB)
TC = promote_type(TA, TB)
Expand Down
2 changes: 1 addition & 1 deletion src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function Base.similar(
bc::Base.Broadcast.Broadcasted{FS},
::Type{T}
) where {S,T,N,FS<:AbstractStrideStyle{S,N}}
StrideArray{T}(undef, to_tuple(S, size(bc)))
StrideArray{T}(undef, to_tuple(S, static_size(bc)))
end
@generated function to_tuple(::Type{S}) where {N,S<:Tuple{Vararg{StaticInt,N}}}
map(StaticInt, known(S))
Expand Down
6 changes: 3 additions & 3 deletions src/kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# @inline _select(_, ::StaticInt{M}) where {M} = StaticInt{M}()
# @inline _select(x, _) = x
# @inline function matmul_sizes(C,A,B)
# MC, NC = size(C)
# MA, KA = size(A)
# KB, NB = size(B)
# MC, NC = static_size(C)
# MA, KA = static_size(A)
# KB, NB = static_size(B)
# @assert ((MC == MA) & (KA == KB) & (NC == NB)) "Size mismatch."
# (_select(MA, MC), _select(KA, KB), _select(NB, NC))
# end
Expand Down
10 changes: 5 additions & 5 deletions src/miscellaneous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ end
end

@inline function Base.vcat(A::AbstractStrideMatrix, B::AbstractStrideMatrix)
MA, NA = size(A)
MB, NB = size(B)
MA, NA = static_size(A)
MB, NB = static_size(B)
@assert NA == NB
TC = promote_type(eltype(A), eltype(B))
C = StrideArray{TC}(undef, (MA + MB, NA))
# TODO: Actually handle offsets
@assert offsets(A) === offsets(B)
@assert offsets(A) === offsets(C)
@turbo for j axes(A, 2), i axes(A, 1)
@turbo for j static_axes(A, 2), i static_axes(A, 1)
C[i, j] = A[i, j]
end
@turbo for j axes(B, 2), i axes(B, 1)
@turbo for j static_axes(B, 2), i static_axes(B, 1)
C[i+MA, j] = B[i, j]
end
C
Expand All @@ -217,7 +217,7 @@ end
@inline function make_stride_dynamic(
p::StridedPointer{T,N,C,B,R}
) where {T,N,C,B,R}
si = StrideIndex{N,R,C}(map(Int, strides(p)), offsets(p))
si = StrideIndex{N,R,C}(map(Int, static_strides(p)), offsets(p))
stridedpointer(pointer(p), si, StaticInt{B}())
end
@inline function make_dynamic(A::PtrArray)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrayInterface = "0d7ed370-da01-4f52-bd93-41d350b8b718"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
26 changes: 10 additions & 16 deletions test/matmul_tests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

# const TRAVIS_SKIP = VERSION.minor != 4 && !isnothing(get(ENV, "TRAVIS_BRANCH", nothing))

function test_fixed_size(A, At, B, Bt, Aa, Aat, Ba, Bat)::NTuple{4,Float64}
t0 = @elapsed(@test Aa * Ba A * B)
t1 = @elapsed(@test Aa * Bat A * Bt)
t2 = @elapsed(@test Aat * Ba At * B)
t3 = @elapsed(@test Aat * Bat At * Bt)
t0, t1, t2, t3
function test_fixed_size(A, At, B, Bt, Aa, Aat, Ba, Bat)
@test Aa * Ba A * B
@test Aa * Bat A * Bt
@test Aat * Ba At * B
@test Aat * Bat At * Bt
nothing
end

function test_fixed_size(M, K, N)
Expand All @@ -18,8 +18,8 @@ function test_fixed_size(M, K, N)
Ba = Array(B)
Aat = Array(At)
Bat = Array(Bt)
t0 = test_fixed_size(A, At, B, Bt, Aa, Aat, Ba, Bat)
t1 = test_fixed_size(
test_fixed_size(A, At, B, Bt, Aa, Aat, Ba, Bat)
test_fixed_size(
StrideArrays.make_dynamic(A),
StrideArrays.make_dynamic(At),
B,
Expand All @@ -29,7 +29,7 @@ function test_fixed_size(M, K, N)
Ba,
Bat
)
t2 = test_fixed_size(
test_fixed_size(
A,
At,
StrideArrays.make_dynamic(B),
Expand All @@ -39,7 +39,7 @@ function test_fixed_size(M, K, N)
Ba,
Bat
)
t3 = test_fixed_size(
test_fixed_size(
StrideArrays.make_dynamic(A),
StrideArrays.make_dynamic(At),
StrideArrays.make_dynamic(B),
Expand All @@ -49,12 +49,6 @@ function test_fixed_size(M, K, N)
Ba,
Bat
)
gflops = let gflop = 2e-9M * K * N
map((t0, t1, t2, t3)) do t
gflop ./ t
end
end
@show (M, K, N), gflops
nothing
end

Expand Down
12 changes: 6 additions & 6 deletions test/misc.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

@noinline function dostuff(A; B = I)
StrideArrays.@avx for i in eachindex(A)
StrideArrays.@turbo for i in eachindex(A)
A[i] += 1
end
C = A * B
s = zero(eltype(C))
StrideArrays.@avx for i in eachindex(C)
StrideArrays.@turbo for i in eachindex(C)
s += C[i]
end
s
Expand All @@ -25,19 +25,19 @@ foo(x, f) = f(x)
@test iszero(@allocated gc_preserve_test())

A = @StrideArray rand($(5 << 1), $(1 << 3))
@test StrideArrays.size(A) === (StaticInt(10), StaticInt(8))
@test StrideArrays.static_size(A) === (StaticInt(10), StaticInt(8))
A_u = view(A, StaticInt(1):StaticInt(6), :)
A_l = view(A, StaticInt(7):StaticInt(10), :)
@test A == @inferred(vcat(A_u, A_l))
@test StrideArrays.size(A) === StrideArrays.size(vcat(A_u, A_l))
@test StrideArrays.static_size(A) === StrideArrays.static_size(vcat(A_u, A_l))

# On 1.5 tests fail if you don't do this first.
@test pointer(view(A, 1:StaticInt(6), :)) == pointer(A)
A_u = view(A, 1:StaticInt(6), :)
A_l = view(A, StaticInt(7):StaticInt(10), :)
@test A == @inferred(vcat(A_u, A_l))
@test StrideArrays.size(A) == StrideArrays.size(vcat(A_u, A_l))
@test StrideArrays.size(A) !== StrideArrays.size(vcat(A_u, A_l))
@test StrideArrays.static_size(A) == StrideArrays.static_size(vcat(A_u, A_l))
@test StrideArrays.static_size(A) !== StrideArrays.static_size(vcat(A_u, A_l))

Aa = Array(A)
@test sum(A) sum(Aa)
Expand Down
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using StrideArrays, LinearAlgebra, Aqua, ArrayInterface
using StrideArrays, LinearAlgebra, Aqua, StaticArrayInterface
using Test
const ArrayInterface = StaticArrayInterface

import InteractiveUtils
InteractiveUtils.versioninfo(stdout; verbose = true)
Expand All @@ -14,7 +15,8 @@ const START_TIME = time()
StrideArrays,
ambiguities = false,
project_toml_formatting = false,
deps_compat = VERSION <= v"1.8" || isempty(VERSION.prerelease)
deps_compat = VERSION <= v"1.8" || isempty(VERSION.prerelease),
piracy = false
)
# Currently, there are five method ambiguities:
# (rand!(A::AbstractStrideArray, args::Vararg{Any, K}) where K in StrideArrays at StrideArrays/src/rand.jl:3, rand!(f::F, rng::VectorizedRNG.AbstractVRNG, x::AbstractArray{T}, α::Number, β, γ) where {T<:Union{Float32, Float64}, F} in VectorizedRNG at VectorizedRNG/L3orR/src/api.jl:242)
Expand Down

2 comments on commit c69b4d1

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

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/79524

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:

git tag -a v0.1.24 -m "<description of version>" c69b4d16f59833c51a3e1e40ae236f6d32fdcd30
git push origin v0.1.24

Please sign in to comment.