dotnet / dotnet/TorchSharp

build native pack of Torchsharp and libtorch for arm64 ubuntu

Open
#1,516 5 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
1.9k
Forks
228
PR merge metrics
No merged PRs in 30d

Description

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]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.