1 /* Copyright 2018 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_SERVICE_BUFFER_VALUE_CONTAINERS_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_BUFFER_VALUE_CONTAINERS_H_ 18 19 #include "absl/container/flat_hash_set.h" 20 #include "tensorflow/compiler/xla/service/buffer_value.h" 21 #include "tensorflow/compiler/xla/service/logical_buffer.h" 22 #include "tensorflow/core/lib/gtl/compactptrset.h" 23 24 namespace xla { 25 26 // Define various containers of BufferValues, and utilities to convert from 27 // containers of LogicalBuffers to containers of BufferValues. 28 29 using BufferValueCompactPointerSet = 30 tensorflow::gtl::CompactPointerSet<const BufferValue*>; 31 template <class LogicalBufferContainerT> ToBufferValueCompactPointerSet(const LogicalBufferContainerT & logical_buffer_container)32BufferValueCompactPointerSet ToBufferValueCompactPointerSet( 33 const LogicalBufferContainerT& logical_buffer_container) { 34 BufferValueCompactPointerSet output; 35 for (const LogicalBuffer* buffer : logical_buffer_container) { 36 output.insert(buffer); 37 } 38 return output; 39 } 40 41 using BufferValueFlatSet = absl::flat_hash_set<const BufferValue*>; 42 template <class LogicalBufferContainerT> ToBufferValueFlatSet(const LogicalBufferContainerT & logical_buffer_container)43BufferValueFlatSet ToBufferValueFlatSet( 44 const LogicalBufferContainerT& logical_buffer_container) { 45 BufferValueFlatSet output; 46 output.reserve(logical_buffer_container.size()); 47 for (const LogicalBuffer* buffer : logical_buffer_container) { 48 output.insert(buffer); 49 } 50 return output; 51 } 52 53 } // namespace xla 54 55 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_BUFFER_VALUE_CONTAINERS_H_ 56