Go binding for MXNet C predict API. This is used by the MXNet agent in MLModelScope to perform model inference in Go.
Download and install go-mxnet:
go get -v github.com/c3sr/go-mxnet
The binding requires MXNet and other Go packages.
The MXNet C library is expected to be under /opt/mxnet
.
To install MXNet on your system, you can follow the MXNet documentation, or refer to our scripts or the LIBRARY INSTALLATION
section in the dockefiles. OpenBLAS is used in our default build.
-
The default blas is OpenBLAS. The default OpenBLAS path for macOS is
/usr/local/opt/openblas
if installed throught homebrew (openblas is keg-only, which means it was not symlinked into /usr/local, because macOS provides BLAS and LAPACK in the Accelerate framework). -
The default mxnet installation path is
/opt/mxnet
for linux, darwin and ppc64le without powerai;/opt/DL/mxnet
for ppc64le with powerai. -
The default CUDA path is
/usr/local/cuda
See lib.go for details.
If you get an error about not being able to write to /opt
then perform the following
sudo mkdir -p /opt/mxnet
sudo chown -R `whoami` /opt/mxnet
If you are using MXNet docker images or other libary paths, change CGO_CFLAGS, CGO_CXXFLAGS and CGO_LDFLAGS enviroment variables. Refer to Using cgo with the go command.
For example,
export CGO_CFLAGS="${CGO_CFLAGS} -I/tmp/mxnet/include"
export CGO_CXXFLAGS="${CGO_CXXFLAGS} -I/tmp/mxnet/include"
export CGO_LDFLAGS="${CGO_LDFLAGS} -L/tmp/mxnet/lib"
You can install the dependency through go get
.
cd $GOPATH/src/github.com/c3sr/go-mxnet
go get -u -v ./...
Or use Dep.
dep ensure -v
This installs the dependency in vendor/
.
Configure the linker environmental variables since the MXNet C library is under a non-system directory. Place the following in either your ~/.bashrc
or ~/.zshrc
file
Linux
export LIBRARY_PATH=$LIBRARY_PATH:/opt/mxnet/lib
export LD_LIBRARY_PATH=/opt/mxnet/lib:$DYLD_LIBRARY_PATH
macOS
export LIBRARY_PATH=$LIBRARY_PATH:/opt/mxnet/lib
export DYLD_LIBRARY_PATH=/opt/mxnet/lib:$DYLD_LIBRARY_PATH
Run go build
in to check the dependences installation and library paths set-up.
On linux, the default is to use GPU, if you don't have a GPU, do go build -tags nogpu
instead of go build
.
Note : The CGO interface passes go pointers to the C API. This is an error by the CGO runtime. Disable the error by placing
export GODEBUG=cgocheck=0
in your ~/.bashrc
or ~/.zshrc
file and then run either source ~/.bashrc
or source ~/.zshrc