From f9c8169d8f4a444b8cbc365363a8c31196acaa88 Mon Sep 17 00:00:00 2001 From: Guangda Lai Date: Wed, 19 Jun 2019 13:33:42 -0700 Subject: [PATCH] Populate TF_TENSORRT_VERSION during configuration process. PiperOrigin-RevId: 254059615 --- tensorflow/opensource_only.files | 1 + .../stream_executor/platform/default/BUILD | 1 + .../platform/default/dso_loader.cc | 5 +--- tensorflow/tools/lib_package/BUILD | 2 ++ tensorflow/tools/pip_package/BUILD | 1 + third_party/tensorrt/BUILD.tpl | 5 +++- .../tensorrt/include/tensorrt_config.h.tpl | 21 +++++++++++++++ third_party/tensorrt/tensorrt_configure.bzl | 26 +++++++++++++++++++ .../preconfig/centos6/tensorrt5/BUILD | 5 +++- .../preconfig/centos6/tensorrt5/LICENSE | 0 .../tensorrt/include/tensorrt_config.h | 21 +++++++++++++++ .../preconfig/ubuntu14.04/tensorrt5/BUILD | 5 +++- .../preconfig/ubuntu14.04/tensorrt5/LICENSE | 0 .../tensorrt/include/tensorrt_config.h | 21 +++++++++++++++ .../preconfig/ubuntu16.04/tensorrt5/BUILD | 5 +++- .../preconfig/ubuntu16.04/tensorrt5/LICENSE | 0 .../tensorrt/include/tensorrt_config.h | 21 +++++++++++++++ 17 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 third_party/tensorrt/tensorrt/include/tensorrt_config.h.tpl create mode 100644 third_party/toolchains/preconfig/centos6/tensorrt5/LICENSE create mode 100644 third_party/toolchains/preconfig/centos6/tensorrt5/tensorrt/include/tensorrt_config.h create mode 100644 third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/LICENSE create mode 100644 third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/tensorrt/include/tensorrt_config.h create mode 100644 third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/LICENSE create mode 100644 third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/tensorrt/include/tensorrt_config.h diff --git a/tensorflow/opensource_only.files b/tensorflow/opensource_only.files index 9e23c22984e..f598b4bd5b0 100644 --- a/tensorflow/opensource_only.files +++ b/tensorflow/opensource_only.files @@ -202,6 +202,7 @@ tensorflow/third_party/tensorrt/BUILD tensorflow/third_party/tensorrt/build_defs.bzl.tpl tensorflow/third_party/tensorrt/BUILD.tpl tensorflow/third_party/tensorrt/tensorrt_configure.bzl +tensorflow/third_party/tensorrt/tensorrt/include/tensorrt_config.h.tpl tensorflow/third_party/kafka/config.patch tensorflow/third_party/kafka/BUILD tensorflow/third_party/android/BUILD diff --git a/tensorflow/stream_executor/platform/default/BUILD b/tensorflow/stream_executor/platform/default/BUILD index ff2555a2215..e039b5e4f57 100644 --- a/tensorflow/stream_executor/platform/default/BUILD +++ b/tensorflow/stream_executor/platform/default/BUILD @@ -27,5 +27,6 @@ cc_library( "//tensorflow/stream_executor/platform", "@com_google_absl//absl/strings", "@local_config_cuda//cuda:cuda_headers", + "@local_config_tensorrt//:tensorrt_headers", ], ) diff --git a/tensorflow/stream_executor/platform/default/dso_loader.cc b/tensorflow/stream_executor/platform/default/dso_loader.cc index c774a987a74..9ae8b41ccf4 100644 --- a/tensorflow/stream_executor/platform/default/dso_loader.cc +++ b/tensorflow/stream_executor/platform/default/dso_loader.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/stream_executor/lib/path.h" #include "tensorflow/stream_executor/platform/logging.h" #include "tensorflow/stream_executor/platform/port.h" +#include "third_party/tensorrt/tensorrt_config.h" namespace stream_executor { namespace internal { @@ -32,10 +33,6 @@ namespace { string GetCudaVersion() { return TF_CUDA_VERSION; } string GetCudaLibVersion() { return TF_CUDA_LIB_VERSION; } string GetCudnnVersion() { return TF_CUDNN_VERSION; } - -// TODO(laigd): populate the version string during configuration process. For -// now hardcoded version 5 since 4.0 is not supported anyway. -#define TF_TENSORRT_VERSION "5" string GetTensorRTVersion() { return TF_TENSORRT_VERSION; } port::StatusOr GetDsoHandle(const string& name, const string& version) { diff --git a/tensorflow/tools/lib_package/BUILD b/tensorflow/tools/lib_package/BUILD index 60c92fbc2a3..b8ebdc81053 100644 --- a/tensorflow/tools/lib_package/BUILD +++ b/tensorflow/tools/lib_package/BUILD @@ -157,6 +157,7 @@ genrule( "@jpeg//:LICENSE.md", "@lmdb//:LICENSE", "@local_config_sycl//sycl:LICENSE.text", + "@local_config_tensorrt//:LICENSE", "@nasm//:LICENSE", "@nsync//:LICENSE", "@png_archive//:LICENSE", @@ -228,6 +229,7 @@ genrule( "@jpeg//:LICENSE.md", "@lmdb//:LICENSE", "@local_config_sycl//sycl:LICENSE.text", + "@local_config_tensorrt//:LICENSE", "@nasm//:LICENSE", "@nsync//:LICENSE", "@png_archive//:LICENSE", diff --git a/tensorflow/tools/pip_package/BUILD b/tensorflow/tools/pip_package/BUILD index bdc4b0afe20..eac8cd43cac 100644 --- a/tensorflow/tools/pip_package/BUILD +++ b/tensorflow/tools/pip_package/BUILD @@ -181,6 +181,7 @@ filegroup( "@keras_applications_archive//:LICENSE", "@lmdb//:LICENSE", "@local_config_sycl//sycl:LICENSE.text", + "@local_config_tensorrt//:LICENSE", "@nasm//:LICENSE", "@nsync//:LICENSE", "@pasta//:LICENSE", diff --git a/third_party/tensorrt/BUILD.tpl b/third_party/tensorrt/BUILD.tpl index aa6cc3928b3..5e3b223e695 100644 --- a/third_party/tensorrt/BUILD.tpl +++ b/third_party/tensorrt/BUILD.tpl @@ -11,7 +11,10 @@ exports_files(["LICENSE"]) cc_library( name = "tensorrt_headers", - hdrs = [":tensorrt_include"], + hdrs = [ + "tensorrt/include/tensorrt_config.h", + ":tensorrt_include" + ], include_prefix = "third_party/tensorrt", strip_include_prefix = "tensorrt/include", ) diff --git a/third_party/tensorrt/tensorrt/include/tensorrt_config.h.tpl b/third_party/tensorrt/tensorrt/include/tensorrt_config.h.tpl new file mode 100644 index 00000000000..f9a09cf51e5 --- /dev/null +++ b/third_party/tensorrt/tensorrt/include/tensorrt_config.h.tpl @@ -0,0 +1,21 @@ +/* Copyright 2019 The TensorFlow Authors. 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 + + http://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 TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ +#define TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ + +#define TF_TENSORRT_VERSION "%{tensorrt_version}" + +#endif // TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ diff --git a/third_party/tensorrt/tensorrt_configure.bzl b/third_party/tensorrt/tensorrt_configure.bzl index 81612e52124..603732fce21 100644 --- a/third_party/tensorrt/tensorrt_configure.bzl +++ b/third_party/tensorrt/tensorrt_configure.bzl @@ -61,6 +61,9 @@ def _create_dummy_repository(repository_ctx): "\":tensorrt_include\"": "", "\":tensorrt_lib\"": "", }) + _tpl(repository_ctx, "tensorrt/include/tensorrt_config.h", { + "%{tensorrt_version}": "", + }) def enable_tensorrt(repository_ctx): """Returns whether to build with TensorRT support.""" @@ -77,8 +80,25 @@ def _tensorrt_configure_impl(repository_ctx): Label(remote_config_repo + ":build_defs.bzl"), {}, ) + repository_ctx.template( + "tensorrt/include/tensorrt_config.h", + Label(remote_config_repo + ":tensorrt/include/tensorrt_config.h"), + {}, + ) + repository_ctx.template( + "LICENSE", + Label(remote_config_repo + ":LICENSE"), + {}, + ) return + # Copy license file in non-remote build. + repository_ctx.template( + "LICENSE", + Label("//third_party/tensorrt:LICENSE"), + {}, + ) + if not enable_tensorrt(repository_ctx): _create_dummy_repository(repository_ctx) return @@ -115,6 +135,12 @@ def _tensorrt_configure_impl(repository_ctx): "%{copy_rules}": "\n".join(copy_rules), }) + # Set up tensorrt_config.h, which is used by + # tensorflow/stream_executor/dso_loader.cc. + _tpl(repository_ctx, "tensorrt/include/tensorrt_config.h", { + "%{tensorrt_version}": trt_version, + }) + tensorrt_configure = repository_rule( implementation = _tensorrt_configure_impl, environ = [ diff --git a/third_party/toolchains/preconfig/centos6/tensorrt5/BUILD b/third_party/toolchains/preconfig/centos6/tensorrt5/BUILD index 842efab2465..e179b9361e7 100755 --- a/third_party/toolchains/preconfig/centos6/tensorrt5/BUILD +++ b/third_party/toolchains/preconfig/centos6/tensorrt5/BUILD @@ -11,7 +11,10 @@ exports_files(["LICENSE"]) cc_library( name = "tensorrt_headers", - hdrs = [":tensorrt_include"], + hdrs = [ + "tensorrt/include/tensorrt_config.h", + ":tensorrt_include", + ], include_prefix = "third_party/tensorrt", strip_include_prefix = "tensorrt/include", ) diff --git a/third_party/toolchains/preconfig/centos6/tensorrt5/LICENSE b/third_party/toolchains/preconfig/centos6/tensorrt5/LICENSE new file mode 100644 index 00000000000..e69de29bb2d diff --git a/third_party/toolchains/preconfig/centos6/tensorrt5/tensorrt/include/tensorrt_config.h b/third_party/toolchains/preconfig/centos6/tensorrt5/tensorrt/include/tensorrt_config.h new file mode 100644 index 00000000000..02a166f4cd1 --- /dev/null +++ b/third_party/toolchains/preconfig/centos6/tensorrt5/tensorrt/include/tensorrt_config.h @@ -0,0 +1,21 @@ +/* Copyright 2019 The TensorFlow Authors. 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 + + http://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 TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ +#define TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ + +#define TF_TENSORRT_VERSION "5" + +#endif // TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ diff --git a/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/BUILD b/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/BUILD index 9f7adc493c9..121990a9aff 100755 --- a/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/BUILD +++ b/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/BUILD @@ -11,7 +11,10 @@ exports_files(["LICENSE"]) cc_library( name = "tensorrt_headers", - hdrs = [":tensorrt_include"], + hdrs = [ + "tensorrt/include/tensorrt_config.h", + ":tensorrt_include", + ], include_prefix = "third_party/tensorrt", strip_include_prefix = "tensorrt/include", ) diff --git a/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/LICENSE b/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/LICENSE new file mode 100644 index 00000000000..e69de29bb2d diff --git a/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/tensorrt/include/tensorrt_config.h b/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/tensorrt/include/tensorrt_config.h new file mode 100644 index 00000000000..02a166f4cd1 --- /dev/null +++ b/third_party/toolchains/preconfig/ubuntu14.04/tensorrt5/tensorrt/include/tensorrt_config.h @@ -0,0 +1,21 @@ +/* Copyright 2019 The TensorFlow Authors. 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 + + http://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 TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ +#define TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ + +#define TF_TENSORRT_VERSION "5" + +#endif // TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ diff --git a/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/BUILD b/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/BUILD index 9f7adc493c9..121990a9aff 100755 --- a/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/BUILD +++ b/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/BUILD @@ -11,7 +11,10 @@ exports_files(["LICENSE"]) cc_library( name = "tensorrt_headers", - hdrs = [":tensorrt_include"], + hdrs = [ + "tensorrt/include/tensorrt_config.h", + ":tensorrt_include", + ], include_prefix = "third_party/tensorrt", strip_include_prefix = "tensorrt/include", ) diff --git a/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/LICENSE b/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/LICENSE new file mode 100644 index 00000000000..e69de29bb2d diff --git a/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/tensorrt/include/tensorrt_config.h b/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/tensorrt/include/tensorrt_config.h new file mode 100644 index 00000000000..02a166f4cd1 --- /dev/null +++ b/third_party/toolchains/preconfig/ubuntu16.04/tensorrt5/tensorrt/include/tensorrt_config.h @@ -0,0 +1,21 @@ +/* Copyright 2019 The TensorFlow Authors. 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 + + http://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 TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ +#define TENSORRT_TENSORRT_INCLUDE_CONFIG_H_ + +#define TF_TENSORRT_VERSION "5" + +#endif // TENSORRT_TENSORRT_INCLUDE_CONFIG_H_