-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
109 lines (91 loc) · 3.45 KB
/
Makefile
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
# Author: Salvatore Mandra (salvatore.mandra@nasa.gov)
#
# Copyright © 2021, United States Government, as represented by the Administrator
# of the National Aeronautics and Space Administration. All rights reserved.
#
# The HybridQ: A Hybrid Simulator for Quantum Circuits platform is 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
# http://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.
# Fix size of packs
LOG2_PACK_SIZE ?= 0
# Set default compiler
CXX ?= g++
# Set default architecture
ARCH ?= native
# Set default C++ flags
CXXFLAGS ?= -Wall \
-Wpedantic \
-Wno-vla \
-Ofast \
-ffast-math \
-march=$(ARCH)
# Add flags for shared library
CXXFLAGS := $(CXXFLAGS) \
-std=c++17 \
-shared \
-fPIC
# Add extra CXXFLAGS
CXXFLAGS += $(CXXFLAGS_EXTRA)
# Check support for openMP
is_openmp_supported := $(shell echo | \
$(CXX) $(CPPFLAGS) $(LDFLAGS) $(CXXFLAGS) \
-fopenmp -x c++ -c - -o /dev/null 2>/dev/null && \
echo yes || \
echo no)
# Update CXXFLAGS is OpenMP is supported
ifeq ($(is_openmp_supported), yes)
CXXFLAGS += -fopenmp
endif
# Define command for compilation
COMPILE := $(CXX) $(CPPFLAGS) $(LDFLAGS) $(CXXFLAGS)
# Check support for AVX
avx := $(shell $(COMPILE) -x c++ -dM -E - < /dev/null | grep -i '__AVX__' | head -n 1 | wc -l)
avx2 := $(shell $(COMPILE) -x c++ -dM -E - < /dev/null | grep -i '__AVX2__' | head -n 1 | wc -l)
avx512 := $(shell $(COMPILE) -x c++ -dM -E - < /dev/null | grep -i '__AVX512' | head -n 1 | wc -l)
# If not specified, infer pack size
ifeq ($(LOG2_PACK_SIZE), 0)
LOG2_PACK_SIZE := $(shell \
if [ $(avx512) -eq 1 ]; then \
echo 4; \
elif [ $(avx2) -eq 1 ]; then \
echo 3; \
else \
echo 3; \
fi)
endif
.PHONY=all
all: print_support \
hybridq/utils/hybridq_swap.so \
hybridq/utils/hybridq.so
.PHONY=print_support
print_support:
@# Print support for OpenMP
$(info # Support OpenMP? $(is_openmp_supported))
@# Print support for AVX
$(info # Support AVX? $(shell (exit $(avx)) && echo no || echo yes))
$(info # Support AVX-2? $(shell (exit $(avx2)) && echo no || echo yes))
$(info # Support AVX-512? $(shell (exit $(avx512)) && echo no || echo yes))
@# Print pack size
$(info # Size of Pack: 2^$(LOG2_PACK_SIZE))
hybridq/utils/hybridq_swap.so: include/python_swap.cpp \
include/swap.h \
include/utils.h \
include/pack.h
@# Compile
$(COMPILE) $< -o $@
hybridq/utils/hybridq.so: include/python_U.cpp \
include/U.h \
include/utils.h \
include/pack.h
@# Compile
$(COMPILE) $< -o $@ \
-DLOG2_PACK_SIZE=$(LOG2_PACK_SIZE)
clean:
-rm -f hybridq/utils/hybridq.so
-rm -f hybridq/utils/hybridq_swap.so