Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions projects/clr/hipamd/src/hrr/hip_capture_generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7812,6 +7812,21 @@ static hipError_t capture_hipLibraryGetModule(hipModule_t* pMod, hipLibrary_t li
return r;
}

// Generated shim
static hipError_t capture_hipKernelSetAttributeForDevice(hipKernel_t kernel, hipFuncAttribute attr, int value, int device) {
hipError_t r = g_real_table.hipKernelSetAttributeForDevice_fn(kernel, attr, value, device);
if (r == hipSuccess) {
hrr_args_hipKernelSetAttributeForDevice a{};
a.ret = static_cast<int32_t>(r);
a.kernel = reinterpret_cast<uint64_t>(kernel);
a.attr = static_cast<decltype(a.attr)>(attr);
a.value = static_cast<decltype(a.value)>(value);
a.device = static_cast<decltype(a.device)>(device);
hrr_cap::writer::write_event_raw(HRR_API_HIPKERNELSETATTRIBUTEFORDEVICE, &a.hdr, sizeof(a));
}
return r;
}

// Generated shim
static hipError_t capture___hipPopCallConfiguration(dim3* gridDim, dim3* blockDim, size_t* sharedMem, hipStream_t* stream) {
hipError_t r = g_real_compiler_table.__hipPopCallConfiguration_fn(gridDim, blockDim, sharedMem, stream);
Expand Down Expand Up @@ -8549,6 +8564,7 @@ void hip_capture_build_table() {
g_cap_table.hipModuleEnumerateFunctions_fn = capture_hipModuleEnumerateFunctions;
g_cap_table.hipDeviceFlushGPUDirectRDMAWrites_fn = capture_hipDeviceFlushGPUDirectRDMAWrites;
g_cap_table.hipLibraryGetModule_fn = capture_hipLibraryGetModule;
g_cap_table.hipKernelSetAttributeForDevice_fn = capture_hipKernelSetAttributeForDevice;
}

void hip_capture_build_compiler_table() {
Expand Down
20 changes: 11 additions & 9 deletions projects/hrr/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ the parent that exited cleanly needs no repair. A sub-archive is skipped when
payloads, finds it complete in the sense `load_archive` uses. `--info` on a
root applies the same check before it shows a process as complete.

### Archive Format (v8)
### Archive Format (v9)
```
capture.hrr/
manifest.json { version, capture_mode, owner_pid, processes[] }
Expand Down Expand Up @@ -371,13 +371,13 @@ The generator classifies each API:
Generated capture shims for manual APIs are pass-throughs (no `write_event()`).
When adding HIP API support, update this script to classify the API in the appropriate capture and playback policy sets. APIs requiring non-trivial serialization or replay belong in `MANUAL_CAPTURE_APIS` and/or `MANUAL_PLAYBACK_APIS`; intentionally unsupported replay APIs belong in `NOOP_PLAYBACK_APIS`.

## Archive Format (v8)
## Archive Format (v9)

Single-authority definition in `hrr_api_args.h` (auto-generated):

```
HRR_MAGIC = 0x52524845 ("HRRE")
HRR_VERSION = 8
HRR_VERSION = 9
```

Version history, so an archive written by an older runtime can be placed:
Expand Down Expand Up @@ -411,12 +411,15 @@ Version history, so an archive written by an older runtime can be placed:
`HipDispatchTable`. That slot takes the first compiler ID and shifts the
compiler API IDs up by one. A v7 reader would decode those events as the
wrong API.
- **v9** records `hipKernelSetAttributeForDevice`, appended to
`HipDispatchTable`, which shifts the compiler API IDs up by one again. A v8
reader would decode those events as the wrong API.

```
<output_dir>/
manifest.json { version, capture_mode, owner_pid, processes[] }
(version here is the manifest schema = 1, distinct from the
events.bin HRR_VERSION = 8)
events.bin HRR_VERSION = 9)
pid-<pid>/
manifest.json { pid, parent_pid, complete, event_count, blob_count }
active one line naming the process instance (boot id and
Expand Down Expand Up @@ -1277,7 +1280,6 @@ in `alloc_map`:
| API | Playback handler |
|-----|-----------------|
| `hipHostAlloc` | no-op |
| `hipMallocHost` | no-op |
| `hipMemAllocHost` | no-op |
| `hipMalloc3DArray` | no-op |
| `hipMallocArray` | no-op |
Expand Down Expand Up @@ -1310,8 +1312,8 @@ no-op won, so nothing was allocated or recorded and every derived pointer transl

**What does not work:**

- **Kernel launches** that pass the device-side alias of a `hipHostAlloc` /
`hipMallocHost` buffer as a kernel argument. The alias is obtained at capture
- **Kernel launches** that pass the device-side alias of a `hipHostAlloc`
buffer as a kernel argument. The alias is obtained at capture
time via `hipHostGetDevicePointer`, and that device address is never recorded
in `alloc_map`. At replay, `translate_ptr` returns `nullptr` for that argument,
and the kernel receives a null pointer — producing wrong results or a GPU fault.
Expand All @@ -1320,7 +1322,7 @@ no-op won, so nothing was allocated or recorded and every derived pointer transl
D2H transfers (the common case) replay correctly. Workloads that pass pinned memory
pointers directly to GPU kernels will produce incorrect output.

**Workaround:** replace `hipHostAlloc` / `hipMallocHost` with `hipHostRegister` on
**Workaround:** replace `hipHostAlloc` with `hipHostRegister` on
an existing `malloc` buffer — `hipHostRegister` _is_ fully captured and replayed,
including the device alias registration.

Expand Down Expand Up @@ -1485,7 +1487,7 @@ The event wire format (finding H5):
shrinking `reserved` to 2 bytes), so kernel launches with large serialized payloads
(many args / long mangled names / large by-value structs) up to ~4 GiB are recorded
normally instead of being dropped at 65535 bytes. This is the change that bumped
`HRR_VERSION` to 4; the current version is 8, see Archive Format above. The
`HRR_VERSION` to 4; the current version is 9, see Archive Format above. The
writer's single-record buffer path now writes any oversized record straight through.
- **Per-argument size limit (64 KiB) now fails loudly.** Each kernel arg's size is still
a `uint16_t`. A by-value struct argument ≥ 64 KiB cannot be represented, so the launch
Expand Down
2 changes: 2 additions & 0 deletions projects/hrr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ zero-extent or host-to-host 2D copy is a no-op. A fixed-size string in a record
copied into a bounded, NUL-terminated buffer before it is used.
`tools/tests/test_gen_raw_slots.py` regenerates the handlers and fails if a raw
cast of a recorded pointer or handle remains.
`tools/tests/test_generated_files_current.py` fails if a checked-in generated
source or the matrix expectations header is stale against the generator.

### External region annotations

Expand Down
39 changes: 27 additions & 12 deletions projects/hrr/include/hrr/hrr_api_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@
* v8: hipDeviceFlushGPUDirectRDMAWrites and hipLibraryGetModule were
* appended to HipDispatchTable. Each took a compiler ID, so the compiler
* API IDs moved up by two. develop still records both under v7. A v7
* reader decodes those events as the wrong API. */
#define HRR_VERSION ((uint16_t)8u)
* reader decodes those events as the wrong API.
* v9: hipKernelSetAttributeForDevice was appended to HipDispatchTable,
* taking the first compiler ID and shifting the compiler API IDs up by one.
* A v8 reader would decode those events as the wrong API. */
#define HRR_VERSION ((uint16_t)9u)

/* Written once at byte 0 of events.bin. */
#pragma pack(push, 1)
Expand Down Expand Up @@ -5853,6 +5856,16 @@ typedef struct {
uint64_t library;
} hrr_args_hipLibraryGetModule;

/* hipError_t hipKernelSetAttributeForDevice(hipKernel_t kernel, hipFuncAttribute attr, int value, int device) */
typedef struct {
hrr_event_header hdr;
int32_t ret;
uint64_t kernel;
int32_t attr;
int32_t value;
int32_t device;
} hrr_args_hipKernelSetAttributeForDevice;

/* ---- API id enumeration ---- */
typedef enum hrr_api_id {
HRR_API_HIPAPINAME = 0,
Expand Down Expand Up @@ -6402,16 +6415,17 @@ typedef enum hrr_api_id {
HRR_API_HIPMODULEENUMERATEFUNCTIONS = 544,
HRR_API_HIPDEVICEFLUSHGPUDIRECTRDMAWRITES = 545,
HRR_API_HIPLIBRARYGETMODULE = 546,
HRR_API_HIPPOPCALLCONFIGURATION = 547,
HRR_API_HIPPUSHCALLCONFIGURATION = 548,
HRR_API_HIPREGISTERFATBINARY = 549,
HRR_API_HIPREGISTERFUNCTION = 550,
HRR_API_HIPREGISTERMANAGEDVAR = 551,
HRR_API_HIPREGISTERSURFACE = 552,
HRR_API_HIPREGISTERTEXTURE = 553,
HRR_API_HIPREGISTERVAR = 554,
HRR_API_HIPUNREGISTERFATBINARY = 555,
HRR_API_COUNT = 556
HRR_API_HIPKERNELSETATTRIBUTEFORDEVICE = 547,
HRR_API_HIPPOPCALLCONFIGURATION = 548,
HRR_API_HIPPUSHCALLCONFIGURATION = 549,
HRR_API_HIPREGISTERFATBINARY = 550,
HRR_API_HIPREGISTERFUNCTION = 551,
HRR_API_HIPREGISTERMANAGEDVAR = 552,
HRR_API_HIPREGISTERSURFACE = 553,
HRR_API_HIPREGISTERTEXTURE = 554,
HRR_API_HIPREGISTERVAR = 555,
HRR_API_HIPUNREGISTERFATBINARY = 556,
HRR_API_COUNT = 557
} hrr_api_id_t;

/* Array of API names indexed by hrr_api_id_t */
Expand Down Expand Up @@ -6964,6 +6978,7 @@ const char* const hrr_api_names[HRR_API_COUNT] = {
"hipModuleEnumerateFunctions",
"hipDeviceFlushGPUDirectRDMAWrites",
"hipLibraryGetModule",
"hipKernelSetAttributeForDevice",
"__hipPopCallConfiguration",
"__hipPushCallConfiguration",
"__hipRegisterFatBinary",
Expand Down
48 changes: 30 additions & 18 deletions projects/hrr/playback/hip_playback_generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5569,6 +5569,16 @@ static hipError_t playback_hipLibraryGetModule(PlaybackContext& ctx, const uint8
return hipSuccess;
}

static hipError_t playback_hipKernelSetAttributeForDevice(PlaybackContext& ctx, const uint8_t* payload) {
(void)ctx; (void)payload;
static std::atomic<bool> warned{false};
if (!warned.exchange(true)) {
fprintf(stderr, "[HRR] NOOP playback handler called for hipKernelSetAttributeForDevice — "
"this API is not replayed; results may differ from capture.\n");
}
return hipSuccess;
}

static hipError_t playback___hipPopCallConfiguration(PlaybackContext& ctx, const uint8_t* payload) {
(void)ctx; (void)payload;
return hipSuccess;
Expand Down Expand Up @@ -6162,15 +6172,16 @@ const uint32_t hrr_api_min_payload_size[HRR_API_COUNT] = {
static_cast<uint32_t>(sizeof(hrr_args_hipModuleEnumerateFunctions)), // [544] HRR_API_HIPMODULEENUMERATEFUNCTIONS
static_cast<uint32_t>(sizeof(hrr_args_hipDeviceFlushGPUDirectRDMAWrites)), // [545] HRR_API_HIPDEVICEFLUSHGPUDIRECTRDMAWRITES
static_cast<uint32_t>(sizeof(hrr_args_hipLibraryGetModule)), // [546] HRR_API_HIPLIBRARYGETMODULE
static_cast<uint32_t>(sizeof(hrr_args___hipPopCallConfiguration)), // [547] HRR_API_HIPPOPCALLCONFIGURATION
static_cast<uint32_t>(sizeof(hrr_args___hipPushCallConfiguration)), // [548] HRR_API_HIPPUSHCALLCONFIGURATION
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterFatBinary)), // [549] HRR_API_HIPREGISTERFATBINARY
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterFunction)), // [550] HRR_API_HIPREGISTERFUNCTION
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterManagedVar)), // [551] HRR_API_HIPREGISTERMANAGEDVAR
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterSurface)), // [552] HRR_API_HIPREGISTERSURFACE
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterTexture)), // [553] HRR_API_HIPREGISTERTEXTURE
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterVar)), // [554] HRR_API_HIPREGISTERVAR
static_cast<uint32_t>(sizeof(hrr_args___hipUnregisterFatBinary)), // [555] HRR_API_HIPUNREGISTERFATBINARY
static_cast<uint32_t>(sizeof(hrr_args_hipKernelSetAttributeForDevice)), // [547] HRR_API_HIPKERNELSETATTRIBUTEFORDEVICE
static_cast<uint32_t>(sizeof(hrr_args___hipPopCallConfiguration)), // [548] HRR_API_HIPPOPCALLCONFIGURATION
static_cast<uint32_t>(sizeof(hrr_args___hipPushCallConfiguration)), // [549] HRR_API_HIPPUSHCALLCONFIGURATION
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterFatBinary)), // [550] HRR_API_HIPREGISTERFATBINARY
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterFunction)), // [551] HRR_API_HIPREGISTERFUNCTION
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterManagedVar)), // [552] HRR_API_HIPREGISTERMANAGEDVAR
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterSurface)), // [553] HRR_API_HIPREGISTERSURFACE
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterTexture)), // [554] HRR_API_HIPREGISTERTEXTURE
static_cast<uint32_t>(sizeof(hrr_args___hipRegisterVar)), // [555] HRR_API_HIPREGISTERVAR
static_cast<uint32_t>(sizeof(hrr_args___hipUnregisterFatBinary)), // [556] HRR_API_HIPUNREGISTERFATBINARY
};

// ============================================================
Expand Down Expand Up @@ -6724,13 +6735,14 @@ hrr_playback_fn_t hrr_playback_dispatch[HRR_API_COUNT] = {
playback_hipModuleEnumerateFunctions, // [544] HRR_API_HIPMODULEENUMERATEFUNCTIONS
playback_hipDeviceFlushGPUDirectRDMAWrites, // [545] HRR_API_HIPDEVICEFLUSHGPUDIRECTRDMAWRITES
playback_hipLibraryGetModule, // [546] HRR_API_HIPLIBRARYGETMODULE
playback___hipPopCallConfiguration, // [547] HRR_API_HIPPOPCALLCONFIGURATION
playback___hipPushCallConfiguration, // [548] HRR_API_HIPPUSHCALLCONFIGURATION
playback___hipRegisterFatBinary, // [549] HRR_API_HIPREGISTERFATBINARY
playback___hipRegisterFunction, // [550] HRR_API_HIPREGISTERFUNCTION
playback___hipRegisterManagedVar, // [551] HRR_API_HIPREGISTERMANAGEDVAR
playback___hipRegisterSurface, // [552] HRR_API_HIPREGISTERSURFACE
playback___hipRegisterTexture, // [553] HRR_API_HIPREGISTERTEXTURE
playback___hipRegisterVar, // [554] HRR_API_HIPREGISTERVAR
playback___hipUnregisterFatBinary, // [555] HRR_API_HIPUNREGISTERFATBINARY
playback_hipKernelSetAttributeForDevice, // [547] HRR_API_HIPKERNELSETATTRIBUTEFORDEVICE
playback___hipPopCallConfiguration, // [548] HRR_API_HIPPOPCALLCONFIGURATION
playback___hipPushCallConfiguration, // [549] HRR_API_HIPPUSHCALLCONFIGURATION
playback___hipRegisterFatBinary, // [550] HRR_API_HIPREGISTERFATBINARY
playback___hipRegisterFunction, // [551] HRR_API_HIPREGISTERFUNCTION
playback___hipRegisterManagedVar, // [552] HRR_API_HIPREGISTERMANAGEDVAR
playback___hipRegisterSurface, // [553] HRR_API_HIPREGISTERSURFACE
playback___hipRegisterTexture, // [554] HRR_API_HIPREGISTERTEXTURE
playback___hipRegisterVar, // [555] HRR_API_HIPREGISTERVAR
playback___hipUnregisterFatBinary, // [556] HRR_API_HIPUNREGISTERFATBINARY
};
2 changes: 2 additions & 0 deletions projects/hrr/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ add_subdirectory(unit)

# Generator rules: regenerate the playback handlers and fail if
# one still casts an archive field to a pointer or an opaque handle.
# Also fails if a checked-in generated source or the API matrix header is
# stale against the generator (test_generated_files_current.py).
find_package(Python3 COMPONENTS Interpreter)
if(Python3_Interpreter_FOUND)
add_test(NAME hrr-generator-rules
Expand Down
Loading
Loading