Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -1647,6 +1647,15 @@ get_device_counting_service(rocprofiler_agent_id_t agent_id)
// still carries.
thread_local auto tl_current_replay_pass = std::optional<uint64_t>{};

// The kernel iteration filter (--kernel-iteration-range) counts iterations per kernel, advancing
// the count on every call. Replay dispatches the same kernel once per pass, so consulting the
// filter on each pass would charge one user-visible launch several iterations and drop every pass
// after the range is exhausted -- the first pass would be collected and the rest silently skipped.
// The decision therefore belongs to the dispatch, not the pass: pass 0 consults the filter and the
// remaining passes of that dispatch reuse the answer recorded here. Passes run synchronously and in
// order on the enqueuing thread, so a thread-local is sufficient.
thread_local auto tl_replay_dispatch_targeted = std::optional<bool>{};

// The two 32-bit fields that share the single 64-bit user_data slot: the enqueuing thread id (a
// Linux tid, i.e. 32-bit pid_t) and the replay pass index. Modeled as a struct so pack/unpack is a
// plain field access instead of hand-rolled shifts and masks. The width of each field is asserted
Expand Down Expand Up @@ -2011,7 +2020,17 @@ counter_dispatch_callback(rocprofiler_dispatch_counting_service_data_t dispatch_
auto kernel_id = dispatch_data.dispatch_info.kernel_id;
auto agent_id = dispatch_data.dispatch_info.agent_id;

if(!is_targeted_kernel(kernel_id, kernel_iteration))
// Ask the iteration filter once per dispatch rather than once per pass. Inside a replay loop
// only pass 0 consults it (which advances the kernel's iteration count by one, matching the
// single launch the application made); later passes reuse that answer so the filter cannot
// reject them and leave their counter groups uncollected.
const auto in_later_replay_pass =
Comment thread
amd-vkale marked this conversation as resolved.
Resolved
tl_current_replay_pass.value_or(0) > 0 && tl_replay_dispatch_targeted.has_value();
const auto is_target = in_later_replay_pass ? *tl_replay_dispatch_targeted
: is_targeted_kernel(kernel_id, kernel_iteration);
if(tl_current_replay_pass.has_value()) tl_replay_dispatch_targeted = is_target;

if(!is_target)
{
return;
}
Expand Down Expand Up @@ -2544,6 +2563,9 @@ kernel_replay_callback(rocprofiler_callback_tracing_record_t record,
{
// Tell the SDK how many passes to run for this dispatch (= counter groups for its agent).
payload->replay_pass_count = kernel_replay_pass_count_callback;
// A new replay loop begins here, so the previous dispatch's iteration-filter decision must
// not carry into it; pass 0 below will record a fresh one.
tl_replay_dispatch_targeted.reset();
}
else if(record.operation == ROCPROFILER_KERNEL_REPLAY_PASS)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,61 @@ set_tests_properties(
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")

# Regression test for AIPROFSDK-1130: --kernel-iteration-range selects logical launches,
# so replay passes must not consume iterations. With four launches, range 2-3, and two
# counter groups, exactly two logical dispatches must survive and each must carry passes
# [0, 1]. This exercises rejecting launch 1, accepting launches 2 and 3, rejecting launch
# 4, and resetting the cached decision between dispatches.
add_test(
NAME rocprofv3-test-kernel-replay-iteration-range-generate
COMMAND
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --pmc SQ_WAVES SQ_INSTS_VALU GRBM_COUNT
--pmc SQ_WAVES SQ_INSTS_VALU GRBM_GUI_ACTIVE --replay-mode kernel
--kernel-replay-beta-enabled --kernel-include-regex saxpy
--kernel-iteration-range "2-3" --output-format json -d
${CMAKE_CURRENT_BINARY_DIR}/kernel-replay-iteration-range -o out --
$<TARGET_FILE:kernel-replay> 65536 4)

set_tests_properties(
rocprofv3-test-kernel-replay-iteration-range-generate
PROPERTIES TIMEOUT
120
LABELS
"integration-tests;kernel-replay"
ENVIRONMENT
"${rocprofv3-generate-env}"
RESOURCE_LOCK
rocprofiler_kernel_replay
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}"
FIXTURES_SETUP
rocprofv3-test-kernel-replay-iteration-range-data)

# Validate the exact ticket invariant: two selected logical dispatches, each carrying two
# distinct counter-group passes. Numeric dispatch IDs are deliberately not pinned.
add_test(
NAME rocprofv3-test-kernel-replay-iteration-range-validate
COMMAND
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --json-input
${CMAKE_CURRENT_BINARY_DIR}/kernel-replay-iteration-range/out_results.json
--passes 2 --expected-dispatch-count 2 --common-counters SQ_WAVES SQ_INSTS_VALU
-k
"dispatch_id_constant_across_replay_passes or expected_logical_dispatch_count or each_pass_collects_distinct_batch"
)

set_tests_properties(
rocprofv3-test-kernel-replay-iteration-range-validate
PROPERTIES TIMEOUT
120
LABELS
"integration-tests;kernel-replay"
ENVIRONMENT
"${rocprofv3-validate-env}"
FIXTURES_REQUIRED
rocprofv3-test-kernel-replay-iteration-range-data
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")

# One-pass baseline for performance scaling checks (same workload, single --pmc group).
add_test(
NAME rocprofv3-test-kernel-replay-baseline-generate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def pytest_addoption(parser):
default=["SQ_WAVES", "SQ_INSTS_VALU"],
help="counters shared by every --pmc group; must be constant across a kernel's passes",
)
parser.addoption(
"--expected-dispatch-count",
action="store",
type=int,
default=None,
help="optional exact number of logical dispatches expected in the counter records",
)


@pytest.fixture
Expand All @@ -62,6 +69,11 @@ def expected_passes(request):
return request.config.getoption("--passes")


@pytest.fixture
def expected_dispatch_count(request):
return request.config.getoption("--expected-dispatch-count")


@pytest.fixture
def common_counters(request):
return list(request.config.getoption("--common-counters"))
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ def test_dispatch_id_constant_across_replay_passes(json_data, expected_passes):
)


def test_expected_logical_dispatch_count(json_data, expected_dispatch_count):
if expected_dispatch_count is None:
pytest.skip("--expected-dispatch-count was not specified")

table = _dispatch_passes(_sdk(json_data))
assert len(table) == expected_dispatch_count, (
f"expected {expected_dispatch_count} selected logical dispatches, found {len(table)}: "
f"dispatch_ids={sorted(table)}"
)


def test_dispatch_ids_increment_sequentially(json_data):
# Across distinct dispatches the dispatch_id increments sequentially -- one fresh id per logical
# dispatch, none skipped, none reused. Replay passes reuse their dispatch's reserved id (they
Expand Down
Loading