Skip to content
Merged
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
30 changes: 17 additions & 13 deletions backends/vulkan/serialization/vulkan_graph_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,23 @@ def serialize_constant_tensors(

current_offset = len(raw_bytes)
for tensor in const_tensors:
array_type = ctypes.c_char * tensor.untyped_storage().nbytes()
array = ctypes.cast(
tensor.untyped_storage().data_ptr(),
ctypes.POINTER(array_type),
).contents

tensor_bytes = bytes(array)
# Pad the tensor bytes to the next 16 byte boundary
raw_bytes += tensor_bytes
raw_bytes += b"\x00" * padding_required(len(tensor_bytes))

vk_graph.constants.append(VkBytes(current_offset, len(tensor_bytes)))
current_offset += aligned_size(len(tensor_bytes))
if tensor.numel() == 0:
vk_graph.constants.append(VkBytes(current_offset, 0))
continue
else:
array_type = ctypes.c_char * tensor.untyped_storage().nbytes()
array = ctypes.cast(
tensor.untyped_storage().data_ptr(),
ctypes.POINTER(array_type),
).contents

tensor_bytes = bytes(array)
# Pad the tensor bytes to the next 16 byte boundary
raw_bytes += tensor_bytes
raw_bytes += b"\x00" * padding_required(len(tensor_bytes))

vk_graph.constants.append(VkBytes(current_offset, len(tensor_bytes)))
current_offset += aligned_size(len(tensor_bytes))


def serialize_custom_shaders(
Expand Down
Loading