Skip to content

invocation_wrapper: support non-POD types using placement new #115

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

Merged
merged 1 commit into from
May 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/acl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,11 +1014,15 @@ static void l_forcibly_release_allocations(cl_context context) {
}

if (context->invocation_wrapper) {
unsigned i;
for (i = 0; i < context->num_invocation_wrappers_allocated; i++) {
if (context->invocation_wrapper[i]->image->arg_value)
acl_delete_arr(context->invocation_wrapper[i]->image->arg_value);
acl_free(context->invocation_wrapper[i]);
for (unsigned int i = 0; i < context->num_invocation_wrappers_allocated;
i++) {
auto *const wrapper = context->invocation_wrapper[i];
if (wrapper->image->arg_value) {
acl_delete_arr(wrapper->image->arg_value);
}
// invoke non-default destructors of non-POD types, e.g., std::vector
wrapper->~acl_kernel_invocation_wrapper_t();
acl_free(wrapper);
}
acl_free(context->invocation_wrapper);
context->invocation_wrapper = 0;
Expand Down Expand Up @@ -1208,6 +1212,8 @@ l_init_kernel_invocation_wrapper(acl_kernel_invocation_wrapper_t *wrapper,
acl_assert_locked();

if (wrapper) {
// invoke non-default constructors of non-POD types, e.g., std::vector
new (wrapper) acl_kernel_invocation_wrapper_t{};
wrapper->id = i;
wrapper->image = &(wrapper->image_storage);
wrapper->image->arg_value = nullptr;
Expand Down