Skip to content

Commit 65e4783

Browse files
tsrw2048tensorflower-gardener
authored andcommitted
PR #39744: [ROCm] Porting CUB sort FFI handler consolidation to ROCm.
Imported from GitHub PR openxla/xla#39744 📝 Summary of Changes The CUB sort FFI handler was recently refactored and consolidated in two commits: - openxla/xla@878c525 - openxla/xla@ce4b95a In order to allow ROCm devices to continue using the CUB sort function, these same changes were ported to the relevant ROCm files. Changes to files in `xla/stream_executor/rocm/` - The build file is restructured so that it no longer compiles `cub_sort_kernel_rocm.cc` for each type. - The various helper functions from commit openxla/xla@878c525 have been ported here. - The missing S32_B16 and S32_B64 template instantiations have been added. 🎯 Justification This change was breaking unit tests in XLA and JAX on ROCm: - XLA: - xla/gpu/service/tests/sorting_test.cc - JAX: - tests/ann_test.py::AnnTest::test_approx_max_k0 - tests/ann_test.py::AnnTest::test_approx_max_k5 - tests/ann_test.py::AnnTest::test_approx_max_k8 - tests/ann_test.py::AnnTest::test_approx_min_k0 - tests/ann_test.py::AnnTest::test_approx_min_k5 - tests/ann_test.py::AnnTest::test_approx_min_k8 - tests/scipy_signal_test.py::LaxBackedScipySignalTests::testWelchAgainstNumpy8 🚀 Kind of Contribution 🐛 Bug Fix 🧪 Unit Tests: The various unit tests are now passing with the changes in the PR. - XLA (`sorting_test.cc`): ``` ================================================================================ INFO: Found 1 test target... Target //xla/service/gpu/tests:sorting_test_amdgpu_any up-to-date: bazel-bin/xla/service/gpu/tests/sorting_test_amdgpu_any INFO: Elapsed time: 192.140s, Critical Path: 153.72s INFO: 5136 processes: 650 internal, 4486 local. INFO: Build completed successfully, 5136 total actions //xla/service/gpu/tests:sorting_test_amdgpu_any PASSED in 31.8s Stats over 15 runs: max = 31.8s, min = 22.3s, avg = 29.9s, dev = 2.7s Executed 1 out of 1 test: 1 test passes. ``` - JAX (`tests/ann_test.py::AnnTest::test_approx_*`): ``` ==================================================================== test session starts ==================================================================== platform linux -- Python 3.12.3, pytest-8.4.2, pluggy-1.6.0 -- /usr/bin/python3 cachedir: .pytest_cache hypothesis profile 'default' rootdir: /workspace/rocm-jax/jax configfile: pyproject.toml plugins: xdist-3.8.0, hypothesis-6.142.1 collected 42 items / 32 deselected / 10 selected tests/ann_test.py::AnnTest::test_approx_max_k0 PASSED tests/ann_test.py::AnnTest::test_approx_max_k1 PASSED tests/ann_test.py::AnnTest::test_approx_max_k2 PASSED tests/ann_test.py::AnnTest::test_approx_max_k3 PASSED tests/ann_test.py::AnnTest::test_approx_max_k4 PASSED tests/ann_test.py::AnnTest::test_approx_max_k5 PASSED tests/ann_test.py::AnnTest::test_approx_max_k6 PASSED tests/ann_test.py::AnnTest::test_approx_max_k7 PASSED tests/ann_test.py::AnnTest::test_approx_max_k8 PASSED tests/ann_test.py::AnnTest::test_approx_max_k9 PASSED ============================================================= 10 passed, 32 deselected in 9.25s ============================================================= ``` - JAX (`tests/scipy_signal_test.py::LaxBackedScipySignalTests::testWelchAgainstNumpy8`): ``` ==================================================================== test session starts ==================================================================== platform linux -- Python 3.12.3, pytest-8.4.2, pluggy-1.6.0 -- /usr/bin/python3 cachedir: .pytest_cache hypothesis profile 'default' rootdir: /workspace/rocm-jax/jax configfile: pyproject.toml plugins: xdist-3.8.0, hypothesis-6.142.1 collected 100 items / 99 deselected / 1 selected tests/scipy_signal_test.py::LaxBackedScipySignalTests::testWelchAgainstNumpy8 PASSED ============================================================= 1 passed, 99 deselected in 8.16s ============================================================== ``` Copybara import of the project: -- 6b432c264245514680969c508d9a0c510b15aed5 by tsrw2048 <[email protected]>: [ROCm] Porting CUB sort FFI handler consolidation to ROCm. The CUB sort FFI handler was refactored and consolidated in two commits: - 878c52525f1a72856e5c5fd42775211f19266568 - ce4b95a3668977155ec4914b1b28f2d5bf040ef2 In order to allow ROCm devices to continue using the CUB sort function, these same changes were ported to the relevant ROCm files. Changes to files in xla/stream_executor/rocm/ - The build file is restructured so that it no longer compiles cub_sort_kernel_rocm.cc for each type. - The various helper functions from commit 878c525 have been ported here. - The missing S32_B16 and S32_B64 template instantiations have been added. Merging this change closes #39744 FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#39744 from ROCm:rocm-cub-sort-pair-fix-upstream 6b432c264245514680969c508d9a0c510b15aed5 PiperOrigin-RevId: 892245912
1 parent 2bb2829 commit 65e4783

4 files changed

Lines changed: 363 additions & 196 deletions

File tree

‎third_party/xla/xla/stream_executor/rocm/BUILD‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,8 @@ cc_library(
828828
":amdhipblaslt_plugin",
829829
":buffer_comparator_kernel_rocm",
830830
":collective_signal_rocm",
831+
":cub_scan_kernel_rocm",
832+
":cub_sort_kernel_rocm",
831833
":hipfft_plugin",
832834
":make_batch_pointers_kernel_rocm",
833835
":miopen_plugin",
@@ -840,8 +842,6 @@ cc_library(
840842
":rocm_platform",
841843
":rocm_solver_context",
842844
":topk_kernel_rocm",
843-
] + [":cub_sort_kernel_rocm_" + suffix for suffix in get_cub_sort_kernel_types()] + [
844-
":cub_scan_kernel_rocm",
845845
],
846846
alwayslink = 1,
847847
)
@@ -1157,7 +1157,7 @@ cc_library(
11571157

11581158
# CUB sort kernel implementation (hipCUB/rocPRIM) - compiled with hipcc
11591159
[rocm_library(
1160-
name = "cub_sort_kernel_rocm_impl_{}".format(typename),
1160+
name = "cub_sort_kernel_rocm_type_{}".format(typename),
11611161
srcs = ["cub_sort_kernel_rocm_impl.cu.cc"],
11621162
# copybara:uncomment compatible_with = ["//buildenv/target:non_prod"],
11631163
local_defines = ["CUB_TYPE_" + typename.upper()],
@@ -1178,25 +1178,32 @@ cc_library(
11781178
) for typename in get_cub_sort_kernel_types()]
11791179

11801180
# CUB sort kernel FFI registration - compiled with regular C++ compiler
1181-
[cc_library(
1182-
name = "cub_sort_kernel_rocm_{}".format(typename),
1181+
cc_library(
1182+
name = "cub_sort_kernel_rocm",
11831183
srcs = ["cub_sort_kernel_rocm.cc"],
1184-
local_defines = ["CUB_TYPE_" + typename.upper()],
11851184
tags = [
11861185
"gpu",
11871186
"rocm-only",
11881187
],
11891188
deps = [
11901189
":cub_sort_kernel_rocm_header",
1191-
":cub_sort_kernel_rocm_impl_{}".format(typename),
1190+
":rocm_status",
1191+
"//xla:shape_util",
1192+
"//xla:xla_data_proto_cc",
11921193
"//xla/backends/gpu:ffi",
11931194
"//xla/ffi",
11941195
"//xla/ffi:ffi_api",
1196+
"//xla/tsl/platform:status_macros",
11951197
"@com_google_absl//absl/status",
1198+
"@com_google_absl//absl/status:statusor",
1199+
"@com_google_absl//absl/strings",
11961200
"@local_config_rocm//rocm:rocm_headers",
1201+
] + [
1202+
":cub_sort_kernel_rocm_type_{}".format(typename)
1203+
for typename in get_cub_sort_kernel_types()
11971204
],
11981205
alwayslink = 1,
1199-
) for typename in get_cub_sort_kernel_types()]
1206+
)
12001207

12011208
# CUB scan kernel implementation (hipCUB/rocPRIM) - compiled with hipcc
12021209
rocm_library(

0 commit comments

Comments
 (0)