Skip to content

[vulkan] Release timepoint fences more aggressively when possible - #2800

Merged
antiagainst merged 7 commits into
iree-org:mainfrom
antiagainst:fix-fence-release
Aug 27, 2020
Merged

antiagainst merged 7 commits into
iree-org:mainfrom
antiagainst:fix-fence-release

Conversation

@antiagainst

Copy link
Copy Markdown
Member

In the emulated timeline semaphore, we use VkFence as a way to
probe the status of submissions. This is needed for both the
emulated timeline semaphores and the serializing queue itself
because we can wait on either the timeline semaphore or the queue.
This requires us to hold ref ptrs to the timepoint fence in both
the timeline semaphore and the queue. The expectation is that when
both releases the ref ptr, the fence can be automatically released
to the pool.

However, the ref ptr held in the queue can typically linger on
longer because we normally don't wait queue/device idle until
the very last when all work are done. Because of the ref hold
there, the fences will not be released.

This commit adds another callback to let the emulated timeline
semaphore to inform the queue when some fences are known to
have signaled (because the timeline signaled passing a certain
value tracked by the fence), so that we can more aggressively
drop the ref ptr inside the serializing queue.

At the same time, reduces the number of initial VkFence requested.

Fixes #2526

In the emulated timeline semaphore, we use VkFence as a way to
probe the status of submissions. This is needed for both the
emulated timeline semaphores and the serializing queue itself
because we can wait on either the timeline semaphore or the queue.
This requires us to hold ref ptrs to the timepoint fence in both
the timeline semaphore and the queue. The expectation is that when
both releases the ref ptr, the fence can be automatically released
to the pool.

However, the ref ptr held in the queue can typically linger on
longer because we normally don't wait queue/device idle until
the very last when all work are done. Because of the ref hold
there, the fences will not be released.

This commit adds another callback to let the emulated timeline
semaphore to inform the queue when some fences are known to
have signaled (because the timeline signaled passing a certain
value tracked by the fence), so that we can more aggressively
drop the ref ptr inside the serializing queue.

At the same time, reduces the number of initial VkFence requested.

Fixes iree-org#2526
@antiagainst

Copy link
Copy Markdown
Member Author

Note that this should fix #2526; the failure is actually another issue tracked by #2659..

@ScottTodd ScottTodd added runtime Relating to the IREE runtime library hal/vulkan Runtime Vulkan GPU HAL backend labels Aug 6, 2020
Comment thread integrations/tensorflow/e2e/BUILD Resolved
uint64_t to_upper_value) {
IREE_TRACE_SCOPE0("EmulatedTimelineSemaphore::TryToAdvanceTimeline");
absl::InlinedVector<VkFence, 4> signaled_fences;
auto status = TryToAdvanceTimeline(to_upper_value, &signaled_fences);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why defer checking the status until after calling on_fence_signal_?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think it matters that much? If errors happen, either returning immediately or still sending the queue a notice to clean up something are both okay to me..

@antiagainst

Copy link
Copy Markdown
Member Author

@hanhanW FYI

@antiagainst

Copy link
Copy Markdown
Member Author

Thanks @ScottTodd! :D

@ScottTodd

Copy link
Copy Markdown
Member

Thanks @ScottTodd! :D

No problem, sorry for letting this sit for so long x_x

@antiagainst
antiagainst merged commit 6db4e7b into iree-org:main Aug 27, 2020
@antiagainst
antiagainst deleted the fix-fence-release branch August 27, 2020 15:50
@antiagainst

Copy link
Copy Markdown
Member Author

No worries. :) Gonna be cautious on changes related to timeline semaphore. ;-P

hanhanW added a commit that referenced this pull request Aug 27, 2020
With #2904 and #2800, the issue on SwiftShader is resolved.

Fixes #3007
@rsuderman rsuderman mentioned this pull request Aug 27, 2020
copybara-service Bot pushed a commit that referenced this pull request Aug 27, 2020
* aa8d1c0 Enable simple.mlir test for iree-benchmark-module on vulkan (#3016)
* 6db4e7b [vulkan] Release timepoint fences more aggressively when possible (#2800)
* a1365d3 [vulkan] Do not request timeline semaphore if not available (#2904)
* a38c890 Add more type support to model builder matmul benchmark. (#2977)
* a293ca7 Fix hyperlink to getting started docs on python page. (#3015)
* b022e70 Release inputs before closing the session. (#3004)
* f1678df Dynamicly register benchmark for entry_function with name BM_{entry_function} ..
* 6282700 Expand the tf_module_to_compiler_module API (#3009)
* f7e561a Merge pull request #3006 from rsuderman/google-to-main
* 8341d71 Explicitly insert dialects in conversion passes (#3002)
* b7c2b60 Fix format by changing to LLVM style (#3008)
* 4286f17 Merge branch 'main' into google-to-main
* f0a07f6 Allow iree.placeholder as an op between splittable ops. (#2999)
* 6bd3b1d Use hidden visibility for all symbols by default (#2997)
* d650082 VMLA Dynamic Iota support with Shape dialect work. (#2965)
* c724ee4 Add function to hide SavedModel roundtrip (#2995)
* 2fedce6 Merge pull request #2996
* c5f7030 Merge branch 'main' into google-to-main
* cf3211d [vulkan] Reset TimePointFence status when releasing back to pool (#2905)
* ebc6a83 Add lint action to check for tabs (#2984)
* 932339c Merge pull request #2964 from silvasean/add-dynamic-dot-example
* df727ae Integrate MLIR-EmitC at iml130/mlir-emitc@560cd8c (#2990)
* e824d36 Refactor for explicit dialect registration (#2978)
* 38b7d2c Allow ModelRunner to receive an array of extra symbols available during JITing..
* 264a97d Fuse linalg.tensor_reshape operations with hal.interface* operations. (#2973)
* 0e3c737 Fold flow.tensor.update when all operands are constant (#2982)
* c7a21c2 Merge pull request #2983 from rsuderman/google-to-main
* fd55a86 Add a dynamically shaped mhlo.dot lowering example

COPYBARA_INTEGRATE_REVIEW=#3018 from rsuderman:main-to-google 4a9ea02
PiperOrigin-RevId: 328784816
This was referenced Aug 27, 2020
copybara-service Bot pushed a commit that referenced this pull request Aug 27, 2020
* 0c97a1c Merge pull request #3022 from rsuderman/google-to-main
* bf264f4 Merge branch 'main' into google-to-main
* 8524cb9 Split LLVM targets into subfolders to support CMake filtering. (#2960)
* 6e78211 Fixed Emulator Timeline Semaphore parameter name (#3019)
* aa8d1c0 Enable simple.mlir test for iree-benchmark-module on vulkan (#3016)
* 6db4e7b [vulkan] Release timepoint fences more aggressively when possible (#2800)
* a1365d3 [vulkan] Do not request timeline semaphore if not available (#2904)
* a38c890 Add more type support to model builder matmul benchmark. (#2977)
* a293ca7 Fix hyperlink to getting started docs on python page. (#3015)
* b022e70 Release inputs before closing the session. (#3004)
* f1678df Dynamicly register benchmark for entry_function with name BM_{entry_function} ..
* 6282700 Expand the tf_module_to_compiler_module API (#3009)
* f7e561a Merge pull request #3006 from rsuderman/google-to-main
* 8341d71 Explicitly insert dialects in conversion passes (#3002)
* b7c2b60 Fix format by changing to LLVM style (#3008)
* 4286f17 Merge branch 'main' into google-to-main
* f0a07f6 Allow iree.placeholder as an op between splittable ops. (#2999)
* 6bd3b1d Use hidden visibility for all symbols by default (#2997)
* d650082 VMLA Dynamic Iota support with Shape dialect work. (#2965)
* c724ee4 Add function to hide SavedModel roundtrip (#2995)
* 2fedce6 Merge pull request #2996
* c5f7030 Merge branch 'main' into google-to-main
* cf3211d [vulkan] Reset TimePointFence status when releasing back to pool (#2905)
* ebc6a83 Add lint action to check for tabs (#2984)
* 932339c Merge pull request #2964 from silvasean/add-dynamic-dot-example
* df727ae Integrate MLIR-EmitC at iml130/mlir-emitc@560cd8c (#2990)
* e824d36 Refactor for explicit dialect registration (#2978)
* 38b7d2c Allow ModelRunner to receive an array of extra symbols available during JITing..
* 264a97d Fuse linalg.tensor_reshape operations with hal.interface* operations. (#2973)
* 0e3c737 Fold flow.tensor.update when all operands are constant (#2982)
* c7a21c2 Merge pull request #2983 from rsuderman/google-to-main
* fd55a86 Add a dynamically shaped mhlo.dot lowering example

COPYBARA_INTEGRATE_REVIEW=#3025 from rsuderman:main-to-google 0c97a1c
PiperOrigin-RevId: 328804964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hal/vulkan Runtime Vulkan GPU HAL backend runtime Relating to the IREE runtime library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

control_flow_test is failing on vulkan backend

2 participants