Issues using VPI with python multiprocessing module

Hello, I have been having issues using the VPI library with the multiprocessing module in python. I am getting “Error: VPI_ERROR_INTERNAL: (cudaErrorInitializationError)” when attempting to use any vpi method in a multiprocessing “Process”. there are also issues when I am trying to send vpi objects through queues or pipes, as I see that these objects cannot be pickled. This can be worked around, but the first error is holding me back from doing anything with VPI while using multiprocessing. I have tried using “set_start_method” and setting it to “spawn”, however, though this makes the above error go away, I simply get an error that “terminate called without an active exception”, which prevents me from running code as well. If anyone has some advice for this it’d be greatly appreciated.

1 Like

Hi,

Which VPI version are you using?
Could you share a simple reproducible source so we can check it further?

Thanks.

Hello,

I am using VPI 2.2.7. Here is some example code to display the issue:

import cv2
import numpy as np
import vpi
from multiprocessing import Process, Event, Pipe, set_start_method, Queue, get_context

def feature_tracking(child_conn, event):
    frame = child_conn.recv()
    with vpi.Backend.PVA:
        features, scores = frame.harriscorners(strength=2.0,sensitivity=0.1,min_nms_distance=8.0)
    with features.lock_cpu as FeatData:
        feats = FeatData.copy()    
    return feats

def image_conversion(img_q, parent_conn, event):
        
        image = img_q.get()
        with vpi.Backend.CUDA:
            image = vpi.asimage(image,vpi.Format.RGB8).convert(vpi.Format.S16)
        event.set()
        parent_conn.send(image)
        
        return


if __name__ == '__main__':
    try:

        images = Queue()
        cap = cv2.VideoCapture(path)
        for i in range(20):
            ret, frame = cap.read()
            images.put(frame)
        cap.release()

        signal = Event()
        parent, child = Pipe()
        convert= Process(target=image_conversion, args=(images,parent,signal))

        features = Process(target=feature_tracking,args = (child,signal))


        convert.start()

        features.start()

        convert.join()

        features.join()

        convert.close()
        features.close()
    except Exception as e:
        print(f"Error: {e}")

This code, when executed, will give the CUDA initialization error which I mentioned in the original post. Please let me know if you find any solutions for this, thank you.

Hi,

Thanks for sharing the reproducible code.
Confirmed that we also meet the same error in our environment.

We are checking this with our internal team.
Will update more info with you later.

1 Like

Gotcha, thanks for letting me know. I appreciate your quick responses.

Hi,

We got some updates from our internal team.
Currently, VPI doesn’t support multi-processing.

Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.