Skip to content

OpenCL: remove the OpenCL-only generator paths, share the readers and the tracer helpers - #575

Open
TApplencourt wants to merge 20 commits into
develfrom
opencl-simplify
Open

TApplencourt wants to merge 20 commits into
develfrom
opencl-simplify

Conversation

@TApplencourt

@TApplencourt TApplencourt commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up of #564. That PR moved OpenCL onto the shared generators without changing a generated file. This one removes what it kept only for that, and puts the reading side (babeltrace model, Ruby printer) on the shared generators too. The generated files change; what is traced does not, except where listed below.

56 files, +715 −1533.

What changes

OpenCL-only settings removed from the shared generators. The NULL-check, argument and declaration spellings, the traced type names, the tracepoint preamble, the libffi int override and the legacy blob rule are gone: the generated C reads like the other backends'. result_field became result_name accepting a callable. _duration and the --host-profile option of tracer_opencl.sh are removed (see below). Only pointer_type_suffix is left, and it is needed: cl_ext.h and cl_egl.h declare <function>_t.

Reading side on the shared generators.

  • btx_cl_model.yaml comes from print_bt_model.
  • cl_library.rb and babeltrace_opencl_lib.rb are generated. The hand-written printer, opencl_model.yaml and its generator are deleted.
  • What only OpenCL has is in babeltrace_opencl_values.rb (device-partition property lists, what a clGet*Info call returned), called through a render: hook of print_babeltrace_lib.
  • gen_opencl_xml_yaml.rb now gives only the traced functions and the enum groups. Four hunks of cl.xml.patch that no longer change anything are dropped.

Shared C, in utils/include.

  • function_pointer_utils.h: the libffi closure struct, hash and mutex that ze and opencl each kept, plus thapi_closure_for(). The generated lookup epilogue is one call per extension function (tracer_opencl.c is 2100 lines shorter).
  • tracer_init_utils.h: opening the real library and the run-once guard, which hip, mpi, cuda, cudart, opencl and ze each carried.

ze. One gen_ze_tracepoints.rb replaces the twelve per-namespace generators. The .tp files are identical.

Visible changes

  • OpenCL pretty output takes the shared format (braces, zero-padded hex). It names what it named before: error codes, enums, flags, partition lists, info values. The properties pointer is in hex instead of decimal. The exits of clGet*Info show _param_name, the key they answered (this is opencl: keep _param_name in the babeltrace model #570, which this PR replaces).
  • clGetKernelArgInfo records arg_indx, the header's name; it was arg_index, the registry's.
  • clGetSupportedImageFormats: image_formats_vals holds num_entries structs; it held num_entries bytes.
  • Void blobs have the media type x86-64/uint8_t instead of application/octet-stream.
  • ze, cuda, hip and omp printers name the elements of an array of enums or flags, and read a composite flag back by its name. Their babeltrace models name the class of those arrays (be_class: ze 2 fields, hip 2, omp 1, cuda 15); before, only a single enum or flag was named and an array printed as numbers.
  • When the real library cannot be loaded, every tracer prints THAPI: Failure: could not load <name> library! on stderr. OpenCL printed it on stdout; hip, cudart and ze without the prefix.
  • _duration is gone from the OpenCL exit events, with tracer_opencl.sh -h/--host-profile and LTTNG_UST_OPENCL_HOST_PROFILE. It timed the real call alone (2020); iprof never set the option, so the field was always 0 there, and nothing reads it: the interval plugin takes exit minus entry, like the other backends.
  • opencl_ruby_ffi is no longer needed (README, CI).

Checks (against devel 042fb3e)

  • make check: opencl 10/10, ze 9/9.
  • OpenCL, 11 apps on the CPU runtime and 6 on a GPU node, old and new tracer: same event sequences. The pretty output compared modulo format carries the same information.
  • Replay of 6 recorded traces: same information, same tally.
  • clinfo under both tracers (406 OpenCL events, every clGet*Info): same information; the new printer also decodes cl_version and capability values that were printed as bytes.
  • Every generated OpenCL event printer called with synthetic payloads (386 printers, 7240 calls): no error.
  • ze, SYCL app on a GPU node: same 1478 events, same tally.
  • MPI, small program under iprof -b mpi: same events.
  • hip, cuda, cudart: compiled, not run.
  • After the last four commits (5caf199: _duration removed, info lookup by key value): make check, the 6 replays, the 11 apps and clinfo on the CPU runtime, and the printer fuzzer were run again. The GPU-node and MPI runs above are from before them.
  • No zex function was called through a closure in the ze runs; the OpenCL apps exercise the same closure code.
  • The mpi and itt babeltrace models are byte-identical; ze, cuda, hip and omp differ only by the be_class of their enum arrays (above).

"Assert generated files are equivalent" fails by design: the workflow builds the same target list in both trees, and it now names cl_library.rb, which devel does not have (it named opencl_model.yaml, deleted here). It runs again once this is merged.

🤖 Generated with Claude Code

TApplencourt and others added 20 commits November 13, 2026 22:00
The NULL-check, tracepoint-argument and declaration spellings, the traced
type names, the tracepoint preamble and the libffi int override were kept
by #564 so that it changed no generated file. The generated C now reads
like the other backends: same events, same fields.

clGetKernelArgInfo records its index as arg_indx, the name the header
gives it (the registry says arg_index).

The libffi wrappers ze and opencl print are one helper.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
OpenCL kept its own blob rule so that #564 changed no generated file: a
void array was an octet-stream blob, a pointed-to struct was cast to
uint8_t *, and an array of structs was a blob as long as its element
count. The shared rule records the same bytes for the first two, and all
the bytes of the third: clGetSupportedImageFormats recorded num_entries
bytes of image_formats, it now records num_entries structs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
print_bt_model replaces OpenCL own model generator. For that the shared
helper learns what OpenCL events have: ctf_enum fields, hand-written
events with an entry and an exit, a result field named by the backend,
and literal rows on by-value parameters (_param_name, #570).

The headers #define the values of the enums, so OpenCLApi takes the enum
and flag types from the registry groups. The model now names the class of
each enum and flag field, records pointers as unsigned, and keeps
_param_name in the clGet*Info exits.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
cl_library.rb and babeltrace_opencl_lib.rb are generated by the shared
library and printer generators; the hand-written printer and
opencl_model.yaml, the file it read, are gone. The enum and flag classes
come from the registry groups, the structs from the headers.

What only OpenCL has stays in babeltrace_opencl_values.rb and a render
hook: device-partition property lists, and what a clGet*Info call
returned, read as opencl_infos.yaml says.

The output takes the shared format (braces, padded hex). It names what it
named before: error codes, enums, flags, partition lists, info values.
Pointers the old printer showed in decimal are now in hex, and the exits
of clGet*Info show the key they answered.

For that the shared generators name the elements of an array of enums or
flags, and a bitmask reads a composite flag back by its name
(CL_DEVICE_TYPE_ALL). Both show in ze, cuda, hip and omp output too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…m groups

The type map, the struct, scalar and handle lists and the CL_OBJECTS check
only fed opencl_model.yaml: the readers now take them from the headers.
cl_bool is a line of supported_enums.yaml like the other types, and the
command-execution-status group, which nothing read, is gone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The registry converter no longer reads the types, so the two typedef
hunks change nothing; neither do two of the bitfield comments. Found by
dropping each hunk in turn: opencl_xml.yaml is identical.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Both tracers kept the same closure struct, hash and mutex, and the
generated lookup epilogue repeated the same forty lines of libffi calls
for every extension function. function_pointer_utils.h has them once:
thapi_closure_for() finds or makes the closure of a real pointer, under
one lock. The generated epilogue is a call to it per function
(tracer_opencl.c: 2100 lines shorter).

cuda carried a commented-out copy of the struct; removed. The opencl and
cuda helpers are clang-formatted since they are touched.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
result_field: result_name is one name for the API or a callable naming
each command result, which is what OpenCL needs.

duration: _duration is a tracer-filled parameter and a literal field, like
any other (HostDuration, in opencl_model.rb), with the clock started by
the last prologue. The shared generators no longer know about it. The
events are laid out as before; the babeltrace model now lists _duration,
which the trace always had, so the test inputs carry it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The twelve gen_<namespace>[_structs]_tracepoints.rb differed by the
namespace alone. gen_ze_tracepoints.rb takes it from the name of the file
the build asks for. The generated .tp files are identical.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
hip, mpi, cuda, cudart, opencl and ze each carried the same code to open
the real library (the path from an environment variable, the check that
dlopen did not hand the tracer back, the exit when there is none) and the
same run-once guard around it. tracer_init_utils.h has both:
thapi_dlopen_real() and THAPI_INIT_ONCE().

The failure message is now the same for all, on stderr:
"THAPI: Failure: could not load <name> library!" (opencl printed it on
stdout, hip, cudart and ze without the prefix).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…cl_model.yaml

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…me-version structs

The printer named the class of the key of every clGet*Info call, but
clGetICDLoaderInfoOCLICD has a key (cl_icdl_info) the registry gives no
enum for: uninitialized constant CL::IcdlInfo, found by the integration
test (clinfo). Such a value is printed as bytes, as before this branch.

cl_name_version structs print their version as major.minor.patch again
(the hand-written printer got that from opencl_ruby_ffi).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
_duration timed the real call alone (tracer_opencl.sh -h, 2020). iprof
never set the option, so the field was always 0 there, and nothing reads
it: the interval plugin takes exit minus entry, like the other backends.

Gone with it: HostDuration and the prologue that had to stay the last
one, do_host_profile, LTTNG_UST_OPENCL_HOST_PROFILE, and the field in the
test inputs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… its key

The key was looked up by the name its value reads back as, and the
registry gives some keys two names: clGetKernelSubGroupInfo values were
printed as bytes (the infos list CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE,
the value reads back as ..._KHR).

Also:
- uintptr_t values (SVM and USM pointers) are in hex again.
- a set of flags is "[ A, B ]" everywhere.
- the keys of a partition list that take a list of values come from the
  table the tracer walks the list with, through cl_library.rb.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- print_bt_model takes several declared-event files, so OpenCL does not
  pass a callable for its second one; a declared event is one event class
  or one per phase through the same code.
- one expression names an enum or a set of flags, for a field and for an
  array of them.
- a by-value parameter is told by its type, not by respond_to?.
- two comments back on the code they describe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
README: the host-profile option, opencl_ruby_ffi (nothing requires it
anymore, CI does not install it), opencl_result_name. .gitignore: the two
generated readers instead of opencl_model.yaml.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The babeltrace2 gem built from the branch is installed with --local and
needs ffi, which came in only as a dependency of opencl_ruby_ffi.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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