From 2b0718bbfbdfcb9a28c4114dd3ec97cee16ea9d7 Mon Sep 17 00:00:00 2001 From: Gunhan Gulsoy Date: Wed, 2 Oct 2019 11:05:09 -0700 Subject: [PATCH] Remove all usages of STLDeleteElements and remove the function from tensorflow/core PiperOrigin-RevId: 272476237 --- .../tf2tensorrt/kernels/trt_engine_op_test.cc | 6 ++++-- .../kernels/trt_engine_resource_ops_test.cc | 11 ++++++++--- tensorflow/core/common_runtime/process_state.cc | 6 ++++-- tensorflow/core/framework/device_base.cc | 8 ++++++-- tensorflow/core/kernels/ops_testutil.h | 16 ++++++++++++---- tensorflow/core/lib/gtl/stl_util.h | 17 ----------------- tensorflow/core/lib/gtl/top_n_test.cc | 6 ++++-- 7 files changed, 38 insertions(+), 32 deletions(-) diff --git a/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_op_test.cc b/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_op_test.cc index 4228136e0c8..d375cb2b2f8 100644 --- a/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_op_test.cc +++ b/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_op_test.cc @@ -36,7 +36,6 @@ limitations under the License. #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/kernels/ops_testutil.h" -#include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/platform/test.h" #if GOOGLE_CUDA @@ -102,7 +101,10 @@ class TRTEngineOpTestBase : public OpsTestBase { void ResetInputs() { inputs_.clear(); - gtl::STLDeleteElements(&tensors_); + for (auto& temp : tensors_) { + delete temp; + } + tensors_.clear(); } private: diff --git a/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_resource_ops_test.cc b/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_resource_ops_test.cc index d27a67582d8..21ff913b84c 100644 --- a/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_resource_ops_test.cc +++ b/tensorflow/compiler/tf2tensorrt/kernels/trt_engine_resource_ops_test.cc @@ -29,7 +29,6 @@ limitations under the License. #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/kernels/ops_testutil.h" -#include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/io/record_reader.h" #include "tensorflow/core/platform/env.h" @@ -44,9 +43,15 @@ namespace tensorrt { class TRTEngineResourceOpsTest : public OpsTestBase { protected: void Reset() { + for (auto& temp : tensors_) { + delete temp; + } + for (auto& temp : managed_outputs_) { + delete temp; + } + tensors_.clear(); + managed_outputs_.clear(); inputs_.clear(); - gtl::STLDeleteElements(&tensors_); - gtl::STLDeleteElements(&managed_outputs_); } TrtUniquePtrType CreateTRTEngine() { diff --git a/tensorflow/core/common_runtime/process_state.cc b/tensorflow/core/common_runtime/process_state.cc index fdb79767ec1..06f969faf42 100644 --- a/tensorflow/core/common_runtime/process_state.cc +++ b/tensorflow/core/common_runtime/process_state.cc @@ -23,7 +23,6 @@ limitations under the License. #include "tensorflow/core/framework/allocator.h" #include "tensorflow/core/framework/log_memory.h" #include "tensorflow/core/framework/tracking_allocator.h" -#include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/mutex.h" @@ -148,7 +147,10 @@ void ProcessState::TestOnlyReset() { if (a != default_cpu_allocator) delete a; } cpu_allocators_.clear(); - gtl::STLDeleteElements(&cpu_al_); + for (Allocator* a : cpu_al_) { + delete a; + } + cpu_al_.clear(); } } // namespace tensorflow diff --git a/tensorflow/core/framework/device_base.cc b/tensorflow/core/framework/device_base.cc index f0ecfc5da40..c962f233962 100644 --- a/tensorflow/core/framework/device_base.cc +++ b/tensorflow/core/framework/device_base.cc @@ -22,12 +22,16 @@ limitations under the License. #include "absl/container/flat_hash_set.h" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" -#include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/util/work_sharder.h" namespace tensorflow { -DeviceBase::~DeviceBase() { gtl::STLDeleteElements(&eigen_cpu_devices_); } +DeviceBase::~DeviceBase() { + for (auto& temp : eigen_cpu_devices_) { + delete temp; + } + eigen_cpu_devices_.clear(); +} const DeviceAttributes& DeviceBase::attributes() const { LOG(FATAL) << "Device does not implement attributes()"; diff --git a/tensorflow/core/kernels/ops_testutil.h b/tensorflow/core/kernels/ops_testutil.h index b13c1127b70..81089d8328a 100644 --- a/tensorflow/core/kernels/ops_testutil.h +++ b/tensorflow/core/kernels/ops_testutil.h @@ -37,7 +37,6 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" -#include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/macros.h" @@ -90,8 +89,14 @@ class OpsTestBase : public ::testing::Test { } ~OpsTestBase() override { - gtl::STLDeleteElements(&tensors_); - gtl::STLDeleteElements(&managed_outputs_); + for (auto& temp : tensors_) { + delete temp; + } + for (auto& temp : managed_outputs_) { + delete temp; + } + tensors_.clear(); + managed_outputs_.clear(); context_.reset(nullptr); params_.reset(nullptr); } @@ -177,7 +182,10 @@ class OpsTestBase : public ::testing::Test { context_.reset(nullptr); // Delete the output copies from previous runs. - gtl::STLDeleteElements(&managed_outputs_); + for (auto& temp : managed_outputs_) { + delete temp; + } + managed_outputs_.clear(); managed_outputs_.resize(0); params_.reset(new OpKernelContext::Params); diff --git a/tensorflow/core/lib/gtl/stl_util.h b/tensorflow/core/lib/gtl/stl_util.h index 37a70248773..2d4e4e88298 100644 --- a/tensorflow/core/lib/gtl/stl_util.h +++ b/tensorflow/core/lib/gtl/stl_util.h @@ -32,23 +32,6 @@ limitations under the License. namespace tensorflow { namespace gtl { -// Deletes all the elements in an STL container and clears the container. This -// function is suitable for use with a vector, set, hash_set, or any other STL -// container which defines sensible begin(), end(), and clear() methods. -// -// If container is NULL, this function is a no-op. -template -void STLDeleteElements(T* container) { - if (!container) return; - auto it = container->begin(); - while (it != container->end()) { - auto temp = it; - ++it; - delete *temp; - } - container->clear(); -} - // Given an STL container consisting of (key, value) pairs, STLDeleteValues // deletes all the "value" components and clears the container. Does nothing in // the case it's given a NULL pointer. diff --git a/tensorflow/core/lib/gtl/top_n_test.cc b/tensorflow/core/lib/gtl/top_n_test.cc index ba30c072a90..069b10b60c1 100644 --- a/tensorflow/core/lib/gtl/top_n_test.cc +++ b/tensorflow/core/lib/gtl/top_n_test.cc @@ -20,7 +20,6 @@ limitations under the License. #include #include -#include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/lib/random/simple_philox.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/test.h" @@ -184,7 +183,10 @@ TEST(TopNTest, Ptr) { } std::vector extract = ConsumeRawPtr(topn.Extract()); - tensorflow::gtl::STLDeleteElements(&extract); + for (auto &temp : extract) { + delete temp; + } + extract.clear(); } struct PointeeGreater {