Skip to content

Generalizing the VM buffer type and adding VM buffer ops.#5748

Merged
benvanik merged 3 commits into
mainfrom
benvanik-vm-buffers
May 6, 2021
Merged

Generalizing the VM buffer type and adding VM buffer ops.#5748
benvanik merged 3 commits into
mainfrom
benvanik-vm-buffers

Conversation

@benvanik
Copy link
Copy Markdown
Collaborator

@benvanik benvanik commented May 5, 2021

Previously the VM had a special builtin for read-only buffers and it was always just a placeholder for something more meaningful. This is the start of that. This implementation will undergo a lot of changes as VMVX is brought up but is the first wave of work to unblock that exploration.

vm.list/iree_vm_list_t are useful for storing reference-counted objects and heterogeneous element types and supports resizing, and this new vm.buffer/iree_vm_buffer_t is useful for fast access to fixed-length sets of primitive values with the ability to bitcast the storage. The buffer is access checked (preventing writes to read-only memory), origin checked (preventing inadvertent lifetime extension), bounds checked/alignment-enforced, and is a ref object like any other so that proper lifetime is tracked across host/guest/module boundaries.

The intent is to have a memory-safe byte buffer that supports external host memory, read-only mapped buffer memory (.rodata sections), and read/write memory allocated from within the user VM code. There's a long list of ops in the HAL that needed this (such as hal.command_buffer.update_buffer) and techniques like uniform buffers or mapping memory directly from devices into VM-accessible data.

The op set here is relatively mundane with malloc, memset, memcmp, memcpy, etc and typed load/store routines. Future extensions to this can add more ways of loading/storing such as multi-value loads/stores to reduce overhead - VMVX may use that to emulate vector loads/stores, for example, with a vm.buffer.load.i16x32.

@benvanik benvanik added the runtime/vm IREE bytecode VM interpreter label May 5, 2021
@google-cla google-cla Bot added the cla: yes label May 5, 2021
@benvanik benvanik force-pushed the benvanik-vm-buffers branch from 2a82a27 to bbd2898 Compare May 5, 2021 19:43
@benvanik benvanik requested a review from ScottTodd May 5, 2021 19:43
@benvanik
Copy link
Copy Markdown
Collaborator Author

benvanik commented May 5, 2021

(still a few tests to write, but otherwise ready for review I think)

@benvanik benvanik marked this pull request as ready for review May 5, 2021 19:43
@benvanik benvanik force-pushed the benvanik-vm-buffers branch from bbd2898 to fcee6b5 Compare May 6, 2021 00:05
@benvanik benvanik added the codegen/vmvx VMVX (IREE VM) code generation compiler backend label May 6, 2021
@benvanik benvanik force-pushed the benvanik-vm-buffers branch from fcee6b5 to 70502d6 Compare May 6, 2021 02:57
Copy link
Copy Markdown
Member

@ScottTodd ScottTodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real comments :P

Straightforward buffer manipulation code that fits into the rest of the VM nicely. Thanks for the header file comments and explicit access types.

@benvanik benvanik merged commit a481b6d into main May 6, 2021
@benvanik benvanik deleted the benvanik-vm-buffers branch May 6, 2021 21:23
hcindyl added a commit to hcindyl/iree that referenced this pull request May 7, 2021
Update with the identifier changes in iree-org#5748
@ScottTodd ScottTodd mentioned this pull request May 7, 2021
hcindyl added a commit that referenced this pull request May 7, 2021
Update with the identifier change in #5748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen/vmvx VMVX (IREE VM) code generation compiler backend runtime/vm IREE bytecode VM interpreter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants