Skip to content

[HAL] Add command buffer flush and invalidate operations - #24945

Merged
AGindinson merged 1 commit into
iree-org:mainfrom
purnima-nlp:stream-flush-invalidate-lowering
Oct 13, 2026
Merged

AGindinson merged 1 commit into
iree-org:mainfrom
purnima-nlp:stream-flush-invalidate-lowering

Conversation

@purnima-nlp

@purnima-nlp purnima-nlp commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds HAL and runtime plumbing for ordered command-buffer buffer flush and invalidate operations.

It introduces:

  • hal.command_buffer.flush_buffer
  • hal.command_buffer.invalidate_buffer
  • HAL-to-VM lowering and VM imports
  • runtime command-buffer API and vtable hooks
  • VM module/shim plumbing
  • inline command-buffer support
  • deferred command-buffer recording/replay support
  • HAL IR and HAL-to-VM test coverage

The operations carry a buffer reference, offset, and length and are intended to represent execution-ordered cache maintenance for shared non-coherent memory.

Stream-to-HAL lowering is intentionally left unchanged in this PR. Some backends, especially Vulkan, require queue/submission-level handling to preserve execution-time ordering because a HAL command buffer is currently replayed into a single native VkCommandBuffer. Enabling Stream lowering before that backend support exists could cause unsupported runtime paths.

This PR therefore focuses on establishing the HAL/runtime infrastructure first. Backend-specific execution support and Stream lowering can follow separately.

Related to #24930.

AI Tool Disclosure
Assisted by codex for code base exploration

@github-actions

Copy link
Copy Markdown

Hello @purnima-nlp 👋

Thank you for submitting a Pull Request to IREE! It looks like this is your first one. We have one ask, and you can also find some general tips below.


Action required: acknowledge IREE project policies

IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.

All contributions to IREE must follow our IREE AI Tool Use Policy. In particular:

  • Contributors must fully understand, and vouch for, all submitted changes and the intent behind them.
  • Substantial use of LLM/generative AI tools must be noted in the PR description, e.g. via Assisted-by: tool-name or Co-authored-by: tool-name tool@email trailers.
  • Contributors must write PR descriptions themselves. There must always be a human in the loop: contributors must respond to reviews and questions by themselves.
    If a response includes LLM-assisted segments (e.g. reproducers, LLM agent analysis excerpts), the segment should be clearly marked as "assisted", same as for PR contents.
  • GitHub issues labeled as "Good first issue" are explicitly designated as learning opportunities for newcomers to the project. With exceptions for boilerplate edits, AI tool usage for resolutions to such issues is forbidden.

We kindly ask you to reply to this message and confirm that you understand and accept the cited policies, particularly the AI Tool Use Policy.


General guidance

Our general Contributing guide contains information and links to detailed guides on code quality, testing, commit summaries and our CI system.

A common point for new PRs: if a DCO signing check fails for you, check out the section on Developer Certificate of Origin.
In these cases, it should suffice to amend your commit signature(s) per the guide and force-push the PR branch.

If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.

Thank you,
The IREE Community

@devtbi

devtbi commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

@purnima-nlp could you take a moment to read & acknowledge the policies?
Also DCO and linting CI is failing

@purnima-nlp

Copy link
Copy Markdown
Contributor Author

Hello @purnima-nlp 👋

Thank you for submitting a Pull Request to IREE! It looks like this is your first one. We have one ask, and you can also find some general tips below.

Action required: acknowledge IREE project policies

IREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct.

All contributions to IREE must follow our IREE AI Tool Use Policy. In particular:

  • Contributors must fully understand, and vouch for, all submitted changes and the intent behind them.
  • Substantial use of LLM/generative AI tools must be noted in the PR description, e.g. via Assisted-by: tool-name or Co-authored-by: tool-name tool@email trailers.
  • Contributors must write PR descriptions themselves. There must always be a human in the loop: contributors must respond to reviews and questions by themselves.
    If a response includes LLM-assisted segments (e.g. reproducers, LLM agent analysis excerpts), the segment should be clearly marked as "assisted", same as for PR contents.
  • GitHub issues labeled as "Good first issue" are explicitly designated as learning opportunities for newcomers to the project. With exceptions for boilerplate edits, AI tool usage for resolutions to such issues is forbidden.

We kindly ask you to reply to this message and confirm that you understand and accept the cited policies, particularly the AI Tool Use Policy.

General guidance

Our general Contributing guide contains information and links to detailed guides on code quality, testing, commit summaries and our CI system.

A common point for new PRs: if a DCO signing check fails for you, check out the section on Developer Certificate of Origin. In these cases, it should suffice to amend your commit signature(s) per the guide and force-push the PR branch.

If you have any questions, feel free to leave a comment here, or ask away on IREE Discord.

Thank you, The IREE Community

I understand and accept the cited policies

@Manewing Manewing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good so far :) just a few comments

Also, could we add a few runtime tests for the inline and deferred implementations? A mock buffer that tracks flush/invalidate calls should let us check that the calls happen at the right time, receive the correct ranges, and propagate errors. It would also be good to cover missing indirect bindings and the UNIMPLEMENTED fallback. None of that should require support in the other backends.

For copy buffer there already is some test setup in runtime/src/iree/hal/cts/command_buffer/copy_buffer_test.cc I think we can implement the tests in a similar fashion for flush/invalidate

Comment thread runtime/src/iree/hal/command_buffer.c Resolved
Comment thread runtime/src/iree/hal/command_buffer.c Resolved
Comment thread runtime/src/iree/hal/command_buffer.c Resolved
Comment thread runtime/src/iree/hal/command_buffer.h Resolved
@purnima-nlp

Copy link
Copy Markdown
Contributor Author

@Manewing Thanks for the review comments — I’ve started addressing them in focused parts.

So far I’ve updated the generic command-buffer APIs to add validation, replaced the ternary dispatch with explicit handling, added the backend-support FIXME, and clarified the flush/invalidate docs to state that they perform cache maintenance but do not establish execution dependencies.

For the tests, I’m splitting the work like below:

  1. generic API/fallback behavior,
  2. inline command-buffer behavior,
  3. deferred command-buffer behavior.

The generic API tests are now in place and passing. They cover exact buffer-ref forwarding, callback error propagation, zero-length no-op behavior, missing backend callbacks returning UNIMPLEMENTED, and validation of unsupported command categories.

Next I’m adding the inline and deferred tests, including timing/range behavior, indirect bindings, and error propagation as you suggested.

@Murari007 Murari007 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, @purnima-nlp. Linting & DCO issues need to be resolved.

@purnima-nlp
purnima-nlp force-pushed the stream-flush-invalidate-lowering branch from fedad1b to dde0824 Compare September 24, 2026 16:27

@Manewing Manewing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the test cases!

Two things before this can merge:

  • The CI issues need to be addressed
  • I think there is a an issue with current validation. Both new validators leave target_reqs.usage at zero, but iree_hal_command_buffer_validate_binding_requirements treats that as an unused binding and returns immediately. This skips the required-buffer, memory-type, and range checks. Could we ensure flush/invalidate bindings are treated as required and add validation-enabled tests for null and undersized bindings? The null binding could reach inline replay and cause an assertion/null dereference.

@purnima-nlp
purnima-nlp force-pushed the stream-flush-invalidate-lowering branch from dde0824 to 4710eee Compare October 3, 2026 16:45
@purnima-nlp

Copy link
Copy Markdown
Contributor Author

Thanks for adding the test cases!

Two things before this can merge:

  • The CI issues need to be addressed
  • I think there is a an issue with current validation. Both new validators leave target_reqs.usage at zero, but iree_hal_command_buffer_validate_binding_requirements treats that as an unused binding and returns immediately. This skips the required-buffer, memory-type, and range checks. Could we ensure flush/invalidate bindings are treated as required and add validation-enabled tests for null and undersized bindings? The null binding could reach inline replay and cause an assertion/null dereference.

Thanks! I’ve addressed both points:

  • Fixed binding validation so bindings with non-usage requirements are no longer treated as unused. Flush/invalidate bindings now still validate required buffer presence, memory type, and range.
  • Added validation-enabled tests for both flush and invalidate covering null bindings and undersized bindings.

I also fixed the clang-format CI issue locally using the repo’s pre-commit hook. The focused runtime tests are passing: 13 command buffer + 10 inline + 10 deferred tests.

I’ve pushed the updated commit and CI is rerunning now.

@purnima-nlp
purnima-nlp force-pushed the stream-flush-invalidate-lowering branch from 4710eee to 3ee39f5 Compare October 8, 2026 18:32
@purnima-nlp

Copy link
Copy Markdown
Contributor Author

I’ve pushed a small follow-up fix for the Windows MSVC C++17 build failure. The new workflow run is waiting for approval since the PR is from a fork. Could someone please approve the workflow run when convenient?

@purnima-nlp

Copy link
Copy Markdown
Contributor Author

The checks that didn't pass are unrelated to this PR
Can this work may land without these checks?
I don't have the merge access.

@AGindinson
AGindinson merged commit 17fb04d into iree-org:main Oct 13, 2026
55 of 57 checks passed
@devtbi devtbi mentioned this pull request Oct 19, 2026
7 of 8 tasks
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.

5 participants