Skip to content

Add parameter to destroy upstream_memory_provider in finalize() #806

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

Conversation

ldorau
Copy link
Contributor

@ldorau ldorau commented Oct 17, 2024

Description

Add parameter to destroy upstream_memory_provider in finalize().

Checklist

  • Code compiles without errors locally
  • All tests pass locally
  • CI workflows execute properly

@ldorau ldorau requested a review from a team as a code owner October 17, 2024 12:02
@bratpiorka
Copy link
Contributor

why do we need this parameter? If the user creates an upstream provider, why can't he destroy it?

@ldorau
Copy link
Contributor Author

ldorau commented Oct 17, 2024

why do we need this parameter? If the user creates an upstream provider, why can't he destroy it?

In order to prevent a memory leak in our tests using the umfPoolTest fixture (see: #808) the upstream provider has to be destroyed automatically.

@igchor
Copy link
Member

igchor commented Oct 17, 2024

why do we need this parameter? If the user creates an upstream provider, why can't he destroy it?

In order to prevent a memory leak in our tests using the umfPoolTest fixture (see: #808) the upstream provider has to be destroyed automatically.

If it's only for tests then you can prevent the leak by just destroying the provider in pool_unique_handle_t. You just need to modify this line:

return umf::pool_unique_handle_t(hPool, &umfPoolDestroy);

To be something like this:

auto dtor = [coarse_provider ](umf_memory_pool_handle_t pool) {
    umfPoolDestory(pool):
    umfMemoryProviderDestory(coarse_provider );
};
return umf::pool_unique_handle_t(hPool, std;:move(dtor));

@ldorau ldorau force-pushed the Add_parameter_to_destroy_upstream_memory_provider_in_finalize branch from 8f263da to 3be7e4a Compare October 17, 2024 19:29
@ldorau
Copy link
Contributor Author

ldorau commented Oct 17, 2024

why do we need this parameter? If the user creates an upstream provider, why can't he destroy it?

In order to prevent a memory leak in our tests using the umfPoolTest fixture (see: #808) the upstream provider has to be destroyed automatically.

If it's only for tests then you can prevent the leak by just destroying the provider in pool_unique_handle_t. You just need to modify this line:

return umf::pool_unique_handle_t(hPool, &umfPoolDestroy);

To be something like this:

auto dtor = [coarse_provider ](umf_memory_pool_handle_t pool) {
    umfPoolDestory(pool):
    umfMemoryProviderDestory(coarse_provider );
};
return umf::pool_unique_handle_t(hPool, std;:move(dtor));

Thanks @igchor ! I applied that in #808.

@ldorau ldorau closed this Oct 17, 2024
@ldorau ldorau deleted the Add_parameter_to_destroy_upstream_memory_provider_in_finalize branch October 17, 2024 20:15
@vinser52
Copy link
Contributor

why do we need this parameter? If the user creates an upstream provider, why can't he destroy it?

@igchor @bratpiorka @ldorau

But what if the user creates a memory pool with the UMF_POOL_CREATE_FLAG_OWN_PROVIDER flag? In that case, the user expects that the pool destructor will destroy the memory provider used by the pool. And in case the coarse provider is used, it is destroyed automatically, but the upstream memory provider is not.

Did I miss something?

@ldorau
Copy link
Contributor Author

ldorau commented Oct 18, 2024

why do we need this parameter? If the user creates an upstream provider, why can't he destroy it?

@igchor @bratpiorka @ldorau

But what if the user creates a memory pool with the UMF_POOL_CREATE_FLAG_OWN_PROVIDER flag? In that case, the user expects that the pool destructor will destroy the memory provider used by the pool. And in case the coarse provider is used, it is destroyed automatically, but the upstream memory provider is not.

Did I miss something?

@vinser52 You are right. It seems this parameter is needed when UMF_POOL_CREATE_FLAG_OWN_PROVIDER is used.
@bratpiorka @lplewa Do you agree?

@ldorau ldorau restored the Add_parameter_to_destroy_upstream_memory_provider_in_finalize branch October 18, 2024 06:51
@bratpiorka
Copy link
Contributor

@ldorau agree + please add test for this (for both cases - when UMF_POOL_CREATE_FLAG_OWN_PROVIDER is set to true and false)

@ldorau ldorau reopened this Oct 21, 2024
@ldorau ldorau force-pushed the Add_parameter_to_destroy_upstream_memory_provider_in_finalize branch from 3be7e4a to 9f6eb80 Compare October 21, 2024 07:17
@ldorau
Copy link
Contributor Author

ldorau commented Oct 21, 2024

@ldorau agree + please add test for this (for both cases - when UMF_POOL_CREATE_FLAG_OWN_PROVIDER is set to true and false)

@bratpiorka Done

@ldorau ldorau force-pushed the Add_parameter_to_destroy_upstream_memory_provider_in_finalize branch from 9f6eb80 to 7a210f0 Compare October 21, 2024 07:24
Copy link
Contributor

@lukaszstolarczuk lukaszstolarczuk left a comment

Choose a reason for hiding this comment

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

👍

@@ -898,6 +901,13 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

if (coarse_params->destroy_upstream_memory_provider &&
!coarse_params->upstream_memory_provider) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the coarse provider always require the upstream provider to be specified?

What is the reason for not specifying the upstream provider? @bratpiorka what do you think?

P.S. I understand that it is out of scope for this particular PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The coarse provider contains the fixed provider yet - in the case of the fixed provider the upstream provider is not required. The fixed provider will be moved to a separate provider and the upstream provider will be always required then.

@ldorau ldorau merged commit 2e740f6 into oneapi-src:main Oct 21, 2024
74 checks passed
@ldorau ldorau deleted the Add_parameter_to_destroy_upstream_memory_provider_in_finalize branch October 21, 2024 12:35
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