Skip to content

Commit

Permalink
Updated to use generated Cuda constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ authored and m4rs-mt committed Feb 15, 2023
1 parent 17f7cdb commit 938a705
Show file tree
Hide file tree
Showing 10 changed files with 716 additions and 295 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ Src/ILGPU/IntrinsicMath.CPUOnly.cs
Src/ILGPU/Memory.cs
Src/ILGPU/Runtime/ArrayViewExtensions.Generated.cs
Src/ILGPU/Runtime/ArrayViews.cs
Src/ILGPU/Runtime/Cuda/CudaArchitecture.Generated.cs
Src/ILGPU/Runtime/Cuda/CudaAsm.Generated.cs
Src/ILGPU/Runtime/Cuda/CudaDriverVersion.Generated.cs
Src/ILGPU/Runtime/Cuda/CudaInstructionSet.Generated.cs
Src/ILGPU/Runtime/Cuda/LibDevice.cs
Src/ILGPU/Runtime/KernelLoaders.cs
Src/ILGPU/Runtime/MemoryBuffers.cs
Expand Down
42 changes: 42 additions & 0 deletions Src/ILGPU/ILGPU.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,26 @@
<AutoGen>True</AutoGen>
<DependentUpon>IntrinsicMatchers.tt</DependentUpon>
</None>
<None Include="Runtime\Cuda\CudaArchitecture.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaArchitecture.Generated.tt</DependentUpon>
</None>
<None Include="Runtime\Cuda\CudaAsm.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaAsm.Generated.tt</DependentUpon>
</None>
<None Include="Runtime\Cuda\CudaDriverVersion.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaDriverVersion.Generated.tt</DependentUpon>
</None>
<None Include="Runtime\Cuda\CudaInstructionSet.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaInstructionSet.Generated.tt</DependentUpon>
</None>
<None Include="Runtime\PageLockedArrays.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -157,6 +172,18 @@
<AutoGen>True</AutoGen>
<DependentUpon>PrimitiveDataBlocks.tt</DependentUpon>
</None>
<None Update="Runtime\Cuda\CudaArchitecture.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>CudaArchitecture.Generated.cs</LastGenOutput>
</None>
<None Update="Runtime\Cuda\CudaDriverVersion.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>CudaDriverVersion.Generated.cs</LastGenOutput>
</None>
<None Update="Runtime\Cuda\CudaInstructionSet.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>CudaInstructionSet.Generated.cs</LastGenOutput>
</None>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -230,11 +257,26 @@
<AutoGen>True</AutoGen>
<DependentUpon>ValueTuples.tt</DependentUpon>
</Compile>
<Compile Update="Runtime\Cuda\CudaArchitecture.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaArchitecture.Generated.tt</DependentUpon>
</Compile>
<Compile Update="Runtime\Cuda\CudaAsm.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaAsm.Generated.tt</DependentUpon>
</Compile>
<Compile Update="Runtime\Cuda\CudaDriverVersion.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaDriverVersion.Generated.tt</DependentUpon>
</Compile>
<Compile Update="Runtime\Cuda\CudaInstructionSet.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>CudaInstructionSet.Generated.tt</DependentUpon>
</Compile>
<Compile Update="Runtime\Cuda\LibDevice.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down
48 changes: 48 additions & 0 deletions Src/ILGPU/Runtime/Cuda/CudaArchitecture.Generated.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2023 ILGPU Project
// www.ilgpu.net
//
// File: CudaArchitecture.Generated.tt/CudaArchitecture.Generated.cs
//
// This file is part of ILGPU and is distributed under the University of Illinois Open
// Source License. See LICENSE.txt for details.
// ---------------------------------------------------------------------------------------

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file="../../Static/TypeInformation.ttinclude" #>
<#@ include file="../../Static/CudaVersions.ttinclude" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<#
string rootPath = Host.ResolvePath("../../Static");
var versions = CudaVersions.Load(rootPath, "CudaVersions.xml");

var architectures =
versions
.Select(x => x.ArchitectureVersion)
.Distinct()
.OrderBy(x => x)
.ToArray();
#>

namespace ILGPU.Runtime.Cuda
{
partial struct CudaArchitecture
{
#region Constants

<# foreach (var arch in architectures) { #>
/// <summary>
/// The <#= arch.Major #>.<#= arch.Minor #> architecture.
/// </summary>
public static readonly CudaArchitecture SM_<#= arch.Major #><#= arch.Minor #> =
new CudaArchitecture(<#= arch.Major #>, <#= arch.Minor #>);

<# } #>
#endregion
}
}
98 changes: 2 additions & 96 deletions Src/ILGPU/Runtime/Cuda/CudaArchitecture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021-2022 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: CudaArchitecture.cs
Expand All @@ -17,104 +17,10 @@ namespace ILGPU.Runtime.Cuda
/// <summary>
/// Represents a Cuda architecture.
/// </summary>
public readonly struct CudaArchitecture :
public readonly partial struct CudaArchitecture :
IEquatable<CudaArchitecture>,
IComparable<CudaArchitecture>
{
#region Constants

/// <summary>
/// The 3.0 architecture.
/// </summary>
public static readonly CudaArchitecture SM_30 = new CudaArchitecture(3, 0);

/// <summary>
/// The 3.2 architecture.
/// </summary>
public static readonly CudaArchitecture SM_32 = new CudaArchitecture(3, 2);

/// <summary>
/// The 3.5 architecture.
/// </summary>
public static readonly CudaArchitecture SM_35 = new CudaArchitecture(3, 5);

/// <summary>
/// The 3.7 architecture.
/// </summary>
public static readonly CudaArchitecture SM_37 = new CudaArchitecture(3, 7);

/// <summary>
/// The 5.0 architecture.
/// </summary>
public static readonly CudaArchitecture SM_50 = new CudaArchitecture(5, 0);

/// <summary>
/// The 5.2 architecture.
/// </summary>
public static readonly CudaArchitecture SM_52 = new CudaArchitecture(5, 2);

/// <summary>
/// The 5.3 architecture.
/// </summary>
public static readonly CudaArchitecture SM_53 = new CudaArchitecture(5, 3);

/// <summary>
/// The 6.0 architecture.
/// </summary>
public static readonly CudaArchitecture SM_60 = new CudaArchitecture(6, 0);

/// <summary>
/// The 6.1 architecture.
/// </summary>
public static readonly CudaArchitecture SM_61 = new CudaArchitecture(6, 1);

/// <summary>
/// The 6.2 architecture.
/// </summary>
public static readonly CudaArchitecture SM_62 = new CudaArchitecture(6, 2);

/// <summary>
/// The 7.0 architecture.
/// </summary>
public static readonly CudaArchitecture SM_70 = new CudaArchitecture(7, 0);

/// <summary>
/// The 7.2 architecture.
/// </summary>
public static readonly CudaArchitecture SM_72 = new CudaArchitecture(7, 2);

/// <summary>
/// The 7.5 architecture.
/// </summary>
public static readonly CudaArchitecture SM_75 = new CudaArchitecture(7, 5);

/// <summary>
/// The 8.0 architecture.
/// </summary>
public static readonly CudaArchitecture SM_80 = new CudaArchitecture(8, 0);

/// <summary>
/// The 8.6 architecture.
/// </summary>
public static readonly CudaArchitecture SM_86 = new CudaArchitecture(8, 6);

/// <summary>
/// The 8.7 architecture.
/// </summary>
public static readonly CudaArchitecture SM_87 = new CudaArchitecture(8, 7);

/// <summary>
/// The 8.9 architecture.
/// </summary>
public static readonly CudaArchitecture SM_89 = new CudaArchitecture(8, 9);

/// <summary>
/// The 9.0 architecture.
/// </summary>
public static readonly CudaArchitecture SM_90 = new CudaArchitecture(9, 0);

#endregion

#region Instance

/// <summary>
Expand Down
86 changes: 86 additions & 0 deletions Src/ILGPU/Runtime/Cuda/CudaDriverVersion.Generated.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2023 ILGPU Project
// www.ilgpu.net
//
// File: CudaDriverVersion.Generated.tt/CudaDriverVersion.Generated.cs
//
// This file is part of ILGPU and is distributed under the University of Illinois Open
// Source License. See LICENSE.txt for details.
// ---------------------------------------------------------------------------------------

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file="../../Static/TypeInformation.ttinclude" #>
<#@ include file="../../Static/CudaVersions.ttinclude" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<#
string rootPath = Host.ResolvePath("../../Static");
var versions = CudaVersions.Load(rootPath, "CudaVersions.xml");

var architectures =
versions
.GroupBy(x => x.ArchitectureVersion)
.OrderBy(x => x.Key)
.Select(g => (g.Key, g.Min(x => x.DriverVersion)))
.ToArray();

var instructionSets =
versions
.GroupBy(x => x.InstructionSetVersion)
.OrderBy(x => x.Key)
.Select(g => (g.Key, g.Min(x => x.DriverVersion)))
.ToArray();
#>

using System.Collections.Generic;

namespace ILGPU.Runtime.Cuda
{
partial class CudaDriverVersionUtils
{
#region Static

/// <summary>
/// Maps PTX architecture to their corresponding minimum CUDA driver version.
/// </summary>
private static readonly Dictionary<
CudaArchitecture,
CudaDriverVersion> ArchitectureLookup =
new Dictionary<CudaArchitecture, CudaDriverVersion>
{
<# foreach (var architecture in architectures) { #>
<# var arch = architecture.Item1; #>
<# var drv = architecture.Item2; #>
{
CudaArchitecture.SM_<#= arch.Major #><#= arch.Minor #>,
CudaDriverVersion.FromMajorMinor(<#= drv.Major #>, <#= drv.Minor #>)
},
<# } #>
};

/// <summary>
/// Maps PTX ISA to their corresponding minimum CUDA driver version.
/// </summary>
internal static readonly Dictionary<
CudaInstructionSet,
CudaDriverVersion> InstructionSetLookup =
new Dictionary<CudaInstructionSet, CudaDriverVersion>
{
<# foreach (var instructionSet in instructionSets) { #>
<# var isa = instructionSet.Item1; #>
<# var drv = instructionSet.Item2; #>
{
CudaInstructionSet.ISA_<#= isa.Major #><#= isa.Minor #>,
CudaDriverVersion.FromMajorMinor(<#= drv.Major #>, <#= drv.Minor #>)
},
<# } #>
};


#endregion
}
}
Loading

0 comments on commit 938a705

Please sign in to comment.