Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Commit 53e47ed

Browse files
committed
Combined with ILGPU
1 parent 3297faa commit 53e47ed

File tree

7 files changed

+74
-13
lines changed

7 files changed

+74
-13
lines changed

SpawnDev.ILGPU.WebGPU.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Solution>
2-
<Project Path="../ILGPU/Src/ILGPU/ILGPU.csproj" />
2+
<Project Path="ILGPU/ILGPU.csproj" />
33
<Project Path="PlaywrightTestRunner/PlaywrightTestRunner.csproj" />
44
<Project Path="SpawnDev.ILGPU.WebGPU.Demo/SpawnDev.ILGPU.WebGPU.Demo.csproj" />
55
<Project Path="SpawnDev.ILGPU.WebGPU/SpawnDev.ILGPU.WebGPU.csproj" />

SpawnDev.ILGPU.WebGPU/Backend/WGSLIntrinsic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public sealed class WebGPUIntrinsic : global::ILGPU.IR.Intrinsics.IntrinsicImple
3939
/// <param name="mode">The code-generation mode.</param>
4040
public WebGPUIntrinsic(System.Reflection.MethodInfo targetMethod, global::ILGPU.IR.Intrinsics.IntrinsicImplementationMode mode)
4141
: base(
42-
global::ILGPU.Backends.BackendType.WebGPU,
42+
WebGPUBackend.BackendTypeWebGPU,
4343
targetMethod,
4444
mode)
4545
{ }
@@ -52,7 +52,7 @@ public WebGPUIntrinsic(System.Reflection.MethodInfo targetMethod, global::ILGPU.
5252
/// <param name="mode">The code-generator mode.</param>
5353
public WebGPUIntrinsic(System.Type handlerType, string methodName, global::ILGPU.IR.Intrinsics.IntrinsicImplementationMode mode)
5454
: base(
55-
global::ILGPU.Backends.BackendType.WebGPU,
55+
WebGPUBackend.BackendTypeWebGPU,
5656
handlerType,
5757
methodName,
5858
mode)

SpawnDev.ILGPU.WebGPU/Backend/WebGPUBackend.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using global::ILGPU.IR;
1414
using global::ILGPU.IR.Analyses;
1515
using global::ILGPU.IR.Intrinsics;
16+
using ILGPU.IR.Types;
1617
using ILGPU.Runtime;
1718
using System.Reflection;
1819
using System.Text;
@@ -29,6 +30,9 @@ public class WebGPUBackend : CodeGeneratorBackend<
2930
WGSLCodeGenerator,
3031
StringBuilder>
3132
{
33+
34+
public const BackendType BackendTypeWebGPU = BackendType.WebGPU; // Ensure this matches ILGPU's BackendType enum for WebGPU (if defined)
35+
3236
#region Instance
3337

3438
/// <summary>
@@ -39,7 +43,7 @@ public WebGPUBackend(Context context)
3943
: base(
4044
context,
4145
new WebGPUCapabilityContext(),
42-
BackendType.WebGPU,
46+
BackendTypeWebGPU,
4347
new WebGPUArgumentMapper(context))
4448
{
4549
InitIntrinsicProvider();
@@ -89,7 +93,7 @@ private static void FixIntrinsicManager(IntrinsicImplementationManager manager)
8993
if (containersField == null) return;
9094

9195
var containers = (Array)containersField.GetValue(manager);
92-
int webGpuIndex = (int)BackendType.WebGPU;
96+
int webGpuIndex = (int)BackendTypeWebGPU;
9397

9498
// Check if we need to resize or initialize
9599
if (webGpuIndex >= containers.Length || containers.GetValue(webGpuIndex) == null)
@@ -388,6 +392,19 @@ public WebGPUCompiledKernel(Context context, EntryPoint entryPoint, string wgslS
388392
{
389393
WGSLSource = wgslSource;
390394
}
395+
396+
//public EntryPoint EntryPointExt
397+
//{
398+
// get
399+
// {
400+
// // Expose EntryPoint as public
401+
// // (EntryPoint is protected in base class)
402+
// // This is a workaround since we cannot change the base class
403+
// // use reflection to get the value
404+
// var prop = typeof(CompiledKernel).GetProperty("EntryPoint", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
405+
// return (EntryPoint)prop.GetValue(this);
406+
// }
407+
//}
391408
}
392409

393410
/// <summary>

SpawnDev.ILGPU.WebGPU/SpawnDev.ILGPU.WebGPU.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<TargetFramework>net10.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>1.0.0-preview.0</Version>
7+
<Version>1.0.0-preview.1</Version>
88
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<EmbedAllSources>true</EmbedAllSources>
1111
<DebugType>Embedded</DebugType>
1212
<Title>SpawnDev.ILGPU.WebGPU</Title>
1313
<Authors>LostBeard</Authors>
14-
<Description>WebGPU backend for ILGPU, enabling GPU compute in Blazor WebAssembly application.</Description>
14+
<Description>WebGPU backend for ILGPU, enabling GPU compute in Blazor WebAssembly applications.</Description>
1515
<PackageProjectUrl>https://github.com/LostBeard/SpawnDev.ILGPU.WebGPU</PackageProjectUrl>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>
1717
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<ProjectReference Include="..\..\ILGPU\Src\ILGPU\ILGPU.csproj" />
41+
<ProjectReference Include="..\ILGPU\ILGPU.csproj" />
4242
</ItemGroup>
4343

4444
</Project>

SpawnDev.ILGPU.WebGPU/WebGPUCapabilityContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public WebGPUCapabilityContext()
2222
Int64 = false;
2323
}
2424

25+
/// <summary>
26+
/// Supports Float16 (double) data type.
27+
/// </summary>
28+
//public bool Float16 { get; internal set; }
29+
2530
/// <summary>
2631
/// Supports Float64 (double) data type.
2732
/// </summary>

SpawnDev.ILGPU.WebGPU/WebGPUContext.cs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
using global::ILGPU;
2+
using ILGPU.IR.Types;
3+
using ILGPU.Runtime;
4+
using System.Reflection;
25

36
namespace SpawnDev.ILGPU.WebGPU
47
{
5-
/// <summary>
6-
/// WebGPU context extensions.
7-
/// </summary>
8-
public static class WebGPUContextExtensions
8+
/// <summary>
9+
/// WebGPU context extensions.
10+
/// </summary>
11+
public static class WebGPUContextExtensions
912
{
1013
#region Builder
1114

15+
//extension(Context.Builder builder)
16+
//{
17+
// public DeviceRegistry DeviceRegistryExt
18+
// {
19+
// get
20+
// {
21+
// // Access the private DeviceRegistry property via reflection
22+
// var infof = typeof(Context.Builder).GetField("DeviceRegistry", System.Reflection.BindingFlags.NonPublic | BindingFlags.Public | System.Reflection.BindingFlags.Instance);
23+
// var info = typeof(Context.Builder).GetProperty("DeviceRegistry", System.Reflection.BindingFlags.NonPublic | BindingFlags.Public | System.Reflection.BindingFlags.Instance);
24+
// if (info == null)
25+
// {
26+
// throw new InvalidOperationException("Could not find deviceRegistry field in Context.Builder.");
27+
// }
28+
// return (DeviceRegistry)info.GetValue(builder);
29+
// }
30+
// }
31+
//}
32+
1233
/// <summary>
1334
/// Asynchronously enables all detected WebGPU devices.
1435
/// </summary>
@@ -41,6 +62,23 @@ await WebGPUILGPUDevice.GetDevicesAsync(
4162

4263
#region Context
4364

65+
//extension(Context context)
66+
//{
67+
// /// <summary>
68+
// /// Only needed to access internal TypeContext property
69+
// /// </summary>
70+
// public IRTypeContext TypeContextExt
71+
// {
72+
// get
73+
// {
74+
// var prop = typeof(Context).GetProperty("TypeContext", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
75+
// if (prop == null) throw new InvalidOperationException("Could not find TypeContext property on Context.");
76+
// var typeContext = (IRTypeContext)prop.GetValue(context);
77+
// return typeContext;
78+
// }
79+
// }
80+
//}
81+
4482
/// <summary>
4583
/// Gets the i-th registered WebGPU device.
4684
/// </summary>

SpawnDev.ILGPU.WebGPU/WebGPUILGPUDevice.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ namespace SpawnDev.ILGPU.WebGPU
1313
/// <summary>
1414
/// Represents an ILGPU Device implementation for WebGPU.
1515
/// </summary>
16-
[DeviceType(AcceleratorType.WebGPU)]
16+
[DeviceType(WebGPUILGPUDevice.WebGPUAcceleratorType)]
1717
public sealed class WebGPUILGPUDevice : Device
1818
{
19+
public const AcceleratorType WebGPUAcceleratorType = AcceleratorType.WebGPU;
1920
#region Static
2021

2122
/// <summary>

0 commit comments

Comments
 (0)