s/no_retry_on_failure/retry_on_failure; NFC

no_XYZ properties tend to be harder to reason about since we they force us to
deal with double-negatives.

PiperOrigin-RevId: 325278071
Change-Id: I4a30b9dd501de237b487ab6afda787f213d40b1c
This commit is contained in:
Sanjoy Das 2020-08-06 11:54:56 -07:00 committed by TensorFlower Gardener
parent a8a50023bb
commit d9b5042f03
7 changed files with 19 additions and 16 deletions
tensorflow
compiler/tf2tensorrt/utils
core
stream_executor

View File

@ -74,7 +74,7 @@ void* TRTDeviceAllocator::allocate(uint64_t size, uint64_t alignment,
// algorithm uses too much memory. If we don't fail immediately building the
// engine can be *very* slow with TensorRT7 when GPU memory is limited.
AllocationAttributes attributes;
attributes.no_retry_on_failure = true;
attributes.retry_on_failure = false;
void* mem = allocator_->AllocateRaw(alignment, total_size, attributes);
if (!mem) return nullptr;

View File

@ -230,7 +230,7 @@ void* BFCAllocator::AllocateRawInternalWithRetry(
void* BFCAllocator::AllocateRaw(size_t unused_alignment, size_t num_bytes,
const AllocationAttributes& allocation_attr) {
VLOG(1) << "AllocateRaw " << Name() << " " << num_bytes;
if (allocation_attr.no_retry_on_failure) {
if (!allocation_attr.retry_on_failure) {
// Return immediately upon the first failure if this is for allocating an
// optional scratch space.
bool dump_log_on_failure = VLOG_IS_ON(2);

View File

@ -39,17 +39,19 @@ class TensorShape;
struct AllocationAttributes {
AllocationAttributes() = default;
AllocationAttributes(bool no_retry_on_failure, bool allocation_will_be_logged,
AllocationAttributes(bool retry_on_failure, bool allocation_will_be_logged,
std::function<uint64()>* freed_by_func)
: no_retry_on_failure(no_retry_on_failure),
: retry_on_failure(retry_on_failure),
allocation_will_be_logged(allocation_will_be_logged),
freed_by_func(freed_by_func) {}
// If the first attempt to allocate the memory fails, the allocation
// should return immediately without retrying.
// An example use case is optional scratch spaces where a failure
// has only performance impact.
bool no_retry_on_failure = false;
// If the first attempt to allocate the memory fails, the allocation should
// wait and retry (with a timeout).
//
// This is usually set to true, but we may set it to false in cases where a
// failure has only performance impact (e.g. optional scratch space
// allocation).
bool retry_on_failure = true;
// If a Tensor is allocated without the following set to true, then
// it is logged as an unknown allocation. During execution Tensors
// should be allocated through the OpKernelContext which records

View File

@ -709,10 +709,11 @@ Status OpKernelContext::allocate_tensor(
DataType type, const TensorShape& shape, Tensor* out_tensor,
AllocatorAttributes attr, const AllocationAttributes& allocation_attr) {
Allocator* a = get_allocator(attr);
Tensor new_tensor(a, type, shape,
AllocationAttributes(allocation_attr.no_retry_on_failure,
/* allocation_will_be_logged= */ true,
allocation_attr.freed_by_func));
Tensor new_tensor(
a, type, shape,
AllocationAttributes(
/*retry_on_failure=*/allocation_attr.retry_on_failure,
/*allocation_will_be_logged=*/true, allocation_attr.freed_by_func));
if (!new_tensor.IsInitialized()) {
return errors::ResourceExhausted(

View File

@ -68,7 +68,7 @@ class DnnScratchAllocator : public se::ScratchAllocator {
memory_limit_, ").")};
}
AllocationAttributes allocation_attr;
allocation_attr.no_retry_on_failure = true;
allocation_attr.retry_on_failure = false;
Status allocation_status(context_->allocate_temp(
DT_UINT8, TensorShape({byte_size}), &temporary_memory,
AllocatorAttributes(), allocation_attr));

View File

@ -372,7 +372,7 @@ class CufftScratchAllocator : public se::ScratchAllocator {
return se::port::StatusOr<se::DeviceMemory<uint8>>();
}
AllocationAttributes allocation_attr;
allocation_attr.no_retry_on_failure = true;
allocation_attr.retry_on_failure = false;
Status allocation_status(context_->allocate_temp(
DT_UINT8, TensorShape({byte_size}), &temporary_memory,
AllocatorAttributes(), allocation_attr));

View File

@ -40,7 +40,7 @@ port::StatusOr<OwningDeviceMemory> TfAllocatorAdapter::Allocate(
int64 memory_space) {
CHECK_EQ(memory_space, 0);
tensorflow::AllocationAttributes attrs;
attrs.no_retry_on_failure = !retry_on_failure;
attrs.retry_on_failure = retry_on_failure;
void *data = nullptr;
if (size != 0) {
data = wrapped_->AllocateRaw(tensorflow::Allocator::kAllocatorAlignment,