Skip to content

Commit 1abd188

Browse files
infiWangtensorflower-gardener
authored andcommitted
PR #32812: [XLA:CPU] Add support for riscv64
Imported from GitHub PR openxla/xla#32812 Co-author: @kxxt 📝 Summary of Changes: This pull request adds support for RISC-V 64 architecture across the build system, code generation, and Python packaging infrastructure. 🎯 Justification: The changes ensure that riscv64 is recognized as a valid target in Bazel build configurations, LLVM toolchain selection, Python manylinux compliance checks, and related tests and patches. This allows the project to build and test components for riscv64 alongside other supported architectures. 🚀 Kind of Contribution: ✨ New Feature Copybara import of the project: -- 0d02393a6335fb43d67678d0cd15d671e77dc089 by gns <[email protected]>: [XLA:CPU] Add support for riscv64 Co-authored-by: Levi Zim <[email protected]> -- 5d95fb479e45524299ff4193b99bb4db0d74483b by gns <[email protected]>: Refresh `rules_python` riscv64 patch Co-authored-by: Levi Zim <[email protected]> Merging this change closes #32812 PiperOrigin-RevId: 828379922
1 parent 852c9ca commit 1abd188

File tree

12 files changed

+57
-0
lines changed

12 files changed

+57
-0
lines changed

tensorflow/core/platform/build_config_root.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load(
77
_if_llvm_arm_available = "if_llvm_arm_available",
88
_if_llvm_hexagon_available = "if_llvm_hexagon_available",
99
_if_llvm_powerpc_available = "if_llvm_powerpc_available",
10+
_if_llvm_riscv_available = "if_llvm_riscv_available",
1011
_if_llvm_system_z_available = "if_llvm_system_z_available",
1112
_if_llvm_x86_available = "if_llvm_x86_available",
1213
_if_pywrap = "if_pywrap",
@@ -32,6 +33,7 @@ if_llvm_aarch64_available = _if_llvm_aarch64_available
3233
if_llvm_arm_available = _if_llvm_arm_available
3334
if_llvm_hexagon_available = _if_llvm_hexagon_available
3435
if_llvm_powerpc_available = _if_llvm_powerpc_available
36+
if_llvm_riscv_available = _if_llvm_riscv_available
3537
if_llvm_system_z_available = _if_llvm_system_z_available
3638
if_llvm_x86_available = _if_llvm_x86_available
3739
if_dynamic_kernels = _if_dynamic_kernels

third_party/xla/third_party/hwloc/hwloc.BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ cc_library(
272272
"hwloc/topology-linux.c",
273273
"include/hwloc/linux.h",
274274
],
275+
"@local_xla//xla/tsl:linux_riscv64": [
276+
"hwloc/topology-linux.c",
277+
"include/hwloc/linux.h",
278+
],
275279
"@local_xla//xla/tsl:linux_s390x": [
276280
"hwloc/topology-linux.c",
277281
"include/hwloc/linux.h",

third_party/xla/third_party/mkl_dnn/mkldnn_v1.BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ cc_library(
220220
"@local_xla//xla/tsl:linux_aarch64": ["-lrt"],
221221
"@local_xla//xla/tsl:linux_x86_64": ["-lrt"],
222222
"@local_xla//xla/tsl:linux_ppc64le": ["-lrt"],
223+
"@local_xla//xla/tsl:linux_riscv64": ["-lrt"],
223224
"//conditions:default": [],
224225
}),
225226
textual_hdrs = _TEXTUAL_HDRS_LIST,

third_party/xla/xla/backends/cpu/codegen/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ load(
55
"//xla/tsl/platform:build_config_root.bzl",
66
"if_llvm_aarch64_available",
77
"if_llvm_powerpc_available",
8+
"if_llvm_riscv_available",
89
"if_llvm_system_z_available",
910
"if_llvm_x86_available",
1011
)
@@ -164,6 +165,8 @@ xla_cc_test(
164165
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
165166
]) + if_llvm_powerpc_available([
166167
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
168+
]) + if_llvm_riscv_available([
169+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
167170
]) + if_llvm_system_z_available([
168171
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
169172
]) + if_llvm_x86_available([
@@ -286,6 +289,8 @@ cc_library(
286289
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
287290
]) + if_llvm_powerpc_available([
288291
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
292+
]) + if_llvm_riscv_available([
293+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
289294
]) + if_llvm_system_z_available([
290295
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
291296
]) + if_llvm_x86_available([

third_party/xla/xla/backends/cpu/codegen/tools/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load(
44
"//xla/tsl/platform:build_config_root.bzl",
55
"if_llvm_aarch64_available",
66
"if_llvm_powerpc_available",
7+
"if_llvm_riscv_available",
78
"if_llvm_system_z_available",
89
"if_llvm_x86_available",
910
)
@@ -38,6 +39,8 @@ cc_library(
3839
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
3940
]) + if_llvm_powerpc_available([
4041
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
42+
]) + if_llvm_riscv_available([
43+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
4144
]) + if_llvm_system_z_available([
4245
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
4346
]) + if_llvm_x86_available([

third_party/xla/xla/codegen/intrinsic/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load(
33
"//xla/tsl/platform:build_config_root.bzl",
44
"if_llvm_aarch64_available",
55
"if_llvm_powerpc_available",
6+
"if_llvm_riscv_available",
67
"if_llvm_system_z_available",
78
"if_llvm_x86_available",
89
)
@@ -149,6 +150,9 @@ cc_library(
149150
]) + if_llvm_powerpc_available([
150151
"@llvm-project//llvm:PowerPCAsmParser", # fixdeps: keep
151152
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
153+
]) + if_llvm_riscv_available([
154+
"@llvm-project//llvm:RISCVAsmParser", # fixdeps: keep
155+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
152156
]) + if_llvm_system_z_available([
153157
"@llvm-project//llvm:SystemZAsmParser", # fixdeps: keep
154158
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep

third_party/xla/xla/service/cpu/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ load(
1919
"//xla/tsl/platform:build_config_root.bzl",
2020
"if_llvm_aarch64_available",
2121
"if_llvm_powerpc_available",
22+
"if_llvm_riscv_available",
2223
"if_llvm_system_z_available",
2324
"if_llvm_x86_available",
2425
)
@@ -392,6 +393,8 @@ cc_library(
392393
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
393394
]) + if_llvm_powerpc_available([
394395
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
396+
]) + if_llvm_riscv_available([
397+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
395398
]) + if_llvm_system_z_available([
396399
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
397400
]) + if_llvm_x86_available([
@@ -2120,6 +2123,8 @@ cc_library(
21202123
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
21212124
]) + if_llvm_powerpc_available([
21222125
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
2126+
]) + if_llvm_riscv_available([
2127+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
21232128
]) + if_llvm_system_z_available([
21242129
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
21252130
]) + if_llvm_x86_available([

third_party/xla/xla/service/cpu/test_target_triple_helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ static const char kTargetTripleForHost[] = "aarch64-unknown-linux-gnu";
2323
defined(__ppc__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
2424
static const char kTargetCpuForHost[] = "ppc";
2525
static const char kTargetTripleForHost[] = "ppc64le-ibm-linux-gnu";
26+
#elif defined(__riscv) && (__riscv_xlen == 64)
27+
static const char kTargetCpuForHost[] = "";
28+
static const char kTargetTripleForHost[] = "riscv64-unknown-linux-gnu";
2629
#elif defined(__s390x__)
2730
static const char kTargetCpuForHost[] = "s390x";
2831
static const char kTargetTripleForHost[] = "systemz-none-linux-gnu";

third_party/xla/xla/tsl/BUILD

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ config_setting(
316316
visibility = ["//visibility:public"],
317317
)
318318

319+
config_setting(
320+
name = "linux_riscv64",
321+
constraint_values =
322+
[
323+
"@platforms//cpu:riscv64",
324+
"@platforms//os:linux",
325+
],
326+
visibility = ["//visibility:public"],
327+
)
328+
319329
config_setting(
320330
name = "linux_s390x",
321331
constraint_values =
@@ -382,6 +392,15 @@ selects.config_setting_group(
382392
visibility = ["//visibility:public"],
383393
)
384394

395+
selects.config_setting_group(
396+
name = "riscv64_or_cross",
397+
match_any = [
398+
":linux_riscv64",
399+
":with_cross_compiler_support",
400+
],
401+
visibility = ["//visibility:public"],
402+
)
403+
385404
selects.config_setting_group(
386405
name = "s390x_or_cross",
387406
match_any = [
@@ -453,6 +472,7 @@ selects.config_setting_group(
453472
":linux_aarch64",
454473
":linux_armhf",
455474
":linux_ppc64le",
475+
":linux_riscv64",
456476
":linux_s390x",
457477
":linux_x86_64",
458478
],

third_party/xla/xla/tsl/framework/contraction/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ cc_library(
113113
"//xla/tsl:fuchsia_x86_64": [],
114114
"//xla/tsl:ios": [],
115115
"//xla/tsl:linux_ppc64le": [],
116+
"//xla/tsl:linux_riscv64": [],
116117
"//xla/tsl:linux_s390x": [],
117118
"//xla/tsl:macos_arm64": [],
118119
"//conditions:default": [
@@ -132,6 +133,7 @@ cc_library(
132133
"//xla/tsl:fuchsia_x86_64": [],
133134
"//xla/tsl:ios": [],
134135
"//xla/tsl:linux_ppc64le": [],
136+
"//xla/tsl:linux_riscv64": [],
135137
"//xla/tsl:linux_s390x": [],
136138
"//xla/tsl:macos_arm64": [],
137139
"//conditions:default": ["//xla/tsl/mkl:onednn"],

0 commit comments

Comments
 (0)