/// <summary>Initializes OpenCL and reads devices. Uses previously created context and command queue if supplied. In that case DevicesToUse is ignored.</summary> public static void InitCL(ComputeDeviceTypes DevicesToUse, ComputeContext PrevCtx, ComputeCommandQueue PrevCQ) { if (CLAcceleration != CLAccelerationType.UsingCL) { try { if (ComputePlatform.Platforms.Count > 0) CLAccel = CLAccelerationType.UsingCL; else CLAccel = CLAccelerationType.NotUsingCL; //Program.Event = new List<ComputeEventBase>(); CLPlatforms = new List<ComputePlatform>(); foreach (ComputePlatform pp in ComputePlatform.Platforms) CLPlatforms.Add(pp); ComputeContextPropertyList Properties = new ComputeContextPropertyList(ComputePlatform.Platforms[0]); if (PrevCtx == null) { Program.Context = new ComputeContext(DevicesToUse, Properties, null, IntPtr.Zero); } else Program.Context = PrevCtx; CLDevices = new List<ComputeDevice>(); for (int i = 0; i < Program.Context.Devices.Count; i++) { CLDevices.Add(Program.Context.Devices[i]); } Program.CommQueues = new List<ComputeCommandQueue>(); Program.AsyncCommQueues = new List<ComputeCommandQueue>(); Program.DefaultCQ = -1; if (PrevCQ == null) { for (int i = 0; i < CLDevices.Count; i++) { //Comandos para os devices ComputeCommandQueue CQ = new ComputeCommandQueue(Program.Context, CLDevices[i], ComputeCommandQueueFlags.None); ComputeCommandQueue AsyncCQ = new ComputeCommandQueue(Program.Context, CLDevices[i], ComputeCommandQueueFlags.OutOfOrderExecution); //Comando para a primeira GPU if ((CLDevices[i].Type == ComputeDeviceTypes.Gpu || CLDevices[i].Type == ComputeDeviceTypes.Accelerator) && Program.DefaultCQ < 0) Program.DefaultCQ = i; Program.CommQueues.Add(CQ); Program.AsyncCommQueues.Add(AsyncCQ); } //Só tem CPU if (Program.DefaultCQ < 0 && Program.CommQueues.Count > 0) Program.DefaultCQ = 0; } else { Program.CommQueues.Add(PrevCQ); Program.DefaultCQ = 0; } } catch (Exception ex) { CLInitErr = ex.ToString(); CLAccel = CLAccelerationType.NotUsingCL; } } }
/// <summary>Sets CLCalc status to NotUsingCL</summary> public static void DisableCL() { CLAccel = CLAccelerationType.NotUsingCL; }