Skip to content

Add simulator selector. #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/qsim_amplitudes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) {
return 1;
}

using Simulator = SimulatorAVX<ParallelFor>;
using Simulator = qsim::Simulator<ParallelFor>;
using StateSpace = Simulator::StateSpace;
using State = StateSpace::State;

Expand Down
4 changes: 2 additions & 2 deletions apps/qsim_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) {
return 1;
}

using Simulator = SimulatorAVX<ParallelFor>;
using Simulator = qsim::Simulator<ParallelFor>;
using StateSpace = Simulator::StateSpace;
using State = StateSpace::State;
using Runner = QSimRunner<IO, BasicGateFuser<GateQSim<float>>, Simulator>;
Expand Down
4 changes: 2 additions & 2 deletions apps/qsim_von_neumann.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +89,7 @@ int main(int argc, char* argv[]) {
return 1;
}

using Simulator = SimulatorAVX<ParallelFor>;
using Simulator = qsim::Simulator<ParallelFor>;
using StateSpace = Simulator::StateSpace;
using State = StateSpace::State;

Expand Down
4 changes: 2 additions & 2 deletions apps/qsimh_amplitudes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) {
return 1;
}

using Simulator = SimulatorAVX<ParallelFor>;
using Simulator = qsim::Simulator<ParallelFor>;
using HybridSimulator = HybridSimulator<IO, BasicGateFuser, Simulator,
ParallelFor>;
using Runner = QSimHRunner<IO, HybridSimulator>;
Expand Down
4 changes: 2 additions & 2 deletions apps/qsimh_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) {
bitstrings.push_back(i);
}

using Simulator = SimulatorAVX<ParallelFor>;
using Simulator = qsim::Simulator<ParallelFor>;
using HybridSimulator = HybridSimulator<IO, BasicGateFuser, Simulator,
ParallelFor>;
using Runner = QSimHRunner<IO, HybridSimulator>;
Expand Down
1 change: 1 addition & 0 deletions lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions lib/simmux.h
Original file line number Diff line number Diff line change
@@ -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 <typename ParallelFor>
using Simulator = SimulatorAVX<ParallelFor>;
}
#elif __SSE4_1__
# include "simulator_sse.h"
namespace qsim {
template <typename ParallelFor>
using Simulator = SimulatorSSE<ParallelFor>;
}
#else
# include "simulator_basic.h"
namespace qsim {
template <typename ParallelFor>
using Simulator = SimulatorBasic<ParallelFor>;
}
#endif

#endif // SIMMUX_H_
2 changes: 1 addition & 1 deletion lib/simulator_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace qsim {

// Quantim circuit simulator without vectorization.
template <typename ParallelFor, typename FP>
template <typename ParallelFor, typename FP = float>
class SimulatorBasic final {
public:
using StateSpace = StateSpaceBasic<ParallelFor, FP>;
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down