Skip to content

Commit

Permalink
Make libcudacxx respect CMake options for CUDA archs. (#235)
Browse files Browse the repository at this point in the history
* Allow compute_archs to be parsed with several sane delimiters

* Remove compute_future stuff, just parse CMake options
  • Loading branch information
wmaxey authored Jul 17, 2023
1 parent c44b5b7 commit ca0f635
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
10 changes: 3 additions & 7 deletions libcudacxx/.upstream-tests/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ foreach (COMPUTE_ARCH ${LIBCUDACXX_COMPUTE_ARCHS})
set(LIBCUDACXX_COMPUTE_ARCHS_STRING "${LIBCUDACXX_COMPUTE_ARCHS_STRING} ${COMPUTE_ARCH}")
endforeach ()

option(LIBCUDACXX_ENABLE_COMPUTE_FUTURE "Enable code generation for tests for compute_${LIBCUDACXX_HIGHEST_COMPUTE_ARCH}" OFF)
if (LIBCUDACXX_ENABLE_COMPUTE_FUTURE)
set(_compute_message "${_compute_message} compute_${LIBCUDACXX_HIGHEST_COMPUTE_ARCH}")
endif ()

message(STATUS "Enabled CUDA architectures:${_compute_message}")

option(LIBCUDACXX_TEST_WITH_NVRTC
Expand Down Expand Up @@ -67,6 +62,9 @@ if (${CMAKE_CUDA_COMPILER_ID} STREQUAL "NVHPC")
-stdpar")
endif()

set(LIBCUDACXX_COMPUTE_ARCHS_STRING
"${CMAKE_CUDA_ARCHITECTURES}")

include(AddLLVM)

set(LIBCUDACXX_TARGET_INFO "libcudacxx.test.target_info.LocalTI" CACHE STRING
Expand All @@ -83,8 +81,6 @@ endif()

set(AUTO_GEN_COMMENT "## Autogenerated by libcudacxx configuration.\n# Do not edit!")

pythonize_bool(LIBCUDACXX_ENABLE_COMPUTE_FUTURE)

configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
Expand Down
1 change: 0 additions & 1 deletion libcudacxx/.upstream-tests/test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ config.test_linker_flags = "@LIBCUDACXX_TEST_LINKER_FLAGS@"
config.test_compiler_flags = "@LIBCUDACXX_TEST_COMPILER_FLAGS@"

config.compute_archs = "@LIBCUDACXX_COMPUTE_ARCHS_STRING@"
config.enable_compute_future = @LIBCUDACXX_ENABLE_COMPUTE_FUTURE@
config.nvcc_host_compiler = "@CMAKE_CUDA_HOST_COMPILER@"

config.executor = "@LIBCUDACXX_EXECUTOR@"
Expand Down
16 changes: 9 additions & 7 deletions libcudacxx/.upstream-tests/utils/libcudacxx/test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,18 +588,20 @@ def configure_compile_flags(self):
pre_sm_70 = False
pre_sm_80 = False
pre_sm_90 = False
compute_archs = [int(a) for a in sorted(shlex.split(compute_archs))]
for arch in compute_archs:
compute_archs = set(sorted(re.split('\s|;|,', compute_archs)))
for s in compute_archs:
# Split arch and mode i.e. 80-virtual -> 80, virtual
arch, *mode = re.split('-', s)
arch = int(arch)
if arch < 32: pre_sm_32 = True
if arch < 60: pre_sm_60 = True
if arch < 70: pre_sm_70 = True
if arch < 80: pre_sm_80 = True
if arch < 90: pre_sm_90 = True
arch_flag = '-gencode=arch=compute_{0},code=sm_{0}'.format(arch)
self.cxx.compile_flags += [arch_flag]
enable_compute_future = self.get_lit_conf('enable_compute_future')
if enable_compute_future:
arch_flag = '-gencode=arch=compute_{0},code=compute_{0}'.format(arch)
if mode.count("virtual"):
arch_flag = '-gencode=arch=compute_{0},code=compute_{0}'.format(arch)
else:
arch_flag = '-gencode=arch=compute_{0},code=sm_{0}'.format(arch)
self.cxx.compile_flags += [arch_flag]
if pre_sm_32:
self.config.available_features.add("pre-sm-32")
Expand Down

0 comments on commit ca0f635

Please sign in to comment.