Log in

View Full Version : Test Plugin Compatibility


MysteryX
7th May 2016, 06:38
Hi, as you know, KNLMeans is a great denoiser but the latest version only works with certain graphic cards. For generating scripts, it breaks for many users. Not good.

Perhaps I could run a script that tests KNLMeans for compatibility and write the result to a text file.

Can someone help me write such a script? Then I can generate the script based on what the hardware supports.

Groucho2004
7th May 2016, 13:45
The first thing you would have to do is to check the capabilities of the card and driver. GPU Caps Viewer can export this via command line to a text file. You would then have to parse that text file and check if OpenCL 1.2 is supported. That should be all that's needed but I would also create a small test script that runs KNLMeansCL on a single frame and check if Avisynth throws any errors (which it will if for example the correct runtimes are not installed).
The script could be as simple as this:
colorbars(pixel_type = "yv12").killaudio().trim(1, 1)
KNLMeansCL()

MysteryX
7th May 2016, 17:18
Is there a way to check for error within the script and write to a text file whether the error was thrown or not?

Groucho2004
7th May 2016, 17:32
Is there a way to check for error within the script and write to a text file whether the error was thrown or not?
You can use AVSMeter to run the script and have it write a log file. Any error, be it a SEH exception, Avisynth exception or an error reported by "GetLastError()" will be written to the log file.
However, if Avisynth for example throws "There is no function named KNLMeansCL()", it could have various reasons:
1. KNLMeansCL can't be found either in the auto-load directory or in the directory specified in "LoadPlugin()"
2. MS runtime is missing
3. OpenCL.dll is missing or the wrong version
4. A combination of the above

These are just the ones I have come across. So, in order to figure out what the problem is you'll have to design a smarter detection process.

As I mentioned, you should first make sure that the OpenCL API version is supported.

MysteryX
8th May 2016, 04:32
Or perhaps Try...Catch would be a cleaner way to do it.
http://avisynth.nl/index.php/Control_structures

There can be a variety of reasons for it to break, and that's why I'd rather just try the plugin instead of detecting the OpenCL version.

"If this works, use it, otherwise use an alternative plugin (either a previous build or xNLMeans)."

TheFluff
8th May 2016, 20:46
In general "good programming practices" terms, trying something and seeing if it works is much preferable to attempting to detect if it could work. It's less code so it's easier to maintain (you don't have to update your detection code to match updates in the code doing the thing you want to do), and your detection code isn't the real thing and doesn't behave like the real thing so it might not run into the same problems that the real thing does. The big exception to this general rule is if trying would waste a lot of time/resources, of course.

However, try/catch in Avisynth script will only work if the plugin fails by throwing an Avisynth exception, or fails in a way that the script interpreter can convert to an Avisynth exception. If it fails in any other way (such as by crashing the script environment) you've still got a problem on your hands, that you may or may not care about handling.

MysteryX
9th May 2016, 13:01
OK this is the script I ended up creating. It's working fine.


P="Encoder\"
LoadPlugin(P+"KNLMeansCL.dll")
colorbars(pixel_type = "yv12").killaudio().trim(1, 1)
Result = true
try {
KNLMeansCL()
} catch(error_msg) {
Result = false
}
WriteFileStart("Temp.txt", string(Result))


If the file contains "false", I instead load an older version of KNLMeansCL that works with OpenCL 1.1