CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
124 lines
4.7 KiB
Python
124 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
# MIT License
|
|
#
|
|
# Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
# copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
# SOFTWARE.
|
|
|
|
"""
|
|
Validates that hipStream_t pointer recycling does not cause stream ID collisions.
|
|
|
|
The test binary exercises multiple stream reuse patterns:
|
|
Phase 1: 4x sequential create/use/destroy (LIFO reuse)
|
|
Phase 2: 4x sequential create/use/destroy (recycled pointers)
|
|
Phase 3: 4x bulk create/use/destroy, then 4x bulk re-create/use/destroy
|
|
Phase 4: 3x paired create/use/destroy with alternating destroy order
|
|
|
|
Total: 22 kernel dispatches, each on a distinct stream.
|
|
|
|
The test binary also writes the raw hipStream_t pointer values to a file.
|
|
If HIP did not actually recycle any pointer values, the uniqueness assertion
|
|
is trivially satisfied and this test is NOT exercising the fix — a warning
|
|
is emitted in that case.
|
|
"""
|
|
|
|
import sys
|
|
import warnings
|
|
import pytest
|
|
|
|
NUM_EXPECTED_DISPATCHES = 22
|
|
|
|
|
|
def _pointers_were_recycled(pointer_data):
|
|
"""Return True if any raw pointer value appears more than once."""
|
|
return len(pointer_data) != len(set(pointer_data))
|
|
|
|
|
|
def test_stream_ids_are_unique_after_reuse(json_data, pointer_data):
|
|
"""
|
|
Every kernel dispatch must be attributed to a unique stream ID.
|
|
Before the fix, recycled hipStream_t pointers would collide with stale
|
|
map entries and dispatches would be misattributed to old stream lanes.
|
|
"""
|
|
data = json_data["rocprofiler-sdk-tool"]
|
|
buffer_records = data["buffer_records"]
|
|
|
|
kernel_dispatch_data = buffer_records["kernel_dispatch"]
|
|
assert len(kernel_dispatch_data) > 0, "Expected kernel dispatch records"
|
|
|
|
assert len(kernel_dispatch_data) == NUM_EXPECTED_DISPATCHES, (
|
|
f"Expected {NUM_EXPECTED_DISPATCHES} kernel dispatches, "
|
|
f"got {len(kernel_dispatch_data)}"
|
|
)
|
|
|
|
stream_ids = []
|
|
for node in kernel_dispatch_data:
|
|
assert "stream_id" in node
|
|
stream_id = node.stream_id.handle
|
|
assert stream_id != 0, "Kernel dispatch should not be on the null stream"
|
|
stream_ids.append(stream_id)
|
|
|
|
unique_stream_ids = set(stream_ids)
|
|
|
|
if not _pointers_were_recycled(pointer_data):
|
|
warnings.warn(
|
|
"HIP did not recycle any hipStream_t pointer values in this run. "
|
|
"This test is NOT exercising the stream-reuse fix. "
|
|
"The uniqueness assertion passes trivially.",
|
|
stacklevel=1,
|
|
)
|
|
|
|
assert len(unique_stream_ids) == NUM_EXPECTED_DISPATCHES, (
|
|
f"Expected {NUM_EXPECTED_DISPATCHES} unique stream IDs but got "
|
|
f"{len(unique_stream_ids)}: {sorted(unique_stream_ids)}. "
|
|
f"Stream ID collision detected (pointer recycling bug)."
|
|
)
|
|
|
|
|
|
def test_stream_ids_monotonically_increase(json_data, pointer_data):
|
|
"""
|
|
Stream IDs should be assigned in increasing order since streams are created
|
|
sequentially in this test (no concurrent creation).
|
|
"""
|
|
data = json_data["rocprofiler-sdk-tool"]
|
|
buffer_records = data["buffer_records"]
|
|
|
|
kernel_dispatch_data = buffer_records["kernel_dispatch"]
|
|
assert len(kernel_dispatch_data) > 0
|
|
|
|
stream_ids = [node.stream_id.handle for node in kernel_dispatch_data]
|
|
|
|
if not _pointers_were_recycled(pointer_data):
|
|
warnings.warn(
|
|
"HIP did not recycle any hipStream_t pointer values in this run. "
|
|
"Monotonicity check passes trivially without recycling.",
|
|
stacklevel=1,
|
|
)
|
|
|
|
for i in range(1, len(stream_ids)):
|
|
assert stream_ids[i] > stream_ids[i - 1], (
|
|
f"Stream IDs should be monotonically increasing but "
|
|
f"stream_id[{i}]={stream_ids[i]} <= stream_id[{i-1}]={stream_ids[i-1]}"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
|
|
sys.exit(exit_code)
|