Octavian.jl icon indicating copy to clipboard operation
Octavian.jl copied to clipboard

Feature request: `Octavian.batched_mul` and `Octavian.batched_mul!`

Open DilumAluthge opened this issue 4 years ago • 1 comments

NNlib.jl has the following nice functions:

Function Description
batched_mul(A, B) -> C Batched matrix multiplication. Result has C[:,:,k] == A[:,:,k] * B[:,:,k] for all k. If size(B,3) == 1 then instead C[:,:,k] == A[:,:,k] * B[:,:,1], and similarly for A.
batched_mul!(C, A, B) -> C and batched_mul!(C, A, B, α=1, β=0) In-place batched matrix multiplication, equivalent to mul!(C[:,:,k], A[:,:,k], B[:,:,k], α, β) for all k. If size(B,3) == 1 then every batch uses B[:,:,1] instead.

Of course, under the hood, all of these functions call LinearAlgebra.mul!. It would be nice if Octavian could have its own batched_mul and batched_mul! that calls our own pure Julia matmul routines.

Octavian.batched_mul and Octavian.batched_mul! would be public functions, i.e. we would document them and put them in the manual. But we probably won't export them, just so we don't clash with NNlib.

DilumAluthge avatar Jan 17 '21 21:01 DilumAluthge

It's worth exploring if some sort of repacking could improve performance, in particular for large batches of small matrices.

chriselrod avatar Jan 17 '21 22:01 chriselrod