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. #1090

Merged
merged 4 commits into from
Sep 12, 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
60 changes: 60 additions & 0 deletions .github/workflows/check-required.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check required jobs

# This workflow is triggered when a workflow run for the CI is completed.
# It checks if the "All required checks done" job was actually successful
# (and not just skipped) and creates a check run if that is the case. The
# check run can be used to protect the main branch from being merged if the
# CI is not passing.

on:
workflow_run:
types: [completed]
workflows:
- CI
- Deploy Site with Jekyll, GitHub Pages

permissions:
actions: read
checks: write

jobs:
required-jobs:
name: Check required jobs
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
// list jobs for worklow run attempt
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRunAttempt({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
run_id: context.payload.workflow_run.id,
attempt_number: context.payload.workflow_run.run_attempt,
});
// check if required job was successful
var success = false;
core.info(`Checking jobs for workflow run ${context.payload.workflow_run.html_url}`);
jobs.forEach(job => {
var mark = '-'
if (job.name === 'All required checks done' && job.conclusion === 'success') {
success = true;
mark = '✅';
}
core.info(`${mark} ${job.name}: ${job.conclusion}`);
});
// create check run if job was successful
if (success) {
await github.rest.checks.create({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
name: 'All required checks succeeded',
head_sha: context.payload.workflow_run.head_sha,
status: 'completed',
conclusion: 'success',
output: {
title: 'All required checks succeeded',
summary: `See [workflow run](${context.payload.workflow_run.html_url}) for details.`,
},
});
}
17 changes: 6 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
)
) && os+=("macos-latest")

[ "${{ steps.is-fork.outputs.fork }}" == "false" ] && os+=("cuda-${{ github.run_id }}-${{ github.run_attempt }}")
[ "${{ steps.is-fork.outputs.fork }}" == "false" ] && os+=("cuda")

echo "os=$(jq -cn '$ARGS.positional' --args ${os[@]})" >> $GITHUB_OUTPUT
outputs:
Expand Down Expand Up @@ -162,46 +162,38 @@ jobs:
library: ILGPU.Algorithms
framework: net471
fail-fast: false
runs-on: ${{ contains(matrix.os, 'cuda') && format('{0}-{1}-{2}', matrix.os, matrix.library, matrix.framework) || matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup the latest .NET Core 3.1 SDK
if: matrix.framework == 'netcoreapp3.1'
uses: actions/setup-dotnet@v3.2.0
env:
DOTNET_INSTALL_DIR: ${{ matrix.framework == 'cuda' && '~/.' }}
with:
dotnet-version: 3.1.x

- name: Setup the latest .NET 5 SDK
if: matrix.framework == 'net5.0'
uses: actions/setup-dotnet@v3.2.0
env:
DOTNET_INSTALL_DIR: ${{ matrix.framework == 'cuda' && '~/.' }}
with:
dotnet-version: 5.0.x

- name: Setup the latest .NET 6 SDK
if: matrix.framework == 'net6.0'
uses: actions/setup-dotnet@v3.2.0
env:
DOTNET_INSTALL_DIR: ${{ matrix.framework == 'cuda' && '~/.' }}
with:
dotnet-version: 6.0.x

- name: Setup the latest .NET 7 SDK
uses: actions/setup-dotnet@v3.2.0
env:
DOTNET_INSTALL_DIR: ${{ matrix.framework == 'cuda' && '~/.' }}
with:
dotnet-version: 7.0.x

- name: Set test flavor
id: test-flavor
shell: bash
run: echo "flavor=$([[ "${{ matrix.os }}" == cuda-* ]] && echo "Cuda" || echo "CPU")" >> $GITHUB_OUTPUT
run: echo "flavor=$([[ "${{ matrix.os }}" == cuda ]] && echo "Cuda" || echo "CPU")" >> $GITHUB_OUTPUT

- name: Build and test
run: dotnet test Src/${{ matrix.library }}.Tests.${{ steps.test-flavor.outputs.flavor }} --configuration=Release --framework=${{ matrix.framework }} -p:TreatWarningsAsErrors=true
Expand Down Expand Up @@ -341,6 +333,9 @@ jobs:

# Virtual job that can be configured as a required check before a PR can be
# merged.
# As GitHub considers a check as successful if it is skipped, we need to
# check its status in another workflow (check-required.yml) and create a
# check there.
all-required-checks-done:
needs:
- check-style
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ jobs:
uses: actions/upload-pages-artifact@v2
##### GitHub Pages #####

# Virtual job that can be configured as a required check before a PR can be
# merged.
# As GitHub considers a check as successful if it is skipped, we need to
# check its status in another workflow (check-required.yml) and create a
# check there.
all-required-checks-done:
needs:
- build
Expand Down
63 changes: 56 additions & 7 deletions Src/ILGPU/Backends/OpenCL/CLCodeGenerator.Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public struct StatementEmitter : IDisposable
#region Instance

private readonly StringBuilder stringBuilder;
private readonly StringBuilder variableBuilder;
private bool argMode;
private int argumentCount;

Expand All @@ -58,6 +59,7 @@ internal StatementEmitter(CLCodeGenerator codeGenerator)
{
CodeGenerator = codeGenerator;
stringBuilder = codeGenerator.Builder;
variableBuilder = codeGenerator.VariableBuilder;
argumentCount = 0;
argMode = false;

Expand Down Expand Up @@ -85,20 +87,23 @@ internal StatementEmitter(CLCodeGenerator codeGenerator)
private void BeginAppendTarget(Variable target, bool appendNew = true)
{
if (appendNew)
{
var variableType = CodeGenerator.GetVariableType(target);
stringBuilder.Append(variableType);
stringBuilder.Append(' ');
}
AppendDeclaration(target);
stringBuilder.Append(target.ToString());
}

/// <summary>
/// Appends a target declaration.
/// </summary>
/// <param name="target">The target declaration.</param>
internal void AppendDeclaration(Variable target) =>
BeginAppendTarget(target);
internal void AppendDeclaration(Variable target)
{
var variableType = CodeGenerator.GetVariableType(target);
variableBuilder.Append('\t');
variableBuilder.Append(variableType);
variableBuilder.Append(' ');
variableBuilder.Append(target.ToString());
variableBuilder.AppendLine(";");
}

/// <summary>
/// Appends a target.
Expand Down Expand Up @@ -828,6 +833,50 @@ public StatementEmitter BeginStatement(FormattableString command)
return emitter;
}

/// <summary>
/// Begins the function body, switching to variable capturing mode.
/// </summary>
protected void BeginFunctionBody()
{
// Start the function body.
Builder.AppendLine("{");
PushIndent();

#if DEBUG
Builder.AppendLine();
Builder.AppendLine("\t// Variable declarations");
Builder.AppendLine();
#endif

// Switch to the alternate builder, so that we can capture the code and
// variable declarations separately.
prefixBuilder = Builder;
Builder = suffixBuilder;
}

/// <summary>
/// Finishes the function body, ending variable capturing mode.
/// </summary>
protected void FinishFunctionBody()
{
// Restore the original builder, containing code before the variable
// declarations.
Builder = prefixBuilder;

// Add the variable declarations at the start of the function, to avoid
// issues with OpenCL compilers that are not C99 compliant, and cannot
// handle variable declarations intermingled with other code.
Builder.Append(VariableBuilder);
Builder.AppendLine();

// Add the code that was generated along with the variable declarations.
Builder.Append(suffixBuilder);

// Close the function body.
PopIndent();
Builder.AppendLine("}");
}

#endregion
}
}
12 changes: 10 additions & 2 deletions Src/ILGPU/Backends/OpenCL/CLCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ protected static string GetParameterName(Parameter parameter) =>
new Dictionary<BasicBlock, string>();
private readonly string labelPrefix;

private StringBuilder prefixBuilder = new StringBuilder();
private StringBuilder suffixBuilder = new StringBuilder();

/// <summary>
/// Constructs a new code generator.
/// </summary>
Expand All @@ -295,7 +298,7 @@ internal CLCodeGenerator(in GeneratorArgs args, Method method, Allocas allocas)

labelPrefix = "L_" + Method.Id.ToString();

Builder = new StringBuilder();
Builder = prefixBuilder;
}

#endregion
Expand Down Expand Up @@ -327,7 +330,12 @@ public IntrinsicImplementationProvider<CLIntrinsic.Handler>
/// <summary>
/// Returns the associated string builder.
/// </summary>
public StringBuilder Builder { get; }
public StringBuilder Builder { get; private set; }

/// <summary>
/// Returns the associated string builder.
/// </summary>
public StringBuilder VariableBuilder { get; } = new StringBuilder();

#endregion

Expand Down
6 changes: 2 additions & 4 deletions Src/ILGPU/Backends/OpenCL/CLFunctionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ public override void GenerateCode()
BindSharedMemoryAllocation(Allocas.DynamicSharedAllocations);

// Generate code
Builder.AppendLine("{");
PushIndent();
BeginFunctionBody();
GenerateCodeInternal();
PopIndent();
Builder.AppendLine("}");
FinishFunctionBody();
}

#endregion
Expand Down
6 changes: 2 additions & 4 deletions Src/ILGPU/Backends/OpenCL/CLKernelFunctionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ public override void GenerateCode()
Builder.AppendLine(")");

// Emit code that moves view arguments into their appropriate targets
Builder.AppendLine("{");
PushIndent();
BeginFunctionBody();
GenerateArgumentMapping();

// Emit index computation
Expand Down Expand Up @@ -323,8 +322,7 @@ public override void GenerateCode()

// Generate code
GenerateCodeInternal();
PopIndent();
Builder.AppendLine("}");
FinishFunctionBody();
}

/// <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
Loading