static CLAccelerator() { var accelerators = ImmutableArray.CreateBuilder <CLAcceleratorId>(); try { // Resolve all platforms if (CLAPI.GetNumPlatforms(out int numPlatforms) != CLError.CL_SUCCESS || numPlatforms < 1) { return; } var platforms = new IntPtr[numPlatforms]; if (CLAPI.GetPlatforms(platforms, out numPlatforms) != CLError.CL_SUCCESS) { return; } foreach (var platform in platforms) { // Resolve all devices if (CLAPI.GetNumDevices( platform, CLDeviceType.CL_DEVICE_TYPE_ALL, out int numDevices) != CLError.CL_SUCCESS) { continue; } var devices = new IntPtr[numDevices]; if (CLAPI.GetDevices( platform, CLDeviceType.CL_DEVICE_TYPE_ALL, devices, out numDevices) != CLError.CL_SUCCESS) { continue; } foreach (var device in devices) { // Check for available device if (CLAPI.GetDeviceInfo <int>( device, CLDeviceInfoType.CL_DEVICE_AVAILABLE) == 0) { continue; } accelerators.Add(new CLAcceleratorId( platform, device)); } } } catch (Exception) { // Ignore API-specific exceptions at this point } finally { CLAccelerators = accelerators.ToImmutable(); } }