Skip to content

Commit

Permalink
Moved OpenCL C version detection to CLAcceleratorId to distinguish be…
Browse files Browse the repository at this point in the history
…tween supported and unsupported accelerators.
  • Loading branch information
m4rs-mt committed Nov 30, 2019
1 parent efd7506 commit 4c553aa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Src/ILGPU.Tests.Cuda/ContextProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ILGPU.IR.Transformations;
using ILGPU.Runtime;
using ILGPU.Runtime.Cuda;
using System;

namespace ILGPU.Tests.Cuda
{
Expand All @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions Src/ILGPU.Tests.OpenCL/ContextProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ILGPU.IR.Transformations;
using ILGPU.Runtime;
using ILGPU.Runtime.OpenCL;
using System;

namespace ILGPU.Tests.OpenCL
{
Expand All @@ -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);
}
Expand Down
28 changes: 15 additions & 13 deletions Src/ILGPU/Runtime/OpenCL/CLAccelerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public sealed class CLAccelerator : KernelAccelerator<CLCompiledKernel, CLKernel
static CLAccelerator()
{
var accelerators = ImmutableArray.CreateBuilder<CLAcceleratorId>();
var allAccelerators = ImmutableArray.CreateBuilder<CLAcceleratorId>();

try
{
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -158,14 +162,20 @@ static CLAccelerator()
finally
{
CLAccelerators = accelerators.ToImmutable();
AllCLAccelerators = allAccelerators.ToImmutable();
}
}

/// <summary>
/// Represents the list of available Cuda accelerators.
/// Represents the list of available and supported OpenCL accelerators.
/// </summary>
public static ImmutableArray<CLAcceleratorId> CLAccelerators { get; }

/// <summary>
/// Represents the list of all available OpenCL accelerators.
/// </summary>
public static ImmutableArray<CLAcceleratorId> AllCLAccelerators { get; }

#endregion

#region Instance
Expand All @@ -185,6 +195,7 @@ public CLAccelerator(Context context, CLAcceleratorId acceleratorId)

PlatformId = acceleratorId.PlatformId;
DeviceId = acceleratorId.DeviceId;
CVersion = acceleratorId.CVersion;

PlatformName = CLAPI.GetPlatformInfo(
PlatformId,
Expand All @@ -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<int>(
DeviceId,
Expand Down Expand Up @@ -338,7 +341,6 @@ private void InitVendorFeatures()
}
}


/// <summary>
/// Initializes support for sub groups.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Src/ILGPU/Runtime/OpenCL/CLAcceleratorId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<clGetKernelSubGroupInfoKHR>(platformId);
}
Expand All @@ -94,6 +103,11 @@ public CLAcceleratorId(IntPtr platformId, IntPtr deviceId)
/// </summary>
public CLDeviceType DeviceType { get; }

/// <summary>
/// Returns the supported OpenCL C version.
/// </summary>
public CLCVersion CVersion { get; }

/// <summary>
/// Returns all extensions.
/// </summary>
Expand Down

0 comments on commit 4c553aa

Please sign in to comment.