Skip to content

Add Windows ARM64 CPU support for TorchSharp#1549

Open
alinpahontu2912 wants to merge 3 commits intodotnet:mainfrom
alinpahontu2912:arm64_support
Open

Add Windows ARM64 CPU support for TorchSharp#1549
alinpahontu2912 wants to merge 3 commits intodotnet:mainfrom
alinpahontu2912:arm64_support

Conversation

@alinpahontu2912
Copy link
Member

@alinpahontu2912 alinpahontu2912 commented Feb 27, 2026

Fixes #945
Add support for building, packaging, and distributing TorchSharp on Windows ARM64 (CPU-only, no CUDA). This enables .NET developers on Windows ARM64 devices to use TorchSharp with the stable LibTorch 2.10.0 release.

Key changes:

  • MSBuild: Add win-arm64 RID mapping, archive name, and cmake path (ARM64 archive has different layout: lib/ instead of libtorch/lib/)
  • Native build: Enable ARM64 cross-compilation from x64 via MSVC amd64_arm64 toolchain and CMake -A ARM64
  • Runtime: Detect win-arm64 in Torch.cs nativeRid for correct native library loading
  • NuGet: Add libtorch-cpu-win-arm64 package and update libtorch-cpu meta-package
  • CI: Add Windows ARM64 PR validation and native build pipeline jobs (cross-compiled on x64 agents)
  • LibTorch: ARM64 uses armpl_lp64.dll (ARM Performance Libraries) instead of Intel OpenMP (libiomp5md.dll)

Add support for building, packaging, and distributing TorchSharp on
Windows ARM64 (CPU-only, no CUDA). This enables .NET developers on
Windows ARM64 devices to use TorchSharp with the stable LibTorch 2.10.0
release.

Key changes:
- MSBuild: Add win-arm64 RID mapping, archive name, and cmake path
  (ARM64 archive has different layout: lib/ instead of libtorch/lib/)
- Native build: Enable ARM64 cross-compilation from x64 via MSVC
  amd64_arm64 toolchain and CMake -A ARM64
- Runtime: Detect win-arm64 in Torch.cs nativeRid for correct native
  library loading
- NuGet: Add libtorch-cpu-win-arm64 package and update libtorch-cpu
  meta-package
- CI: Add Windows ARM64 PR validation and native build pipeline jobs
  (cross-compiled on x64 agents)
- LibTorch: ARM64 uses armpl_lp64.dll (ARM Performance Libraries)
  instead of Intel OpenMP (libiomp5md.dll)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Windows ARM64 (CPU-only) support across TorchSharp’s runtime RID detection, build/packaging scripts, redist file lists, and CI packaging pipelines to enable building and distributing win-arm64-native assets.

Changes:

  • Add win-arm64 runtime RID detection and new libtorch-cpu win-arm64 packaging inputs (SHA + NuGet project).
  • Update MSBuild/native build scripts for ARM64 cross-compilation and ARM64-specific LibTorch archive layout.
  • Extend Azure Pipelines to validate/build and to produce/package Windows ARM64 artifacts.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/TorchSharp/Torch.cs Detect win-arm64 for native package/runtime selection.
src/Redist/libtorch-cpu/libtorch-win-arm64-shared-with-deps-2.10.0%2Bcpu.zip.sha Adds SHA pin for the Windows ARM64 LibTorch CPU archive.
src/Redist/libtorch-cpu/libtorch-cpu.proj Adds ARM64-specific Windows DLL list and archive layout differences.
src/Native/gen-buildsys-win.bat Adds CMake generator arch selection for ARM64.
src/Native/build.cmd Enables MSVC cross-compilation setup for ARM64 and passes ARM64 through to CMake.
pkg/pack.proj Adds packaging warning for missing win-arm64 TorchSharp native assets.
pkg/libtorch-cpu/libtorch-cpu.nupkgproj Includes the new win-arm64 libtorch-cpu package as a dependency.
pkg/libtorch-cpu-win-arm64/libtorch-cpu-win-arm64.nupkgproj New NuGet packaging project for libtorch-cpu-win-arm64.
azure-pipelines.yml Adds PR validation job and packaging-stage job/artifact handling for Windows ARM64.
Directory.Build.targets Adds ARM64 Windows CPU native dependency list for examples/tests.
Directory.Build.props Adds win-arm64 RID mapping, ARM64 archive naming, and ARM64-specific CMake path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

alinpahontu2912 and others added 2 commits March 11, 2026 15:48
- Use ProcessArchitecture instead of OSArchitecture for nativeRid to
  correctly handle x64 emulation on ARM64 Windows
- Add missing '-c Release' configuration to Windows_arm64 CI job
- Consolidate duplicate TargetRuntimeID blocks into single block with
  mutually exclusive conditions
- Update VS version list in gen-buildsys-win.bat usage text to include
  VS2022 and VS2026

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The job template appends \ to buildScript, so including
'Release' after '-c' resulted in 'dotnet build ... -c Release Release',
where the trailing 'Release' was interpreted as a project path (MSB1009).

Remove the explicit 'Release' so the template provides it, matching
the pattern used by the MacOS_arm64 job.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ARM64 support

2 participants