Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@withalloc allocates but @withalloc1 does not #3

Closed
cortner opened this issue May 31, 2024 · 1 comment
Closed

@withalloc allocates but @withalloc1 does not #3

cortner opened this issue May 31, 2024 · 1 comment

Comments

@cortner
Copy link
Member

cortner commented May 31, 2024

For the simple case of a single pre-allocation @withalloc is non-allocating. But for more than one pre-allocation there is a very small allocation that I cannot track down and don't understand.

using WithAlloc, LinearAlgebra, Bumper, BenchmarkTools 

mymul2!(A1, A2, B, C, D) = mul!(A1, B, C), mul!(A2, B, D)

function WithAlloc.whatalloc(::typeof(mymul2!), B, C, D) 
   T1 = promote_type(eltype(B), eltype(C))
   T2 = promote_type(eltype(B), eltype(D))
   return ( (T1, size(B, 1), size(C, 2)), 
            (T2, size(B, 1), size(D, 2)) )
end

function alloctest1(B, C, D) 
   @no_escape begin 
      a1, a2 = WithAlloc.whatalloc(mymul2!, B, C, D)
      A1 = @alloc(a1...)
      A2 = @alloc(a2...)
      mymul2!(A1, A2, B, C, D) 
     # this change makes it again allocating: 
     #    A12 = ( (@alloc(a1...)), (@alloc(a2...)) )
     #    mymul2!(A12..., B, C, D) 
      sum(A1) + sum(A2)
   end
end 

function alloctest2(B, C, D) 
   @no_escape begin 
      A1, A2 = @withalloc mymul2!(B, C, D) 
      sum(A1) + sum(A2)
   end
end 

B = randn(5,10); C = randn(10, 3); D = randn(10, 5)
@btime alloctest1($B, $C, $D)
@btime alloctest2($B, $C, $D)
@cortner
Copy link
Member Author

cortner commented May 31, 2024

fixed by commit e58c617

@cortner cortner closed this as completed May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant