Skip to content

Commit

Permalink
Improve M1 support (#183)
Browse files Browse the repository at this point in the history
* Improve M1 support

* apple silicon params

* No `strict=true` for `makedocs`
  • Loading branch information
chriselrod committed Sep 17, 2023
1 parent dcc448d commit ade704c
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Octavian"
uuid = "6fd5a793-0b7e-452c-907f-f8bfe9c57db4"
authors = ["Chris Elrod", "Dilum Aluthge", "Mason Protter", "contributors"]
version = "0.3.25"
version = "0.3.26"

[deps]
CPUSummary = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/tilesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function matrix_range(S, ::Type{T} = Float64) where {T}
Cs, As, Bs
end

T = Float64
T = Float32
min_size = round(
Int,
sqrt(
Expand Down
1 change: 0 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ makedocs(;
"Public API" => "public-api.md",
"Internals (Private)" => "internals.md"
],
strict = true
)

deploydocs(; repo = "github.com/JuliaLinearAlgebra/Octavian.jl")
31 changes: 14 additions & 17 deletions ext/ForwardDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ module ForwardDiffExt

using ForwardDiff: ForwardDiff

using Octavian: ArrayInterface,
@turbo, @tturbo,
One, Zero,
indices, static
using Octavian: ArrayInterface, @turbo, @tturbo, One, Zero, indices, static
import Octavian: real_rep, _matmul!, _matmul_serial!

real_rep(a::AbstractArray{DualT}) where {TAG,T,DualT<:ForwardDiff.Dual{TAG,T}} =
Expand Down Expand Up @@ -53,9 +50,9 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
MKN = nothing
) where {TAG,T,DualT<:ForwardDiff.Dual{TAG,T}}
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
A = reinterpret(T, _A)
C = reinterpret(T, _C)
Expand Down Expand Up @@ -94,9 +91,9 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
C = real_rep(_C)
B = real_rep(_B)
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
Ar = reinterpret(T, _A)
Cr = reinterpret(T, _C)
Expand Down Expand Up @@ -151,7 +148,7 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
_C
end

# multiplication of dual matrix by standard vector/matrix from the right
# multiplication of dual matrix by standard vector/matrix from the right
@eval @inline function _matmul_serial!(
_C::$(AbstractVectorOrMatrix){DualT},
_A::AbstractMatrix{DualT},
Expand All @@ -161,9 +158,9 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
MKN
) where {TAG,T,DualT<:ForwardDiff.Dual{TAG,T}}
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
A = reinterpret(T, _A)
C = reinterpret(T, _C)
Expand Down Expand Up @@ -200,9 +197,9 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
C = real_rep(_C)
B = real_rep(_B)
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
Ar = reinterpret(T, _A)
Cr = reinterpret(T, _C)
Expand Down
39 changes: 18 additions & 21 deletions ext/HyperDualNumbersExt.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
module HyperDualNumbersExt

using HyperDualNumbers: Hyper
using Octavian: ArrayInterface,
@turbo, @tturbo,
One, Zero,
indices, static
using Octavian: ArrayInterface, @turbo, @tturbo, One, Zero, indices, static
import Octavian: real_rep, _matmul!, _matmul_serial!

real_rep(a::AbstractArray{DualT}) where {T,DualT<:Hyper{T}} =
Expand All @@ -23,7 +20,7 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
nthread::Nothing = nothing,
MKN = nothing,
contig_axis = nothing
) where {T, DualT<:Hyper{T}}
) where {T,DualT<:Hyper{T}}
B = real_rep(_B)
C = real_rep(_C)

Expand Down Expand Up @@ -52,9 +49,9 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
MKN = nothing
) where {T,DualT<:Hyper{T}}
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
A = reinterpret(T, _A)
C = reinterpret(T, _C)
Expand Down Expand Up @@ -93,9 +90,9 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
C = real_rep(_C)
B = real_rep(_B)
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
Ar = reinterpret(T, _A)
Cr = reinterpret(T, _C)
Expand Down Expand Up @@ -139,7 +136,7 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
α,
β,
MKN
) where {T, DualT<:Hyper{T}}
) where {T,DualT<:Hyper{T}}
B = real_rep(_B)
C = real_rep(_C)

Expand All @@ -157,7 +154,7 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
_C
end

# multiplication of dual matrix by standard vector/matrix from the right
# multiplication of dual matrix by standard vector/matrix from the right
@eval @inline function _matmul_serial!(
_C::$(AbstractVectorOrMatrix){DualT},
_A::AbstractMatrix{DualT},
Expand All @@ -167,9 +164,9 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
MKN
) where {T,DualT<:Hyper{T}}
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
A = reinterpret(T, _A)
C = reinterpret(T, _C)
Expand Down Expand Up @@ -201,14 +198,14 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
α,
β,
MKN
) where {T, DualT<:Hyper{T}}
) where {T,DualT<:Hyper{T}}
A = real_rep(_A)
C = real_rep(_C)
B = real_rep(_B)
if Bool(ArrayInterface.is_dense(_C)) &&
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
Bool(ArrayInterface.is_column_major(_C)) &&
Bool(ArrayInterface.is_dense(_A)) &&
Bool(ArrayInterface.is_column_major(_A))
# we can avoid the reshape and call the standard method
Ar = reinterpret(T, _A)
Cr = reinterpret(T, _C)
Expand Down Expand Up @@ -246,4 +243,4 @@ for AbstractVectorOrMatrix in (:AbstractVector, :AbstractMatrix)
end
end # for

end # module
end # module
1 change: 0 additions & 1 deletion src/Octavian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ if !isdefined(Base, :get_extension)
include("../ext/HyperDualNumbersExt.jl")
end


end # module Octavian
24 changes: 18 additions & 6 deletions src/global_constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ MᵣW_mul_factor(::True) = StaticInt{4}()
MᵣW_mul_factor(::False) = StaticInt{9}()
MᵣW_mul_factor() = MᵣW_mul_factor(has_feature(Val(:x86_64_avx512f)))


if Sys.ARCH === :aarch64 && (Sys.isapple() || occursin("apple", Sys.CPU_NAME::String))
W₁Default() = StaticFloat64{0.23015506935919203}()
W₂Default() = StaticFloat64{0.16967706087713014}()
R₁Default() = StaticFloat64{0.9982516031563079}()
R₂Default() = StaticFloat64{0.5167030291302886}()
else
W₁Default(::True) = StaticFloat64{0.0007423708195588264}()
W₂Default(::True) = StaticFloat64{0.7757548987718677}()
R₁Default(::True) = StaticFloat64{0.7936663315339363}()
Expand Down Expand Up @@ -50,13 +57,14 @@ W₁Default() = W₁Default(has_feature(Val(:x86_64_avx512f)))
W₂Default() = W₂Default(has_feature(Val(:x86_64_avx512f)))
R₁Default() = R₁Default(has_feature(Val(:x86_64_avx512f)))
R₂Default() = R₂Default(has_feature(Val(:x86_64_avx512f)))

@static if Sys.ARCH === :x86_64 || Sys.ARCH === :i686
first_cache() = StaticInt{2}()
else
first_cache() = StaticInt{1}()
end

# @static if Sys.ARCH === :x86_64 || Sys.ARCH === :i686
first_cache() = StaticInt{2}()
# else
# first_cache() = StaticInt{1}()
# end

second_cache() = first_cache() + One()

_first_cache_size(fcs::StaticInt) = ifelse(
Expand All @@ -69,7 +77,11 @@ first_cache_size() = _first_cache_size(cache_size(first_cache()))

_second_cache_size(scs::StaticInt, ::True) = scs - cache_size(first_cache())
_second_cache_size(scs::StaticInt, ::False) = scs
_second_cache_size(::StaticInt{0}, ::Nothing) = StaticInt(3145728)
@static if (Sys.isapple() || occursin("apple", Sys.CPU_NAME::String)) && Sys.ARCH === :aarch64
_second_cache_size(::StaticInt{0}, ::False) = StaticInt(100663296)
else
_second_cache_size(::StaticInt{0}, ::False) = StaticInt(3145728)
end
function second_cache_size()
sc = second_cache()
_second_cache_size(cache_size(sc), cache_inclusive(sc))
Expand Down
12 changes: 5 additions & 7 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ function __init__()
end

function init_bcache()
BCACHEPTR[] == C_NULL || return
c = Threads.nthreads() * second_cache_size()
if bcache_count() Zero()
if BCACHEPTR[] == C_NULL
BCACHEPTR[] = VectorizationBase.valloc(
Threads.nthreads() * second_cache_size() * bcache_count(),
Cvoid,
ccall(:jl_getpagesize, Int, ())
)
end
c *= bcache_count()
end
BCACHEPTR[] =
VectorizationBase.valloc(c, Cvoid, ccall(:jl_getpagesize, Int, ()))
nothing
end

Expand Down
8 changes: 6 additions & 2 deletions test/aqua.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@testset "Aqua.jl" begin
Aqua.test_all(Octavian; ambiguities = false, project_toml_formatting = false,
stale_deps = (; ignore = [:ForwardDiff]))
Aqua.test_all(
Octavian;
ambiguities = false,
project_toml_formatting = false,
stale_deps = (; ignore = [:ForwardDiff])
)
@test isempty(Test.detect_ambiguities(Octavian))
end
21 changes: 14 additions & 7 deletions test/hyperduals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
@testset "real array from the right" begin
A1dual = randdual(A1)
C1dual = randdual(C1)

A2dual = deepcopy(A1dual)
B2 = deepcopy(B1)
C2dual = deepcopy(C1dual)
Expand All @@ -49,7 +49,6 @@ end
@test reinterpret(Float64, C1dual) reinterpret(Float64, C2dual)
end


@testset "transposed arrays" begin
A1dual = randdual(A1')
C1dual = randdual(C1)
Expand All @@ -67,13 +66,21 @@ end

Cref = zeros(Float64, size(C1)...)
LinearAlgebra.mul!(Cref, A1, B1)
@test (reinterpretHD(Float64, C1dual) reinterpretHD(Float64, C2dual)
reinterpretHD(Float64, C3dual) reinterpretHD(Float64, C4dual) Cref) &&
(reinterpret(Float64, C1dual) reinterpret(Float64, C2dual)
reinterpret(Float64, C3dual) reinterpret(Float64, C4dual) )
@test (
reinterpretHD(Float64, C1dual)
reinterpretHD(Float64, C2dual)
reinterpretHD(Float64, C3dual)
reinterpretHD(Float64, C4dual)
Cref
) && (
reinterpret(Float64, C1dual)
reinterpret(Float64, C2dual)
reinterpret(Float64, C3dual)
reinterpret(Float64, C4dual)
)
end

@testset "two dual arrays" begin
@testset "two dual arrays" begin
A1d = randdual(A1)
B1d = randdual(B1)
@test reinterpret(Float64, Octavian.matmul(A1d, B1d, 1.3))
Expand Down

2 comments on commit ade704c

@chriselrod
Copy link
Collaborator 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/91556

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.3.26 -m "<description of version>" ade704cfa5d028ad9e8fbfb864138904350b4674
git push origin v0.3.26

Please sign in to comment.