Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope out usage of CUDA as cmake language #135

Open
bartgol opened this issue Sep 14, 2021 · 1 comment
Open

Scope out usage of CUDA as cmake language #135

bartgol opened this issue Sep 14, 2021 · 1 comment
Labels
cmake code quality CUDA enhancement New feature or request help wanted Extra attention is needed

Comments

@bartgol
Copy link
Contributor

bartgol commented Sep 14, 2021

Idea: do not rely on nvcc_wrapper for the cuda-vs-host compiler magic, but use native CMake stuff (assuming cmake version is 3.18 or higher). Possible approach: set a var CXX_LANG which evaluates to CXX for non-cuda builds, and to CUDA for cuda builds. Then manually set the language of all src files to ${CXX_LANG}, to force compilation with the proper compiler.

I speculate that this would also allow to get stuff like

target_compile_features(mylib PRIVATE cxx_constexpr)

to work correctly. I think the nvcc_wrapper layer is somehow blocking communication between the compiler and cmake, preventing correct detection of cxx features. By using native CMake support for CUDA, I suspect this could be fixed, since cmake would invoke nvcc for compiling CUDA sources, folllowed by an invoke of the host compiler on the generated intermediate cpp source.

@bartgol bartgol added enhancement New feature or request help wanted Extra attention is needed cmake CUDA code quality labels Sep 14, 2021
@bartgol
Copy link
Contributor Author

bartgol commented Sep 14, 2021

E.g., do something like this:

...
if (Kokkos_ENABLE_CUDA)
  set(Kokkos_LANG CUDA)
else ()
  set (Kokkos_LANG CXX)
endif()
project (ekat C Fortran ${Kokkos_LANG})
...

add_library(ekat ${EKAT_SOURCES})
set_source_files_properties (${EKAT_SOURCES} PROPERTIES LANGUAGE ${Kokkos_LANG})

This should a) be made flexible so to only set the language for cxx sources (do a foreach over src files, check file language, if cxx, then override with ${Kokkos_LANG}), and b) provide macros for downstream apps to create libs/execs, and do this language setting magic inside these macros. Something like

macro(ekat_add_library libName ...)
  add_library(${libName} ...)
  # set LANGUAGE=${Kokkos_LANG} for all CXX sources
endmacro()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake code quality CUDA enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant