Compile OpenMP application with target pragma on Nvidia GPU

Viewed 186

I’m trying to compile and run an application with OpenMP target pragma that checks if it runs on GPU or CPU.

#include <stdio.h>
#include <omp.h>

int main()
{
int runningOnGPU = 0;
/* Test if GPU is available using OpenMP4.5 */
#pragma omp target map(from:runningOnGPU)
{
if (omp_is_initial_device() == 0)
runningOnGPU = 1;
}
/* If still running on CPU, GPU must not be available */
if (runningOnGPU)
printf("### Able to use the GPU! ### \n");
else
printf("### Unable to use the GPU, using CPU! ###\n");

return 0;
}

My OS is Ubunto 18.04 LTS, GPU - Quadro P4000, the driver is nvidia-driver-440-server and Cuda version 10.0.

I tried to follow those documents but none of them worked. https://freecompilercamp.org/llvm-openmp-build/ - segmentation fault with this build command

clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda ongpu.c

https://github.com/clang-ykt/clang/wiki - build error

https://kristerw.blogspot.com/2017/04/building-gcc-with-support-for-nvidia.html - compilation error

https://on-demand.gputechconf.com/gtc/2016/presentation/s6510-jeff-larkin-targeting-gpus-openmp.pdf - - compilation error

Where can I find a document with instructions on how to build a simple OpenMP application that runs on GPU?

0 Answers
Related