Skip to content

Commit 987cf33

Browse files
infiWangGoogle-ML-Automation
authored andcommitted
PR #32812: [XLA:CPU] Add support for riscv64
Imported from GitHub PR #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: -- 0d02393 by gns <[email protected]>: [XLA:CPU] Add support for riscv64 Co-authored-by: Levi Zim <[email protected]> -- 5d95fb4 by gns <[email protected]>: Refresh `rules_python` riscv64 patch Co-authored-by: Levi Zim <[email protected]> Merging this change closes #32812 FUTURE_COPYBARA_INTEGRATE_REVIEW=#32812 from infiWang:riscv64 5d95fb4 PiperOrigin-RevId: 827890705
1 parent 8d2943b commit 987cf33

File tree

11 files changed

+55
-0
lines changed

11 files changed

+55
-0
lines changed

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+
"@xla//xla/tsl:linux_riscv64": [
276+
"hwloc/topology-linux.c",
277+
"include/hwloc/linux.h",
278+
],
275279
"@xla//xla/tsl:linux_s390x": [
276280
"hwloc/topology-linux.c",
277281
"include/hwloc/linux.h",

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
"@xla//xla/tsl:linux_aarch64": ["-lrt"],
221221
"@xla//xla/tsl:linux_x86_64": ["-lrt"],
222222
"@xla//xla/tsl:linux_ppc64le": ["-lrt"],
223+
"@xla//xla/tsl:linux_riscv64": ["-lrt"],
223224
"//conditions:default": [],
224225
}),
225226
textual_hdrs = _TEXTUAL_HDRS_LIST,

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
)
@@ -137,6 +138,8 @@ xla_cc_test(
137138
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
138139
]) + if_llvm_powerpc_available([
139140
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
141+
]) + if_llvm_riscv_available([
142+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
140143
]) + if_llvm_system_z_available([
141144
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
142145
]) + if_llvm_x86_available([
@@ -259,6 +262,8 @@ cc_library(
259262
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
260263
]) + if_llvm_powerpc_available([
261264
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
265+
]) + if_llvm_riscv_available([
266+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
262267
]) + if_llvm_system_z_available([
263268
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
264269
]) + if_llvm_x86_available([

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([

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

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
)
@@ -396,6 +397,8 @@ cc_library(
396397
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
397398
]) + if_llvm_powerpc_available([
398399
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
400+
]) + if_llvm_riscv_available([
401+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
399402
]) + if_llvm_system_z_available([
400403
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
401404
]) + if_llvm_x86_available([
@@ -2168,6 +2171,8 @@ cc_library(
21682171
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
21692172
]) + if_llvm_powerpc_available([
21702173
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
2174+
]) + if_llvm_riscv_available([
2175+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
21712176
]) + if_llvm_system_z_available([
21722177
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
21732178
]) + if_llvm_x86_available([

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";

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
],

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

xla/tsl/platform/build_config_root.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ load(
1111
_if_llvm_aarch64_available = "if_llvm_aarch64_available",
1212
_if_llvm_arm_available = "if_llvm_arm_available",
1313
_if_llvm_powerpc_available = "if_llvm_powerpc_available",
14+
_if_llvm_riscv_available = "if_llvm_riscv_available",
1415
_if_llvm_system_z_available = "if_llvm_system_z_available",
1516
_if_llvm_x86_available = "if_llvm_x86_available",
1617
_if_pywrap = "if_pywrap",
@@ -32,6 +33,7 @@ if_llvm_aarch32_available = _if_llvm_aarch32_available
3233
if_llvm_aarch64_available = _if_llvm_aarch64_available
3334
if_llvm_arm_available = _if_llvm_arm_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_static = _if_static

0 commit comments

Comments
 (0)