Search Unity

Question Use Barracuda outside of main thread

Discussion in 'Barracuda' started by TeaOfCup, Mar 13, 2023.

  1. TeaOfCup

    TeaOfCup

    Joined:
    Oct 29, 2021
    Posts:
    1
    Hi,

    I am using Barracuda 3.0 to run a LSTM model to compute some data at runtime. I need to execute the model quite regularly but when I'm doing so,
    Barracuda.Execute()
    takes more than 200ms to compute. That's a problem since it induces low FPS for my game. (Since the data I need are required for rendering, I need to call the method in the player loop)

    I looked at the documentation and tried with different back-ends, with types such as the simple
    WorkerFactory.Type.Auto
    and
    WorkerFactory.Type.Compute
    and even
    WorkerFactory.Type.CSharpBurst
    . But the difference seems almost neglectible.

    Since I can start computation on a frame and get the results only several frames later, I tried to call Barracuda asynchronously. But it seems like it requires to be called on the main thread only. (as the computation seems to be handled in background anyway)

    I tried the method
    IWorker.StartManualSchedule(Model)
    but it looks like it is only dividing the execution of the layers on several frames. Maybe I was not using it properly.

    So, is there a way to make Barracuda free up my main thread and perform its computations on background so I could retrieve them later when they are ready ?
     
    Last edited: Mar 14, 2023