Hey there,
I am trying to create a shared library utilising OpenMP offloading and nvc++. Unfortunately, I ran into some trouble using the library.
Let’s consider the following files:
- test_compute.cpp // does some computation with OpenMP offloading
- test.cpp // has int main() and uses the computation
Creating the library works fine:
nvc++ -g -O3 -std=c++17 -fpic -mp=gpu -shared test_compute.cpp -o libtest_compute.so
Compiling and linking with test.cpp
works also:
nvc++ -std=c++17 test.cpp -o test -L${PWD} -ltest_compute
However, when I execute the code, using OMP_TARGET_OFFLOAD=MANDATORY
, I’ll get the following error:
$ LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH OMP_TARGET_OFFLOAD=MANDATORY ./test
Fatal error: Could not run target region on device 0, execution terminated.
Aborted
When I add -mp=gpu
to the compilation and linking of test.cpp
:
nvc++ -std=c++17 -mp=gpu test.cpp -o test -L${PWD} -ltest_compute
everything works fine:
$ LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH OMP_TARGET_OFFLOAD=MANDATORY ./test
//some output
However, as I’d like to create a library that might be linked by any other program or compiler or even work as a Python module, specifying -mp=gpu
is not a solution for me.
Is there any way to make the library “self-contained”, i.e. I do not need to add -mp=gpu
while compiling test.cpp
?
If needed, I can also provide some test files.
I am using NVHPC 21.5:
$ nvc++ --version
nvc++ 21.5-0 LLVM 64-bit target on x86-64 Linux -tp zen
NVIDIA Compilers and Tools
Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
Best,
Andreas