Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/gemm.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const BlasSemiringTypes{T} = Union{Tropical{T}, TropicalMinPlus{T}, TropicalMaxMul{T}}
const BlasSemiringTypes{T} = Union{Tropical{T}, TropicalMinPlus{T}, TropicalMaxMul{T}, TropicalMaxMin{T}, TropicalBitwise{T}}
basetype(::Type{<:Tropical}) = Tropical
basetype(::Type{<:TropicalMinPlus}) = TropicalMinPlus
basetype(::Type{<:TropicalMaxMul}) = TropicalMaxMul
basetype(::Type{<:TropicalMaxMin}) = TropicalMaxMin
basetype(::Type{<:TropicalBitwise}) = TropicalBitwise

# implement neginf for Vec and VecUnroll
TropicalNumbers.neginf(::Type{Vec{N, T}}) where {N,T} = Vec(ntuple(i->neginf(T), N)...)
Expand All @@ -10,7 +12,7 @@ TropicalNumbers.neginf(::Type{VecUnroll{N,W,T,V}}) where {N,W,T,V} = VecUnroll(n
LoopVectorization.check_args(::Type{T}, ::Type{T}) where T<:BlasSemiringTypes = true
LoopVectorization.check_type(::Type{<:BlasSemiringTypes{T}}) where {T} = LoopVectorization.check_type(T)

for TT in [:Tropical, :TropicalMaxMul, :TropicalMinPlus]
for TT in [:Tropical, :TropicalMinPlus, :TropicalMaxMul, :TropicalMaxMin, :TropicalBitwise]
@eval @inline function VectorizationBase._vstore!(
ptr::AbstractStridedPointer, vu::$TT{<:VecUnroll{Nm1,W}}, u::Unroll{AU,F,N,AV,W}, a::A, s::S, nt::NT, si::StaticInt{RS}
) where {A<:StaticBool,S<:StaticBool,NT<:StaticBool,RS,AU,F,N,AV,W,Nm1}
Expand Down Expand Up @@ -101,7 +103,8 @@ for TP in [:NativeTypes, :AbstractSIMD]
for (TT, F0, F1) in [
(:Tropical, :max_fast, :add_fast),
(:TropicalMinPlus, :min_fast, :add_fast),
(:TropicalMaxMul, :max_fast, :mul_fast)
(:TropicalMaxMul, :max_fast, :mul_fast),
(:TropicalMaxMin, :max_fast, :min_fast),
]
@eval @inline function Base.fma(x::$TT{V}, y::$TT{V}, z::$TT{V}) where {V<:$TP}
$TT(Base.FastMath.$F0(content(z), Base.FastMath.$F1(content(x), content(y))))
Expand Down Expand Up @@ -136,7 +139,9 @@ end
for (TT, F0, F1, F2, F3, F4) in [
(:Tropical, :max_fast, :collapse_max, :contract_max, :reduced_max, :vmaximum),
(:TropicalMinPlus, :min_fast, :collapse_min, :contract_min, :reduced_min, :vminimum),
(:TropicalMaxMul, :max_fast, :collapse_max, :contract_max, :reduced_max, :vmaximum)
(:TropicalMaxMul, :max_fast, :collapse_max, :contract_max, :reduced_max, :vmaximum),
(:TropicalMaxMin, :max_fast, :collapse_max, :contract_max, :reduced_max, :vmaximum),
(:TropicalBitwise, :|, :collape_or, :contract_or, :reduced_any, :vany),
]
@eval @inline Base.FastMath.add_fast(a::$TT, b::$TT) = $TT(Base.FastMath.$F0(content(a), content(b)))

Expand Down
10 changes: 7 additions & 3 deletions test/gemm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ end
@test !any(isnan, res)
end

@testset "MinPlus and MaxMul" begin
@testset "MinPlus, MaxMul, MaxMin, and Bitwise" begin
for (T1,T2) in [
[TropicalMinPlusF64, TropicalMinPlusF64],
[TropicalMinPlus{Int64}, TropicalMinPlus{Int64}],
[TropicalMaxMulF64, TropicalMaxMulF64], [TropicalMaxMul{Int64}, TropicalMaxMul{Int64}]
[TropicalMaxMulF64, TropicalMaxMulF64],
[TropicalMaxMul{Int64}, TropicalMaxMul{Int64}],
[TropicalMaxMinF64, TropicalMaxMinF64],
[TropicalMaxMinI64, TropicalMaxMinI64],
[TropicalBitwiseI64, TropicalBitwiseI64],
]
for n in [0, 1, 4, 40]
A = _rand(T1, n, n)
Expand All @@ -124,4 +128,4 @@ end
end
end
end
end
end
Loading