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

Simplify handling of mixed memory management (umpire and non-umpire memory) #869

Open
olesenm opened this issue Feb 13, 2024 · 1 comment

Comments

@olesenm
Copy link

olesenm commented Feb 13, 2024

For the upstream integration of AMD OpenFOAM changes by @suyashtn et al., it would be useful to easily handle (delete) memory that may or may not have been managed by umpire.

For this to work, would ideally wish to either have a return value from the ResourceManager::deallocate() or have a non-failing query for the associated allocator (if any).

For example,

auto& rm = umpire::ResourceManager::getInstance();
auto* strategy = rm.hasAllocationStrategy(ptr);   //  Like findAllocatorForPointer(), but non-failing

if (strategy)
{
    // call Allocator(strategy).deallocate(....);   - except that is a private constructor and really messy
}
else
{
    // Not managed by umpire
    delete ptr;
}

Another alternative might be to have a non-failing deallocate that returns a value.
For example,

auto& rm = umpire::ResourceManager::getInstance();

if (!rm.try_dealloc(ptr))
{
    // Not managed by umpire
    delete ptr;
}

I'm open to any simple solution that doesn't involve a try/catch.

@olesenm
Copy link
Author

olesenm commented Feb 14, 2024

Suggested by @davidbeckingsale (off-line):

auto& rm = umpire::ResourceManager::getInstance();

if (rm.hasAllocator(ptr))
{
    rm.deallocate(ptr);
}
else
{ 
    delete ptr:
}

This is indeed adequate for the purpose, but does do a double lookup (first for the hasAllocator, second for the deallocate call), which may be preferable to avoid.

However, feel free to close with comment if you'd prefer to leave the API as is.

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

No branches or pull requests

1 participant