From 45ca432675f3193628acce4219451b232befcfd6 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Wed, 10 Jun 2026 10:46:16 -0400 Subject: [PATCH] add support for Bumper.ResizeBuffer --- ext/TensorOperationsBumperExt.jl | 6 +++++- test/butensor.jl | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ext/TensorOperationsBumperExt.jl b/ext/TensorOperationsBumperExt.jl index d710e06b..12791765 100644 --- a/ext/TensorOperationsBumperExt.jl +++ b/ext/TensorOperationsBumperExt.jl @@ -3,7 +3,11 @@ module TensorOperationsBumperExt using TensorOperations using Bumper -const BumperBuffer = Union{SlabBuffer, AllocBuffer} +const BumperBuffer = @static if isdefined(Bumper, :ResizeBuffer) + Union{SlabBuffer, AllocBuffer, Bumper.ResizeBuffer} +else + Union{SlabBuffer, AllocBuffer} +end function TensorOperations.tensoralloc( ::Type{A}, structure, ::Val{istemp}, buf::BumperBuffer diff --git a/test/butensor.jl b/test/butensor.jl index 55074d36..fefcb211 100644 --- a/test/butensor.jl +++ b/test/butensor.jl @@ -78,4 +78,19 @@ using Bumper @test E5 isa T @test HRAA5 ≈ HRAA1 @test E5 ≈ E1 + + # resizebuffer (Bumper >= 0.7.2) + @static if isdefined(Bumper, :ResizeBuffer) + resizebuf = Bumper.ResizeBuffer() + @no_escape resizebuf @tensor allocator = resizebuf begin + HRAA6[a, s1, s2, c] := ρₗ[a, a'] * A1[a', t1, b] * A2[b, t2, c'] * ρᵣ[c', c] * + H[s1, s2, t1, t2] + E6 = ρₗ[a', a] * A1[a, s, b] * A2[b, s', c] * ρᵣ[c, c'] * H[t, t', s, s'] * + conj(A1[a', t, b']) * conj(A2[b', t', c']) + end + @test HRAA6 isa Array{T, 4} + @test E6 isa T + @test HRAA6 ≈ HRAA1 + @test E6 ≈ E1 + end end