Hi,

I've made some progress in this by moving the GPU initialization and source 
module compilation within the active function:

class GPU():

   def __init__(self):
       self.kernel_code = '''...'''

   def culsp(self, data, params):
       # Initialize GPU
       import pycuda.autoinit
       mod = compiler.SourceModule(self.kernel_code)
       cuker = mod.get_function('culsp_kernel')
       # Call function
       cuker(data, params)

When CherryPy receives an HTTP GET, it calls culsp with the data and params. 
This now works the first time it is called when CherryPy is running but 
subsequent calls give:

    mod = compiler.SourceModule(self.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

So it looks like with subsequent calls to the function (new thread), no context 
can be established. I'm sure that there must a simple way to do this?

        Cheers,

        Matthew



On Sep 1, 2011, at 11:15 AM, Josh Bleecher Snyder wrote:

> 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
> 


_______________________________________________
PyCUDA mailing list
PyCUDA@tiker.net
http://lists.tiker.net/listinfo/pycuda

Reply via email to