19

It it possible to use openMP pragmas in the CUDA-Files (not in the kernel code)?

I will combine gpu and cpu computation. But nvvc compiler fails with "cannot find Unknown option 'openmp' ", if i am linking the porgram with a openmp option (under linux)

A wayaround is to use openMP-statments only in c/c++ files.

Z boson
  • 32,619
  • 11
  • 123
  • 226
LonliLokli
  • 1,295
  • 4
  • 15
  • 24

4 Answers4

21

I've just found this

http://www.cse.buffalo.edu/faculty/miller/Courses/CSE710/heavner.pdf

Page 25 says:

With gcc: -#include omp.h

Add the -fopenmp flag

With nvcc, this should be -Xcompiler -fopenmp as this needs to be passed directly to gcc -Xcompiler passes flags directly to host compiler

Add -lgomp flag during the linking stage.

I haven't tried it yet...

Doug Lipinski
  • 644
  • 4
  • 9
Javier Ruiz
  • 410
  • 4
  • 10
2

I tried writing the parameter in "Additional Compiler Options" but it didn't work.

What I did for Visual Studio 2010 and CUDA 4.2:

In Project Properties -> Configuration Properties -> CUDA C/C++ -> Command Line -> Additional Options: -Xcompiler "/openmp"

This resulted in two -Xcompiler parameters in the resulting build command but did not cause any problems and worked successfully.

Huseyin Yagli
  • 9,896
  • 6
  • 41
  • 50
0

The solution for the Visual Studio found from the nvidia-forum:

add the '/openmp'-flag to the Extra C++ Options in cuda build rules. I will try the linux solution later.

LonliLokli
  • 1,295
  • 4
  • 15
  • 24
0

Building with CMake

I had to add -Xcompiler=-fopenmp as an compile option to my CMakeLists.txt file to build CUDA host code with OpenMP directives:

# your CMakeLists.txt should contain something like this already
project(<project> Languages CXX CUDA)
find_package(CUDA REQUIRED)
find_package(OpenMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")

# the following line was also necessary
target_compile_options(<target> PRIVATE $<$<COMPILE_LANGUAGE:CUDA>: -Xcompiler=-fopenmp>)
Niklas
  • 180
  • 2
  • 6