-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathMakefile
More file actions
247 lines (204 loc) · 7.33 KB
/
Makefile
File metadata and controls
247 lines (204 loc) · 7.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# If you change the following values, update the values in ./WORKSPACE too.
EIGEN_COMMIT = "b66188b5dfd147265bfa9ec47595ca0db72d21f5"
EIGEN_URL = "https://gitlab.com/libeigen/eigen/-/archive/"
# Default build targets. Additional ones are added conditionally below.
TARGETS = qsim
TESTS = run-cxx-tests
# By default, we also build the pybind11-based Python interface.
# Can be overriden via env variables or command-line flags
PYBIND11 ?= true
ifeq ($(PYBIND11), true)
TARGETS += pybind
TESTS += run-py-tests
endif
# Default options for Pytest (only used if the pybind interface is built).
PYTESTFLAGS ?= -n auto -v
# Default compilers and compiler flags.
# Can be overriden via env variables or command-line flags.
CXX ?= g++
NVCC ?= nvcc
HIPCC ?= hipcc
BASE_CXXFLAGS := -std=c++17
BASE_NVCCFLAGS := -std c++17 -Wno-deprecated-gpu-targets
BASE_HIPCCFLAGS :=
CXXFLAGS := $(BASE_CXXFLAGS) $(CXXFLAGS)
NVCCFLAGS := $(BASE_NVCCFLAGS) $(NVCCFLAGS)
HIPCCFLAGS := $(BASE_HIPCCFLAGS) $(HIPCCFLAGS)
LTO_FLAGS := -flto=auto
USING_CLANG := $(shell $(CXX) --version | grep -isq clang && echo "true")
ifeq ($(USING_CLANG),true)
LTO_FLAGS := -flto
endif
ifdef DEBUG
DEBUG_FLAGS := -g -O0
CXXFLAGS += $(DEBUG_FLAGS)
NVCCFLAGS += $(DEBUG_FLAGS)
HIPCCFLAGS += $(DEBUG_FLAGS)
else
CXXFLAGS += -O3 $(OPENMP_FLAGS) $(LTO_FLAGS)
NVCCFLAGS += -O3
HIPCCFLAGS += -O3
endif
# For compatibility with CMake, if $CUDAARCHS is set, use it to set the
# architecture options to nvcc. Otherwise, default to the "native" option,
# which is what our pybind11_interface/GetCUDAARCHS.cmake also does.
ifneq (,$(CUDAARCHS))
# Avoid a common mistake that leads to difficult-to-diagnose errors.
COMMA := ,
ifeq ($(COMMA),$(findstring $(COMMA),$(CUDAARCHS)))
$(error Error: the value of the CUDAARCHS environment variable \
must use semicolons as separators, not commas)
endif
ARCHS := $(subst ;, ,$(CUDAARCHS))
NVCCFLAGS += $(foreach a,$(ARCHS),--generate-code arch=compute_$(a),code=sm_$(a))
else
NVCCFLAGS += -arch=native
endif
# Determine whether we can include CUDA and cuStateVec support. We build for
# CUDA if (i) we find $NVCC or (ii) $CUDA_PATH is set. For cuStateVec, there's
# no way to find the cuQuantum libraries other than by being told, so we rely
# on the user or calling environment to set variable $CUQUANTUM_ROOT.
ifneq (,$(shell which $(NVCC)))
# nvcc adds appropriate -I and -L flags, so nothing more is needed here.
TARGETS += qsim-cuda
TESTS += run-cuda-tests
else
ifneq (,$(strip $(CUDA_PATH)))
# $CUDA_PATH is set. Check that the path truly does exist.
ifneq (,$(strip $(wildcard $(CUDA_PATH)/.)))
# $CUDA_PATH is set, but we know we didn't find nvcc on the user's
# $PATH or as an absolute path (if $NVCC was set to a full path).
# Try the safest choice for finding nvcc & give up if that fails.
NVCC = $(CUDA_PATH)/bin/nvcc
ifneq (,$(strip $(wildcard $(NVCC))))
CXXFLAGS += -I$(CUDA_PATH)/include -L$(CUDA_PATH)/lib64
TARGETS += qsim-cuda
TESTS += run-cuda-tests
else
$(warning nvcc not found, so cannot build CUDA interfaces)
endif
else
$(warning $$CUDA_PATH is set, but the path does not seem to exist)
endif
endif
endif
ifneq (,$(strip $(CUQUANTUM_ROOT)))
# $CUQUANTUM_ROOT is set. Check that the path truly does exist.
ifneq (,$(strip $(wildcard $(CUQUANTUM_ROOT)/.)))
CUSVFLAGS = -I$(CUQUANTUM_ROOT)/include
CUSVFLAGS += -L${CUQUANTUM_ROOT}/lib -L$(CUQUANTUM_ROOT)/lib64
CUSVFLAGS += -lcustatevec -lcublas
CUSTATEVECFLAGS ?= $(CUSVFLAGS)
TARGETS += qsim-custatevec
TARGETS += qsim-custatevecex
TESTS += run-custatevec-tests
TESTS += run-custatevecex-tests
TESTS += run-custatevecex-mpi-tests
else
$(warning $$CUQUANTUM_ROOT is set, but the path does not seem to exist)
endif
endif
# Export all variables to subprocesses without having to export them individually.
.EXPORT_ALL_VARIABLES:
# The rest is build rules and make targets.
.PHONY: all
all: $(TARGETS)
.PHONY: qsim
qsim:
$(MAKE) -C apps/ qsim
.PHONY: qsim-cuda
qsim-cuda:
$(MAKE) -C apps/ qsim-cuda
.PHONY: qsim-custatevec
qsim-custatevec: | check-cuquantum-root-set
$(MAKE) -C apps/ qsim-custatevec
.PHONY: qsim-custatevecex
qsim-custatevecex: | check-cuquantum-root-set
$(MAKE) -C apps/ qsim-custatevecex
.PHONY: qsim-hip
qsim-hip:
$(MAKE) -C apps/ qsim-hip
.PHONY: pybind
pybind:
$(MAKE) -C pybind_interface/ pybind
.PHONY: cxx-tests
cxx-tests: eigen
$(MAKE) -C tests/ cxx-tests
.PHONY: cuda-tests
cuda-tests:
$(MAKE) -C tests/ cuda-tests
.PHONY: custatevec-tests
custatevec-tests: | check-cuquantum-root-set
$(MAKE) -C tests/ custatevec-tests
.PHONY: custatevecex-tests
custatevecex-tests: | check-cuquantum-root-set
$(MAKE) -C tests/ custatevecex-tests
.PHONY: hip-tests
hip-tests:
$(MAKE) -C tests/ hip-tests
.PHONY: run-cxx-tests
run-cxx-tests: cxx-tests
$(MAKE) -C tests/ run-cxx-tests
.PHONY: run-cuda-tests
run-cuda-tests: cuda-tests
$(MAKE) -C tests/ run-cuda-tests
.PHONY: run-custatevec-tests
run-custatevec-tests: custatevec-tests
$(MAKE) -C tests/ run-custatevec-tests
.PHONY: run-custatevecex-tests
run-custatevecex-tests: custatevecex-tests
$(MAKE) -C tests/ run-custatevecex-tests
.PHONY: run-custatevecex-mpi-tests
run-custatevecex-mpi-tests: custatevecex-tests
$(MAKE) -C tests/ run-custatevecex-mpi-tests
.PHONY: run-hip-tests
run-hip-tests: hip-tests
$(MAKE) -C tests/ run-hip-tests
PYTESTS := $(wildcard qsimcirq_tests/*_test.py)
.PHONY: run-py-tests
run-py-tests: pybind
python3 -m pytest $(PYTESTFLAGS) $(PYTESTS)
.PHONY: run-tests tests
run-tests tests: $(TESTS)
.PHONY: check-cuquantum-root-set
check-cuquantum-root-set:
@if test -z "$(CUQUANTUM_ROOT)"; then \
echo Error: '$$CUQUANTUM_ROOT must be set in order to use cuStateVec.'; \
exit 1; \
fi
# Check whether wget or curl is available on this system.
ifneq (,$(shell command -v wget))
DOWNLOAD_CMD := wget
else ifneq (,$(shell command -v curl))
DOWNLOAD_CMD := curl --fail -L -O
else
$(error Neither wget nor curl found in PATH. Please install curl or wget.)
endif
eigen:
-rm -rf eigen
$(DOWNLOAD_CMD) $(EIGEN_URL)/$(EIGEN_COMMIT)/eigen-$(EIGEN_COMMIT).tar.gz
tar -xzf eigen-$(EIGEN_COMMIT).tar.gz && mv eigen-$(EIGEN_COMMIT) eigen
rm eigen-$(EIGEN_COMMIT).tar.gz
.PHONY: clean
clean:
-rm -rf eigen
-$(MAKE) -C apps/ clean
-$(MAKE) -C tests/ clean
-$(MAKE) -C pybind_interface/ clean
LOCAL_VARS = TARGETS TESTS PYTESTS PYTESTFLAGS CXX CXXFLAGS NVCC NVCCFLAGS $\
HIPCC HIPCCFLAGS CUDA_PATH CUQUANTUM_ROOT CUSTATEVECFLAGS
.PHONY: print-vars
print-vars: ; @$(foreach n,$(sort $(LOCAL_VARS)),echo $n=$($n);)