• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/client/compile_only_client.h"
17 
18 #include "absl/memory/memory.h"
19 #include "llvm/ADT/Triple.h"
20 #include "tensorflow/compiler/xla/status_macros.h"
21 
22 namespace xla {
23 
24 StatusOr<std::vector<std::unique_ptr<AotCompilationResult>>>
CompileAheadOfTime(const absl::Span<const AotXlaComputationInstance> computations,const AotCompilationOptions & options,std::unique_ptr<AotCompilationMetadata> * metadata)25 CompileOnlyClient::CompileAheadOfTime(
26     const absl::Span<const AotXlaComputationInstance> computations,
27     const AotCompilationOptions& options,
28     std::unique_ptr<AotCompilationMetadata>* metadata) {
29   std::vector<CompileOnlyService::AotXlaComputationInstance> service_instances;
30   service_instances.reserve(computations.size());
31   for (const AotXlaComputationInstance& instance : computations) {
32     service_instances.emplace_back();
33     CompileOnlyService::AotXlaComputationInstance& service_instance =
34         service_instances.back();
35     TF_RET_CHECK(instance.computation != nullptr);
36     service_instance.computation = instance.computation->proto();
37     service_instance.argument_layouts = instance.argument_layouts;
38     service_instance.result_layout = instance.result_layout;
39   }
40   return compiler_service_->CompileAheadOfTime(service_instances, options,
41                                                metadata);
42 }
43 
PointerSizeForTriple(absl::string_view triple)44 int64 CompileOnlyClient::PointerSizeForTriple(absl::string_view triple) {
45   llvm::Triple llvm_triple(
46       llvm::Triple::normalize(llvm::StringRef(triple.data(), triple.size())));
47   if (llvm_triple.isArch64Bit()) {
48     return 8;
49   } else if (llvm_triple.isArch32Bit()) {
50     return 4;
51   } else {
52     CHECK(llvm_triple.isArch16Bit());
53     return 2;
54   }
55 }
56 
57 }  // namespace xla
58