Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROTOTYPE] Add unused temporary storage to single work-group scan to fix use-after free error #1712

Conversation

adamfidel
Copy link
Contributor

We were throwing away the result and scratch container inside of the future in __parallel_transform_scan because we needed to return a future without storage. This was causing a use-after free error because the scratch storage was freed before it was used in the kernel.

@@ -681,6 +681,10 @@ __parallel_transform_scan_single_group(oneapi::dpl::__internal::__device_backend
// Specialization for devices that have a max work-group size of 1024
constexpr ::std::uint16_t __targeted_wg_size = 1024;

using _ValueType = typename _InitType::__value_type;
using _TempStorage = __result_and_scratch_storage<std::decay_t<_ExecutionPolicy>, _ValueType>;
_TempStorage __result_and_scratch{__exec, 0};
Copy link
Contributor

@danhoeflinger danhoeflinger Jul 18, 2024

Choose a reason for hiding this comment

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

Can we name this __dummy_result_and_scratch or something similar to draw attention to why this is here but unused in practice?

Also can we add a comment explaining the purpose of this dummy scratch space?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed it and added a comment explaining why it's here.

@@ -699,17 +703,17 @@ __parallel_transform_scan_single_group(oneapi::dpl::__internal::__device_backend
::std::integral_constant<::std::uint16_t, __num_elems_per_item>, _BinaryOperation,
/* _IsFullGroup= */ std::true_type, _Inclusive, _CustomName>>>()(
::std::forward<_ExecutionPolicy>(__exec), std::forward<_InRng>(__in_rng),
std::forward<_OutRng>(__out_rng), __n, __init, __binary_op, __unary_op);
std::forward<_OutRng>(__out_rng), __n, __init, __binary_op, __unary_op, __result_and_scratch);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to pass this scratch space in only to return it?
Perhaps it is more clear if we instead return an event from the submitter, and construct the future here with the dummy variable. It would make it more clear that it goes unused, and minimize the changes required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I changed the submitters to return an event and constructed the future in the outer context instead.

Copy link
Contributor

@mmichel11 mmichel11 left a comment

Choose a reason for hiding this comment

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

LGTM

@danhoeflinger
Copy link
Contributor

LGTM (from phone)

@adamfidel adamfidel merged commit fab0445 into dev/shared/reduce_then_scan_impl Jul 18, 2024
@adamfidel adamfidel deleted the dev/adamfidel/reduce_then_scan_use_after_free branch July 18, 2024 22:17
adamfidel added a commit that referenced this pull request Jul 24, 2024
mmichel11 pushed a commit that referenced this pull request Jul 31, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 5, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 6, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 6, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 7, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 7, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 8, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 8, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 8, 2024
danhoeflinger pushed a commit that referenced this pull request Aug 14, 2024
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.

3 participants