ParallelGpu 0.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ParallelGpu --version 0.6.0
                    
NuGet\Install-Package ParallelGpu -Version 0.6.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="ParallelGpu" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ParallelGpu" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="ParallelGpu" />
                    
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 ParallelGpu --version 0.6.0
                    
#r "nuget: ParallelGpu, 0.6.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 ParallelGpu@0.6.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=ParallelGpu&version=0.6.0
                    
Install as a Cake Addin
#tool nuget:?package=ParallelGpu&version=0.6.0
                    
Install as a Cake Tool

ParallelGpu

Synchronous C# loops on CUDA or OpenCL, powered by ILGPU. Write a lambda over captured collections; the library compiles it for the selected device, transfers the data, and copies results back before the call returns.

Installation

dotnet add package ParallelGpu

Quick start

using ParallelGpu;

using var gpu = new Gpu();
int[] input = { 1, 2, 3 };
int[] output = new int[input.Length];

gpu.For(0, input.Length, i => output[i] = input[i] * 2);
// output: 2, 4, 6

Reuse a Gpu instance to retain the accelerator and compiled kernels. GpuParallel.For(...) also provides a static API.

Backend selection

The default backend is Auto. It tries CUDA first, then OpenCL. CPU fallback is disabled by default; enable it explicitly when an application should also run without a compatible GPU:

using var gpu = new Gpu(new GpuOptions
{
    Backend = GpuBackend.Auto,
    AllowCpuFallback = true
});
Backend Requirements and behavior
Auto Tries available GPUs in CUDA-first order; CPU fallback requires AllowCpuFallback = true.
Cuda Requires an NVIDIA GPU and a compatible CUDA driver.
OpenCL Requires a compatible GPU and OpenCL runtime with OpenCL C 2.0 or newer and generic address-space support. An OpenCL 3.0 version label alone is insufficient.
Cpu Uses the ILGPU CPU accelerator for debugging and correctness checks.

Explicit Cuda and OpenCL selections never fall back to CPU. Use GpuOptions.DeviceIndex to select a device, and inspect gpu.Backend, gpu.DeviceName, and gpu.IsGpu after initialization.

Capabilities

  • Automatic transfers for arrays of any rank, jagged arrays, fixed-size lists, and supported memory views, with shared storage preserved.
  • Automatic value mappings for numeric types, bool, char, enums, supported structures, and nullable values.
  • Device buffers via Upload<T> and Allocate<T> to retain data between kernels, with partial CopyFrom/CopyTo transfers using array offsets/counts or spans.
  • Backend-independent GpuView<T> from buffer.DeviceView to use the same lambda API with data retained on the device.
  • Explicit value kernels through IGpuForKernel and IGpuForEachKernel<T>.
  • Reductions, atomic operations, and bounded append buffers for variable output.
  • Host collection adapters support inherited and renamed indexers, including List<T>-derived collections; snapshots preserve slices, read-only access, shared identities and one host commit per identity. When a snapshot identifies its original list as storage, native list helper parameters and return values expose the full list; the registered custom declaration keeps the snapshot slice. Implicit reference conversions between collection declarations with different element types are unsupported; capture the required native declaration separately. Explicit object-graph adapters support custom data models.
  • Floating-point % and .NET 8 Math/MathF overloads for the supported numeric types, including trigonometry, hyperbolic functions, logarithms, rounding modes, fused multiply-add, IEEE helpers, BigMul, and both DivRem forms. Overloads using decimal, nint, or nuint are excluded.

Execution requirements and limitations

The automatic lambda API requires runtime code generation (Reflection.Emit) and access to method IL. Delegates must target an ordinary void Method(int); closed static delegates with bound arguments and DynamicMethod delegates are unsupported. It is not supported in Native AOT applications.

Loop iterations are unordered. Use independent writes, atomics, or reductions to avoid races. Scalar captures, including volatile fields, use host snapshots refreshed per call and are read-only; collection elements may be writable, but collection sizes and array topology cannot change during execution.

Loop bodies and their helpers must be device-compatible. Arbitrary .NET methods, managed allocation, boxing, reflection, exception handlers, and checked integer arithmetic are unsupported. Automatic structure mappings cannot contain managed references, native pointers, or explicit layout. Inline arrays and fixed buffers are unsupported, including in nested structures. Lists, segments, memory, and spans require supported value elements; access nested arrays directly through jagged-array descriptors. Direct device buffers require unmanaged ILGPU-compatible types; explicit kernel types, ForEach/Reduce elements, and lambda native-view payloads must be public.

Automatic loops transfer captured collections on every call. For repeated operations, keep data in device buffers and download results when needed. Transfers and kernel compilation can outweigh the benefit of GPU execution for small or inexpensive workloads.

GpuView<T> borrows device memory. Lambda captures validate its owner and lifetime before execution; indices must be in range in both lambdas and explicit kernels. Device buffer writes are not rolled back on later errors.

Bounds, null access, read-only writes and guarded arithmetic errors become host exceptions before automatic collection copyback, including ref access in value constructors. Translated ordinary bodies and helpers stop after a deferred failure so fallback values cannot keep their loops running. ArraySegment<T> constructor validation follows CLR behavior. Large loops may use several launches with shared device storage; copyback requires every launch to succeed. Owned device buffers and callback side effects are not rolled back.

Calls on one Gpu instance are serialized. Avoid modifying transferred host collections concurrently, and dispose the executor and its buffers when finished. Transcendental functions are approximate; compare with a numerical tolerance. Floating-point reduction results may differ from sequential CPU results and between devices.

Documentation and examples

See the ParallelGpu repository for the full API guide, supported math operations, collection and object-graph examples, and sample applications.

License

Licensed under MIT.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.7.0 41 10/14/2026
0.6.0 83 10/13/2026
0.5.0 86 10/12/2026
0.4.0 82 10/12/2026
0.3.0 86 10/12/2026
0.2.0 84 10/11/2026
0.1.0 81 10/10/2026