build native pack of Torchsharp and libtorch for arm64 ubuntu

Open
#1,516 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Quiet
Tech stack
cmake, csharp, linux, python, pytorch, ubuntu

Research direction

Start with src/Native/build.proj and src/Native/build.sh, then trace the failing --libtorchpath shown in the build error. Compare that path with the ARM64 installation under src/Native/NativeDependencies/arm64-linux/libtorch and the generated /pytorch/build/install directory. Done means the native build uses the locally built LibTorch without downloading the x86 package, and dotnet build and dotnet pack complete successfully.

Written by the indexing model from the issue text.

Description

question

How to build native pack of Torchsharp and libtorch on arm64 ubuntu 24.04?

sudo apt update
sudo apt install -y git cmake build-essential python3 python3-pip
libopenblas-dev libomp-dev python3.12-dev python3-venv

wget https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --channel 8.0
export PATH=$PATH:$HOME/.dotnet

git clone --recursive https://github.com/pytorch/pytorch.git
cd pytorch

sudo apt install python3-venv python3-full
python3 -m venv ~/pytorch-env
source ~/pytorch-env/bin/activate

=== 1. Prepare environment ===

sudo apt update

pip install --upgrade pip setuptools wheel
pip install typing_extensions numpy pyyaml
pip install -r requirements.txt

=== 2. Clone PyTorch and install deps ===

git clone --recursive https://github.com/pytorch/pytorch.git
cd pytorch
git checkout 2.7.1

pip install -r requirements.txt

Clean any old build

rm -rf build

=== 3. Build LibTorch for ARM64 ===

tmux new -s pytorch-build

python3 setup.py build | tee build.log

#if ssh closed use this for keept it

  • If SSH disconnects, reconnect and run
    tmux attach -t pytorch-build.

#for detach from tmux
Ctrl + b, then d

#Check logs if needed
tail -f ~/pytorch/build.log

Generate LibTorch dir include bin,lib,share,...

cd /pytorch/build
cmake --install . --prefix ./install

back to root

cd /

=== 4. Clone TorchSharp and integrate LibTorch ===

git clone https://github.com/dotnet/TorchSharp.git
cd TorchSharp

Copy native libs into TorchSharp NativeDependencies

mkdir -p src/NativeDependencies/arm64-linux/libtorch
cp -r /pytorch/build/install/* /TorchSharp/src/Native/NativeDependencies/arm64-linux/libtorch

cd /TorchSharp/src/Native

cmake -DCMAKE_PREFIX_PATH=/TorchSharp/src/Native/NativeDependencies/arm64-linux/libtorch -DCMAKE_BUILD_TYPE=Release

=== 5. link TorchSharp to natively built libtorch ===

how to do that?
how to do that?
I'm stock here!!!!!!!!!

=== 6. Build and pack TorchSharp NuGet ===

dotnet build -c Release
dotnet pack -c Release

I'm stock at step 5 , when going to do step 6, it download libtorch set in
/TorchSharp/src/Redist/libtorch-cpu

and got this error:
build failed with 2 error(s) (0.9s)
collect2 : error : ld returned 1 exit status
/TorchSharp/src/Native/build.proj(40,5): error MSB3073: The command ""/TorchSharp/src/Native/build.sh" --configuration Release --arch arm64 --libtorchpath /TorchSharp/bin/obj/AnyCPU.Release/libtorch-cpu/libtorch-cxx11-abi-shared-with-deps-2.7.1cpu/libtorch/share/cmake/Torch" exited with code 2.

Build failed with 2 error(s) in 4.5s

please help

Please complete the following information:

  • OS: [arm64 ubuntu 24.04
  • Package Type [e.g. torchsharp-cpu-linux, torchsharp-cuda-linux]
  • Version [e.g. 0.105.0]
Dominant language
C#
Stars
1.9k
Forks
228
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/TorchSharp

All issues in dotnet/TorchSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.