August 02, 2012, 4:52 PM — Researchers at the Massachusetts Institute of Technology have figured out a way of helping developers more easily rearrange their image processing code so that it could execute faster and use fewer computational resources.
Such a technique could prove especially beneficial for mobile phones and other portable devices where battery power is at a premium. Users are growing ever more accustomed to running advanced photo manipulation apps like Instagram on their phones, so developers of these apps are struggling to make their creations as speedy as possible.
"I was looking for some easier way to write high performance code for mobile devices, but it turned out to be great for desktops as well," said Andrew Adams, a postdoctoral student at the MIT Computer Science and Artificial Intelligence Laboratory (CSAIL).
Adams, along with other researchers from MIT, Stanford University and Adobe, have developed a DSL (Domain Specific Language), and associated compiler, that creates a layer of abstraction that allows developers to easily move around chunks of code in order to find the most computationally efficient method of processing images.
The researchers have used the DSL, called Halide, to rewrite several common image-processing functions. In many cases they were able to demonstrate two-, three-, or even six-fold increases in speed.
Typically, image processing involves multiple steps, some of which can be executed in a parallel in multicore processors. For developers, however, moving code around to find the optimal order of execution can be a complicated and error-prone process, given that with the imperative languages used today for image processing -- such as C++ -- the order in which a program executes tends to be "baked into the code," Adams said.
"Getting performance improvements on mobile platforms can be quite painful. If you've already optimized your code a certain way, If you want to try optimizing a different way you have to rearrange all your code, and you'll probably just increased the number bugs. It's just a painful experience," Adams said.
Borrowing ideas from functional programming, Halide provides developers with the ability to easily schedule when and where each routine should execute. The programmer can experiment with the order in which the program executes, without worrying about introducing bugs or breakages.
Halide can also save time in porting programs to different hardware as well. The programmer needs only to reorder the execution of code that is optimal for the new platform.