<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog of developer Mikkel Ovesen &#187; vs2008</title>
	<atom:link href="http://blog.ovesens.net/tag/vs2008/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ovesens.net</link>
	<description>My thoughts, stuff I need to remember or things I just want to share with the world</description>
	<lastBuildDate>Thu, 19 Jan 2012 11:55:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Cuda v3.2 template project using C++</title>
		<link>http://blog.ovesens.net/2011/05/cuda-v3-2-template-project-using-cpp/</link>
		<comments>http://blog.ovesens.net/2011/05/cuda-v3-2-template-project-using-cpp/#comments</comments>
		<pubDate>Wed, 18 May 2011 16:59:27 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[cuda]]></category>
		<category><![CDATA[gpgpu]]></category>
		<category><![CDATA[gpu]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vs2008]]></category>

		<guid isPermaLink="false">http://blog.ovesens.net/?p=388</guid>
		<description><![CDATA[Important The tutorial is missing some compilation, linker, library settings steps. However you can download the template project, it works and has everything setup. Introduction Download template project source Download executable I am a developer who has been developing software &#8230; <a href="http://blog.ovesens.net/2011/05/cuda-v3-2-template-project-using-cpp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Important</h2>
<p>The tutorial is missing some compilation, linker, library settings steps. However you can download the template project, it works and has everything setup.</p>
<h1>Introduction</h1>
<ul>
<li><a href="/wp-content/uploads/2011/05/CudaTemplate_Cuda_3.2.zip">Download template project source</a></li>
<li><a href="/wp-content/uploads/2011/05/CudaTemplate_exe_Cuda_3.2.zip">Download executable</a></li>
</ul>
<h2><span style="font-size: 16px; color: #444444; line-height: 24px;">I am a developer who has been developing software using .NET and C# for several years. I have never used C or C++, and it has never been required.</span></h2>
<p>I like to investigate new technologies, mainly because I am curious, but also because it could make my daily development work easier or smarter.</p>
<p>Recently my focus has been directed towards GPGPU on the Nvidia Cuda platform.</p>
<p>The programming language for Cuda is called &#8220;Cuda C&#8221;. The name implies that knowledge of C indeed is required for using GPGPU on the Cuda platform.</p>
<p>I discovered that there exist .NET bindings to the Cuda platform and drivers. However, I find their usage complicated and insufficient, and further more kernel development will still have to done in Cuda C.</p>
<p>These fact made me realise that I would have to learn a bit of C and C++ to use Cuda as it was actually intended by Nvidia. Nvidia provides many samples and suggest that a Cuda development environment on Windows could use Visual Studio and Nvidia Parallel NSight for debugging, profiling etc.</p>
<p>As my knowledge of C and C++ development was severely limited, so was the setting up and configuration of Visual Studio 2008 for Cuda C development.</p>
<p>I have read &#8220;Cuda by example&#8230;&#8221; (<a href="http://developer.nvidia.com/object/cuda-by-example.html">http://developer.nvidia.com/object/cuda-by-example.html</a>), &#8220;Programming Massively Parallel Processors&#8230;&#8221; (<a href="http://www.nvidia.com/object/io_1264656303008.html">http://www.nvidia.com/object/io_1264656303008.html</a>) and &#8220;C Programming Language, 2. edition&#8221; (<a href="http://www.pearsonhighered.com/educator/product/C-Programming-Language/9780131103627.page">http://www.pearsonhighered.com/educator/product/C-Programming-Language/9780131103627.page</a>). These books have given me the foundation to start developing using Cuda C and GPGPU.</p>
<p>Setting up Visual Studio 2008 and making the compiler work required some work, but here is what I did.</p>
<h2>1. Download and install driver and toolkit</h2>
<p>Download Cuda toolkit and the developer driver and install. A restart is probably required. (<a href="http://developer.nvidia.com/object/gpucomputing.html">http://developer.nvidia.com/object/gpucomputing.html</a>)</p>
<h2>2. Start Visual Studio 2008, and create a new project of type Win32 Console Application</h2>
<p>Give the project and solution a name (here called Cuda_Template).</p>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_2_create_project..png"><img class="alignnone size-full wp-image-389" title="Step 2 - Create solution and project" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_2_create_project..png" alt="" width="804" height="572" /></a></p>
<h2>3. Click Next</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_3_click_next.png"><img class="alignnone size-full wp-image-398" title="Step 3 - Click next" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_3_click_next.png" alt="" width="625" height="530" /></a></p>
<h2>4. Select Console application and check the empty project, then click Finish</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_4_project_settings.png"><img class="alignnone size-full wp-image-399" title="Step 4 - Project settings" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_4_project_settings.png" alt="" width="625" height="530" /></a></p>
<h2>5. Add new item called main.cpp of type C++ File</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_5_create_cpp_file.png"><img class="alignnone size-full wp-image-400" title="Step 5 - Create C++ file" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_5_create_cpp_file.png" alt="" width="804" height="514" /></a></p>
<h2>6. Add the following code the file</h2>
<pre class="brush: cpp;">#include &lt;stdio.h&gt; 

int main() {

    printf("Hello world...\n);
    return 0;

}</pre>
<h2>7. Build and try to run the exe file. The output should be</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_7_exe_output.png"><img class="alignnone size-full wp-image-404" title="Step 7 - Hello world output" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_7_exe_output.png" alt="" width="709" height="359" /></a></p>
<h2>8. Select Project -&gt; Custom Build Rules&#8230;</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_8_custom_build_rules.png"><img class="alignnone size-full wp-image-405" title="Step 8 - Custom build rules" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_8_custom_build_rules.png" alt="" width="1280" height="760" /></a></p>
<h2>9. Select Cuda Runtime API build rule (v3.2)</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_9_cuda_build_rules.png"><img class="alignnone size-full wp-image-406" title="Step 9 - Cuda build rule" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_9_cuda_build_rules.png" alt="" width="676" height="433" /></a></p>
<h2>10. Add a new file called kernel.cu</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_10_create_kernel.png"><img class="alignnone size-full wp-image-407" title="Step 10 - Create kernel" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_10_create_kernel.png" alt="" width="804" height="514" /></a></p>
<h2>11. Add the following to the file kernel.cu</h2>
<pre class="brush: c;">/* power: raise base to n-th power; n &gt;= 0 */
__device__ int devicePower(int base, int n) {

    int p = 1;

    for (int i = 1; i &lt;= n; ++i) {
        p = p * base;
    }

    return p;
}

__global__ void power( int *base, int *n, int *output, int threadMax ) {

    int tid = threadIdx.x + blockIdx.x * blockDim.x;

    if (tid &lt; threadMax) {
        output[tid] = devicePower(base[tid], n[tid]);
    }

}</pre>
<h2>12. Right click the newly created file and select properties</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_12_kernel_properties.png"><img class="alignnone size-full wp-image-414" title="Step 12 - Kernel properties" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_12_kernel_properties.png" alt="" width="1280" height="760" /></a></p>
<h2>13. Set the &#8220;Exclude From Build&#8221; and make sure that the project still builds</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_13_kernel_exclude_from_build.png"><img class="alignnone size-full wp-image-415" title="Step 13 - Exclude kernel from build" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_13_kernel_exclude_from_build.png" alt="" width="759" height="531" /></a></p>
<h2>14. Create a new file called call_kernel.cu</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_14_create_kernel_call_file..png"><img class="alignnone size-full wp-image-416" title="Step 14 - Create C++ kernel calling file" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_14_create_kernel_call_file..png" alt="" width="804" height="514" /></a></p>
<h2>15. Add the following to the file call_kernel.cu</h2>
<pre class="brush: c">#include &lt;cuda_runtime_api.h&gt;
#include "main.h"

// includes, kernels
#include &lt;kernel.cu&gt;

void call_kernel_power(int *base, int *n, int *output, int elementCount) {

    int *dev_base, *dev_n, *dev_output;
    int gridX = (elementCount+ThreadsPerBlock-1)/ThreadsPerBlock;

    cudaMalloc( (void**)&amp;dev_base, elementCount * sizeof(int) );
    cudaMalloc( (void**)&amp;dev_n, elementCount * sizeof(int) );
    cudaMalloc( (void**)&amp;dev_output, elementCount * sizeof(int) );

    cudaMemcpy( dev_base, base, elementCount * sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy( dev_n, n, elementCount * sizeof(int), cudaMemcpyHostToDevice);

    power&lt;&lt;&lt;gridX,ThreadsPerBlock&gt;&gt;&gt;(dev_base, dev_n, dev_output, elementCount);

    cudaMemcpy( output, dev_output, elementCount * sizeof(int), cudaMemcpyDeviceToHost);

    cudaFree( dev_base );
    cudaFree( dev_n );
    cudaFree( dev_output );
}</pre>
<h2>16. Create a new header file called main.h</h2>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_16_create_main_header.png"><img class="alignnone size-full wp-image-419" title="Step 16 - Create header main.h file" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_16_create_main_header.png" alt="" width="804" height="514" /></a></p>
<h2>17. Add the following content to the file</h2>
<pre class="brush: cpp">#define ThreadsPerBlock 128

#include &lt;stdio.h&gt;

void call_kernel_power(int *base, int *n, int *output, int elementCount);</pre>
<h2>18. Update the main.cpp file with the following:</h2>
<pre class="brush: cpp">#include "main.h"

#define N   80000

int main() {

    printf("Power Cuda kernel test from C++\n");
    printf("Testing %d elements\n", N);

    int base[N], n[N], output[N];

    for(int i = 0; i &lt; N; i++) {
          base[i] = 2;
          n[i] = i+1;
          output[i] = 0;
      }

    call_kernel_power(base, n, output, N);

    for(int i = 0; i &lt; N &amp;&amp; i &lt; 15; i++) {

          printf("%d^%d = %d\n", base[i], n[i], output[i]);

      }

      printf("Done\n");

    return 0;
}</pre>
<h2>19. That should be it&#8230;</h2>
<p>You now have a template that you can work from. When you build the file and run it, I get this output:</p>
<p><a href="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_19_exe_output.png"><img class="alignnone size-full wp-image-417" title="Step 19 - Output" src="http://blog.ovesens.net/wp-content/uploads/2011/05/CudaTemplate_19_exe_output.png" alt="" width="661" height="487" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2011/05/cuda-v3-2-template-project-using-cpp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008 debugging and breakpoints</title>
		<link>http://blog.ovesens.net/2010/01/visual-studio-2008-debugging-and-breakpoints/</link>
		<comments>http://blog.ovesens.net/2010/01/visual-studio-2008-debugging-and-breakpoints/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 08:38:32 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vs2008]]></category>

		<guid isPermaLink="false">http://blog.ovesens.net/?p=207</guid>
		<description><![CDATA[My development tools are currently Visual Studio 2008, Resharper 4.5, Gallio and Testdriven.NET. But for as long as I have used these tools, my Visual Studio debugger has only worked partly. The problem When I inserted some breakpoints inÂ my code, &#8230; <a href="http://blog.ovesens.net/2010/01/visual-studio-2008-debugging-and-breakpoints/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My development tools are currently <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx" target="_blank">Visual Studio 2008</a>, <a href="http://www.jetbrains.com/resharper/index.html" target="_blank">Resharper 4.5</a>, <a href="http://www.gallio.org/" target="_blank">Gallio</a> and <a href="http://www.testdriven.net/" target="_blank">Testdriven.NET</a>. But for as long as I have used these tools, my Visual Studio debugger has only worked partly.</p>
<h2>The problem</h2>
<p>When I inserted some breakpoints inÂ my code, the first one was almost all the time hit. However, when I tried to step through the code, it worked fine for a bout 3-6 steps. But then Visual Studio debugger decided that was enough, and just completed the code.</p>
<p>The good thing was, it forced me to write many unit test cases, but sometimes I really think it is nice to visually see the state of your objects, in the code.</p>
<p>I have spoken to colleagues, and tested with different combinations of Gallio, Testdriven.NET and Re-sharper enabled, as I thought they cased the problem. But the debugger just kept bugging me. I had actually given up finding a solution to this problem, thinking that Visual Studio 2010 would fix it.</p>
<h2>The solution</h2>
<p>So finally, in a complete other context, I stumbled upon this page:</p>
<p><a href="http://code.msdn.microsoft.com/KB957912" target="_blank">http://code.msdn.microsoft.com/KB957912</a></p>
<p>And thought&#8230;. that title sounds interesting&#8230; I quickly moved to the <a href="http://support.microsoft.com/kb/957912" target="_blank">KB article</a>, and started to read. I thought, that sounds exactly as my problem.</p>
<p>With nothing to loose I installed the update, and started to test the debugger&#8230; until now it seems to work <img src='http://blog.ovesens.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><em>- please note, I do not use the debugger that often as I write very reliable code <img src='http://blog.ovesens.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2010/01/visual-studio-2008-debugging-and-breakpoints/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008 &#8211; ItemTemplatesCache missing</title>
		<link>http://blog.ovesens.net/2008/11/visual-studio-2008-itemtemplatescache-missing/</link>
		<comments>http://blog.ovesens.net/2008/11/visual-studio-2008-itemtemplatescache-missing/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 23:57:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vs]]></category>
		<category><![CDATA[vs2008]]></category>

		<guid isPermaLink="false">/post/2008/11/11/Visual-Studio-2008-ItemTemplatesCache-missing.aspx</guid>
		<description><![CDATA[The issue&#160; My Visual Studio 2008 opened the solution file with no problem. However, when I was to add a new class, user control, aspx file or similar, I received the error: Could not find part of &#34;c:\Program Files\Microsoft Visual &#8230; <a href="http://blog.ovesens.net/2008/11/visual-studio-2008-itemtemplatescache-missing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h1>The issue&nbsp;</h1>
<p>
My Visual Studio 2008 opened the solution file with no problem. However, when I was to add a new class, user control, aspx file or similar, I received the error:
</p>
<p>
Could not find part of &quot;c:\Program Files\Microsoft Visual Studio 9.0\&#8230;\ItemTemplatesCache&#8230;&quot;
</p>
<p>
[and the path to the ItemTemplatesCache in Visual Studio 2008 folder].
</p>
<h1>The solution</h1>
<p>
Well, one slution would be to reinstall or repair installation of Visual studio 2008. However, after searching for a while I found a solution that is much easier:
</p>
<ol>
<li>Open &quot;Visual Studio 2008 Command Prompt&quot; as an Administrator</li>
<li>Run the command: &quot;devenv /installvstemplates&quot;</li>
<li>That&#39;s it</li>
</ol>
<p>
&nbsp;
</p>
<p>
It takes a while but it completely rebuild your item template cache if it is corrupt or completely missing like me.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2008/11/visual-studio-2008-itemtemplatescache-missing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

