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_CPU_TARGET_MACHINE_FEATURES_FAKE_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_TARGET_MACHINE_FEATURES_FAKE_H_ 18 19 #include "tensorflow/compiler/xla/service/cpu/target_machine_features.h" 20 21 namespace xla { 22 namespace cpu { 23 // Delegates calls to minimum_alignment_for_allocation to a user provided 24 // std::function, crashes on all other methods. 25 // 26 // Primarily useful for testing. 27 class TargetMachineFeaturesWithFakeAlignmentLogic 28 : public TargetMachineFeatures { 29 public: 30 explicit TargetMachineFeaturesWithFakeAlignmentLogic( 31 std::function<int64(int64)> fake_alignment_logic) 32 : fake_alignment_logic_(std::move(fake_alignment_logic)) {} 33 34 int vectorization_factor_in_bytes() const override { 35 LOG(FATAL) << "Unexpected call to " << __func__; 36 } 37 38 int vector_register_byte_size(const llvm::Function& function) const override { 39 LOG(FATAL) << "Unexpected call to " << __func__; 40 } 41 42 int vector_register_num_elements(const llvm::Function& function, 43 PrimitiveType type) const override { 44 LOG(FATAL) << "Unexpected call to " << __func__; 45 } 46 47 int64 minimum_alignment_for_allocation(int64 size_bytes) const override { 48 return fake_alignment_logic_(size_bytes); 49 } 50 51 private: 52 std::function<int64(int64)> fake_alignment_logic_; 53 }; 54 } // namespace cpu 55 } // namespace xla 56 57 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_TARGET_MACHINE_FEATURES_FAKE_H_ 58