1 /* Copyright 2019 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 #ifndef TENSORFLOW_COMPILER_XLA_STREAM_EXECUTOR_ALLOCATOR_STATS_H_ 17 #define TENSORFLOW_COMPILER_XLA_STREAM_EXECUTOR_ALLOCATOR_STATS_H_ 18 19 #include <string> 20 21 #include "absl/types/optional.h" 22 #include "tensorflow/compiler/xla/stream_executor/platform/port.h" 23 24 namespace stream_executor { 25 26 // Runtime statistics collected by an allocator. Exactly the same as 27 // tensorflow::AllocatorStats, but independently defined to preserve the mutual 28 // independence of StreamExecutor and TensorFlow. 29 struct AllocatorStats { 30 int64_t num_allocs; // Number of allocations. 31 int64_t bytes_in_use; // Number of bytes in use. 32 int64_t peak_bytes_in_use; // The peak bytes in use. 33 int64_t largest_alloc_size; // The largest single allocation seen. 34 35 // The upper limit of bytes of user allocatable device memory, if such a limit 36 // is known. 37 std::optional<int64_t> bytes_limit; 38 39 // Stack related memory usage. 40 int64_t bytes_reserved; // Number of bytes reserved on the stack. 41 int64_t 42 peak_bytes_reserved; // The peak number of bytes reserved on the stack. 43 // The upper limit on the number bytes of reservable memory on the stack, 44 // if such a limit is known. 45 std::optional<int64_t> bytes_reservable_limit; 46 47 int64_t largest_free_block_bytes; // Largest free block's size in heap. 48 AllocatorStatsAllocatorStats49 AllocatorStats() 50 : num_allocs(0), 51 bytes_in_use(0), 52 peak_bytes_in_use(0), 53 largest_alloc_size(0), 54 bytes_reserved(0), 55 peak_bytes_reserved(0), 56 largest_free_block_bytes(0) {} 57 58 std::string DebugString() const; 59 }; 60 61 } // namespace stream_executor 62 63 #endif // TENSORFLOW_COMPILER_XLA_STREAM_EXECUTOR_ALLOCATOR_STATS_H_ 64