GPUSharp 0.3.0

dotnet add package GPUSharp --version 0.3.0
                    
NuGet\Install-Package GPUSharp -Version 0.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GPUSharp" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GPUSharp" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="GPUSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GPUSharp --version 0.3.0
                    
#r "nuget: GPUSharp, 0.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GPUSharp@0.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GPUSharp&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=GPUSharp&version=0.3.0
                    
Install as a Cake Tool

GPUSharp

Turn ordinary C# methods into GPU-accelerated operations with a single attribute.

GPUSharp is an experimental .NET library that compiles attributed C# methods into NVIDIA CUDA kernels using Roslyn source generation and a Rust-based compiler.

Write your computation once in C#. Keep the original CPU method and use the generated GPU companion API to process arrays in parallel.

public static class Calculator
{
    [GpuKernel]
    public static float Add(float a, float b)
    {
        return a + b;
    }
}

float[] result = CalculatorGpu.Add(a, b);

Build status

CI

Install

GPUSharp targets .NET 10. dotnet build works on Windows and Linux. Running a kernel requires Linux, cargo oxide 0.2.1, the CUDA toolkit, LLVM 21, and an NVIDIA GPU (Ampere, sm_80, or newer). Calling a kernel on another operating system throws.

dotnet add package GPUSharp

The published package includes the compiler for Windows and Linux. Windows builds check the kernels and emit the managed API. Linux builds compile the kernel library with cargo oxide on PATH.

Example

On a Linux machine with an NVIDIA GPU:

dotnet run --project samples/AddArrays

That runs Calculator.Add over two 5-element arrays and prints 11, 22, 33, 44, 55.

samples/AddArrays.NuGet is the same program with a floating PackageReference (Version="*") so restore picks up the latest GPUSharp on nuget.org. Its nuget.config lists only nuget.org, so the build does not use a local package source or the projects in this repo:

dotnet run --project samples/AddArrays.NuGet

How it works

src/GPUSharp defines [GpuKernel]. src/GPUSharp.Generator finds marked methods at build time and emits the array companion. rust/gpusharp-compiler compiles each method into a cuda-oxide kernel and a host library that launches it.

Development

  • samples/AddArrays — console app that adds two arrays through CalculatorGpu.Add.
  • samples/AddArrays.NuGet — the same app, restored from the GPUSharp package on nuget.org.
  • src/GPUSharp — .NET 10 package and [GpuKernel].
  • src/GPUSharp.Generator — Roslyn source generator for the array companion.
  • rust/gpusharp-compiler — kernel compiler. dll --out <so> <export-name> <method.cs> compiles one kernel with cargo oxide.

cargo test checks the emitted kernel. It does not need a GPU or the CUDA toolkit. dotnet build compiles the sample kernel and needs the Linux toolchain above. dotnet run launches it and needs a GPU.

From the repository root:

cargo test --manifest-path rust/gpusharp-compiler/Cargo.toml
cargo fmt --manifest-path rust/gpusharp-compiler/Cargo.toml --check
cargo clippy --manifest-path rust/gpusharp-compiler/Cargo.toml --all-targets -- -D warnings
dotnet build GPUSharp.slnx

cargo fmt and cargo clippy require the rustfmt and clippy components (rustup component add rustfmt clippy). GPUSHARP_CUDA_ARCH overrides the default sm_80 target.

License

GPUSharp is licensed under the Apache License 2.0.

Contributing

This is a young project, and a good time to help shape it. Ideas, bug reports, and pull requests are all welcome!

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 67 11/30/2026
0.2.0 77 11/12/2026
0.1.0 66 11/12/2026