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(); } }
static CLAccelerator() { var accelerators = ImmutableArray.CreateBuilder <CLAcceleratorId>(); var allAccelerators = ImmutableArray.CreateBuilder <CLAcceleratorId>(); var devices = new IntPtr[MaxNumDevicesPerPlatform]; 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 int numDevices = devices.Length; Array.Clear(devices, 0, numDevices); if (CLAPI.GetDevices( platform, CLDeviceType.CL_DEVICE_TYPE_ALL, devices, out numDevices) != CLError.CL_SUCCESS) { continue; } for (int i = 0; i < numDevices; ++i) { // Resolve device and ignore invalid devices var device = devices[i]; if (device == IntPtr.Zero) { continue; } // Check for available device if (CLAPI.GetDeviceInfo <int>( device, CLDeviceInfoType.CL_DEVICE_AVAILABLE) == 0) { continue; } var acceleratorId = new CLAcceleratorId(platform, device); allAccelerators.Add(acceleratorId); if (acceleratorId.CVersion >= CLBackend.MinimumVersion) { accelerators.Add(acceleratorId); } } } } catch (Exception) { // Ignore API-specific exceptions at this point } finally { CLAccelerators = accelerators.ToImmutable(); AllCLAccelerators = allAccelerators.ToImmutable(); } }