I want to run a pyCUDA code on a flask
server. The file runs correctly directly using python3
but fails when the corresponding function is called u
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
def index():
cuda.init()
device = cuda.Device(0) # enter your gpu id here
ctx = device.make_context()
mod = SourceModule("""
int x = 4;
""")
ctx.pop() # very important
print ("done")
return "success"