1 /* Copyright 2017 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/llvm_compiler.h" 17 #include "tensorflow/core/platform/denormal.h" 18 19 #ifdef __FAST_MATH__ 20 #error "Don't build XLA with -ffast-math" 21 #endif 22 23 namespace xla { 24 StatusOr<std::vector<std::unique_ptr<Executable>>> LLVMCompiler::Compile( 25 std::vector<std::unique_ptr<HloModule>> modules, 26 std::vector<std::vector<perftools::gputools::StreamExecutor*>> stream_execs, 27 DeviceMemoryAllocator* device_allocator) { 28 // Tensorflow tries to enable the following behaviors in all its threads: 29 // 30 // - Denormals are zero (DAZ): roughly, operations treat denormal floats as 31 // zero. 32 // - Flush denormals to zero (FTZ): roughly, operations produce zero instead 33 // of denormal floats. 34 // 35 // In theory enabling these shouldn't matter since the compiler should ideally 36 // not leak its environment into generated code, but we turn off DAZ and FTZ 37 // to get some defense-in-depth. 38 tensorflow::port::ScopedDontFlushDenormal dont_flush_denormals; 39 40 std::vector<std::unique_ptr<Executable>> result; 41 for (size_t i = 0; i < modules.size(); i++) { 42 if (stream_execs[i].size() != 1) { 43 return Unimplemented( 44 "Model partitioning not implemented for the CPU/GPU compilers!"); 45 } 46 47 TF_ASSIGN_OR_RETURN(modules[i], 48 RunHloPasses(std::move(modules[i]), stream_execs[i][0], 49 device_allocator)); 50 TF_ASSIGN_OR_RETURN(std::unique_ptr<Executable> executable, 51 RunBackend(std::move(modules[i]), stream_execs[i][0], 52 device_allocator)); 53 result.push_back(std::move(executable)); 54 } 55 56 return {std::move(result)}; 57 } 58 } // namespace xla 59