ParallelGpu 0.3.0
See the version list below for details.
dotnet add package ParallelGpu --version 0.3.0
NuGet\Install-Package ParallelGpu -Version 0.3.0
<PackageReference Include="ParallelGpu" Version="0.3.0" />
<PackageVersion Include="ParallelGpu" Version="0.3.0" />
<PackageReference Include="ParallelGpu" />
paket add ParallelGpu --version 0.3.0
#r "nuget: ParallelGpu, 0.3.0"
#:package ParallelGpu@0.3.0
#addin nuget:?package=ParallelGpu&version=0.3.0
#tool nuget:?package=ParallelGpu&version=0.3.0
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>andAllocate<T>to retain data between kernels, with partialCopyFrom/CopyTotransfers using array offsets/counts or spans. - Explicit value kernels through
IGpuForKernelandIGpuForEachKernel<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. Explicit object-graph adapters support custom data models. - Floating-point
%and supportedMath/MathFoperations, includingCopySign,Sin,Cos,Powand bothLogoverloads (natural logarithm or a specified base).
Execution requirements and limitations
The automatic lambda API requires runtime code generation (Reflection.Emit) and access to method IL. It is not supported in Native AOT applications.
Loop iterations are unordered. Use independent writes, atomics, or reductions to avoid races. Scalars captured by a lambda 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. Direct device buffers and explicit value kernels require public unmanaged ILGPU-compatible types.
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.
Bounds, null access, read-only writes and guarded arithmetic errors become host exceptions before automatic collection copyback, including ref access in value constructors. 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 | Versions 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. |
-
.NETStandard 2.1
- ILGPU (>= 1.5.3)
- ILGPU.Algorithms (>= 1.5.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.