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/target_machine_features.h" 17 18 #include <algorithm> 19 20 #include "tensorflow/compiler/xla/cpu_function_runtime.h" 21 #include "tensorflow/core/platform/logging.h" 22 23 namespace xla { 24 namespace cpu { 25 GetTargetTransformInfoFor(const llvm::Function & function) const26llvm::TargetTransformInfo* LLVMTargetMachineFeatures::GetTargetTransformInfoFor( 27 const llvm::Function& function) const { 28 auto it = target_transform_info_cache_.find(&function); 29 if (it == target_transform_info_cache_.end()) { 30 auto emplace_result = target_transform_info_cache_.emplace( 31 &function, target_machine_->getTargetTransformInfo(function)); 32 CHECK(emplace_result.second); 33 it = emplace_result.first; 34 } 35 36 return &it->second; 37 } 38 minimum_alignment_for_allocation(int64_t size_bytes) const39int64_t LLVMTargetMachineFeatures::minimum_alignment_for_allocation( 40 int64_t size_bytes) const { 41 // Assume that all pointers are aligned to at least 42 // xla::cpu_function_runtime::kMinAlign. 43 if (size_bytes == 0) { 44 // No need to align empty buffers. 45 return 1; 46 } 47 48 // Allow small buffers to be underaligned, there is no vectorization benefit 49 // anyways. 50 return std::min<int64_t>(llvm::PowerOf2Ceil(size_bytes), 51 cpu_function_runtime::MinAlign()); 52 } 53 54 } // namespace cpu 55 } // namespace xla 56