@@ -7,10 +7,11 @@ using GPUArrays.KernelAbstractions: @kernel, @index, get_backend
77using Strided: StridedViews
88using MatrixAlgebraKit, Adapt
99using TensorKit
10+ using TensorKit. TensorOperations: linearize
1011using TensorKit. Factorizations
1112using TensorKit. Factorizations: AbstractAlgorithm
1213using TensorKit: SectorDict, tensormaptype, scalar, similarstoragetype, AdjointTensorMap, scalartype, project_symmetric_and_check
13- import TensorKit: randisometry, rand, randn, fill_braidingsubblock!
14+ import TensorKit: randisometry, rand, randn, fill_braidingsubblock!, add_transform_kernel!
1415
1516function TensorKit. fill_braidingsubblock! (data:: TD , val) where {T, TD <: Union{<:AnyGPUMatrix{T}, <:StridedViews.StridedView{T, 4, <:AnyGPUArray{T}}} }
1617 # COV_EXCL_START
@@ -121,5 +122,30 @@ function TensorKit.scalar(t::TensorMap{T, S, 0, 0, <:AnyGPUArray}) where {T, S}
121122 return isempty (inds) ? zero (scalartype (t)) : @allowscalar @inbounds t. data[only (inds)]
122123end
123124
125+ # COV_EXCL_START
126+ # kernels are not reachable by coverage
127+ @kernel function abelian_batched_permute! (data_dst:: AbstractArray{T} , data_src, transformer_data, p, α, β, :: Val{N} ) where {T, N}
128+ idx = @index (Global, Linear)
129+ if idx <= length (transformer_data)
130+ coeff, struct_dst, struct_src = @inbounds transformer_data[idx]
131+ dst_view = StridedViews. StridedView (data_dst, struct_dst... )
132+ sz_src, st_src, offs_src = struct_src
133+ psz = ntuple (n -> sz_src[p[n]], Val (N))
134+ pst = ntuple (n -> st_src[p[n]], Val (N))
135+ p_src_view = StridedViews. StridedView (data_src, psz, pst, offs_src)
136+ for ix in 1 : length (dst_view)
137+ @inbounds dst_view[ix] = α * coeff * p_src_view[ix] + β * dst_view[ix]
138+ end
139+ end
140+ end
141+ # COV_EXCL_STOP
142+
143+ function TensorKit. add_transform_kernel! (data_dst:: A , data_src:: A , p, transformer:: TensorKit.AbelianTreeTransformer{T, N} , α, β, backend, allocator, scheduler) where {T, N, A <: AnyGPUArray }
144+ new_typ = similar (data_dst, Tuple{T, TensorKit. StridedStructure{N}, TensorKit. StridedStructure{N}}, 0 )
145+ device_data = adapt (typeof (new_typ), transformer. data)
146+ p_ = linearize (p)
147+ abelian_batched_permute! (get_backend (data_dst))(data_dst, data_src, device_data, p_, α, β, Val (N); ndrange = length (device_data))
148+ return
149+ end
124150
125151end
0 commit comments