NVIDIA / go-nvml

Go Bindings for the NVIDIA Management Library (NVML)
Apache License 2.0
311 stars 64 forks source link

option to disable go-runtime library load #33

Open Sora233 opened 2 years ago

Sora233 commented 2 years ago

because of cgo flags, the nvml symbol just remain undefined for now.

and that doesn't work for me, because I have go plugin dependency , which force all symbols to be resolved when the program starts (before we enter usercode runtime)

compile-time dependency for me is just ok.

Sora233 commented 2 years ago

Although we can add cgo flag by hand, I am not sure whether there is still any performance penalty

/*
#cgo LDFLAGS: -lnvidia-ml
*/
import "C"
klueska commented 2 years ago

Try building with:

go build -ldflags="-extldflags=-Wl,-z,lazy" test.go

As pointed out here: https://github.com/NVIDIA/go-nvml/issues/18#issuecomment-809674036

The problem with doing:

/*
#cgo LDFLAGS: -lnvidia-ml
*/
import "C"

is that (1) you have to a specific version of NVML installed on your build machine and this version will then need to match the version of NVML on your deploy machine (whereas go-nvml is designed to work across all versions of NVML independent of build/deploy machine), and (2) you are forced to add this line to your application (it can't be added in the go-nvml library itself or otherwise a build dependency on NVML would be created).

Sora233 commented 2 years ago

I don't think that work because I have -znow already: https://github.com/golang/go/blob/c5fee935bbb8f02406eb653cfed550593755a1a4/src/cmd/link/internal/ld/lib.go#L1383