Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def pytest_addoption(parser):
default=40,
help="Memory copies issued after Tool B registered (Tool B must capture these)",
)
parser.addoption(
"--copy-bytes",
action="store",
type=int,
default=16 << 20,
help="Bytes moved by each copy the workload issues",
)


def _load(path):
Expand All @@ -78,3 +85,8 @@ def phase1_copies(request):
@pytest.fixture
def phase2_copies(request):
return request.config.getoption("--phase2-copies")


@pytest.fixture
def copy_bytes(request):
return request.config.getoption("--copy-bytes")
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ def test_tool_b_captured_memcpy_only(tool_b_data):
)


def test_tool_b_copy_count_is_phase2_only(tool_b_data, phase1_copies, phase2_copies):
"""Count proof: Tool B captured exactly the post-registration copies."""
def test_tool_b_copy_volume_is_phase2_only(
tool_b_data, phase1_copies, phase2_copies, copy_bytes
):
"""Volume proof: Tool B captured exactly the post-registration copies, in bytes."""
sdk = _sdk(tool_b_data)
captured = len(sdk["buffer_records"]["memory_copies"])
copies = sdk["buffer_records"]["memory_copies"]

captured = sum(itr["bytes"] for itr in copies)
expected = phase2_copies * copy_bytes

assert captured == phase2_copies, (
f"expected exactly {phase2_copies} memory copies (phase 2 only), got {captured}; "
f"phase 1 ({phase1_copies}) should have been missed"
assert captured == expected, (
f"expected exactly {expected} bytes of memory copies (phase 2 only), "
f"got {captured}; phase 1 ({phase1_copies * copy_bytes} bytes) should "
"have been missed"
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def pytest_addoption(parser):
default=40,
help="Memory copies issued after the late tools registered",
)
parser.addoption(
"--copy-bytes",
action="store",
type=int,
default=16 << 20,
help="Bytes moved by each copy the workload issues",
)


def _load(path):
Expand Down Expand Up @@ -89,3 +96,8 @@ def phase2_dispatches(request):
@pytest.fixture
def phase2_copies(request):
return request.config.getoption("--phase2-copies")


@pytest.fixture
def copy_bytes(request):
return request.config.getoption("--copy-bytes")
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ def test_tool_b1_dispatch_count_is_phase2(tool_b1_data, phase2_dispatches):
), f"expected {phase2_dispatches} dispatches (phase 2), got {captured}"


def test_tool_b2_copy_count_is_phase2(tool_b2_data, phase2_copies):
captured = len(_buf(tool_b2_data, "memory_copies"))
def test_tool_b2_copy_volume_is_phase2(tool_b2_data, phase2_copies, copy_bytes):
"""Tool B2 captured the phase 2 copies, measured in bytes."""
copies = _buf(tool_b2_data, "memory_copies")
captured = sum(itr["bytes"] for itr in copies)
expected = phase2_copies * copy_bytes

assert (
captured == phase2_copies
), f"expected {phase2_copies} memory copies (phase 2), got {captured}"
captured == expected
), f"expected {expected} bytes of memory copies (phase 2), got {captured}"


# ---- timing proof for both late tools -------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def pytest_addoption(parser):
default=40,
help="Memory copies issued after Tool B registered",
)
parser.addoption(
"--copy-bytes",
action="store",
type=int,
default=16 << 20,
help="Bytes moved by each copy the workload issues",
)


def _load(path):
Expand All @@ -78,3 +85,8 @@ def phase2_dispatches(request):
@pytest.fixture
def phase2_copies(request):
return request.config.getoption("--phase2-copies")


@pytest.fixture
def copy_bytes(request):
return request.config.getoption("--copy-bytes")
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,21 @@ def test_rccl_is_tool_a_exclusive(tool_a_data, tool_b_data):
assert len(_buf(tool_b_data, "rccl_api_traces")) == 0


def test_tool_b_counts_are_phase2(tool_b_data, phase2_dispatches, phase2_copies):
"""Tool B captured the post-registration dispatch and copy counts.

Memory copies are deterministic (exact). Kernel dispatches are asserted as a lower
bound: RCCL all-reduce launches its own GPU kernels under the hood, so the dispatch
count is the explicit kernels (phase2_dispatches) PLUS RCCL's internal kernels.
"""
def test_tool_b_counts_are_phase2(
tool_b_data, phase2_dispatches, phase2_copies, copy_bytes
):
"""Tool B captured the phase 2 work: copies in bytes, dispatches as a lower
bound because RCCL all-reduce launches its own GPU kernels."""
disp = len(_buf(tool_b_data, "kernel_dispatch"))
copies = len(_buf(tool_b_data, "memory_copies"))
copied = sum(itr["bytes"] for itr in _buf(tool_b_data, "memory_copies"))
expected = phase2_copies * copy_bytes
assert disp >= phase2_dispatches, (
f"expected at least {phase2_dispatches} dispatches (phase 2 explicit kernels), "
f"got {disp}"
)
assert (
copies == phase2_copies
), f"expected {phase2_copies} memory copies (phase 2), got {copies}"
copied == expected
), f"expected {expected} bytes of memory copies (phase 2), got {copied}"


def test_tool_b_records_after_registration(tool_b_data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def pytest_addoption(parser):
default=40,
help="Memory copies issued after Tool B registered",
)
parser.addoption(
"--copy-bytes",
action="store",
type=int,
default=16 << 20,
help="Bytes moved by each copy the workload issues",
)


def _load(path):
Expand All @@ -78,3 +85,8 @@ def phase2_dispatches(request):
@pytest.fixture
def phase2_copies(request):
return request.config.getoption("--phase2-copies")


@pytest.fixture
def copy_bytes(request):
return request.config.getoption("--copy-bytes")
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,21 @@ def test_dispatch_and_copy_are_tool_b_exclusive(tool_a_data, tool_b_data):
# ---- Tool B count proofs ---------------------------------------------------


def test_tool_b_counts_are_phase2(tool_b_data, phase2_dispatches, phase2_copies):
"""Memory copies are deterministic (exact). Kernel dispatches are a lower bound:
RCCL all-reduce launches its own GPU kernels, so the count is the explicit kernels
plus RCCL's internal kernels."""
def test_tool_b_counts_are_phase2(
tool_b_data, phase2_dispatches, phase2_copies, copy_bytes
):
"""Tool B captured the phase 2 work: copies in bytes, dispatches as a lower
bound because RCCL all-reduce launches its own GPU kernels."""
disp = len(_buf(tool_b_data, "kernel_dispatch"))
copies = len(_buf(tool_b_data, "memory_copies"))
copied = sum(itr["bytes"] for itr in _buf(tool_b_data, "memory_copies"))
expected = phase2_copies * copy_bytes
assert disp >= phase2_dispatches, (
f"expected at least {phase2_dispatches} dispatches (phase 2 explicit kernels), "
f"got {disp}"
)
assert (
copies == phase2_copies
), f"expected {phase2_copies} memory copies (phase 2), got {copies}"
copied == expected
), f"expected {expected} bytes of memory copies (phase 2), got {copied}"


def test_tool_b_records_after_registration(tool_b_data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def pytest_addoption(parser):
default=40,
help="Memory copies issued after Tool B registered",
)
parser.addoption(
"--copy-bytes",
action="store",
type=int,
default=16 << 20,
help="Bytes moved by each copy the workload issues",
)
parser.addoption(
"--phase2-allocates",
action="store",
Expand Down Expand Up @@ -87,6 +94,11 @@ def phase2_copies(request):
return request.config.getoption("--phase2-copies")


@pytest.fixture
def copy_bytes(request):
return request.config.getoption("--copy-bytes")


@pytest.fixture
def phase2_allocates(request):
return request.config.getoption("--phase2-allocates")
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Overlap services (HSA, dispatch, memcpy, marker) must appear in BOTH tools. The
A-exclusive service (HIP) must be absent from B; the B-exclusive service (allocation)
must be absent from A. For the shared services, Tool B must capture exactly its Phase 2
share (count proof on the deterministic ones: dispatch, memcpy, allocate).
share: dispatch and allocate by count, memcpy by bytes.
"""

import sys
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_overlap_service_in_both_tools(tool_a_data, tool_b_data, key):
assert len(_buf(tool_b_data, key)) > 0, f"Tool B missing overlapping service {key}"


# ---- Tool B count proofs (deterministic services) --------------------------
# ---- Tool B phase 2 share proofs -------------------------------------------


def test_tool_b_dispatch_count_is_phase2(tool_b_data, phase2_dispatches):
Expand All @@ -104,11 +104,15 @@ def test_tool_b_dispatch_count_is_phase2(tool_b_data, phase2_dispatches):
), f"expected {phase2_dispatches} dispatches (phase 2), got {captured}"


def test_tool_b_copy_count_is_phase2(tool_b_data, phase2_copies):
captured = len(_buf(tool_b_data, "memory_copies"))
def test_tool_b_copy_volume_is_phase2(tool_b_data, phase2_copies, copy_bytes):
"""Tool B captured the phase 2 copies, measured in bytes."""
copies = _buf(tool_b_data, "memory_copies")
captured = sum(itr["bytes"] for itr in copies)
expected = phase2_copies * copy_bytes

assert (
captured == phase2_copies
), f"expected {phase2_copies} memory copies (phase 2), got {captured}"
captured == expected
), f"expected {expected} bytes of memory copies (phase 2), got {captured}"


def test_tool_b_allocate_count_is_phase2(tool_b_data, phase2_allocates):
Expand All @@ -122,7 +126,7 @@ def test_tool_b_allocate_count_is_phase2(tool_b_data, phase2_allocates):
), f"expected {phase2_allocates} allocate records (phase 2), got {len(allocates)}"


# ---- Tool B timing proof on the shared deterministic services --------------
# ---- Tool B timing proof on the shared services ----------------------------


def test_tool_b_records_after_registration(tool_b_data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ constexpr int blocks = (elements + threads - 1) / threads;
// Copy buffers are deliberately large: HIP routes tiny copies through an inline
// synchronous path that bypasses hsa_amd_memory_async_copy (so MEMORY_COPY tracing sees
// nothing). A multi-MB copy goes through the async DMA path that is traced.
// Changing this requires updating --copy-bytes in the anytime-tool-config tests.
constexpr int copy_elements = 4 * 1024 * 1024; // 16 MiB of float

struct stream_state_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ def test_hsa_api_trace(hsa_trace_input_data):

correlation_ids = sorted(list(set(correlation_ids)))

# deterministic call counts
# exact counts of calls the app issues
num_queue_create_calls = 2
num_queue_destroy_calls = 2
num_hsa_mem_free_calls = 2

# signal create/destroy calls
# although the app explicitly only creates 3 signals
# but hsa_init() internally calls hsa_signal_create
num_hsa_signal_create_calls = 4
num_hsa_signal_destroy_calls = 4
# The app creates 3 signals; ROCr adds an unspecified number. This floor does
# not cover internal-origin calls -- rocprofv3/tracing-hip-in-libraries does.
num_app_signal_calls = 3

# all correlation ids are unique
assert len(correlation_ids) == len(hsa_trace_input_data)
Expand All @@ -63,8 +61,14 @@ def test_hsa_api_trace(hsa_trace_input_data):
assert functions.count("hsa_queue_create") == num_queue_create_calls
assert functions.count("hsa_queue_destroy") == num_queue_destroy_calls
assert functions.count("hsa_memory_free") == num_hsa_mem_free_calls
assert functions.count("hsa_signal_create") == num_hsa_signal_create_calls
assert functions.count("hsa_signal_destroy") == num_hsa_signal_destroy_calls
signal_creates = functions.count("hsa_signal_create")
signal_destroys = functions.count("hsa_signal_destroy")
assert (
signal_creates == signal_destroys
), f"{signal_creates} signals created but {signal_destroys} destroyed"
assert (
signal_creates >= num_app_signal_calls
), f"{signal_creates} signals created, fewer than the app's {num_app_signal_calls}"


def test_kernel_trace(kernel_trace_input_data):
Expand Down Expand Up @@ -153,16 +157,14 @@ def get_kind_name(kind_id):

correlation_ids = sorted(list(set(correlation_ids)))

# deterministic call counts
# exact counts of calls the app issues
num_queue_create_calls = 2
num_queue_destroy_calls = 2
num_hsa_mem_free_calls = 2

# signal create/destroy calls
# although the app explicitly only creates 3 signals
# but hsa_init() internally calls hsa_signal_create
num_hsa_signal_create_calls = 4
num_hsa_signal_destroy_calls = 4
# The app creates 3 signals; ROCr adds an unspecified number. This floor does
# not cover internal-origin calls -- rocprofv3/tracing-hip-in-libraries does.
num_app_signal_calls = 3

# all correlation ids are unique
assert len(correlation_ids) == len(hsa_api_data)
Expand All @@ -172,8 +174,14 @@ def get_kind_name(kind_id):
assert functions.count("hsa_queue_create") == num_queue_create_calls
assert functions.count("hsa_queue_destroy") == num_queue_destroy_calls
assert functions.count("hsa_memory_free") == num_hsa_mem_free_calls
assert functions.count("hsa_signal_create") == num_hsa_signal_create_calls
assert functions.count("hsa_signal_destroy") == num_hsa_signal_destroy_calls
signal_creates = functions.count("hsa_signal_create")
signal_destroys = functions.count("hsa_signal_destroy")
assert (
signal_creates == signal_destroys
), f"{signal_creates} signals created but {signal_destroys} destroyed"
assert (
signal_creates >= num_app_signal_calls
), f"{signal_creates} signals created, fewer than the app's {num_app_signal_calls}"


def test_perfetto_data(pftrace_data, json_data):
Expand Down
Loading