From dc1446da9ed857e63e85bdfd09035fdebbcf4ffa Mon Sep 17 00:00:00 2001 From: mhucka Date: Mon, 5 Jan 2026 21:57:04 +0000 Subject: [PATCH 1/4] Fix handling of user CXXFLAGS and add a DEBUG flag The way `CXXFLAGS` and other flags were being set meant that users had to add the default values (`-std=c++17 -fopenmp -O3` etc) if they set the flags at all. The new approach here adds the user values to the existing ones, so that they can override values more selectively. This also adds a DEBUG flag that switches between using `-g -O0` and the regular `-O3` option. --- Makefile | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4b37317c2..2cf6b1428 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,12 @@ EIGEN_PREFIX = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e" EIGEN_URL = "https://gitlab.com/libeigen/eigen/-/archive/" -# Default build targets. Additional may be added conditionally below. +# 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) @@ -31,14 +32,31 @@ endif # Default options for Pytest (only used if the pybind interface is built). PYTESTFLAGS ?= -v -# Default C++ compilers and compiler flags. Can be overriden via env variables. +# Default compilers and compiler flags. +# Can be overriden via env variables or command-line flags. CXX ?= g++ NVCC ?= nvcc HIPCC ?= hipcc -CXXFLAGS ?= -O3 -std=c++17 -fopenmp -flto=auto -NVCCFLAGS ?= -O3 --std c++17 -Wno-deprecated-gpu-targets -HIPCCFLAGS ?= -O3 +BASE_CXXFLAGS := -std=c++17 -fopenmp +BASE_NVCCFLAGS := -std c++17 -Wno-deprecated-gpu-targets +BASE_HIPCCFLAGS := + +CXXFLAGS := $(BASE_CXXFLAGS) $(CXXFLAGS) +NVCCFLAGS := $(BASE_NVCCFLAGS) $(NVCCFLAGS) +HIPCCFLAGS := $(BASE_HIPCCFLAGS) $(HIPCCFLAGS) + +ifdef DEBUG + # Debug build: Add debug symbols & disable optimizations. + DEBUG_FLAGS := -g -O0 + CXXFLAGS += $(DEBUG_FLAGS) + NVCCFLAGS += $(DEBUG_FLAGS) + HIPCCFLAGS += $(DEBUG_FLAGS) +else + CXXFLAGS += -O3 -flto=auto + 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, @@ -91,7 +109,7 @@ ifneq (,$(strip $(CUQUANTUM_ROOT))) ifneq (,$(strip $(wildcard $(CUQUANTUM_ROOT)/.))) CUSVFLAGS = -I$(CUQUANTUM_ROOT)/include CUSVFLAGS += -L${CUQUANTUM_ROOT}/lib -L$(CUQUANTUM_ROOT)/lib64 - CUSVFLAGS += -lcustatevec -lcublas + CUSVFLAGS += -Xcompiler \"-Wl,-rpath=${CUQUANTUM_ROOT}/lib\" CUSTATEVECFLAGS ?= $(CUSVFLAGS) TARGETS += qsim-custatevec TARGETS += qsim-custatevecex From 3298cdc348e0c28c43e452c6de18429a60702934 Mon Sep 17 00:00:00 2001 From: mhucka Date: Mon, 5 Jan 2026 21:58:45 +0000 Subject: [PATCH 2/4] Fix an accidental line deletion --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2cf6b1428..2bdf59065 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ ifneq (,$(strip $(CUQUANTUM_ROOT))) ifneq (,$(strip $(wildcard $(CUQUANTUM_ROOT)/.))) CUSVFLAGS = -I$(CUQUANTUM_ROOT)/include CUSVFLAGS += -L${CUQUANTUM_ROOT}/lib -L$(CUQUANTUM_ROOT)/lib64 - CUSVFLAGS += -Xcompiler \"-Wl,-rpath=${CUQUANTUM_ROOT}/lib\" + CUSVFLAGS += -lcustatevec -lcublas CUSTATEVECFLAGS ?= $(CUSVFLAGS) TARGETS += qsim-custatevec TARGETS += qsim-custatevecex From 292d5dfb94d2e72911960b86c4fc29eaabc617d8 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 6 Jan 2026 04:10:04 +0000 Subject: [PATCH 3/4] Remove trivial comment --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 2bdf59065..cb1d851d6 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,6 @@ NVCCFLAGS := $(BASE_NVCCFLAGS) $(NVCCFLAGS) HIPCCFLAGS := $(BASE_HIPCCFLAGS) $(HIPCCFLAGS) ifdef DEBUG - # Debug build: Add debug symbols & disable optimizations. DEBUG_FLAGS := -g -O0 CXXFLAGS += $(DEBUG_FLAGS) NVCCFLAGS += $(DEBUG_FLAGS) From 6c33861bda36d171dd62ad9a132e73db51963dee Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 6 Jan 2026 04:50:42 +0000 Subject: [PATCH 4/4] Use correct version of -flto flag for Clang Clang doesn't understand `-flto=auto` and G++ doesn't understand `-flto`. --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cb1d851d6..3e470c21f 100644 --- a/Makefile +++ b/Makefile @@ -46,13 +46,19 @@ 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 -flto=auto + CXXFLAGS += -O3 $(LTO_FLAGS) NVCCFLAGS += -O3 HIPCCFLAGS += -O3 endif