Waz up?

After a year plus some, Campy is starting to work on some practical examples. But, when things go sour in an executing kernel, there’s not much I can do but single step and look at disassemblies and registers of the GPU. I know what things should look like because you’d expect that from a compiler writer. But, for the average user, they’re not going to understand much. Before I get LLVM debugging information really working, the first step is good ol’ WriteLine() calls. What I should be able to do is this little ditty:


using System;
namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            Campy.Parallel.For(4, i => { System.Console.WriteLine(i); });
        }
    }
}

This simple kernel does quite a bit. First thing to note is the code generated :


Node: 1 
    Method System.Void ConsoleApp4.Program/<>c::b__1_0(System.Int32) ConsoleApp4.exe C:\Users\kenne\Documents\Campy2\ConsoleApp4\bin\Debug\ConsoleApp4.exe
    Method System.Void ConsoleApp4.Program/<>c::b__1_0(System.Int32) ConsoleApp4.exe .\ConsoleApp4.exe
    HasThis   False
    Args   0
    Locals 0
    Return (reuse) False
    Instructions:
        IL_0000: nop    
        IL_0001: ldarg.1    
        IL_0002: call System.Void System.Console::WriteLine(System.String)    
        IL_0007: nop    
        IL_0008: ret    

In this example, there is no expect call to “ToString()” the value after the ldarg.1, so Campy must know to convert the integer to a string. I’m a little surprised when I see crap like this coming out of the C# compiler; it would have made my life a little easier if it generated code to convert to the appropriate parameter type. It’s likely there are many other such implicit type conversions: the rules for implicit argument coercion is in ECMA 335 (page 305), although it does not mention int to string conversion. Does anyone know where this is in the spec?

Second, while a lot of the infrastructure for compiling this test works, there are still a number of problems preventing it from working. Looking through the output of the compiler, the generated LLVM code isn’t correct for newarr:

        IL_0040: newarr System.Char    

This will be fixed. I’m hoping the next release will have WriteLine finally working.

Third, I’m noticing that there are lots of try-catch-finally blocks in the NET runtime to compile. I’ve been holding off on this, as it appears that CUDA does not allow try/catch exception handling whatsoever. For the moment, I can try to string together basic blocks so that the finally clauses are executed at least from the try clause. I might be able to implement some sort of exception handling, but it’s not at all clear at the moment.

BTW, does anyone else hate how Windows OS ignores case for file or directory names? I just found out that there’s a “Corlib” and a “corlib” in the Campy Git repository. Undoubtedly I added using the CLI for Git and typed in by mistake both ways. Unfortunately, to correct it, I’ll have to use Linux less I repeat the same mistakes on Windows.

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.