Skip to content

Commit f6dca43

Browse files
lkdvosclaude
andcommitted
Drop the coverage exclusions around GPU kernels and the @index workaround
The workaround for nested `@index` in the CPU backend of KernelAbstractions is no longer needed since KernelAbstractions v0.9.45 (JuliaGPU/KernelAbstractions.jl#877). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 64184a2 commit f6dca43

1 file changed

Lines changed: 4 additions & 21 deletions

File tree

‎ext/TensorKitGPUArraysExt.jl‎

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ using TensorKit: SubblockIterator
1818
import TensorKit: randisometry, rand, randn, fill_braidingsubblock!, add_transform_kernel!, trace_transform_kernel!
1919

2020
function TensorKit.fill_braidingsubblock!(data::TD, val) where {T, TD <: Union{<:AnyGPUMatrix{T}, <:StridedViews.StridedView{T, 4, <:AnyGPUArray{T}}}}
21-
# COV_EXCL_START
22-
# kernels are not reachable by coverage
2321
@kernel function fill_subblock_kernel!(subblock, val)
2422
idx = @index(Global, Cartesian)
2523
idx_val = idx[1] == idx[4] && idx[2] == idx[3] ? val : zero(val)
2624
@inbounds subblock[idx] = idx_val
2725
end
28-
# COV_EXCL_STOP
2926
kernel = fill_subblock_kernel!(get_backend(data))
3027
kernel(data, val; ndrange = size(data))
3128
return data
@@ -462,9 +459,6 @@ function device_transformer(A, transformer::TraceTransformer, p, q)
462459
end
463460
end
464461

465-
# COV_EXCL_START
466-
# kernels are not reachable by coverage
467-
468462
# largest `i` with `offsets[i] <= w`. This corresponds to the
469463
# block which this kernel thread will work on. Since this is
470464
# used inside a GPU kernel, searchsortedlast/searchsortedfirst
@@ -503,9 +497,7 @@ end
503497
@kernel function unique_batched_permute_kernel!(
504498
data_dst, data_src, op, blocks, work_offsets, α, β, nwork, ::Val{N}
505499
) where {N}
506-
# w = @index(Global, Linear) - 1 does not work due to JLArrays bug
507-
w = @index(Global, Linear)
508-
w -= 1
500+
w = @index(Global, Linear) - 1
509501
if w < nwork
510502
b = _searchblock(work_offsets, w)
511503
blk = @inbounds blocks[b]
@@ -516,8 +508,6 @@ end
516508
end
517509
end
518510

519-
# COV_EXCL_STOP
520-
521511
# One thread per destination element in `data_dst`. This makes much better use of the
522512
# GPU "massive parallelism" as compared to the one-thread-per-subtransformer approach.
523513
# It also more evenly divides the work among threads so the work profile is less
@@ -530,9 +520,7 @@ end
530520
data_dst, data_src, op, blocks, work_offsets, coeffs, structs_dst, structs_src,
531521
α, β, nwork, ::Val{N}
532522
) where {N}
533-
# w = @index(Global, Linear) - 1 does not work due to JLArrays bug
534-
w = @index(Global, Linear)
535-
w -= 1
523+
w = @index(Global, Linear) - 1
536524
if w < nwork
537525
# bookkeeping to figure out where to read from and write to
538526
b = _searchblock(work_offsets, w)
@@ -561,13 +549,10 @@ end
561549
end
562550
end
563551

564-
# COV_EXCL_START
565552
# First stage: one thread per (chunk, remaining entry) of every source subblock, writing its
566553
# partial trace to `partials[w + 1]`. Consecutive threads handle consecutive remaining entries.
567554
@kernel function partial_trace_kernel!(partials, data_src, sources, partial_offsets, npartials)
568-
# w = @index(Global, Linear) - 1 does not work due to JLArrays bug
569-
w = @index(Global, Linear)
570-
w -= 1
555+
w = @index(Global, Linear) - 1
571556
if w < npartials
572557
j = _searchblock(partial_offsets, w)
573558
src = @inbounds sources[j]
@@ -591,8 +576,7 @@ end
591576
data_dst, partials, blocks, work_offsets, coeffs, structs_dst, sources, partial_offsets,
592577
α, β, nwork
593578
)
594-
w = @index(Global, Linear)
595-
w -= 1
579+
w = @index(Global, Linear) - 1
596580
if w < nwork
597581
b = _searchblock(work_offsets, w)
598582
blk = @inbounds blocks[b]
@@ -620,7 +604,6 @@ end
620604
@inbounds data_dst[i_dst] = iszero(β) ? α * acc : α * acc + β * data_dst[i_dst]
621605
end
622606
end
623-
# COV_EXCL_STOP
624607

625608
function _launch_unique!(data_dst, data_src, op, transformer, α, β, ::Val{N}) where {N}
626609
nwork = transformer.nwork

0 commit comments

Comments
 (0)