AviSynth CUDA DLL Anyone has success with CUDA and Avisynt

Has anyone successfully gotten Avisynth and CUDA to play with each other? I’ve compiled a DLL from the CUDA template and implement the AviSynth DLL export function(s). If I don’t call any functions from a .cu file the DLL works. If I call a function in a .cu file I get an exception thrown from AviSynth. Anyone have any luck with this?

I also tried compiling two seperate DLLs. One with the AviSynth functions and one with the CUDA functions. But that suffers the same fate.

My next thought is to create a client/server system or use a pipe to transfer data from the AviSynth DLL to a CUDA executable, perform the work and transfer it back. But I am afraid this may incur a large data movement penalty.

Any suggestions? My goal is to accelerate several AviSynth filters via the CUDA interface, but so far this isn’t looking feasible.

Thanks.

The problem seems to be that AVISynth (at least the latest 2.5.8 version) calls the plug-in’s constructor/destructor and GetFrame function from different threads. Since the CUDA context is attached to a thread, if you initialize CUDA in constructor/destructor and try to use CUDA in GetFrame it fails. Trying to initialize CUDA in GetFrame does not work well either, since it’s possible to have different thread calling GetFrame too.

My approach is to create a thread in plug-in’s constructor, and do everything CUDA related in that thread. I use two events to synchronize the thread with GetFrame (“start work” and “work complete”). It looks like this:

ThreadProc()

{

    initialize CUDA

    wait for event "start work"

    while(running) {

        do CUDA related things

        set event "work complete"

        wait for event "start work"

    }

   uninitialize CUDA

}

GetFrame()

{

    ...

    write parameters to some member variable (visible from ThreadProc)

    set event "start work"

    wait for event "work complete"

}

destructor()

{

    running = false;

    set event "start work"

    wait for thread to stop

}