Skip to content

Make the _matmul more generic #98

@GiggleLiu

Description

@GiggleLiu

There is a Real type annotation added to matmul functions in recent versions.

Octavian.jl/src/matmul.jl

Lines 266 to 296 in 5ded095

@inline function _matmul!(C::AbstractMatrix{T}, A, B, α, β, nthread, MKN) where {T<:Real}
M, K, N = MKN === nothing ? matmul_sizes(C, A, B) : MKN
if M * N == 0
return
elseif K == 0
matmul_only_β!(C, β)
return
end
W = pick_vector_width(T)
pA = zstridedpointer(A); pB = zstridedpointer(B); pC = zstridedpointer(C);
Cb = preserve_buffer(C); Ab = preserve_buffer(A); Bb = preserve_buffer(B);
mᵣ, nᵣ = matmul_params(Val(T))
GC.@preserve Cb Ab Bb begin
if maybeinline(M, N, T, ArrayInterface.is_column_major(A)) # check MUST be compile-time resolvable
inlineloopmul!(pC, pA, pB, One(), Zero(), M, K, N)
return
else
(nᵣ N) && @goto LOOPMUL
if (Sys.ARCH === :x86_64) || (Sys.ARCH === :i686)
(M*K*N < (StaticInt{4_096}() * W)) && @goto LOOPMUL
else
(M*K*N < (StaticInt{32_000}() * W)) && @goto LOOPMUL
end
__matmul!(pC, pA, pB, α, β, M, K, N, nthread)
return
@label LOOPMUL
loopmul!(pC, pA, pB, α, β, M, K, N)
return
end
end
end

This function looks generic, we do not have to throw a type error on this function for non-real input. Now, I have to copy ~100 lines of code from Octavian to TropicalGEMM to fix the broken tests because the TropicalNumber is not a Real number but using exactly the same matrix multiplication code.

Actually, as @chriselrod mentioned before, any composite type with multiple fields is not supported yet, not because the type is not Real. May I open a PR to undo this change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions