Log in

View Full Version : How to Optimize GPU Usage


MysteryX
7th October 2015, 00:50
I have this plugin to run HLSL pixel shaders in AviSynth.
https://github.com/mysteryx93/AviSynthShader/

This code runs at 3.3fps @ 80% CPU. When I run it on a Intel HD 4000, however, it is only using 10-25% of the GPU, including KNLMeans's usage.

Is there a way I could make better use of the GPU?

PluginPath=".\"
LoadPlugin(PluginPath+"ColorMatrix.dll")
LoadPlugin(PluginPath+"KNLMeansCL.dll")
LoadPlugin(PluginPath+"nnedi3.dll")
LoadPlugin(PluginPath+"Shader.dll")
Import(PluginPath+"SuperRes.avsi")
LoadPlugin(PluginPath+"svpflow1.dll")
LoadPlugin(PluginPath+"svpflow2.dll")
Import(PluginPath+"InterFrame2.avsi")

SetMTMode(3,4)
AviSource("Preview.avi", audio=false, pixel_type="YV12")
SetMTMode(2)
ColorMatrix(mode="Rec.601->Rec.709")
Crop(0, 0, -10, -0)
SetMTMode(5)
KNLMeansCL(D=2, A=1, h=3, device_type="GPU")
SetMTMode(2)
SuperRes(2, 0.42, 0, true, """nnedi3_rpow2(2, nns=4, cshift="Spline16Resize", Threads=2)""")
InterFrame(Cores=4, Tuning="Smooth", NewNum=60000, NewDen=1001, GPU=true)
SuperRes(2, 0.42, 0, true, """nnedi3_rpow2(2, nns=4, cshift="Spline36Resize", fwidth=940, fheight=728, Threads=2)""")
Spline36Resize(940, 720, 0, 4, -0, -4)
Distributor()


SuperRes is defined here
https://github.com/mysteryx93/AviSynthShader/blob/master/Shaders/SuperRes/SuperRes.avsi

MysteryX
8th October 2015, 04:44
After running a profiler, I see that the bottleneck is in the format conversion: ConvertToFloat(), and especially ConvertFromFloat().
https://github.com/mysteryx93/AviSynthShader/blob/master/Src/ConvertFromFloat.cpp

Who is good at optimizing this kind of stuff?

Khanattila
8th October 2015, 11:32
In your chain KNLMeansCL weighs very little. It is negligible.
Indeed, it makes you also use more CPU than necessary.

wonkey_monkey
8th October 2015, 18:19
Who is good at optimizing this kind of stuff?

As I understand it, there is a mismatch between the normal setup of an x86 processor and some C or Posix standard, or something, which can make converting to/from floats slower than necessary.

If you're compiling with Visual Studio, you could try this:

https://msdn.microsoft.com/en-us/library/6d9xx1d2.aspx

You could also try enabling SSE2 under Enhanced Instruction Set, or changing Floating Point Model to "fast".

But I don't really know if this is anything to do with your problem. It's just something I heard about that sounded like it might be related, and might even be out of date.