I've made a simple test program to offload a SAXPY workload to the GPU with openMP, but have been unable to detect the presence of the GPU. I'm unsure if the compiler is configured correctly for this purpose.
omp_get_num_devices()
returns 0, indicating there is no available target for offloading. omp_is_initial_device()
also returns 1 within the target region, which indicated it is falling back to the CPU. This machine has a 4070ti, an i7-11700 (which has an iGPU), and is running Linux Mint 21.
The command I am using for compilation is the following:
g++ -fopenmp -g -O2 saxpy.cpp -o saxpy
Running gcc -v
in order to determine if it is properly configured, I get the following:
Using built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapperOFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsaOFFLOAD_TARGET_DEFAULT=1Target: x86_64-linux-gnuConfigured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2Thread model: posixSupported LTO compression algorithms: zlib zstdgcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
Looking at --enable-offload-targets=nvptx-none
, I am inclined to believe it should be able to offload to the NVIDIA GPU on the machine. I am unsure how to proceed, how can I further diagnose the problem, and ultimately get at least one of the GPUs to be recognized and used for offloading?
Lastly, here is the source code. I believe this part isn't the source of the problem, but just in case:
#include <stdlib.h>#include <stdio.h>#include <omp.h>#define SAXPY_SIZE 1024*1024*1024void saxpy(float a, float* x, float* y, int sz) { double runtime = omp_get_wtime(); #pragma omp target device(1) map(to:x[0:sz]) map(tofrom:y[0:sz]) { #pragma omp parallel for simd firstprivate(a) for (size_t i = 0; i < sz; i++) { y[i] = a * x[i] + y[i]; } printf("%d\n", omp_is_initial_device()); } runtime = omp_get_wtime() - runtime; printf("%8d kb SAXPY Runtime: %lf\n", sz/1024, runtime);}int main(void) { float a, *x, *y; x = (float*)malloc(sizeof(float) * SAXPY_SIZE); y = (float*)malloc(sizeof(float) * SAXPY_SIZE); printf("%d devices\n", omp_get_num_devices()); for (size_t i = 4096; i <= SAXPY_SIZE; i *= 2) { saxpy(1.0, x, y, i); } return 0;}