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

Refined PTX argument mapping and analyses #1065

Merged
merged 3 commits into from
Sep 5, 2023
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
7 changes: 1 addition & 6 deletions Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
{
#region Constants

/// <summary>
/// The internal prefix name for all runtime fields.
/// </summary>
private const string FieldPrefixName = "Field";

/// <summary>
/// The intrinsic kernel length parameter field name.
/// </summary>
Expand Down Expand Up @@ -520,7 +515,7 @@
private static string GetFieldName(int index)
{
Debug.Assert(index >= 0, "Invalid field index");
return FieldPrefixName + index;
return StructureType.GetFieldName(index);
}

#endregion
Expand Down Expand Up @@ -608,7 +603,7 @@
FieldAttributes.Public);
}
// Build wrapper type and return it
return typeBuilder.CreateType();

Check warning on line 606 in Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs

View workflow job for this annotation

GitHub Actions / Analyze (Src/ILGPU.sln, net6.0)

Possible null reference return.

Check warning on line 606 in Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs

View workflow job for this annotation

GitHub Actions / Analyze (Src/ILGPU.sln, net6.0)

Possible null reference return.

Check warning on line 606 in Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs

View workflow job for this annotation

GitHub Actions / Analyze (Samples/ILGPU.Samples.sln, net6.0)

Possible null reference return.

Check warning on line 606 in Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs

View workflow job for this annotation

GitHub Actions / Analyze (Samples/ILGPU.Samples.sln, net6.0)

Possible null reference return.
}

/// <summary>
Expand Down Expand Up @@ -973,7 +968,7 @@
}
}

return typeBuilder.CreateType();

Check warning on line 971 in Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs

View workflow job for this annotation

GitHub Actions / Analyze (Src/ILGPU.sln, net6.0)

Possible null reference return.

Check warning on line 971 in Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs

View workflow job for this annotation

GitHub Actions / Analyze (Samples/ILGPU.Samples.sln, net6.0)

Possible null reference return.

Check warning on line 971 in Src/ILGPU/Backends/EntryPoints/ArgumentMapper.cs

View workflow job for this annotation

GitHub Actions / Analyze (Samples/ILGPU.Samples.sln, net6.0)

Possible null reference return.
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Src/ILGPU/Backends/PTX/Analyses/DefaultPTXBlockSchedule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2020-2021 ILGPU Project
// Copyright (c) 2020-2023 ILGPU Project
// www.ilgpu.net
//
// File: DefaultPTXBlockSchedule.cs
Expand All @@ -18,7 +18,7 @@ namespace ILGPU.Backends.PTX.Analyses
/// <summary>
/// Represents a default PTX-specific block schedule.
/// </summary>
public sealed class DefaultPTXBlockSchedule :
sealed class DefaultPTXBlockSchedule :
PTXBlockSchedule<ReversePostOrder, Forwards>
{
#region Instance
Expand Down Expand Up @@ -53,7 +53,7 @@ public override bool IsImplicitSuccessor(
#endregion
}

public partial class PTXBlockScheduleExtensions
partial class PTXBlockScheduleExtensions
{
/// <summary>
/// Creates a new default block schedule using the given blocks.
Expand Down
42 changes: 5 additions & 37 deletions Src/ILGPU/Backends/PTX/Analyses/OptimizedPTXBlockSchedule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2020-2021 ILGPU Project
// Copyright (c) 2020-2023 ILGPU Project
// www.ilgpu.net
//
// File: OptimizedPTXBlockSchedule.cs
Expand All @@ -24,41 +24,11 @@ namespace ILGPU.Backends.PTX.Analyses
/// </summary>
/// <typeparam name="TOrder">The current order.</typeparam>
/// <typeparam name="TDirection">The control-flow direction.</typeparam>
public sealed class OptimizedPTXBlockSchedule<TOrder, TDirection> :
class OptimizedPTXBlockSchedule<TOrder, TDirection> :
PTXBlockSchedule<TOrder, TDirection>
where TOrder : struct, ITraversalOrder
where TDirection : struct, IControlFlowDirection
{
#region Nested Types

/// <summary>
/// A specific successor provider that inverts the successors of all
/// <see cref="IfBranch"/> terminators.
/// </summary>
private readonly struct SuccessorProvider :
ITraversalSuccessorsProvider<Forwards>
{
/// <summary>
/// Returns all successors in the default order except for
/// <see cref="IfBranch"/> terminators. The successors of these terminators
/// will be reversed to invert all if branch targets.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<BasicBlock> GetSuccessors(BasicBlock basicBlock)
{
var successors = basicBlock.Successors;
if (basicBlock.Terminator is IfBranch ifBranch && ifBranch.IsInverted)
{
var tempList = successors.ToInlineList();
tempList.Reverse();
successors = tempList;
}
return successors;
}
}

#endregion

#region Instance

/// <summary>
Expand Down Expand Up @@ -135,24 +105,22 @@ public override bool NeedBranchTarget(BasicBlock block)
#endregion
}

public partial class PTXBlockScheduleExtensions
partial class PTXBlockScheduleExtensions
{
#region Nested Types

/// <summary>
/// A specific successor provider that inverts the successors of all
/// <see cref="IfBranch"/> terminators.
/// </summary>
private readonly struct SuccessorProvider :
ITraversalSuccessorsProvider<Forwards>
private readonly struct SuccessorProvider : ITraversalSuccessorsProvider<Forwards>
{
/// <summary>
/// Returns all successors in the default order except for
/// <see cref="IfBranch"/> terminators. The successors of these terminators
/// will be reversed to invert all if branch targets.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<BasicBlock> GetSuccessors(BasicBlock basicBlock)
public ReadOnlySpan<BasicBlock> GetSuccessors(BasicBlock basicBlock)
{
var successors = basicBlock.Successors;
if (basicBlock.Terminator is IfBranch ifBranch && ifBranch.IsInverted)
Expand Down
6 changes: 3 additions & 3 deletions Src/ILGPU/Backends/PTX/Analyses/PTXBlockSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ILGPU.Backends.PTX.Analyses
/// <summary>
/// Represents a PTX-specific block schedule.
/// </summary>
public abstract class PTXBlockSchedule
abstract class PTXBlockSchedule
{
#region Instance

Expand Down Expand Up @@ -96,7 +96,7 @@ public ImmutableArray<BasicBlock>.Enumerator GetEnumerator() =>
/// </summary>
/// <typeparam name="TOrder">The current order.</typeparam>
/// <typeparam name="TDirection">The control-flow direction.</typeparam>
public abstract class PTXBlockSchedule<TOrder, TDirection> : PTXBlockSchedule
abstract class PTXBlockSchedule<TOrder, TDirection> : PTXBlockSchedule
where TOrder : struct, ITraversalOrder
where TDirection : struct, IControlFlowDirection
{
Expand Down Expand Up @@ -140,5 +140,5 @@ public override PhiBindings ComputePhiBindings<TAllocator>(
/// <summary>
/// Extensions methods for the <see cref="PTXBlockSchedule"/> class.
/// </summary>
public static partial class PTXBlockScheduleExtensions { }
static partial class PTXBlockScheduleExtensions { }
}
2 changes: 1 addition & 1 deletion Src/ILGPU/Backends/PTX/PTXArgumentMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace ILGPU.Backends.PTX
/// Constructs mappings for PTX kernels.
/// </summary>
/// <remarks>Members of this class are not thread safe.</remarks>
public sealed class PTXArgumentMapper : ViewArgumentMapper
public class PTXArgumentMapper : ViewArgumentMapper
{
#region Nested Types

Expand Down
2 changes: 1 addition & 1 deletion Src/ILGPU/Backends/PTX/PTXCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public IntrinsicImplementationProvider<PTXIntrinsic.Handler>
/// <summary>
/// Returns all blocks in an appropriate schedule.
/// </summary>
public PTXBlockSchedule Schedule { get; }
internal PTXBlockSchedule Schedule { get; }

#endregion

Expand Down
4 changes: 2 additions & 2 deletions Src/ILGPU/Backends/PTX/Transformations/PTXBlockScheduling.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2020-2021 ILGPU Project
// Copyright (c) 2020-2023 ILGPU Project
// www.ilgpu.net
//
// File: PTXBlockScheduling.cs
Expand All @@ -20,7 +20,7 @@ namespace ILGPU.Backends.PTX.Transformations
/// Adapts the actual block branch order in a way to avoid negated predicated
/// branches and which maximizes the number of implicit block branches.
/// </summary>
public sealed class PTXBlockScheduling : UnorderedTransformation
sealed class PTXBlockScheduling : UnorderedTransformation
{
/// <summary>
/// Applies the PTX-specific block schedule to the given builder.
Expand Down
Loading