# ERROR: LoadError: UndefVarError: \`local\_d\` not defined in \`Main\`

**URL:** https://discourse.julialang.org/t/error-loaderror-undefvarerror-local-d-not-defined-in-main/131296
**Category:** General Usage
**Tags:** kernelabstractions
**Created:** [August 1, 2025, 4:51pm UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-local-d-not-defined-in-main/131296 "2025-08-01T16:51:08Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)
#### Post date: [August 5, 2025, 10:32am UTC](https://discourse.julialang.org/t/error-loaderror-undefvarerror-local-d-not-defined-in-main/131296/2 "2025-08-05T10:32:14Z")

</div>

Welcome to the Julia community!

> [@darkg3n3sis](#):
>
> Sorry for the bad formatting

Please read [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) to improve your formatting.

* * *

I’ve tried to run your code with `CUDABackend()`. Apart from changing a `ROCArray` into a `CuArray` I also had to

- change `temp = @localmem(Int32, group_sz)` into `@temp = @localmem(Int32, GROUP_SIZE)`
- remove the `wait(total_found)`
- add `KADevice` to `output_indices = KernelAbstractions.zeros(Int32, count)`.

Then I get `Int32[3, 4, 6, 8]`, which I assume is the desired output.

* * *

Based on the documentation, I cannot really tell what is the point of `@private`. Coming from CUDA.jl I don’t see why you couldn’t just write `local_d = 1`. And indeed you can: the `CUDABackend()` code runs perfectly fine in this manner. But it does seem important when using `CPU()` as backend.

The issue when using `@private local_d = 1` turns out to be in the `local_d *= 2` line. Seemingly `local_d` across threads is represented as an `NTuple{256, Int64}` (with `256 == @groupsize()`) and stuff starts to break down after the (attempted) reassignment. So a MWE for the issue is

```julia-repl
julia> @kernel function kern()
           @private var = 1
           var *= 2
       end

julia> kern(CPU(), 1, 1)()
ERROR: MethodError: no method matching setindex!(::Tuple{Int64}, ::Int64, ::Int64)
(...)

```

This looks like a bug to me.

---

_[View the full topic](https://discourse.julialang.org/t/error-loaderror-undefvarerror-local-d-not-defined-in-main/131296)._
