|
6 | 6 | # the terms of the Apache License 2.0 which accompanies this distribution. # |
7 | 7 | # ============================================================================ # |
8 | 8 |
|
9 | | -# Requering the same version as the others. |
| 9 | +# Requiring the same version as the others. |
10 | 10 | cmake_minimum_required(VERSION 3.28 FATAL_ERROR) |
11 | 11 |
|
12 | 12 | # Project setup |
@@ -52,6 +52,44 @@ option(CUDAQX_QEC_INSTALL_PYTHON |
52 | 52 | "Install python files alongside the library." |
53 | 53 | ${CUDAQX_INSTALL_PYTHON}) |
54 | 54 |
|
| 55 | +# Check for CUDA Support (ref: cuda-quantum/CMakeLists.txt) |
| 56 | +# ============================================================================== |
| 57 | +include(CheckLanguage) |
| 58 | +check_language(CUDA) |
| 59 | +set(CUDA_FOUND FALSE) |
| 60 | +# Generate -gencode arch=compute_XX,code=sm_XX for list of supported |
| 61 | +# arch values. |
| 62 | +# List should be sorted in increasing order. |
| 63 | +function(CUDA_get_gencode_args out_args_string arch_values) |
| 64 | + # allow the user to pass the list like a normal variable |
| 65 | + set(arch_list ${arch_values} ${ARGN}) |
| 66 | + set(out "") |
| 67 | + foreach(arch IN LISTS arch_list) |
| 68 | + set(out "${out} -gencode arch=compute_${arch},code=sm_${arch}") |
| 69 | + endforeach(arch) |
| 70 | + |
| 71 | + # Repeat the last one as to ensure the generation of PTX for most |
| 72 | + # recent virtual architecture for forward compatibility |
| 73 | + list(GET arch_list -1 last_arch) |
| 74 | + set(out "${out} -gencode arch=compute_${last_arch},code=compute_${last_arch}") |
| 75 | + set(${out_args_string} ${out} PARENT_SCOPE) |
| 76 | +endfunction() |
| 77 | + |
| 78 | +if(CMAKE_CUDA_COMPILER) |
| 79 | + if (NOT CUDA_TARGET_ARCHS) |
| 80 | + # Volta, Ampere, Hopper |
| 81 | + set(CUDA_TARGET_ARCHS "70;80;90") |
| 82 | + endif() |
| 83 | + CUDA_get_gencode_args(CUDA_gencode_flags ${CUDA_TARGET_ARCHS}) |
| 84 | + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -shared -std=c++17 ${CUDA_gencode_flags} --compiler-options -fPIC") |
| 85 | + |
| 86 | + enable_language(CUDA) |
| 87 | + set(CUDA_FOUND TRUE) |
| 88 | + set(CMAKE_CUDA_STANDARD 17) |
| 89 | + set(CMAKE_CUDA_STANDARD_REQUIRED TRUE) |
| 90 | + message(STATUS "Cuda language found.") |
| 91 | +endif() |
| 92 | + |
55 | 93 | # External Dependencies |
56 | 94 | # ============================================================================== |
57 | 95 |
|
|
0 commit comments