xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/client/compile_only_client.cc (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 <memory>
19 
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/ADT/Twine.h"
22 #include "tensorflow/compiler/xla/status_macros.h"
23 
24 namespace xla {
25 
26 StatusOr<std::unique_ptr<HloModuleConfig>>
CreateModuleConfig(const ProgramShape & program_shape,absl::Span<const Shape * const> argument_shapes,const ExecutionOptions * execution_options)27 CompileOnlyClient::CreateModuleConfig(
28     const ProgramShape& program_shape,
29     absl::Span<const Shape* const> argument_shapes,
30     const ExecutionOptions* execution_options) {
31   return compiler_service_->CreateModuleConfig(program_shape, argument_shapes,
32                                                execution_options);
33 }
34 
35 StatusOr<std::vector<std::unique_ptr<AotCompilationResult>>>
CompileAheadOfTime(const absl::Span<const AotXlaComputationInstance> computations,const AotCompilationOptions & options,std::unique_ptr<AotCompilationMetadata> * metadata)36 CompileOnlyClient::CompileAheadOfTime(
37     const absl::Span<const AotXlaComputationInstance> computations,
38     const AotCompilationOptions& options,
39     std::unique_ptr<AotCompilationMetadata>* metadata) {
40   std::vector<CompileOnlyService::AotXlaComputationInstance> service_instances;
41   service_instances.reserve(computations.size());
42   for (const AotXlaComputationInstance& instance : computations) {
43     service_instances.emplace_back();
44     CompileOnlyService::AotXlaComputationInstance& service_instance =
45         service_instances.back();
46     TF_RET_CHECK(instance.computation != nullptr);
47     service_instance.computation = instance.computation->proto();
48     service_instance.argument_layouts = instance.argument_layouts;
49     service_instance.result_layout = *instance.result_layout;
50   }
51   return compiler_service_->CompileAheadOfTime(service_instances, options,
52                                                metadata);
53 }
54 
PointerSizeForTriple(absl::string_view triple)55 int64_t CompileOnlyClient::PointerSizeForTriple(absl::string_view triple) {
56   llvm::Triple llvm_triple(
57       llvm::Triple::normalize(llvm::StringRef(triple.data(), triple.size())));
58   if (llvm_triple.isArch64Bit()) {
59     return 8;
60   } else if (llvm_triple.isArch32Bit()) {
61     return 4;
62   } else {
63     CHECK(llvm_triple.isArch16Bit());
64     return 2;
65   }
66 }
67 
68 }  // namespace xla
69