Skip to content

Commit

Permalink
Merge pull request #82 from quantumlib/simmux
Browse files Browse the repository at this point in the history
Add simulator selector.
  • Loading branch information
sergeisakov committed Apr 23, 2020
2 parents 1e661d9 + aec8f12 commit 9708283
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
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
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
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
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
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
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
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
@@ -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
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
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

0 comments on commit 9708283

Please sign in to comment.