@NVES,thanks for your replay.here is the code.
import tensorrt as trt
import pycuda.driver as cuda
import pycuda.autoinit
TRT_LOGGER = trt.Logger()
def get_engine(engineFilePath):
with open(engineFilePath,“rb” ) as f,trt.Runtime(TRT_LOGGRR) as runtime:
return(runtime.deserialize_cuda_engine(f.read()))
@app.route(‘./yoloimg’,methods=[‘’])
def img():
cuda.init()
device = cuda.Device(0)
ctx = device.make_context()
ctx.push()
****
engine = get_engine()
inference code
******
ctx.pop()
above code is ok ,while get_engine take much time,so i want to put the piece code outside of img,looks like
import tensorrt as trt
import pycuda.driver as cuda
import pycuda.autoinit
TRT_LOGGER = trt.Logger()
def get_engine(engineFilePath):
with open(engineFilePath,“rb” ) as f,trt.Runtime(TRT_LOGGRR) as runtime:
return(runtime.deserialize_cuda_engine(f.read()))
++++++engine = get_engine()
@app.route(‘./yoloimg’,methods=[‘’])
def img():
cuda.init()
device = cuda.Device(0)
ctx = device.make_context()
ctx.push()
****
----- engine = get_engine()
inference code
******
ctx.pop()
it will make wrong. i find that if
import tensorrt as trt
import pycuda.driver as cuda
import pycuda.autoinit
+++++cuda.init()
+++++ device = cuda.Device(0)
+++++ctx = device.make_context()
TRT_LOGGER = trt.Logger()
def get_engine(engineFilePath):
with open(engineFilePath,“rb” ) as f,trt.Runtime(TRT_LOGGRR) as runtime:
return(runtime.deserialize_cuda_engine(f.read()))
++++++engine = get_engine()
++++++ctx.push()
@app.route(‘./yoloimg’,methods=[‘’])
def img():
— cuda.init()
— device = cuda.Device(0)
— ctx = device.make_context()
ctx.push()
****
----- engine = get_engine()
inference code
******
ctx.pop()
it will only success once.since cuda.init() only initialize once. can you help me find the solution? if neeed,i will provide you the code.