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

SWDEV-506793 - segfault in ihipMallocManaged when no devices are available #122

Open
wants to merge 2 commits into
base: amd-staging
Choose a base branch
from

Conversation

benrichard-amd
Copy link

A segfault was occurring immediately in HIP programs that uses static managed memory (i.e. globals with __managed__ modifier).

This avoids a segfault in ihipMallocManaged() when no devices are available. And because this happens during initialization before entering main(), we do not abort. Instead, the managed pointer is set to nullptr.

@@ -287,6 +287,10 @@ hipError_t ihipMallocManaged(void** ptr, size_t size, unsigned int align) {
assert((hip::host_context != nullptr) && "Current host context must be valid");
amd::Context& ctx = *hip::host_context;

if (ctx.devices().size() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

HIP_INIT_API macro already validates the active devices. I don't see why we need extra validation, unless something else is broken.

#define HIP_INIT_API(cid, ...)
HIP_INIT_API_INTERNAL(0, cid, VA_ARGS)
if (hip::g_devices.size() == 0) {
HIP_RETURN(hipErrorNoDevice);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Just validate the devices in __hipRegisterManagedVar() itself.

void __hipRegisterManagedVar(
. . .
HIP_INIT_VOID();
hipError_t status = ihipMallocManaged(pointer, size, align);

Copy link
Author

Choose a reason for hiding this comment

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

Moved device count check to __hipRegisterManagedVar().

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.

2 participants