Skip to content

Commit

Permalink
Reworked builder.Debug semantics. (#1103)
Browse files Browse the repository at this point in the history
* Introduced DebugConfig to configure debugging in ILGPU land.
* Adjusted context properties accordingly.
* Adjusted Inliner to obsolete inlining flags.
* Adapted TestContext instances in ILGPU tests.
* Disabled IO operations in VelocityBackend.
* Adapted ILGPU tests contexts to turn on assertion checks in all configurations.
* Adapted ILGPU.Algorithms tests contexts to turn off assertion checks in O1 and O2 builds on Cuda and OpenCL platforms.
* Adapted Samples.
  • Loading branch information
m4rs-mt authored Oct 23, 2023
1 parent 32c6e13 commit 9c2518f
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 99 deletions.
4 changes: 2 additions & 2 deletions Samples/SimpleDebugAssert/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU Samples
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: Program.cs
Expand Down Expand Up @@ -43,7 +43,7 @@ static void Main()
// Create main context
using var context = Context.Create(builder =>
{
builder.Cuda().OpenCL().AutoAssertions();
builder.Cuda().OpenCL().DebugConfig(enableAssertions: true);
// Alternatives to explore:
// builder.Default();
// builder.AllAccelerators().Debug();
Expand Down
4 changes: 3 additions & 1 deletion Src/ILGPU.Algorithms.Tests.CPU/Configurations.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU Algorithms
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: Configurations.tt/Configurations.cs
Expand Down Expand Up @@ -44,6 +44,8 @@ namespace ILGPU.Algorithms.Tests.CPU
public CPUTestContext<#= config #>()
: base(
OptimizationLevel.<#= level #>,
enableAssertions: true,
forceDebugConfig: true,
builder => builder.EnableAlgorithms())
{ }
}
Expand Down
4 changes: 3 additions & 1 deletion Src/ILGPU.Algorithms.Tests.Cuda/Configurations.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU Algorithms
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: Configurations.tt/Configurations.cs
Expand Down Expand Up @@ -44,6 +44,8 @@ namespace ILGPU.Algorithms.Tests.Cuda
public CudaTestContext<#= config #>()
: base(
OptimizationLevel.<#= level #>,
enableAssertions: false,
forceDebugConfig: false,
builder => builder.EnableAlgorithms())
{ }
}
Expand Down
4 changes: 3 additions & 1 deletion Src/ILGPU.Algorithms.Tests.OpenCL/Configurations.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU Algorithms
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: Configurations.tt/Configurations.cs
Expand Down Expand Up @@ -44,6 +44,8 @@ namespace ILGPU.Algorithms.Tests.OpenCL
public CLTestContext<#= config #>()
: base(
OptimizationLevel.<#= level #>,
enableAssertions: false,
forceDebugConfig: false,
builder => builder.EnableAlgorithms())
{ }
}
Expand Down
8 changes: 6 additions & 2 deletions Src/ILGPU.Tests.CPU/Configurations.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: Configurations.tt/Configurations.cs
Expand Down Expand Up @@ -40,7 +40,11 @@ namespace ILGPU.Tests.CPU
public class CPUTestContext<#= config #> : CPUTestContext
{
public CPUTestContext<#= config #>()
: base(OptimizationLevel.<#= level #>)
: base(
OptimizationLevel.<#= level #>,
enableAssertions: true,
forceDebugConfig: true,
_ => { })
{ }
}

Expand Down
7 changes: 4 additions & 3 deletions Src/ILGPU.Tests.CPU/RuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: RuntimeTests.cs
Expand Down Expand Up @@ -69,8 +69,9 @@ public void TestCustomDeviceSetup(
Skip.If(customDevice.NumThreads > maxNumThreads);
}

using var context = Context.Create(builder =>
builder.Assertions().CPU(customDevice));
using var context = Context.Create(builder => builder
.DebugConfig(enableAssertions: true)
.CPU(customDevice));

// Spawn a new accelerator and invoke a simple sequence kernel to check
// whether all threads are actually executed
Expand Down
20 changes: 11 additions & 9 deletions Src/ILGPU.Tests.CPU/TestContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: TestContext.cs
Expand Down Expand Up @@ -52,22 +52,24 @@ private static CPUDeviceKind GetCPUDeviceKind()
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
/// <param name="enableAssertions">
/// Enables use of assertions.
/// </param>
/// <param name="forceDebugConfig">
/// Forces use of debug configuration in O1 and O2 builds.
/// </param>
/// <param name="prepareContext">The context preparation handler.</param>
protected CPUTestContext(
OptimizationLevel optimizationLevel,
bool enableAssertions,
bool forceDebugConfig,
Action<Context.Builder> prepareContext)
: base(
optimizationLevel,
enableAssertions,
forceDebugConfig,
builder => prepareContext(builder.CPU(GetCPUDeviceKind())),
context => context.CreateCPUAccelerator(0))
{ }

/// <summary>
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
protected CPUTestContext(OptimizationLevel optimizationLevel)
: this(optimizationLevel, _ => { })
{ }
}
}
8 changes: 6 additions & 2 deletions Src/ILGPU.Tests.Cuda/Configurations.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: Configurations.tt/Configurations.cs
Expand Down Expand Up @@ -39,7 +39,11 @@ namespace ILGPU.Tests.Cuda
public class CudaTestContext<#= config #> : CudaTestContext
{
public CudaTestContext<#= config #>()
: base(OptimizationLevel.<#= level #>)
: base(
OptimizationLevel.<#= level #>,
enableAssertions: true,
forceDebugConfig: true,
_ => { })
{ }
}

Expand Down
20 changes: 11 additions & 9 deletions Src/ILGPU.Tests.Cuda/TestContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: TestContext.cs
Expand All @@ -23,22 +23,24 @@ public abstract class CudaTestContext : TestContext
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
/// <param name="enableAssertions">
/// Enables use of assertions.
/// </param>
/// <param name="forceDebugConfig">
/// Forces use of debug configuration in O1 and O2 builds.
/// </param>
/// <param name="prepareContext">The context preparation handler.</param>
protected CudaTestContext(
OptimizationLevel optimizationLevel,
bool enableAssertions,
bool forceDebugConfig,
Action<Context.Builder> prepareContext)
: base(
optimizationLevel,
enableAssertions,
forceDebugConfig,
builder => prepareContext(builder.Cuda()),
context => context.CreateCudaAccelerator(0))
{ }

/// <summary>
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
protected CudaTestContext(OptimizationLevel optimizationLevel)
: this(optimizationLevel, _ => { })
{ }
}
}
8 changes: 6 additions & 2 deletions Src/ILGPU.Tests.OpenCL/Configurations.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: Configurations.tt/Configurations.cs
Expand Down Expand Up @@ -39,7 +39,11 @@ namespace ILGPU.Tests.OpenCL
public class CLTestContext<#= config #> : CLTestContext
{
public CLTestContext<#= config #>()
: base(OptimizationLevel.<#= level #>)
: base(
OptimizationLevel.<#= level #>,
enableAssertions: true,
forceDebugConfig: true,
_ => { })
{ }
}

Expand Down
20 changes: 11 additions & 9 deletions Src/ILGPU.Tests.OpenCL/TestContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: TestContext.cs
Expand All @@ -23,22 +23,24 @@ public abstract class CLTestContext : TestContext
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
/// <param name="enableAssertions">
/// Enables use of assertions.
/// </param>
/// <param name="forceDebugConfig">
/// Forces use of debug configuration in O1 and O2 builds.
/// </param>
/// <param name="prepareContext">The context preparation handler.</param>
protected CLTestContext(
OptimizationLevel optimizationLevel,
bool enableAssertions,
bool forceDebugConfig,
Action<Context.Builder> prepareContext)
: base(
optimizationLevel,
enableAssertions,
forceDebugConfig,
builder => prepareContext(builder.OpenCL()),
context => context.CreateCLAccelerator(0))
{ }

/// <summary>
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
protected CLTestContext(OptimizationLevel optimizationLevel)
: this(optimizationLevel, _ => { })
{ }
}
}
6 changes: 5 additions & 1 deletion Src/ILGPU.Tests.Velocity/Configurations.tt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ namespace ILGPU.Tests.Velocity
public class VelocityTestContext<#= config #> : VelocityTestContext
{
public VelocityTestContext<#= config #>()
: base(OptimizationLevel.<#= level #>)
: base(
OptimizationLevel.<#= level #>,
enableAssertions: true,
forceDebugConfig: true,
_ => { })
{ }
}

Expand Down
18 changes: 10 additions & 8 deletions Src/ILGPU.Tests.Velocity/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ public abstract class VelocityTestContext : TestContext
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
/// <param name="enableAssertions">
/// Enables use of assertions.
/// </param>
/// <param name="forceDebugConfig">
/// Forces use of debug configuration in O1 and O2 builds.
/// </param>
/// <param name="prepareContext">The context preparation handler.</param>
protected VelocityTestContext(
OptimizationLevel optimizationLevel,
bool enableAssertions,
bool forceDebugConfig,
Action<Context.Builder> prepareContext)
: base(
optimizationLevel,
enableAssertions,
forceDebugConfig,
builder => prepareContext(
builder.Velocity(VelocityDeviceType.Scalar2)),
context => context.CreateVelocityAccelerator())
{ }

/// <summary>
/// Creates a new test context instance.
/// </summary>
/// <param name="optimizationLevel">The optimization level to use.</param>
protected VelocityTestContext(OptimizationLevel optimizationLevel)
: this(optimizationLevel, _ => { })
{ }
}
}
18 changes: 15 additions & 3 deletions Src/ILGPU.Tests/Generic/TestContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021-2022 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: TestContext.cs
Expand All @@ -24,22 +24,34 @@ public abstract class TestContext : DisposeBase
/// Constructs a new context provider.
/// </summary>
/// <param name="level">The optimization level.</param>
/// <param name="enableAssertions">
/// Enables use of assertions.
/// </param>
/// <param name="forceDebugConfig">
/// Forces use of debug configuration in O1 and O2 builds.
/// </param>
/// <param name="prepareContext">
/// Prepares the context by setting additional field/initializing specific
/// items before the accelerator is created.
/// </param>
/// <param name="createAccelerator">Creates a new accelerator.</param>
protected TestContext(
OptimizationLevel level,
bool enableAssertions,
bool forceDebugConfig,
Action<Context.Builder> prepareContext,
Func<Context, Accelerator> createAccelerator)
{
Context = Context.Create(builder =>
prepareContext(
builder
.Assertions()
.DebugConfig(
enableAssertions: enableAssertions,
enableIOOperations: true,
debugSymbolsMode: DebugSymbolsMode.Auto,
forceDebuggingOfOptimizedKernels: forceDebugConfig,
enableIRVerifier: true)
.Arrays(ArrayMode.InlineMutableStaticArrays)
.Verify()
.Optimize(level)
.Profiling()));
Accelerator = createAccelerator(Context);
Expand Down
2 changes: 1 addition & 1 deletion Src/ILGPU/Backends/Velocity/VelocityBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public VelocityBackend(
PointerType,
warpSize,
Context.Properties.EnableAssertions,
Context.Properties.EnableIOOperations),
enableIOOperations: false),
context.Properties.InliningMode,
context.Properties.OptimizationLevel);

Expand Down
Loading

0 comments on commit 9c2518f

Please sign in to comment.