SEt
27th September 2009, 22:29
As suggested by IanB i'm opening thread for discussing MT implementation in AviSynth 2.6.
Main concepts i propose:
2.6 plugins are required to be threading-aware.
Threading mode is chosen by filter itself, not by the script. It's not the user who should guess in what mode some filter won't crash and will work faster.
Implementation thoughts, at least 3 modes are needed:
0) Threading is handled by the filter: 1 instance that is called from all threads with no protection.
1) Threading is handled by Avisynth: as many instances of the filter as there are working threads. Filter is aware that frame requests from each instance are likely non-sequential and part of the frames is handled by other instances.
2) No threading: 1 instance of the filter that is protected by Avisynth to be called only from 1 thread at a time. Intended only for source filters and debugging. Frame requests are likely sequential (due to cache after it) but it's not guaranteed.
Mode is selected ~at the time of instance creation, so filter can choice the mode based on the passed arguments.
Problem: some things (for example Cdeblend script, likely IVTC filters) want single instance and sequential frame requests to work correctly. Perhaps there should be some help from Avisynth core to run them in that way even if it's very slow (Mode 3 ?). This can also benefit sources with temporal compression where single backward frame request can be very expensive but even unneeded sequential requests are cheap.
Related issues:
MT should be completely separated from caching. Cache is Mode 0 filter that is inserted after most other filters.
Setting CacheHints should be mandatory. Cache should be more intellectual about connected requesting filters and number of working threads:
When set to no caching and there is only one requesting filter - no cache is inserted at all.
When there are several requesting filters (like Interleave(last.f1(), last.f2())) cache instance is inserted even if all request no caching.
Caching amount is adjusted by number of working threads and multiple requesting filters.
There should be a clean way to detect cache filter, not hack like now. I propose changing return value from void to at least bool and returning success state. Cache returns success for IsCache request.
This is intended as memory usage optimization that is required to be able to run multiple threads. Auto guessing mode of cache is often not needed at all (many filers are pure spatial) and can excess poor 32-bit address space limit before it learns that no caching is actually needed.
Main concepts i propose:
2.6 plugins are required to be threading-aware.
Threading mode is chosen by filter itself, not by the script. It's not the user who should guess in what mode some filter won't crash and will work faster.
Implementation thoughts, at least 3 modes are needed:
0) Threading is handled by the filter: 1 instance that is called from all threads with no protection.
1) Threading is handled by Avisynth: as many instances of the filter as there are working threads. Filter is aware that frame requests from each instance are likely non-sequential and part of the frames is handled by other instances.
2) No threading: 1 instance of the filter that is protected by Avisynth to be called only from 1 thread at a time. Intended only for source filters and debugging. Frame requests are likely sequential (due to cache after it) but it's not guaranteed.
Mode is selected ~at the time of instance creation, so filter can choice the mode based on the passed arguments.
Problem: some things (for example Cdeblend script, likely IVTC filters) want single instance and sequential frame requests to work correctly. Perhaps there should be some help from Avisynth core to run them in that way even if it's very slow (Mode 3 ?). This can also benefit sources with temporal compression where single backward frame request can be very expensive but even unneeded sequential requests are cheap.
Related issues:
MT should be completely separated from caching. Cache is Mode 0 filter that is inserted after most other filters.
Setting CacheHints should be mandatory. Cache should be more intellectual about connected requesting filters and number of working threads:
When set to no caching and there is only one requesting filter - no cache is inserted at all.
When there are several requesting filters (like Interleave(last.f1(), last.f2())) cache instance is inserted even if all request no caching.
Caching amount is adjusted by number of working threads and multiple requesting filters.
There should be a clean way to detect cache filter, not hack like now. I propose changing return value from void to at least bool and returning success state. Cache returns success for IsCache request.
This is intended as memory usage optimization that is required to be able to run multiple threads. Auto guessing mode of cache is often not needed at all (many filers are pure spatial) and can excess poor 32-bit address space limit before it learns that no caching is actually needed.