Skip to content

Commit

Permalink
Merge pull request #66 from mchinen/v333_4
Browse files Browse the repository at this point in the history
ViSQOL v333 with tflite support (linux/mac/win) and python support (linux/mac)
  • Loading branch information
mchinen authored Apr 7, 2022
2 parents 51da255 + c3a1ee6 commit c3aa2e4
Show file tree
Hide file tree
Showing 122 changed files with 4,047 additions and 2,138 deletions.
102 changes: 102 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Most of this file is to allow tensorflow to build.
# Inspired by TensorFlow serving's .bazelrc to build from the source.
# It also may be useful to refer to TensorFlow .bazelrc for more details:
# https://github.com/tensorflow/tensorflow/blob/master/.bazelrc

# Optimizations used for TF Serving release builds.
build:release --copt=-mavx
build:release --copt=-msse4.2

# Options used to build with CUDA.
build:cuda --repo_env TF_NEED_CUDA=1
build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain
build:cuda --@local_config_cuda//:enable_cuda
build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true
build:cuda --action_env=TF_CUDA_COMPUTE_CAPABILITIES="sm_35,sm_50,sm_60,sm_70,sm_75,compute_80"

# Options used to build with TPU support.
build:tpu --distinct_host_configuration=false
build:tpu --define=with_tpu_support=true --define=framework_shared_object=false

# Please note that MKL on MacOS or windows is still not supported.
# If you would like to use a local MKL instead of downloading, please set the
# environment variable "TF_MKL_ROOT" every time before build.
build:mkl --define=build_with_mkl=true --define=enable_mkl=true --define=build_with_openmp=true
build:mkl --define=tensorflow_mkldnn_contraction_kernel=0

# This config option is used to enable MKL-DNN open source library only,
# without depending on MKL binary version.
build:mkl_open_source_only --define=build_with_mkl_dnn_only=true
build:mkl_open_source_only --define=build_with_mkl=true --define=enable_mkl=true
build:mkl_open_source_only --define=tensorflow_mkldnn_contraction_kernel=0

# Processor native optimizations (depends on build host capabilities).
build:nativeopt --copt=-march=native
build:nativeopt --host_copt=-march=native
build:nativeopt --copt=-O3

build --keep_going
build --verbose_failures=true
build --spawn_strategy=standalone
build --genrule_strategy=standalone

build --define=grpc_no_ares=true

# Sets the default Apple platform to macOS.
build --apple_platform_type=macos

build -c opt

# ViSQOL is overridding the default c++14 settings in tensorflow.
# TF's .bazelrc claims it c++14 required, but it is likely required
# in the sense that it is backwards compatible with c++17.
build --cxxopt=-std=c++17
build --linkopt=-ldl
build --host_cxxopt=-std=c++17

build --experimental_repo_remote_exec

# Enable platform specific config (e.g. by default use --config=windows when on windows, and --config=linux when on linux)
build --enable_platform_specific_config


## Windows config
startup --windows_enable_symlinks
build:windows --enable_runfiles

# These settings below allow for compilation using MSVC
# It would be nice to use clang to compile for Windows as well,
# but the bazel instructions did not work.
build:windows --copt=/D_USE_MATH_DEFINES
build:windows --host_copt=/D_USE_MATH_DEFINES
build:windows --cxxopt=-D_HAS_DEPRECATED_RESULT_OF=1

build:windows --cxxopt=/Zc:__cplusplus
# c++20 needed in MSVC for designated initializers (llvm libc++
# and gnu stc++ provides them in c++17).
build:windows --cxxopt=/std:c++20
build:windows --linkopt=-ldl
build:windows --host_cxxopt=/std:c++20

# Make sure to include as little of windows.h as possible
build:windows --copt=-DWIN32_LEAN_AND_MEAN
build:windows --host_copt=-DWIN32_LEAN_AND_MEAN
build:windows --copt=-DNOGDI
build:windows --host_copt=-DNOGDI

# MSVC (Windows): Standards-conformant preprocessor mode
# See https://docs.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview
build:windows --copt=/Zc:preprocessor
build:windows --host_copt=/Zc:preprocessor

# Misc build options we need for windows according to tensorflow
build:windows --linkopt=/DEBUG
build:windows --host_linkopt=/DEBUG
build:windows --linkopt=/OPT:REF
build:windows --host_linkopt=/OPT:REF
build:windows --linkopt=/OPT:ICF
build:windows --host_linkopt=/OPT:ICF
# This is a workaround for this magic preprocessor constant/macro not existing
# in MSVC
build:windows --host_copt=-D__PRETTY_FUNCTION__=__FUNCSIG__
build:windows --copt=-D__PRETTY_FUNCTION__=__FUNCSIG__
123 changes: 104 additions & 19 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library")

package(
default_visibility = ["//visibility:private"],
)
Expand Down Expand Up @@ -33,6 +35,51 @@ cc_proto_library(
deps = [":visqol_config"],
)

py_proto_library(
name = "similarity_result_py_pb2",
visibility = ["//visibility:public"],
deps = [":similarity_result"],
)

py_proto_library(
name = "visqol_config_py_pb2",
visibility = ["//visibility:public"],
deps = [":visqol_config"],
)

cc_library(
name = "tflite_quality_mapper",
srcs = ["src/tflite_quality_mapper.cc"],
hdrs = ["src/include/tflite_quality_mapper.h"],
includes = ["src/include"],
deps = [
":file_path",
":similarity_to_quality_mapper",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@org_tensorflow//tensorflow/lite:framework",
"@org_tensorflow//tensorflow/lite/c:c_api_types",
"@org_tensorflow//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
"@org_tensorflow//tensorflow/lite/kernels:builtin_ops",
],
)

cc_library(
name = "similarity_to_quality_mapper",
hdrs = ["src/include/similarity_to_quality_mapper.h"],
deps = [
"@com_google_absl//absl/status",
],
)

cc_library(
name = "file_path",
hdrs = ["src/include/file_path.h"],
deps = [
"@com_google_absl//absl/strings",
],
)

cc_library(
name = "visqol_lib",
srcs = glob(
Expand All @@ -44,9 +91,19 @@ cc_library(
"src/svr_training/*.h",
"src/include/*.h",
],
exclude = ["**/main.cc"],
exclude = [
"**/main.cc",
"src/tflite_quality_mapper.cc",
"src/include/tflite_quality_mapper.h",
],
),
hdrs = glob(
["src/include/*.h"],
exclude = [
"src/include/tflite_quality_mapper.h",
"src/include/similarity_to_quality_mapper.h",
],
),
hdrs = glob(["src/include/*.h"]),
copts = select({
"@bazel_tools//src/conditions:windows": [
# Windows Compile Opts
Expand All @@ -56,31 +113,36 @@ cc_library(
# Mac/Linux Compile Opts
],
}),
data = [
"//model:libsvm_nu_svr_model.txt",
"//model:tflite_speech_lattice_default_model",
],
includes = [
"src/include",
"src/proto",
"src/svr_training",
],
visibility = ["//visibility:public"],
deps = [
":file_path",
":similarity_result_cc_proto",
":similarity_to_quality_mapper",
":tflite_quality_mapper",
":visqol_config_cc_proto",
"@com_google_absl//absl/base",
"@armadillo_headers//:armadillo_header",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/flags:usage",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/types:optional",
"@com_google_absl//absl/types:span",
"@armadillo_headers//:armadillo_header",
"@svm_lib//:libsvm",
"@pffft_lib//:pffft_lib",
"@boost//:filesystem",
"@boost//:system",
"@com_google_protobuf//:protobuf_lite",
"@pffft_lib",
"@svm_lib//:libsvm",
],
)

Expand All @@ -90,8 +152,8 @@ cc_binary(
name = "visqol",
srcs = ["src/main.cc"],
data = [
"//model:lattice_tcditugenmeetpackhref_ls2_nl60_lr12_bs2048_learn.005_ep2400_train1_7_raw.tflite",
"//model:libsvm_nu_svr_model.txt",
"//model:tcdvoip_nu.568_c5.31474325639_g3.17773760038_model.txt",
],
visibility = ["//visibility:public"],
deps = [
Expand Down Expand Up @@ -146,9 +208,11 @@ cc_library(
testonly = True,
hdrs = ["tests/test_utility.h"],
deps = [
":file_path",
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -173,8 +237,8 @@ cc_test(
deps = [
":test_utility",
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/flags:flag",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -186,8 +250,17 @@ cc_test(
],
deps = [
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/memory",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "visqol_test",
srcs = ["tests/visqol_test.cc"],
deps = [
":visqol_lib",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -208,9 +281,9 @@ cc_test(
":similarity_result_cc_proto",
":visqol_config_cc_proto",
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/status",
"@com_google_googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -253,8 +326,8 @@ cc_test(
],
deps = [
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/flags:flag",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -263,8 +336,8 @@ cc_test(
srcs = ["tests/comparison_patches_selector_test.cc"],
deps = [
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -306,6 +379,7 @@ cc_test(
deps = [
":test_utility",
":visqol_lib",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)
Expand All @@ -322,8 +396,8 @@ cc_test(
deps = [
":test_utility",
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/memory",
"@com_google_googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -442,8 +516,8 @@ cc_test(
],
deps = [
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/memory",
"@com_google_googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -485,8 +559,8 @@ cc_test(
deps = [
":test_utility",
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/flags:flag",
"@com_google_googletest//:gtest_main",
],
)

Expand Down Expand Up @@ -527,7 +601,18 @@ cc_test(
deps = [
":test_utility",
":visqol_lib",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "tflite_quality_mapper_test",
srcs = ["tests/tflite_quality_mapper_test.cc"],
data = ["//model:tflite_speech_lattice_default_model"],
deps = [
":tflite_quality_mapper",
"@com_google_googletest//:gtest_main",
],
)
Loading

0 comments on commit c3aa2e4

Please sign in to comment.