Friday, July 8, 2011

Massively parallel programming and the GPGPU

I don't often delve into the deep technicalities of programming, but I was running a model that took 4 days to finish and decided there must be a better way. The model was already optimised, running in parallel etc, so there was nothing for it but to have a go and using a graphics card to do the computation.

A quick Google suggested mixed views. Clearly in the best cases speedups of 40 or more possible, but that was after some pretty complex optimization (exactly what memory you use on the card and how you access seemed to play a big part in the gains that you get). However, 4 days was not really satisfactory.

Being a die hard .net user and not really willing to learn anything new a bit more Googling revealed a number of potential ways of automatically converting .net code to work with the graphics card. I had a look at 3 or 4 different methods and the one I chose is Cuda running on a Nvidia card (as it is by far the best supported GPGPU as far as I can tell) and Cudafy (available from http://www.hybriddsp.com/Products/CUDAfyNET.aspx (free) as it seemed the most elegant approach.

The effort wasn't too bad - Cudafy automatically translates .net code into something that can run on the graphics card so all you need to do is to figure out how to get Cudafy to work. It took about a day (I'd like to see a lot more documentation) but it worked pretty much as it claimed. - various little issues, like checking for integer overflows is switched on in the Visual Studio compiler and needs to be switched off when generating the graphics code took a bit of time to uncover but now they are sorted they will remain sorted. Hats off to Hybrid for producing a very easy to use product.

Converting your code is also pretty trivial - Provided that its written to be analysed in parallel in the first place that is. You add a variable that tells the "kernel" (sub routine in more traditional language) which thread is running the kernel and what you want each thread to do and let rip. Its possible to generate millions of threads and the graphics card will schedule them all over the multiple processors that it has available (240 in my case).

The results are amazing - my out of the box conversion (no memory optimizations or anything fancy just a default translation of my code) produced about a 20 fold increase in speed over the .net version. I reckon that by being a little bit fancy you could probably double the speed on the graphics card. - a day well spent. It will definitely become my method of choice for running large models and datasets.

21 comments:

Mark said...

Very cool! Thanks for sharing your experience. I hadn't heard of Cudafy, but will definitely check it out.

Uptravi said...

If you can fill half your plate at every meal with high fiber and nutrient packed vegetables you are well on your way to significant and long lasting weight loss. This is probably one of the simplest things you can do to really kickstart your weight loss journey.
Keto Gedeon

james said...

Male enhancement videos are found scattered all over the internet. However, there are only a number that really demonstrate the right and effective ways to achieve male enhancement. Some show how to use homemade male enhancements such as traction
Bionatrol Pro Enhance

james said...

Finally, there are natural solutions for male enhancement and they are found in most of these natural supplements. Unlike drugs that apart from the fact have hazardous side effects, are very expensive, require doctor visits, a full prescription, require clinical supervision, these male supplements are different and unique.
Ryzex Male Enhancement

james said...

vegetables at least half of your diet and take up moderate exercise at about a half hour per day. That's what the U.S. government recommends for optimum health.
Keto Trim 800

Ronaldo said...

It is only when the body's glycogen stores become significantly depleted that the body begins to burn fat for energy. However, each gram of fat has about twice the calorie content of 1 gram of glycogen and therefore it would require burning double the amount of calories needed to lose 1 gram of glycogen to lose 1 gram of fat.
Rapid Fast Keto Boost

Watson said...

Which man doesn't want to enjoy increased sexual energy, boosted stamina, improved endurance and the ability to take their lover over and over again in bed? The real question here is: do you want to be subjected to constant doctor visits and tests, take painful testosterone injections or would you rather use a natural enhancement pill to boost your testosterone levels?
Celaxryn RX

james said...

The best thing which one can get from natural enhancement products is that they are entirely free of injurious side effects. On the other hand chemical product have their own side effects such as increase in blood pressure, skin irritations and can even cause insomnia in certain
Zydenafil

james said...

A beanbag and a corner electric fireplace will transform your space into a tranquil environment where you can simply relax after a long day. Both have been proven to have a calming effect individually and when you pair them together, you're rewarded with total bliss.
Electric Back Massager Reviews

james said...

If you don't know the answer to those questions, you have totally missed the point of this article and the lesson it's trying to teach you, and are set up for failure. Go back and read this section again...By default, diet B is superior.
Number One Keto

james said...

Green tea is the best and highest recommended caffeinated beverage that you can have for your healthy weight loss and quick weight loss journey. Most of them are even decaffeinated! I would recommend that you have 3 - 4 cups of hot green tea per day. Studies

Keto Shred Biotic Immunity Booster

james said...

Weight Loss Truth: Sir Isaac Newton once said " What goes up must come down." There are natural principles that govern our lives. If you throw a ball up in the air, it is going to come back down. You can sit on your couch and imagine and visualize that the ball will staying afloat in the air, but natural principles teach us that it will come down. Same goes when it comes to our weight.
Keto Shred Biotic Immunity Booster

james said...

One of the biggest and most popular male enhancement products to have hit the market are penis enlargement pills. While there are many skeptics who believe these pills don't work, the bottom line is they do. Like many Americans, we often don't follow the doctors order
Empowered x Energy

Ultiva80 said...
This comment has been removed by the author.
Ultiva80 said...

for gratifying sex. It also helps to cure mental health problems, stress etc. It can be used as health tonic to improve immune system of the body. Musli Strong is very good for the treatment of natal and postnatal problems. One who uses Musli Strong regularly would get the production of HDL cholesterol that means good cholesterol.
Formax Lean Male Enhancement

james said...

women who need to workout with minimal equipment while traveling. It needed to take away all excuses for a newly motivated weight loss participant and that's what it does. By providing exact diets and exercise instructions the Body Fat Meltdown program ensures success if a woman will simply follow it for ninety days. This is an example of a program that
Reliant Keto

james said...

Patients that are motivated to lose weight and willing to follow through with diet and exercise prior to receiving weight loss surgery may experience greater levels of success immediately following the procedure and in the long term. Most people did not find themselves severely obese overnight. It took years to reach that weight and therefore
Vaso Prime RX

Intuniv said...

belt that removes essential nutrients from the fat and delivers them to specific body parts. Hormones that regulate our blood sugar levels activate an enzyme in fat tissue called lipase. Lipase ignites fat cells to release triglycerides, which is what makes fat cells fat. When they receive a signal from lipase to exit the fat cells, the triglycerides break-up into glycerol and

Reliant Keto

Udenyca said...

Physical Adaptation Our bodies adapt themselves to our calorie consumption and physical activity levels. When we begin an exercise regime, our body is required to make several changes to adjust to changing workloads. Our muscles have to rebuild themselves and this requires many calories. But, over time the body finishes adapting and burns less calories for
Nature Clarity Keto

Harper said...

Many diet programs out there don't address the psychological aspect of why people fail to be successful with long term weight loss. However, quite a few studies exist that have looked at just that. In many respects, the psychological aspect is the most important for long term weight loss, and probably the most underappreciated component.
Viadine Male Enhancement

james said...

If you can fill half your plate at every meal with high fiber and nutrient packed vegetables you are well on your way to significant and long lasting weight loss. This is probably one of the simplest things you can do to really kickstart your weight loss journey.
Virtus Strong Testo Boost Pro