1+ # you will need this to use Tropical numbers in CUDA.
2+ using CUDA
3+ CUDA. allowscalar (false )
4+ using TropicalGEMM: XTranspose, NativeTypes, Tropical, TropicalTypes, CountingTropical
5+ using LinearAlgebra
6+ using Test
7+
8+ const CTranspose{T} = Transpose{T, <: StridedCuVecOrMat{T} }
9+ for TT in [:(Tropical{<: NativeTypes }), :TropicalTypes ]
10+ for RT in [TT, :Real ]
11+ for (TA, CTA) in [(:CuMatrix , :CuMatrix ), (:CTranspose , :(Transpose{<: Any , <: StridedCuVecOrMat }))]
12+ for (TB, CTB) in [(:CuMatrix , :CuMatrix ), (:CTranspose , :(Transpose{<: Any , <: StridedCuVecOrMat }))]
13+ @eval function LinearAlgebra. mul! (o:: CuMatrix{T} , a:: $TA{T} , b:: $TB{T} , α:: $RT , β:: $RT ) where {T<: $TT }
14+ CUDA. CUBLAS. gemm_dispatch! (o, a, b, α, β)
15+ end
16+ end
17+ end
18+ end
19+ end
20+
21+ @testset " cuda patch" begin
22+ for T in [Tropical{Float64}, CountingTropical{Float64,Float64}]
23+ a = T .(CUDA. randn (4 , 4 ))
24+ b = T .(CUDA. randn (4 ))
25+ for A in [transpose (a), a, transpose (b)]
26+ for B in [transpose (a), a, b]
27+ if ! (size (A) == (1 ,4 ) && size (B) == (4 ,))
28+ res0 = Array (A) * Array (B)
29+ res1 = A * B
30+ res2 = mul! (CUDA. zeros (T, size (res0)... ), A, B, true , false )
31+ @test Array (res1) ≈ res0
32+ @test Array (res2) ≈ res0
33+ end
34+ end
35+ end
36+ end
37+ end
0 commit comments