Skip to content

Commit 3bf303a

Browse files
committed
resolved merge conflicts
2 parents fb14668 + 5e71a9d commit 3bf303a

4 files changed

Lines changed: 100 additions & 5 deletions

File tree

‎backends/ze/tracer_ze_helpers.include.c‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,71 @@ static void _dump_driver_device_properties(ze_driver_handle_t hDriver) {
13231323
}
13241324
}
13251325

1326+
/* Emit a device_peer_access tracepoint for every ordered (src, peer) pair
1327+
* across a driver's devices and their sub-devices. A device is never paired
1328+
* with itself, but sub-devices of the same parent are paired with each other
1329+
* and with other parents' sub-devices. */
1330+
static void _dump_driver_p2p(ze_driver_handle_t hDriver) {
1331+
if (!tracepoint_enabled(lttng_ust_ze_properties, zeMetadata_device_peer_access))
1332+
return;
1333+
1334+
uint32_t deviceCount = 0;
1335+
if (ZE_DEVICE_GET_PTR(hDriver, &deviceCount, NULL) != ZE_RESULT_SUCCESS || deviceCount == 0)
1336+
return;
1337+
ze_device_handle_t *phDevices =
1338+
(ze_device_handle_t *)alloca(deviceCount * sizeof(ze_device_handle_t));
1339+
if (ZE_DEVICE_GET_PTR(hDriver, &deviceCount, phDevices) != ZE_RESULT_SUCCESS)
1340+
return;
1341+
1342+
/* First pass: count the flat total (devices + all sub-devices) so we can
1343+
* allocate a single flat handle array. */
1344+
uint32_t totalCount = deviceCount;
1345+
for (uint32_t i = 0; i < deviceCount; i++) {
1346+
uint32_t subCount = 0;
1347+
if (ZE_DEVICE_GET_SUB_DEVICES_PTR(phDevices[i], &subCount, NULL) == ZE_RESULT_SUCCESS)
1348+
totalCount += subCount;
1349+
}
1350+
1351+
ze_device_handle_t *phAll =
1352+
(ze_device_handle_t *)alloca(totalCount * sizeof(ze_device_handle_t));
1353+
uint32_t idx = 0;
1354+
for (uint32_t i = 0; i < deviceCount; i++) {
1355+
phAll[idx++] = phDevices[i];
1356+
uint32_t subCount = 0;
1357+
if (ZE_DEVICE_GET_SUB_DEVICES_PTR(phDevices[i], &subCount, NULL) != ZE_RESULT_SUCCESS ||
1358+
subCount == 0)
1359+
continue;
1360+
if (ZE_DEVICE_GET_SUB_DEVICES_PTR(phDevices[i], &subCount, phAll + idx) != ZE_RESULT_SUCCESS)
1361+
continue;
1362+
idx += subCount;
1363+
}
1364+
totalCount = idx;
1365+
1366+
for (uint32_t i = 0; i < totalCount; i++) {
1367+
for (uint32_t j = 0; j < totalCount; j++) {
1368+
if (i == j)
1369+
continue;
1370+
ze_bool_t canAccess = 0;
1371+
if (ZE_DEVICE_CAN_ACCESS_PEER_PTR(phAll[i], phAll[j], &canAccess) != ZE_RESULT_SUCCESS)
1372+
continue;
1373+
ze_device_p2p_properties_t props = {0};
1374+
props.stype = ZE_STRUCTURE_TYPE_DEVICE_P2P_PROPERTIES;
1375+
props.pNext = NULL;
1376+
if (ZE_DEVICE_GET_P2PPROPERTIES_PTR(phAll[i], phAll[j], &props) != ZE_RESULT_SUCCESS)
1377+
continue;
1378+
do_tracepoint(lttng_ust_ze_properties, zeMetadata_device_peer_access, hDriver, phAll[i], phAll[j],
1379+
canAccess, &props);
1380+
}
1381+
}
1382+
}
1383+
1384+
static void _dump_p2p_all_drivers(uint32_t driverCount, ze_driver_handle_t *phDrivers) {
1385+
if (!tracepoint_enabled(lttng_ust_ze_properties, zeMetadata_device_peer_access))
1386+
return;
1387+
for (uint32_t i = 0; i < driverCount; i++)
1388+
_dump_driver_p2p(phDrivers[i]);
1389+
}
1390+
13261391
static void _dump_kernel_properties(ze_kernel_handle_t hKernel) {
13271392
ze_kernel_properties_t kernelProperties = {.stype = ZE_STRUCTURE_TYPE_KERNEL_PROPERTIES};
13281393
if (ZE_KERNEL_GET_PROPERTIES_PTR(hKernel, &kernelProperties) == ZE_RESULT_SUCCESS)

‎backends/ze/ze_events.yaml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ lttng_ust_ze_properties:
171171
- [ctf_integer_hex, uintptr_t, hDevice, "(uintptr_t)hDevice"]
172172
- [ctf_integer, uint32_t, numGroups, numGroups]
173173
- [ctf_sequence_text, uint8_t, pGroupProperties_val, pGroupProperties, size_t, "numGroups * sizeof(ze_command_queue_group_properties_t)"]
174+
- name: zeMetadata_device_peer_access
175+
args:
176+
- [ze_driver_handle_t, hDriver]
177+
- [ze_device_handle_t, hDevice]
178+
- [ze_device_handle_t, hPeerDevice]
179+
- [ze_bool_t, canAccess]
180+
- [ze_device_p2p_properties_t *, pP2PProperties]
181+
fields:
182+
- [ctf_integer_hex, uintptr_t, hDriver, "(uintptr_t)hDriver"]
183+
- [ctf_integer_hex, uintptr_t, hDevice, "(uintptr_t)hDevice"]
184+
- [ctf_integer_hex, uintptr_t, hPeerDevice, "(uintptr_t)hPeerDevice"]
185+
- [ctf_integer, uint8_t, canAccess, canAccess]
186+
- [ctf_sequence_text, uint8_t, pP2PProperties_val, pP2PProperties, size_t, "sizeof(ze_device_p2p_properties_t)"]
174187
- name: device_timer
175188
args:
176189
- [ze_device_handle_t, hDevice]

‎backends/ze/ze_model.rb‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
RESULT_NAME = 'zeResult'
1212

13-
$ze_api_yaml = YAML.load_file('ze_api.yaml')
13+
$ze_api_yaml = YAML.load_file('ze_api.yaml') # $var represents global var. @var Instance var, @@var class var, var local var, VAR constant
1414
$zet_api_yaml = YAML.load_file('zet_api.yaml')
1515
$zes_api_yaml = YAML.load_file('zes_api.yaml')
1616
$zel_api_yaml = YAML.load_file('zel_api.yaml')
@@ -35,15 +35,15 @@
3535
typedefs = $ze_api['typedefs'] + $zet_api['typedefs'] + $zes_api['typedefs'] + $zel_api['typedefs'] + $zer_api['typedefs'] + $zex_api['typedefs']
3636
structs = $ze_api['structs'] + $zet_api['structs'] + $zes_api['structs'] + $zel_api['structs'] + $zer_api['structs'] + $zex_api['structs']
3737

38-
find_all_types(typedefs)
38+
find_all_types(typedefs) #yaml_ast.rb
3939
gen_struct_map(typedefs, structs)
4040
gen_ffi_type_map(typedefs)
4141

4242
# zesInit is included here so that a pure-Sysman program (one that only calls
4343
# zesInit, never zeInit) still triggers the tracer initialization.
4444
# Ideally we would split this into INIT_ZE_FUNCTIONS / INIT_ZES_FUNCTIONS
4545
# so each namespace initializes its own symbols.
46-
INIT_FUNCTIONS = /zeInit|zeLoaderInit|zeInitDrivers|zesInit/
46+
INIT_FUNCTIONS = /zeInit|zeLoaderInit|zeInitDrivers|zesInit/ # REGEX
4747

4848
$struct_type_conversion_table = {
4949
'ZE_STRUCTURE_TYPE_IMAGE_MEMORY_PROPERTIES_EXP' => 'ZE_STRUCTURE_TYPE_IMAGE_MEMORY_EXP_PROPERTIES',
@@ -274,11 +274,23 @@ def upper_snake_case(str)
274274
_on_destroy_event(hEvent);
275275
EOF
276276

277+
# Emit device_peer_access tracepoints after the loader hands back the driver
278+
# list. Guarded on phDrivers so the count-only invocation (phDrivers == NULL)
279+
# doesn't trigger a dump.
280+
p2p_epilogue = <<EOF
281+
if (_retval == ZE_RESULT_SUCCESS && phDrivers && pCount &&
282+
tracepoint_enabled(lttng_ust_ze_properties, zeMetadata_device_peer_access)) {
283+
_dump_p2p_all_drivers(*pCount, phDrivers);
284+
}
285+
EOF
286+
register_epilogue 'zeDriverGet', p2p_epilogue
287+
register_epilogue 'zeInitDrivers', p2p_epilogue
288+
277289
# Dump memory info if required
278290
memory_info_dump = lambda { |ptr_name|
279291
"_dump_memory_info(hCommandList, #{ptr_name})"
280292
}
281-
293+
#memory info device,heap, etc. Only if paranoid memory tracking is enabled
282294
memory_info_prologue = lambda { |ptr_names|
283295
<<EOF
284296
if (_do_paranoid_memory_location &&
@@ -346,6 +358,7 @@ def upper_snake_case(str)
346358
EOF
347359
}
348360

361+
# event name is known from API Spec
349362
profiling_epilogue = lambda { |_event_name, waits_expr = 'phWaitEvents', n_waits_expr = 'numWaitEvents'|
350363
<<EOF
351364
if (_do_profile && _einj) {
@@ -449,6 +462,8 @@ def upper_snake_case(str)
449462
}
450463
EOF
451464

465+
# generates the dispatch table?
466+
# replaces the original function calls with the wrappers
452467
($ze_commands + $zet_commands + $zes_commands + $zel_commands + $zer_commands).select do |c|
453468
c.name.match(/(ze|zet|zes|zel|zer)Get.*ProcAddrTable/)
454469
end.each do |c|
@@ -576,4 +591,4 @@ def get_ffi_type(a)
576591

577592
register_epilogue 'zeInit', <<EOF
578593
_in_loader_init = 0;
579-
EOF
594+
EOF

‎utils/command.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,5 @@ def register_epilogue(method, code)
134134
META_PARAMETERS = Hash.new { |h, k| h[k] = [] }
135135
PROLOGUES = Hash.new { |h, k| h[k] = [] }
136136
EPILOGUES = Hash.new { |h, k| h[k] = [] }
137+
138+
# appending of prologues and epilogues happens later

0 commit comments

Comments
 (0)