Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,63 @@ set_tests_properties(
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")

# Regression test: --kernel-iteration-range selects host-observed launches, so replay
# passes must not consume iterations. The filter advances a per-kernel counter on every
# consultation; consulting it once per pass instead of once per dispatch charged a single
# launch N iterations, so with a range of [1] the first pass was collected and the
# remaining N-1 were rejected and silently dropped. The dispatches that survive the filter
# must still carry all REPLAY_PASSES passes.
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 --pmc SQ_WAVES SQ_INSTS_VALU
SQ_INSTS_SALU --pmc SQ_WAVES SQ_INSTS_VALU SQ_INSTS_SMEM --pmc SQ_WAVES
SQ_INSTS_VALU SQ_INSTS_LDS --replay-mode kernel --kernel-replay-beta-enabled
--kernel-iteration-range "[1]" --output-format csv json -d
Comment thread
MythreyaK marked this conversation as resolved.
Resolved
${CMAKE_CURRENT_BINARY_DIR}/kernel-replay-iteration-range -o out --
$<TARGET_FILE:kernel-replay> 1048576 1)

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)

# Filtering to iteration [1] deliberately skips the later launches of a kernel, so the
# contiguous dispatch-id run the unfiltered validation asserts does not hold here and is
# the one check deselected. Everything else, including the pass-completeness assertion
# this test exists for, applies unchanged.
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 ${REPLAY_PASSES} --common-counters SQ_WAVES SQ_INSTS_VALU -k
"not dispatch_ids_increment_sequentially")

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
Loading