# General question on GPU Programming and on how to use low level C API

**URL:** https://discourse.julialang.org/t/general-question-on-gpu-programming-and-on-how-to-use-low-level-c-api/39526
**Category:** GPU
**Tags:** question
**Created:** [May 15, 2020, 2:09pm UTC](https://discourse.julialang.org/t/general-question-on-gpu-programming-and-on-how-to-use-low-level-c-api/39526 "2020-05-15T14:09:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Olivier\_Gagnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivier_gagnon/32/13182_2.png) [@Olivier\_Gagnon](https://discourse.julialang.org/u/Olivier_Gagnon)
#### Post date: [May 15, 2020, 2:09pm UTC](https://discourse.julialang.org/t/general-question-on-gpu-programming-and-on-how-to-use-low-level-c-api/39526/1 "2020-05-15T14:09:58Z")

</div>

Hey everyone,

I just started to learn GPU Programming (and also rather new to Julia). I am currently trying to go through Cuda by Example but reproducing everything in Julia.

I would have 2 questions (everything is executed in a Jupyter Notebook):

1. I have the following code to do a simple Hello World example.

```julia
using CUDAnative, CUDAdrv

function hello_world()
    @cuprintf("Hello Woarld from the GPU\n")
    return
end

```

If I run `@cuda hello_world()` in a different cell, there will be no output until I use `synchronize()`.

While, when I run `@cuda hello_world()` inside the same cell, I do get an output, but if I change the string I need to run it twice to see the new string. Again, if I add `synchronize()` this doesn’t happen (new string get printed first time I run the cell).

Not sure I understand what is happening here…

1. I am trying to run a low-level C API function `cuDeviceGetProperties`. For this, I need a `(prop, dev)` with type `(Ptr{CUdevprop}, CUdevice)` . For the device, I know I can get it with `CuDevice(0)`, but I have no idea for the prop…

I tried defining my own struct with similar field as in the book (which would likely not work since the field likely changed with new version of CUDA), and it fails.

Doing something similar to this :

```julia
using CUDAdrv

struct CUdevprop
    (define fields here)
end

prop = Ref{CUdevprop}()
CUDAdrv.cuDeviceGetProperties(prop,CuDevice(0))

```

Any help would be greatly appreciated 🙂

Thanks

---

<div class="post-metadata">

### Author: ![R366Y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/r366y/32/10970_2.png) [@R366Y](https://discourse.julialang.org/u/R366Y)
#### Post date: [October 14, 2020, 6:22pm UTC](https://discourse.julialang.org/t/general-question-on-gpu-programming-and-on-how-to-use-low-level-c-api/39526/2 "2020-10-14T18:22:12Z")

</div>

Hi Oliver ,  
regarding question n. 2, to get the device properties you can use **CUDA.attribute** function. E.g.

```julia
using CUDA

function print_gpu_properties()

    for (i,device) in enumerate(CUDA.devices())
        println(" ***General properties for device $i***")
        name = CUDA.name(device)
        println("Device name: $name")
        major = CUDA.attribute(device, CUDA.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR)
        minor = CUDA.attribute(device, CUDA.CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR)
        println("Compute capabilities: $major.$minor")
        clock_rate = CUDA.attribute(device, CUDA.CU_DEVICE_ATTRIBUTE_CLOCK_RATE)
        println("Clock rate: $clock_rate")
        device_overlap = CUDA.attribute(device, CUDA.CU_DEVICE_ATTRIBUTE_GPU_OVERLAP)
        print("Device copy overlap: ")
        println(device_overlap > 0 ? "enabled" : "disabled")
        kernel_exec_timeout = CUDA.attribute(device, CUDA.CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT)
        print("Kernel execution timeout: ")
        println(kernel_exec_timeout > 0 ? "enabled" : "disabled")
    end
end

```
