When trying to use openmp target offloading with llvm I get the following error
$ cat offload.cpp
#include <omp.h>
int main() {
#pragma omp target teams distribute parallel for
for(int i=0; i<100; i++);
return 0;
}
$ clang++ -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda --cuda-path=$CUDA_TOOLKIT_ROOT_DIR offload.cpp -o offload
$ ./offload
Libomptarget fatal error 1: default offloading policy must switched to mandatory or disabled
$
.
I have llvm-8.0.0 installed in my system at LLVM_PATH. I downloaded openmp-8.0.0 source from the llvm download page. To build openmp I used the following command:
$ mkdir build && cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$LLVM_PATH -DCMAKE_C_COMPILER=$LLVM_PATH/bin/clang -DCMAKE_CXX_COMPILER= $LLVM_PATH/bin/clang++ -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=35,60,70 ..
$ make && make install
OpenMP got built without giving any error. But when trying to use target offloading with OpenMP I get the above mentioned fatal error. I tried this on 3 different machines, with same result.
I am able to build and run CUDA examples on my system with nvcc.
Regards,
Alok
I found the answer. To make sure we compile for offloading we need to use the flags:
-Xopenmp-target -march=sm_XX
where XX is the compute capability. So for me
clang++ -Xopenmp-target -march=sm_35 -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda --cuda-path=$CUDA_TOOLKIT_ROOT_DIR offload.cpp -o offload
worked