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 #include "tensorflow/compiler/xla/service/cpu/buffer_info_util.h" 17 18 namespace xla { 19 namespace cpu { 20 21 using BufferInfo = ::tensorflow::cpu_function_runtime::BufferInfo; 22 CreateBufferInfosFromBufferAssignment(const BufferAssignment & buffer_assignment)23std::vector<BufferInfo> CreateBufferInfosFromBufferAssignment( 24 const BufferAssignment& buffer_assignment) { 25 std::vector<BufferInfo> buffer_infos; 26 for (const BufferAllocation& allocation : buffer_assignment.Allocations()) { 27 if (allocation.is_thread_local()) { 28 buffer_infos.push_back(BufferInfo::MakeOnStackBuffer(allocation.size())); 29 } else if (allocation.is_constant()) { 30 buffer_infos.push_back(BufferInfo::MakeConstant(allocation.size())); 31 } else if (allocation.is_entry_computation_parameter()) { 32 buffer_infos.push_back(BufferInfo::MakeEntryParameter( 33 /*size=*/allocation.size(), 34 /*param_number=*/allocation.parameter_number())); 35 } else { 36 buffer_infos.push_back(BufferInfo::MakeTempBuffer(allocation.size())); 37 } 38 } 39 return buffer_infos; 40 } 41 CreateArgIndexTableFromBufferInfos(absl::Span<const BufferInfo> buffer_infos)42std::vector<int32> CreateArgIndexTableFromBufferInfos( 43 absl::Span<const BufferInfo> buffer_infos) { 44 std::vector<int32> result; 45 for (int64 i = 0; i < buffer_infos.size(); i++) { 46 if (buffer_infos[i].is_entry_parameter()) { 47 if (buffer_infos[i].entry_parameter_number() >= result.size()) { 48 result.resize(buffer_infos[i].entry_parameter_number() + 1); 49 } 50 result[buffer_infos[i].entry_parameter_number()] = i; 51 } 52 } 53 return result; 54 } 55 56 } // namespace cpu 57 } // namespace xla 58