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

TTM @einsum versus handwritten performance #630

Closed
willow-ahrens opened this issue Nov 1, 2024 · 1 comment
Closed

TTM @einsum versus handwritten performance #630

willow-ahrens opened this issue Nov 1, 2024 · 1 comment

Comments

@willow-ahrens
Copy link
Collaborator

willow-ahrens commented Nov 1, 2024

julia> N = 700
700

julia> P = Tensor(Dense(SparseList(SparseList(Element(0.0)))), fsprand(N, N, N, 0.0005));

julia> E = Tensor(Dense(Dense(Element(0.0))), rand(N, N));

julia> @btime begin
           P = $P
           E = $E
           @einsum K1[n,j,k] = P[i,j,k]*E[i,n]
       end;
  17.489 s (678 allocations: 20.34 GiB)

julia> K1 = Tensor(Dense(SparseList(Dense(Element(0.0)))));

julia> tmp = Tensor(SparseByteMap(Element(0.0)));

julia> function mcc3_step1!(P, E, K1)
           @finch begin
               K1 .= 0
               for k=_, j=_
                   tmp .= 0
                   for n=_, i=_
                       tmp[n] += P[i,j,k]*E[i,n]
                   end
                   for n=_
                       K1[n,j,k] = tmp[n]
                   end
               end
           end
           return K1
       end
mcc3_step1! (generic function with 1 method)

julia> @btime mcc3_step1!($P, $E, $K1);
  747.221 ms (25 allocations: 3.94 KiB)

julia> function simple_mcc3_step1!(P, E, K1)
           @finch begin
               K1 .= 0
               for k=_, j=_
                   for n=_, i=_
                       K1[n,j,k] += P[i,j,k]*E[i,n]
                   end
               end
           end
           return K1
       end
simple_mcc3_step1! (generic function with 1 method)

julia> K1 = Tensor(Dense(SparseDict(Dense(Element(0.0)))));

julia> @btime simple_mcc3_step1!($P, $E, $K1);
  218.026 ms (18 allocations: 4.42 MiB)
@willow-ahrens
Copy link
Collaborator Author

the issue was @einsum K1[n,j,k] = P[i,j,k]*E[i,n] and not @einsum K1[n,j,k] += P[i,j,k]*E[i,n]

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