gotch: example doesn't run on ubuntu
That’s error because your Dockerfile didn’t effectively update CGO flags at gotch package $GOPATH/$GOPATH/pkg/mod/github.com/sugarme/gotch@$GOTCH_VERSION/libtch/lib.go .
In your Dockerfile you should do these in order:
Install compiler dependencies Install Go and setup GOPATH environment Install libtorch Install gotch Have a look at Setup gotch CPU shell script for more detail (it needs to read GOPATH env to know where is gotch package located and update its lib.go file for CGO flags before your Go example can compile and run).
@sugarme I have some issues still with the demo example - what to install regarding compiler dependencies?
where I find which CGO flags I need to set? I see there is something in the https://github.com/sugarme/gotch/blob/master/setup-gotch.sh - but who also sets the SRCDIR in that script? also the GOPATH in the setup-gotch.sh is set automatically if not defined…
will go build my app also need to set the same flags as for the lib?
do you have an example which shows how to compile the main.go somewhere in this repo?
here is my updated Dockerfile:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends build-essential ca-certificates cmake curl unzip nano wget g++
WORKDIR /home/developer
ENV HOME /home/developer
ENV GOPATH "$HOME/go"
# Install golang
RUN wget -c https://go.dev/dl/go1.19.5.linux-amd64.tar.gz \
&& rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.5.linux-amd64.tar.gz \
&& rm go1.19.5.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin
# Install Libtorch - CPU
RUN wget https://raw.githubusercontent.com/sugarme/gotch/master/setup-libtorch.sh
RUN chmod +x setup-libtorch.sh
RUN sed -i 's/sudo//g' setup-libtorch.sh
ENV CUDA_VER=cpu
RUN bash setup-libtorch.sh
ENV GOTCH_LIBTORCH="/usr/local/lib/libtorch"
ENV LIBRARY_PATH="$LIBRARY_PATH:$GOTCH_LIBTORCH/lib"
ENV CPATH="$CPATH:$GOTCH_LIBTORCH/lib:$GOTCH_LIBTORCH/include:$GOTCH_LIBTORCH/include/torch/csrc/api/include"
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GOTCH_LIBTORCH/lib"
# Setup gotch
RUN wget https://raw.githubusercontent.com/sugarme/gotch/master/setup-gotch.sh
RUN chmod +x setup-gotch.sh
RUN sed -i 's/sudo//g' setup-gotch.sh
ENV CUDA_VER=cpu
ENV GOTCH_VER=v0.7.0
RUN bash setup-gotch.sh
COPY main.go /home/developer/pytorch_demo/main.go
WORKDIR /home/developer/pytorch_demo
RUN go mod init main
RUN go mod tidy
#RUN go build main.go
ENTRYPOINT bash
my env variables:
$ printenv
HOSTNAME=17dbfb11a10c
PWD=/home/developer/pytorch_demo
HOME=/home/developer
CUDA_VER=cpu
TERM=xterm
LIBRARY_PATH=:/usr/local/lib/libtorch/lib
SHLVL=1
GOTCH_LIBTORCH=/usr/local/lib/libtorch
LD_LIBRARY_PATH=:/usr/local/lib/libtorch/lib
GOTCH_VER=v0.7.0
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin
CPATH=:/usr/local/lib/libtorch/lib:/usr/local/lib/libtorch/include:/usr/local/lib/libtorch/include/torch/csrc/api/include
DEBIAN_FRONTEND=noninteractive
GOPATH=/home/developer/go
_=/usr/bin/printenv
go build main.go errors:
go build main.go
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running g++ failed: exit status 1
/usr/bin/ld: cannot find -lcuda: No such file or directory
/usr/bin/ld: cannot find -lcudart: No such file or directory
/usr/bin/ld: cannot find -lcublas: No such file or directory
/usr/bin/ld: cannot find -lcudnn: No such file or directory
/usr/bin/ld: cannot find -lcaffe2_nvrtc: No such file or directory
/usr/bin/ld: cannot find -lnvrtc-builtins: No such file or directory
/usr/bin/ld: cannot find -lnvrtc: No such file or directory
/usr/bin/ld: cannot find -lnvToolsExt: No such file or directory
/usr/bin/ld: cannot find -lc10_cuda: No such file or directory
/usr/bin/ld: cannot find -ltorch_cuda: No such file or directory
collect2: error: ld returned 1 exit status
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (6 by maintainers)
@Arnold1,
hey, finally! Not sure, maybe cgo kicked in too early.
This just saved me hours of headache! Thank you! No idea why it’s required but it is 😄
@sugarme I already ssh into the docker container and got the printenv:
oh that worked fine:
any idea why that was necessary?
thanks @sugarme - will close that ticket…