@@ -592,7 +592,6 @@ function add_transform_kernel!(
592592 # Non-Abelian fusion: trees sharing the same set of uncoupled (external) sectors
593593 # form a *fusion block* and mix under the transformation via a recoupling matrix U
594594 # (rows = destination trees, columns = source trees). We iterate over blocks.
595- tl_buffers = OhMyThreads. TaskLocalValue (() -> allocate_buffers (tdst, tsrc, transformer, allocator))
596595 tforeach (fusionblocks (tsrc); scheduler) do src
597596 dst, U = transformer (src)
598597 if length (src) == 1
@@ -611,26 +610,27 @@ function add_transform_kernel!(
611610 # 2. Recoupling: buffer_dst = buffer_src * U^T (blocksize × rows)
612611 # 3. Insert: scatter columns of buffer_dst to destination blocks,
613612 # applying the actual permutation p in the same step.
614- buffer1, buffer2 = tl_buffers[]
615613 rows, cols = size (U)
616614 sz_src = size (tsrc[first (fusiontrees (src))... ])
617615 blocksize = prod (sz_src)
618616 ptriv = (ntuple (identity, length (sz_src)), ())
619- buffer_src = StridedView (buffer2, (blocksize, cols), (1 , blocksize), 0 )
617+ buffer = TO. tensoralloc (storagetype (tdst), blocksize * (rows + cols), Val (true ), allocator)
618+ buffer_dst = StridedView (buffer, (blocksize, rows), (1 , blocksize), 0 )
619+ buffer_src = StridedView (buffer, (blocksize, cols), (1 , blocksize), blocksize * rows)
620620 @inbounds for (i, (f₁, f₂)) in enumerate (fusiontrees (src))
621621 TO. tensoradd! (
622622 sreshape (buffer_src[:, i], sz_src), tsrc[f₁, f₂],
623623 ptriv, false , One (), Zero (), backend, allocator
624624 )
625625 end
626- buffer_dst = StridedView (buffer1, (blocksize, rows), (1 , blocksize), 0 )
627626 mul! (buffer_dst, buffer_src, transpose (StridedView (U)))
628627 @inbounds for (i, (f₃, f₄)) in enumerate (fusiontrees (dst))
629628 TO. tensoradd! (
630629 tdst[f₃, f₄], sreshape (buffer_dst[:, i], sz_src),
631630 p, false , α, β, backend, allocator
632631 )
633632 end
633+ TO. tensorfree! (buffer, allocator)
634634 end
635635 end
636636 end
@@ -663,7 +663,6 @@ function add_transform_kernel!(
663663 # U — recoupling matrix (rows = dst trees, cols = src trees)
664664 # sz_{dst,src} — array shape of each block (same for all trees in the block)
665665 # structs_{dst,src}[i] — (offset, strides) into the flat data vector for tree i
666- tl_buffers = OhMyThreads. TaskLocalValue (() -> allocate_buffers (data_dst, data_src, transformer, allocator))
667666 tforeach (transformer. data; scheduler) do (U, (sz_dst, structs_dst), (sz_src, structs_src))
668667 if length (U) == 1
669668 # Degenerate block with a single tree: no matmul needed.
@@ -676,14 +675,15 @@ function add_transform_kernel!(
676675 else
677676 # Multi-tree block: pack → recoupling matmul → unpack.
678677 # buffer2 = source staging area, buffer1 = destination staging area.
679- buffer1, buffer2 = tl_buffers[]
680678 rows, cols = size (U)
681679 blocksize = prod (sz_src)
682680 ptriv = (ntuple (identity, length (sz_src)), ())
681+ buffer = TO. tensoralloc (typeof (data_dst), blocksize * (rows + cols), Val (true ), allocator)
682+ buffer_dst = StridedView (buffer, (blocksize, rows), (1 , blocksize), 0 )
683+ buffer_src = StridedView (buffer, (blocksize, cols), (1 , blocksize), blocksize * rows)
683684
684685 # 1. Extract: copy each source block into column i of buffer_src as a flat vector,
685686 # using a trivial permutation so the layout is canonical before the matmul.
686- buffer_src = StridedView (buffer2, (blocksize, cols), (1 , blocksize), 0 )
687687 @inbounds for (i, struct_src_i) in enumerate (structs_src)
688688 TO. tensoradd! (
689689 sreshape (buffer_src[:, i], sz_src), StridedView (data_src, sz_src, struct_src_i... ),
@@ -693,7 +693,6 @@ function add_transform_kernel!(
693693
694694 # 2. Recoupling: buffer_dst = buffer_src * U^T (each output tree is a linear
695695 # combination of input trees weighted by the recoupling coefficients).
696- buffer_dst = StridedView (buffer1, (blocksize, rows), (1 , blocksize), 0 )
697696 mul! (buffer_dst, buffer_src, transpose (StridedView (U)))
698697
699698 # 3. Insert: scatter column i of buffer_dst into the destination, applying the
@@ -704,6 +703,7 @@ function add_transform_kernel!(
704703 p, false , α, β, backend, allocator
705704 )
706705 end
706+ TO. tensorfree! (buffer, allocator)
707707 end
708708 end
709709 return nothing
0 commit comments