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