From 4c553aa99c564a9f4f632d7d32c56dd8b0430e54 Mon Sep 17 00:00:00 2001 From: Marcel Koester Date: Sat, 30 Nov 2019 10:27:37 +0100 Subject: [PATCH] Moved OpenCL C version detection to CLAcceleratorId to distinguish between supported and unsupported accelerators. --- Src/ILGPU.Tests.Cuda/ContextProvider.cs | 3 +++ Src/ILGPU.Tests.OpenCL/ContextProvider.cs | 3 +++ Src/ILGPU/Runtime/OpenCL/CLAccelerator.cs | 28 +++++++++++---------- Src/ILGPU/Runtime/OpenCL/CLAcceleratorId.cs | 14 +++++++++++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Src/ILGPU.Tests.Cuda/ContextProvider.cs b/Src/ILGPU.Tests.Cuda/ContextProvider.cs index b578c351c..b12e3d368 100644 --- a/Src/ILGPU.Tests.Cuda/ContextProvider.cs +++ b/Src/ILGPU.Tests.Cuda/ContextProvider.cs @@ -1,6 +1,7 @@ using ILGPU.IR.Transformations; using ILGPU.Runtime; using ILGPU.Runtime.Cuda; +using System; namespace ILGPU.Tests.Cuda { @@ -12,6 +13,8 @@ public CudaContextProvider(OptimizationLevel optimizationLevel) public override Accelerator CreateAccelerator(Context context) { + if (CudaAccelerator.CudaAccelerators.Length < 1) + throw new NotSupportedException(); return new CudaAccelerator(context); } } diff --git a/Src/ILGPU.Tests.OpenCL/ContextProvider.cs b/Src/ILGPU.Tests.OpenCL/ContextProvider.cs index 6b576f890..579357d10 100644 --- a/Src/ILGPU.Tests.OpenCL/ContextProvider.cs +++ b/Src/ILGPU.Tests.OpenCL/ContextProvider.cs @@ -1,6 +1,7 @@ using ILGPU.IR.Transformations; using ILGPU.Runtime; using ILGPU.Runtime.OpenCL; +using System; namespace ILGPU.Tests.OpenCL { @@ -12,6 +13,8 @@ public OpenCLContextProvider(OptimizationLevel optimizationLevel) public override Accelerator CreateAccelerator(Context context) { + if (CLAccelerator.CLAccelerators.Length < 1) + throw new NotSupportedException(); var mainAccelerator = CLAccelerator.CLAccelerators[0]; return new CLAccelerator(context, mainAccelerator); } diff --git a/Src/ILGPU/Runtime/OpenCL/CLAccelerator.cs b/Src/ILGPU/Runtime/OpenCL/CLAccelerator.cs index b468309b5..1e41d7a9b 100644 --- a/Src/ILGPU/Runtime/OpenCL/CLAccelerator.cs +++ b/Src/ILGPU/Runtime/OpenCL/CLAccelerator.cs @@ -108,6 +108,7 @@ public sealed class CLAccelerator : KernelAccelerator(); + var allAccelerators = ImmutableArray.CreateBuilder(); try { @@ -145,9 +146,12 @@ static CLAccelerator() CLDeviceInfoType.CL_DEVICE_AVAILABLE) == 0) continue; - accelerators.Add(new CLAcceleratorId( - platform, - device)); + var acceleratorId = new CLAcceleratorId(platform, device); + + if (acceleratorId.CVersion < CLBackend.MinimumVersion) + allAccelerators.Add(acceleratorId); + else + accelerators.Add(acceleratorId); } } } @@ -158,14 +162,20 @@ static CLAccelerator() finally { CLAccelerators = accelerators.ToImmutable(); + AllCLAccelerators = allAccelerators.ToImmutable(); } } /// - /// Represents the list of available Cuda accelerators. + /// Represents the list of available and supported OpenCL accelerators. /// public static ImmutableArray CLAccelerators { get; } + /// + /// Represents the list of all available OpenCL accelerators. + /// + public static ImmutableArray AllCLAccelerators { get; } + #endregion #region Instance @@ -185,6 +195,7 @@ public CLAccelerator(Context context, CLAcceleratorId acceleratorId) PlatformId = acceleratorId.PlatformId; DeviceId = acceleratorId.DeviceId; + CVersion = acceleratorId.CVersion; PlatformName = CLAPI.GetPlatformInfo( PlatformId, @@ -211,14 +222,6 @@ public CLAccelerator(Context context, CLAcceleratorId acceleratorId) DeviceId, CLDeviceInfoType.CL_DEVICE_TYPE); - // Determine the supported OpenCL C version - var clVersionString = CLAPI.GetDeviceInfo( - DeviceId, - CLDeviceInfoType.CL_DEVICE_OPENCL_C_VERSION); - if (!CLCVersion.TryParse(clVersionString, out CLCVersion version)) - version = CLCVersion.CL10; - CVersion = version; - // Max grid size int workItemDimensions = IntrinsicMath.Max(CLAPI.GetDeviceInfo( DeviceId, @@ -338,7 +341,6 @@ private void InitVendorFeatures() } } - /// /// Initializes support for sub groups. /// diff --git a/Src/ILGPU/Runtime/OpenCL/CLAcceleratorId.cs b/Src/ILGPU/Runtime/OpenCL/CLAcceleratorId.cs index 93f58aff4..85307e88e 100644 --- a/Src/ILGPU/Runtime/OpenCL/CLAcceleratorId.cs +++ b/Src/ILGPU/Runtime/OpenCL/CLAcceleratorId.cs @@ -9,6 +9,7 @@ // Illinois Open Source License. See LICENSE.txt for details // ----------------------------------------------------------------------------- +using ILGPU.Backends.OpenCL; using ILGPU.Runtime.OpenCL.API; using ILGPU.Util; using System; @@ -71,6 +72,14 @@ public CLAcceleratorId(IntPtr platformId, IntPtr deviceId) extensionString.ToLower().Split(' ')); Extensions = extensionSet.ToImmutableArray(); + // Determine the supported OpenCL C version + var clVersionString = CLAPI.GetDeviceInfo( + DeviceId, + CLDeviceInfoType.CL_DEVICE_OPENCL_C_VERSION); + if (!CLCVersion.TryParse(clVersionString, out CLCVersion version)) + version = CLCVersion.CL10; + CVersion = version; + // Resolve extension method getKernelSubGroupInfo = CLAPI.GetExtension(platformId); } @@ -94,6 +103,11 @@ public CLAcceleratorId(IntPtr platformId, IntPtr deviceId) /// public CLDeviceType DeviceType { get; } + /// + /// Returns the supported OpenCL C version. + /// + public CLCVersion CVersion { get; } + /// /// Returns all extensions. ///