Getting build error details in openCL and Cloo

I’m learning OpenCL using Cloo, and not surprisingly my first kernels contain errors (but I’m improving very quickly).

This piece of code gets a log of the errors from the build process. It is simple but I think it is worth to be shared because currently there are little code samples for Cloo available on the web.

    var source = @"kernel void MyCode () {...........}";
    var platform = ComputePlatform.Platforms[0];
    var devices = new List(platform.Devices.ToArray());
    var properties = new ComputeContextPropertyList(platform);
    var context = new ComputeContext(devices, properties, null, IntPtr.Zero);
    var program = new ComputeProgram(context, source);
    var statuses = new ComputeProgramBuildStatus[devices.Count];
    var buildLog = "";
    var success = true;
    try
    {
        program.Build(null, null, null, IntPtr.Zero);
    }
    catch
    {
        success = false;
        var sb = new StringBuilder();
        for (int i = 0; i < devices.Count; ++i)
        {
            var device = devices[i];
            statuses[i] = program.GetBuildStatus(device);
            sb.Append("Device: ");
            sb.AppendLine(device.Name);
            sb.Append("Build status: ");
            sb.AppendLine(program.GetBuildStatus(device).ToString());
            sb.Append("Build log: ");
            sb.AppendLine(program.GetBuildLog(devices[0]));
        }
        buildLog = sb.ToString();
    }
    if (!success)
    {
        //manage error situation
    }

Keeping things in (partial) order

I this thread I will discuss about making order in our life… well… at least in a long vector of objects… OK, just a small part of that vector.

This is a fundamental aspect of search engines: you are interested in getting only the k most relevant results, whatever the size of the collection you are searching on is.
The k value is usually very small with respect to the collection size, e.g. on the Web one is likely to look at just the first ten-twenty results. Search engines typically set a z value of maximum returned results that is designed to be larger than the largest part of possible k values, e.g. Google returns at most one thousand results.
Continue reading