Skip to content

Commit

Permalink
Merge pull request #596 from jaeyoo/cuda_enabled
Browse files Browse the repository at this point in the history
Cuda enabled - SimulatorCUDA
  • Loading branch information
95-martin-orion authored Apr 12, 2023
2 parents 658cc3b + fe3c823 commit d747970
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 35 deletions.
9 changes: 7 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Default build options
build --copt -std=c++11
build --copt -D_GLIBCXX_USE_CXX11_ABI=0
build --copt -std=c++17
build --copt -D_GLIBCXX_USE_CXX11_ABI=1
build --experimental_repo_remote_exec

##### Sanitizers (choose one, or nosan for none) #####

Expand Down Expand Up @@ -55,3 +56,7 @@ build:malloc --

# Test flags
test --test_output=errors

# CUDA options
build:cuda --@local_config_cuda//:enable_cuda
build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.3.0
23 changes: 16 additions & 7 deletions .github/workflows/bazeltest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
pull_request:

jobs:
# Run tests with Bazel v0.26.
# Run tests with Bazel v5.3.0.
test:
name: Test with Bazel
runs-on: ubuntu-20.04
Expand All @@ -26,8 +26,11 @@ jobs:
run: git submodule update --init --recursive
- name: Install Bazel on CI
run: |
wget https://github.com/bazelbuild/bazel/releases/download/3.7.2/bazel_3.7.2-linux-x86_64.deb
sudo dpkg -i bazel_3.7.2-linux-x86_64.deb
wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb
sudo dpkg -i bazel_5.3.0-linux-x86_64.deb
- name: Install requirements
run: |
python3 -m pip install -r requirements.txt
- name: Run C++ tests
run: |
bazel test --config=${{ matrix.hardware_opt }} \
Expand All @@ -52,8 +55,11 @@ jobs:
run: git submodule update --init --recursive
- name: Install Bazel on CI
run: |
wget https://github.com/bazelbuild/bazel/releases/download/3.7.2/bazel_3.7.2-linux-x86_64.deb
sudo dpkg -i bazel_3.7.2-linux-x86_64.deb
wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb
sudo dpkg -i bazel_5.3.0-linux-x86_64.deb
- name: Install requirements
run: |
python3 -m pip install -r requirements.txt
- name: Run C++ tests
run: |
bazel test --config=avx --config=openmp \
Expand All @@ -69,8 +75,11 @@ jobs:
run: git submodule update --init --recursive
- name: Install Bazel on CI
run: |
wget https://github.com/bazelbuild/bazel/releases/download/3.7.2/bazel_3.7.2-linux-x86_64.deb
sudo dpkg -i bazel_3.7.2-linux-x86_64.deb
wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb
sudo dpkg -i bazel_5.3.0-linux-x86_64.deb
- name: Install requirements
run: |
python3 -m pip install -r requirements.txt
- name: Install google-perftools for tcmalloc
run: sudo apt-get install libgoogle-perftools-dev
- name: Run C++ tests
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
- name: Install cibuildwheel and twine
run: python -m pip install cibuildwheel==2.2.2

- name: Install requirements
run: python -m pip install -r requirements.txt

- name: Run C++ tests
run: bash build_tools/test_libs.sh

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/testing_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
- name: Install cibuildwheel and twine
run: python -m pip install cibuildwheel==2.2.2

- name: Install requirements
run: python -m pip install -r requirements.txt

- name: Run C++ tests
run: bash build_tools/test_libs.sh

Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ bazel-*

# Eigen library
eigen

# vscode
.vscode/*

# Bazel files
/bazel-*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EIGEN_PREFIX = "d10b27fe37736d2944630ecd7557cefa95cf87c9"
EIGEN_PREFIX = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e"
EIGEN_URL = "https://gitlab.com/libeigen/eigen/-/archive/"

TARGETS = qsim
Expand Down
26 changes: 21 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,32 @@ http_archive(
# https://github.com/tensorflow/quantum
http_archive(
name = "org_tensorflow",
sha256 = "e82f3b94d863e223881678406faa5071b895e1ff928ba18578d2adbbc6b42a4c",
strip_prefix = "tensorflow-2.1.0",
sha256 = "e52cda3bae45f0ae0fccd4055e9fa29892b414f70e2df94df9a3a10319c75fff",
strip_prefix = "tensorflow-2.11.0",
urls = [
"https://github.com/tensorflow/tensorflow/archive/v2.1.0.zip",
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.11.0.zip",
],
)

load("@org_tensorflow//tensorflow:workspace3.bzl", "workspace")

EIGEN_COMMIT = "12e8d57108c50d8a63605c6eb0144c838c128337"
EIGEN_SHA256 = "f689246e342c3955af48d26ce74ac34d21b579a00675c341721a735937919b02"
workspace()

load("@org_tensorflow//tensorflow:workspace2.bzl", "workspace")

workspace()

load("@org_tensorflow//tensorflow:workspace1.bzl", "workspace")

workspace()

load("@org_tensorflow//tensorflow:workspace0.bzl", "workspace")

workspace()


EIGEN_COMMIT = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e"
EIGEN_SHA256 = "eca9847b3fe6249e0234a342b78f73feec07d29f534e914ba5f920f3e09383a3"


http_archive(
Expand Down
2 changes: 1 addition & 1 deletion build_tools/test_libs.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi
set e # Ignore errors until artifacts are collected.
EXIT_CODE=0
for TARGET in bitstring_test channels_cirq_test circuit_qsim_parser_test expect_test \
fuser_basic_test gates_qsim_test hybrid_test matrix_test qtrajectory_test \
fuser_basic_test gates_qsim_test hybrid_avx_test matrix_test qtrajectory_avx_test \
run_qsim_test run_qsimh_test simulator_basic_test simulator_sse_test statespace_basic_test \
statespace_sse_test unitary_calculator_basic_test unitary_calculator_sse_test \
unitaryspace_basic_test unitaryspace_sse_test vectorspace_test; do \
Expand Down
24 changes: 8 additions & 16 deletions lib/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package(default_visibility = ["//visibility:public"])
load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library")

# Libraries of the following form:
# # cuda_library
# cc_library(...)
# are converted to cuda_library rules when imported to the Google codebase.
# Do not modify this tag.
package(default_visibility = ["//visibility:public"])

##### Aggregate libraries #####

Expand Down Expand Up @@ -67,8 +63,7 @@ cc_library(
)

# Full qsim library, including CUDA
# cuda_library
cc_library(
cuda_library(
name = "qsim_cuda_lib",
hdrs = [
"bits.h",
Expand Down Expand Up @@ -99,6 +94,7 @@ cc_library(
"run_qsimh.h",
"seqfor.h",
"simmux.h",
"simmux_gpu.h",
"simulator.h",
"simulator_avx.h",
"simulator_avx512.h",
Expand Down Expand Up @@ -247,8 +243,7 @@ cc_library(
hdrs = ["util_cpu.h"],
)

# cuda_library
cc_library(
cuda_library(
name = "util_cuda",
hdrs = ["util_cuda.h"],
)
Expand Down Expand Up @@ -408,8 +403,7 @@ cc_library(
hdrs = ["vectorspace.h"],
)

# cuda_library
cc_library(
cuda_library(
name = "vectorspace_cuda",
hdrs = ["vectorspace_cuda.h"],
)
Expand Down Expand Up @@ -462,8 +456,7 @@ cc_library(
],
)

# cuda_library
cc_library(
cuda_library(
name = "statespace_cuda",
hdrs = [
"statespace_cuda.h",
Expand Down Expand Up @@ -520,8 +513,7 @@ cc_library(
],
)

# cuda_library
cc_library(
cuda_library(
name = "simulator_cuda",
hdrs = [
"simulator_cuda.h",
Expand Down
30 changes: 30 additions & 0 deletions lib/simmux_gpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023 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_GPU_H_
#define SIMMUX_GPU_H_

#ifdef __CUSTATEVEC__
# include "simulator_custatevec.h"
namespace qsim {
using SimulatorGpu = SimulatorCuStateVec;
}
#else
# include "simulator_cuda.h"
namespace qsim {
using SimulatorGpu = SimulatorCUDA;
}
#endif

#endif // SIMMUX_GPU_H_
2 changes: 1 addition & 1 deletion pybind_interface/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PYBINDFLAGS_AVX2 = -mavx2 -mfma -Wall -shared -std=c++17 -fPIC `python3 -m pybin
PYBINDFLAGS_AVX512 = -mavx512f -mbmi2 -Wall -shared -std=c++17 -fPIC `python3 -m pybind11 --includes`

# The flags for the compilation of GPU-specific Pybind11 interfaces
PYBINDFLAGS_CUDA = -std=c++14 -x cu -Xcompiler "-Wall -shared -fPIC `python3 -m pybind11 --includes`"
PYBINDFLAGS_CUDA = -std=c++17 -x cu -Xcompiler "-Wall -shared -fPIC `python3 -m pybind11 --includes`"

# The flags for the compilation of cuStateVec-specific Pybind11 interfaces
PYBINDFLAGS_CUSTATEVEC = $(CUSTATEVECFLAGS) $(PYBINDFLAGS_CUDA)
Expand Down
4 changes: 2 additions & 2 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ sse_copts = ['-msse4']

windows_copts = [
"/arch:AVX",
"/std:c++14",
"/std:c++17",
]

windows_avx512_copts = [
"/arch:AVX512",
"/std:c++14",
"/std:c++17",
]

config_setting(
Expand Down

0 comments on commit d747970

Please sign in to comment.