Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tensorflow c++ api support #41

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion build_deps/tf_dependency/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ cc_library(
visibility = ["//visibility:public"],
)


cc_library(
name = "libtensorflow_cc",
srcs = ["%{TF_SHARED_CC_LIBRARY_NAME}"],
visibility = ["//visibility:public"],
)

%{TF_HEADER_GENRULE}
%{TF_SHARED_LIBRARY_GENRULE}
%{TF_SHARED_LIBRARY_GENRULE}
%{TF_SHARED_CC_LIBRARY_GENRULE}
16 changes: 16 additions & 0 deletions build_deps/tf_dependency/tf_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ _TF_SHARED_LIBRARY_DIR = "TF_SHARED_LIBRARY_DIR"

_TF_SHARED_LIBRARY_NAME = "TF_SHARED_LIBRARY_NAME"

_TF_SHARED_CC_LIBRARY_NAME = "TF_SHARED_CC_LIBRARY_NAME"

_TF_CXX11_ABI_FLAG = "TF_CXX11_ABI_FLAG"

_TF_CPLUSPLUS_VER = "TF_CPLUSPLUS_VER"
Expand Down Expand Up @@ -204,7 +206,9 @@ def _tf_pip_impl(repository_ctx):

tf_shared_library_dir = repository_ctx.os.environ[_TF_SHARED_LIBRARY_DIR]
tf_shared_library_name = repository_ctx.os.environ[_TF_SHARED_LIBRARY_NAME]
tf_shared_cc_library_name = repository_ctx.os.environ[_TF_SHARED_CC_LIBRARY_NAME]
tf_shared_library_path = "%s/%s" % (tf_shared_library_dir, tf_shared_library_name)
tf_shared_cc_library_path = "%s/%s" % (tf_shared_library_dir, tf_shared_cc_library_name)
tf_cx11_abi = "-D_GLIBCXX_USE_CXX11_ABI=%s" % (repository_ctx.os.environ[_TF_CXX11_ABI_FLAG])
tf_cplusplus_ver = "-std=%s" % repository_ctx.os.environ[_TF_CPLUSPLUS_VER]

Expand All @@ -217,10 +221,21 @@ def _tf_pip_impl(repository_ctx):
[tf_shared_library_name],
)

tf_shared_cc_library_rule = _symlink_genrule_for_dir(
repository_ctx,
None,
"",
tf_shared_cc_library_name,
[tf_shared_cc_library_path],
[tf_shared_cc_library_name],
)

_tpl(repository_ctx, "BUILD", {
"%{TF_HEADER_GENRULE}": tf_header_rule,
"%{TF_SHARED_LIBRARY_GENRULE}": tf_shared_library_rule,
"%{TF_SHARED_CC_LIBRARY_GENRULE}": tf_shared_cc_library_rule,
"%{TF_SHARED_LIBRARY_NAME}": tf_shared_library_name,
"%{TF_SHARED_CC_LIBRARY_NAME}": tf_shared_cc_library_name,
})

_tpl(
Expand All @@ -237,6 +252,7 @@ tf_configure = repository_rule(
_TF_HEADER_DIR,
_TF_SHARED_LIBRARY_DIR,
_TF_SHARED_LIBRARY_NAME,
_TF_SHARED_CC_LIBRARY_NAME,
_TF_CXX11_ABI_FLAG,
_TF_CPLUSPLUS_VER,
],
Expand Down
12 changes: 8 additions & 4 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,10 @@ def set_gcc_host_compiler_path(environ_cp):


def choose_compiler(environ_cp):
question = 'Do you want to use Clang to build TensorFlow?'
yes_reply = 'Clang will be used to compile TensorFlow.'
no_reply = 'GCC will be used to compile TensorFlow.'
var = int(get_var(environ_cp, 'TF_NEED_CLANG', None, True, question, yes_reply, no_reply))
question = 'Do you want to use Clang to build Deepray?'
yes_reply = 'Clang will be used to compile Deepray.'
no_reply = 'GCC will be used to compile Deepray.'
var = int(get_var(environ_cp, 'TF_NEED_CLANG', None, False, question, yes_reply, no_reply))
return var


Expand Down Expand Up @@ -1141,6 +1141,10 @@ def main():
write_action_env_to_bazelrc("TF_HEADER_DIR", get_tf_header_dir())
write_action_env_to_bazelrc("TF_SHARED_LIBRARY_DIR", get_tf_shared_lib_dir())
write_action_env_to_bazelrc("TF_SHARED_LIBRARY_NAME", get_shared_lib_name())
write_action_env_to_bazelrc(
"TF_SHARED_CC_LIBRARY_NAME",
get_shared_lib_name().replace("libtensorflow_framework", "libtensorflow_cc")
)
write_action_env_to_bazelrc("TF_CXX11_ABI_FLAG", tf.sysconfig.CXX11_ABI_FLAG)
# This should be replaced with a call to tf.sysconfig if it's added
write_action_env_to_bazelrc("TF_CPLUSPLUS_VER", get_cpp_version())
Expand Down
Loading
Loading