Repository: JuliaGPU/KernelAbstractions.jl
Pull request #567 (2025-02-14 09:24:35)

Fix indicies->indices typo everywhere

vchuravy: * **#567** <a href="https://app.graphite.dev/github/pr/JuliaGPU/KernelAbstractions.jl/567?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a> 👈 <a href="https://app.graphite.dev/github/pr/JuliaGPU/KernelAbstractions.jl/567?utm_source=stack-comment-view-in-graphite" target="_blank">(View in Graphite)</a>
* `main`


<h2></h2>

This stack of pull requests is managed by <a href="https://graphite.dev?utm-source=stack-comment"><b>Graphite</b></a>. Learn more about <a href="https://stacking.dev/?utm_source=stack-comment">stacking</a>.
<!-- Current dependencies on/for this PR: -->
github-actions[bot]: ### Benchmark Results


|                                                | main                | dce672dbd5e0bb...  | main/dce672dbd5e0bb... |
|:-----------------------------------------------|:-------------------:|:------------------:|:----------------------:|
| saxpy/default/Float16/1024                     | 0.753 ± 0.0076 μs   | 0.74 ± 0.0073 μs   | 1.02                   |
| saxpy/default/Float16/1048576                  | 0.173 ± 0.0018 ms   | 0.173 ± 0.0012 ms  | 1                      |
| saxpy/default/Float16/16384                    | 3.35 ± 0.028 μs     | 3.34 ± 0.026 μs    | 1.01                   |
| saxpy/default/Float16/2048                     | 0.931 ± 0.01 μs     | 0.916 ± 0.011 μs   | 1.02                   |
| saxpy/default/Float16/256                      | 0.603 ± 0.0058 μs   | 0.591 ± 0.0053 μs  | 1.02                   |
| saxpy/default/Float16/262144                   | 0.0439 ± 0.00039 ms | 0.044 ± 0.00025 ms | 0.998                  |
| saxpy/default/Float16/32768                    | 6.04 ± 0.062 μs     | 6.01 ± 0.057 μs    | 1                      |
| saxpy/default/Float16/4096                     | 1.33 ± 0.024 μs     | 1.31 ± 0.027 μs    | 1.01                   |
| saxpy/default/Float16/512                      | 0.666 ± 0.0062 μs   | 0.652 ± 0.0057 μs  | 1.02                   |
| saxpy/default/Float16/64                       | 0.572 ± 0.0046 μs   | 0.563 ± 0.0046 μs  | 1.02                   |
| saxpy/default/Float16/65536                    | 11.7 ± 0.091 μs     | 11.6 ± 0.11 μs     | 1.01                   |
| saxpy/default/Float32/1024                     | 0.634 ± 0.013 μs    | 0.643 ± 0.012 μs   | 0.987                  |
| saxpy/default/Float32/1048576                  | 0.228 ± 0.021 ms    | 0.229 ± 0.012 ms   | 0.995                  |
| saxpy/default/Float32/16384                    | 2.8 ± 0.2 μs        | 2.78 ± 0.14 μs     | 1.01                   |
| saxpy/default/Float32/2048                     | 0.753 ± 0.072 μs    | 0.76 ± 0.071 μs    | 0.991                  |
| saxpy/default/Float32/256                      | 0.561 ± 0.0063 μs   | 0.574 ± 0.0073 μs  | 0.977                  |
| saxpy/default/Float32/262144                   | 0.0555 ± 0.0034 ms  | 0.0568 ± 0.003 ms  | 0.977                  |
| saxpy/default/Float32/32768                    | 5.33 ± 0.38 μs      | 5.34 ± 0.38 μs     | 0.998                  |
| saxpy/default/Float32/4096                     | 1.11 ± 0.08 μs      | 1.15 ± 0.11 μs     | 0.963                  |
| saxpy/default/Float32/512                      | 0.597 ± 0.0092 μs   | 0.61 ± 0.011 μs    | 0.979                  |
| saxpy/default/Float32/64                       | 0.549 ± 0.0046 μs   | 0.566 ± 0.0053 μs  | 0.971                  |
| saxpy/default/Float32/65536                    | 12.4 ± 0.66 μs      | 12.3 ± 0.61 μs     | 1.01                   |
| saxpy/default/Float64/1024                     | 0.741 ± 0.04 μs     | 0.75 ± 0.073 μs    | 0.989                  |
| saxpy/default/Float64/1048576                  | 0.491 ± 0.022 ms    | 0.495 ± 0.022 ms   | 0.992                  |
| saxpy/default/Float64/16384                    | 5.32 ± 0.38 μs      | 5.38 ± 0.54 μs     | 0.989                  |
| saxpy/default/Float64/2048                     | 1.13 ± 0.092 μs     | 1.14 ± 0.098 μs    | 0.991                  |
| saxpy/default/Float64/256                      | 0.564 ± 0.0076 μs   | 0.574 ± 0.0075 μs  | 0.983                  |
| saxpy/default/Float64/262144                   | 0.114 ± 0.0067 ms   | 0.114 ± 0.0045 ms  | 1                      |
| saxpy/default/Float64/32768                    | 12.5 ± 0.63 μs      | 12.5 ± 0.66 μs     | 0.998                  |
| saxpy/default/Float64/4096                     | 1.69 ± 0.16 μs      | 1.67 ± 0.1 μs      | 1.01                   |
| saxpy/default/Float64/512                      | 0.616 ± 0.013 μs    | 0.625 ± 0.01 μs    | 0.986                  |
| saxpy/default/Float64/64                       | 0.543 ± 0.0039 μs   | 0.547 ± 0.0076 μs  | 0.992                  |
| saxpy/default/Float64/65536                    | 28.5 ± 1.4 μs       | 28.5 ± 1.4 μs      | 0.998                  |
| saxpy/static workgroup=(1024,)/Float16/1024    | 2.2 ± 0.024 μs      | 2.19 ± 0.025 μs    | 1.01                   |
| saxpy/static workgroup=(1024,)/Float16/1048576 | 0.157 ± 0.0024 ms   | 0.157 ± 0.0029 ms  | 0.999                  |
| saxpy/static workgroup=(1024,)/Float16/16384   | 4.45 ± 0.086 μs     | 4.43 ± 0.073 μs    | 1                      |
| saxpy/static workgroup=(1024,)/Float16/2048    | 2.38 ± 0.023 μs     | 2.36 ± 0.029 μs    | 1.01                   |
| saxpy/static workgroup=(1024,)/Float16/256     | 2.84 ± 0.033 μs     | 2.79 ± 0.031 μs    | 1.02                   |
| saxpy/static workgroup=(1024,)/Float16/262144  | 0.0416 ± 0.0012 ms  | 0.042 ± 0.0015 ms  | 0.991                  |
| saxpy/static workgroup=(1024,)/Float16/32768   | 6.86 ± 0.18 μs      | 6.87 ± 0.16 μs     | 0.999                  |
| saxpy/static workgroup=(1024,)/Float16/4096    | 2.71 ± 0.032 μs     | 2.67 ± 0.039 μs    | 1.01                   |
| saxpy/static workgroup=(1024,)/Float16/512     | 3.29 ± 0.036 μs     | 3.24 ± 0.033 μs    | 1.01                   |
| saxpy/static workgroup=(1024,)/Float16/64      | 2.54 ± 0.22 μs      | 2.49 ± 0.22 μs     | 1.02                   |
| saxpy/static workgroup=(1024,)/Float16/65536   | 12.5 ± 0.21 μs      | 12.4 ± 0.24 μs     | 1.01                   |
| saxpy/static workgroup=(1024,)/Float32/1024    | 2.23 ± 0.029 μs     | 2.19 ± 0.028 μs    | 1.01                   |
| saxpy/static workgroup=(1024,)/Float32/1048576 | 0.233 ± 0.018 ms    | 0.237 ± 0.011 ms   | 0.98                   |
| saxpy/static workgroup=(1024,)/Float32/16384   | 4.4 ± 0.3 μs        | 4.37 ± 0.29 μs     | 1.01                   |
| saxpy/static workgroup=(1024,)/Float32/2048    | 2.37 ± 0.051 μs     | 2.36 ± 0.07 μs     | 1.01                   |
| saxpy/static workgroup=(1024,)/Float32/256     | 2.67 ± 0.041 μs     | 2.68 ± 0.039 μs    | 0.997                  |
| saxpy/static workgroup=(1024,)/Float32/262144  | 0.0588 ± 0.004 ms   | 0.0606 ± 0.0023 ms | 0.97                   |
| saxpy/static workgroup=(1024,)/Float32/32768   | 7.42 ± 0.37 μs      | 7.46 ± 0.51 μs     | 0.994                  |
| saxpy/static workgroup=(1024,)/Float32/4096    | 2.66 ± 0.079 μs     | 2.66 ± 0.084 μs    | 0.997                  |
| saxpy/static workgroup=(1024,)/Float32/512     | 2.69 ± 0.029 μs     | 2.71 ± 0.033 μs    | 0.993                  |
| saxpy/static workgroup=(1024,)/Float32/64      | 2.69 ± 4.5 μs       | 2.71 ± 5.3 μs      | 0.993                  |
| saxpy/static workgroup=(1024,)/Float32/65536   | 15.1 ± 0.81 μs      | 15.3 ± 0.86 μs     | 0.986                  |
| saxpy/static workgroup=(1024,)/Float64/1024    | 2.41 ± 0.064 μs     | 2.31 ± 0.085 μs    | 1.04                   |
| saxpy/static workgroup=(1024,)/Float64/1048576 | 0.506 ± 0.021 ms    | 0.493 ± 0.023 ms   | 1.03                   |
| saxpy/static workgroup=(1024,)/Float64/16384   | 7.32 ± 0.4 μs       | 7.33 ± 0.44 μs     | 0.999                  |
| saxpy/static workgroup=(1024,)/Float64/2048    | 2.65 ± 0.078 μs     | 2.6 ± 0.083 μs     | 1.02                   |
| saxpy/static workgroup=(1024,)/Float64/256     | 2.67 ± 0.051 μs     | 2.64 ± 0.053 μs    | 1.01                   |
| saxpy/static workgroup=(1024,)/Float64/262144  | 0.118 ± 0.0068 ms   | 0.117 ± 0.0045 ms  | 1                      |
| saxpy/static workgroup=(1024,)/Float64/32768   | 15.2 ± 0.86 μs      | 15.2 ± 0.86 μs     | 1                      |
| saxpy/static workgroup=(1024,)/Float64/4096    | 3.19 ± 0.19 μs      | 3.14 ± 0.14 μs     | 1.02                   |
| saxpy/static workgroup=(1024,)/Float64/512     | 2.68 ± 0.064 μs     | 2.65 ± 0.066 μs    | 1.01                   |
| saxpy/static workgroup=(1024,)/Float64/64      | 2.62 ± 0.065 μs     | 2.6 ± 0.072 μs     | 1.01                   |
| saxpy/static workgroup=(1024,)/Float64/65536   | 31 ± 1.4 μs         | 31.1 ± 1.2 μs      | 0.997                  |
| time_to_load                                   | 0.315 ± 0.0027 s    | 0.314 ± 0.00099 s  | 1                      |



### Benchmark Plots
A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).


Patch:
diff --git a/docs/src/design.md b/docs/src/design.md
index 1fc774d7..df2d60b7 100644
--- a/docs/src/design.md
+++ b/docs/src/design.md
@@ -8,7 +8,7 @@
     - `ldg` on the GPU
     - `@aliasscopes` on the CPU
 
-- Cartesian or Linear indicies supported
+- Cartesian or Linear indices supported
   - `@index(Linear)
   - `@index(Cartesian)
 - `@synchronize` for inserting workgroup-level synchronization
diff --git a/docs/src/index.md b/docs/src/index.md
index f8bb81f5..164f6c63 100644
--- a/docs/src/index.md
+++ b/docs/src/index.md
@@ -58,7 +58,7 @@ The `CPU` backend always had this limitation and upon investigation the CUDA bac
 but allows for a wider set of valid kernels.
 
 This highlighted a design flaw in KernelAbstractions. Most GPU implementations execute KernelAbstraction workgroups on static blocks
-This means a kernel with `ndrange=(32, 30)` might be executed on a static block of `(32,32)`. In order to block these extra indicies,
+This means a kernel with `ndrange=(32, 30)` might be executed on a static block of `(32,32)`. In order to block these extra indices,
 KernelAbstraction would insert a dynamic boundscheck.
 
 Prior to v0.9.34 a kernel like
@@ -118,7 +118,7 @@ Since this transformation can be disruptive, user can now opt out of the implici
 but users must avoid the use of `@index(Global)` and instead use their own derivation based on `@index(Group)` and `@index(Local)`.
 
 ```julia
-@kernel unsafe_indicies=true function localmem(A)
+@kernel unsafe_indices=true function localmem(A)
     N = @uniform prod(@groupsize())
     gI = @index(Group, Linear)
     i = @index(Local, Linear)
diff --git a/src/KernelAbstractions.jl b/src/KernelAbstractions.jl
index 997ab770..582a61e9 100644
--- a/src/KernelAbstractions.jl
+++ b/src/KernelAbstractions.jl
@@ -50,7 +50,7 @@ synchronize(backend)
 ```
 """
 macro kernel(expr)
-    return __kernel(expr, #=generate_cpu=# true, #=force_inbounds=# false, #=unsafe_indicies=# false)
+    return __kernel(expr, #=generate_cpu=# true, #=force_inbounds=# false, #=unsafe_indices=# false)
 end
 
 """
@@ -60,7 +60,7 @@ This allows for two different configurations:
 
 1. `cpu={true, false}`: Disables code-generation of the CPU function. This relaxes semantics such that KernelAbstractions primitives can be used in non-kernel functions.
 2. `inbounds={false, true}`: Enables a forced `@inbounds` macro around the function definition in the case the user is using too many `@inbounds` already in their kernel. Note that this can lead to incorrect results, crashes, etc and is fundamentally unsafe. Be careful!
-3. `unsafe_indicies={false, true}`: Disables the implicit validation of indicies, users must avoid `@index(Global)`.
+3. `unsafe_indices={false, true}`: Disables the implicit validation of indices, users must avoid `@index(Global)`.
 
 - [`@context`](@ref)
 
@@ -72,7 +72,7 @@ macro kernel(ex...)
         return __kernel(ex[1], true, false, false)
     else
         generate_cpu = true
-        unsafe_indicies = false
+        unsafe_indices = false
         force_inbounds = false
         for i in 1:(length(ex) - 1)
             if ex[i] isa Expr && ex[i].head == :(=) &&
@@ -82,19 +82,19 @@ macro kernel(ex...)
                     ex[i].args[1] == :inbounds && ex[i].args[2] isa Bool
                 force_inbounds = ex[i].args[2]
             elseif ex[i] isa Expr && ex[i].head == :(=) &&
-                    ex[i].args[1] == :unsafe_indicies && ex[i].args[2] isa Bool
-                unsafe_indicies = ex[i].args[2]
+                    ex[i].args[1] == :unsafe_indices && ex[i].args[2] isa Bool
+                unsafe_indices = ex[i].args[2]
             else
                 error(
                     "Configuration should be of form:\n" *
                         "* `cpu=false`\n" *
                         "* `inbounds=true`\n" *
-                        "* `unsafe_indicies=true`\n" *
+                        "* `unsafe_indices=true`\n" *
                         "got `", ex[i], "`",
                 )
             end
         end
-        return __kernel(ex[end], generate_cpu, force_inbounds, unsafe_indicies)
+        return __kernel(ex[end], generate_cpu, force_inbounds, unsafe_indices)
     end
 end
 
diff --git a/src/macros.jl b/src/macros.jl
index fc8ddca8..c83d6030 100644
--- a/src/macros.jl
+++ b/src/macros.jl
@@ -10,7 +10,7 @@ function find_return(stmt)
 end
 
 # XXX: Proper errors
-function __kernel(expr, generate_cpu = true, force_inbounds = false, unsafe_indicies = false)
+function __kernel(expr, generate_cpu = true, force_inbounds = false, unsafe_indices = false)
     def = splitdef(expr)
     name = def[:name]
     args = def[:args]
@@ -46,7 +46,7 @@ function __kernel(expr, generate_cpu = true, force_inbounds = false, unsafe_indi
 
     def_gpu = deepcopy(def)
     def_gpu[:name] = gpu_name = Symbol(:gpu_, name)
-    transform_gpu!(def_gpu, constargs, force_inbounds, unsafe_indicies)
+    transform_gpu!(def_gpu, constargs, force_inbounds, unsafe_indices)
     gpu_function = combinedef(def_gpu)
 
     # create constructor functions
@@ -78,7 +78,7 @@ end
 
 # The easy case, transform the function for GPU execution
 # - mark constant arguments by applying `constify`.
-function transform_gpu!(def, constargs, force_inbounds, unsafe_indicies)
+function transform_gpu!(def, constargs, force_inbounds, unsafe_indices)
     let_constargs = Expr[]
     for (i, arg) in enumerate(def[:args])
         if constargs[i]
@@ -89,13 +89,13 @@ function transform_gpu!(def, constargs, force_inbounds, unsafe_indicies)
     new_stmts = Expr[]
     body = MacroTools.flatten(def[:body])
     push!(new_stmts, Expr(:aliasscope))
-    if !unsafe_indicies
+    if !unsafe_indices
         push!(new_stmts, :(__active_lane__ = $__validindex(__ctx__)))
     end
     if force_inbounds
         push!(new_stmts, Expr(:inbounds, true))
     end
-    if !unsafe_indicies
+    if !unsafe_indices
         append!(new_stmts, split(emit_gpu, body.args))
     else
         push!(new_stmts, body)
@@ -117,7 +117,7 @@ end
 # - mark constant arguments by applying `constify`.
 # - insert aliasscope markers
 # - insert implied loop bodys
-#   - handle indicies
+#   - handle indices
 #   - hoist workgroup definitions
 #   - hoist uniform variables
 function transform_cpu!(def, constargs, force_inbounds)
@@ -149,7 +149,7 @@ function transform_cpu!(def, constargs, force_inbounds)
 end
 
 struct WorkgroupLoop
-    indicies::Vector{Any}
+    indices::Vector{Any}
     stmts::Vector{Any}
     allocations::Vector{Any}
     private_allocations::Vector{Any}
@@ -177,7 +177,7 @@ end
 function split(
         emit,
         stmts,
-        indicies = Any[], private = Set{Symbol}(),
+        indices = Any[], private = Set{Symbol}(),
     )
     # 1. Split the code into blocks separated by `@synchronize`
     # 2. Aggregate `@index` expressions
@@ -191,7 +191,7 @@ function split(
     for stmt in stmts
         has_sync = find_sync(stmt)
         if has_sync
-            loop = WorkgroupLoop(deepcopy(indicies), current, allocations, private_allocations, deepcopy(private), is_sync(stmt))
+            loop = WorkgroupLoop(deepcopy(indices), current, allocations, private_allocations, deepcopy(private), is_sync(stmt))
             push!(new_stmts, emit(loop))
             allocations = Any[]
             private_allocations = Any[]
@@ -206,7 +206,7 @@ function split(
             function recurse(expr::Expr)
                 expr = unblock(expr)
                 if is_scope_construct(expr) && any(find_sync, expr.args)
-                    new_args = unblock(split(emit, expr.args, deepcopy(indicies), deepcopy(private)))
+                    new_args = unblock(split(emit, expr.args, deepcopy(indices), deepcopy(private)))
                     return Expr(expr.head, new_args...)
                 else
                     return Expr(expr.head, map(recurse, expr.args)...)
@@ -225,7 +225,7 @@ function split(
             continue
         elseif @capture(stmt, lhs_ = rhs_ | (vs__, lhs_ = rhs_))
             if @capture(rhs, @index(args__))
-                push!(indicies, stmt)
+                push!(indices, stmt)
                 continue
             elseif @capture(rhs, @localmem(args__) | @uniform(args__))
                 push!(allocations, stmt)
@@ -249,7 +249,7 @@ function split(
 
     # everything since the last `@synchronize`
     if !isempty(current)
-        loop = WorkgroupLoop(deepcopy(indicies), current, allocations, private_allocations, deepcopy(private), false)
+        loop = WorkgroupLoop(deepcopy(indices), current, allocations, private_allocations, deepcopy(private), false)
         push!(new_stmts, emit(loop))
     end
     return new_stmts
@@ -257,7 +257,7 @@ end
 
 function emit_cpu(loop)
     idx = gensym(:I)
-    for stmt in loop.indicies
+    for stmt in loop.indices
         # splice index into the i = @index(Cartesian, $idx)
         @assert stmt.head === :(=)
         rhs = stmt.args[2]
@@ -300,7 +300,7 @@ function emit_cpu(loop)
         loopexpr = quote
             for $idx in $__workitems_iterspace(__ctx__)
                 $__validindex(__ctx__, $idx) || continue
-                $(loop.indicies...)
+                $(loop.indices...)
                 $(unblock(body))
             end
         end
@@ -318,7 +318,7 @@ function emit_gpu(loop)
         $(loop.allocations...)
         $(loop.private_allocations...)
         if __active_lane__
-            $(loop.indicies...)
+            $(loop.indices...)
             $(unblock(body))
         end
     end


Test patch:
diff --git a/test/localmem.jl b/test/localmem.jl
index fe47d2a5..9a34d97c 100644
--- a/test/localmem.jl
+++ b/test/localmem.jl
@@ -34,7 +34,7 @@ end
     end
 end
 
-@kernel unsafe_indicies = true function localmem_unsafe_indicies(A)
+@kernel unsafe_indices = true function localmem_unsafe_indices(A)
     N = @uniform prod(@groupsize())
     gI = @index(Group, Linear)
     i = @index(Local, Linear)
@@ -49,7 +49,7 @@ end
 
 function localmem_testsuite(backend, ArrayT)
     @testset "kernels" begin
-        @testset for kernel! in (localmem(backend(), 16), localmem2(backend(), 16), localmem_unsafe_indicies(backend(), 16))
+        @testset for kernel! in (localmem(backend(), 16), localmem2(backend(), 16), localmem_unsafe_indices(backend(), 16))
             A = ArrayT{Int}(undef, 64)
             kernel!(A, ndrange = size(A))
             synchronize(backend())