Repository: spack/spack

Issue:
Installation issue: Kokkos does not support multiple `cuda_arch`
### Steps to reproduce the issue

```console
$ spack spec -I kokkos+cuda+cuda_lambda+wrapper cuda_arch=60,70
Input spec
--------------------------------
 -   kokkos+cuda+cuda_lambda+wrapper cuda_arch=60,70

Concretized
--------------------------------
 -   kokkos@4.0.00%gcc@11.3.0~aggressive_vectorization~compiler_warnings+cuda~cuda_constexpr+cuda_lambda~cuda_ldg_intrinsic~cuda_relocatable_device_code~cuda_uvm~debug~debug_bounds_check~debug_dualview_modify_check~deprecated_code~examples~explicit_instantiation~hpx~hpx_async_dispatch~hwloc~ipo~memkind~numactl~openmp~openmptarget~pic+profiling~profiling_load_print~pthread~qthread~rocm+serial+shared~sycl~tests~tuning+wrapper build_system=cmake build_type=RelWithDebInfo cuda_arch=60,70 generator=make intel_gpu_arch=none std=17 arch=linux-almalinux8-x86_64_v3
[+]      ^cmake@3.26.3%gcc@11.3.0~doc+ncurses+ownlibs~qt build_system=generic build_type=Release arch=linux-almalinux8-x86_64_v3
[+]          ^ncurses@6.4%gcc@11.3.0~symlinks+termlib abi=none build_system=autotools arch=linux-almalinux8-x86_64_v3
[+]              ^pkgconf@1.8.0%gcc@11.3.0 build_system=autotools arch=linux-almalinux8-x86_64_v3
[+]          ^openssl@1.1.1t%gcc@11.3.0~docs~shared build_system=generic certs=mozilla arch=linux-almalinux8-x86_64_v3
[+]              ^ca-certificates-mozilla@2023-01-10%gcc@11.3.0 build_system=generic arch=linux-almalinux8-x86_64_v3
[+]              ^perl@5.36.0%gcc@11.3.0+cpanm+open+shared+threads build_system=generic arch=linux-almalinux8-x86_64_v3
[+]                  ^berkeley-db@18.1.40%gcc@11.3.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-almalinux8-x86_64_v3
[+]                  ^bzip2@1.0.8%gcc@11.3.0~debug~pic+shared build_system=generic arch=linux-almalinux8-x86_64_v3
[+]                      ^diffutils@3.9%gcc@11.3.0 build_system=autotools arch=linux-almalinux8-x86_64_v3
[+]                  ^gdbm@1.23%gcc@11.3.0 build_system=autotools arch=linux-almalinux8-x86_64_v3
[+]                      ^readline@8.2%gcc@11.3.0 build_system=autotools patches=bbf97f1 arch=linux-almalinux8-x86_64_v3
[+]              ^zlib@1.2.13%gcc@11.3.0+optimize+pic+shared build_system=makefile arch=linux-almalinux8-x86_64_v3
[+]      ^cuda@11.8.0%gcc@11.3.0~allow-unsupported-compilers~dev build_system=generic arch=linux-almalinux8-x86_64_v3
[+]          ^libxml2@2.10.3%gcc@11.3.0~python build_system=autotools arch=linux-almalinux8-x86_64_v3
[+]              ^libiconv@1.17%gcc@11.3.0 build_system=autotools libs=shared,static arch=linux-almalinux8-x86_64_v3
[+]              ^xz@5.4.1%gcc@11.3.0~pic build_system=autotools libs=shared,static arch=linux-almalinux8-x86_64_v3
[+]      ^gmake@4.4.1%gcc@11.3.0~guile build_system=autotools arch=linux-almalinux8-x86_64_v3
[+]      ^kokkos-nvcc-wrapper@3.2.00%gcc@11.3.0+mpi build_system=generic arch=linux-almalinux8-x86_64_v3
[+]          ^hpcx-mpi@2.9.0%gcc@11.3.0 build_system=generic arch=linux-almalinux8-x86_64_v3
```

### Error message

<details><summary>Error message</summary>

<pre>
==> Installing kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62
==> No binary for kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62 found: installing from source
==> Using cached archive: /anfhome/spack/var/spack/cache/_source-cache/archive/18/1829a423883d4b44223c7c3a53d3c51671145aad57d7d23e6a1a4bebf710dcf6.tar.gz
==> No patches needed for kokkos
==> kokkos: Executing phase: 'cmake'
==> Error: ProcessError: Command exited with status 1:
    '/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/cmake-3.26.3-467jnpp7mfhqlru4ornzk3klqam5ynno/bin/cmake' '-G' 'Unix Makefiles' '-DCMAKE_INSTALL_PREFIX:STRING=/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62' '-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo' '-DBUILD_TESTING:BOOL=OFF' '-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF' '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON' '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=ON' '-DCMAKE_INSTALL_RPATH:STRING=/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62/lib;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62/lib64;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/libxml2-2.10.3-wyc4xkv7vtxujjfe25s2lrwtpz3z62wl/lib;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/libiconv-1.17-e5ymnmaoonwmmwvadiq6nwsf5lccrslr/lib;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/xz-5.4.1-yxjac4bcriikc6ksa6i5l6ryrej6s43t/lib;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/zlib-1.2.13-wtjrjn6euwvbl3e4vanh3glmd7yimsgg/lib;/opt/hpcx-v2.13-gcc-MLNX_OFED_LINUX-5-redhat8-cuda11-gdrcopy2-nccl2.12-x86_64/ompi/lib;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/cuda-11.8.0-wvtqd2ksmmya75xl6aphhvmmkjl7f3nb/lib64' '-DCMAKE_PREFIX_PATH:STRING=/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/kokkos-nvcc-wrapper-3.2.00-p3y4zu6bskdvw634etsw7lkfsinm7upa;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/gmake-4.4.1-ccx67ikj66zvgv6vvgpphxem3k4bq7h5;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/cuda-11.8.0-wvtqd2ksmmya75xl6aphhvmmkjl7f3nb;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/cuda-11.8.0-wvtqd2ksmmya75xl6aphhvmmkjl7f3nb/targets/x86_64-linux/lib/cmake;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/libxml2-2.10.3-wyc4xkv7vtxujjfe25s2lrwtpz3z62wl;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/xz-5.4.1-yxjac4bcriikc6ksa6i5l6ryrej6s43t;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/cmake-3.26.3-467jnpp7mfhqlru4ornzk3klqam5ynno;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/zlib-1.2.13-wtjrjn6euwvbl3e4vanh3glmd7yimsgg;/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/libiconv-1.17-e5ymnmaoonwmmwvadiq6nwsf5lccrslr;/opt/hpcx-v2.13-gcc-MLNX_OFED_LINUX-5-redhat8-cuda11-gdrcopy2-nccl2.12-x86_64/ompi' '-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF' '-DCMAKE_CXX_STANDARD:STRING=17' '-DBUILD_SHARED_LIBS:BOOL=ON' '-DKokkos_ARCH_PASCAL60:BOOL=ON' '-DKokkos_ARCH_VOLTA70:BOOL=ON' '-DKokkos_ENABLE_CUDA:BOOL=ON' '-DKokkos_ENABLE_OPENMP:BOOL=OFF' '-DKokkos_ENABLE_PTHREAD:BOOL=OFF' '-DKokkos_ENABLE_SERIAL:BOOL=ON' '-DKokkos_ENABLE_HIP:BOOL=OFF' '-DKokkos_ENABLE_SYCL:BOOL=OFF' '-DKokkos_ENABLE_OPENMPTARGET:BOOL=OFF' '-DKokkos_ENABLE_AGGRESSIVE_VECTORIZATION:BOOL=OFF' '-DKokkos_ENABLE_COMPILER_WARNINGS:BOOL=OFF' '-DKokkos_ENABLE_CUDA_CONSTEXPR:BOOL=OFF' '-DKokkos_ENABLE_CUDA_LAMBDA:BOOL=ON' '-DKokkos_ENABLE_CUDA_LDG_INTRINSIC:BOOL=OFF' '-DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE:BOOL=OFF' '-DKokkos_ENABLE_CUDA_UVM:BOOL=OFF' '-DKokkos_ENABLE_DEBUG:BOOL=OFF' '-DKokkos_ENABLE_DEBUG_BOUNDS_CHECK:BOOL=OFF' '-DKokkos_ENABLE_DEBUG_DUALVIEW_MODIFY_CHECK:BOOL=OFF' '-DKokkos_ENABLE_DEPRECATED_CODE:BOOL=OFF' '-DKokkos_ENABLE_EXAMPLES:BOOL=OFF' '-DKokkos_ENABLE_EXPLICIT_INSTANTIATION:BOOL=OFF' '-DKokkos_ENABLE_HPX_ASYNC_DISPATCH:BOOL=OFF' '-DKokkos_ENABLE_PROFILING:BOOL=ON' '-DKokkos_ENABLE_TUNING:BOOL=OFF' '-DKokkos_ENABLE_PROFILING_LOAD_PRINT:BOOL=OFF' '-DKokkos_ENABLE_QTHREAD:BOOL=OFF' '-DKokkos_ENABLE_TESTS:BOOL=OFF' '-DKokkos_ENABLE_HPX:BOOL=OFF' '-DKokkos_ENABLE_HWLOC:BOOL=OFF' '-DKokkos_ENABLE_NUMACTL:BOOL=OFF' '-DKokkos_ENABLE_MEMKIND:BOOL=OFF' '-DCMAKE_CXX_COMPILER:STRING=/anfhome/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placehold/linux-almalinux8-x86_64_v3/gcc-11.3.0/kokkos-nvcc-wrapper-3.2.00-p3y4zu6bskdvw634etsw7lkfsinm7upa/bin/nvcc_wrapper' '/mnt/scratch/root/spack-stage/spack-stage-kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62/spack-src'

1 error found in build log:
     8     -- Detecting CXX compile features
     9     -- Detecting CXX compile features - done
     10    -- The project name is: Kokkos
     11    -- Using internal gtest for testing
     12    -- Compiler Version: 11.8.89
     13    -- Using -std=c++17 for C++17 standard as feature
  >> 14    CMake Error at cmake/kokkos_arch.cmake:531 (MESSAGE):
     15      Multiple GPU architectures given! Already have PASCAL60, but trying to add
     16      VOLTA70.  If you are re-running CMake, try clearing the cache and running
     17      again.
     18    Call Stack (most recent call first):
     19      cmake/kokkos_arch.cmake:574 (CHECK_CUDA_ARCH)
     20      cmake/kokkos_tribits.cmake:244 (INCLUDE)

See build log for details:
  /mnt/scratch/root/spack-stage/spack-stage-kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62/spack-build-out.txt

make: *** [Makefile:24: /anfhome/spack/var/spack/environments/Test/.spack-env/makedeps/install/kokkos-4.0.00-b77vp7lbjauthvu5iriuonvh22vc5s62] Error 1
</pre></details>


### Information on your system

* **Spack:** 0.20.0.dev0 (be1c9ac6e6b8aebdb6f090830766f761c93557a6)
* **Python:** 3.9.16
* **Platform:** linux-almalinux8-zen2
* **Concretizer:** clingo

### Additional information

Kokkos can only take one `cuda_arch` at a time, when is built with `+cuda`.
I will submit a PR to raise an error in case multiple `cuda_arch` are specified.

@crtrott  @janciesko 
[spack-build-env.txt](https://github.com/spack/spack/files/11951293/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/11951294/spack-build-out.txt)

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/kokkos/package.py b/var/spack/repos/builtin/packages/kokkos/package.py
--- a/var/spack/repos/builtin/packages/kokkos/package.py
+++ b/var/spack/repos/builtin/packages/kokkos/package.py
@@ -138,6 +138,17 @@ class Kokkos(CMakePackage, CudaPackage, ROCmPackage):
     cuda_arches = spack_cuda_arch_map.values()
     conflicts("+cuda", when="cuda_arch=none")
 
+    # Kokkos support only one cuda_arch at a time
+    variant(
+        "cuda_arch",
+        description="CUDA architecture",
+        values=("none",) + CudaPackage.cuda_arch_values,
+        default="none",
+        multi=False,
+        sticky=True,
+        when="+cuda",
+    )
+
     amdgpu_arch_map = {
         "gfx900": "vega900",
         "gfx906": "vega906",
@@ -288,11 +299,16 @@ def cmake_args(self):
 
         spack_microarches = []
         if "+cuda" in spec:
-            # this is a list
-            for cuda_arch in spec.variants["cuda_arch"].value:
-                if not cuda_arch == "none":
-                    kokkos_arch_name = self.spack_cuda_arch_map[cuda_arch]
-                    spack_microarches.append(kokkos_arch_name)
+            if isinstance(spec.variants["cuda_arch"].value, str):
+                cuda_arch = spec.variants["cuda_arch"].value
+            else:
+                if len(spec.variants["cuda_arch"].value) > 1:
+                    msg = "Kokkos supports only one cuda_arch at a time."
+                    raise InstallError(msg)
+                cuda_arch = spec.variants["cuda_arch"].value[0]
+            if cuda_arch != "none":
+                kokkos_arch_name = self.spack_cuda_arch_map[cuda_arch]
+                spack_microarches.append(kokkos_arch_name)
 
         kokkos_microarch_name = self.get_microarch(spec.target)
         if kokkos_microarch_name:


Test patch: