Skip to content

Commit

Permalink
Update sample to actually dispose resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Yey007 committed Feb 20, 2024
1 parent d667259 commit 6b65d8d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Samples/RefTypeAnalyzer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public MyUnmanagedType()
Hello = 42;
}
}

static int AnotherFunction()
{
return new MyRefType().Hello;

Check failure on line 23 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

GitHub Actions / build (Samples)

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.

Check failure on line 23 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.

Check failure on line 23 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.

Check failure on line 23 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.
}

static void Kernel(Index1D index, ArrayView<int> input, ArrayView<int> output)
{
Expand All @@ -30,16 +35,19 @@ static void Kernel(Index1D index, ArrayView<int> input, ArrayView<int> output)

// But arrays of reference types are still disallowed
MyRefType[] refs = [new MyRefType()];

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

GitHub Actions / build (Samples)

Feature 'collection expressions' is not available in C# 10.0. Please use language version 12.0 or greater.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

GitHub Actions / build (Samples)

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

GitHub Actions / build (Samples)

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

GitHub Actions / build (Samples)

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Feature 'collection expressions' is not available in C# 11.0. Please use language version 12.0 or greater.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Feature 'collection expressions' is not available in C# 10.0. Please use language version 12.0 or greater.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType[]' is an array of type 'Program.MyRefType', which is a reference type. Arrays of reference types cannot be used in kernels.

Check failure on line 37 in Samples/RefTypeAnalyzer/Program.cs

View workflow job for this annotation

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

Type 'Program.MyRefType' is a reference type. Reference types like classes cannot be used in kernels, except for arrays of value types.

// Any functions that may be called are also analyzed
int result = AnotherFunction();
}

static void Main(string[] args)
{
var context = Context.CreateDefault();
using var context = Context.CreateDefault();
var device = context.GetPreferredDevice(false);
var accelerator = device.CreateAccelerator(context);
using var accelerator = device.CreateAccelerator(context);

var input = accelerator.Allocate1D<int>(1024);
var output = accelerator.Allocate1D<int>(1024);
using var input = accelerator.Allocate1D<int>(1024);
using var output = accelerator.Allocate1D<int>(1024);

var kernel = accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<int>, ArrayView<int>>(Kernel);

Expand Down

0 comments on commit 6b65d8d

Please sign in to comment.