[TF:TRT] Clean up the implementation for getting the TensorRT version.

Move the implementation from utils/py_utils.cc to common/utils.cc. Delete the
string returning version of the routines from convert/utils.cc

PiperOrigin-RevId: 327663715
Change-Id: Ic8652e03677ebad0730c9685cd43c14079a741e9
This commit is contained in:
Bixia Zheng 2020-08-20 11:24:58 -07:00 committed by TensorFlower Gardener
parent 7d04ea3da4
commit ea8f734603
9 changed files with 73 additions and 79 deletions

View File

@ -80,6 +80,7 @@ tf_cuda_cc_test(
cc_library( cc_library(
name = "common_utils", name = "common_utils",
srcs = ["common/utils.cc"],
hdrs = ["common/utils.h"], hdrs = ["common/utils.h"],
copts = tf_copts(), copts = tf_copts(),
deps = [ deps = [
@ -587,6 +588,7 @@ pybind_extension(
link_in_framework = True, link_in_framework = True,
module_name = "_pywrap_py_utils", module_name = "_pywrap_py_utils",
deps = [ deps = [
":common_utils",
":py_utils", ":py_utils",
"//tensorflow/core/platform:env", "//tensorflow/core/platform:env",
"//tensorflow/core/platform:logging", "//tensorflow/core/platform:logging",

View File

@ -0,0 +1,48 @@
/* Copyright 2020 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.
==============================================================================*/
#include "tensorflow/compiler/tf2tensorrt/common/utils.h"
#if GOOGLE_CUDA && GOOGLE_TENSORRT
#include "third_party/tensorrt/NvInfer.h"
#endif // GOOGLE_CUDA && GOOGLE_TENSORRT
namespace tensorflow {
namespace tensorrt {
std::tuple<int, int, int> GetLinkedTensorRTVersion() {
#if GOOGLE_CUDA && GOOGLE_TENSORRT
return std::tuple<int, int, int>{NV_TENSORRT_MAJOR, NV_TENSORRT_MINOR,
NV_TENSORRT_PATCH};
#else
return std::tuple<int, int, int>{0, 0, 0};
#endif
}
std::tuple<int, int, int> GetLoadedTensorRTVersion() {
#if GOOGLE_CUDA && GOOGLE_TENSORRT
int ver = getInferLibVersion();
int major = ver / 1000;
ver = ver - major * 1000;
int minor = ver / 100;
int patch = ver - minor * 100;
return std::tuple<int, int, int>{major, minor, patch};
#else
return std::tuple<int, int, int>{0, 0, 0};
#endif
}
} // namespace tensorrt
} // namespace tensorflow

View File

@ -16,6 +16,20 @@ limitations under the License.
#ifndef TENSORFLOW_COMPILER_TF2TENSORRT_COMMON_UTILS_H_ #ifndef TENSORFLOW_COMPILER_TF2TENSORRT_COMMON_UTILS_H_
#define TENSORFLOW_COMPILER_TF2TENSORRT_COMMON_UTILS_H_ #define TENSORFLOW_COMPILER_TF2TENSORRT_COMMON_UTILS_H_
#include <tuple>
namespace tensorflow {
namespace tensorrt {
// Returns the compile time TensorRT library version information
// {Maj, Min, Patch}.
std::tuple<int, int, int> GetLinkedTensorRTVersion();
// Returns the runtime time TensorRT library version information
// {Maj, Min, Patch}.
std::tuple<int, int, int> GetLoadedTensorRTVersion();
} // namespace tensorrt
} // namespace tensorflow
#if GOOGLE_CUDA && GOOGLE_TENSORRT #if GOOGLE_CUDA && GOOGLE_TENSORRT
#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/logging.h"

View File

@ -1203,8 +1203,10 @@ static void InitializeTrtPlugins(nvinfer1::ILogger* trt_logger) {
mutex_lock lock(plugin_mutex); mutex_lock lock(plugin_mutex);
if (plugin_initialized) return; if (plugin_initialized) return;
LOG(INFO) << "Linked TensorRT version: " << GetLinkedTensorRTVersion(); LOG(INFO) << "Linked TensorRT version: "
LOG(INFO) << "Loaded TensorRT version: " << GetLoadedTensorRTVersion(); << absl::StrJoin(GetLinkedTensorRTVersion(), ".");
LOG(INFO) << "Loaded TensorRT version: "
<< absl::StrJoin(GetLoadedTensorRTVersion(), ".");
plugin_initialized = initLibNvInferPlugins(trt_logger, ""); plugin_initialized = initLibNvInferPlugins(trt_logger, "");
if (!plugin_initialized) { if (!plugin_initialized) {
@ -1434,7 +1436,8 @@ Status Converter::BuildCudaEngine(
TF_RETURN_IF_ERROR( TF_RETURN_IF_ERROR(
TrtPrecisionModeToName(precision_mode_, &precision_mode_str)); TrtPrecisionModeToName(precision_mode_, &precision_mode_str));
string trt_network_name = StrCat( string trt_network_name = StrCat(
"TF:", TF_VERSION_STRING, ", ", "TRT:", GetLoadedTensorRTVersion(), "-", "TF:", TF_VERSION_STRING, ", ",
"TRT:", absl::StrJoin(GetLoadedTensorRTVersion(), "."), "-",
"Precision:", precision_mode_str, ", ", "Calibration:", use_calibration_, "Precision:", precision_mode_str, ", ", "Calibration:", use_calibration_,
", ", "Max-Batch-Size:", max_batch_size, ", ", ", ", "Max-Batch-Size:", max_batch_size, ", ",
"Max-Workspace-Size:", max_workspace_size_bytes); "Max-Workspace-Size:", max_workspace_size_bytes);

View File

@ -241,36 +241,6 @@ int GetNumberOfEngineInputs(const nvinfer1::ICudaEngine* engine) {
#endif #endif
string GetLinkedTensorRTVersion() {
int major, minor, patch;
#if GOOGLE_CUDA && GOOGLE_TENSORRT
major = NV_TENSORRT_MAJOR;
minor = NV_TENSORRT_MINOR;
patch = NV_TENSORRT_PATCH;
#else
major = 0;
minor = 0;
patch = 0;
#endif
return absl::StrCat(major, ".", minor, ".", patch);
}
string GetLoadedTensorRTVersion() {
int major, minor, patch;
#if GOOGLE_CUDA && GOOGLE_TENSORRT
int ver = getInferLibVersion();
major = ver / 1000;
ver = ver - major * 1000;
minor = ver / 100;
patch = ver - minor * 100;
#else
major = 0;
minor = 0;
patch = 0;
#endif
return absl::StrCat(major, ".", minor, ".", patch);
}
absl::string_view GetDeviceName(const Node* node) { absl::string_view GetDeviceName(const Node* node) {
if (node->has_assigned_device_name()) { if (node->has_assigned_device_name()) {
return node->assigned_device_name(); return node->assigned_device_name();

View File

@ -117,14 +117,6 @@ Status TrtDimsToTensorShape(const nvinfer1::Dims trt_dims,
Status TfTypeToTrtType(DataType tf_type, nvinfer1::DataType* trt_type); Status TfTypeToTrtType(DataType tf_type, nvinfer1::DataType* trt_type);
Status TrtTypeToTfType(nvinfer1::DataType trt_type, DataType* tf_type); Status TrtTypeToTfType(nvinfer1::DataType trt_type, DataType* tf_type);
// Returns a string that includes compile time TensorRT library version
// information {Maj, Min, Patch}.
string GetLinkedTensorRTVersion();
// Returns a string that includes runtime time TensorRT library version
// information {Maj, Min, Patch}.
string GetLoadedTensorRTVersion();
// Returns true if an engine built for cached_shapes can also run actual_shapes. // Returns true if an engine built for cached_shapes can also run actual_shapes.
bool AreShapesCompatible(const std::vector<TensorShape>& actual_shapes, bool AreShapesCompatible(const std::vector<TensorShape>& actual_shapes,
const std::vector<TensorShape>& cached_shapes); const std::vector<TensorShape>& cached_shapes);

View File

@ -41,31 +41,5 @@ bool IsGoogleTensorRTEnabled() {
#endif #endif
} }
void GetLinkedTensorRTVersion(int* major, int* minor, int* patch) {
#if GOOGLE_CUDA && GOOGLE_TENSORRT
*major = NV_TENSORRT_MAJOR;
*minor = NV_TENSORRT_MINOR;
*patch = NV_TENSORRT_PATCH;
#else
*major = 0;
*minor = 0;
*patch = 0;
#endif
}
void GetLoadedTensorRTVersion(int* major, int* minor, int* patch) {
#if GOOGLE_CUDA && GOOGLE_TENSORRT
int ver = getInferLibVersion();
*major = ver / 1000;
ver = ver - *major * 1000;
*minor = ver / 100;
*patch = ver - *minor * 100;
#else
*major = 0;
*minor = 0;
*patch = 0;
#endif
}
} // namespace tensorrt } // namespace tensorrt
} // namespace tensorflow } // namespace tensorflow

View File

@ -21,12 +21,6 @@ namespace tensorrt {
bool IsGoogleTensorRTEnabled(); bool IsGoogleTensorRTEnabled();
// Return compile time TensorRT library version information {Maj, Min, Patch}.
void GetLinkedTensorRTVersion(int* major, int* minor, int* patch);
// Return runtime time TensorRT library version information {Maj, Min, Patch}.
void GetLoadedTensorRTVersion(int* major, int* minor, int* patch);
} // namespace tensorrt } // namespace tensorrt
} // namespace tensorflow } // namespace tensorflow

View File

@ -16,18 +16,15 @@ limitations under the License.
#include <tuple> #include <tuple>
#include "pybind11/pybind11.h" #include "pybind11/pybind11.h"
#include "tensorflow/compiler/tf2tensorrt/common/utils.h"
#include "tensorflow/compiler/tf2tensorrt/utils/py_utils.h" #include "tensorflow/compiler/tf2tensorrt/utils/py_utils.h"
std::tuple<int, int, int> get_linked_tensorrt_version() { std::tuple<int, int, int> get_linked_tensorrt_version() {
int major, minor, patch; return tensorflow::tensorrt::GetLinkedTensorRTVersion();
tensorflow::tensorrt::GetLinkedTensorRTVersion(&major, &minor, &patch);
return std::tuple<int, int, int>{major, minor, patch};
} }
std::tuple<int, int, int> get_loaded_tensorrt_version() { std::tuple<int, int, int> get_loaded_tensorrt_version() {
int major, minor, patch; return tensorflow::tensorrt::GetLoadedTensorRTVersion();
tensorflow::tensorrt::GetLoadedTensorRTVersion(&major, &minor, &patch);
return std::tuple<int, int, int>{major, minor, patch};
} }
PYBIND11_MODULE(_pywrap_py_utils, m) { PYBIND11_MODULE(_pywrap_py_utils, m) {