Skip to content

Deploy the opt-in CUDA backend to the C# GGUF samples - #45

Merged
Nick Eubanks (nieubank) merged 1 commit into
mainfrom
nieubank/csharp-llamacuda
Nov 18, 2026
Merged

Nick Eubanks (nieubank) merged 1 commit into
mainfrom
nieubank/csharp-llamacuda

Conversation

@nieubank

Copy link
Copy Markdown
Contributor

Summary

build.ps1 -LlamaCuda set WinMLSamplesLlamaCuda only for the MSBuild restore and build of the C++ projects. The C# samples build through dotnet with their own arguments, so the four C# GGUF samples kept only the CPU backend while the build reported CPU and CUDA.

The Runtime and Tasks build scripts now pass the property to the C# builds too, and the four C# GGUF projects reference Microsoft.Windows.AI.MachineLearning.LibLlama under it, as their C++ counterparts do. The GGUF guide and the Tasks README now say the switch covers C#. A build without -LlamaCuda doesn't change, and the CPU backend stays the default.

Related issue

None. Follows #40, which added the opt-in CUDA backend to the C++ GGUF samples, and #41, which added two of the four C# GGUF samples.

Affected samples

  • Samples/Runtime/language/hello-language-model/csharp
  • Samples/Tasks/model-backed/text-generation/csharp
  • Samples/Tasks/language/chat-completion/csharp
  • Samples/Tasks/model-backed/text-generation-features/csharp
  • Samples/Runtime/build.ps1 and Samples/Tasks/build.ps1, plus Samples/Tasks/README.md and docs/Runtime/gguf-models.md

Checklist

  • I built Samples/WindowsML-Samples.sln locally with Visual Studio 2022 or Visual Studio 2026 (that solution isn't in the repo, so I built the Runtime and Tasks catalogs with build.ps1 for ARM64 and x64, with no warnings)
  • I ran the affected sample(s) end-to-end on Windows 11 (x64 and/or ARM64) (ARM64 with an NVIDIA RTX Spark GPU, see Testing notes)
  • C++ changes follow the repo .clang-format (ran Samples/format-code.ps1 if available) (there's no C++ in this PR)
  • I updated the relevant per-sample README.md (the Tasks README and the GGUF guide)
  • I did not check in large model artifacts, build outputs, or secrets

Testing notes

Built on main at 3c6f5b2, which includes #44, against Microsoft.Windows.AI.MachineLearning 2.9.36-experimental and the LibLlama 0.7.0.107-experimental packages, on an ARM64 PC with an NVIDIA RTX Spark GPU, starting from empty output folders.

Command Result
Samples\Runtime\build.ps1 -Sample hello-language-model-csharp -Platform ARM64 -PackageOnly Passed, 0 warnings. The output has no LlamaBackends\cuda
Samples\Tasks\build.ps1 -Sample all -Platform ARM64 -PackageOnly Passed, 0 warnings. None of the three C# GGUF Task outputs has LlamaBackends\cuda
The same two builds with -LlamaCuda Passed, 0 warnings. All four C# outputs have ggml-cuda.dll, cublas64_13.dll, cublasLt64_13.dll and the backend manifest in LlamaBackends\cuda
Samples\Runtime\build.ps1 -Sample all -Platform x64 -PackageOnly -LlamaCuda, and the same for Samples\Tasks Passed, 0 warnings. The x64 C# outputs have the same CUDA files as the x64 C++ outputs
hello-language-model-csharp.exe --model qwen2.5-0.5b-instruct-q4_k_m.gguf --device gpu Printed ggml_cuda_init: found 1 CUDA devices and answered
task-model-text-generation-csharp.exe --llama qwen2.5-0.5b-instruct-q4_k_m.gguf "Name three primary colors." 32 --device gpu Printed ggml_cuda_init: found 1 CUDA devices and named three primary colors

The x64 C# samples weren't run on an NVIDIA GPU. They get the same backend files as the x64 C++ samples, which #40 validated on an RTX 4090.

build.ps1 -LlamaCuda set WinMLSamplesLlamaCuda only for the MSBuild
restore and build of the C++ projects. The C# samples build through
dotnet with their own arguments, so the four C# GGUF samples kept only
the CPU backend while the build reported CPU and CUDA.

The Runtime and Tasks build scripts now pass the property to the C#
builds too, and hello-language-model-csharp,
task-model-text-generation-csharp, task-chat-completion-csharp and
task-text-generation-features-csharp reference
Microsoft.Windows.AI.MachineLearning.LibLlama under it, as their C++
counterparts do. The GGUF guide and the Tasks README now say the switch
covers the C# samples.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ca5b72cf-ae75-4384-9fc4-a6081b9fddea

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the opt-in CUDA support added to the four C# GGUF samples.

No open issues 🎉

What changed in this PR

Extends the existing opt-in CUDA backend deployment to the four C# GGUF samples in the Runtime and Tasks catalogs, keeping the CPU backend as the default.

Changes:

  • Pass WinMLSamplesLlamaCuda to the C# dotnet builds in both catalogs.
  • Conditionally reference Microsoft.Windows.AI.MachineLearning.LibLlama in all four C# GGUF projects.
  • Update documentation to state that -LlamaCuda supports C++ and C#.
File Description
Samples/​Tasks/​README.md Documents C# support for the CUDA switch.
Samples/​Tasks/​model-backed/​text-generation/​csharp/​task-model-text-generation-csharp.csproj Adds the conditional CUDA package reference.
Samples/​Tasks/​model-backed/​text-generation-features/​csharp/​task-text-generation-features-csharp.csproj Adds the conditional CUDA package reference.
Samples/​Tasks/​language/​chat-completion/​csharp/​task-chat-completion-csharp.csproj Adds the conditional CUDA package reference.
Samples/​Tasks/​build.ps1 Forwards the CUDA property to C# builds.
Samples/​Runtime/​language/​hello-language-model/​csharp/​hello-language-model-csharp.csproj Adds the conditional CUDA package reference.
Samples/​Runtime/​build.ps1 Forwards the CUDA property to C# builds.
docs/​Runtime/​gguf-models.md Expands CUDA deployment guidance to include C#.

Review effort: Balanced

@nieubank
Nick Eubanks (nieubank) merged commit acb606a into main Nov 18, 2026
4 checks passed
@nieubank
Nick Eubanks (nieubank) deleted the nieubank/csharp-llamacuda branch November 18, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants