Wednesday 16 September 2015

GPGPU using CUDA Thrust


Long time no see!

I just want to share the presentation that I gave during our weekly meeting in the CGV group in Delft. Usually we do two kind of presentations, the first one is related to our current project, while the second one is more technical and aims at teaching something useful to the other members of the group.

This presentation is of the second type. It aims at showing how CUDA Thrust can be used to implement GPGPU solutions without too much effort.

I think that CUDA is a great platform and I did a lot of work using it. 
However it is difficult to master and, without any high level interface, CUDA code is slow to implement.  I gave a couple of examples in my presentation:

  1. Preparing a CUDA kernel launch is somehow an annoying task. More than that the problem is related to the handling of the memory in the Device. I like how the OpenCV wrapped all the handling in the GpuMat class, however it is something that must be careful planned ahead and well designed with clear specifications.
  2. Memory access influences the performance: This is a key point! It is not so easy to implement an efficient algorithm in the GPU. You can find some details about all the challenges related to memory access at this link.

CUDA Thrust is a parallel algorithms library which resembles the C++ Standard Template Library (STL) and implements many common algorithms that can be used during your daily work.

So if you are already using STL's algorithms and data structures in your code, and you are tackling big problems by decomposing it to small and well known algorithms, CUDA Thrust can be very useful and easy to pick.


Friday 3 April 2015

std::async, std::future and lambda functions to keep GUIs responsive

It has been quite some time since my last post :)

This week I submitted my first paper as a PhD student in TU Delft and I had to shot some video to show my work. I had to show some analytic routine that require some time to be computed but I wanted to keep my GUI responsive, so that the video would results nice.

Imagine that you have a class that is similar to the following one:
You may want to call a method of the class that it is slow to compute. If you do that in the following way the the (Not Responding) problem in your GUI will occur.
The easiest way to solve this problem is to use some cool features of C++11, std::future, std::async and the lambda functions. I use std::async to launch a thread where a lambda function is used to isolate the slow computation. A std::future is used to check if the asynchronous thread has completed the computation and meanwhile the application is refreshed.
there you go :)