Skip to content

Commit 9e8f414

Browse files
infiWangGoogle-ML-Automation
authored andcommitted
PR #102607: Add support for Linux RISC-V 64
Imported from GitHub PR tensorflow/tensorflow#102607 This commit fixes #102159 which prevented TensorFlow from compiling on RISC-V 64 due to missing codepath in the build system. RFC: Currently this patch overrides timeout of rules_python for all platforms which is obviously not ideal. How do we set pip package timeout here in Tensorflow? See also: - bazelbuild/bazel#25236 - bazelbuild/bazel#25699 - bazel-contrib/rules_python#3350 - #32812 - tensorflow/runtime#135 Copybara import of the project: -- 13b7db883e6ea0aa631490fb5f806c55ceea7cb5 by gns <[email protected]>: [XLA:CPU] Add support for riscv64 Co-authored-by: Levi Zim <[email protected]> -- a00c3a3ba94664798960cbc2fb0a6746fe0c3ac1 by gns <[email protected]>: Add missing llvm:: namespace qualifiers for DTensor Add the `llvm::` namespace prefix to `cast` and `isa` where it was missing in the DTensor MLIR code. -- febc5abc56ab302f5f39fe20176ed00c0c95cb7e by gns <[email protected]>: runtime: add missing stdint header Co-authored-by: Levi Zim <[email protected]> -- 6bf63fec56a6d961b06d932fe69b76eae89d8cb7 by gns <[email protected]>: Add riscv64 support patch for rules_python bazel-contrib/rules_python#3350 -- 68c44fa9613d5577f36c51a192c932795e13ed83 by gns <[email protected]>: tools: py: add riscv64 to pip and manylinux compilance test -- 3f2fe1e0256476449f64658219d997727c9cc534 by gns <[email protected]>: Lift timeout of rules_python for BFS wheels -- 252a9b7ad2336b7abbb94e269b4a976b45d5d6e7 by gns <[email protected]>: Revert llvm toolchain patch for riscv64 As already upstreamed. Co-authored-by: Levi Zim <[email protected]> -- 51047a86131e991ffea74fccb8f55e3521237a64 by gns <[email protected]>: Lift timeout for BFS wheels during pip init -- 3b8276420031969423c9a1f150341a0e41fa372e by gns <[email protected]>: Refresh `rules_python` riscv64 patch Co-authored-by: Levi Zim <[email protected]> Merging this change closes #102607 FUTURE_COPYBARA_INTEGRATE_REVIEW=tensorflow/tensorflow#102607 from infiWang:riscv64 3b8276420031969423c9a1f150341a0e41fa372e PiperOrigin-RevId: 825073762
1 parent a402090 commit 9e8f414

29 files changed

+481
-460
lines changed

third_party/py/python_init_pip.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ cc_library(
3939
"numpy": ["numpy_headers"],
4040
},
4141
requirements_lock = REQUIREMENTS_WITH_LOCAL_WHEELS,
42+
timeout = 3600,
4243
)

third_party/py/python_init_rules.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ def python_init_rules(extra_patches = []):
4444
Label("//third_party/py:rules_python_pip_version.patch"),
4545
Label("//third_party/py:rules_python_freethreaded.patch"),
4646
Label("//third_party/py:rules_python_versions.patch"),
47+
Label("//third_party/py:rules_python_riscv64_pypi.patch"),
4748
] + extra_patches,
4849
)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
From: Levi Zim <[email protected]>
2+
Date: Sun, 26 Oct 2025 12:35:53 +0800
3+
Subject: [PATCH] fix: Add linux_riscv64 to _pip_repository_impl (#3350)
4+
5+
Add `linux_riscv64` support for pulling pip dependencies. This is not
6+
adding any hermetic toolchain support - user has to provide a working
7+
toolchain.
8+
9+
Fix #2729
10+
11+
---------
12+
13+
Co-authored-by: Ignas Anikevicius <[email protected]>
14+
---
15+
python/private/pypi/pip_repository.bzl | 1 +
16+
python/private/pypi/whl_installer/platform.py | 3 +++
17+
python/private/pypi/whl_target_platforms.bzl | 1 +
18+
tests/pypi/whl_installer/platform_test.py | 6 +++---
19+
.../whl_target_platforms/whl_target_platforms_tests.bzl | 8 ++++++++
20+
5 files changed, 16 insertions(+), 3 deletions(-)
21+
22+
diff --git a/python/private/pypi/pip_repository.bzl b/python/private/pypi/pip_repository.bzl
23+
index e9a4c44da3..d635651039 100644
24+
--- a/python/private/pypi/pip_repository.bzl
25+
+++ b/python/private/pypi/pip_repository.bzl
26+
@@ -96,6 +96,7 @@ def _pip_repository_impl(rctx):
27+
"linux_aarch64",
28+
"linux_arm",
29+
"linux_ppc",
30+
+ "linux_riscv64",
31+
"linux_s390x",
32+
"linux_x86_64",
33+
"osx_aarch64",
34+
diff --git a/python/private/pypi/whl_installer/platform.py b/python/private/pypi/whl_installer/platform.py
35+
index ff267fe4aa..0757d86990 100644
36+
--- a/python/private/pypi/whl_installer/platform.py
37+
+++ b/python/private/pypi/whl_installer/platform.py
38+
@@ -45,6 +45,7 @@ class Arch(Enum):
39+
ppc64le = 5
40+
s390x = 6
41+
arm = 7
42+
+ riscv64 = 8
43+
amd64 = x86_64
44+
arm64 = aarch64
45+
i386 = x86_32
46+
@@ -269,6 +270,8 @@ def platform_machine(self) -> str:
47+
return "ppc"
48+
elif self.arch == Arch.ppc64le:
49+
return "ppc64le"
50+
+ elif self.arch == Arch.riscv64:
51+
+ return "riscv64"
52+
elif self.arch == Arch.s390x:
53+
return "s390x"
54+
else:
55+
diff --git a/python/private/pypi/whl_target_platforms.bzl b/python/private/pypi/whl_target_platforms.bzl
56+
index 6c3dd5da83..28547c679c 100644
57+
--- a/python/private/pypi/whl_target_platforms.bzl
58+
+++ b/python/private/pypi/whl_target_platforms.bzl
59+
@@ -30,6 +30,7 @@ _CPU_ALIASES = {
60+
"ppc": "ppc",
61+
"ppc64": "ppc",
62+
"ppc64le": "ppc64le",
63+
+ "riscv64": "riscv64",
64+
"s390x": "s390x",
65+
"arm": "arm",
66+
"armv6l": "arm",
67+
diff --git a/tests/pypi/whl_installer/platform_test.py b/tests/pypi/whl_installer/platform_test.py
68+
index ad65650779..0d944bb196 100644
69+
--- a/tests/pypi/whl_installer/platform_test.py
70+
+++ b/tests/pypi/whl_installer/platform_test.py
71+
@@ -38,17 +38,17 @@ def test_can_get_specific_from_string(self):
72+
73+
def test_can_get_all_for_py_version(self):
74+
cp39 = Platform.all(minor_version=9, micro_version=0)
75+
- self.assertEqual(21, len(cp39), f"Got {cp39}")
76+
+ self.assertEqual(24, len(cp39), f"Got {cp39}")
77+
self.assertEqual(cp39, Platform.from_string("cp39.0_*"))
78+
79+
def test_can_get_all_for_os(self):
80+
linuxes = Platform.all(OS.linux, minor_version=9)
81+
- self.assertEqual(7, len(linuxes))
82+
+ self.assertEqual(8, len(linuxes))
83+
self.assertEqual(linuxes, Platform.from_string("cp39_linux_*"))
84+
85+
def test_can_get_all_for_os_for_host_python(self):
86+
linuxes = Platform.all(OS.linux)
87+
- self.assertEqual(7, len(linuxes))
88+
+ self.assertEqual(8, len(linuxes))
89+
self.assertEqual(linuxes, Platform.from_string("linux_*"))
90+
91+
def test_platform_sort(self):
92+
diff --git a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
93+
index a976a0cf95..6bec26c10c 100644
94+
--- a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
95+
+++ b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
96+
@@ -34,6 +34,9 @@ def _test_simple(env):
97+
"musllinux_1_1_ppc64le": [
98+
struct(os = "linux", cpu = "ppc64le", abi = None, target_platform = "linux_ppc64le", version = (1, 1)),
99+
],
100+
+ "musllinux_1_2_riscv64": [
101+
+ struct(os = "linux", cpu = "riscv64", abi = None, target_platform = "linux_riscv64", version = (1, 2)),
102+
+ ],
103+
"win_amd64": [
104+
struct(os = "windows", cpu = "x86_64", abi = None, target_platform = "windows_x86_64", version = (0, 0)),
105+
],
106+
@@ -66,6 +69,9 @@ def _test_with_abi(env):
107+
"musllinux_1_1_ppc64le": [
108+
struct(os = "linux", cpu = "ppc64le", abi = "cp311", target_platform = "cp311_linux_ppc64le", version = (1, 1)),
109+
],
110+
+ "musllinux_1_2_riscv64": [
111+
+ struct(os = "linux", cpu = "riscv64", abi = "cp311", target_platform = "cp311_linux_riscv64", version = (1, 2)),
112+
+ ],
113+
"win_amd64": [
114+
struct(os = "windows", cpu = "x86_64", abi = "cp311", target_platform = "cp311_windows_x86_64", version = (0, 0)),
115+
],
116+
@@ -103,6 +109,7 @@ def _can_parse_existing_tags(env):
117+
"manylinux_11_12_i686": 1,
118+
"manylinux_11_12_ppc64": 1,
119+
"manylinux_11_12_ppc64le": 1,
120+
+ "manylinux_11_12_riscv64": 1,
121+
"manylinux_11_12_s390x": 1,
122+
"manylinux_11_12_x86_64": 1,
123+
"manylinux_1_2_aarch64": 1,
124+
@@ -111,6 +118,7 @@ def _can_parse_existing_tags(env):
125+
"musllinux_11_12_armv7l": 1,
126+
"musllinux_11_12_i686": 1,
127+
"musllinux_11_12_ppc64le": 1,
128+
+ "musllinux_11_12_riscv64": 1,
129+
"musllinux_11_12_s390x": 1,
130+
"musllinux_11_12_x86_64": 1,
131+
"win32": 1,

xla/backends/gpu/runtime/BUILD

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,12 @@ xla_test(
344344
"//xla:xla_data_proto_cc",
345345
"//xla/service:buffer_assignment",
346346
"//xla/stream_executor:gpu_solver_context",
347-
"//xla/stream_executor:platform_manager",
348347
"//xla/stream_executor/platform:platform_object_registry",
349348
"//xla/tests:hlo_test_base",
350349
"//xla/tsl/platform:statusor",
351350
"//xla/tsl/util/proto:proto_matchers",
352-
"@com_google_absl//absl/log:check",
353351
"@com_google_absl//absl/status:status_matchers",
354352
"@com_google_googletest//:gtest_main",
355-
"@tsl//tsl/platform:protobuf",
356353
],
357354
)
358355

@@ -725,7 +722,6 @@ cc_library(
725722
"@com_google_absl//absl/base:nullability",
726723
"@com_google_absl//absl/container:inlined_vector",
727724
"@com_google_absl//absl/log",
728-
"@com_google_absl//absl/log:check",
729725
"@com_google_absl//absl/memory",
730726
"@com_google_absl//absl/status",
731727
"@com_google_absl//absl/status:statusor",
@@ -2901,16 +2897,18 @@ cc_library(
29012897
srcs = ["thunk_buffer_debug_pass.cc"],
29022898
hdrs = ["thunk_buffer_debug_pass.h"],
29032899
deps = [
2900+
":buffer_debug_log_entry_metadata_store",
2901+
":buffer_debug_log_structs",
29042902
":buffers_checksum_thunk",
29052903
":buffers_nan_count_thunk",
29062904
":custom_call_thunk",
29072905
":sequential_thunk",
29082906
":thunk",
2909-
":thunk_buffer_id",
29102907
":thunk_pass_pipeline",
29112908
"//xla:shape_util",
29122909
"//xla:xla_data_proto_cc",
29132910
"//xla/ffi",
2911+
"//xla/ffi:attribute_map",
29142912
"//xla/ffi/api:c_api",
29152913
"//xla/hlo/ir:hlo",
29162914
"//xla/runtime:buffer_use",
@@ -2922,6 +2920,7 @@ cc_library(
29222920
"//xla/tsl/platform:statusor",
29232921
"@com_google_absl//absl/base:nullability",
29242922
"@com_google_absl//absl/container:flat_hash_map",
2923+
"@com_google_absl//absl/functional:bind_front",
29252924
"@com_google_absl//absl/log",
29262925
"@com_google_absl//absl/log:check",
29272926
"@com_google_absl//absl/status",
@@ -2940,7 +2939,6 @@ xla_cc_test(
29402939
":sequential_thunk",
29412940
":thunk",
29422941
":thunk_buffer_debug_pass",
2943-
":thunk_buffer_id",
29442942
":thunk_id",
29452943
":thunk_pass_pipeline",
29462944
"//xla:literal_util",
@@ -3006,8 +3004,10 @@ cc_library(
30063004
srcs = ["buffers_checksum_thunk.cc"],
30073005
hdrs = ["buffers_checksum_thunk.h"],
30083006
deps = [
3007+
":buffer_debug_log_entry_metadata_store",
3008+
":buffer_debug_log_structs",
30093009
":thunk",
3010-
":thunk_buffer_id",
3010+
":thunk_id",
30113011
"//xla/service:buffer_assignment",
30123012
"//xla/stream_executor:device_memory",
30133013
"//xla/stream_executor:launch_dim",
@@ -3035,10 +3035,10 @@ xla_test(
30353035
"gpu",
30363036
],
30373037
deps = [
3038+
":buffer_debug_log_entry_metadata_store",
30383039
":buffer_debug_log_structs",
30393040
":buffers_checksum_thunk",
30403041
":thunk",
3041-
":thunk_buffer_id",
30423042
":thunk_id",
30433043
"//xla/service:buffer_assignment",
30443044
"//xla/service:executable",
@@ -3052,6 +3052,7 @@ xla_test(
30523052
"//xla/stream_executor/gpu:buffer_debug_log",
30533053
"//xla/tsl/lib/core:status_test_util",
30543054
"//xla/tsl/platform:statusor",
3055+
"@com_google_absl//absl/status",
30553056
"@com_google_googletest//:gtest_main",
30563057
],
30573058
)
@@ -3061,8 +3062,10 @@ cc_library(
30613062
srcs = ["buffers_nan_count_thunk.cc"],
30623063
hdrs = ["buffers_nan_count_thunk.h"],
30633064
deps = [
3065+
":buffer_debug_log_entry_metadata_store",
3066+
":buffer_debug_log_structs",
30643067
":thunk",
3065-
":thunk_buffer_id",
3068+
":thunk_id",
30663069
"//xla:types",
30673070
"//xla/service:buffer_assignment",
30683071
"//xla/stream_executor:device_memory",
@@ -3093,10 +3096,10 @@ xla_test(
30933096
"gpu",
30943097
],
30953098
deps = [
3099+
":buffer_debug_log_entry_metadata_store",
30963100
":buffer_debug_log_structs",
30973101
":buffers_nan_count_thunk",
30983102
":thunk",
3099-
":thunk_buffer_id",
31003103
":thunk_id",
31013104
"//xla:types",
31023105
"//xla/service:buffer_assignment",
@@ -3125,38 +3128,14 @@ xla_py_proto_library(
31253128
deps = [":buffer_debug_log_proto"],
31263129
)
31273130

3128-
cc_library(
3129-
name = "thunk_buffer_id",
3130-
hdrs = ["thunk_buffer_id.h"],
3131-
compatible_with = get_compatible_with_portable(),
3132-
deps = [
3133-
":thunk_id",
3134-
"@com_google_absl//absl/status",
3135-
"@com_google_absl//absl/status:statusor",
3136-
"@com_google_absl//absl/strings:str_format",
3137-
],
3138-
)
3139-
3140-
xla_cc_test(
3141-
name = "thunk_buffer_id_test",
3142-
srcs = ["thunk_buffer_id_test.cc"],
3143-
deps = [
3144-
":thunk_buffer_id",
3145-
":thunk_id",
3146-
"//xla/tsl/platform:statusor",
3147-
"@com_google_absl//absl/status",
3148-
"@com_google_absl//absl/status:status_matchers",
3149-
"@com_google_googletest//:gtest_main",
3150-
],
3151-
)
3152-
31533131
cc_library(
31543132
name = "buffer_debug_log_structs",
31553133
hdrs = ["buffer_debug_log_structs.h"],
31563134
compatible_with = get_compatible_with_portable(),
31573135
deps = [
3158-
":thunk_buffer_id",
3136+
":buffer_debug_log_proto_cc",
31593137
"//xla/tsl/lib/gtl:int_type",
3138+
"@com_google_absl//absl/strings:str_format",
31603139
],
31613140
)
31623141

@@ -3182,7 +3161,6 @@ xla_cc_test(
31823161
deps = [
31833162
":buffer_debug_log_entry_metadata_store",
31843163
":buffer_debug_log_structs",
3185-
":thunk_buffer_id",
31863164
":thunk_id",
31873165
"//xla/tsl/util/proto:proto_matchers",
31883166
"@com_google_googletest//:gtest_main",

xla/backends/gpu/runtime/buffer_debug_log_entry_metadata_store.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ BufferDebugLogProto BufferDebugLogEntryMetadataStore::EntriesToProto(
6363

6464
BufferDebugLogProto proto;
6565
for (const BufferDebugLogEntry& entry : entries) {
66-
// TODO: b/447080910 - simplify once entry_id is a BufferDebugLogEntryId.
67-
std::optional<Metadata> metadata =
68-
GetEntryMetadataLocked(BufferDebugLogEntryId{entry.entry_id.value()});
66+
std::optional<Metadata> metadata = GetEntryMetadataLocked(entry.entry_id);
6967
if (!metadata.has_value()) {
7068
continue;
7169
}

xla/backends/gpu/runtime/buffer_debug_log_entry_metadata_store_test.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ limitations under the License.
2121
#include <gmock/gmock.h>
2222
#include <gtest/gtest.h>
2323
#include "xla/backends/gpu/runtime/buffer_debug_log_structs.h"
24-
#include "xla/backends/gpu/runtime/thunk_buffer_id.h"
2524
#include "xla/backends/gpu/runtime/thunk_id.h"
2625
#include "xla/tsl/util/proto/proto_matchers.h"
2726

@@ -76,13 +75,11 @@ TEST(BufferDebugLogEntryMetadataStoreTest, EntriesToProto) {
7675
});
7776
std::vector<BufferDebugLogEntry> entries = {
7877
{
79-
// TODO: b/447080910 - use BufferDebugLogEntryId directly.
80-
/*entry_id=*/reinterpret_cast<const ThunkBufferId&>(entry_id1),
78+
/*entry_id=*/entry_id1,
8179
/*checksum=*/12341234,
8280
},
8381
{
84-
// TODO: b/447080910 - use BufferDebugLogEntryId directly.
85-
/*entry_id=*/reinterpret_cast<const ThunkBufferId&>(entry_id2),
82+
/*entry_id=*/entry_id2,
8683
/*checksum=*/56785678,
8784
},
8885
};

xla/backends/gpu/runtime/buffer_debug_log_structs.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,22 @@ limitations under the License.
2020
#include <cstdint>
2121
#include <tuple>
2222

23-
#include "xla/backends/gpu/runtime/thunk_buffer_id.h"
23+
#include "absl/strings/str_format.h"
24+
#include "xla/backends/gpu/runtime/buffer_debug_log.pb.h"
2425
#include "xla/tsl/lib/gtl/int_type.h"
2526

2627
namespace xla::gpu {
2728

28-
// TODO: b/447080910 - use this instead of ThunkBufferId.
2929
TSL_LIB_GTL_DEFINE_INT_TYPE(BufferDebugLogEntryId, uint32_t)
3030

3131
struct BufferDebugLogEntry {
32-
// An ID that uniquely identifies a thunk and its specific input or output
33-
// buffer.
34-
ThunkBufferId entry_id;
32+
// An ID that uniquely identifies a log entry within a HLO module execution.
33+
BufferDebugLogEntryId entry_id;
3534
uint32_t value;
3635

3736
template <typename Sink>
3837
friend void AbslStringify(Sink& sink, const BufferDebugLogEntry& entry) {
39-
absl::Format(&sink, "{entry_id: %v, value: %u}", entry.entry_id,
38+
absl::Format(&sink, "{entry_id: %v, value: %u}", entry.entry_id.value(),
4039
entry.value);
4140
}
4241

0 commit comments

Comments
 (0)