Open chunhualiao opened 4 years ago
//https://lc.llnl.gov/confluence/display/LC/Clang+OpenMP+4.5+with+GPU+support#space-menu-link-content
#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;
}
results
liao6@ip-128-115-246-7:~$ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda hasGPU.c
clang-10: warning: Unknown CUDA version 10.2. Assuming the latest supported version 10.1 [-Wunknown-cuda-version]
clang-10: warning: No library 'libomptarget-nvptx-sm_70.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices. [-Wopenmp-target]
liao6@ip-128-115-246-7:~$ ./a.out
./a.out: error while loading shared libraries: libomp.so: cannot open shared object file: No such file or directory
liao6@ip-128-115-246-7:~$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/liao6/opt/llvm-10.0.0/lib
liao6@ip-128-115-246-7:~$ ./a.out
### Unable to use the GPU, using CPU! ###
No more warning about libomptarget lib. But the code still does not behave as expected.
//https://lc.llnl.gov/confluence/display/LC/Clang+OpenMP+4.5+with+GPU+support#space-menu-link-content
// Revised a bit
#include <stdio.h>
#include <omp.h>
int main()
{
int runningOnGPU = 0;
printf ("The number of target devices =%d\n", omp_get_num_devices());
/* Test if GPU is available using OpenMP4.5 */
#pragma omp target map(from:runningOnGPU)
{
// This function returns true if currently running on the host device, false otherwise.
if (!omp_is_initial_device())
runningOnGPU = 1;
}
/* If still running on CPU, GPU must not be available */
if (runningOnGPU == 1)
printf("### Able to use the GPU! ### \n");
else
printf("### Unable to use the GPU, using CPU! ###\n");
return 0;
}
liao6@ip-128-115-246-7:~$ clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda hasGPU.c
clang-10: warning: Unknown CUDA version 10.2. Assuming the latest supported version 10.1 [-Wunknown-cuda-version]
liao6@ip-128-115-246-7:~$ ./a.out
The number of target devices =0
### Unable to use the GPU, using CPU! ###
@ouankou Can you test the instructions on http://freecompilercamp.org/llvm-openmp-build/ using the GPU machine? I updated them a few weeks back and I need someone to review/test them.
part of the process to revise the steps, ask the official steps.
https://hpc-wiki.info/hpc/Building_LLVM/Clang_with_OpenMP_Offloading_to_NVIDIA_GPUs
Later deployed in AWS gpu instance