• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/stream_executor/temporary_device_memory.h"
17 
18 #include "tensorflow/stream_executor/stream.h"
19 
20 namespace stream_executor {
21 
~TemporaryDeviceMemoryBase()22 TemporaryDeviceMemoryBase::~TemporaryDeviceMemoryBase() {
23   parent_->temporary_memory_manager()->MarkFinalized(device_memory_,
24                                                      allocation_generation_,
25                                                      /*must_exist=*/false);
26 }
27 
mutable_device_memory()28 DeviceMemoryBase* TemporaryDeviceMemoryBase::mutable_device_memory() {
29   DCHECK(!IsFinalized())
30       << "should not access device memory after finalization";
31   return &device_memory_;
32 }
33 
device_memory() const34 const DeviceMemoryBase& TemporaryDeviceMemoryBase::device_memory() const {
35   DCHECK(!IsFinalized())
36       << "should not access device memory after finalization";
37   return device_memory_;
38 }
39 
Finalize()40 void TemporaryDeviceMemoryBase::Finalize() {
41   DCHECK(!IsFinalized()) << "should not finalize more than once";
42   parent_->temporary_memory_manager()->MarkFinalized(device_memory_,
43                                                      allocation_generation_,
44                                                      /*must_exist=*/true);
45 }
46 
IsFinalized() const47 bool TemporaryDeviceMemoryBase::IsFinalized() const {
48   return parent_->temporary_memory_manager()->IsFinalized(
49       device_memory_, allocation_generation_);
50 }
51 
IsAllocated() const52 bool TemporaryDeviceMemoryBase::IsAllocated() const {
53   return parent_->temporary_memory_manager()->HasAllocated(
54       device_memory_, allocation_generation_);
55 }
56 
TemporaryDeviceMemoryBase(Stream * parent,DeviceMemoryBase device_memory,uint64 allocation_generation)57 TemporaryDeviceMemoryBase::TemporaryDeviceMemoryBase(
58     Stream* parent, DeviceMemoryBase device_memory,
59     uint64 allocation_generation)
60     : device_memory_(device_memory),
61       allocation_generation_(allocation_generation),
62       parent_(parent) {
63   DCHECK(IsAllocated());
64 }
65 
66 }  // namespace stream_executor
67