diff --git a/.github/workflows/pre-sanity.yml b/.github/workflows/pre-sanity.yml new file mode 100644 index 0000000..7e2ef58 --- /dev/null +++ b/.github/workflows/pre-sanity.yml @@ -0,0 +1,22 @@ +name: Run pre sanity + +# run this workflow for each commit +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build dev image + run: make .build-image + + - name: Build + run: make docker-build + + - name: Tests + run: make docker-coverage + + - name: Checks + run: make docker-check diff --git a/Makefile b/Makefile index 8df5c90..19521e9 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -MODULE := github.com/nvidia/go-gpuallocator +MODULE := github.com/NVIDIA/go-gpuallocator DOCKER ?= docker -GOLANG_VERSION := 1.15 +GOLANG_VERSION := 1.20.4 ifeq ($(IMAGE),) REGISTRY ?= nvidia diff --git a/docker/Dockerfile.devel b/docker/Dockerfile.devel index d3a8308..60a2234 100644 --- a/docker/Dockerfile.devel +++ b/docker/Dockerfile.devel @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -ARG GOLANG_VERSION=1.15 +ARG GOLANG_VERSION=1.20.4 FROM golang:${GOLANG_VERSION} -RUN go get -u golang.org/x/lint/golint +RUN go install golang.org/x/lint/golint@latest diff --git a/go.mod b/go.mod index 4bda907..826515d 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,11 @@ module github.com/NVIDIA/go-gpuallocator -go 1.15 +go 1.20 require github.com/NVIDIA/go-nvlib v0.0.0-20231116150931-9fd385bace0d +require github.com/NVIDIA/go-nvml v0.12.0-1.0.20231020145430-e06766c5e74f // indirect + replace ( k8s.io/api => k8s.io/api v0.18.2 k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.2 diff --git a/go.sum b/go.sum index d2c2a29..76f6a0c 100644 --- a/go.sum +++ b/go.sum @@ -14,7 +14,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/gpuallocator/device.go b/gpuallocator/device.go index 31b1433..d85b238 100644 --- a/gpuallocator/device.go +++ b/gpuallocator/device.go @@ -72,7 +72,7 @@ type DeviceList []*Device type DeviceSet map[string]*Device // NewDevices creates a list of Devices from all available nvml.Devices using the specified options. -func NewDevices(opts ...deviceListOption) (DeviceList, error) { +func NewDevices(opts ...Option) (DeviceList, error) { o := &deviceListBuilder{} for _, opt := range opts { opt(o) diff --git a/gpuallocator/options.go b/gpuallocator/options.go index 5a75669..1c6224a 100644 --- a/gpuallocator/options.go +++ b/gpuallocator/options.go @@ -27,17 +27,18 @@ type deviceListBuilder struct { devicelib device.Interface } -type deviceListOption func(*deviceListBuilder) +// Option defines a type for functional options for constructing device lists. +type Option func(*deviceListBuilder) // WithNvmlLib provides an option to set the nvml library. -func WithNvmlLib(nvmllib nvml.Interface) deviceListOption { +func WithNvmlLib(nvmllib nvml.Interface) Option { return func(o *deviceListBuilder) { o.nvmllib = nvmllib } } // WithDeviceLib provides an option to set the library used for device enumeration. -func WithDeviceLib(devicelib device.Interface) deviceListOption { +func WithDeviceLib(devicelib device.Interface) Option { return func(o *deviceListBuilder) { o.devicelib = devicelib } diff --git a/internal/links/device.go b/internal/links/device.go index 61b587d..ed2ec23 100644 --- a/internal/links/device.go +++ b/internal/links/device.go @@ -23,8 +23,11 @@ import ( "github.com/NVIDIA/go-nvlib/pkg/nvml" ) +// P2PLinkType defines the link information between two devices. type P2PLinkType uint +// The following constants define the nature of a link between two devices. +// These include peer-2-peer and NVLink information. const ( P2PLinkUnknown P2PLinkType = iota P2PLinkCrossCPU @@ -90,11 +93,11 @@ func GetNVLink(dev1 device.Device, dev2 device.Device) (P2PLinkType, error) { if ret != nvml.SUCCESS { return P2PLinkUnknown, fmt.Errorf("failed to get pci info: %v", ret) } - dev2BusId := PciInfo(dev2PciInfo).BusID() + dev2BusID := PciInfo(dev2PciInfo).BusID() nvlink := P2PLinkUnknown for _, pciInfo := range pciInfos { - if pciInfo.BusID() == dev2BusId { + if pciInfo.BusID() == dev2BusID { continue } switch nvlink { diff --git a/vendor/modules.txt b/vendor/modules.txt index 726087c..8d86838 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,8 +1,9 @@ # github.com/NVIDIA/go-nvlib v0.0.0-20231116150931-9fd385bace0d -## explicit +## explicit; go 1.20 github.com/NVIDIA/go-nvlib/pkg/nvlib/device github.com/NVIDIA/go-nvlib/pkg/nvml # github.com/NVIDIA/go-nvml v0.12.0-1.0.20231020145430-e06766c5e74f +## explicit; go 1.15 github.com/NVIDIA/go-nvml/pkg/dl github.com/NVIDIA/go-nvml/pkg/nvml # k8s.io/api => k8s.io/api v0.18.2