Perhaps CherryPy is spinning up new Python threads to handle the inbound requests, and the handle to the CUDA context doesn't transfer nicely across threads.
I encountered a similar situation (in a different context), and ended up with a solution in which I have standalone single-threaded worker processes that do the GPU processing, and my request handler communicates with them to get actual processing done. Or perhaps CherryPy has a single-threaded mode... -josh On Thu, Sep 1, 2011 at 8:21 AM, Matthew Graham <m...@cacr.caltech.edu> wrote: > Hi Andreas, > > In both cases, I am the user running the code. > > Cheers, > > Matthew > > > On Sep 1, 2011, at 5:06 AM, Andreas Kloeckner wrote: > >> Hi Matthew, >>Pu >> On Wed, 31 Aug 2011 22:10:33 -0700, Matthew Graham <m...@cacr.caltech.edu> >> wrote: >>> I have some code that runs fine as a standalone routine; however, I want to >>> incorporate it as part of a web service using CherryPy as the hosting >>> framework. When I try and call it from a client, I get: >>> >>> [31/Aug/2011:21:56:38] HTTP Traceback (most recent call last): >>> File >>> "/Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/cherrypy/_cprequest.py", >>> line 606, in respond >>> cherrypy.response.body = self.handler() >>> File >>> "/Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/cherrypy/_cpdispatch.py", >>> line 25, in __call__ >>> return self.callable(*self.args, **self.kwargs) >>> File "tscs.py", line 124, in POST >>> response = self._analyze(data, kwargs) >>> File "tscs.py", line 83, in _analyze >>> row.append(self.stats[statid]['method'](data[id])) >>> File "/Users/mjg/Projects/python/kiss/statistics.py", line 268, in gpuls >>> lsp = Culsp() >>> File "/Users/mjg/Projects/python/kiss/culsp.py", line 146, in __init__ >>> mod = compiler.SourceModule(kernel_code) >>> File >>> "/Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/pycuda-2011.1-py2.6-macosx-10.5-i386.egg/pycuda/compiler.py", >>> line 271, in __init__ >>> arch, code, cache_dir, include_dirs) >>> File >>> "/Library/Frameworks/Python.framework/Versions/6.0.0/lib/python2.6/site-packages/pycuda-2011.1-py2.6-macosx-10.5-i386.egg/pycuda/compiler.py", >>> line 218, in compile >>> arch = "sm_%d%d" % Context.get_device().compute_capability() >>> LogicError: cuCtxGetDevice failed: invalid context >>> >>> Any ideas? I'm running CUDA 4.0 and PyCUDA 2011.1.2. >> >> Have you run your code as the web user? (Often www-data, but maybe >> something different?) Does the same thing happen then? In any case, I >> suspect that this is some permissions/security issue. It might be >> helpful trying to replicate all the restrictions that web >> server-executed code has on it... >> >> HTH, >> Andreas > > > _______________________________________________ > PyCUDA mailing list > PyCUDA@tiker.net > http://lists.tiker.net/listinfo/pycuda > _______________________________________________ PyCUDA mailing list PyCUDA@tiker.net http://lists.tiker.net/listinfo/pycuda