Skip to content

Add Perfetto trace extraction and replay (clkp-extractor & clkp-runner) - #7

Merged
rjodinchr merged 6 commits into
mainfrom
replay
Oct 1, 2026
Merged

rjodinchr merged 6 commits into
mainfrom
replay

Conversation

@rjodinchr

Copy link
Copy Markdown
Collaborator

Add multi-dispatch Perfetto trace replay using Perfetto's protozero SDK:

  • Layer (layer/): Move layer source from src/ to layer/ and expand it to capture all OpenCL state required for replay (contexts, queues, programs, kernels, kernel args, buffers, images, samplers, and cl_khr_command_buffer / cl_khr_command_buffer_mutable_dispatch calls) with monotonic call_id and dispatch_id tracking.
  • Extractor (extractor/clkp-extractor): Inspect captured dispatches (--list-dispatches) and filter/window Perfetto traces (--start-dispatch/--end-dispatch, --start-call/--end-call) into self-contained .perfetto-trace files with full upstream dependency closure.
  • Runner (runner/clkp-runner): Replay multi-dispatch and cl_khr_command_buffer workloads from .perfetto-trace files (-m <warmup>, -n <iterations>, --use-command-buffer, --emulate-command-buffer, --json) and report GPU profiling timings.
  • Tests & CI: Extend tests/ and .github/workflows/presubmit.yml to build and test clkp-extractor, clkp-runner, and cl_khr_command_buffer replay.

@rjodinchr
rjodinchr force-pushed the replay branch 3 times, most recently from f969fe1 to 2073ced Compare September 29, 2026 16:23
Relocate opencl-kernel-profiler.cpp into a dedicated layer/ directory to separate the OpenCL ICD layer from the trace extractor and replay runner tools, and update CMakeLists.txt and Android.bp.example accordingly.
@rjodinchr
rjodinchr force-pushed the replay branch 2 times, most recently from cc52483 to 5099266 Compare September 30, 2026 13:25
Add shared Perfetto TrackEvent schema and protozero decoding helpers in include/clkp_common.hpp, and expand the OpenCL ICD layer to record all state required for standalone multi-dispatch replay:
- Assign monotonic call_id and dispatch_id values and synthetic handle IDs for contexts, queues, programs, kernels, memory objects, samplers, events, command buffers, and mutable commands.
- Capture context, command queue, program (source, IL, binary chunks, build/compile/link options, specialization constants), kernel creation, and clSetKernelArg bindings (classified as LOCAL, MEM, SAMPLER, or VALUE).
- Capture buffer, sub-buffer, image, and sampler creation, as well as queue transfer, map/unmap, barrier, and synchronization calls.
- Intercept cl_khr_command_buffer and cl_khr_command_buffer_mutable_dispatch extension functions via clGetExtensionFunctionAddressForPlatform and clGetExtensionFunctionAddress, including GPU execution profiling for clEnqueueCommandBufferKHR.
Implement clkp-extractor using Perfetto's protozero decoders and encoders without depending on sqlite or libtrace_processor:
- Support --list-dispatches to summarize all captured queue dispatches and command buffer executions along with their GPU execution times.
- Support full and windowed trace extraction (--start-dispatch/--end-dispatch, --start-call/--end-call) with transitive dependency closure over upstream OpenCL objects and command buffer recordings.
- Emit self-contained, de-interned .perfetto-trace files ready for replay or inspection in the Perfetto UI.
Implement clkp-runner to parse extracted or raw Perfetto traces via protozero and replay multi-dispatch and cl_khr_command_buffer workloads on OpenCL:
- Separate one-time setup (context, queues, program compilation/linking, kernels, buffers/images/samplers, and command buffer recording) from the hot-loop execution phase (-m <warmup>, -n <iterations>).
- Support native cl_khr_command_buffer and cl_khr_command_buffer_mutable_dispatch replay, command buffer promotion (--use-command-buffer), and command buffer emulation (--emulate-command-buffer).
- Collect hardware GPU profiling timestamps via clGetEventProfilingInfo and report min/avg/median/max execution times in console and JSON (--json) formats.
Update tests and GitHub Actions CI workflow:
- Add --cmdbuf CLI option to opencl-kernel-profiler-test to exercise cl_khr_command_buffer capture.
- Extend tests/test.sh to test clkp-extractor (--list-dispatches, full and windowed extraction) and clkp-runner (multi-dispatch replay, native command buffer replay, and --emulate-command-buffer).
- Update .github/workflows/presubmit.yml to build OpenCL-ICD-Loader on Android and pass OPENCL_LIBRARY_PATH on Linux and Android.
@rjodinchr
rjodinchr merged commit 5fc848a into main Oct 1, 2026
12 checks passed
@rjodinchr
rjodinchr deleted the replay branch October 1, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant