# How to generate Coverage for CUDA functions

**URL:** <https://discourse.julialang.org/t/how-to-generate-coverage-for-cuda-functions/43752>\
**Category:** New to Julia\
**Tags:** gpu, coverage\
**Created:** [July 27, 2020, 10:11am UTC](https://discourse.julialang.org/t/how-to-generate-coverage-for-cuda-functions/43752 "2020-07-27T10:11:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zitzeronion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zitzeronion/32/15006_2.png) [@Zitzeronion](https://discourse.julialang.org/u/Zitzeronion)\
**Post date:** [July 27, 2020, 10:11am UTC](https://discourse.julialang.org/t/how-to-generate-coverage-for-cuda-functions/43752/1 "2020-07-27T10:11:38Z")

</div>

Hey there I have a hard time getting the correct coverage for my small project.  
So I am trying to do simple CFD and run most of the computation on the GPU with CUDA.jl.

Everything works as I would expect it and the tests pass and show the correct results.  
Now when I try to get coverage from the tests all CUDA functions say they are not covered.  
Here is one of my functions:

```julia
function kernel_laplacianperiodic!(res, arg)
    len = size(res,1)
    wid = size(res,2)
    @inbounds for j = 1:wid 
        for i = 1:len
            # NN
            ip = mod1(i+1+len,len)
            im = mod1(i-1-len,len)
            jp = mod1(j+1+wid,wid)
            jm = mod1(j-1-wid,wid)

            # Computation
            res[i,j] = 1.0f0/6.0f0 * (4.0f0 * (arg[ip, j] + arg[im, j] + arg[i, jp] + arg[i, jm])
                                    + (arg[ip, jp] + arg[im, jp] + arg[im, jm] + arg[ip, jm])
                                    - 20.0f0 * arg[i, j])
        end
    end
    return nothing
end

```

And I test this with:

```julia
@testset "kernel_laplacianperiodic" begin
        x = reshape(collect(1.0f0:25.0f0),5,5)
        xcu = cu(x) 
        y = CUDA.zeros(5,5)
        @cuda blocks=(4,4) threads=(8,8) kernel_laplacianperiodic!(y, xcu)
        @test isa(y, CuArray{Float32,2,Nothing})
        result = zeros(5,5)
        result[1,1] = 30.0; result[1,2] = 5.0; result[1,3] = 5.0; result[1,4] = 5.0; result[1,5] = -20.0;  
        result[2,1] = 25.0; result[2,5] = -25.0;  
        result[3,1] = 25.0; result[3,5] = -25.0;  
        result[4,1] = 25.0; result[4,5] = -25.0;  
        result[5,1] = 20.0; result[5,2] = -5.0; result[5,3] = -5.0; result[5,4] = -5.0; result[5,5] = -30.0;
        yy = Array(y)
        @test yy == result    
    end

```

The test passes and in my .cov file I can see that the lines are executed, but somehow in the coverages output it says that the functions has no coverage at all.  
Is there a simple way to fix it? Yes I ran the tests on an machine with GPUs. I use Coverage.jl v1.1.1 and julia v1.4.2 on linux

---

<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:** [July 27, 2020, 2:08pm UTC](https://discourse.julialang.org/t/how-to-generate-coverage-for-cuda-functions/43752/2 "2020-07-27T14:08:13Z")

</div>

Code coverage is not supported GPU-side. As a workaround, you can use `COV_EXCL_START` and `COV_EXCL_STOP` markers around kernel code.

---

<div class="post-metadata">

**Author:** ![Zitzeronion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zitzeronion/32/15006_2.png) [@Zitzeronion](https://discourse.julialang.org/u/Zitzeronion)\
**Post date:** [July 27, 2020, 4:56pm UTC](https://discourse.julialang.org/t/how-to-generate-coverage-for-cuda-functions/43752/3 "2020-07-27T16:56:40Z")

</div>

I see, thanks for the quick response 🙂
