[xla:cpu] Add target machine features to the error message

PiperOrigin-RevId: 826253599
This commit is contained in:
Eugene Zhulenev 2025-10-30 17:42:32 -07:00 committed by TensorFlower Gardener
parent d9024af6d4
commit 429a0cf1c7
2 changed files with 19 additions and 6 deletions

View File

@ -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",

View File

@ -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<bool> 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<std::string> 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, ","));
}
}