From 429a0cf1c7a7560ddc37d6a5318548971ca1d6b2 Mon Sep 17 00:00:00 2001 From: Eugene Zhulenev Date: Thu, 30 Oct 2025 17:42:32 -0700 Subject: [PATCH] [xla:cpu] Add target machine features to the error message PiperOrigin-RevId: 826253599 --- third_party/xla/xla/service/cpu/BUILD | 1 + .../xla/xla/service/cpu/cpu_aot_loader.cc | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/third_party/xla/xla/service/cpu/BUILD b/third_party/xla/xla/service/cpu/BUILD index af339d467b3..daed5024ae6 100644 --- a/third_party/xla/xla/service/cpu/BUILD +++ b/third_party/xla/xla/service/cpu/BUILD @@ -2177,6 +2177,7 @@ cc_library( "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", "@llvm-project//llvm:Support", "@llvm-project//llvm:Target", diff --git a/third_party/xla/xla/service/cpu/cpu_aot_loader.cc b/third_party/xla/xla/service/cpu/cpu_aot_loader.cc index a4595bec665..e968b76f069 100644 --- a/third_party/xla/xla/service/cpu/cpu_aot_loader.cc +++ b/third_party/xla/xla/service/cpu/cpu_aot_loader.cc @@ -23,7 +23,9 @@ limitations under the License. #include "absl/log/log.h" #include "absl/status/statusor.h" +#include "absl/strings/str_join.h" #include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/DataLayout.h" @@ -185,18 +187,28 @@ CpuAotLoader::LoadAotCompilationResult( expected_triple.getArchName(), triple.getArchName()); } + llvm::StringMap host_machine_features = llvm::sys::getHostCPUFeatures(); auto compile_machine_features = absl::StrSplit(aot_result_proto.target_machine_options().features(), ','); - auto host_machine_features = llvm::sys::getHostCPUFeatures(); - - for (const auto& feature : compile_machine_features) { + for (const absl::string_view feature : compile_machine_features) { if (!host_machine_features.contains(feature) || !host_machine_features[feature]) { + // Convert the supported features to a vector of strings. + std::vector host_machine_features_vector; + for (const auto& [feature, supported] : host_machine_features) { + if (supported) { + host_machine_features_vector.push_back(feature.str()); + } + } + return Internal( - "Cannot load AOT result. Target machine feature %s is not supported " - "on the host machine.", - feature); + "Cannot load XLA:CPU AOT result. Target machine feature %s is not " + "supported on the host machine. Machine type used for XLA:CPU " + "compilation doesn't match the machine type for execution. Compile " + "machine features: [%s] vs host machine features: [%s]", + feature, absl::StrJoin(compile_machine_features, ","), + absl::StrJoin(host_machine_features_vector, ",")); } }