Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
80a4026
opencl: unify tracepoint printing with shared utils/LTTng.rb
TApplencourt Jul 29, 2026
d72ce2a
test: add opencl_tracepoints.tp to generated-file comparison oracle
TApplencourt Jul 29, 2026
bfa9652
test: guard all opencl generated files in comparison oracle
TApplencourt Jul 29, 2026
2050fe9
utils: introduce TypeRegistry value object, keep global instance
TApplencourt Jul 29, 2026
c6752a5
utils: gen_bt_field_model(registry, ...) reads from TypeRegistry
TApplencourt Jul 29, 2026
0c2160d
babeltrace-model: thread TypeRegistry explicitly, drop load-time glob…
TApplencourt Jul 29, 2026
cadbe79
opencl: drop fake AST globals that only fed the helper's deleted load…
TApplencourt Jul 29, 2026
b8da260
opencl: document why parse_field stays separate from shared helper
TApplencourt Jul 30, 2026
6511b99
babeltrace-model: assert per-backend bitfield invariant; note remaini…
TApplencourt Jul 30, 2026
f9cc819
gen: delete dead code (unused to_snake_case dups, dead flag, commente…
TApplencourt Jul 30, 2026
cc77d75
opencl: remove permanently-empty ENUM lookup tables and their dead re…
TApplencourt Jul 30, 2026
c8d3510
gen: extract shared classify_ast_types, collapse 6 per-backend loops
TApplencourt Jul 30, 2026
c888bac
Dedup meta-parameter YAML loading into load_meta_parameters helper
TApplencourt Jul 30, 2026
bd19b7f
Dedup upper_snake_case into utils/LTTng.rb
TApplencourt Jul 30, 2026
37a5a4b
babeltrace-model: fold TypeRegistry construction into build_ast_registry
TApplencourt Jul 30, 2026
fb7826a
babeltrace-model: fold command/extra event loops into shared helpers
TApplencourt Jul 30, 2026
5c87e29
gen: extract find_objects / find_int_scalars from library-base files
TApplencourt Jul 30, 2026
c681786
gen: hoist shared Handle/UUID modules into gen_library_base
TApplencourt Aug 10, 2026
443d6cd
gen: call print_object directly, drop the per-backend aliases
TApplencourt Aug 10, 2026
faa47f5
gen: call the *_with_namespace helpers directly, drop namespace aliases
TApplencourt Aug 10, 2026
555d417
gen: inline the cuda/hip/mpi print_enum namespace aliases
TApplencourt Aug 10, 2026
c414c28
gen: share the UUID-prepending struct printer between cuda and hip
TApplencourt Aug 10, 2026
b180ae2
lint: satisfy rubocop on the files this branch touches
TApplencourt Aug 10, 2026
047ef11
gitignore: ignore __pycache__
TApplencourt Aug 10, 2026
005ea93
ci: build the opencl model yamls the oracle compares
TApplencourt Aug 10, 2026
44e9396
gen: fail loudly when a meta-parameter YAML has no meta_parameters key
TApplencourt Aug 10, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
make -C backends/cuda tracer_cuda.c cuda_library.rb btx_cuda_model.yaml libcuda.la
make -C backends/cuda tracer_cudart.c libcudart.la
make -C backends/ze tracer_ze.c ze_library.rb btx_ze_model.yaml libze_loader.la
make -C backends/opencl libOpenCL.la
make -C backends/opencl opencl_model.yaml btx_cl_model.yaml libOpenCL.la
make -C backends/cxi cxi_sampling.tp
make -C backends/itt tracer_itt.c itt_library.rb btx_itt_model.yaml libittnotify.la
make -C backends/opencl opencl_profiling.tp
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ m4
aclocal.m4
configure
Makefile.in
__pycache__
18 changes: 2 additions & 16 deletions backends/cuda/cuda_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,8 @@ def initialize(command, name)
end
end

$cuda_meta_parameters = YAML.load_file(File.join(SRC_DIR, 'cuda_meta_parameters.yaml'))
$cuda_meta_parameters['meta_parameters'].each do |func, list|
list.each do |type, *args|
register_meta_parameter func, Kernel.const_get(type), *args
end
end
$cuda_exports_meta_parameters = YAML.load_file(File.join(SRC_DIR, 'cuda_exports_meta_parameters.yaml'))
$cuda_exports_meta_parameters['meta_parameters'].each do |func, list|
list.each do |type, *args|
register_meta_parameter func, Kernel.const_get(type), *args
end
end
load_meta_parameters('cuda_meta_parameters.yaml')
load_meta_parameters('cuda_exports_meta_parameters.yaml')

$cuda_commands = cuda_funcs_e.collect do |func|
Command.new(func)
Expand All @@ -102,10 +92,6 @@ def initialize(command, name)
Command.new(func)
end

def upper_snake_case(str)
str.gsub(/([A-Z][A-Z0-9]*)/, '_\1').upcase
end

CUDA_POINTER_NAMES = ($cuda_commands +
$cuda_exports_commands).collect do |c|
[c, upper_snake_case(c.pointer_name)]
Expand Down
11 changes: 1 addition & 10 deletions backends/cuda/cudart_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,12 @@
# Currently ignored by gen_cudart.rb
INIT_FUNCTIONS = /.*/

$cudart_meta_parameters = YAML.load_file(File.join(SRC_DIR, 'cudart_meta_parameters.yaml'))
$cudart_meta_parameters['meta_parameters'].each do |func, list|
list.each do |type, *args|
register_meta_parameter func, Kernel.const_get(type), *args
end
end
load_meta_parameters('cudart_meta_parameters.yaml')

$cudart_commands = funcs.collect do |func|
Command.new(func)
end

def upper_snake_case(str)
str.gsub(/([A-Z][A-Z0-9]*)/, '_\1').upcase
end

CUDART_POINTER_NAMES = $cudart_commands.collect do |c|
[c, upper_snake_case(c.pointer_name)]
end.to_h
19 changes: 5 additions & 14 deletions backends/cuda/gen_babeltrace_cuda_model.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
require_relative 'gen_cuda_library_base'
require_relative '../../utils/gen_babeltrace_model_helper'

event_classes =
[[:lttng_ust_cuda, $cuda_commands],
[:lttng_ust_cuda_exports, $cuda_exports_commands]].collect do |provider, commands|
commands.collect do |c|
[gen_event_bt_model(provider, c, :start),
gen_event_bt_model(provider, c, :stop)]
end
end.flatten(2)
registry = build_ast_registry('cuda', expect_bitfields: false)

cuda_events = YAML.load_file(File.join(SRC_DIR, 'cuda_events.yaml'))
event_classes += cuda_events.collect do |provider, es|
es['events'].collect do |event|
gen_extra_event_bt_model(provider, event)
end
end.flatten
event_classes = gen_command_events_bt_model(registry,
[[:lttng_ust_cuda, $cuda_commands],
[:lttng_ust_cuda_exports, $cuda_exports_commands]])
event_classes += gen_extra_events_bt_model(registry, 'cuda_events.yaml')

puts YAML.dump(gen_yaml(event_classes, 'cuda'))
95 changes: 0 additions & 95 deletions backends/cuda/gen_cuda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

static void _init_tracer(void);
EOF
# puts <<EOF
# #include <ffi.h>
# EOF

($cuda_commands + $cuda_exports_commands).each do |c|
puts "#define #{CUDA_POINTER_NAMES[c]} #{c.pointer_name}"
Expand Down Expand Up @@ -65,9 +62,6 @@
#{c.decl_hidden_alias};
static void wrap_#{c.name}(void **pfn);
EOF
# puts <<EOF
# static #{c.decl_ffi_wrapper};
# EOF
end

puts <<~EOF
Expand Down Expand Up @@ -197,30 +191,6 @@
end

$cuda_commands.each do |c|
# puts <<EOF
# static #{c.decl_ffi_wrapper} {
# (void)cif;
# EOF
# if c.parameters.size == 0
# puts <<EOF
# (void)args;
# EOF
# else
# c.parameters.each_with_index { |p, i|
# puts <<EOF
# #{p} = *(#{p.type} *)args[#{i}];
# EOF
# }
# end
# common_block.call(c, :lttng_ust_cuda)
# if c.has_return_type?
# puts <<EOF
# *(#{c.type} *)ffi_ret = _retval;
# EOF
# end
# puts <<EOF
# }
# EOF
puts <<~EOF

static void wrap_#{c.name}(void **pfn) {
Expand All @@ -230,71 +200,6 @@
*pfn = #{c.hidden_alias_name};
}
EOF
# begin
# str << <<EOF
# struct cuda_closure *closure = NULL;
# pthread_mutex_lock(&cuda_closures_mutex);
# HASH_FIND_PTR(cuda_closures, pfn, closure);
# pthread_mutex_unlock(&cuda_closures_mutex);
# if (closure != NULL) {
# *pfn = closure->c_ptr;
# } else {
# closure = (struct cuda_closure *)malloc(sizeof(struct cuda_closure) + #{c.parameters.size} * sizeof(ffi_type *));
# if (closure != NULL) {
# closure->types = (ffi_type **)((intptr_t)closure + sizeof(struct cuda_closure));
# closure->closure = ffi_closure_alloc(sizeof(ffi_closure), &(closure->c_ptr));
# if (closure->closure != NULL) {
# closure->ptr = *pfn;
# EOF
# c.parameters.each_with_index { |a, i|
# if a.type.kind_of?(YAMLCAst::Pointer)
# ffi_type = "ffi_type_pointer"
# elsif FFI_TYPE_MAP["#{a.type}"]
# ffi_type = FFI_TYPE_MAP["#{a.type}"]
# else
# raise "Unsupported type: #{a.type}"
# end
# str << <<EOF
# closure->types[#{i}] = &#{ffi_type};
# EOF
# }
# if c.type.kind_of?(YAMLCAst::Void)
# ffi_ret_type = "ffi_type_void"
# elsif c.type.kind_of?(YAMLCAst::Pointer)
# ffi_ret_type = "ffi_type_pointer"
# elsif FFI_TYPE_MAP["#{c.type}"]
# ffi_ret_type = FFI_TYPE_MAP["#{c.type}"]
# else
# raise "Unsupported type: #{c.type}"
# end
# str << <<EOF
# if (ffi_prep_cif(&(closure->cif), FFI_DEFAULT_ABI, #{c.parameters.size}, &#{ffi_ret_type}, closure->types) == FFI_OK) {
# if (ffi_prep_closure_loc(closure->closure, &(closure->cif), (void (*)(ffi_cif*, void *, void **, void *))#{c.ffi_name}, *pfn, closure->c_ptr) == FFI_OK) {
# pthread_mutex_lock(&cuda_closures_mutex);
# HASH_ADD_PTR(cuda_closures, ptr, closure);
# pthread_mutex_unlock(&cuda_closures_mutex);
# *pfn = closure->c_ptr;
# } else {
# ffi_closure_free(closure->closure);
# free(closure);
# }
# } else {
# ffi_closure_free(closure->closure);
# free(closure);
# }
# } else {
# free(closure);
# }
# }
# }
# EOF
# rescue => e
# str = <<EOF
# (void)pfn;
# (void)#{c.ffi_name};
# EOF
# end
#
print str
puts <<~EOF
}
Expand Down
63 changes: 6 additions & 57 deletions backends/cuda/gen_cuda_library.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
require_relative 'gen_cuda_library_base'

def print_enum(name, enum)
print_enum_with_namespace(:CUDA, name, enum)
end

def print_cuda_object(object)
print_object(object)
end

print_ffi_module(:CUDA)

puts <<~EOF
Expand All @@ -19,53 +11,10 @@ module CUDA
CUDA_IPC_HANDLE_SIZE = 64
extend FFI::Library

module Handle
def to_s
s = '{ reserved: "'
s << self[:reserved].to_a.collect { |v| "\\\\x%02x" % ((v + 256)%256) }.join
s << '" }'
end
end

module UUID
def to_s
a = self[:bytes].to_a.collect { |v| v < 0 ? 0x100 + v : v }
s = "{ id: "
s << "%02x" % a[0]
s << "%02x" % a[1]
s << "%02x" % a[2]
s << "%02x" % a[3]
s << "-"
s << "%02x" % a[4]
s << "%02x" % a[5]
s << "-"
s << "%02x" % a[6]
s << "%02x" % a[7]
s << "-"
s << "%02x" % a[8]
s << "%02x" % a[9]
s << "-"
s << "%02x" % a[10]
s << "%02x" % a[11]
s << "%02x" % a[12]
s << "%02x" % a[13]
s << "%02x" % a[14]
s << "%02x" % a[15]
s << " }"
end
end

EOF

def print_union(name, union)
print_union_with_namespace(:CUDA, name, union)
end

def print_struct(name, struct)
prepends = []
prepends << 'UUID' if to_class_name(name).match('UUID')
print_struct_with_namespace(:CUDA, name, struct, prepends: prepends)
end
print_handle_uuid_modules
puts

puts <<EOF
typedef :uint32, #{to_ffi_name('cuuint32_t')}
Expand All @@ -81,19 +30,19 @@ def print_struct(name, struct)
$all_types.each do |t|
if t.type.is_a? YAMLCAst::Enum
enum = $all_enums.find { |e| t.type.name == e.name }
print_enum(t.name, enum)
print_enum_with_namespace(:CUDA, t.name, enum)
elsif $objects.include?(t.name)
print_cuda_object(t.name)
print_object(t.name)
elsif t.type.is_a? YAMLCAst::Struct
struct = $all_structs.find { |s| t.type.name == s.name }
next unless struct

print_struct(t.name, struct)
print_struct_prepending_uuid(:CUDA, t.name, struct)
elsif t.type.is_a? YAMLCAst::Union
union = $all_unions.find { |s| t.type.name == s.name }
next unless union

print_union(t.name, union)
print_union_with_namespace(:CUDA, t.name, union)
elsif t.type.is_a?(YAMLCAst::Pointer) && t.type.type.is_a?(YAMLCAst::Function)
print_function_pointer_type(t.name, t.type.type)
end
Expand Down
32 changes: 4 additions & 28 deletions backends/cuda/gen_cuda_library_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,8 @@
$all_enums = $cuda_api['enums']
$all_funcs = $cuda_api['functions']

$all_enum_names = []
$all_bitfield_names = []
$all_struct_names = []
$all_union_names = []

$objects = $all_types.select do |t|
t.type.is_a?(YAMLCAst::Pointer) &&
t.type.type.is_a?(YAMLCAst::Struct)
end.collect { |t| t.name }

$all_types.each do |t|
$objects.push t.name if t.type.is_a?(YAMLCAst::CustomType) && OBJECT_TYPES.include?(t.type.name)
end

$int_scalars = {}
$all_types.each do |t|
$int_scalars[t.name] = t.type.name if t.type.is_a?(YAMLCAst::CustomType) && INT_TYPES.include?(t.type.name)
end
$objects = find_objects($all_types)
$int_scalars = find_int_scalars($all_types)

def to_snake_case(str)
str.gsub(/([A-Z][A-Z0-9]*)/, '_\1').downcase
Expand Down Expand Up @@ -87,16 +71,8 @@ def to_name_space(name)
end
end

$all_types.each do |t|
if t.type.is_a? YAMLCAst::Enum
$all_enums.find { |e| t.type.name == e.name }
$all_enum_names.push t.name
elsif t.type.is_a? YAMLCAst::Struct
$all_struct_names.push t.name
elsif t.type.is_a? YAMLCAst::Union
$all_union_names.push t.name
end
end
$all_enum_names, $all_bitfield_names, $all_struct_names, $all_union_names =
classify_ast_types($all_types, $all_enums)

FFI_STRUCT = 'FFI::CUDAStruct'
FFI_UNION = 'FFI::CUDAUnion'
Expand Down
16 changes: 3 additions & 13 deletions backends/hip/gen_babeltrace_hip_model.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
require_relative 'gen_hip_library_base'
require_relative '../../utils/gen_babeltrace_model_helper'

event_classes =
[[:lttng_ust_hip, $hip_commands]].collect do |provider, commands|
commands.collect do |c|
[gen_event_bt_model(provider, c, :start),
gen_event_bt_model(provider, c, :stop)]
end
end.flatten(2)
registry = build_ast_registry('hip', expect_bitfields: false)

hip_events = YAML.load_file(File.join(SRC_DIR, 'hip_events.yaml'))
event_classes += hip_events.collect do |provider, es|
es['events'].collect do |event|
gen_extra_event_bt_model(provider, event)
end
end.flatten
event_classes = gen_command_events_bt_model(registry, [[:lttng_ust_hip, $hip_commands]])
event_classes += gen_extra_events_bt_model(registry, 'hip_events.yaml')

puts YAML.dump(gen_yaml(event_classes, 'hip'))
Loading
Loading