Skip to content

Commit 5a7a261

Browse files
authored
Merge branch 'main' into pr-update-decoder-interface
2 parents 3e2bcc9 + 93becbf commit 5a7a261

File tree

4 files changed

+147
-1
lines changed

4 files changed

+147
-1
lines changed

CMakeLists.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,68 @@ if (CUDAQX_INCLUDE_TESTS)
9191
endif()
9292
endif()
9393

94+
# Hooks setup. If the repo contains a custom pre-push hook, attempt to install
95+
# it. If the user has a different one installed, then warn them but do not fail
96+
# configuration.
97+
# ==============================================================================
98+
99+
# Define the directory where your hooks are stored
100+
set(SRC_HOOK_PRE_PUSH "${CMAKE_SOURCE_DIR}/.githooks/pre-push")
101+
102+
if(EXISTS "${SRC_HOOK_PRE_PUSH}")
103+
# Get the Git hooks directory from the Git configuration
104+
execute_process(
105+
COMMAND git config --get core.hooksPath
106+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
107+
OUTPUT_VARIABLE GIT_HOOKS_DIR
108+
OUTPUT_STRIP_TRAILING_WHITESPACE
109+
)
110+
111+
# Determine the target hooks directory
112+
if(GIT_HOOKS_DIR)
113+
set(TARGET_HOOKS_DIR "${GIT_HOOKS_DIR}")
114+
else()
115+
set(TARGET_HOOKS_DIR "${CMAKE_SOURCE_DIR}/.git/hooks")
116+
endif()
117+
set(DST_HOOK_PRE_PUSH "${TARGET_HOOKS_DIR}/pre-push")
118+
119+
if(EXISTS "${DST_HOOK_PRE_PUSH}")
120+
# Compare the contents of the src and dst hook.
121+
execute_process(
122+
COMMAND git hash-object "${DST_HOOK_PRE_PUSH}"
123+
OUTPUT_VARIABLE SHA_DST
124+
OUTPUT_STRIP_TRAILING_WHITESPACE
125+
)
126+
execute_process(
127+
COMMAND git hash-object "${SRC_HOOK_PRE_PUSH}"
128+
OUTPUT_VARIABLE SHA_SRC
129+
OUTPUT_STRIP_TRAILING_WHITESPACE
130+
)
131+
if(NOT SHA_SRC STREQUAL SHA_DST)
132+
message(WARNING
133+
"You already have a ${DST_HOOK_PRE_PUSH} script installed. "
134+
"This configuration script will not overwrite it despite the fact that "
135+
"it is strongly recommended to use ${SRC_HOOK_PRE_PUSH} in your environment."
136+
"\nProceed with caution!")
137+
endif()
138+
else()
139+
if(EXISTS "${TARGET_HOOKS_DIR}")
140+
file(COPY "${SRC_HOOK_PRE_PUSH}"
141+
DESTINATION "${TARGET_HOOKS_DIR}"
142+
FILE_PERMISSIONS
143+
OWNER_READ OWNER_WRITE OWNER_EXECUTE
144+
GROUP_READ GROUP_EXECUTE
145+
WORLD_READ WORLD_EXECUTE)
146+
message(STATUS "Git pre-push hook installed to ${TARGET_HOOKS_DIR}")
147+
else()
148+
message(WARNING
149+
"The Git hooks directory does not exist: ${TARGET_HOOKS_DIR}\n"
150+
"Are you sure this is a Git repository? Hook cannot be installed."
151+
)
152+
endif()
153+
endif()
154+
endif()
155+
94156
# Directory setup
95157
# ==============================================================================
96158

docs/sphinx/quickstart/installation.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ The simplest way to install CUDA-QX is via pip. You can install individual compo
2222
# Install both libraries
2323
pip install cudaq-qec cudaq-solvers
2424
25+
.. note::
26+
27+
CUDA-Q Solvers will require the presence of :code:`libgfortran`, which is
28+
not distributed with the Python wheel, for provided classical optimizers. If
29+
:code:`libgfortran` is not installed, you will need to install it via your
30+
distribution's package manager. On Debian based systems, you can install
31+
this with :code:`apt-get install gfortran`.
32+
2533
Docker Container
2634
^^^^^^^^^^^^^^^^
2735

libs/qec/CMakeLists.txt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# the terms of the Apache License 2.0 which accompanies this distribution. #
77
# ============================================================================ #
88

9-
# Requering the same version as the others.
9+
# Requiring the same version as the others.
1010
cmake_minimum_required(VERSION 3.28 FATAL_ERROR)
1111

1212
# Project setup
@@ -52,6 +52,44 @@ option(CUDAQX_QEC_INSTALL_PYTHON
5252
"Install python files alongside the library."
5353
${CUDAQX_INSTALL_PYTHON})
5454

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+
5593
# External Dependencies
5694
# ==============================================================================
5795

libs/solvers/CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,44 @@ option(CUDAQX_SOLVERS_INSTALL_PYTHON
6363
"Install python files alongside the library."
6464
${CUDAQX_INSTALL_PYTHON})
6565

66+
# Check for CUDA Support (ref: cuda-quantum/CMakeLists.txt)
67+
# ==============================================================================
68+
include(CheckLanguage)
69+
check_language(CUDA)
70+
set(CUDA_FOUND FALSE)
71+
# Generate -gencode arch=compute_XX,code=sm_XX for list of supported
72+
# arch values.
73+
# List should be sorted in increasing order.
74+
function(CUDA_get_gencode_args out_args_string arch_values)
75+
# allow the user to pass the list like a normal variable
76+
set(arch_list ${arch_values} ${ARGN})
77+
set(out "")
78+
foreach(arch IN LISTS arch_list)
79+
set(out "${out} -gencode arch=compute_${arch},code=sm_${arch}")
80+
endforeach(arch)
81+
82+
# Repeat the last one as to ensure the generation of PTX for most
83+
# recent virtual architecture for forward compatibility
84+
list(GET arch_list -1 last_arch)
85+
set(out "${out} -gencode arch=compute_${last_arch},code=compute_${last_arch}")
86+
set(${out_args_string} ${out} PARENT_SCOPE)
87+
endfunction()
88+
89+
if(CMAKE_CUDA_COMPILER)
90+
if (NOT CUDA_TARGET_ARCHS)
91+
# Volta, Ampere, Hopper
92+
set(CUDA_TARGET_ARCHS "70;80;90")
93+
endif()
94+
CUDA_get_gencode_args(CUDA_gencode_flags ${CUDA_TARGET_ARCHS})
95+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -shared -std=c++17 ${CUDA_gencode_flags} --compiler-options -fPIC")
96+
97+
enable_language(CUDA)
98+
set(CUDA_FOUND TRUE)
99+
set(CMAKE_CUDA_STANDARD 17)
100+
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
101+
message(STATUS "Cuda language found.")
102+
endif()
103+
66104
# External Dependencies
67105
# ==============================================================================
68106

0 commit comments

Comments
 (0)