ecmwf-ifs / ectrans

Global spherical harmonics transforms library underpinning the IFS
Apache License 2.0
19 stars 35 forks source link

GPU branches: Missing dependency imports in ectrans-import.cmake #92

Open reuterbal opened 7 months ago

reuterbal commented 7 months ago

For $reason I attempted a standalone build of redgreengpu (outside of a bundle) on an NVIDIA GPU machine and link IFS in a bundle build against it. (I can share more details if required.)

In that scenario, ectrans is imported into ifs-source via the CMake config files. The link interfaces in ectrans-targets.cmake include (correctly) CUDA::cufft, CUDA::cublas and OpenACC::OpenACC_Fortran. However, the dependencies to CUDAToolkit and OpenACC are not captured in the corresponding ectrans-import.cmake.

The import file does correctly issue the dependencies on OpenMP and fiat, but from a quick glance I wasn't able to figure out how to achieve the same for OpenACC, CUDA and CUDAToolkit. Manually editing the file and adding the following worked:

    if( NOT CMAKE_CUDA_COMPILER_LOADED )
        enable_language( CUDA )
    endif()
    find_dependency( CUDAToolkit )
    find_package( OpenACC )
    if( OpenACC_Fortran_FOUND AND OpenACC_C_FOUND )
        set( OpenACC_FOUND ON )
    endif()

For some reason, using find_dependency(OpenACC) did not work and made the entire ectrans import fail. Using instead find_package and doing the usual set(OpenACC_FOUND ON) hack worked.

Presumably, similar issues would appear with HIP on AMD platforms, and are likely affecting the optimised GPU branch, too.

@wdeconinck might have an idea where the CMake needs to be changed for this?

wdeconinck commented 7 months ago

Hi @reuterbal which version of CMake is used?

From my tests of a "find_package( CUDAToolkit )" it is not required that CUDA is enabled as language, so that find_dependency( CUDAToolkit ) should be sufficient.

CUDA should also not be required for find_package( OpenACC ) The reason that find_dependency( OpenACC ) might not have worked here, is when you have this triggered due to find_package( ectrans REQUIRED ) it then implicitly adds the REQUIRED keyword to all find_dependency: find_dependency( OpenACC REQUIRED ) which fails due to the "usual" workaround issue. That is in fact the only difference between find_package and find_dependency: find_dependency inherits REQUIRED from the parent find_package.

reuterbal commented 7 months ago

Thanks! As discussed offline, CUDA is probably redundant, I didn't check this carefully enough.

The CMake version was 3.24.3, so you're likely right that this may be the issue with OpenACC_FOUND not being set.