Skip to content

Commit

Permalink
Refined PTX argument mapping and analyses. (#1090)
Browse files Browse the repository at this point in the history
* Refined PTX argument mapping and analyses.
- Backported #1065.

Co-authored-by: Marcel Koester <[email protected]>
  • Loading branch information
MoFtZ and m4rs-mt authored Sep 12, 2023
1 parent df6b23a commit 7a5aa45
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 48 deletions.
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 { }
}
4 changes: 2 additions & 2 deletions Src/ILGPU/Backends/PTX/PTXArgumentMapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2018-2021 ILGPU Project
// Copyright (c) 2018-2023 ILGPU Project
// www.ilgpu.net
//
// File: PTXArgumentMapper.cs
Expand All @@ -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

0 comments on commit 7a5aa45

Please sign in to comment.