Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3258389
opencl: unify tracepoint printing with shared utils/LTTng.rb
TApplencourt Jul 29, 2026
1840e95
test: add opencl_tracepoints.tp to generated-file comparison oracle
TApplencourt Jul 29, 2026
c2f3403
test: guard all opencl generated files in comparison oracle
TApplencourt Jul 29, 2026
f795997
utils: introduce TypeRegistry value object, keep global instance
TApplencourt Jul 29, 2026
18cff9c
utils: gen_bt_field_model(registry, ...) reads from TypeRegistry
TApplencourt Jul 29, 2026
53d1b1e
babeltrace-model: thread TypeRegistry explicitly, drop load-time glob…
TApplencourt Jul 29, 2026
c3ac862
opencl: drop fake AST globals that only fed the helper's deleted load…
TApplencourt Jul 29, 2026
92b87bf
opencl: document why parse_field stays separate from shared helper
TApplencourt Jul 30, 2026
31720f3
babeltrace-model: assert per-backend bitfield invariant; note remaini…
TApplencourt Jul 30, 2026
b158fb8
gen: delete dead code (unused to_snake_case dups, dead flag, commente…
TApplencourt Jul 30, 2026
43a5926
opencl: remove permanently-empty ENUM lookup tables and their dead re…
TApplencourt Jul 30, 2026
aa6a970
gen: extract shared classify_ast_types, collapse 6 per-backend loops
TApplencourt Jul 30, 2026
c0b5a82
Dedup meta-parameter YAML loading into load_meta_parameters helper
TApplencourt Jul 30, 2026
2910f7d
Dedup upper_snake_case into utils/LTTng.rb
TApplencourt Jul 30, 2026
b334aa5
babeltrace-model: fold TypeRegistry construction into build_ast_registry
TApplencourt Jul 30, 2026
ce9b8fa
babeltrace-model: fold command/extra event loops into shared helpers
TApplencourt Jul 30, 2026
14f37a0
gen: extract find_objects / find_int_scalars from library-base files
TApplencourt Jul 30, 2026
6fb40eb
gen: hoist shared Handle/UUID modules into gen_library_base
TApplencourt Aug 10, 2026
125cbcb
gen: call print_object directly, drop the per-backend aliases
TApplencourt Aug 10, 2026
bbd3fff
gen: call the *_with_namespace helpers directly, drop namespace aliases
TApplencourt Aug 10, 2026
f2007eb
gen: inline the cuda/hip/mpi print_enum namespace aliases
TApplencourt Aug 10, 2026
f8f130b
gen: share the UUID-prepending struct printer between cuda and hip
TApplencourt Aug 10, 2026
7966922
lint: satisfy rubocop on the files this branch touches
TApplencourt Aug 10, 2026
cf2b2bc
gitignore: ignore __pycache__
TApplencourt Aug 10, 2026
b1cad47
ci: build the opencl model yamls the oracle compares
TApplencourt Aug 10, 2026
c018743
gen: fail loudly when a meta-parameter YAML has no meta_parameters key
TApplencourt Aug 10, 2026
0f646a9
gen: return the meta-parameter spec instead of mutating a global
TApplencourt Aug 13, 2026
e84cc6c
build: declare command.rb and type_registry.rb as codegen dependencies
TApplencourt Aug 13, 2026
b9aee10
gen: attach prologues and epilogues to the commands themselves
TApplencourt Aug 13, 2026
b9e49c1
gen: look opencl commands up in the index, not in 1000 globals
TApplencourt Aug 13, 2026
8c0c312
gen: delete state nothing reads
TApplencourt Aug 13, 2026
f8d7978
gen: opencl loads its meta-parameters the same way everyone else does
TApplencourt Aug 13, 2026
caeebb8
gen: make `commands` the one handle for reaching commands
TApplencourt Aug 13, 2026
0b709ba
gen: drop the pointer-name tables itt and omp never look up
TApplencourt Aug 13, 2026
180d76d
gen: stop publishing $all_funcs for one reader
TApplencourt Aug 13, 2026
24b090f
gen: give each backend an ApiModel instead of nine globals
TApplencourt Aug 13, 2026
df9e518
gen: raise on a missing type definition instead of skipping it
TApplencourt Aug 13, 2026
aaa08d9
gen: load an api.yaml into an AST in one call
TApplencourt Aug 13, 2026
ae20c51
gen: make the two tracepoint emitters methods, not global lambdas
TApplencourt Aug 13, 2026
5a1998b
gen: name the frozen lookup tables as constants
TApplencourt Aug 13, 2026
0b29e5d
ze: restore the line continuation before meta_parameter_spec.rb
TApplencourt Aug 13, 2026
0b32667
itt: pass fnptr_syms in instead of reaching for a global behind a guard
TApplencourt Aug 13, 2026
8b9f617
test: note the intentional mpi_library.rb divergence in the oracle
TApplencourt Aug 13, 2026
04c69a2
gen: give every API all five type lists, empty when absent
TApplencourt Aug 13, 2026
aa53eea
gen: resolve typedef aliases when classifying object types
TApplencourt Aug 13, 2026
1f42a3f
itt: resolve enums with API.enum like every other backend
TApplencourt Aug 13, 2026
a66d446
Compute ApiModel objects locally instead of reading OBJECT_TYPES
TApplencourt Aug 14, 2026
7ce8cef
Drop write-only FLOAT_TYPES
TApplencourt Aug 14, 2026
8ace578
Return type classifications instead of accumulating into globals
TApplencourt Aug 14, 2026
9a5a261
Let an API declare its own hex integer types
TApplencourt Aug 14, 2026
6a34c5a
Give Command a BackendContext instead of four ambient constants
TApplencourt Aug 14, 2026
cef3023
Pass the type classification into lttng_type
TApplencourt Aug 14, 2026
d090e74
Give ApiModel the struct map and let ze read it from there
TApplencourt Aug 14, 2026
eec79fa
Ask TypeClasses for a category instead of walking it twice
TApplencourt Aug 14, 2026
06664db
Let ApiModel parse the file it models
TApplencourt Aug 14, 2026
8dac4b0
Let each model publish its API instead of a global
TApplencourt Aug 14, 2026
4ab1a1b
Name cudart's model API like every other backend
TApplencourt Aug 14, 2026
0fb3ad6
Let each model publish its command index instead of globals
TApplencourt Aug 14, 2026
d748648
ze: reconcile the meta-parameters with the API like every other backend
TApplencourt Aug 14, 2026
515207a
ze: derive the meta-parameter file list from APIS
TApplencourt Aug 14, 2026
aa73225
ze: look up zer's structs in zer, not zel
TApplencourt Aug 14, 2026
53c5678
gen: make the namespace contract explicit instead of accidental
TApplencourt Aug 14, 2026
f6d91cc
gen: an editor's pass over this branch's comments
TApplencourt Aug 14, 2026
166bc3a
gen: collapse indirection that only ever had one caller
TApplencourt Aug 14, 2026
2d3f5fb
oracle: drop the note about the mpi divergence devel now carries
TApplencourt Aug 27, 2026
6212ef2
gen: name the block CommandIndex#each forwards
TApplencourt Aug 27, 2026
505f72b
gen: read the model directly instead of aliasing it first
TApplencourt Aug 27, 2026
d59b97a
gen: classify each API's types once, in the model that owns them
TApplencourt Aug 27, 2026
46f56ca
ze: ask the model which structs carry an stype tag
TApplencourt Aug 27, 2026
a8c9c6f
ze: let API mean what it means in every other backend
TApplencourt Aug 27, 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__
15 changes: 10 additions & 5 deletions backends/cuda/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,35 @@ ML_CUDA_FILES = \
$(srcdir)/cuda_meta_parameters.yaml \
$(srcdir)/cuda_exports_meta_parameters.yaml

ML_CUDART_FILES = \
$(srcdir)/cudart_meta_parameters.yaml

EXTRA_DIST += $(ML_CUDA_FILES) $(ML_CUDART_FILES)
EXTRA_DIST += $(ML_CUDA_FILES)

CUDA_MODEL = \
$(srcdir)/cuda_model.rb \
$(ML_CUDA_FILES) \
$(srcdir)/cuda_events.yaml \
$(CUDA_EXTRACTED) \
$(top_srcdir)/utils/api_model.rb \
$(top_srcdir)/utils/yaml_ast.rb \
$(top_srcdir)/utils/yaml_ast_lttng.rb \
$(top_srcdir)/utils/meta_parameters.rb \
$(top_srcdir)/utils/LTTng.rb \
$(top_srcdir)/utils/command.rb \
$(top_srcdir)/utils/command_index.rb \
$(top_srcdir)/utils/meta_parameter_spec.rb \
$(srcdir)/cuda.h.include \
cuda_exports.h.include

CUDART_MODEL = \
$(srcdir)/cudart_model.rb \
$(ML_CUDART_FILES) \
$(CUDART_EXTRACTED) \
$(top_srcdir)/utils/api_model.rb \
$(top_srcdir)/utils/yaml_ast.rb \
$(top_srcdir)/utils/yaml_ast_lttng.rb \
$(top_srcdir)/utils/meta_parameters.rb \
$(top_srcdir)/utils/LTTng.rb \
$(top_srcdir)/utils/command.rb \
$(top_srcdir)/utils/command_index.rb \
$(top_srcdir)/utils/meta_parameter_spec.rb \
$(srcdir)/cudart.h.include

btx_cuda_model.yaml: $(srcdir)/gen_babeltrace_cuda_model.rb $(CUDA_LIB_GEN) $(CUDA_MODEL)
Expand Down Expand Up @@ -306,6 +309,8 @@ install-data-hook:

CUDA_LIB_GEN = \
$(top_srcdir)/utils/gen_babeltrace_model_helper.rb \
$(top_srcdir)/utils/api_model.rb \
$(top_srcdir)/utils/type_registry.rb \
$(top_srcdir)/utils/gen_library_base.rb \
$(srcdir)/gen_cuda_library_base.rb \
$(top_srcdir)/utils/gen_probe_base.rb
Expand Down
125 changes: 51 additions & 74 deletions backends/cuda/cuda_model.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
require 'yaml'
require 'pp'
require 'set'
require_relative '../../utils/api_model'
require_relative '../../utils/yaml_ast_lttng'
require_relative '../../utils/LTTng'
require_relative '../../utils/command'
require_relative '../../utils/meta_parameters'

SRC_DIR = ENV['SRC_DIR'] || '.'

RESULT_NAME = 'cuResult'
# CUdeviceptr is a device address carried in an integer, so it reads as hex
# rather than as a decimal that means nothing to anyone.
cuda_api = ApiModel.load_file('cuda_api.yaml', hex_ints: ['CUdeviceptr'])
cuda_exports_api = ApiModel.load_file('cuda_exports_api.yaml')

$cuda_api_versions_yaml = YAML.load_file('cuda_api_versions.yaml')
$cuda_api_yaml = YAML.load_file('cuda_api.yaml')
$cuda_exports_api_yaml = YAML.load_file('cuda_exports_api.yaml')
# The driver and its export tables are traced as one API: an export-table
# typedef can name a driver struct, so they have to be classified together.
API = cuda_api + cuda_exports_api

$cuda_api = YAMLCAst.from_yaml_ast($cuda_api_yaml)
$cuda_exports_api = YAMLCAst.from_yaml_ast($cuda_exports_api_yaml)
gen_ffi_type_map(API.types, API.type_classes)

cuda_funcs_e = $cuda_api['functions']
cuda_exports_funcs_e = $cuda_exports_api['functions']

cuda_types_e = $cuda_api['typedefs']
cuda_exports_type_e = $cuda_exports_api['typedefs']

typedefs = cuda_types_e + cuda_exports_type_e
structs = $cuda_api['structs'] + $cuda_exports_api['structs']

find_all_types(typedefs)
gen_struct_map(typedefs, structs)
gen_ffi_type_map(typedefs)

HEX_INT_TYPES.push('CUdeviceptr')
CONTEXT = BackendContext.new(
result_name: 'cuResult',
# cuda's pointers start at a _uninit trampoline that calls _init_tracer(), so
# no function is singled out as the initializer and Command#init? is never
# asked.
init_functions: nil,
struct_map: API.struct_map,
type_classes: API.type_classes
)

class TracepointParameter
attr_reader :name, :type, :init, :after
Expand Down Expand Up @@ -81,33 +79,19 @@ 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

$cuda_commands = cuda_funcs_e.collect do |func|
Command.new(func)
end
meta_parameters = load_meta_parameters('cuda_meta_parameters.yaml', 'cuda_exports_meta_parameters.yaml')

$cuda_exports_commands = cuda_exports_funcs_e.collect do |func|
Command.new(func)
end
# The driver and its export tables are one API but two LTTng providers, so the
# commands are grouped by the provider that will carry them.
COMMANDS = CommandIndex.new(
{ lttng_ust_cuda: cuda_api.functions, lttng_ust_cuda_exports: cuda_exports_api.functions }.transform_values do |funcs|
funcs.collect { |func| Command.new(func, context: CONTEXT, meta_parameters: meta_parameters[func.name]) }
end
)

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

CUDA_POINTER_NAMES = ($cuda_commands +
$cuda_exports_commands).collect do |c|
CUDA_POINTER_NAMES = COMMANDS.collect do |c|
[c, upper_snake_case(c.pointer_name)]
end.to_h

Expand All @@ -119,7 +103,7 @@ def upper_snake_case(str)
cuLaunchKernel_ptsz
cuLaunchKernelEx
cuLaunchKernelEx_ptsz].each do |m|
register_prologue m, dump_args
COMMANDS.add_prologue m, dump_args
end

dump_args = <<EOF
Expand All @@ -128,7 +112,7 @@ def upper_snake_case(str)

%w[cuLaunchCooperativeKernel
cuLaunchCooperativeKernel_ptsz].each do |m|
register_prologue m, dump_args
COMMANDS.add_prologue m, dump_args
end

dump_args = <<EOF
Expand All @@ -139,18 +123,18 @@ def upper_snake_case(str)

%w[cuGraphAddKernelNode
cuGraphExecKernelNodeSetParams].each do |m|
register_prologue m, dump_args
COMMANDS.add_prologue m, dump_args
end

register_prologue 'cuLaunchCooperativeKernelMultiDevice', <<EOF
COMMANDS.add_prologue 'cuLaunchCooperativeKernelMultiDevice', <<EOF
if (launchParamsList) {
for( unsigned int _i = 0; _i < numDevices; _i++) {
_dump_kernel_args(launchParamsList[_i].function, launchParamsList[_i].kernelParams, NULL);
}
}
EOF

register_epilogue 'cuGraphKernelNodeGetParams', <<EOF
COMMANDS.add_epilogue 'cuGraphKernelNodeGetParams', <<EOF
if (_retval == CUDA_SUCCESS && nodeParams) {
_dump_kernel_args(nodeParams->func, nodeParams->kernelParams, nodeParams->extra);
}
Expand Down Expand Up @@ -192,7 +176,7 @@ def upper_snake_case(str)

stream_commands = []
no_stream_commands = []
mem_commands = $cuda_commands.select { |c| c.name.match(/cuMemcpy|cuMemset/) }
mem_commands = COMMANDS.groups[:lttng_ust_cuda].select { |c| c.name.match(/cuMemcpy|cuMemset/) }
mem_stream_commands = mem_commands.select { |c| c.name.match(/Async/) }
mem_no_stream_commands = mem_commands - mem_stream_commands
stream_commands += mem_stream_commands.collect(&:name)
Expand Down Expand Up @@ -221,39 +205,39 @@ def upper_snake_case(str)
]

stream_commands.each do |m|
register_prologue m, profiling_start_stream
register_epilogue m, profiling_stop_stream
COMMANDS.add_prologue m, profiling_start_stream
COMMANDS.add_epilogue m, profiling_stop_stream
end

no_stream_commands.each do |m|
register_prologue m, profiling_start_no_stream
register_epilogue m, profiling_stop_no_stream
COMMANDS.add_prologue m, profiling_start_no_stream
COMMANDS.add_epilogue m, profiling_stop_no_stream
end

config_commands.each do |m|
register_prologue m, profiling_start_config
register_epilogue m, profiling_stop_config
COMMANDS.add_prologue m, profiling_start_config
COMMANDS.add_epilogue m, profiling_stop_config
end

# if a context is to be destroyed we must attempt to get profiling event results
%w[cuCtxDestroy
cuCtxDestroy_v2].each do |m|
register_prologue m, <<EOF
COMMANDS.add_prologue m, <<EOF
if (ctx) {
_context_event_cleanup(ctx);
}
EOF
end

register_epilogue 'cuDevicePrimaryCtxRetain', <<EOF
COMMANDS.add_epilogue 'cuDevicePrimaryCtxRetain', <<EOF
if (_do_profile && _retval == CUDA_SUCCESS && *pctx) {
_primary_context_retain(dev, *pctx);
}
EOF

%w[cuDevicePrimaryCtxRelease_v2
cuDevicePrimaryCtxRelease].each do |m|
register_prologue m, <<EOF
COMMANDS.add_prologue m, <<EOF
if (_do_profile) {
_primary_context_release(dev);
}
Expand All @@ -262,29 +246,31 @@ def upper_snake_case(str)

%w[cuDevicePrimaryCtxReset_v2
cuDevicePrimaryCtxReset].each do |m|
register_prologue m, <<EOF
COMMANDS.add_prologue m, <<EOF
if (_do_profile) {
_primary_context_reset(dev);
}
EOF
end

# Export tracing
register_epilogue 'cuGetExportTable', <<EOF
COMMANDS.add_epilogue 'cuGetExportTable', <<EOF
if (_do_trace_export_tables && _retval == CUDA_SUCCESS) {
const void *tmp = _wrap_and_cache_export_table(*ppExportTable, pExportTableId);
*ppExportTable = tmp;
}
EOF

register_epilogue 'cuInit', <<EOF
COMMANDS.add_epilogue 'cuInit', <<EOF
if (_retval == CUDA_SUCCESS) {
_init_cuda();
}
EOF

# cuGetProcAddress*
command_names = $cuda_commands.collect(&:name).to_set
# Not an api.yaml: a plain name -> suffix -> versions map, used only here.
api_versions = YAML.load_file('cuda_api_versions.yaml')
command_names = COMMANDS.groups[:lttng_ust_cuda].collect(&:name).to_set
pt_condition = '((flags & CU_GET_PROC_ADDRESS_PER_THREAD_DEFAULT_STREAM) && !(flags & CU_GET_PROC_ADDRESS_LEGACY_STREAM))'
normal_condition = '((flags & CU_GET_PROC_ADDRESS_LEGACY_STREAM) || !(flags & CU_GET_PROC_ADDRESS_PER_THREAD_DEFAULT_STREAM))'

Expand All @@ -296,7 +282,7 @@ def upper_snake_case(str)
fprintf(stderr, "THAPI: CUDA version %d is unsupported, could not wrap %s symbol\\n", cudaVersion, symbol);
} else if (_retval == CUDA_SUCCESS && pfn && *pfn) {
EOF
str << $cuda_api_versions_yaml.map { |name, suffixes|
str << api_versions.map { |name, suffixes|
suffixes.map { |suffix, versions|
versions.map.with_index { |version, i|
fullname = "#{name}#{"_v#{versions.size - i}" if versions.size - i > 1}#{suffix}"
Expand All @@ -313,20 +299,11 @@ def upper_snake_case(str)
}.flatten.join(<<EOF)
else
EOF
# str << $cuda_commands.collect { |c|
# <<EOF
# if (tracepoint_enabled(lttng_ust_cuda, #{c.name}_#{START}) && strcmp(symbol, "#{c.name}") == 0) {
# wrap_#{c.name}(pfn);
# }
# EOF
# }.join(<<EOF)
# else
# EOF
str << <<EOF
}
EOF

register_epilogue method, str
COMMANDS.add_epilogue method, str
}

register_proc_callbacks.call('cuGetProcAddress')
Expand Down
2 changes: 0 additions & 2 deletions backends/cuda/cudart_meta_parameters.yaml

This file was deleted.

44 changes: 15 additions & 29 deletions backends/cuda/cudart_model.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
require 'yaml'
require 'pp'
require_relative '../../utils/api_model'
require_relative '../../utils/yaml_ast_lttng'
require_relative '../../utils/LTTng'
require_relative '../../utils/command'
require_relative '../../utils/meta_parameters'

SRC_DIR = ENV['SRC_DIR'] || '.'

RESULT_NAME = 'cudaResult'
API = ApiModel.load_file('cudart_api.yaml')

$cudart_api_yaml = YAML.load_file('cudart_api.yaml')
gen_ffi_type_map(API.types, API.type_classes)

$cudart_api = YAMLCAst.from_yaml_ast($cudart_api_yaml)
CONTEXT = BackendContext.new(
result_name: 'cudaResult',
# gen_cudart.rb calls _init_tracer() from every wrapper, so no function is
# singled out as the initializer and Command#init? is never asked.
init_functions: nil,
struct_map: API.struct_map,
type_classes: API.type_classes
)

funcs = $cudart_api['functions']
typedefs = $cudart_api['typedefs']
structs = $cudart_api['structs']
COMMANDS = CommandIndex.new(lttng_ust_cudart: API.functions.collect do |func|
Command.new(func, context: CONTEXT)
end)

find_all_types(typedefs)
gen_struct_map(typedefs, structs)
gen_ffi_type_map(typedefs)

# 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

$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|
CUDART_POINTER_NAMES = COMMANDS.collect do |c|
[c, upper_snake_case(c.pointer_name)]
end.to_h
Loading
Loading