[NFC] s/AbstractStackTrace/ManagedStackTrace

There is nohing abstract about abstract stack trace: it assumes a particular
storage, and it is passed by value everywhere, making extending this class
virtually (pardon the pun) impossible.

PiperOrigin-RevId: 344118317
Change-Id: Ic35f899d56f360eca45ac0b3f0752770926f6c22
This commit is contained in:
George Karpenkov 2020-11-24 13:11:27 -08:00 committed by TensorFlower Gardener
parent faa6548fba
commit 3d3c4aaaed
7 changed files with 18 additions and 18 deletions

View File

@ -27,7 +27,7 @@ limitations under the License.
#include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/platform/casts.h" #include "tensorflow/core/platform/casts.h"
#include "tensorflow/core/platform/status.h" #include "tensorflow/core/platform/status.h"
#include "tensorflow/core/util/abstract_stack_trace.h" #include "tensorflow/core/util/managed_stack_trace.h"
struct TFE_Op; struct TFE_Op;
@ -48,10 +48,10 @@ class ImmediateExecutionOperation : public AbstractOperation {
virtual Status OutputLength(const char* output_name, int* length) = 0; virtual Status OutputLength(const char* output_name, int* length) = 0;
// Set stack trace to be used for potential async error reporting. // Set stack trace to be used for potential async error reporting.
virtual void SetStackTrace(AbstractStackTrace stack_trace) = 0; virtual void SetStackTrace(ManagedStackTrace stack_trace) = 0;
// Returns the stack trace set by `SetStackTrace` if exists. // Returns the stack trace set by `SetStackTrace` if exists.
virtual absl::optional<AbstractStackTrace> GetStackTrace() = 0; virtual absl::optional<ManagedStackTrace> GetStackTrace() = 0;
// For LLVM style RTTI. // For LLVM style RTTI.
static bool classof(const AbstractOperation* ptr) { static bool classof(const AbstractOperation* ptr) {

View File

@ -29,8 +29,8 @@ limitations under the License.
#include "tensorflow/core/framework/cancellation.h" #include "tensorflow/core/framework/cancellation.h"
#include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/framework/device_attributes.pb.h"
#include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/util/abstract_stack_trace.h"
#include "tensorflow/core/util/device_name_utils.h" #include "tensorflow/core/util/device_name_utils.h"
#include "tensorflow/core/util/managed_stack_trace.h"
namespace tensorflow { namespace tensorflow {
@ -120,11 +120,11 @@ class EagerOperation : public ImmediateExecutionOperation {
Status InputLength(const char* input_name, int* length) override; Status InputLength(const char* input_name, int* length) override;
Status OutputLength(const char* output_name, int* length) override; Status OutputLength(const char* output_name, int* length) override;
void SetStackTrace(AbstractStackTrace stack_trace) override { void SetStackTrace(ManagedStackTrace stack_trace) override {
stack_trace_ = stack_trace; stack_trace_ = stack_trace;
} }
absl::optional<AbstractStackTrace> GetStackTrace() override { absl::optional<ManagedStackTrace> GetStackTrace() override {
return stack_trace_; return stack_trace_;
} }
@ -225,7 +225,7 @@ class EagerOperation : public ImmediateExecutionOperation {
// updated accordingly. // updated accordingly.
VariantDevice device_; VariantDevice device_;
absl::optional<AbstractStackTrace> stack_trace_; absl::optional<ManagedStackTrace> stack_trace_;
bool is_function_; // Conceptually const, but can't be because of Reset bool is_function_; // Conceptually const, but can't be because of Reset
bool colocation_exempt_; bool colocation_exempt_;
CancellationManager* cancellation_manager_ = nullptr; // Not owned. CancellationManager* cancellation_manager_ = nullptr; // Not owned.

View File

@ -151,7 +151,7 @@ class AsyncExecuteNode : public EagerNode {
GraphCollector* graph_collector, GraphCollector* graph_collector,
CancellationManager* cancellation_manager, CancellationManager* cancellation_manager,
absl::Span<TensorHandle*> retvals, absl::Span<TensorHandle*> retvals,
absl::optional<AbstractStackTrace> stack_trace) absl::optional<ManagedStackTrace> stack_trace)
: EagerNode(), : EagerNode(),
ctx_(ctx), ctx_(ctx),
inputs_(inputs), inputs_(inputs),
@ -233,7 +233,7 @@ class AsyncExecuteNode : public EagerNode {
core::RefCountPtr<KernelAndDevice> kernel_; core::RefCountPtr<KernelAndDevice> kernel_;
GraphCollector* graph_collector_; GraphCollector* graph_collector_;
CancellationManager* const cancellation_manager_; CancellationManager* const cancellation_manager_;
absl::optional<AbstractStackTrace> stack_trace_; absl::optional<ManagedStackTrace> stack_trace_;
absl::InlinedVector<TensorHandle*, 2> retvals_; absl::InlinedVector<TensorHandle*, 2> retvals_;
}; };

View File

@ -74,7 +74,6 @@ filegroup(
filegroup( filegroup(
name = "mobile_srcs_only_runtime", name = "mobile_srcs_only_runtime",
srcs = [ srcs = [
"abstract_stack_trace.h",
"batch_util.cc", "batch_util.cc",
"batch_util.h", "batch_util.h",
"bcast.cc", "bcast.cc",
@ -97,6 +96,7 @@ filegroup(
"example_proto_helper.h", "example_proto_helper.h",
"guarded_philox_random.cc", "guarded_philox_random.cc",
"guarded_philox_random.h", "guarded_philox_random.h",
"managed_stack_trace.h",
"matmul_autotune.cc", "matmul_autotune.cc",
"matmul_autotune.h", "matmul_autotune.h",
"matmul_bcast.h", "matmul_bcast.h",
@ -327,7 +327,6 @@ filegroup(
filegroup( filegroup(
name = "framework_srcs", name = "framework_srcs",
srcs = [ srcs = [
"abstract_stack_trace.h",
"activation_mode.h", "activation_mode.h",
"batch_util.h", "batch_util.h",
"bcast.h", "bcast.h",
@ -340,6 +339,7 @@ filegroup(
"example_proto_helper.h", "example_proto_helper.h",
"gpu_kernel_helper.h", "gpu_kernel_helper.h",
"guarded_philox_random.h", "guarded_philox_random.h",
"managed_stack_trace.h",
"matmul_autotune.h", "matmul_autotune.h",
"matmul_bcast.h", "matmul_bcast.h",
"mirror_pad_mode.h", "mirror_pad_mode.h",
@ -470,7 +470,7 @@ cc_library(
cc_library( cc_library(
name = "abstract_stack_trace", name = "abstract_stack_trace",
hdrs = ["abstract_stack_trace.h"], hdrs = ["managed_stack_trace.h"],
visibility = [ visibility = [
"//tensorflow/c/eager:__pkg__", "//tensorflow/c/eager:__pkg__",
"//tensorflow/core:__pkg__", "//tensorflow/core:__pkg__",

View File

@ -24,9 +24,9 @@ namespace tensorflow {
// Language agnostic stack trace class. It only saves an id, and language // Language agnostic stack trace class. It only saves an id, and language
// clients are responsible for managing the actual stack trace objects. // clients are responsible for managing the actual stack trace objects.
class AbstractStackTrace { class ManagedStackTrace {
public: public:
AbstractStackTrace(int id, std::vector<StackFrame> (*to_stack_frames)(int)) ManagedStackTrace(int id, std::vector<StackFrame> (*to_stack_frames)(int))
: id_(id), to_stack_frames_(to_stack_frames) {} : id_(id), to_stack_frames_(to_stack_frames) {}
// Returns stack trace as a vector of `StackFrame`s. // Returns stack trace as a vector of `StackFrame`s.

View File

@ -42,7 +42,7 @@ limitations under the License.
#include "tensorflow/core/platform/status.h" #include "tensorflow/core/platform/status.h"
#include "tensorflow/core/platform/types.h" #include "tensorflow/core/platform/types.h"
#include "tensorflow/core/profiler/lib/traceme.h" #include "tensorflow/core/profiler/lib/traceme.h"
#include "tensorflow/core/util/abstract_stack_trace.h" #include "tensorflow/core/util/managed_stack_trace.h"
#include "tensorflow/python/eager/pywrap_gradient_exclusions.h" #include "tensorflow/python/eager/pywrap_gradient_exclusions.h"
#include "tensorflow/python/eager/pywrap_tensor.h" #include "tensorflow/python/eager/pywrap_tensor.h"
#include "tensorflow/python/eager/pywrap_tfe.h" #include "tensorflow/python/eager/pywrap_tfe.h"

View File

@ -28,7 +28,7 @@ limitations under the License.
#include "absl/base/optimization.h" #include "absl/base/optimization.h"
#include "absl/container/inlined_vector.h" #include "absl/container/inlined_vector.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "tensorflow/core/util/abstract_stack_trace.h" #include "tensorflow/core/util/managed_stack_trace.h"
namespace tensorflow { namespace tensorflow {
@ -158,9 +158,9 @@ extern StackTraceManager* const stack_trace_manager;
// Note that the actual stack trace is kept in a circular buffer for string // Note that the actual stack trace is kept in a circular buffer for string
// conversion could fail if it's evicted before. // conversion could fail if it's evicted before.
// Python GIL must be acquired beforehand. // Python GIL must be acquired beforehand.
inline AbstractStackTrace GetStackTrace(int limit) { inline ManagedStackTrace GetStackTrace(int limit) {
DCheckPyGilStateForStackTrace(); DCheckPyGilStateForStackTrace();
return AbstractStackTrace(stack_trace_manager->Capture(limit), [](int id) { return ManagedStackTrace(stack_trace_manager->Capture(limit), [](int id) {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
std::vector<StackFrame> result = std::vector<StackFrame> result =
stack_trace_manager->Get(id)->ToStackFrames(); stack_trace_manager->Get(id)->ToStackFrames();