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
}