Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved OpenCL IntrinsicMath implementations. #1185

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading