diff options
author | 2018-04-19 19:27:34 -0700 | |
---|---|---|
committer | 2018-04-19 19:30:26 -0700 | |
commit | 8723770b4cbcac0a528354d8508a5ef83716d1fa (patch) | |
tree | 117e18a458acc5c0a2eb7630cfcc4f3cb6f9d045 /tensorflow/compiler/xla/service/device_memory_allocator.h | |
parent | b001827146ff95c9e0ce5668c85d8cc2daf6b78d (diff) |
[XLA] Remove default argument on virtual function DeviceMemoryAllocator::Allocate().
Default args on virtual functions are disallowed by the Google style
guide, for good reason. They have the extremely surprising behavior
that the defaults you get when calling a function on a pointer depend
not on the underlying type of the object, but on whatever is the
semantic type of the pointer!
PiperOrigin-RevId: 193611213
Diffstat (limited to 'tensorflow/compiler/xla/service/device_memory_allocator.h')
-rw-r--r-- | tensorflow/compiler/xla/service/device_memory_allocator.h | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/tensorflow/compiler/xla/service/device_memory_allocator.h b/tensorflow/compiler/xla/service/device_memory_allocator.h index 240acf8973..da45c4d45a 100644 --- a/tensorflow/compiler/xla/service/device_memory_allocator.h +++ b/tensorflow/compiler/xla/service/device_memory_allocator.h @@ -38,13 +38,25 @@ class DeviceMemoryAllocator { virtual ~DeviceMemoryAllocator() {} // 'retry_on_failure': If false, and 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. + // fails, the allocation should return immediately without retrying. An + // example use case is optional scratch spaces where a failure has only + // performance impact. + // // Allocate() should return a null pointer for a size-0 allocation. // Deallocate() must be a no-op for null pointers. - virtual StatusOr<se::DeviceMemoryBase> Allocate( - int device_ordinal, uint64 size, bool retry_on_failure = true) = 0; + virtual StatusOr<se::DeviceMemoryBase> Allocate(int device_ordinal, + uint64 size, + bool retry_on_failure) = 0; + + // Two-arg version of Allocate(), which sets retry-on-failure to true. + // + // (We don't simply use a default argument on the virtual Allocate function + // because default args on virtual functions are disallowed by the Google + // style guide.) + StatusOr<se::DeviceMemoryBase> Allocate(int device_ordinal, uint64 size) { + return Allocate(device_ordinal, size, /*retry_on_failure=*/true); + } + virtual tensorflow::Status Deallocate(int device_ordinal, se::DeviceMemoryBase* mem) = 0; @@ -67,8 +79,12 @@ class StreamExecutorMemoryAllocator : public DeviceMemoryAllocator { const se::Platform* platform, tensorflow::gtl::ArraySlice<se::StreamExecutor*> stream_executors); - StatusOr<se::DeviceMemoryBase> Allocate( - int device_ordinal, uint64 size, bool retry_on_failure = true) override; + StatusOr<se::DeviceMemoryBase> Allocate(int device_ordinal, uint64 size, + bool retry_on_failure) override; + + // Pull in two-arg overload that sets retry_on_failure to true. + using DeviceMemoryAllocator::Allocate; + tensorflow::Status Deallocate(int device_ordinal, se::DeviceMemoryBase* mem) override; |