aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/service/shaped_buffer.h
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-02-15 11:34:10 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-02-15 11:38:56 -0800
commit5dd585abb84c5d13af0017f78741e29505f7b5f7 (patch)
treec7034ec631b988bd50eff10ab60e9cba1f00f7aa /tensorflow/compiler/xla/service/shaped_buffer.h
parent9d1d0253a2d634c0fd1f1db53b6e4922b8e92f28 (diff)
Make conversions from ShapedBuffer <-> ScopedShapedBuffer efficient by
moving memory ownership instead of copying. PiperOrigin-RevId: 185871648
Diffstat (limited to 'tensorflow/compiler/xla/service/shaped_buffer.h')
-rw-r--r--tensorflow/compiler/xla/service/shaped_buffer.h26
1 files changed, 19 insertions, 7 deletions
diff --git a/tensorflow/compiler/xla/service/shaped_buffer.h b/tensorflow/compiler/xla/service/shaped_buffer.h
index d397e47d2c..b816df8385 100644
--- a/tensorflow/compiler/xla/service/shaped_buffer.h
+++ b/tensorflow/compiler/xla/service/shaped_buffer.h
@@ -87,18 +87,24 @@ class ShapedBuffer {
string ToString() const;
+ ShapedBuffer(ShapedBuffer&& s);
+ ShapedBuffer& operator=(ShapedBuffer&&);
+
protected:
+ ShapedBuffer(const ShapedBuffer&) = delete;
+ ShapedBuffer& operator=(const ShapedBuffer&) = delete;
+
// The shape of the data when represented on the host.
- const Shape on_host_shape_;
+ Shape on_host_shape_;
// The shape of the data on the device.
- const Shape on_device_shape_;
+ Shape on_device_shape_;
// The platform the memory is allocated on.
const perftools::gputools::Platform* platform_;
// The device the memory is allocated on.
- const int device_ordinal_;
+ int device_ordinal_;
// The tree of device buffers. Its shape is on_device_shape().
ShapeTree<perftools::gputools::DeviceMemoryBase> buffers_;
@@ -121,14 +127,20 @@ class ScopedShapedBuffer : public ShapedBuffer {
ScopedShapedBuffer(const Shape& on_host_shape, const Shape& on_device_shape,
DeviceMemoryAllocator* allocator, int device_ordinal);
+ // Create a ScopedShapedBuffer by taking over the memory from the incoming
+ // ShapedBuffer.
+ ScopedShapedBuffer(ShapedBuffer shaped_buffer,
+ DeviceMemoryAllocator* allocator);
+
// Return the allocator used to allocate the device memory held in this
// ScopedShapedBuffer.
DeviceMemoryAllocator* memory_allocator() const { return allocator_; }
- // Release all device memory owned by this ScopedShapedBuffer and return the
- // device memory pointers in the form of a ShapedBuffer. Device memory
- // pointers in this ScopedShapedBuffer object are set to null. This method is
- // analogous to std::unique_ptr::release().
+ // Release all device memory owned by this ScopedShapedBuffer and
+ // return the device memory pointers in the form of a
+ // ShapedBuffer. The returned ShapedBuffer takes over the memory
+ // from the ScopedShapedBuffer. The resulting ScopedShapedBuffer can
+ // only be destroyed.
std::unique_ptr<ShapedBuffer> release();
// All buffers in the shape are deallocated on destruction.