DualCore processing with IMAQ Vision

By

Monday, February 11, 2008

Today the DualCore processors much more easily available than few years ago. With LabVIEW we can use such CPUs much more effectively. So, below - just simple example how to do this with IMAQ Vision. In the given example we will perform simple convolution with 5x5 kernel:

Now I will put this code in the cycle and measure execution time:

Well, for 250 images 512x512 I have 1380 milliseconds, or approximately 5,5 ms per image. Not so bad, but how to do this faster?

Take a note, that overall CPU usage was approximately 50%:

For parallelizing most people tried to do following:

But this will not work, because two reasons - first the same SubVI (which is not reentrant) used in both cycles, and the second the data dependency. But it is possible to do processing twice faster. Now I will copy IMAQ Convolution.vi into IMAQ Convolution 1.vi and IMAQ Convolution 2.vi and store both in my project. Second - the data should be independent:

Well, now I have 1430 milliseconds. The time nearby the same as before, but 500 images processed instead of 250. So, we have 2,86 ms per image, or x1,9 faster in comparison with single loop.

And, of course CPU Usage now 100 percent:

Very important is following: inside of Convolution 1.vi is a DLL Call, and this DLL call should be thread-safe, in other words - it should be possible to execute this in any thread, not in UI thread:

Otherwise both VIs will be executed sequentially, and advantages of parallel processing will be not used.

You can download the source code for your experiments here.