Repository navigation
OpenCL: generate from the headers through the shared generators - #564
Merged
Merged
Conversation
TApplencourt
force-pushed
the
opencl-unify
branch
3 times, most recently
from
November 9, 2026 21:20
6cae790 to
07bf2e9
Compare
TApplencourt
force-pushed
the
opencl-headers
branch
from
November 9, 2026 22:23
fd1edb7 to
b4e810a
Compare
TApplencourt
force-pushed
the
opencl-unify
branch
from
November 9, 2026 22:23
07bf2e9 to
b811e84
Compare
TApplencourt
marked this pull request as ready for review
November 9, 2026 22:38
Like every other AST-driven backend: extract/opencl_api.h includes the refreshed OpenCL headers plus opencl_missing_apis.h, and h2yaml turns them into opencl_api.yaml. Nothing consumes it yet. cl_platform.h includes the x86 intrinsic headers, and declares the vector types of cl_float4 & co., when __SSE__, __SSE2__, __MMX__ or __AVX__ is defined. A libclang without its own resource headers (the pip wheel CI installs) falls back to GCC's intrinsics and cannot parse them, and h2yaml 0.4.3 has no vector kind. No traced function takes a vector type, so the h2yaml call undefines those four macros. All 173 functions the XML path traces are in opencl_api.yaml, with the same parameter names but for one: the oneAPI cl.h calls clGetKernelArgInfo's arg_index `arg_indx`. Generated files are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preparation for moving OpenCL onto the shared, header-driven generators. No generated file changes: every addition below is off unless a backend asks for it, and none does yet. Shared features any API needs: - Typedefs of float classify as :float and trace with ctf_float. - An unsized array parameter (`T x[]`) is the pointer C decays it to. - A meta-parameter row may end in a mapping of keyword options; OutScalar takes `nocheck:`, for a pointer the tracer has already made non-NULL. - load_meta_parameters accepts an absolute path, for a generated spec. - A declared event with `start`/`stop` field lists wraps a call: it declares an entry and an exit tracepoint, like a traced function. - print_tracepoint_provider takes a `preamble` printed before lttng's own header. - get_ffi_type moves from ze_model.rb to utils/command.rb, so ze and OpenCL build their libffi closures with the same one. Per-backend settings that keep the C OpenCL generated before byte-for-byte (to be dropped in a follow-up that accepts the output change): - ApiModel `trace_as:` traces a scalar typedef as the base type its chain reaches (cl_mem_flags as cl_ulong). - BackendContext: result_field, duration, null_guard, null_test, xml_arg_spelling, legacy_blobs, pointer_type_suffix, declarations (documented where BackendContext is defined). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OpenCL was the one backend with a code generator of its own: cl.xml read with Nokogiri by a 1300-line opencl_model.rb, with its own Command, Parameter and meta-parameter classes and its own type-to-lttng mapping. It now goes the way of ze, cuda and hip: the headers through h2yaml (opencl_api.yaml), utils/command.rb's Command, utils/meta_parameters.rb, print_tracepoint_provider and print_traced_wrappers. The registry is still read, but only to produce data, by gen_opencl_xml_yaml.rb (opencl_xml.yaml): - the functions traced, in registry order, core vs. extension; - every function's meta-parameter rows: the ones OpenCL's naming implies (event_wait_list, errcode_ret, param_value ...), the hand-written ones, and the queried param_name of clGet*Info; - the declarations as the registry writes them, which the wrappers repeat; - the enum/bitfield groups, typedef map and struct list opencl_model.yaml carries for the babeltrace model and the pretty-printer. It also checks that the headers declare every traced function, with as many parameters. The tracepoints keep the registry's parameter names (opencl_model.rb renames the AST's): the oneAPI cl.h calls clGetKernelArgInfo's arg_index `arg_indx`. The registry rules of the header update (#565) move with the rest: functions only experimental extensions require are not traced; the clIcd*KHR and layer functions, and supported_extensions.yaml's, are not looked up at load; PoCL is a vendor suffix; cl_semaphore_khr is a handle (its result field is `semaphore`). OpenCL keeps spelling a C int `ffi_type_sint` and an empty parameter list `(void)`. opencl_meta_parameters.yaml spells out two things the old classes implied: the `num_entries` size of four arrays, and clCreateSubBuffer's buffer_create_info blob (an InLTTng row). opencl_model.rb keeps what is OpenCL's own: its BackendContext settings, the device-fission property list, and the prologues/epilogues (dump, profiling, source capture, extension-function dispatch ...), unchanged. Generated files are identical. Checked against origin/devel: every generated file and exported symbol of every backend; make check; and iprof pretty-print and tally of real OpenCL and SYCL-on-OpenCL traces. CommandIndex no longer needs `pointer_name_of`, which existed for the old OpenCL Command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gen_opencl_xml_yaml.rb: - The traced lists are list operations, not regexes built from the lists. - `spelled` loses its `strip:` option: it kept the trailing space of the one `void` parameter cl.xml no longer has. - A supported_enums.yaml type that no <require comment> names stops the generator with a message. The XML generator crashed on it; the new one gave the type no values, silently. README: point at where the code now lives (gen_opencl_xml_yaml.rb, opencl_result_field, with_registry_names) and at the errors gen_opencl_xml_yaml.rb raises; list CL_HDR_ROOT in the header steps. Drop the `ffi_type_...` problem: the libffi types now come from the shared map and the headers, as do the handles (CL_OBJECTS only feeds opencl_model.yaml). Correct what the cl_affinity_domain_ext typedef hunk does: without it, nothing crashes, type_map just lacks the entry. Generated files are identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TApplencourt
force-pushed
the
opencl-unify
branch
from
November 13, 2026 18:45
bc8c0cb to
a9533fd
Compare
ApiModel's `trace_as` walked each typedef chain in the AST to find the cl_* (or C) base type OpenCL records a scalar under (cl_mem_flags as cl_ulong). gen_opencl_xml_yaml.rb already writes that mapping from the registry (`type_map`): for every typedef both know, the two agree, and the registry also covers types the parsed headers do not declare (beta, Windows, layer). ApiModel now takes the map itself (`trace_names:`), and find_trace_names goes. Generated files are identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The meta-parameter rows OpenCL's naming conventions imply (event_wait_list, errcode_ret, param_value_size_ret, param_value, event, and the queried param_name of clGet*Info) were computed from the registry by gen_opencl_xml_yaml.rb and read back as a generated spec. They depend on the prologues of opencl_model.rb: errcode_ret and param_value_size_ret skip their NULL check only because a prologue points them at a local. They are now computed there, from the same AST the prologues read, and opencl_xml.yaml only carries what the registry says. Two utils changes made only to read that generated spec go back to devel's code: load_meta_parameters takes a path under SRC_DIR again, and no longer parses a trailing mapping of keyword options (the hand-written specs never use one). Generated files are identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gen_opencl.rb and gen_opencl_probes.rb now require utils/gen_tracer_base.rb and utils/gen_probe_base.rb, but tracer_opencl.c and opencl_tracepoints.tp did not depend on them, as they do in every other backend: an edit to either left OpenCL's generated files stale. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ze (zeDriverGetExtensionFunctionAddress) and OpenCL (clGetExtensionFunctionAddress[ForPlatform]) hand out extension functions that no library exports, and each driver returns its own: the tracer wraps each real pointer in a libffi closure calling its `<command>_ffi` wrapper, cached by pointer. Both models carried the same ~35-line C template for it; now that both build their commands with utils/command.rb, it is one function there, ffi_closure_epilogue, next to get_ffi_type. The callers only say what differs: the lookup's provider and name variable, the closure prefix, where the real pointer is, and how the lookup returns. Generated files are identical (every backend). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kups - CL_OBJECTS repeated what the registry and the headers say: the handles are the registry's pointer typedefs (`struct _cl_foo *`, `void *`) that the headers declare. The list stays, in the order opencl_model.yaml has it, but gen_opencl_xml_yaml.rb now stops when it is not exactly those, so a new handle can no longer be missed. The registry's `*`-before-<name> test is one function, also used for parameters. - supported_extensions.yaml: a name cl.xml does not have stops the generator instead of being dropped silently. - "Takes a pointer named x" was computed twice in opencl_model.rb: for the `nocheck` meta-parameters and for the prologues that make them safe. One pointer_parameter? now serves both. - The two "named like an extension" selections (handed back by clGetExtensionFunctionAddress; looked up with it at load) sit together in opencl_model.rb instead of in two files. Generated files are identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
OpenCL was the one backend with its own code generator:
cl.xmlread with Nokogiri by a 1349-lineopencl_model.rb, with its own Command/Parameter/meta-parameter classes and type mapping. It now uses the same path as ze, cuda and hip:opencl_api.yaml;Command, meta-parameters,print_tracepoint_providerandprint_traced_wrappersgenerate the code.cl.xmlis still read, but only to produce data.gen_opencl_xml_yaml.rbwritesopencl_xml.yaml:clIcd*/layer functions, PoCL as a vendor suffix);It also checks that the headers declare every traced function with as many parameters. The tracepoints keep the registry's parameter names: the oneAPI
cl.hcallsclGetKernelArgInfo'sarg_indexarg_indx, soopencl_model.rbrenames it.Commits
opencl: parse the headers with h2yaml into opencl_api.yaml. The h2yaml call undefines__SSE__/__SSE2__/__MMX__/__AVX__: the pip libclang can't parse GCC's intrinsic headers, and no traced function takes a vector type.utils: let the shared generators say what OpenCL's output says: shared features plus per-backend spelling settings, documented onBackendContext. No output change.opencl: generate from the headers, through the shared generators:opencl_model.rbgoes from 1349 lines to 634, and the old XML model and generators are deleted.opencl: simpler traced-function lists; README for the h2yaml path: review pass. List operations instead of regexes built from lists; asupported_enums.yamltype that no<require comment>names now stops the generator (the old one crashed, the new one silently gave it no values);backends/opencl/README.mdpoints at where the code now lives.utils: take OpenCL's traced scalar names from the registry, not the AST:gen_opencl_xml_yaml.rbalready writes the typedef → base-type map (type_map), and it agrees with the AST walk on every typedef both know, soApiModeltakes that map andfind_trace_namesgoes.opencl: compute the implied meta-parameters next to the prologues: the rows OpenCL's naming implies (errcode_ret,event, …) are computed inopencl_model.rbfrom the AST, next to the prologues they depend on, instead of ingen_opencl_xml_yaml.rb.opencl_xml.yamlonly carries registry facts, andload_meta_parametersgoes back to devel's code.opencl: rebuild the tracer and probes when the shared generators change:tracer_opencl.candopencl_tracepoints.tpnow depend onutils/gen_tracer_base.rb/utils/gen_probe_base.rb, like every other backend.utils: one libffi closure generator for ze and OpenCL: both backends wrap the extension functions a driver hands out in a libffi closure, with the same ~35-line C template; it is nowffi_closure_epilogueinutils/command.rb(−26 lines overall, generated files identical for every backend).opencl: one source for handles, pointer parameters, and extension lookups:CL_OBJECTSis checked against the registry's pointer typedefs the headers declare (a new handle stops the build instead of being missed); asupported_extensions.yamlname unknown to cl.xml stops the generator; onepointer_parameter?serves both thenocheckmeta-parameters and the prologues that justify them.Generated output
Identical to
devel: every generated file and every exported symbol of every backend (utils/test_compare_generated_*.py, 59/59).Also checked locally (sunspot):
make checkinbackends/opencl(10/10);-t) and tally of real OpenCL and SYCL-on-OpenCL traces, replayed with this branch and withdevel: identical._param_namein the babeltrace model (#570, merged into this branch before) is no longer here: it changesopencl_model.yamlandbtx_cl_model.yaml. It will come back as its own PR after this one.Follow-up (separate PR)
Remove the per-backend spelling settings and the registry declarations, move the reading side (
opencl_model.yaml→ btx model, Ruby pretty-printer) ontoprint_bt_modeland a generated library, and accept the resulting output diffs.🤖 Generated with Claude Code