private void CreateOpenCLContext(OpenCLNNInitParameters oclInitPars) { ComputePlatform platform = null; if (String.IsNullOrEmpty(oclInitPars.PlatformName)) { platform = OpenCLContext.DefaultPlatform; } else { platform = OpenCLContext.Platforms.Where(p => string.Compare(oclInitPars.PlatformName, p.Name, true) == 0).FirstOrDefault(); } if (platform == null) throw new OpenCLException("Platform '" + oclInitPars.PlatformName + "' not found."); oclContext = new OpenCLContext(ComputeDeviceTypes.All, platform); try { if (string.IsNullOrEmpty(oclInitPars.DeviceName)) { oclDevice = oclContext.DefaultDevice; //oclDevice = oclContext.Devices.Where(d => d.Type == ComputeDeviceTypes.Cpu).First(); } else { oclDevice = oclContext.Devices.Where(d => string.Compare(oclInitPars.DeviceName, d.Name, true) == 0).FirstOrDefault(); } if (oclDevice == null) throw new OpenCLException("Device '" + oclInitPars.DeviceName + "' not found."); oclQueue = oclContext.CreateQueue(oclDevice, ComputeCommandQueueFlags.OutOfOrderExecution); } catch { oclContext.Dispose(); oclContext = null; throw; } }
private void DisposeUnmanagedResources() { oclValueBuffer.Dispose(); oclValueBuffer = null; oclQueue.Dispose(); oclQueue = null; oclContext.Dispose(); oclContext = null; }