EPCCed / gpu-directives

Contains material for a course using GPU directives
0 stars 0 forks source link

Calling cuda/rocm libraries from openmp #2

Open lucaparisi91 opened 2 months ago

lucaparisi91 commented 2 months ago
lucaparisi91 commented 1 month ago

Pointers Translation

OpenMP to HIP/CUDA

You can get the device address of a host variable mapped to the device. An example is

double * x = ..... // allocate x on host
#pragma omp target data map(to:x[0:count]) 
{
    #pragma omp target data use_device_addr(x[:,0])
   { 
       // launch hip/cuda kernel here
       launch_my_hip_kernel(x)    
   }
}

HIP/Cuda to OpenMP

double * x_device;
allocate_and_copy_from_host_to_device() // cuda/hip code

#pragma omp target is_device_ptr(x_device)
{
  // code using x_device here
}