Skip to content

Add dump support for empty views#34

Draft
daxmawal wants to merge 2 commits into
mainfrom
fix/dump_support_empty_view
Draft

Add dump support for empty views#34
daxmawal wants to merge 2 commits into
mainfrom
fix/dump_support_empty_view

Conversation

@daxmawal

@daxmawal daxmawal commented Jul 8, 2026

Copy link
Copy Markdown
Member

Fix issue #25
There is also a draft proposed PR in Kokkos Core to fix this.

Fix overview

Before, the dump path trusted the size reported by the Kokkos allocation hook and used it as the number of bytes to copy from p_data.

That is unsafe because p_data points to the user-data region after the Kokkos allocation header, while the reported size can be larger than the bytes that are actually available from that pointer.

For a non-empty view, the layout looks like this:

allocation base                                      allocation end
|                                                    |
v                                                    v
+--------------------------+-------------------------+
| Kokkos allocation header | user data bytes         |
+--------------------------+-------------------------+
                           ^
                           |
                         p_data

For an empty view, p_data point at the end of the allocation:

allocation base             allocation end
|                           |
v                           v
+---------------------------+
| Kokkos allocation header  |
+---------------------------+
                            ^
                            |
                          p_data

The fix computes the real allocation bounds first, then validates the byte range before copying:

available = allocation_end - p_data

if available >= reported_size:
    copied size = reported_size
else:
    copied size = 0

The dump now stores both values:
size: number of user-data bytes that are safe to copy
reported_size: size reported by the Kokkos allocation hook

@daxmawal daxmawal force-pushed the fix/dump_support_empty_view branch 7 times, most recently from f70359c to b14d82c Compare July 8, 2026 20:29
@daxmawal daxmawal force-pushed the fix/dump_support_empty_view branch from b14d82c to a1dc0d8 Compare July 8, 2026 20:32
Signed-off-by: daxmawal <jeanfrancoismanutea@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant