Skip to content

Commit

Permalink
Moved OpenCL IntrinsicMath implementations. (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ authored Apr 9, 2024
1 parent dd46974 commit 2a7db8a
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 486 deletions.
28 changes: 1 addition & 27 deletions Src/ILGPU.Algorithms/CL/CLContext.Generated.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU Algorithms
// Copyright (c) 2019-2021 ILGPU Project
// Copyright (c) 2019-2024 ILGPU Project
// www.ilgpu.net
//
// File: CLContext.Generated.tt/CLContext.Generated.cs
Expand All @@ -17,16 +17,6 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<#
var unaryMathFunctions = new ValueTuple<string, Type, string, string>[]
{
UnaryMathFunctions[18], // Rcp
UnaryMathFunctions[19], // Rcp
};
var binaryMathFunctions = new ValueTuple<string, Type, string, string>[]
{
BinaryMathFunctions[6], // Log
BinaryMathFunctions[7], // Log
};
var xmathUnaryCodeGenerators = new ValueTuple<string, string>[]
{
( "RoundAwayFromZero", "round" ),
Expand All @@ -49,22 +39,6 @@ namespace ILGPU.Algorithms.CL
public static void EnableCLAlgorithms(IntrinsicImplementationManager manager)
{
// Register math intrinsics
<# foreach (var (name, type, kind, basicType) in binaryMathFunctions) { #>
manager.RegisterBinaryArithmetic(
BinaryArithmeticKind.<#= kind #>,
BasicValueType.<#= basicType #>,
GetMathIntrinsic(
"<#= name #>",
typeof(<#= type #>), typeof(<#= type #>)));
<# } #>

<# foreach (var (name, type, kind, basicType) in unaryMathFunctions) { #>
manager.RegisterUnaryArithmetic(
UnaryArithmeticKind.<#= kind #>,
BasicValueType.<#= basicType #>,
MathCodeGeneratorIntrinsic);
<# } #>

<# foreach (var (name, functionName) in xmathUnaryCodeGenerators) { #>
RegisterXMathCodeGenerator(
manager,
Expand Down
46 changes: 1 addition & 45 deletions Src/ILGPU.Algorithms/CL/CLContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU Algorithms
// Copyright (c) 2019-2023 ILGPU Project
// Copyright (c) 2019-2024 ILGPU Project
// www.ilgpu.net
//
// File: CLContext.cs
Expand All @@ -27,32 +27,6 @@ namespace ILGPU.Algorithms.CL
/// </summary>
static partial class CLContext
{
/// <summary>
/// The <see cref="CLMath"/> type.
/// </summary>
private static readonly Type CLMathType = typeof(CLMath);

/// <summary>
/// Represents the <see cref="CLMath.GenerateMathIntrinsic(CLBackend,
/// CLCodeGenerator, IR.Value)"/>
/// methods.
/// </summary>
private static readonly MethodInfo MathCodeGenerator =
CLMathType.GetMethod(
nameof(CLMath.GenerateMathIntrinsic),
AlgorithmContext.IntrinsicBindingFlags)
.ThrowIfNull();

/// <summary>
/// Represents the intrinsic representation of the
/// <see cref="MathCodeGenerator"/>.
/// </summary>
private static readonly CLIntrinsic MathCodeGeneratorIntrinsic =
new CLIntrinsic(
MathCodeGenerator,
IntrinsicImplementationMode.GenerateCode)
.ThrowIfNull();

/// <summary>
/// The <see cref="CLGroupExtensions"/> type.
/// </summary>
Expand All @@ -63,24 +37,6 @@ static partial class CLContext
/// </summary>
internal static readonly Type CLWarpExtensionsType = typeof(CLWarpExtensions);

/// <summary>
/// Resolves a CL intrinsic for the given math-function configuration.
/// </summary>
/// <param name="name">The intrinsic name.</param>
/// <param name="types">The parameter types.</param>
/// <returns>The resolved intrinsic representation.</returns>
private static CLIntrinsic GetMathIntrinsic(string name, params Type[] types)
{
var targetMethod = CLMathType.GetMethod(
name,
AlgorithmContext.IntrinsicBindingFlags,
null,
types,
null)
.ThrowIfNull();
return new CLIntrinsic(targetMethod, IntrinsicImplementationMode.Redirect);
}

/// <summary>
/// Registers an intrinsic mapping.
/// </summary>
Expand Down
Loading

0 comments on commit 2a7db8a

Please sign in to comment.