Supprocom.CSharp2CUDA
0.3.2
dotnet add package Supprocom.CSharp2CUDA --version 0.3.2
NuGet\Install-Package Supprocom.CSharp2CUDA -Version 0.3.2
<PackageReference Include="Supprocom.CSharp2CUDA" Version="0.3.2" />
<PackageVersion Include="Supprocom.CSharp2CUDA" Version="0.3.2" />
<PackageReference Include="Supprocom.CSharp2CUDA" />
paket add Supprocom.CSharp2CUDA --version 0.3.2
#r "nuget: Supprocom.CSharp2CUDA, 0.3.2"
#:package Supprocom.CSharp2CUDA@0.3.2
#addin nuget:?package=Supprocom.CSharp2CUDA&version=0.3.2
#tool nuget:?package=Supprocom.CSharp2CUDA&version=0.3.2
CSharp2CUDA
Regular C# static methods can become CUDA code. CSharp2CUDA lets you reuse existing numerical algorithms and translate the sections that benefit from GPU acceleration without first rewriting those algorithms in CUDA or requiring a C# developer to learn CUDA syntax.
CSharp2CUDA is intentionally selective. It is useful for moving bounded, value-oriented parts of a C# program onto a GPU; it is not intended to become the default way to maintain a large application or to reproduce the managed .NET runtime on a device.
Translate an existing algorithm
Keep the reusable algorithm as ordinary C#. A small adapter supplies the CUDA entry point and its pointer-based launch boundary.
using System;
using Supprocom.CSharp2CUDA;
internal static class ExistingAlgorithm
{
public static float Apply(float value, float scale)
{
float positive = MathF.Max(value, 0.0f);
return positive * scale;
}
}
[TranspileToCUDA]
internal static unsafe class ApplyOnGpu
{
[CudaGlobal(Name = "apply_values")]
private static void Kernel(float* input, float* output, int count, float scale)
{
int index = Cuda.BlockIdx.X * Cuda.BlockDim.X + Cuda.ThreadIdx.X;
if (index < count)
output[index] = ExistingAlgorithm.Apply(input[index], scale);
}
}
Roslyn checks both methods as C#. CSharp2CUDA follows the call from Kernel,
emits ExistingAlgorithm.Apply as a CUDA device helper, and emits Kernel as
the apply_values global function. The CPU version remains directly callable
from ordinary managed code.
Add the package
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Supprocom.CSharp2CUDA" Version="0.3.2" />
</ItemGroup>
Build normally with dotnet build. A marked class keeps the managed assembly
and adds a .cu output; a dedicated transpilation project can instead set
<TranspileToCUDA>true</TranspileToCUDA>.
The package emits CUDA C++ source. Your application still chooses a CUDA toolchain, owns device memory, and launches kernels.
Where to go next
- Getting started explains project selection, generated files, diagnostics, and manual Roslyn APIs.
- Portable C# profile lists supported C# features, restrictions, traps, lifetime rules, and examples.
- CUDA interop covers intrinsics, shared and constant storage, ABI rules, and external CUDA linkage.
- Tool package explains when to use
Supprocom.CSharp2CUDA.Toolinstead of the build-integrated package. - Contributing covers repository builds and tests.
CSharp2CUDA fails closed: when a construct cannot be translated with the required C# semantics, it reports a diagnostic and returns no partial CUDA source.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.CodeAnalysis.CSharp (= 5.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Clean up analyzer findings and establish warning-free compiler, package, and test builds. No new CUDA language features.