Skip to content

Commit

Permalink
Upgrade to TFv2.11 and add CUDA support
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyoo committed Mar 17, 2023
1 parent 658cc3b commit 8967675
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 20 deletions.
8 changes: 6 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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

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

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

# Test flags
test --test_output=errors

# CUDA options
build:cuda --@local_config_cuda//:enable_cuda
build --experimental_repo_remote_exec
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-*
25 changes: 20 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +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",
],
)


EIGEN_COMMIT = "12e8d57108c50d8a63605c6eb0144c838c128337"
EIGEN_SHA256 = "f689246e342c3955af48d26ce74ac34d21b579a00675c341721a735937919b02"
EIGEN_COMMIT = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e"
EIGEN_SHA256 = "eca9847b3fe6249e0234a342b78f73feec07d29f534e914ba5f920f3e09383a3"

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

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()

http_archive(
name = "eigen",
Expand Down
17 changes: 7 additions & 10 deletions lib/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured", "cuda_library")

package(default_visibility = ["//visibility:public"])

# Libraries of the following form:
Expand Down Expand Up @@ -67,8 +69,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 @@ -247,8 +248,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 +408,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 +461,7 @@ cc_library(
],
)

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

# cuda_library
cc_library(
cuda_library(
name = "simulator_cuda",
hdrs = [
"simulator_cuda.h",
Expand Down
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
22 changes: 20 additions & 2 deletions tests/BUILD
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured")

# Options for testing different simulator types.
avx_copts = ['-mavx2', '-mfma']
avx512_copts = ['-march=native']
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 Expand Up @@ -353,6 +355,22 @@ cc_test(
}),
)

cc_test(
name = "simulator_cuda_test",
srcs = ["simulator_cuda_test.cu"],
deps = [
":simulator_testfixture",
"@com_google_googletest//:gtest_main",
"//lib:parfor",
"//lib:seqfor",
] + if_cuda_is_configured(["//lib:simulator_cuda"]),
linkshared = 1,
copts = select({
":windows": windows_copts + ["/D__CLANG_SUPPORT_DYN_ANNOTATION__", "/DEIGEN_MPL2_ONLY", "/DEIGEN_MAX_ALIGN_BYTES=64", "/DEIGEN_HAS_TYPE_TRAITS=0", "/DTF_USE_SNAPPY", "/showIncludes", "/MD", "/O2", "/DNDEBUG", "/w", "-DWIN32_LEAN_AND_MEAN", "-DNOGDI", "/d2ReducedOptimizeHugeFunctions", "/arch:AVX", "/std:c++17", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", "/DTENSORFLOW_USE_EIGEN_THREADPOOL", "/DEIGEN_AVOID_STL_ARRAY", "/Iexternal/gemmlowp", "/wd4018", "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY"],
"//conditions:default": ["-pthread", "-std=c++17", "-D_GLIBCXX_USE_CXX11_ABI=1"],
}) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]),
)

cc_library(
name = "statespace_testfixture",
hdrs = ["statespace_testfixture.h"],
Expand Down

0 comments on commit 8967675

Please sign in to comment.