Skip to content

Conversation

kboyarinov
Copy link
Contributor

Description

Improve function_task::cancel to propagate the cancellation signal

Fixes # - issue number(s) if exists

Type of change

Choose one or multiple, leave empty if none of the other choices apply

Add a respective label(s) to PR if you have permissions

  • bug fix - change that fixes an issue
  • new feature - change that adds functionality
  • tests - change in tests
  • infrastructure - change in infrastructure and CI
  • documentation - documentation update

Tests

  • added - required for new features and some bug fixes
  • not needed

Documentation

  • updated in # - add PR number
  • needs to be updated
  • not needed

Breaks backward compatibility

  • Yes
  • No
  • Unknown

Notify the following users

List users with @ to send notifications

Other information

…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part3' into dev/kboyarinov/poc-dynamic-dependencies-cancellation-support
@kboyarinov kboyarinov added this to the 2022.3.0 milestone Jul 21, 2025
…dencies-part2' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part2.5' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part3' into dev/kboyarinov/poc-dynamic-dependencies-cancellation-support
@kboyarinov kboyarinov changed the title Implementation of task_group dynamic dependencies - part 4 - support for task cancellation Implementation of task_group dynamic dependencies - part 5 - support for task cancellation Aug 18, 2025
Comment on lines +108 to +109
// TODO: complete_and_try_get_successor returns one ready successor task, others are spawned and cancelled by the scheduler
// Should cancel() be called directly instead?
Copy link
Contributor

Choose a reason for hiding this comment

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

The tradeoff is not obvious. Spawning carries some overhead but allows finalization to be done by multiple threads. And we cannot predict how many tasks are there for finalization. Perhaps some experimentation is needed to see how many (in the order of magnitude) tasks are needed for the break-even point between the two approaches.

#if __TBB_PREVIEW_TASK_GROUP_EXTENSIONS
// TODO: complete_and_try_get_successor returns one ready successor task, others are spawned and cancelled by the scheduler
// Should cancel() be called directly instead?
task_ptr = this->complete_and_try_get_successor();
Copy link
Contributor

Choose a reason for hiding this comment

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

In the case of cancellation, do we even need to preserve the dependencies? Can the dependency counting to be fully skipped, and instead some marker in task_dynamic_state put in place of the task pointer to indicate that the task has been taken for cancellation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like this is not that straightforward to implement. Consider submitting the predecessor task_handle and not submitting the successor handle with the cancelled execution.
Since there are not dependencies for the predecessor task, it would be cancelled by the scheduler. Yes, we can mark the successor list of the predecessor as completed (or using the special flag), but what should we do with the successor list.
I don't think that cancelling all of the tasks without dependency counting is a good idea, since the successor would be cancelled before being submitted for execution in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way, the "correct" support for cancellation needs to be reconsidered in a similar way with the partial graph destruction. Imagine cancelling some of the tasks and then resetting the task_group_context.
The idea of this patch is to avoid hangs on waiting if the execution is cancelled as a "preliminary" support for cancellation.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, we have more open questions to add to the design RFC it seems.

@kboyarinov kboyarinov changed the title Implementation of task_group dynamic dependencies - part 5 - support for task cancellation Implementation of task_group dynamic dependencies - part 4 - support for task cancellation Aug 26, 2025
…dencies-part1' into dev/kboyarinov/poc-dynamic-dependencies-part3
…dencies-part3' into dev/kboyarinov/poc-dynamic-dependencies-cancellation-support
Base automatically changed from dev/kboyarinov/poc-dynamic-dependencies-part3 to dev/kboyarinov/poc-dynamic-dependencies-part1 August 28, 2025 14:28
@@ -338,6 +338,7 @@ d1::task* task_dispatcher::local_wait_for_all(d1::task* t, Waiter& waiter ) {

ITT_CALLEE_ENTER(ITTPossible, t, itt_caller);

m_innermost_running_task = t;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same double setting of m_innermost_running_task issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebased to part1 after merging the transferring support. Resolved.

…dencies-part1' into dev/kboyarinov/poc-dynamic-dependencies-cancellation-support
Copy link
Contributor

@vossmjp vossmjp left a comment

Choose a reason for hiding this comment

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

I would suggest (at some point) adding a test that runs at least some part of the task graph before the task_group is canceled. So probably, cancel from within a task at an intermediate level.

@kboyarinov kboyarinov merged commit cde849b into dev/kboyarinov/poc-dynamic-dependencies-part1 Aug 28, 2025
26 checks passed
@kboyarinov kboyarinov deleted the dev/kboyarinov/poc-dynamic-dependencies-cancellation-support branch August 28, 2025 16:24
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.

4 participants