From cd1f851f2463a8a27b0a485fd521bec5bda0ae35 Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Fri, 5 Jun 2020 15:59:38 -0700 Subject: [PATCH] Check all config flags in CI tests. --- .github/workflows/bazeltest.yml | 15 +++++++++++++-- docs/bazel.md | 33 +++++++++++++++++++++++++++++---- lib/BUILD | 2 +- tests/BUILD | 31 ++++++++++--------------------- tests/hybrid_test.cc | 6 +++--- tests/run_qsim_test.cc | 8 ++++---- tests/run_qsimh_test.cc | 6 +++--- 7 files changed, 63 insertions(+), 38 deletions(-) diff --git a/.github/workflows/bazeltest.yml b/.github/workflows/bazeltest.yml index 9dfbe561..40f7e6a9 100644 --- a/.github/workflows/bazeltest.yml +++ b/.github/workflows/bazeltest.yml @@ -20,6 +20,12 @@ jobs: test: name: Test with Bazel runs-on: ubuntu-16.04 + strategy: + matrix: + # Hardware optimizers. + hardware_opt: [avx,sse,basic] + # Optimizers for parallelism. + parallel_opt: [openmp,basic] steps: - uses: actions/checkout@v2 @@ -30,6 +36,11 @@ jobs: wget https://github.com/bazelbuild/bazel/releases/download/0.26.0/bazel_0.26.0-linux-x86_64.deb sudo dpkg -i bazel_0.26.0-linux-x86_64.deb - name: Run C++ tests - run: bazel test tests:all + run: | + bazel test --config=${{ matrix.hardware_opt }} \ + --config=${{ matrix.parallel_opt }} tests:all - name: Run sample simulation - run: bazel run --config=avx --config=openmp apps:qsim_base -- -c circuits/circuit_q24 + run: | + bazel run --config=${{ matrix.hardware_opt }} \ + --config=${{ matrix.parallel_opt }} apps:qsim_base \ + -- -c circuits/circuit_q24 diff --git a/docs/bazel.md b/docs/bazel.md index e92868b5..61f08f91 100644 --- a/docs/bazel.md +++ b/docs/bazel.md @@ -1,16 +1,41 @@ # Building with Bazel - qsim provides [Bazel](https://github.com/bazelbuild/bazel) build rules for its applications and tests. To build and run all tests using Bazel, run the following command: ``` -bazel test --config=avx tests:all +# AVX and OpenMP are recommended for best performance. +# See "Build configs" section below for more information. +bazel test --config=avx --config=openmp tests:all ``` To run a sample simulation, use the command below. Note that this command requires the circuit file to be specified both on the command line and in the `data` field of the `qsim_base` BUILD rule. ``` -bazel run --config=avx apps:qsim_base -- -c circuits/circuit_q24 -``` \ No newline at end of file +bazel run --config=avx --config=openmp apps:qsim_base -- -c circuits/circuit_q24 +``` + +## Build configs + +Depending on the optimizers available on your machine, different config flags +(such as `--config=avx`, above) can be set to control which optimizers are +included in a given build or test run. + +Vector arithmetic optimizers (pick one at most): +``` +# Use AVX instructions for vector arithmetic. +--config=avx + +# Use SSE instructions for vector arithmetic. +--config=sse +``` + +Parallelism optimizers (pick one at most): +``` +# Use OpenMP to run operations in parallel when possible. +--config=avx +``` + +We also provide `--config=basic`. This flag does not affect the build or test, +but can be useful in scripts (e.g. where `--config=" "` is not valid). diff --git a/lib/BUILD b/lib/BUILD index bb2297b9..6904ca7b 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -144,7 +144,7 @@ cc_library( hdrs = ["seqfor.h"], ) -# All three state-vector simulators with multiplexer +# Both parallelism control paths with multiplexer cc_library( name = "formux", hdrs = ["formux.h"], diff --git a/tests/BUILD b/tests/BUILD index 846dd3c3..9b1dc939 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -1,8 +1,6 @@ # Options for testing different simulator types. avx_copts = ['-mavx2', '-mfma'] sse_copts = ['-msse4'] -omp_copts = ['-fopenmp'] -omp_linkopts = ['-lgomp'] windows_copts = [ "/arch:AVX", @@ -92,13 +90,12 @@ cc_test( "//lib:gates_qsim", "//lib:hybrid", "//lib:io", - "//lib:simulator_avx", + "//lib:simulator", ], copts = select({ ":windows": windows_copts, - "//conditions:default": avx_copts + omp_copts, + "//conditions:default": [], }), - linkopts = omp_linkopts, ) cc_test( @@ -124,9 +121,8 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": avx_copts + omp_copts, + "//conditions:default": [], }), - linkopts = omp_linkopts, ) cc_test( @@ -139,9 +135,8 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": avx_copts + omp_copts, + "//conditions:default": [], }), - linkopts = omp_linkopts, ) cc_library( @@ -171,9 +166,8 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": avx_copts + omp_copts, + "//conditions:default": avx_copts, }), - linkopts = omp_linkopts, ) cc_test( @@ -187,9 +181,8 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": omp_copts, + "//conditions:default": [], }), - linkopts = omp_linkopts, ) cc_test( @@ -203,9 +196,8 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": sse_copts + omp_copts, + "//conditions:default": sse_copts, }), - linkopts = omp_linkopts, ) cc_library( @@ -238,9 +230,8 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": avx_copts + omp_copts, + "//conditions:default": avx_copts, }), - linkopts = omp_linkopts, ) cc_test( @@ -255,9 +246,8 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": omp_copts, + "//conditions:default": [], }), - linkopts = omp_linkopts, ) cc_test( @@ -272,7 +262,6 @@ cc_test( ], copts = select({ ":windows": windows_copts, - "//conditions:default": sse_copts + omp_copts, + "//conditions:default": sse_copts, }), - linkopts = omp_linkopts, ) diff --git a/tests/hybrid_test.cc b/tests/hybrid_test.cc index e7fac2e7..1cc55860 100644 --- a/tests/hybrid_test.cc +++ b/tests/hybrid_test.cc @@ -25,7 +25,7 @@ #include "../lib/gates_qsim.h" #include "../lib/hybrid.h" #include "../lib/io.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" namespace qsim { @@ -66,7 +66,7 @@ R"(2 EXPECT_EQ(circuit.num_qubits, 2); EXPECT_EQ(circuit.gates.size(), 23); - using Simulator = SimulatorAVX; + using Simulator = Simulator; using HybridSimulator = HybridSimulator, BasicGateFuser, Simulator, For>; using Fuser = HybridSimulator::Fuser; @@ -245,7 +245,7 @@ R"(4 EXPECT_EQ(circuit.num_qubits, 4); EXPECT_EQ(circuit.gates.size(), 63); - using Simulator = SimulatorAVX; + using Simulator = Simulator; using HybridSimulator = HybridSimulator, BasicGateFuser, Simulator, For>; using Fuser = HybridSimulator::Fuser; diff --git a/tests/run_qsim_test.cc b/tests/run_qsim_test.cc index 104c4ef7..49c56b57 100644 --- a/tests/run_qsim_test.cc +++ b/tests/run_qsim_test.cc @@ -27,7 +27,7 @@ #include "../lib/gates_qsim.h" #include "../lib/io.h" #include "../lib/run_qsim.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" namespace qsim { @@ -72,7 +72,7 @@ TEST(RunQSimTest, QSimRunner1) { EXPECT_EQ(circuit.num_qubits, 4); EXPECT_EQ(circuit.gates.size(), 27); - using Simulator = SimulatorAVX; + using Simulator = Simulator; using StateSpace = Simulator::StateSpace; using State = StateSpace::State; using Runner = QSimRunner>, Simulator>; @@ -109,7 +109,7 @@ TEST(RunQSimTest, QSimRunner2) { EXPECT_EQ(circuit.num_qubits, 4); EXPECT_EQ(circuit.gates.size(), 27); - using Simulator = SimulatorAVX; + using Simulator = Simulator; using StateSpace = Simulator::StateSpace; using State = StateSpace::State; using Runner = QSimRunner>, Simulator>; @@ -144,7 +144,7 @@ TEST(RunQSimTest, CirqGates) { auto circuit = CirqCircuit1::GetCircuit(); const auto& expected_results = CirqCircuit1::expected_results; - using Simulator = SimulatorAVX; + using Simulator = Simulator; using StateSpace = Simulator::StateSpace; using State = StateSpace::State; using Runner = QSimRunner>, diff --git a/tests/run_qsimh_test.cc b/tests/run_qsimh_test.cc index 29d5aa29..d6189dd1 100644 --- a/tests/run_qsimh_test.cc +++ b/tests/run_qsimh_test.cc @@ -27,7 +27,7 @@ #include "../lib/gates_qsim.h" #include "../lib/io.h" #include "../lib/run_qsimh.h" -#include "../lib/simulator_avx.h" +#include "../lib/simmux.h" namespace qsim { @@ -108,7 +108,7 @@ TEST(RunQSimHTest, QSimHRunner) { EXPECT_EQ(circuit.num_qubits, 4); EXPECT_EQ(circuit.gates.size(), 63); - using Simulator = SimulatorAVX; + using Simulator = Simulator; using HybridSimulator = HybridSimulator, BasicGateFuser, Simulator, For>; using Runner = QSimHRunner; @@ -165,7 +165,7 @@ TEST(RunQSimHTest, CirqGates) { auto circuit = CirqCircuit1::GetCircuit(); const auto& expected_results = CirqCircuit1::expected_results; - using Simulator = SimulatorAVX; + using Simulator = Simulator; using HybridSimulator = HybridSimulator, BasicGateFuser, Simulator, For>; using Runner = QSimHRunner;