diff --git a/Makefile b/Makefile index fa0df9102..84ad1fffc 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ TARGETS = qsim TESTS = run-cxx-tests CXX=g++ -CXXFLAGS = -O3 -mavx2 -mfma -fopenmp +CXXFLAGS = -O3 -march=native -fopenmp PYBIND11 = true export CXX diff --git a/apps/qsim_amplitudes.cc b/apps/qsim_amplitudes.cc index a2a7fc907..ae9e11a0e 100644 --- a/apps/qsim_amplitudes.cc +++ b/apps/qsim_amplitudes.cc @@ -28,7 +28,7 @@ #include "../lib/io.h" #include "../lib/parfor.h" #include "../lib/run_qsim.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" #include "../lib/util.h" constexpr char usage[] = "usage:\n ./qsim_amplitudes -c circuit_file " @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) { return 1; } - using Simulator = SimulatorAVX; + using Simulator = qsim::Simulator; using StateSpace = Simulator::StateSpace; using State = StateSpace::State; diff --git a/apps/qsim_base.cc b/apps/qsim_base.cc index 19b4afe53..73adc5e35 100644 --- a/apps/qsim_base.cc +++ b/apps/qsim_base.cc @@ -25,7 +25,7 @@ #include "../lib/io.h" #include "../lib/parfor.h" #include "../lib/run_qsim.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" struct Options { std::string circuit_file; @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) { return 1; } - using Simulator = SimulatorAVX; + using Simulator = qsim::Simulator; using StateSpace = Simulator::StateSpace; using State = StateSpace::State; using Runner = QSimRunner>, Simulator>; diff --git a/apps/qsim_von_neumann.cc b/apps/qsim_von_neumann.cc index 6262971be..5fcd54de0 100644 --- a/apps/qsim_von_neumann.cc +++ b/apps/qsim_von_neumann.cc @@ -27,7 +27,7 @@ #include "../lib/io.h" #include "../lib/parfor.h" #include "../lib/run_qsim.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" struct Options { std::string circuit_file; @@ -89,7 +89,7 @@ int main(int argc, char* argv[]) { return 1; } - using Simulator = SimulatorAVX; + using Simulator = qsim::Simulator; using StateSpace = Simulator::StateSpace; using State = StateSpace::State; diff --git a/apps/qsimh_amplitudes.cc b/apps/qsimh_amplitudes.cc index c2b42f857..6dc1d1e2f 100644 --- a/apps/qsimh_amplitudes.cc +++ b/apps/qsimh_amplitudes.cc @@ -27,7 +27,7 @@ #include "../lib/io.h" #include "../lib/parfor.h" #include "../lib/run_qsimh.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" #include "../lib/util.h" constexpr char usage[] = "usage:\n ./qsimh_amplitudes -c circuit_file " @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) { return 1; } - using Simulator = SimulatorAVX; + using Simulator = qsim::Simulator; using HybridSimulator = HybridSimulator; using Runner = QSimHRunner; diff --git a/apps/qsimh_base.cc b/apps/qsimh_base.cc index 67455cda3..f4f8399e6 100644 --- a/apps/qsimh_base.cc +++ b/apps/qsimh_base.cc @@ -27,7 +27,7 @@ #include "../lib/io.h" #include "../lib/parfor.h" #include "../lib/run_qsimh.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" #include "../lib/util.h" constexpr char usage[] = "usage:\n ./qsimh_base -c circuit_file " @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) { bitstrings.push_back(i); } - using Simulator = SimulatorAVX; + using Simulator = qsim::Simulator; using HybridSimulator = HybridSimulator; using Runner = QSimHRunner; diff --git a/lib/BUILD b/lib/BUILD index ea372d1c2..3bbfd5588 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -19,6 +19,7 @@ cc_library( "run_qsim.h", "run_qsimh.h", "seqfor.h", + "simmux.h", "simulator_avx.h", "simulator_basic.h", "simulator_sse.h", diff --git a/lib/simmux.h b/lib/simmux.h new file mode 100644 index 000000000..067ae83ee --- /dev/null +++ b/lib/simmux.h @@ -0,0 +1,38 @@ +// Copyright 2019 Google LLC. All Rights Reserved. +// +// 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. + +#ifndef SIMMUX_H_ +#define SIMMUX_H_ + +#ifdef __AVX2__ +# include "simulator_avx.h" + namespace qsim { + template + using Simulator = SimulatorAVX; + } +#elif __SSE4_1__ +# include "simulator_sse.h" + namespace qsim { + template + using Simulator = SimulatorSSE; + } +#else +# include "simulator_basic.h" + namespace qsim { + template + using Simulator = SimulatorBasic; + } +#endif + +#endif // SIMMUX_H_ diff --git a/lib/simulator_basic.h b/lib/simulator_basic.h index 25d0f4bd9..5b98c9853 100644 --- a/lib/simulator_basic.h +++ b/lib/simulator_basic.h @@ -22,7 +22,7 @@ namespace qsim { // Quantim circuit simulator without vectorization. -template +template class SimulatorBasic final { public: using StateSpace = StateSpaceBasic; diff --git a/tests/Makefile b/tests/Makefile index f4ab39a6f..cc2c8299b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -6,7 +6,7 @@ GMOCK_DIR = $(CURDIR)/googletest/googlemock CMAKE=cmake -TESTFLAGS = -I$(GTEST_DIR)/include -L$(GTEST_DIR)/make/lib -mavx2 -mfma -fopenmp -lgtest +TESTFLAGS = -I$(GTEST_DIR)/include -L$(GTEST_DIR)/make/lib -march=native -fopenmp -lgtest .PHONY: all all: $(TARGETS)