Pycuda With Flask Gives Pycuda._driver.logicerror: Cumoduleloaddataex
Solution 1:
Solved the issue with lazy loading in flask
and making the context
manually (i.e. without pycuda.autoinit
in PyCUDA
.
Refer this for lazy loading in flask
.
My views.py
file:
import numpy as np
import pycuda.driver as cuda
from pycuda.compiler import SourceModule
defindex():
cuda.init()
device = cuda.Device(0) # enter your gpu id here
ctx = device.make_context()
mod = SourceModule("""
int x = 4;
""")
ctx.pop() # very importantprint ("done")
return"success"
Solution 2:
PyCUDA may not be compatible with WSGI web server contexts. You could possibly make it work if you use some kind of message queue like Celery, where the HTTP request places a job on the queue and the worker on the other side of the queue runs the CUDA program.
Edit: A quick and easy way would be to use Python Subprocess check_output function
In the web request:
subprocess.check_output(['python', 'cudaFlask.py'])
Solution 3:
According to your solution I changed my code from
def print_device_info():
(free,total)=drv.mem_get_info()
print("Global memory occupancy:%f%% free"%(free*100/total))
for devicenum in range(cuda.Device.count()):
device=drv.Device(devicenum)
attrs=device.get_attributes()
#Beyond this point is just pretty printing
print("\n===Attributes for device %d"%devicenum)
for (key,value) in attrs.iteritems():
print("%s:%s"%(str(key),str(value)))
to
def print_device_info():
drv.init()
device = drv.Device(0) # enter your gpu id here
ctx = device.make_context()
(free,total)=drv.mem_get_info()
print("Global memory occupancy:%f%% free"%(free*100/total))
attrs=device.get_attributes()
#Beyond this point is just pretty printing
print("\n===Attributes for device %d"%0)
for (key,value) in attrs.items():
print("%s:%s"%(str(key),str(value)))
ctx.pop()
and it works like a charm. Thank you so much for sharing your solution, this really made my day !
Solution 4:
Starting the Flask application in non-threaded mode:
app.run(host=HOST, port=PORT, debug=False,threaded=False)
Post a Comment for "Pycuda With Flask Gives Pycuda._driver.logicerror: Cumoduleloaddataex"