This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] libomptarget / CUDA plugin: Check for existing CUDA context before new context creation
AbandonedPublic

Authored by grokos on Jun 28 2017, 8:27 PM.

Details

Summary

This commit checks for an existing CUDA context (using cuCtxGetCurrent), before creating a new context. If an existing context exists, no new context is created. This change ensures that all allocations made in the program interacting with the openmp offload library are visible in the device context; especially important for CUDA managed allocations (using cudaMallocManaged).

For the existing version, if a context exists, the cuCtxCreate call fails, and hence all further allocations crash.

Thanks to Hashim Sharif, University of Illinois at Urbana, for spotting the problem and submitting the original patch.

Diff Detail

Repository
rL LLVM

Event Timeline

grokos created this revision.Jun 28 2017, 8:27 PM
grokos abandoned this revision.Jun 28 2017, 9:12 PM

It seems there is a bug but it's not related to context creation. False alarm, I'm cancelling the revision. Sorry for that...

It seems there is a bug but it's not related to context creation. False alarm, I'm cancelling the revision. Sorry for that...

What do you mean?

libomptarget/plugins/cuda/src/rtl.cpp
257

Spaces needed before/after parens.

What do you mean?

Hashim Sharif had some issues with managed allocations which went away when he applied this patch onto his local branch. However the patch is definitely wrong, it doesn't do what I thought it does. It actually sets the context on all devices to the same context (cuCtxGetCurrent does not retrieve the context from DeviceInfo.Contexts[device_id], rather it gets the context from the current host thread and assigns it to DeviceInfo.Contexts[device_id] - this way all devices get the context of the first device to be initialized...).

I have requested a test case demonstrating Hashim's problem, once I've got got I'll get back to you with an exact description of the problem and a proposed solution.