# Strange behaviour of @cuprintf?

**URL:** <https://discourse.julialang.org/t/strange-behaviour-of-cuprintf/11635>\
**Category:** GPU\
**Created:** [June 13, 2018, 8:23am UTC](https://discourse.julialang.org/t/strange-behaviour-of-cuprintf/11635 "2018-06-13T08:23:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [June 13, 2018, 8:23am UTC](https://discourse.julialang.org/t/strange-behaviour-of-cuprintf/11635/1 "2018-06-13T08:23:44Z")

</div>

I modified the example from the `CUDAnative` readme as follows. Am I using `@cuprintf` in the wrong way?

```julia
function kernel_vadd(a, b, c)
    i = (blockIdx().x-1) * blockDim().x + threadIdx().x
    @cuprintf("blockx= %d, blockDx=%d, threadid=%d\n",(blockIdx().x-1) , blockDim().x , threadIdx().x)
    c[i] = a[i] + b[i]

    return nothing
end

a = round.(rand(Float32, (3, 4)))
b = round.(rand(Float32, (3, 4)))
d_a = CuArray(a)
d_b = CuArray(b)
d_c = similar(d_a) # output array

julia> @cuda threads=12 kernel_vadd(d_a, d_b, d_c)

julia> blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12
blockx= 0, blockDx=0, threadid=12

```

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [June 13, 2018, 9:30am UTC](https://discourse.julialang.org/t/strange-behaviour-of-cuprintf/11635/2 "2018-06-13T09:30:26Z")

</div>

[https://github.com/JuliaGPU/CUDAnative.jl/issues/190](https://github.com/JuliaGPU/CUDAnative.jl/issues/190)

Need to fix the examples. Use `%ld` or `%lld` on Windows as formatting string.

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [June 13, 2018, 12:07pm UTC](https://discourse.julialang.org/t/strange-behaviour-of-cuprintf/11635/3 "2018-06-13T12:07:09Z")

</div>

cool. which examples do you mean? I just did `%d` because that’s how I would use it in fortran and elsewhere, not because I saw an old example. could PR.

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [June 13, 2018, 12:34pm UTC](https://discourse.julialang.org/t/strange-behaviour-of-cuprintf/11635/4 "2018-06-13T12:34:24Z")

</div>

Oh ok, I had thought you were looking at [https://github.com/JuliaGPU/CUDAnative.jl/blob/master/examples/hello\_world.jl](https://github.com/JuliaGPU/CUDAnative.jl/blob/master/examples/hello_world.jl) where the formatting string is wrong for Windows platforms.
