I've run into a few issues trying to build the cgo bindings for libtorch on my M1 Macbook (arm64).
I've tried building the bindings after using go get to fetch the package as well as cloning the repo directly from Github and running the build script from the raw source code.
Attempt 1 (using go get)
run go get github.com/wangkuiyi/gotorch
run $GOPATH/pkg/mod/github.com/wangkuiyi/gotorch@v0.0.0-20201028015551-9afed2f3ad7b/cgotorch/build.sh
This will produce the following errors. There are a few things I noticed in the output which makes it seem like there's a lot wrong here.
unzip cannot find libtorch-macos-1.6.0.zip, libtorch-macos-1.6.0.zip.zip or libtorch-macos-1.6.0.zip.ZIP.
ln: libtorch permission denied
make: *** No rule to make targetmacos/libtorch', needed by libcgotorch.so'. Stop.
The various permission denied issues at the end of the output.
This will produce this output (truncated for brevity). This seems to be something isn't compatible with an M1 (arm64) architecture.
Building for macOS ...
+ make CXX=clang++ LIB_SUFFIX=dylib 'INSTALL_NAME=-install_name @rpath/$@' LIBTORCH_DIR=macos/libtorch GLIBCXX_USE_CXX11_ABI=1 LOAD=all_load CUDA_FLAGS= -f Makefile -j
clang++ -L libtorch/lib \
cuda.o device.o functional.o init.o memory.o optim.o pickle.o tensor.o torch.o \
-shared \
-o libcgotorch.so -install_name @rpath/libcgotorch.so \
-Wl,-rpath,libtorch/lib \
-Wl,-all_load libtorch/lib/libc10.dylib \
-lc10 -ltorch -ltorch_cpu
ld: warning: ignoring file libtorch/lib/libtorch.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file libtorch/lib/libc10.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file libtorch/lib/libtorch_cpu.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
A couple of follow up questions based on these attempts.
Do I need to install Pytorch ahead of time pip install torch?
Specifically for the first error do I need to use sudo for the build.sh command?
I've run into a few issues trying to build the
cgo
bindings forlibtorch
on my M1 Macbook (arm64).I've tried building the bindings after using
go get
to fetch the package as well as cloning the repo directly from Github and running the build script from the raw source code.Attempt 1 (using go get)
go get github.com/wangkuiyi/gotorch
$GOPATH/pkg/mod/github.com/wangkuiyi/gotorch@v0.0.0-20201028015551-9afed2f3ad7b/cgotorch/build.sh
This will produce the following errors. There are a few things I noticed in the output which makes it seem like there's a lot wrong here.
unzip cannot find libtorch-macos-1.6.0.zip, libtorch-macos-1.6.0.zip.zip or libtorch-macos-1.6.0.zip.ZIP
.ln: libtorch permission denied
make: *** No rule to make target
macos/libtorch', needed bylibcgotorch.so'. Stop.
permission denied
issues at the end of the output.Attempt 2 (cloning repository)
git clone git@github.com:wangkuiyi/gotorch.git
cd gotorch
./cgotorch/build.sh
This will produce this output (truncated for brevity). This seems to be something isn't compatible with an M1 (arm64) architecture.
A couple of follow up questions based on these attempts.
pip install torch
?sudo
for thebuild.sh
command?