I am aware that cuda fortran and hipfort exist for NVIDIA and AMD GPUs. However, I don’t like the idea of being constrained to using nvfortran and hipfc to compile to get GPU support. I was thinking on writing a big module interface which basically does:
#ifdef CUDA
... bind(C,"cudaDeviceSynchronize")
#elif HIP
... bind(C,"hipDeviceSynchronize")
#else
??
#endif
For cuda/hip, cublas/hipblas, cusolver/hipsolver. Am I doing something extraordinarily stupid? I’ve done some initial tests and doing that and simply doing
gfortran -cpp a.F90 -L$CUDA_ROOT/lib -lcudart works fine.
I just would like some community feedback and a straight answer if what I am doing is a waste of my time and I should just force adopt hipfort and cuda fortran.
Unless you really need the fine-grained control of Cuda/HIP, or need to call some Cuda/HIP specific libraries, I’d go with OpenACC as the portable GPU option, or at least look into it.
Also Intel uses OpenMP for offloading to intel GPUs Solving Heterogeneous Programming Challenges with Fortran and OpenMP - Intel Community. nvfortran proposes OpenMP offloading syntax (If I understood correctly, it is actually calling OpenACC behind the curtains, not 100% sure). So OpenMP would look like a good candidate for a common denominator for portable GPU support (eventually).
I agree. GPU support in all languages are abysmal.
The most portable option we have, is to use OpenCL, which only compiles the kernel code during runtime.
However, to use OpenCL, we need to write our kernels in C, which sucks.
We should ask Khronos to support Fortran kernels in OpenCL, which they most likely won’t. Or we can write Fortran to C converters that transpile our Fortran kernel code to C, so OpenCL can run it.
one of the main things we’d use out of cuda and hip is cublas and hipblas. For many other things I can adapt to openmp, since OpenACC is not widely supported anymore. See Cray compilers for example.
FWIW, my recent experience on AMD GPUs with Cray compiler is that OpenACC support, although nowhere near as good as nvfortran support on nvidia GPUs, is much better than OpenMP offload support.