{"id":1362,"date":"2009-05-26T17:27:26","date_gmt":"2009-05-26T16:27:26","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=1362"},"modified":"2010-03-25T11:33:39","modified_gmt":"2010-03-25T10:33:39","slug":"supercharge-matlab-with-your-graphics-card","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=1362","title":{"rendered":"Supercharge MATLAB with your graphics card?"},"content":{"rendered":"<p>Did you know that your graphics card is effectively a mini-supercomputer?\u00a0 Your main CPU (Central Processing Unit) probably has 2 processor cores, 4 if you are lucky but a high end graphics card can have as many as 96 GPUs (Graphics Processing Units) &#8211; which is a lot.\u00a0 Even my laptop&#8217;s relatively low end NVIDIA GeForce 8400MS has 16 &#8216;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Stream_processing\">stream processors<\/a>&#8216; according to <a href=\"http:\/\/en.wikipedia.org\/wiki\/GeForce_8_Series#GeForce_8400M_Series\">this Wikipedia page<\/a>.<\/p>\n<p>The large number of cheap processor cores is the good news.\u00a0 The bad news is that they are not as capable as fully fledged Intel or AMD processor cores since, as you might expect, the cores in your graphics card are rather specialised.\u00a0 They were designed specifically to do the mathematics behind graphics processing and they do this very well indeed but until fairly recently it was rather difficult to get them to do much else.<\/p>\n<p>That hasn&#8217;t stopped people from trying though. Some time ago,<a href=\"http:\/\/www.nvidia.co.uk\/page\/home.html\">NVIDIA<\/a>, the makers of my laptop&#8217;s graphics card, released a software library called <a href=\"http:\/\/www.nvidia.co.uk\/object\/cuda_what_is_uk.html\">CUDA<\/a> which enables C-programmers to access the vast computational power locked away in a typical pixel pusher.\u00a0 The results have been nothing short of astonishing.\u00a0 One developer, for example, <a href=\"http:\/\/www.tobiaspreis.de\/\">recently demonstrated<\/a> how to use CUDA to calculate the properties of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Ising_model\">Ising Model<\/a> (A staple in undergraduate computational physics courses) over 60 times faster than a single, bog standard Intel CPU.<\/p>\n<p>If you are impressed with a factor-60 speed up then the <a href=\"http:\/\/if.us.edu.pl\/cms\/index.php?option=com_content&amp;view=article&amp;id=925\">675 times speed up reported  by Micha\u0142 Januszewski and Marcin Kostur<\/a> is really going to knock your socks off.\u00a0 Yep &#8211; that&#8217;s not a typo.\u00a0 They have written code that can solve certain Stochastic Differential Equations SIX HUNDRED AND SEVENTY FIVE TIMES FASTER than a single, standard CPU core.\u00a0 Your shiny new dual quad-core workstation isn&#8217;t looking so clever now is it?\u00a0 Not bad for technology designed for playing the latest version of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Quake_(series)\">quake<\/a> on.<\/p>\n<p>This is all well and good but I don&#8217;t have the time or the mental stamina to code in C anymore.\u00a0 What I want is for all of my favourite Mathematica, MATLAB or Python functions to be CUDA-ised so that I can enjoy a big speed up at low cost and low programming effort.\u00a0 I&#8217;ll take the <a href=\"http:\/\/www.urbandictionary.com\/define.php?term=moon%20on%20a%20stick\">moon on a stick<\/a> while I&#8217;m at it if you don&#8217;t mind.<\/p>\n<p>Well, it seems that some people are doing exactly this.\u00a0 I have just stumbled across a project called <a href=\"http:\/\/gp-you.org\">GPUmat<\/a> which claims to offer up to 40x speedup with very little effort on the part of the user.\u00a0 One example they give considers the following standard MATALB code.<\/p>\n<pre>A = single(rand(100)); % A is on CPU memory\r\nB = single(rand(100)); % B is on CPU memory\r\nC = A+B;    % executed on CPU.\r\nD = fft(C); % executed on CPU<\/pre>\n<p>To get this running on your graphics card all you need to do is (after you&#8217;ve installed the toolbox and CUDA of course)<\/p>\n<pre>A = GPUsingle(rand(100)); % A is on GPU memory\r\nB = GPUsingle(rand(100)); % B is on GPU memory\r\nC = A+B;    % executed on GPU.\r\nD = fft(C); % executed on GPU<\/pre>\n<p>Very nice.  I&#8217;m not sure what MATLAB functions are supported but I guess it&#8217;s all there in the documentation &#8211; I just haven&#8217;t had time to look through it.  I&#8217;d love to tell you what sort of speed-up I experienced when I tried it out but, unfortunately, the developers are asking for all potential users to register before they get access to the downloads and that put me off a bit<\/p>\n<p>It&#8217;s all free though so if you&#8217;d like to check it out yourself, and you don&#8217;t mind the registration, then head <a href=\"http:\/\/gp-you.org\/\">over to the developer&#8217;s website<\/a>.  I&#8217;d love to hear how you get on.<\/p>\n<p>PS: Make sure your graphics card is CUDA compatible first though.\u00a0 You&#8217;ll waste a lot of time trying out this software if it isn&#8217;t!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you know that your graphics card is effectively a mini-supercomputer?\u00a0 Your main CPU (Central Processing Unit) probably has 2 processor cores, 4 if you are lucky but a high end graphics card can have as many as 96 GPUs (Graphics Processing Units) &#8211; which is a lot.\u00a0 Even my laptop&#8217;s relatively low end NVIDIA [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,11,7],"tags":[],"class_list":["post-1362","post","type-post","status-publish","format-standard","hentry","category-math-software","category-matlab","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-lY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1362"}],"version-history":[{"count":6,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1362\/revisions"}],"predecessor-version":[{"id":1367,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1362\/revisions\/1367"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}