SciML / LinearSolve.jl

LinearSolve.jl: High-Performance Unified Interface for Linear Solvers in Julia. Easily switch between factorization and Krylov methods, add preconditioners, and all in one interface.
https://docs.sciml.ai/LinearSolve/stable/
Other
244 stars 52 forks source link

Setup 64-bit AppleAccelerate 64-bit version #358

Closed ChrisRackauckas closed 1 year ago

ChrisRackauckas commented 1 year ago

It may not be very useful though. Test script:

using BenchmarkTools, Random, VectorizationBase
using LinearAlgebra, LinearSolve
nc = min(Int(VectorizationBase.num_cores()), Threads.nthreads())
BLAS.set_num_threads(nc)
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 0.5

function luflop(m, n = m; innerflop = 2)
    sum(1:min(m, n)) do k
        invflop = 1
        scaleflop = isempty((k + 1):m) ? 0 : sum((k + 1):m)
        updateflop = isempty((k + 1):n) ? 0 :
                     sum((k + 1):n) do j
            isempty((k + 1):m) ? 0 : sum((k + 1):m) do i
                innerflop
            end
        end
        invflop + scaleflop + updateflop
    end
end

algs = [LUFactorization(), GenericLUFactorization(), RFLUFactorization(), AppleAccelerateLUFactorization(), AppleAccelerateLUFactorization(true), FastLUFactorization(), SimpleLUFactorization()]
res = [Float64[] for i in 1:length(algs)]

ns = 4:8:500
for i in 1:length(ns)
    n = ns[i]
    @info "$n × $n"
    rng = MersenneTwister(123)
    global A = rand(rng, n, n)
    global b = rand(rng, n)
    global u0= rand(rng, n)

    for j in 1:length(algs)
        bt = @belapsed solve(prob, $(algs[j])).u setup=(prob = LinearProblem(copy(A), copy(b); u0 = copy(u0), alias_A=true, alias_b=true))
        push!(res[j], luflop(n) / bt / 1e9)
    end
end

using Plots
__parameterless_type(T) = Base.typename(T).wrapper
parameterless_type(x) = __parameterless_type(typeof(x))
parameterless_type(::Type{T}) where {T} = __parameterless_type(T)

p = plot(ns, res[1]; ylabel = "GFLOPs", xlabel = "N", title = "GFLOPs for NxN LU Factorization", label = string(Symbol(parameterless_type(algs[1]))), legend=:outertopright)
for i in 2:length(res)
    if algs[i] isa AppleAccelerateLUFactorization{true}
        plot!(p, ns, res[i]; label = "AppleAccelerateLUFactorization 64-bit")
    else
        plot!(p, ns, res[i]; label = string(Symbol(parameterless_type(algs[i]))))
    end
end
p

savefig("lubench.png")
savefig("lubench.pdf")
ChrisRackauckas commented 1 year ago

lubench.pdf lubench

codecov[bot] commented 1 year ago

Codecov Report

Merging #358 (9fe2983) into main (38e824e) will decrease coverage by 2.54%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #358      +/-   ##
==========================================
- Coverage   73.68%   71.14%   -2.54%     
==========================================
  Files          19       19              
  Lines        1353     1383      +30     
==========================================
- Hits          997      984      -13     
- Misses        356      399      +43     
Files Changed Coverage Δ
src/appleaccelerate.jl 4.59% <0.00%> (-2.68%) :arrow_down:

... and 6 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more