public void PlatformQueries() { uint platformCount; Cl.ErrorCode result = Cl.GetPlatformIDs(0, null, out platformCount); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform count"); Console.WriteLine("{0} platforms found", platformCount); var platformIds = new Cl.Platform[platformCount]; result = Cl.GetPlatformIDs(platformCount, platformIds, out platformCount); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform ids"); foreach (Cl.Platform platformId in platformIds) { IntPtr paramSize; result = Cl.GetPlatformInfo(platformId, Cl.PlatformInfo.Name, IntPtr.Zero, Cl.InfoBuffer.Empty, out paramSize); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform name size"); using (var buffer = new Cl.InfoBuffer(paramSize)) { result = Cl.GetPlatformInfo(platformIds[0], Cl.PlatformInfo.Name, paramSize, buffer, out paramSize); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform name string"); Console.WriteLine("Platform: {0}", buffer); } } }
public void DeviceQueries() { uint platformCount; Cl.ErrorCode result = Cl.GetPlatformIDs(0, null, out platformCount); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform count"); Console.WriteLine("{0} platforms found", platformCount); var platformIds = new Cl.Platform[platformCount]; result = Cl.GetPlatformIDs(platformCount, platformIds, out platformCount); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform ids"); foreach (Cl.Platform platformId in platformIds) { IntPtr paramSize; result = Cl.GetPlatformInfo(platformId, Cl.PlatformInfo.Name, IntPtr.Zero, Cl.InfoBuffer.Empty, out paramSize); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform name size"); using (var buffer = new Cl.InfoBuffer(paramSize)) { result = Cl.GetPlatformInfo(platformIds[0], Cl.PlatformInfo.Name, paramSize, buffer, out paramSize); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get platform name string"); } uint deviceCount; result = Cl.GetDeviceIDs(platformIds[0], Cl.DeviceType.All, 0, null, out deviceCount); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get device count"); var deviceIds = new Cl.Device[deviceCount]; result = Cl.GetDeviceIDs(platformIds[0], Cl.DeviceType.All, deviceCount, deviceIds, out deviceCount); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get device ids"); result = Cl.GetDeviceInfo(deviceIds[0], Cl.DeviceInfo.Vendor, IntPtr.Zero, Cl.InfoBuffer.Empty, out paramSize); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get device vendor name size"); using (var buf = new Cl.InfoBuffer(paramSize)) { result = Cl.GetDeviceInfo(deviceIds[0], Cl.DeviceInfo.Vendor, paramSize, buf, out paramSize); Assert.AreEqual(result, Cl.ErrorCode.Success, "Could not get device vendor name string"); var deviceVendor = buf.ToString(); } } }
public static byte[] ToGPUClBinary(this Program irprog, Cl.Device device) { Cl.ErrorCode error; Cl.Platform platform = Cl.GetDeviceInfo(device, Cl.DeviceInfo.Platform, out error).CastTo <Cl.Platform>(); clSafeCall(error); string platformName = Cl.GetPlatformInfo(platform, Cl.PlatformInfo.Name, out error).ToString(); clSafeCall(error); switch (platformName) { case "NVIDIA CUDA": return(irprog.ToNVIDIAClBinary(device)); case "AMD Accelerated Parallel Processing": return(irprog.ToAMDClBinary(device)); default: throw new NotSupportedException(platformName); } }