On Freitag 08 Januar 2010, Imran Haque wrote: > Hi, > > I'm trying to write a library to support multiple GPUs in one Python > thread, using the context-juggling approach suggested in the FAQ, but > I'm having issues getting it to work properly. The general objective is > to have each library master object be associated with its own CUDA > context so that the user code can instantiate several objects, one (or > more, for whatever reason) for each GPU. The library methods should deal > with pushing and popping their contexts.
I've fought a number of battles with Nvidia's craptastic context API, I'd love to finally get this right. (CL is much saner.) First of all, when you work with multiplie contexts, please use PyCUDA from git, if you aren't already. It's definitely more correct than 0.93, but it's not there yet. (where correct means no crashes and no unjustified warnings, no matter what you do) > The first problem (which is to say, the one for which I've currently got > a minimal test case :)) is that I can't figure out how to get cleanup at > the end of the program to work properly. > > Here's minimal test case 1: > ---------- > #!/usr/bin/python > > import pycuda.driver as cuda > cuda.init() > print "Initialized CUDA" > > class gpuObject: > def __init__(self,deviceID=0): > self.device = cuda.Device(deviceID) > self.context = self.device.make_context(cuda.ctx_flags.SCHED_YIELD) Add self.context.pop() here. Context creation contains an implicit activation. If you add that, the git version executes your example without a problem. The bad news was that when I started testing, it crashed once I added a call to method1. > def method1(self): > self.context.push() > # Do some work... > self.context.pop() > > def main(): > gpu0 = gpuObject(0) > gpu1 = gpuObject(1) > > if __name__ == "__main__": > main() > --------- I've spent another rather puzzling debugging session, only to find out that shared_ptrs held by Boost.Python apparently don't work well with weak_ptrs. I arrived at the conclusion that the entire notion of keeping PyCUDA's context stack as weak_ptrs is ill-conceived, and I've changed the code to hold shared_ptrs instead. As a result, the "destroying context in context stack" warning is also gone--contexts will leak unless they're explicitly popped off the context stack, which seems legitimate. Long story short, your example appears to work with the git version now. (with and without the method1 call). Please test, and let me know. (Daniel: how does your issue look after these fixes?) Andreas
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ PyCUDA mailing list [email protected] http://tiker.net/mailman/listinfo/pycuda_tiker.net
