Log in

View Full Version : QuickGuide: SMP, CCE and AVISynth


insite
24th March 2004, 02:11
Okay, I bought a dual processor system about two years ago when I started to do video processing. I was always a bit disappointed in the 'bang for the buck' with regard to encoding, but I LOVED it as a workstation. Never slowed down. Well, recently I got a wild hair and began testing, tweaking and learning. Here's what I have learned.

SMP systems are better at handling BROAD loads than DEEP loads. They may not run a single process that fast, but they can run several heavy processes without missing a hitch. I can run multiple instances of process-intensive programs without getting bogged down. A problem with video, however, is that CCE will crash if you open multiple instances and try to encode.

I'm getting ahead of myself. I'm going to organize this into two parts: Multi-Instance Encoding and Optimized Affinity Encoding:

Multi-Instance

As I said, CCE wrecks if you open two copies and try to encode two streams simultaneously. There is a sort of hack around that, but it's a bit of a pain: Terminal Services. I have found that while you can't run multiple instances of CCE within your windows account, you CAN run CCE and simultaneously log into your box with Terminal Services and open another instance. The result: Encode two streams in about 115% of the time it would take you to to encode a single stream with a single instance. For those who aren't getting this, it's awesome. If it takes you two hours to encode a two pass on a movie, you can encode TWO movies at two pass in two hours and eighteen minutes. I will not get into how to use/install/configure terminal services here; just know that it works.

Processor Affinity

Okay, CCE is SMP capable but AVISynth is not. This means that while CCE COULD use tons of sys resources to take advantage of a dual box, most frameservers are single processor configured, so your bottleneck is in the stream of frames that CCE receives from the frameserver.

Solution: AFFINITY!

Affinity describes the ability to schedule a process to run on one or the other processor instead of letting your operating system balance the load equally. In this case, EQUAL SUCKS. The problem has been that you cannot set affinity for many core processes or for your hardware from within windows. WELL, THIS IS WRONG.

If you have Win2K or XP, download two programs:

Get the Interrupt Affinity Filter from Microsoft's website (free) and get SMP Seesaw (also free) from the web (google search it).

The affinity filter allows you to set the affinity for interrupt requests coming from devices on your PC. This means that we can load up one of the processors with ALL hardware/virtual device requests and leave the other processor wide open. With me so far?

There's only ONE thing that you need to leave on the OTHER processor:
Video Codecs (avisynth will basically get its own processor)

Now reboot. Open SMPSeesaw. This will allow you to shift the remaining system processes (not device specific) to the processor that we've been loading up, paving the way for smooth sailing with AVISynth.

Open CCE. CCE will automatically be run to process on BOTH processors simultaneously. THIS IS WHAT YOU WANT. Basically, you end up with this:

All hardware / systems processes run on CPU0
Video Codecs run on CPU1
CCE runs on BOTH

Now, encode away. The performance increase that I have noticed is around 30-40% increase over 'stock' configuration. Not bad. AND, I use Win Server 2K3 which has far better SMP threading capability than 2000, so a 2000 box would see a greater relative increase. Performance is as follows (my setup is in my sig):

'Rig'

CCE w/ 2-Pass VBR Encode, Prog Frms, DVD Compliant, no audio, 3/4 frame order, 15% quality, no filter, 16x9 source

Source:
Andretti IMAX Flick, two minute clip.

Results w/ single instance default confit:
2.13x Realtime, Steady State.

Results w/ dual instance terminal services:
1.92x Realtime on Instance 1, Steady State
1.81x Realtime on Instance 2, Steady State

Results w/ Optimized Affinity:
2.91x Realtime, Steady State

Now, the better P4's still smoke my rig with single processors, BUT, i can encode ALMOST as fast (like I am now) with TWO video streams (like I am now) while writing mini-guides, reading email, and running AutoCAD (like I am now) with no noticable drop in performance. Now that's a beast.

I'm not going to take the time to compile a giant guide on exactly how to do this; I wish I had the time. This shoudl be enough to get anyone with a little knowhow and the all-knowing Google well on their way. I will pop in to time to time if anyone has simpler questions; feel free to ask. Hope this was helpful.

************EDIT************
jumped the gun a tad. pulling up a better process viewer shows me that avisynth.dll is still running as a child process under cce. no worries; there is a file called ImageCFG available online that will modify an executable to start with a particular affinity. i have NOT tried this yet on a .dll, but i will tomorrow. i'll post results at that time.

LB
24th March 2004, 05:44
There is something that needs to be stated in this post, which I believe you didn't mention, but it's a question most people are wondering (I think).

The question is, if CCE is SMP enabled, then why bother with all the trouble of this affinity stuff and balancing the loads? Well you hinted at it with the DEEP v. BROAD - "threading". I don't claim to know a lot in this area, and I don't. So I might mistate slightly, but the general concept of what I'm about to say is correct. A program can only send so many "threads" or for lack of a better words, instructions to a cpu, and with those of us lucky enough to have a dually rig, we quickly realize that when encoding, CCE uses a mere 60% of each processor. Why? Shouldn't CCE be using 100%? Well I blame this on poor SMP coding in CCE. You see, on a typical system, CCE is maxed out, using 100% of the cpu. It remains at 100% even on high end systems, running at 3.4Ghz. So these high end systems are getting speeds around 3.5-4.0 RT, whereas us dually people, who have a combined CPU speed of ~5-6Ghz, still only see 2.8; and on a properly coded program, it should be using 100% of each cpu, but that's not the case here. So, CCE has poor SMP coding, which is surprising considering how much it costs in $$.

So insite's answer to this is to run two instances of the program. It's a hassle, but the speeds prove the point that CCE isn't coded well for a dually system. But, again like insite has shown, there are workarounds, but it's still a hassle.

Kedirekin
24th March 2004, 13:32
I feel compelled to pipe in here.

I don't believe it's poor SMP coding in CCE that is the root of the 60% utilization. I believe the root of the issue is the fact that AviSynth and it's filters are not SMP enabled (as insite stated). Basically you have an IO bottleneck - AviSynth can't supply video data fast enough to keep CCE busy, so CCE spends a lot of time idle waiting for data from AviSynth.

You can confirm this yourself. Create an AVI file (I recommend MJPEG for speed) and encode that with CCE. I think you'll find CPU utilization in CCE jumps to near 100%. I used to do this when I had TV captures that needed lots of post-capture processing - it was faster to post-process them once to an AVI, then do the multipass encoding from the AVI.

madluther
24th March 2004, 19:26
Another thing to remember is memory bandwidth, single CPU systems with 800Mhz FSB's seem faster than some duel rigs with 533Mhz FSB's when running CCE.

My case is a little strange. My system is P4 3.0 Ghz HT running linux. I regularly run CCE 2.66 and avisynth under the wine environment and get speeds around 3.3x to 3.5x with 2.35:1 DVDs being recompressed for DVD-R (no filtering in avisynth).

One of the reasons I _think_ the performance is so good is the way wine handles threading in windows apps, it basically converts each thread to a seperate linux process.

When encodes are running, I see 3 wine processes, 2 are CCE and the other is avisynth.

When monitoring cpu load both CPU's (albeit virtual) are generally at 95-100%.

The point of this post is not to start a windows/linux debate, but to illustrate if you get the process balancing right you should get a performance increase regardless of O/S. (In this case wine does it automatically)


Regards.

Mad.

insite
25th March 2004, 01:36
Kedirikan and madluther are correct. In fact, avisynth doesn't even seem to keep up with the memory bandwidth and is without question the bottleneck on conventionally configured smp systems.

to clarify a bit more for LE, i can run cce without avisynth encoding an uncompressed avi file and post obscene speeds. the issue is that it takes so much time and drivespace to convert to an uncompressed avi that it winds up being quicker to just concede the speed loss to avisynth.

madluther's post on wine is an interesting one; what he describes as automatically occuring in wine is exactly what i've been trying to implement in windows: isolating the 'bottleneck' process, avisynth, in a single thread on a single processor while running all system threads on the other and allowing cce to use one thread on each processor. the benefits of this are exactly illustrated by madluther: he's *emulating* through linux, usually something with a lot of processor overhead compared to native os, and is still posting better numbers than in native win environments. this can only be attributed to better utilization of process threading.

another thing that i've noticed but have not yet been able to look into is this: cce calles two avi related dlls when it executes: avisytnth and avifile. now, avifile has a 32 bit counterpart called avifil32.dll. i'm wondering why cce calls the 16 bit version.

LB
25th March 2004, 05:34
Originally posted by Kedirekin
I feel compelled to pipe in here.

I don't believe it's poor SMP coding in CCE that is the root of the 60% utilization. I believe the root of the issue is the fact that AviSynth and it's filters are not SMP enabled (as insite stated). Basically you have an IO bottleneck - AviSynth can't supply video data fast enough to keep CCE busy, so CCE spends a lot of time idle waiting for data from AviSynth.

You can confirm this yourself. Create an AVI file (I recommend MJPEG for speed) and encode that with CCE. I think you'll find CPU utilization in CCE jumps to near 100%. I used to do this when I had TV captures that needed lots of post-capture processing - it was faster to post-process them once to an AVI, then do the multipass encoding from the AVI.

But the thing is, I don't use Avisynth with CCE. I use virtually uncompressed Huffy Avi footage. No bottleneck there.

And insite, again regarding your post, I still stand firm in my belief that it's simply poor SMP coding in CCE, because of the fact that it's still at 60% no matter what I feed into it, avisynth or uncompressed avi footage.

insite
25th March 2004, 11:33
see now that's odd. if i use huffyuv with ANY compression settings and feed that into cce as source, i get near 100% cpu utilization.

lilhobo
27th March 2004, 18:41
just to clarify soemthing here:

3 X RT means an hour movie is encoded in 20 min???

Kedirekin
27th March 2004, 20:42
Maybe.

Specifically, it means it finishes one pass in 20 minutes. If you do a 3-pass VBR encode, the movie would be encoded in 1:20 (3 passes plus VAF pass). On the other hand if you did a CBR encode, the movie would indeed be encoded in 20 minutes.