Skip to content

Commit d5fa396

Browse files
infiWangkxxt
andcommitted
[XLA:CPU] Add support for riscv64
Co-authored-by: Levi Zim <[email protected]>
1 parent a4725eb commit d5fa396

File tree

12 files changed

+53
-1
lines changed

12 files changed

+53
-1
lines changed

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/llvm/toolchains.patch

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ diff --git a/utils/bazel/llvm-project-overlay/llvm/config.bzl b/utils/bazel/llvm
4444
index 2e3bff53ead9..8d01617effdc 100644
4545
--- a/utils/bazel/llvm-project-overlay/llvm/config.bzl
4646
+++ b/utils/bazel/llvm-project-overlay/llvm/config.bzl
47-
@@ -98,8 +98,9 @@ builtin_thread_pointer = select({
47+
@@ -98,8 +98,10 @@ builtin_thread_pointer = select({
4848
# TODO: We should split out host vs. target here.
4949
llvm_config_defines = os_defines + builtin_thread_pointer + select({
5050
"@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"),
@@ -53,6 +53,7 @@ index 2e3bff53ead9..8d01617effdc 100644
5353
+ "//llvm:macos_arm64": native_arch_defines("AArch64", "arm64-apple-darwin"),
5454
+ "//llvm:macos_x86_64": native_arch_defines("X86", "x86_64-unknown-darwin"),
5555
+ "//llvm:macos_x86_64_default": native_arch_defines("X86", "x86_64-unknown-darwin"),
56+
+ "@bazel_tools//src/conditions:linux_riscv64": native_arch_defines("RISCV", "riscv64-unknown-linux-gnu"),
5657
"@bazel_tools//src/conditions:linux_aarch64": native_arch_defines("AArch64", "aarch64-unknown-linux-gnu"),
5758
"@bazel_tools//src/conditions:linux_ppc64le": native_arch_defines("PowerPC", "powerpc64le-unknown-linux-gnu"),
5859
"@bazel_tools//src/conditions:linux_s390x": native_arch_defines("SystemZ", "systemz-unknown-linux_gnu"),

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: 3 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
)
@@ -127,6 +128,8 @@ xla_cc_test(
127128
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
128129
]) + if_llvm_powerpc_available([
129130
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
131+
]) + if_llvm_riscv_available([
132+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
130133
]) + if_llvm_system_z_available([
131134
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
132135
]) + 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
@@ -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
)
@@ -37,6 +38,8 @@ cc_library(
3738
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
3839
]) + if_llvm_powerpc_available([
3940
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
41+
]) + if_llvm_riscv_available([
42+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
4043
]) + if_llvm_system_z_available([
4144
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
4245
]) + if_llvm_x86_available([

third_party/xla/xla/codegen/math/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
)
@@ -142,6 +143,9 @@ cc_library(
142143
]) + if_llvm_powerpc_available([
143144
"@llvm-project//llvm:PowerPCAsmParser", # fixdeps: keep
144145
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
146+
]) + if_llvm_riscv_available([
147+
"@llvm-project//llvm:RISCVAsmParser", # fixdeps: keep
148+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
145149
]) + if_llvm_system_z_available([
146150
"@llvm-project//llvm:SystemZAsmParser", # fixdeps: keep
147151
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep

third_party/xla/xla/service/cpu/BUILD

Lines changed: 3 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
)
@@ -403,6 +404,8 @@ cc_library(
403404
"@llvm-project//llvm:AArch64CodeGen", # fixdeps: keep
404405
]) + if_llvm_powerpc_available([
405406
"@llvm-project//llvm:PowerPCCodeGen", # fixdeps: keep
407+
]) + if_llvm_riscv_available([
408+
"@llvm-project//llvm:RISCVCodeGen", # fixdeps: keep
406409
]) + if_llvm_system_z_available([
407410
"@llvm-project//llvm:SystemZCodeGen", # fixdeps: keep
408411
]) + 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[] = "generic-rv64";
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
@@ -303,6 +303,16 @@ config_setting(
303303
visibility = ["//visibility:public"],
304304
)
305305

306+
config_setting(
307+
name = "linux_riscv64",
308+
constraint_values =
309+
[
310+
"@platforms//cpu:riscv64",
311+
"@platforms//os:linux",
312+
],
313+
visibility = ["//visibility:public"],
314+
)
315+
306316
config_setting(
307317
name = "linux_s390x",
308318
constraint_values =
@@ -369,6 +379,15 @@ selects.config_setting_group(
369379
visibility = ["//visibility:public"],
370380
)
371381

382+
selects.config_setting_group(
383+
name = "riscv64_or_cross",
384+
match_any = [
385+
":linux_riscv64",
386+
":with_cross_compiler_support",
387+
],
388+
visibility = ["//visibility:public"],
389+
)
390+
372391
selects.config_setting_group(
373392
name = "s390x_or_cross",
374393
match_any = [
@@ -440,6 +459,7 @@ selects.config_setting_group(
440459
":linux_aarch64",
441460
":linux_armhf",
442461
":linux_ppc64le",
462+
":linux_riscv64",
443463
":linux_s390x",
444464
":linux_x86_64",
445465
],

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ cc_library(
9696
"//xla/tsl:fuchsia_x86_64": [],
9797
"//xla/tsl:ios": [],
9898
"//xla/tsl:linux_ppc64le": [],
99+
"//xla/tsl:linux_riscv64": [],
99100
"//xla/tsl:linux_s390x": [],
100101
"//xla/tsl:macos_arm64": [],
101102
"//conditions:default": [
@@ -115,6 +116,7 @@ cc_library(
115116
"//xla/tsl:fuchsia_x86_64": [],
116117
"//xla/tsl:ios": [],
117118
"//xla/tsl:linux_ppc64le": [],
119+
"//xla/tsl:linux_riscv64": [],
118120
"//xla/tsl:linux_s390x": [],
119121
"//xla/tsl:macos_arm64": [],
120122
"//conditions:default": ["@onednn//:mkl_dnn"],

0 commit comments

Comments
 (0)