Compare commits

...

32 Commits

Author SHA1 Message Date
Evan Lezar
dc1240922a Merge pull request #592 from elezar/fix-release-scripts
[no-relnote] fix package release scripts
2024-07-09 15:35:21 +02:00
Evan Lezar
eda83913a8 [no-relnote] fix package release scripts
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-07-09 15:34:31 +02:00
Evan Lezar
b093d6a8b3 Merge pull request #575 from elezar/fix-centos7-builds
Fix centos7 builds
2024-07-01 16:55:57 +02:00
Evan Lezar
b787b46480 Bump libnvidia-container to 24b3f92
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-07-01 16:47:37 +02:00
Evan Lezar
4cb817ce92 [no-relnote] Use centos:7 vault repos for builds
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-07-01 16:47:37 +02:00
Evan Lezar
770eb72ee4 [no-relnote] Update submodule to release-1.15
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-07-01 16:47:31 +02:00
Evan Lezar
8b9f22b6c5 Merge pull request #540 from elezar/fix-ppcle64-builds
Fix ppcle64 builds
2024-06-11 14:54:03 +02:00
Evan Lezar
644610b16a Update libnvidia-container
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-06-11 14:53:33 +02:00
Evan Lezar
a8ec6e5b56 Use archived package repo for centos:stream8
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-06-11 14:52:32 +02:00
Evan Lezar
4f4324e105 Merge pull request #535 from NVIDIA/dependabot/go_modules/release-1.15/golang.org/x/mod-0.18.0
Bump golang.org/x/mod from 0.17.0 to 0.18.0
2024-06-10 14:44:59 +02:00
dependabot[bot]
675f259bc8 Bump golang.org/x/mod from 0.17.0 to 0.18.0
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.17.0 to 0.18.0.
- [Commits](https://github.com/golang/mod/compare/v0.17.0...v0.18.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-10 11:45:06 +00:00
Evan Lezar
3fd22e54b6 Merge pull request #534 from NVIDIA/dependabot/go_modules/release-1.15/golang.org/x/sys-0.21.0
Bump golang.org/x/sys from 0.20.0 to 0.21.0
2024-06-10 13:43:57 +02:00
dependabot[bot]
cc728cf96c Bump golang.org/x/sys from 0.20.0 to 0.21.0
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.20.0 to 0.21.0.
- [Commits](https://github.com/golang/sys/compare/v0.20.0...v0.21.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-10 11:36:59 +00:00
Evan Lezar
ffc9824291 Merge pull request #525 from NVIDIA/dependabot/docker/deployments/container/release-1.15/nvidia/cuda-12.5.0-base-ubuntu20.04
Bump nvidia/cuda from 12.4.1-base-ubuntu20.04 to 12.5.0-base-ubuntu20.04 in /deployments/container
2024-06-10 13:36:05 +02:00
Evan Lezar
eb619869d6 Merge pull request #537 from elezar/bump-github.com/xrash/smetrics
Bump github.com/xrash/smetrics to v0.0.0-20240521201337-686a1a2994c1
2024-06-10 13:35:36 +02:00
Evan Lezar
34bae6f368 Bump github.com/xrash/smetrics to v0.0.0-20240521201337-686a1a2994c1
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-06-10 13:32:26 +02:00
dependabot[bot]
11e50626c6 Bump nvidia/cuda in /deployments/container
Bumps nvidia/cuda from 12.4.1-base-ubuntu20.04 to 12.5.0-base-ubuntu20.04.

---
updated-dependencies:
- dependency-name: nvidia/cuda
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-03 08:23:53 +00:00
Evan Lezar
2b3599d63b Merge pull request #505 from NVIDIA/dependabot/go_modules/release-1.15/github.com/NVIDIA/go-nvlib-0.4.0
Bump github.com/NVIDIA/go-nvlib from 0.3.0 to 0.4.0
2024-05-21 13:50:53 +02:00
dependabot[bot]
aeef21029e ---
updated-dependencies:
- dependency-name: github.com/NVIDIA/go-nvlib
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-21 13:40:27 +02:00
Evan Lezar
99e08b572a Merge pull request #496 from NVIDIA/dependabot/go_modules/release-1.15/github.com/NVIDIA/go-nvml-0.12.0-6
Bump github.com/NVIDIA/go-nvml from 0.12.0-4 to 0.12.0-6
2024-05-15 21:12:01 +02:00
Evan Lezar
1947c7b571 Merge pull request #481 from NVIDIA/dependabot/go_modules/release-1.15/github.com/urfave/cli/v2-2.27.2
Bump github.com/urfave/cli/v2 from 2.27.1 to 2.27.2
2024-05-15 21:11:23 +02:00
dependabot[bot]
674271dff3 Bump github.com/NVIDIA/go-nvml from 0.12.0-4 to 0.12.0-6
Bumps [github.com/NVIDIA/go-nvml](https://github.com/NVIDIA/go-nvml) from 0.12.0-4 to 0.12.0-6.
- [Commits](https://github.com/NVIDIA/go-nvml/compare/v0.12.0-4...v0.12.0-6)

---
updated-dependencies:
- dependency-name: github.com/NVIDIA/go-nvml
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-15 12:32:17 +00:00
Evan Lezar
1538204ff7 Merge pull request #480 from NVIDIA/dependabot/go_modules/release-1.15/github.com/NVIDIA/go-nvml-0.12.0-5
Bump github.com/NVIDIA/go-nvml from 0.12.0-3 to 0.12.0-5
2024-05-15 14:31:24 +02:00
Evan Lezar
38137a2d1c Merge pull request #486 from NVIDIA/dependabot/go_modules/release-1.15/golang.org/x/sys-0.20.0
Bump golang.org/x/sys from 0.19.0 to 0.20.0
2024-05-15 14:31:08 +02:00
dependabot[bot]
8efd0f26b0 Bump github.com/urfave/cli/v2 from 2.27.1 to 2.27.2
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.27.1 to 2.27.2.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v2.27.1...v2.27.2)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-15 14:28:20 +02:00
dependabot[bot]
7bf948938f Bump github.com/NVIDIA/go-nvml from 0.12.0-3 to 0.12.0-5
Bumps [github.com/NVIDIA/go-nvml](https://github.com/NVIDIA/go-nvml) from 0.12.0-3 to 0.12.0-5.
- [Commits](https://github.com/NVIDIA/go-nvml/compare/v0.12.0-3...v0.12.0-5)

---
updated-dependencies:
- dependency-name: github.com/NVIDIA/go-nvml
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-07 13:22:21 +00:00
Evan Lezar
90d27b8abd Merge pull request #468 from elezar/manual/go_modules/release-1.15/github.com/NVIDIA/go-nvml-0.12.0-4
Manual/go modules/release 1.15/GitHub.com/nvidia/go nvml 0.12.0 4
2024-05-07 15:21:40 +02:00
dependabot[bot]
29c4fec1f8 Bump golang.org/x/sys from 0.19.0 to 0.20.0
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.19.0 to 0.20.0.
- [Commits](https://github.com/golang/sys/compare/v0.19.0...v0.20.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-05 08:31:45 +00:00
Evan Lezar
28bb021935 Merge pull request #470 from NVIDIA/dependabot/go_modules/release-1.15/tags.cncf.io/container-device-interface-0.7.2
Bump tags.cncf.io/container-device-interface from 0.7.1 to 0.7.2
2024-04-22 14:55:26 +02:00
dependabot[bot]
993412c804 Bump tags.cncf.io/container-device-interface from 0.7.1 to 0.7.2
Bumps [tags.cncf.io/container-device-interface](https://github.com/cncf-tags/container-device-interface) from 0.7.1 to 0.7.2.
- [Release notes](https://github.com/cncf-tags/container-device-interface/releases)
- [Commits](https://github.com/cncf-tags/container-device-interface/compare/v0.7.1...v0.7.2)

---
updated-dependencies:
- dependency-name: tags.cncf.io/container-device-interface
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-21 08:25:18 +00:00
Evan Lezar
b6be911eaa Replace go-nvlib/pkg/nvml with go-nvml/pkg/nvml
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-04-18 15:01:20 +02:00
Evan Lezar
2019cd6f0a Update to go-nvlib v0.3.0 and go-nvml v0.12.0-4
Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-04-18 15:01:03 +02:00
149 changed files with 38208 additions and 10395 deletions

2
.gitmodules vendored
View File

@@ -1,4 +1,4 @@
[submodule "third_party/libnvidia-container"]
path = third_party/libnvidia-container
url = https://github.com/NVIDIA/libnvidia-container.git
branch = main
branch = release-1.15

View File

@@ -14,7 +14,7 @@
ARG GOLANG_VERSION=x.x.x
FROM nvidia/cuda:12.4.1-base-ubuntu20.04
FROM nvidia/cuda:12.5.0-base-ubuntu20.04
ARG ARTIFACTS_ROOT
COPY ${ARTIFACTS_ROOT} /artifacts/packages/

View File

@@ -15,7 +15,7 @@
ARG GOLANG_VERSION=x.x.x
ARG VERSION="N/A"
FROM nvidia/cuda:12.4.1-base-ubi8 as build
FROM nvidia/cuda:12.5.0-base-ubi8 as build
RUN yum install -y \
wget make git gcc \
@@ -48,7 +48,7 @@ COPY . .
RUN GOPATH=/artifacts go install -ldflags="-s -w -X 'main.Version=${VERSION}'" ./tools/...
FROM nvidia/cuda:12.4.1-base-ubi8
FROM nvidia/cuda:12.5.0-base-ubi8
ENV NVIDIA_DISABLE_REQUIRE="true"
ENV NVIDIA_VISIBLE_DEVICES=void

View File

@@ -15,7 +15,7 @@
ARG GOLANG_VERSION=x.x.x
ARG VERSION="N/A"
FROM nvidia/cuda:12.4.1-base-ubuntu20.04 as build
FROM nvidia/cuda:12.5.0-base-ubuntu20.04 as build
RUN apt-get update && \
apt-get install -y wget make git gcc \
@@ -47,7 +47,7 @@ COPY . .
RUN GOPATH=/artifacts go install -ldflags="-s -w -X 'main.Version=${VERSION}'" ./tools/...
FROM nvcr.io/nvidia/cuda:12.4.1-base-ubuntu20.04
FROM nvcr.io/nvidia/cuda:12.5.0-base-ubuntu20.04
# Remove the CUDA repository configurations to avoid issues with rotated GPG keys
RUN rm -f /etc/apt/sources.list.d/cuda.list

View File

@@ -17,6 +17,13 @@
ARG BASEIMAGE
FROM ${BASEIMAGE}
# centos:stream8 is EOL.
# We switch to the vault repositories for this base image.
ARG BASEIMAGE
RUN sed -i -e "s|mirrorlist=|#mirrorlist=|g" \
-e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" \
/etc/yum.repos.d/CentOS-*
RUN yum install -y \
ca-certificates \
gcc \

16
go.mod
View File

@@ -3,22 +3,22 @@ module github.com/NVIDIA/nvidia-container-toolkit
go 1.20
require (
github.com/NVIDIA/go-nvlib v0.2.0
github.com/NVIDIA/go-nvml v0.12.0-3
github.com/NVIDIA/go-nvlib v0.4.0
github.com/NVIDIA/go-nvml v0.12.0-6
github.com/fsnotify/fsnotify v1.7.0
github.com/opencontainers/runtime-spec v1.2.0
github.com/pelletier/go-toml v1.9.5
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.1
golang.org/x/mod v0.17.0
golang.org/x/sys v0.19.0
tags.cncf.io/container-device-interface v0.7.1
github.com/urfave/cli/v2 v2.27.2
golang.org/x/mod v0.18.0
golang.org/x/sys v0.21.0
tags.cncf.io/container-device-interface v0.7.2
tags.cncf.io/container-device-interface/specs-go v0.7.0
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
@@ -29,7 +29,7 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect

32
go.sum
View File

@@ -1,11 +1,11 @@
github.com/NVIDIA/go-nvlib v0.2.0 h1:roq+SDstbP1fcy2XVH7wB2Gz2/Ud7Q+NGQYOcVITVrA=
github.com/NVIDIA/go-nvlib v0.2.0/go.mod h1:kFuLNTyD1tF6FbRFlk+/EdUW5BrkE+v1Y3A3/9zKSjA=
github.com/NVIDIA/go-nvml v0.12.0-3 h1:QwfjYxEqIQVRhl8327g2Y3ZvKResPydpGSKtCIIK9jE=
github.com/NVIDIA/go-nvml v0.12.0-3/go.mod h1:SOufGc5Wql+cxrIZ8RyJwVKDYxfbs4WPkHXqadcbfvA=
github.com/NVIDIA/go-nvlib v0.4.0 h1:dvuqjjSamBODFuxttPg4H/xtNVQRZOSlwFtuNKybcGI=
github.com/NVIDIA/go-nvlib v0.4.0/go.mod h1:87z49ULPr4GWPSGfSIp3taU4XENRYN/enIg88MzcL4k=
github.com/NVIDIA/go-nvml v0.12.0-6 h1:FJYc2KrpvX+VOC/8QQvMiQMmZ/nPMRpdJO/Ik4xfcr0=
github.com/NVIDIA/go-nvml v0.12.0-6/go.mod h1:8Llmj+1Rr+9VGGwZuRer5N/aCjxGuR5nPb/9ebBiIEQ=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -58,8 +58,8 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/urfave/cli v1.19.1/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
@@ -67,15 +67,15 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
@@ -86,7 +86,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
tags.cncf.io/container-device-interface v0.7.1 h1:MATNCbAD1su9U6zwQe5BrQ2vGGp1GBayD70bYaxYCNE=
tags.cncf.io/container-device-interface v0.7.1/go.mod h1:h1JVuOqTQVORp8DziaWKUCDNzAmN+zeCbqbqD30D0ZQ=
tags.cncf.io/container-device-interface v0.7.2 h1:MLqGnWfOr1wB7m08ieI4YJ3IoLKKozEnnNYBtacDPQU=
tags.cncf.io/container-device-interface v0.7.2/go.mod h1:Xb1PvXv2BhfNb3tla4r9JL129ck1Lxv9KuU6eVOfKto=
tags.cncf.io/container-device-interface/specs-go v0.7.0 h1:w/maMGVeLP6TIQJVYT5pbqTi8SCw/iHZ+n4ignuGHqg=
tags.cncf.io/container-device-interface/specs-go v0.7.0/go.mod h1:hMAwAbMZyBLdmYqWgYcKH0F/yctNpV3P35f+/088A80=

View File

@@ -22,7 +22,7 @@ import (
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// additionalInfo allows for the info.Interface to be extened to implement the infoInterface.

View File

@@ -20,7 +20,8 @@ import (
"testing"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml/mock"
"github.com/stretchr/testify/require"
)
@@ -32,7 +33,7 @@ func TestUsesNVGPUModule(t *testing.T) {
}{
{
description: "init failure returns false",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.ERROR_LIBRARY_NOT_FOUND
},
@@ -41,7 +42,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "no devices returns false",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -56,7 +57,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "DeviceGetCount error returns false",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -71,7 +72,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "Failure to get device name returns false",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -82,7 +83,7 @@ func TestUsesNVGPUModule(t *testing.T) {
return 1, nvml.SUCCESS
},
DeviceGetHandleByIndexFunc: func(index int) (nvml.Device, nvml.Return) {
device := &nvml.DeviceMock{
device := &mock.Device{
GetNameFunc: func() (string, nvml.Return) {
return "", nvml.ERROR_UNKNOWN
},
@@ -94,7 +95,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "nested panic returns false",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -105,7 +106,7 @@ func TestUsesNVGPUModule(t *testing.T) {
return 1, nvml.SUCCESS
},
DeviceGetHandleByIndexFunc: func(index int) (nvml.Device, nvml.Return) {
device := &nvml.DeviceMock{
device := &mock.Device{
GetNameFunc: func() (string, nvml.Return) {
panic("deep panic")
},
@@ -117,7 +118,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "Single device name with no nvgpu",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -128,7 +129,7 @@ func TestUsesNVGPUModule(t *testing.T) {
return 1, nvml.SUCCESS
},
DeviceGetHandleByIndexFunc: func(index int) (nvml.Device, nvml.Return) {
device := &nvml.DeviceMock{
device := &mock.Device{
GetNameFunc: func() (string, nvml.Return) {
return "NVIDIA A100-SXM4-40GB", nvml.SUCCESS
},
@@ -140,7 +141,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "Single device name with nvgpu",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -151,7 +152,7 @@ func TestUsesNVGPUModule(t *testing.T) {
return 1, nvml.SUCCESS
},
DeviceGetHandleByIndexFunc: func(index int) (nvml.Device, nvml.Return) {
device := &nvml.DeviceMock{
device := &mock.Device{
GetNameFunc: func() (string, nvml.Return) {
return "Orin (nvgpu)", nvml.SUCCESS
},
@@ -163,7 +164,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "Multiple device names with no nvgpu",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -174,7 +175,7 @@ func TestUsesNVGPUModule(t *testing.T) {
return 2, nvml.SUCCESS
},
DeviceGetHandleByIndexFunc: func(index int) (nvml.Device, nvml.Return) {
device := &nvml.DeviceMock{
device := &mock.Device{
GetNameFunc: func() (string, nvml.Return) {
return "NVIDIA A100-SXM4-40GB", nvml.SUCCESS
},
@@ -186,7 +187,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "Multiple device names with nvgpu",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -197,7 +198,7 @@ func TestUsesNVGPUModule(t *testing.T) {
return 2, nvml.SUCCESS
},
DeviceGetHandleByIndexFunc: func(index int) (nvml.Device, nvml.Return) {
device := &nvml.DeviceMock{
device := &mock.Device{
GetNameFunc: func() (string, nvml.Return) {
return "Orin (nvgpu)", nvml.SUCCESS
},
@@ -209,7 +210,7 @@ func TestUsesNVGPUModule(t *testing.T) {
},
{
description: "Mixed device names",
nvmllib: &nvml.InterfaceMock{
nvmllib: &mock.Interface{
InitFunc: func() nvml.Return {
return nvml.SUCCESS
},
@@ -226,7 +227,7 @@ func TestUsesNVGPUModule(t *testing.T) {
} else {
deviceName = "Orin (nvgpu)"
}
device := &nvml.DeviceMock{
device := &mock.Device{
GetNameFunc: func() (string, nvml.Return) {
return deviceName, nvml.SUCCESS
},

View File

@@ -19,24 +19,15 @@ package info
import (
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
)
// infoInterface provides an alias for mocking.
//
//go:generate moq -stub -out info-interface_mock.go . infoInterface
type infoInterface interface {
info.Interface
// UsesNVGPUModule indicates whether the system is using the nvgpu kernel module
UsesNVGPUModule() (bool, string)
}
type resolver struct {
logger logger.Interface
info infoInterface
info info.PropertyExtractor
}
// ResolveAutoMode determines the correct mode for the platform if set to "auto"
@@ -74,13 +65,13 @@ func (r resolver) resolveMode(mode string, image image.CUDA) (rmode string) {
return "cdi"
}
isTegra, reason := r.info.IsTegraSystem()
isTegra, reason := r.info.HasTegraFiles()
r.logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason)
hasNVML, reason := r.info.HasNvml()
r.logger.Debugf("Has NVML? %v: %v", hasNVML, reason)
usesNVGPUModule, reason := r.info.UsesNVGPUModule()
usesNVGPUModule, reason := r.info.UsesOnlyNVGPUModule()
r.logger.Debugf("Uses nvgpu kernel module? %v: %v", usesNVGPUModule, reason)
if (isTegra && !hasNVML) || usesNVGPUModule {

View File

@@ -19,6 +19,7 @@ package info
import (
"testing"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
"github.com/opencontainers/runtime-spec/specs-go"
testlog "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
@@ -202,14 +203,14 @@ func TestResolveAutoMode(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
info := &infoInterfaceMock{
info := &info.PropertyExtractorMock{
HasNvmlFunc: func() (bool, string) {
return tc.info["nvml"], "nvml"
},
IsTegraSystemFunc: func() (bool, string) {
HasTegraFilesFunc: func() (bool, string) {
return tc.info["tegra"], "tegra"
},
UsesNVGPUModuleFunc: func() (bool, string) {
UsesOnlyNVGPUModuleFunc: func() (bool, string) {
return tc.info["nvgpu"], "nvgpu"
},
}

View File

@@ -1,194 +0,0 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package info
import (
"sync"
)
// Ensure, that infoInterfaceMock does implement infoInterface.
// If this is not the case, regenerate this file with moq.
var _ infoInterface = &infoInterfaceMock{}
// infoInterfaceMock is a mock implementation of infoInterface.
//
// func TestSomethingThatUsesinfoInterface(t *testing.T) {
//
// // make and configure a mocked infoInterface
// mockedinfoInterface := &infoInterfaceMock{
// HasDXCoreFunc: func() (bool, string) {
// panic("mock out the HasDXCore method")
// },
// HasNvmlFunc: func() (bool, string) {
// panic("mock out the HasNvml method")
// },
// IsTegraSystemFunc: func() (bool, string) {
// panic("mock out the IsTegraSystem method")
// },
// UsesNVGPUModuleFunc: func() (bool, string) {
// panic("mock out the UsesNVGPUModule method")
// },
// }
//
// // use mockedinfoInterface in code that requires infoInterface
// // and then make assertions.
//
// }
type infoInterfaceMock struct {
// HasDXCoreFunc mocks the HasDXCore method.
HasDXCoreFunc func() (bool, string)
// HasNvmlFunc mocks the HasNvml method.
HasNvmlFunc func() (bool, string)
// IsTegraSystemFunc mocks the IsTegraSystem method.
IsTegraSystemFunc func() (bool, string)
// UsesNVGPUModuleFunc mocks the UsesNVGPUModule method.
UsesNVGPUModuleFunc func() (bool, string)
// calls tracks calls to the methods.
calls struct {
// HasDXCore holds details about calls to the HasDXCore method.
HasDXCore []struct {
}
// HasNvml holds details about calls to the HasNvml method.
HasNvml []struct {
}
// IsTegraSystem holds details about calls to the IsTegraSystem method.
IsTegraSystem []struct {
}
// UsesNVGPUModule holds details about calls to the UsesNVGPUModule method.
UsesNVGPUModule []struct {
}
}
lockHasDXCore sync.RWMutex
lockHasNvml sync.RWMutex
lockIsTegraSystem sync.RWMutex
lockUsesNVGPUModule sync.RWMutex
}
// HasDXCore calls HasDXCoreFunc.
func (mock *infoInterfaceMock) HasDXCore() (bool, string) {
callInfo := struct {
}{}
mock.lockHasDXCore.Lock()
mock.calls.HasDXCore = append(mock.calls.HasDXCore, callInfo)
mock.lockHasDXCore.Unlock()
if mock.HasDXCoreFunc == nil {
var (
bOut bool
sOut string
)
return bOut, sOut
}
return mock.HasDXCoreFunc()
}
// HasDXCoreCalls gets all the calls that were made to HasDXCore.
// Check the length with:
//
// len(mockedinfoInterface.HasDXCoreCalls())
func (mock *infoInterfaceMock) HasDXCoreCalls() []struct {
} {
var calls []struct {
}
mock.lockHasDXCore.RLock()
calls = mock.calls.HasDXCore
mock.lockHasDXCore.RUnlock()
return calls
}
// HasNvml calls HasNvmlFunc.
func (mock *infoInterfaceMock) HasNvml() (bool, string) {
callInfo := struct {
}{}
mock.lockHasNvml.Lock()
mock.calls.HasNvml = append(mock.calls.HasNvml, callInfo)
mock.lockHasNvml.Unlock()
if mock.HasNvmlFunc == nil {
var (
bOut bool
sOut string
)
return bOut, sOut
}
return mock.HasNvmlFunc()
}
// HasNvmlCalls gets all the calls that were made to HasNvml.
// Check the length with:
//
// len(mockedinfoInterface.HasNvmlCalls())
func (mock *infoInterfaceMock) HasNvmlCalls() []struct {
} {
var calls []struct {
}
mock.lockHasNvml.RLock()
calls = mock.calls.HasNvml
mock.lockHasNvml.RUnlock()
return calls
}
// IsTegraSystem calls IsTegraSystemFunc.
func (mock *infoInterfaceMock) IsTegraSystem() (bool, string) {
callInfo := struct {
}{}
mock.lockIsTegraSystem.Lock()
mock.calls.IsTegraSystem = append(mock.calls.IsTegraSystem, callInfo)
mock.lockIsTegraSystem.Unlock()
if mock.IsTegraSystemFunc == nil {
var (
bOut bool
sOut string
)
return bOut, sOut
}
return mock.IsTegraSystemFunc()
}
// IsTegraSystemCalls gets all the calls that were made to IsTegraSystem.
// Check the length with:
//
// len(mockedinfoInterface.IsTegraSystemCalls())
func (mock *infoInterfaceMock) IsTegraSystemCalls() []struct {
} {
var calls []struct {
}
mock.lockIsTegraSystem.RLock()
calls = mock.calls.IsTegraSystem
mock.lockIsTegraSystem.RUnlock()
return calls
}
// UsesNVGPUModule calls UsesNVGPUModuleFunc.
func (mock *infoInterfaceMock) UsesNVGPUModule() (bool, string) {
callInfo := struct {
}{}
mock.lockUsesNVGPUModule.Lock()
mock.calls.UsesNVGPUModule = append(mock.calls.UsesNVGPUModule, callInfo)
mock.lockUsesNVGPUModule.Unlock()
if mock.UsesNVGPUModuleFunc == nil {
var (
bOut bool
sOut string
)
return bOut, sOut
}
return mock.UsesNVGPUModuleFunc()
}
// UsesNVGPUModuleCalls gets all the calls that were made to UsesNVGPUModule.
// Check the length with:
//
// len(mockedinfoInterface.UsesNVGPUModuleCalls())
func (mock *infoInterfaceMock) UsesNVGPUModuleCalls() []struct {
} {
var calls []struct {
}
mock.lockUsesNVGPUModule.RLock()
calls = mock.calls.UsesNVGPUModule
mock.lockUsesNVGPUModule.RUnlock()
return calls
}

View File

@@ -22,7 +22,7 @@ import (
"path/filepath"
"strings"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"golang.org/x/sys/unix"
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"

View File

@@ -23,7 +23,7 @@ import (
"strings"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"tags.cncf.io/container-device-interface/pkg/cdi"
"tags.cncf.io/container-device-interface/specs-go"

View File

@@ -22,7 +22,7 @@ import (
"strings"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"tags.cncf.io/container-device-interface/pkg/cdi"
"tags.cncf.io/container-device-interface/specs-go"

View File

@@ -21,7 +21,7 @@ import (
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"tags.cncf.io/container-device-interface/pkg/cdi"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
@@ -197,7 +197,7 @@ func (l *nvcdilib) resolveMode() (rmode string) {
isNvml, reason := l.infolib.HasNvml()
l.logger.Debugf("Is NVML-based system? %v: %v", isNvml, reason)
isTegra, reason := l.infolib.IsTegraSystem()
isTegra, reason := l.infolib.HasTegraFiles()
l.logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason)
if isTegra && !isNvml {

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"testing"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
testlog "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
)
@@ -87,9 +88,15 @@ func TestResolveMode(t *testing.T) {
for i, tc := range testCases {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
l := nvcdilib{
logger: logger,
mode: tc.mode,
infolib: infoMock{hasDXCore: tc.hasDXCore, isTegra: tc.isTegra, hasNVML: tc.hasNVML},
logger: logger,
mode: tc.mode,
infolib: infoMock{
PropertyExtractor: &info.PropertyExtractorMock{
HasDXCoreFunc: func() (bool, string) { return tc.hasDXCore, "" },
HasNvmlFunc: func() (bool, string) { return tc.hasNVML, "" },
HasTegraFilesFunc: func() (bool, string) { return tc.isTegra, "" },
},
},
}
require.Equal(t, tc.expected, l.resolveMode())
@@ -98,19 +105,9 @@ func TestResolveMode(t *testing.T) {
}
type infoMock struct {
hasDXCore bool
isTegra bool
hasNVML bool
info.PropertyExtractor
}
func (i infoMock) HasDXCore() (bool, string) {
return i.hasDXCore, ""
}
func (i infoMock) HasNvml() (bool, string) {
return i.hasNVML, ""
}
func (i infoMock) IsTegraSystem() (bool, string) {
return i.isTegra, ""
func (i infoMock) ResolvePlatform() info.Platform {
return "not-implemented"
}

View File

@@ -20,7 +20,7 @@ import (
"fmt"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"tags.cncf.io/container-device-interface/pkg/cdi"
"tags.cncf.io/container-device-interface/specs-go"

View File

@@ -20,7 +20,7 @@ import (
"errors"
"fmt"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// UUIDer is an interface for getting UUIDs.

View File

@@ -6,7 +6,7 @@ package nvcdi
import (
"sync"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// Ensure, that nvmlUUIDerMock does implement nvmlUUIDer.

View File

@@ -19,7 +19,7 @@ package nvcdi
import (
"testing"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/stretchr/testify/require"
)

View File

@@ -18,7 +18,7 @@ package nvcdi
import (
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"

View File

@@ -1,3 +1,7 @@
FROM quay.io/centos/centos:stream8
RUN sed -i -e "s|mirrorlist=|#mirrorlist=|g" \
-e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" \
/etc/yum.repos.d/CentOS-Stream-*
RUN yum install -y createrepo rpm-sign pinentry

View File

@@ -45,7 +45,7 @@ if [[ $# -ge 2 ]]; then
fi
SHA=$(git rev-parse --short=8 ${REFERENCE})
IMAGE_NAME="registry.gitlab.com/nvidia/container-toolkit/container-toolkit/staging/container-toolkit"
IMAGE_NAME="ghcr.io/nvidia/container-toolkit"
IMAGE_TAG=${SHA}-packaging
: ${VERSION:="$(get_version_from_image ${IMAGE_NAME}:${IMAGE_TAG} ${SHA})"}

View File

@@ -17,10 +17,10 @@
package device
import (
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// Interface provides the API to the 'device' package
// Interface provides the API to the 'device' package.
type Interface interface {
AssertValidMigProfileFormat(profile string) error
GetDevices() ([]Device, error)
@@ -46,7 +46,7 @@ type devicelib struct {
var _ Interface = &devicelib{}
// New creates a new instance of the 'device' interface
// New creates a new instance of the 'device' interface.
func New(opts ...Option) Interface {
d := &devicelib{}
for _, opt := range opts {
@@ -68,21 +68,21 @@ func New(opts ...Option) Interface {
return d
}
// WithNvml provides an Option to set the NVML library used by the 'device' interface
// WithNvml provides an Option to set the NVML library used by the 'device' interface.
func WithNvml(nvml nvml.Interface) Option {
return func(d *devicelib) {
d.nvml = nvml
}
}
// WithVerifySymbols provides an option to toggle whether to verify select symbols exist in dynamic libraries before calling them
// WithVerifySymbols provides an option to toggle whether to verify select symbols exist in dynamic libraries before calling them.
func WithVerifySymbols(verify bool) Option {
return func(d *devicelib) {
d.verifySymbols = &verify
}
}
// WithSkippedDevices provides an Option to set devices to be skipped by model name
// WithSkippedDevices provides an Option to set devices to be skipped by model name.
func WithSkippedDevices(names ...string) Option {
return func(d *devicelib) {
if d.skippedDevices == nil {
@@ -94,5 +94,5 @@ func WithSkippedDevices(names ...string) Option {
}
}
// Option defines a function for passing options to the New() call
// Option defines a function for passing options to the New() call.
type Option func(*devicelib)

View File

@@ -19,10 +19,10 @@ package device
import (
"fmt"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// Device defines the set of extended functions associated with a device.Device
// Device defines the set of extended functions associated with a device.Device.
type Device interface {
nvml.Device
GetArchitectureAsString() (string, error)
@@ -44,12 +44,12 @@ type device struct {
var _ Device = &device{}
// NewDevice builds a new Device from an nvml.Device
// NewDevice builds a new Device from an nvml.Device.
func (d *devicelib) NewDevice(dev nvml.Device) (Device, error) {
return d.newDevice(dev)
}
// NewDeviceByUUID builds a new Device from a UUID
// NewDeviceByUUID builds a new Device from a UUID.
func (d *devicelib) NewDeviceByUUID(uuid string) (Device, error) {
dev, ret := d.nvml.DeviceGetHandleByUUID(uuid)
if ret != nvml.SUCCESS {
@@ -58,12 +58,12 @@ func (d *devicelib) NewDeviceByUUID(uuid string) (Device, error) {
return d.newDevice(dev)
}
// newDevice creates a device from an nvml.Device
// newDevice creates a device from an nvml.Device.
func (d *devicelib) newDevice(dev nvml.Device) (*device, error) {
return &device{dev, d, nil}, nil
}
// GetArchitectureAsString returns the Device architecture as a string
// GetArchitectureAsString returns the Device architecture as a string.
func (d *device) GetArchitectureAsString() (string, error) {
arch, ret := d.GetArchitecture()
if ret != nvml.SUCCESS {
@@ -92,7 +92,7 @@ func (d *device) GetArchitectureAsString() (string, error) {
return "", fmt.Errorf("error interpreting device architecture as string: %v", arch)
}
// GetBrandAsString returns the Device architecture as a string
// GetBrandAsString returns the Device architecture as a string.
func (d *device) GetBrandAsString() (string, error) {
brand, ret := d.GetBrand()
if ret != nvml.SUCCESS {
@@ -140,7 +140,7 @@ func (d *device) GetBrandAsString() (string, error) {
return "", fmt.Errorf("error interpreting device brand as string: %v", brand)
}
// GetCudaComputeCapabilityAsString returns the Device's CUDA compute capability as a version string
// GetCudaComputeCapabilityAsString returns the Device's CUDA compute capability as a version string.
func (d *device) GetCudaComputeCapabilityAsString() (string, error) {
major, minor, ret := d.GetCudaComputeCapability()
if ret != nvml.SUCCESS {
@@ -149,7 +149,7 @@ func (d *device) GetCudaComputeCapabilityAsString() (string, error) {
return fmt.Sprintf("%d.%d", major, minor), nil
}
// IsMigCapable checks if a device is capable of having MIG paprtitions created on it
// IsMigCapable checks if a device is capable of having MIG paprtitions created on it.
func (d *device) IsMigCapable() (bool, error) {
if !d.lib.hasSymbol("nvmlDeviceGetMigMode") {
return false, nil
@@ -166,7 +166,7 @@ func (d *device) IsMigCapable() (bool, error) {
return true, nil
}
// IsMigEnabled checks if a device has MIG mode currently enabled on it
// IsMigEnabled checks if a device has MIG mode currently enabled on it.
func (d *device) IsMigEnabled() (bool, error) {
if !d.lib.hasSymbol("nvmlDeviceGetMigMode") {
return false, nil
@@ -183,7 +183,7 @@ func (d *device) IsMigEnabled() (bool, error) {
return (mode == nvml.DEVICE_MIG_ENABLE), nil
}
// VisitMigDevices walks a top-level device and invokes a callback function for each MIG device configured on it
// VisitMigDevices walks a top-level device and invokes a callback function for each MIG device configured on it.
func (d *device) VisitMigDevices(visit func(int, MigDevice) error) error {
capable, err := d.IsMigCapable()
if err != nil {
@@ -221,7 +221,7 @@ func (d *device) VisitMigDevices(visit func(int, MigDevice) error) error {
return nil
}
// VisitMigProfiles walks a top-level device and invokes a callback function for each unique MIG Profile that can be configured on it
// VisitMigProfiles walks a top-level device and invokes a callback function for each unique MIG Profile that can be configured on it.
func (d *device) VisitMigProfiles(visit func(MigProfile) error) error {
capable, err := d.IsMigCapable()
if err != nil {
@@ -283,7 +283,7 @@ func (d *device) VisitMigProfiles(visit func(MigProfile) error) error {
return nil
}
// GetMigDevices gets the set of MIG devices associated with a top-level device
// GetMigDevices gets the set of MIG devices associated with a top-level device.
func (d *device) GetMigDevices() ([]MigDevice, error) {
var migs []MigDevice
err := d.VisitMigDevices(func(j int, m MigDevice) error {
@@ -296,7 +296,7 @@ func (d *device) GetMigDevices() ([]MigDevice, error) {
return migs, nil
}
// GetMigProfiles gets the set of unique MIG profiles associated with a top-level device
// GetMigProfiles gets the set of unique MIG profiles associated with a top-level device.
func (d *device) GetMigProfiles() ([]MigProfile, error) {
// Return the cached list if available
if d.migProfiles != nil {
@@ -313,7 +313,7 @@ func (d *device) GetMigProfiles() ([]MigProfile, error) {
return nil, err
}
// And cache it before returning
// And cache it before returning.
d.migProfiles = profiles
return profiles, nil
}
@@ -332,7 +332,7 @@ func (d *device) isSkipped() (bool, error) {
return false, nil
}
// VisitDevices visits each top-level device and invokes a callback function for it
// VisitDevices visits each top-level device and invokes a callback function for it.
func (d *devicelib) VisitDevices(visit func(int, Device) error) error {
count, ret := d.nvml.DeviceGetCount()
if ret != nvml.SUCCESS {
@@ -365,7 +365,7 @@ func (d *devicelib) VisitDevices(visit func(int, Device) error) error {
return nil
}
// VisitMigDevices walks a top-level device and invokes a callback function for each MIG device configured on it
// VisitMigDevices walks a top-level device and invokes a callback function for each MIG device configured on it.
func (d *devicelib) VisitMigDevices(visit func(int, Device, int, MigDevice) error) error {
err := d.VisitDevices(func(i int, dev Device) error {
err := dev.VisitMigDevices(func(j int, mig MigDevice) error {
@@ -386,7 +386,7 @@ func (d *devicelib) VisitMigDevices(visit func(int, Device, int, MigDevice) erro
return nil
}
// VisitMigProfiles walks a top-level device and invokes a callback function for each unique MIG profile found on them
// VisitMigProfiles walks a top-level device and invokes a callback function for each unique MIG profile found on them.
func (d *devicelib) VisitMigProfiles(visit func(MigProfile) error) error {
visited := make(map[string]bool)
err := d.VisitDevices(func(i int, dev Device) error {
@@ -414,7 +414,7 @@ func (d *devicelib) VisitMigProfiles(visit func(MigProfile) error) error {
return nil
}
// GetDevices gets the set of all top-level devices
// GetDevices gets the set of all top-level devices.
func (d *devicelib) GetDevices() ([]Device, error) {
var devs []Device
err := d.VisitDevices(func(i int, dev Device) error {
@@ -427,7 +427,7 @@ func (d *devicelib) GetDevices() ([]Device, error) {
return devs, nil
}
// GetMigDevices gets the set of MIG devices across all top-level devices
// GetMigDevices gets the set of MIG devices across all top-level devices.
func (d *devicelib) GetMigDevices() ([]MigDevice, error) {
var migs []MigDevice
err := d.VisitMigDevices(func(i int, dev Device, j int, m MigDevice) error {
@@ -440,7 +440,7 @@ func (d *devicelib) GetMigDevices() ([]MigDevice, error) {
return migs, nil
}
// GetMigProfiles gets the set of unique MIG profiles across all top-level devices
// GetMigProfiles gets the set of unique MIG profiles across all top-level devices.
func (d *devicelib) GetMigProfiles() ([]MigProfile, error) {
// Return the cached list if available
if d.migProfiles != nil {
@@ -457,7 +457,7 @@ func (d *devicelib) GetMigProfiles() ([]MigProfile, error) {
return nil, err
}
// And cache it before returning
// And cache it before returning.
d.migProfiles = profiles
return profiles, nil
}
@@ -469,5 +469,5 @@ func (d *devicelib) hasSymbol(symbol string) bool {
return true
}
return d.nvml.Lookup(symbol) == nil
return d.nvml.Extensions().LookupSymbol(symbol) == nil
}

View File

@@ -27,7 +27,7 @@ import (
// This includes a device index or UUID.
type Identifier string
// IsGpuIndex checks if an identifier is a full GPU index
// IsGpuIndex checks if an identifier is a full GPU index.
func (i Identifier) IsGpuIndex() bool {
if _, err := strconv.ParseUint(string(i), 10, 0); err != nil {
return false
@@ -35,7 +35,7 @@ func (i Identifier) IsGpuIndex() bool {
return true
}
// IsMigIndex checks if an identifier is a MIG index
// IsMigIndex checks if an identifier is a MIG index.
func (i Identifier) IsMigIndex() bool {
split := strings.Split(string(i), ":")
if len(split) != 2 {
@@ -49,13 +49,13 @@ func (i Identifier) IsMigIndex() bool {
return true
}
// IsUUID checks if an identifier is a UUID
// IsUUID checks if an identifier is a UUID.
func (i Identifier) IsUUID() bool {
return i.IsGpuUUID() || i.IsMigUUID()
}
// IsGpuUUID checks if an identifier is a GPU UUID
// A GPU UUID must be of the form GPU-b1028956-cfa2-0990-bf4a-5da9abb51763
// IsGpuUUID checks if an identifier is a GPU UUID.
// A GPU UUID must be of the form GPU-b1028956-cfa2-0990-bf4a-5da9abb51763.
func (i Identifier) IsGpuUUID() bool {
if !strings.HasPrefix(string(i), "GPU-") {
return false
@@ -64,7 +64,7 @@ func (i Identifier) IsGpuUUID() bool {
return err == nil
}
// IsMigUUID checks if an identifier is a MIG UUID
// IsMigUUID checks if an identifier is a MIG UUID.
// A MIG UUID can be of one of two forms:
// - MIG-b1028956-cfa2-0990-bf4a-5da9abb51763
// - MIG-GPU-b1028956-cfa2-0990-bf4a-5da9abb51763/3/0

View File

@@ -19,10 +19,10 @@ package device
import (
"fmt"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// MigDevice defines the set of extended functions associated with a MIG device
// MigDevice defines the set of extended functions associated with a MIG device.
type MigDevice interface {
nvml.Device
GetProfile() (MigProfile, error)
@@ -36,7 +36,7 @@ type migdevice struct {
var _ MigDevice = &migdevice{}
// NewMigDevice builds a new MigDevice from an nvml.Device
// NewMigDevice builds a new MigDevice from an nvml.Device.
func (d *devicelib) NewMigDevice(handle nvml.Device) (MigDevice, error) {
isMig, ret := handle.IsMigDeviceHandle()
if ret != nvml.SUCCESS {
@@ -48,7 +48,7 @@ func (d *devicelib) NewMigDevice(handle nvml.Device) (MigDevice, error) {
return &migdevice{handle, d, nil}, nil
}
// NewMigDeviceByUUID builds a new MigDevice from a UUID
// NewMigDeviceByUUID builds a new MigDevice from a UUID.
func (d *devicelib) NewMigDeviceByUUID(uuid string) (MigDevice, error) {
dev, ret := d.nvml.DeviceGetHandleByUUID(uuid)
if ret != nvml.SUCCESS {
@@ -57,7 +57,7 @@ func (d *devicelib) NewMigDeviceByUUID(uuid string) (MigDevice, error) {
return d.NewMigDevice(dev)
}
// GetProfile returns the MIG profile associated with a MIG device
// GetProfile returns the MIG profile associated with a MIG device.
func (m *migdevice) GetProfile() (MigProfile, error) {
if m.profile != nil {
return m.profile, nil

View File

@@ -23,7 +23,7 @@ import (
"strconv"
"strings"
"github.com/NVIDIA/go-nvlib/pkg/nvml"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
const (
@@ -40,7 +40,7 @@ type MigProfile interface {
Matches(profile string) bool
}
// MigProfileInfo holds all info associated with a specific MIG profile
// MigProfileInfo holds all info associated with a specific MIG profile.
type MigProfileInfo struct {
C int
G int
@@ -119,13 +119,13 @@ func (d *devicelib) NewMigProfile(giProfileID, ciProfileID, ciEngProfileID int,
return p, nil
}
// AssertValidMigProfileFormat checks if the string is in the proper format to represent a MIG profile
// AssertValidMigProfileFormat checks if the string is in the proper format to represent a MIG profile.
func (d *devicelib) AssertValidMigProfileFormat(profile string) error {
_, _, _, _, err := parseMigProfile(profile)
return err
}
// ParseMigProfile converts a string representation of a MigProfile into an object
// ParseMigProfile converts a string representation of a MigProfile into an object.
func (d *devicelib) ParseMigProfile(profile string) (MigProfile, error) {
profiles, err := d.GetMigProfiles()
if err != nil {
@@ -141,7 +141,7 @@ func (d *devicelib) ParseMigProfile(profile string) (MigProfile, error) {
return nil, fmt.Errorf("unable to parse profile string into a valid profile")
}
// String returns the string representation of a Profile
// String returns the string representation of a Profile.
func (p MigProfileInfo) String() string {
var suffix string
if len(p.Attributes) > 0 {
@@ -153,12 +153,12 @@ func (p MigProfileInfo) String() string {
return fmt.Sprintf("%dc.%dg.%dgb%s", p.C, p.G, p.GB, suffix)
}
// GetInfo returns detailed info about a Profile
// GetInfo returns detailed info about a Profile.
func (p MigProfileInfo) GetInfo() MigProfileInfo {
return p
}
// Equals checks if two Profiles are identical or not
// Equals checks if two Profiles are identical or not.
func (p MigProfileInfo) Equals(other MigProfile) bool {
o := other.GetInfo()
if p.C != o.C {
@@ -182,7 +182,7 @@ func (p MigProfileInfo) Equals(other MigProfile) bool {
return true
}
// Matches checks if a MigProfile matches the string passed in
// Matches checks if a MigProfile matches the string passed in.
func (p MigProfileInfo) Matches(profile string) bool {
c, g, gb, attrs, err := parseMigProfile(profile)
if err != nil {
@@ -211,26 +211,26 @@ func (p MigProfileInfo) Matches(profile string) bool {
}
func parseMigProfile(profile string) (int, int, int, []string, error) {
// If we are handed the empty string, we cannot parse it
// If we are handed the empty string, we cannot parse it.
if profile == "" {
return -1, -1, -1, nil, fmt.Errorf("profile is the empty string")
}
// Split by + to separate out attributes
// Split by + to separate out attributes.
split := strings.SplitN(profile, "+", 2)
// Check to make sure the c, g, and gb values match
// Check to make sure the c, g, and gb values match.
c, g, gb, err := parseMigProfileFields(split[0])
if err != nil {
return -1, -1, -1, nil, fmt.Errorf("cannot parse fields of '%v': %v", profile, err)
}
// If we have no attributes we are done
// If we have no attributes we are done.
if len(split) == 1 {
return c, g, gb, nil, nil
}
// Make sure we have the same set of attributes
// Make sure we have the same set of attributes.
attrs, err := parseMigProfileAttributes(split[1])
if err != nil {
return -1, -1, -1, nil, fmt.Errorf("cannot parse attributes of '%v': %v", profile, err)

View File

@@ -0,0 +1,41 @@
/**
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
package info
// Interface provides the API to the info package.
type Interface interface {
PlatformResolver
PropertyExtractor
}
// PlatformResolver defines a function to resolve the current platform.
type PlatformResolver interface {
ResolvePlatform() Platform
}
// PropertyExtractor provides a set of functions to query capabilities of the
// system.
//
//go:generate moq -rm -out property-extractor_mock.go . PropertyExtractor
type PropertyExtractor interface {
HasDXCore() (bool, string)
HasNvml() (bool, string)
HasTegraFiles() (bool, string)
// Deprecated: Use HasTegraFiles instead.
IsTegraSystem() (bool, string)
UsesOnlyNVGPUModule() (bool, string)
}

View File

@@ -0,0 +1,78 @@
/**
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
package info
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
)
type infolib struct {
PropertyExtractor
PlatformResolver
}
type options struct {
logger basicLogger
root root
nvmllib nvml.Interface
devicelib device.Interface
platform Platform
propertyExtractor PropertyExtractor
}
// New creates a new instance of the 'info' interface.
func New(opts ...Option) Interface {
o := &options{}
for _, opt := range opts {
opt(o)
}
if o.logger == nil {
o.logger = &nullLogger{}
}
if o.root == "" {
o.root = "/"
}
if o.nvmllib == nil {
o.nvmllib = nvml.New(
nvml.WithLibraryPath(o.root.tryResolveLibrary("libnvidia-ml.so.1")),
)
}
if o.devicelib == nil {
o.devicelib = device.New(device.WithNvml(o.nvmllib))
}
if o.platform == "" {
o.platform = PlatformAuto
}
if o.propertyExtractor == nil {
o.propertyExtractor = &propertyExtractor{
root: o.root,
nvmllib: o.nvmllib,
devicelib: o.devicelib,
}
}
return &infolib{
PlatformResolver: &platformResolver{
logger: o.logger,
platform: o.platform,
propertyExtractor: o.propertyExtractor,
},
PropertyExtractor: o.propertyExtractor,
}
}

View File

@@ -1,102 +0,0 @@
/**
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
package info
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/NVIDIA/go-nvml/pkg/dl"
)
// Interface provides the API to the info package
type Interface interface {
HasDXCore() (bool, string)
HasNvml() (bool, string)
IsTegraSystem() (bool, string)
}
type infolib struct {
root string
}
var _ Interface = &infolib{}
// HasDXCore returns true if DXCore is detected on the system.
func (i *infolib) HasDXCore() (bool, string) {
const (
libraryName = "libdxcore.so"
)
if err := assertHasLibrary(libraryName); err != nil {
return false, fmt.Sprintf("could not load DXCore library: %v", err)
}
return true, "found DXCore library"
}
// HasNvml returns true if NVML is detected on the system
func (i *infolib) HasNvml() (bool, string) {
const (
libraryName = "libnvidia-ml.so.1"
)
if err := assertHasLibrary(libraryName); err != nil {
return false, fmt.Sprintf("could not load NVML library: %v", err)
}
return true, "found NVML library"
}
// IsTegraSystem returns true if the system is detected as a Tegra-based system
func (i *infolib) IsTegraSystem() (bool, string) {
tegraReleaseFile := filepath.Join(i.root, "/etc/nv_tegra_release")
tegraFamilyFile := filepath.Join(i.root, "/sys/devices/soc0/family")
if info, err := os.Stat(tegraReleaseFile); err == nil && !info.IsDir() {
return true, fmt.Sprintf("%v found", tegraReleaseFile)
}
if info, err := os.Stat(tegraFamilyFile); err != nil || info.IsDir() {
return false, fmt.Sprintf("%v file not found", tegraFamilyFile)
}
contents, err := os.ReadFile(tegraFamilyFile)
if err != nil {
return false, fmt.Sprintf("could not read %v", tegraFamilyFile)
}
if strings.HasPrefix(strings.ToLower(string(contents)), "tegra") {
return true, fmt.Sprintf("%v has 'tegra' prefix", tegraFamilyFile)
}
return false, fmt.Sprintf("%v has no 'tegra' prefix", tegraFamilyFile)
}
// assertHasLibrary returns an error if the specified library cannot be loaded
func assertHasLibrary(libraryName string) error {
const (
libraryLoadFlags = dl.RTLD_LAZY
)
lib := dl.New(libraryName, libraryLoadFlags)
if err := lib.Open(); err != nil {
return err
}
defer lib.Close()
return nil
}

View File

@@ -1,5 +1,5 @@
/**
# Copyright 2023 NVIDIA CORPORATION
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,19 +14,15 @@
# limitations under the License.
**/
package nvml
package info
// options represents the options that could be passed to the nvml contructor.
type options struct {
libraryPath string
type basicLogger interface {
Debugf(string, ...interface{})
Infof(string, ...interface{})
}
// Option represents a functional option to control behaviour.
type Option func(*options)
type nullLogger struct{}
// WithLibraryPath sets the NVML library name to use.
func WithLibraryPath(libraryPath string) Option {
return func(o *options) {
o.libraryPath = libraryPath
}
}
func (n *nullLogger) Debugf(string, ...interface{}) {}
func (n *nullLogger) Infof(string, ...interface{}) {}

View File

@@ -16,24 +16,55 @@
package info
// Option defines a function for passing options to the New() call
type Option func(*infolib)
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
// New creates a new instance of the 'info' interface
func New(opts ...Option) Interface {
i := &infolib{}
for _, opt := range opts {
opt(i)
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
)
// Option defines a function for passing options to the New() call.
type Option func(*options)
// WithDeviceLib sets the device library for the library.
func WithDeviceLib(devicelib device.Interface) Option {
return func(i *options) {
i.devicelib = devicelib
}
if i.root == "" {
i.root = "/"
}
return i
}
// WithRoot provides a Option to set the root of the 'info' interface
func WithRoot(root string) Option {
return func(i *infolib) {
i.root = root
// WithLogger sets the logger for the library.
func WithLogger(logger basicLogger) Option {
return func(i *options) {
i.logger = logger
}
}
// WithNvmlLib sets the nvml library for the library.
func WithNvmlLib(nvmllib nvml.Interface) Option {
return func(i *options) {
i.nvmllib = nvmllib
}
}
// WithRoot provides a Option to set the root of the 'info' interface.
func WithRoot(r string) Option {
return func(i *options) {
i.root = root(r)
}
}
// WithPropertyExtractor provides an Option to set the PropertyExtractor
// interface implementation.
// This is predominantly used for testing.
func WithPropertyExtractor(propertyExtractor PropertyExtractor) Option {
return func(i *options) {
i.propertyExtractor = propertyExtractor
}
}
// WithPlatform provides an option to set the platform explicitly.
func WithPlatform(platform Platform) Option {
return func(i *options) {
i.platform = platform
}
}

View File

@@ -0,0 +1,143 @@
/**
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
package info
import (
"fmt"
"os"
"strings"
"github.com/NVIDIA/go-nvml/pkg/nvml"
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
)
type propertyExtractor struct {
root root
nvmllib nvml.Interface
devicelib device.Interface
}
var _ PropertyExtractor = &propertyExtractor{}
// HasDXCore returns true if DXCore is detected on the system.
func (i *propertyExtractor) HasDXCore() (bool, string) {
const (
libraryName = "libdxcore.so"
)
if err := i.root.assertHasLibrary(libraryName); err != nil {
return false, fmt.Sprintf("could not load DXCore library: %v", err)
}
return true, "found DXCore library"
}
// HasNvml returns true if NVML is detected on the system.
func (i *propertyExtractor) HasNvml() (bool, string) {
const (
libraryName = "libnvidia-ml.so.1"
)
if err := i.root.assertHasLibrary(libraryName); err != nil {
return false, fmt.Sprintf("could not load NVML library: %v", err)
}
return true, "found NVML library"
}
// IsTegraSystem returns true if the system is detected as a Tegra-based system.
// Deprecated: Use HasTegraFiles instead.
func (i *propertyExtractor) IsTegraSystem() (bool, string) {
return i.HasTegraFiles()
}
// HasTegraFiles returns true if tegra-based files are detected on the system.
func (i *propertyExtractor) HasTegraFiles() (bool, string) {
tegraReleaseFile := i.root.join("/etc/nv_tegra_release")
tegraFamilyFile := i.root.join("/sys/devices/soc0/family")
if info, err := os.Stat(tegraReleaseFile); err == nil && !info.IsDir() {
return true, fmt.Sprintf("%v found", tegraReleaseFile)
}
if info, err := os.Stat(tegraFamilyFile); err != nil || info.IsDir() {
return false, fmt.Sprintf("%v file not found", tegraFamilyFile)
}
contents, err := os.ReadFile(tegraFamilyFile)
if err != nil {
return false, fmt.Sprintf("could not read %v", tegraFamilyFile)
}
if strings.HasPrefix(strings.ToLower(string(contents)), "tegra") {
return true, fmt.Sprintf("%v has 'tegra' prefix", tegraFamilyFile)
}
return false, fmt.Sprintf("%v has no 'tegra' prefix", tegraFamilyFile)
}
// UsesOnlyNVGPUModule checks whether the only the nvgpu module is used.
// This kernel module is used on Tegra-based systems when using the iGPU.
// Since some of these systems also support NVML, we use the device name
// reported by NVML to determine whether the system is an iGPU system.
//
// Devices that use the nvgpu module have their device names as:
//
// GPU 0: Orin (nvgpu) (UUID: 54d0709b-558d-5a59-9c65-0c5fc14a21a4)
//
// This function returns true if ALL devices use the nvgpu module.
func (i *propertyExtractor) UsesOnlyNVGPUModule() (uses bool, reason string) {
// We ensure that this function never panics
defer func() {
if err := recover(); err != nil {
uses = false
reason = fmt.Sprintf("panic: %v", err)
}
}()
ret := i.nvmllib.Init()
if ret != nvml.SUCCESS {
return false, fmt.Sprintf("failed to initialize nvml: %v", ret)
}
defer func() {
_ = i.nvmllib.Shutdown()
}()
var names []string
err := i.devicelib.VisitDevices(func(i int, d device.Device) error {
name, ret := d.GetName()
if ret != nvml.SUCCESS {
return fmt.Errorf("device %v: %v", i, ret)
}
names = append(names, name)
return nil
})
if err != nil {
return false, fmt.Sprintf("failed to get device names: %v", err)
}
if len(names) == 0 {
return false, "no devices found"
}
for _, name := range names {
if !strings.Contains(name, "(nvgpu)") {
return false, fmt.Sprintf("device %q does not use nvgpu module", name)
}
}
return true, "all devices use nvgpu module"
}

View File

@@ -0,0 +1,215 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package info
import (
"sync"
)
// Ensure, that PropertyExtractorMock does implement PropertyExtractor.
// If this is not the case, regenerate this file with moq.
var _ PropertyExtractor = &PropertyExtractorMock{}
// PropertyExtractorMock is a mock implementation of PropertyExtractor.
//
// func TestSomethingThatUsesPropertyExtractor(t *testing.T) {
//
// // make and configure a mocked PropertyExtractor
// mockedPropertyExtractor := &PropertyExtractorMock{
// HasDXCoreFunc: func() (bool, string) {
// panic("mock out the HasDXCore method")
// },
// HasNvmlFunc: func() (bool, string) {
// panic("mock out the HasNvml method")
// },
// HasTegraFilesFunc: func() (bool, string) {
// panic("mock out the HasTegraFiles method")
// },
// IsTegraSystemFunc: func() (bool, string) {
// panic("mock out the IsTegraSystem method")
// },
// UsesOnlyNVGPUModuleFunc: func() (bool, string) {
// panic("mock out the UsesOnlyNVGPUModule method")
// },
// }
//
// // use mockedPropertyExtractor in code that requires PropertyExtractor
// // and then make assertions.
//
// }
type PropertyExtractorMock struct {
// HasDXCoreFunc mocks the HasDXCore method.
HasDXCoreFunc func() (bool, string)
// HasNvmlFunc mocks the HasNvml method.
HasNvmlFunc func() (bool, string)
// HasTegraFilesFunc mocks the HasTegraFiles method.
HasTegraFilesFunc func() (bool, string)
// IsTegraSystemFunc mocks the IsTegraSystem method.
IsTegraSystemFunc func() (bool, string)
// UsesOnlyNVGPUModuleFunc mocks the UsesOnlyNVGPUModule method.
UsesOnlyNVGPUModuleFunc func() (bool, string)
// calls tracks calls to the methods.
calls struct {
// HasDXCore holds details about calls to the HasDXCore method.
HasDXCore []struct {
}
// HasNvml holds details about calls to the HasNvml method.
HasNvml []struct {
}
// HasTegraFiles holds details about calls to the HasTegraFiles method.
HasTegraFiles []struct {
}
// IsTegraSystem holds details about calls to the IsTegraSystem method.
IsTegraSystem []struct {
}
// UsesOnlyNVGPUModule holds details about calls to the UsesOnlyNVGPUModule method.
UsesOnlyNVGPUModule []struct {
}
}
lockHasDXCore sync.RWMutex
lockHasNvml sync.RWMutex
lockHasTegraFiles sync.RWMutex
lockIsTegraSystem sync.RWMutex
lockUsesOnlyNVGPUModule sync.RWMutex
}
// HasDXCore calls HasDXCoreFunc.
func (mock *PropertyExtractorMock) HasDXCore() (bool, string) {
if mock.HasDXCoreFunc == nil {
panic("PropertyExtractorMock.HasDXCoreFunc: method is nil but PropertyExtractor.HasDXCore was just called")
}
callInfo := struct {
}{}
mock.lockHasDXCore.Lock()
mock.calls.HasDXCore = append(mock.calls.HasDXCore, callInfo)
mock.lockHasDXCore.Unlock()
return mock.HasDXCoreFunc()
}
// HasDXCoreCalls gets all the calls that were made to HasDXCore.
// Check the length with:
//
// len(mockedPropertyExtractor.HasDXCoreCalls())
func (mock *PropertyExtractorMock) HasDXCoreCalls() []struct {
} {
var calls []struct {
}
mock.lockHasDXCore.RLock()
calls = mock.calls.HasDXCore
mock.lockHasDXCore.RUnlock()
return calls
}
// HasNvml calls HasNvmlFunc.
func (mock *PropertyExtractorMock) HasNvml() (bool, string) {
if mock.HasNvmlFunc == nil {
panic("PropertyExtractorMock.HasNvmlFunc: method is nil but PropertyExtractor.HasNvml was just called")
}
callInfo := struct {
}{}
mock.lockHasNvml.Lock()
mock.calls.HasNvml = append(mock.calls.HasNvml, callInfo)
mock.lockHasNvml.Unlock()
return mock.HasNvmlFunc()
}
// HasNvmlCalls gets all the calls that were made to HasNvml.
// Check the length with:
//
// len(mockedPropertyExtractor.HasNvmlCalls())
func (mock *PropertyExtractorMock) HasNvmlCalls() []struct {
} {
var calls []struct {
}
mock.lockHasNvml.RLock()
calls = mock.calls.HasNvml
mock.lockHasNvml.RUnlock()
return calls
}
// HasTegraFiles calls HasTegraFilesFunc.
func (mock *PropertyExtractorMock) HasTegraFiles() (bool, string) {
if mock.HasTegraFilesFunc == nil {
panic("PropertyExtractorMock.HasTegraFilesFunc: method is nil but PropertyExtractor.HasTegraFiles was just called")
}
callInfo := struct {
}{}
mock.lockHasTegraFiles.Lock()
mock.calls.HasTegraFiles = append(mock.calls.HasTegraFiles, callInfo)
mock.lockHasTegraFiles.Unlock()
return mock.HasTegraFilesFunc()
}
// HasTegraFilesCalls gets all the calls that were made to HasTegraFiles.
// Check the length with:
//
// len(mockedPropertyExtractor.HasTegraFilesCalls())
func (mock *PropertyExtractorMock) HasTegraFilesCalls() []struct {
} {
var calls []struct {
}
mock.lockHasTegraFiles.RLock()
calls = mock.calls.HasTegraFiles
mock.lockHasTegraFiles.RUnlock()
return calls
}
// IsTegraSystem calls IsTegraSystemFunc.
func (mock *PropertyExtractorMock) IsTegraSystem() (bool, string) {
if mock.IsTegraSystemFunc == nil {
panic("PropertyExtractorMock.IsTegraSystemFunc: method is nil but PropertyExtractor.IsTegraSystem was just called")
}
callInfo := struct {
}{}
mock.lockIsTegraSystem.Lock()
mock.calls.IsTegraSystem = append(mock.calls.IsTegraSystem, callInfo)
mock.lockIsTegraSystem.Unlock()
return mock.IsTegraSystemFunc()
}
// IsTegraSystemCalls gets all the calls that were made to IsTegraSystem.
// Check the length with:
//
// len(mockedPropertyExtractor.IsTegraSystemCalls())
func (mock *PropertyExtractorMock) IsTegraSystemCalls() []struct {
} {
var calls []struct {
}
mock.lockIsTegraSystem.RLock()
calls = mock.calls.IsTegraSystem
mock.lockIsTegraSystem.RUnlock()
return calls
}
// UsesOnlyNVGPUModule calls UsesOnlyNVGPUModuleFunc.
func (mock *PropertyExtractorMock) UsesOnlyNVGPUModule() (bool, string) {
if mock.UsesOnlyNVGPUModuleFunc == nil {
panic("PropertyExtractorMock.UsesOnlyNVGPUModuleFunc: method is nil but PropertyExtractor.UsesOnlyNVGPUModule was just called")
}
callInfo := struct {
}{}
mock.lockUsesOnlyNVGPUModule.Lock()
mock.calls.UsesOnlyNVGPUModule = append(mock.calls.UsesOnlyNVGPUModule, callInfo)
mock.lockUsesOnlyNVGPUModule.Unlock()
return mock.UsesOnlyNVGPUModuleFunc()
}
// UsesOnlyNVGPUModuleCalls gets all the calls that were made to UsesOnlyNVGPUModule.
// Check the length with:
//
// len(mockedPropertyExtractor.UsesOnlyNVGPUModuleCalls())
func (mock *PropertyExtractorMock) UsesOnlyNVGPUModuleCalls() []struct {
} {
var calls []struct {
}
mock.lockUsesOnlyNVGPUModule.RLock()
calls = mock.calls.UsesOnlyNVGPUModule
mock.lockUsesOnlyNVGPUModule.RUnlock()
return calls
}

View File

@@ -0,0 +1,64 @@
/**
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
package info
// Platform represents a supported plaform.
type Platform string
const (
PlatformAuto = Platform("auto")
PlatformNVML = Platform("nvml")
PlatformTegra = Platform("tegra")
PlatformWSL = Platform("wsl")
PlatformUnknown = Platform("unknown")
)
type platformResolver struct {
logger basicLogger
platform Platform
propertyExtractor PropertyExtractor
}
func (p platformResolver) ResolvePlatform() Platform {
if p.platform != PlatformAuto {
p.logger.Infof("Using requested platform '%s'", p.platform)
return p.platform
}
hasDXCore, reason := p.propertyExtractor.HasDXCore()
p.logger.Debugf("Is WSL-based system? %v: %v", hasDXCore, reason)
hasTegraFiles, reason := p.propertyExtractor.HasTegraFiles()
p.logger.Debugf("Is Tegra-based system? %v: %v", hasTegraFiles, reason)
hasNVML, reason := p.propertyExtractor.HasNvml()
p.logger.Debugf("Is NVML-based system? %v: %v", hasNVML, reason)
usesOnlyNVGPUModule, reason := p.propertyExtractor.UsesOnlyNVGPUModule()
p.logger.Debugf("Uses nvgpu kernel module? %v: %v", usesOnlyNVGPUModule, reason)
switch {
case hasDXCore:
return PlatformWSL
case (hasTegraFiles && !hasNVML), usesOnlyNVGPUModule:
return PlatformTegra
case hasNVML:
return PlatformNVML
default:
return PlatformUnknown
}
}

View File

@@ -0,0 +1,86 @@
/**
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
package info
import (
"fmt"
"path/filepath"
"github.com/NVIDIA/go-nvml/pkg/dl"
)
// root represents a directory on the filesystem relative to which libraries
// such as the NVIDIA driver libraries can be found.
type root string
func (r root) join(parts ...string) string {
return filepath.Join(append([]string{string(r)}, parts...)...)
}
// assertHasLibrary returns an error if the specified library cannot be loaded.
func (r root) assertHasLibrary(libraryName string) error {
const (
libraryLoadFlags = dl.RTLD_LAZY
)
lib := dl.New(r.tryResolveLibrary(libraryName), libraryLoadFlags)
if err := lib.Open(); err != nil {
return err
}
defer lib.Close()
return nil
}
// tryResolveLibrary attempts to locate the specified library in the root.
// If the root is not specified, is "/", or the library cannot be found in the
// set of predefined paths, the input is returned as is.
func (r root) tryResolveLibrary(libraryName string) string {
if r == "" || r == "/" {
return libraryName
}
librarySearchPaths := []string{
"/usr/lib64",
"/usr/lib/x86_64-linux-gnu",
"/usr/lib/aarch64-linux-gnu",
"/lib64",
"/lib/x86_64-linux-gnu",
"/lib/aarch64-linux-gnu",
}
for _, d := range librarySearchPaths {
l := r.join(d, libraryName)
resolved, err := resolveLink(l)
if err != nil {
continue
}
return resolved
}
return libraryName
}
// resolveLink finds the target of a symlink or the file itself in the
// case of a regular file.
// This is equivalent to running `readlink -f ${l}`.
func resolveLink(l string) (string, error) {
resolved, err := filepath.EvalSymlinks(l)
if err != nil {
return "", fmt.Errorf("error resolving link '%v': %w", l, err)
}
return resolved, nil
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
package nvml
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
type nvmlComputeInstance nvml.ComputeInstance
var _ ComputeInstance = (*nvmlComputeInstance)(nil)
// GetInfo() returns info about a Compute Instance
func (ci nvmlComputeInstance) GetInfo() (ComputeInstanceInfo, Return) {
i, r := nvml.ComputeInstance(ci).GetInfo()
info := ComputeInstanceInfo{
Device: nvmlDevice(i.Device),
GpuInstance: nvmlGpuInstance(i.GpuInstance),
Id: i.Id,
ProfileId: i.ProfileId,
Placement: ComputeInstancePlacement(i.Placement),
}
return info, Return(r)
}
// Destroy() destroys a Compute Instance
func (ci nvmlComputeInstance) Destroy() Return {
r := nvml.ComputeInstance(ci).Destroy()
return Return(r)
}

View File

@@ -1,163 +0,0 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
package nvml
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// General untyped constants
const (
NVLINK_MAX_LINKS = nvml.NVLINK_MAX_LINKS
)
// Return constants
const (
SUCCESS = Return(nvml.SUCCESS)
ERROR_UNINITIALIZED = Return(nvml.ERROR_UNINITIALIZED)
ERROR_INVALID_ARGUMENT = Return(nvml.ERROR_INVALID_ARGUMENT)
ERROR_NOT_SUPPORTED = Return(nvml.ERROR_NOT_SUPPORTED)
ERROR_NO_PERMISSION = Return(nvml.ERROR_NO_PERMISSION)
ERROR_ALREADY_INITIALIZED = Return(nvml.ERROR_ALREADY_INITIALIZED)
ERROR_NOT_FOUND = Return(nvml.ERROR_NOT_FOUND)
ERROR_INSUFFICIENT_SIZE = Return(nvml.ERROR_INSUFFICIENT_SIZE)
ERROR_INSUFFICIENT_POWER = Return(nvml.ERROR_INSUFFICIENT_POWER)
ERROR_DRIVER_NOT_LOADED = Return(nvml.ERROR_DRIVER_NOT_LOADED)
ERROR_TIMEOUT = Return(nvml.ERROR_TIMEOUT)
ERROR_IRQ_ISSUE = Return(nvml.ERROR_IRQ_ISSUE)
ERROR_LIBRARY_NOT_FOUND = Return(nvml.ERROR_LIBRARY_NOT_FOUND)
ERROR_FUNCTION_NOT_FOUND = Return(nvml.ERROR_FUNCTION_NOT_FOUND)
ERROR_CORRUPTED_INFOROM = Return(nvml.ERROR_CORRUPTED_INFOROM)
ERROR_GPU_IS_LOST = Return(nvml.ERROR_GPU_IS_LOST)
ERROR_RESET_REQUIRED = Return(nvml.ERROR_RESET_REQUIRED)
ERROR_OPERATING_SYSTEM = Return(nvml.ERROR_OPERATING_SYSTEM)
ERROR_LIB_RM_VERSION_MISMATCH = Return(nvml.ERROR_LIB_RM_VERSION_MISMATCH)
ERROR_IN_USE = Return(nvml.ERROR_IN_USE)
ERROR_MEMORY = Return(nvml.ERROR_MEMORY)
ERROR_NO_DATA = Return(nvml.ERROR_NO_DATA)
ERROR_VGPU_ECC_NOT_SUPPORTED = Return(nvml.ERROR_VGPU_ECC_NOT_SUPPORTED)
ERROR_INSUFFICIENT_RESOURCES = Return(nvml.ERROR_INSUFFICIENT_RESOURCES)
ERROR_UNKNOWN = Return(nvml.ERROR_UNKNOWN)
)
// Device architecture constants
const (
DEVICE_ARCH_KEPLER = nvml.DEVICE_ARCH_KEPLER
DEVICE_ARCH_MAXWELL = nvml.DEVICE_ARCH_MAXWELL
DEVICE_ARCH_PASCAL = nvml.DEVICE_ARCH_PASCAL
DEVICE_ARCH_VOLTA = nvml.DEVICE_ARCH_VOLTA
DEVICE_ARCH_TURING = nvml.DEVICE_ARCH_TURING
DEVICE_ARCH_AMPERE = nvml.DEVICE_ARCH_AMPERE
DEVICE_ARCH_ADA = nvml.DEVICE_ARCH_ADA
DEVICE_ARCH_HOPPER = nvml.DEVICE_ARCH_HOPPER
DEVICE_ARCH_UNKNOWN = nvml.DEVICE_ARCH_UNKNOWN
)
// Device brand constants
const (
BRAND_UNKNOWN = BrandType(nvml.BRAND_UNKNOWN)
BRAND_QUADRO = BrandType(nvml.BRAND_QUADRO)
BRAND_TESLA = BrandType(nvml.BRAND_TESLA)
BRAND_NVS = BrandType(nvml.BRAND_NVS)
BRAND_GRID = BrandType(nvml.BRAND_GRID)
BRAND_GEFORCE = BrandType(nvml.BRAND_GEFORCE)
BRAND_TITAN = BrandType(nvml.BRAND_TITAN)
BRAND_NVIDIA_VAPPS = BrandType(nvml.BRAND_NVIDIA_VAPPS)
BRAND_NVIDIA_VPC = BrandType(nvml.BRAND_NVIDIA_VPC)
BRAND_NVIDIA_VCS = BrandType(nvml.BRAND_NVIDIA_VCS)
BRAND_NVIDIA_VWS = BrandType(nvml.BRAND_NVIDIA_VWS)
BRAND_NVIDIA_CLOUD_GAMING = BrandType(nvml.BRAND_NVIDIA_CLOUD_GAMING)
BRAND_NVIDIA_VGAMING = BrandType(nvml.BRAND_NVIDIA_VGAMING)
BRAND_QUADRO_RTX = BrandType(nvml.BRAND_QUADRO_RTX)
BRAND_NVIDIA_RTX = BrandType(nvml.BRAND_NVIDIA_RTX)
BRAND_NVIDIA = BrandType(nvml.BRAND_NVIDIA)
BRAND_GEFORCE_RTX = BrandType(nvml.BRAND_GEFORCE_RTX)
BRAND_TITAN_RTX = BrandType(nvml.BRAND_TITAN_RTX)
BRAND_COUNT = BrandType(nvml.BRAND_COUNT)
)
// MIG Mode constants
const (
DEVICE_MIG_ENABLE = nvml.DEVICE_MIG_ENABLE
DEVICE_MIG_DISABLE = nvml.DEVICE_MIG_DISABLE
)
// GPU Instance Profiles
const (
GPU_INSTANCE_PROFILE_1_SLICE = nvml.GPU_INSTANCE_PROFILE_1_SLICE
GPU_INSTANCE_PROFILE_2_SLICE = nvml.GPU_INSTANCE_PROFILE_2_SLICE
GPU_INSTANCE_PROFILE_3_SLICE = nvml.GPU_INSTANCE_PROFILE_3_SLICE
GPU_INSTANCE_PROFILE_4_SLICE = nvml.GPU_INSTANCE_PROFILE_4_SLICE
GPU_INSTANCE_PROFILE_6_SLICE = nvml.GPU_INSTANCE_PROFILE_6_SLICE
GPU_INSTANCE_PROFILE_7_SLICE = nvml.GPU_INSTANCE_PROFILE_7_SLICE
GPU_INSTANCE_PROFILE_8_SLICE = nvml.GPU_INSTANCE_PROFILE_8_SLICE
GPU_INSTANCE_PROFILE_1_SLICE_REV1 = nvml.GPU_INSTANCE_PROFILE_1_SLICE_REV1
GPU_INSTANCE_PROFILE_1_SLICE_REV2 = nvml.GPU_INSTANCE_PROFILE_1_SLICE_REV2
GPU_INSTANCE_PROFILE_2_SLICE_REV1 = nvml.GPU_INSTANCE_PROFILE_2_SLICE_REV1
GPU_INSTANCE_PROFILE_COUNT = nvml.GPU_INSTANCE_PROFILE_COUNT
)
// Compute Instance Profiles
const (
COMPUTE_INSTANCE_PROFILE_1_SLICE = nvml.COMPUTE_INSTANCE_PROFILE_1_SLICE
COMPUTE_INSTANCE_PROFILE_2_SLICE = nvml.COMPUTE_INSTANCE_PROFILE_2_SLICE
COMPUTE_INSTANCE_PROFILE_3_SLICE = nvml.COMPUTE_INSTANCE_PROFILE_3_SLICE
COMPUTE_INSTANCE_PROFILE_4_SLICE = nvml.COMPUTE_INSTANCE_PROFILE_4_SLICE
COMPUTE_INSTANCE_PROFILE_6_SLICE = nvml.COMPUTE_INSTANCE_PROFILE_6_SLICE
COMPUTE_INSTANCE_PROFILE_7_SLICE = nvml.COMPUTE_INSTANCE_PROFILE_7_SLICE
COMPUTE_INSTANCE_PROFILE_8_SLICE = nvml.COMPUTE_INSTANCE_PROFILE_8_SLICE
COMPUTE_INSTANCE_PROFILE_1_SLICE_REV1 = nvml.COMPUTE_INSTANCE_PROFILE_1_SLICE_REV1
COMPUTE_INSTANCE_PROFILE_COUNT = nvml.COMPUTE_INSTANCE_PROFILE_COUNT
)
// Compute Instance Engine Profiles
const (
COMPUTE_INSTANCE_ENGINE_PROFILE_SHARED = nvml.COMPUTE_INSTANCE_ENGINE_PROFILE_SHARED
COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT = nvml.COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT
)
// Event Types
const (
EventTypeXidCriticalError = nvml.EventTypeXidCriticalError
EventTypeSingleBitEccError = nvml.EventTypeSingleBitEccError
EventTypeDoubleBitEccError = nvml.EventTypeDoubleBitEccError
)
// GPU Topology enumeration
const (
TOPOLOGY_INTERNAL = GpuTopologyLevel(nvml.TOPOLOGY_INTERNAL)
TOPOLOGY_SINGLE = GpuTopologyLevel(nvml.TOPOLOGY_SINGLE)
TOPOLOGY_MULTIPLE = GpuTopologyLevel(nvml.TOPOLOGY_MULTIPLE)
TOPOLOGY_HOSTBRIDGE = GpuTopologyLevel(nvml.TOPOLOGY_HOSTBRIDGE)
TOPOLOGY_NODE = GpuTopologyLevel(nvml.TOPOLOGY_NODE)
TOPOLOGY_SYSTEM = GpuTopologyLevel(nvml.TOPOLOGY_SYSTEM)
)
// Generic enable/disable constants
const (
FEATURE_DISABLED = EnableState(nvml.FEATURE_DISABLED)
FEATURE_ENABLED = EnableState(nvml.FEATURE_ENABLED)
)
// Compute mode constants
const (
COMPUTEMODE_DEFAULT = ComputeMode(nvml.COMPUTEMODE_DEFAULT)
COMPUTEMODE_EXCLUSIVE_THREAD = ComputeMode(nvml.COMPUTEMODE_EXCLUSIVE_THREAD)
COMPUTEMODE_PROHIBITED = ComputeMode(nvml.COMPUTEMODE_PROHIBITED)
COMPUTEMODE_EXCLUSIVE_PROCESS = ComputeMode(nvml.COMPUTEMODE_EXCLUSIVE_PROCESS)
COMPUTEMODE_COUNT = ComputeMode(nvml.COMPUTEMODE_COUNT)
)

View File

@@ -1,215 +0,0 @@
/**
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
package nvml
import "github.com/NVIDIA/go-nvml/pkg/nvml"
type nvmlDevice nvml.Device
var _ Device = (*nvmlDevice)(nil)
// nvmlDeviceHandle returns a pointer to the underlying device.
func (d nvmlDevice) nvmlDeviceHandle() *nvml.Device {
return (*nvml.Device)(&d)
}
// GetIndex returns the index of a Device
func (d nvmlDevice) GetIndex() (int, Return) {
i, r := nvml.Device(d).GetIndex()
return i, Return(r)
}
// GetPciInfo returns the PCI info of a Device
func (d nvmlDevice) GetPciInfo() (PciInfo, Return) {
p, r := nvml.Device(d).GetPciInfo()
return PciInfo(p), Return(r)
}
// GetMemoryInfo returns the memory info of a Device
func (d nvmlDevice) GetMemoryInfo() (Memory, Return) {
p, r := nvml.Device(d).GetMemoryInfo()
return Memory(p), Return(r)
}
// GetUUID returns the UUID of a Device
func (d nvmlDevice) GetUUID() (string, Return) {
u, r := nvml.Device(d).GetUUID()
return u, Return(r)
}
// GetMinorNumber returns the minor number of a Device
func (d nvmlDevice) GetMinorNumber() (int, Return) {
m, r := nvml.Device(d).GetMinorNumber()
return m, Return(r)
}
// IsMigDeviceHandle returns whether a Device is a MIG device or not
func (d nvmlDevice) IsMigDeviceHandle() (bool, Return) {
b, r := nvml.Device(d).IsMigDeviceHandle()
return b, Return(r)
}
// GetDeviceHandleFromMigDeviceHandle returns the parent Device of a MIG device
func (d nvmlDevice) GetDeviceHandleFromMigDeviceHandle() (Device, Return) {
p, r := nvml.Device(d).GetDeviceHandleFromMigDeviceHandle()
return nvmlDevice(p), Return(r)
}
// SetMigMode sets the MIG mode of a Device
func (d nvmlDevice) SetMigMode(mode int) (Return, Return) {
r1, r2 := nvml.Device(d).SetMigMode(mode)
return Return(r1), Return(r2)
}
// GetMigMode returns the MIG mode of a Device
func (d nvmlDevice) GetMigMode() (int, int, Return) {
s1, s2, r := nvml.Device(d).GetMigMode()
return s1, s2, Return(r)
}
// GetGpuInstanceById returns the GPU Instance associated with a particular ID
func (d nvmlDevice) GetGpuInstanceById(id int) (GpuInstance, Return) {
gi, r := nvml.Device(d).GetGpuInstanceById(id)
return nvmlGpuInstance(gi), Return(r)
}
// GetGpuInstanceProfileInfo returns the profile info of a GPU Instance
func (d nvmlDevice) GetGpuInstanceProfileInfo(profile int) (GpuInstanceProfileInfo, Return) {
p, r := nvml.Device(d).GetGpuInstanceProfileInfo(profile)
return GpuInstanceProfileInfo(p), Return(r)
}
// GetGpuInstancePossiblePlacements returns the possible placements of a GPU Instance
func (d nvmlDevice) GetGpuInstancePossiblePlacements(info *GpuInstanceProfileInfo) ([]GpuInstancePlacement, Return) {
nvmlPlacements, r := nvml.Device(d).GetGpuInstancePossiblePlacements((*nvml.GpuInstanceProfileInfo)(info))
var placements []GpuInstancePlacement
for _, p := range nvmlPlacements {
placements = append(placements, GpuInstancePlacement(p))
}
return placements, Return(r)
}
// GetGpuInstances returns the set of GPU Instances associated with a Device
func (d nvmlDevice) GetGpuInstances(info *GpuInstanceProfileInfo) ([]GpuInstance, Return) {
nvmlGis, r := nvml.Device(d).GetGpuInstances((*nvml.GpuInstanceProfileInfo)(info))
var gis []GpuInstance
for _, gi := range nvmlGis {
gis = append(gis, nvmlGpuInstance(gi))
}
return gis, Return(r)
}
// CreateGpuInstanceWithPlacement creates a GPU Instance with a specific placement
func (d nvmlDevice) CreateGpuInstanceWithPlacement(info *GpuInstanceProfileInfo, placement *GpuInstancePlacement) (GpuInstance, Return) {
gi, r := nvml.Device(d).CreateGpuInstanceWithPlacement((*nvml.GpuInstanceProfileInfo)(info), (*nvml.GpuInstancePlacement)(placement))
return nvmlGpuInstance(gi), Return(r)
}
// GetMaxMigDeviceCount returns the maximum number of MIG devices that can be created on a Device
func (d nvmlDevice) GetMaxMigDeviceCount() (int, Return) {
m, r := nvml.Device(d).GetMaxMigDeviceCount()
return m, Return(r)
}
// GetMigDeviceHandleByIndex returns the handle to a MIG device given its index
func (d nvmlDevice) GetMigDeviceHandleByIndex(Index int) (Device, Return) {
h, r := nvml.Device(d).GetMigDeviceHandleByIndex(Index)
return nvmlDevice(h), Return(r)
}
// GetGpuInstanceId returns the GPU Instance ID of a MIG device
func (d nvmlDevice) GetGpuInstanceId() (int, Return) {
gi, r := nvml.Device(d).GetGpuInstanceId()
return gi, Return(r)
}
// GetComputeInstanceId returns the Compute Instance ID of a MIG device
func (d nvmlDevice) GetComputeInstanceId() (int, Return) {
ci, r := nvml.Device(d).GetComputeInstanceId()
return ci, Return(r)
}
// GetCudaComputeCapability returns the compute capability major and minor versions for a device
func (d nvmlDevice) GetCudaComputeCapability() (int, int, Return) {
major, minor, r := nvml.Device(d).GetCudaComputeCapability()
return major, minor, Return(r)
}
// GetAttributes returns the device attributes for a MIG device
func (d nvmlDevice) GetAttributes() (DeviceAttributes, Return) {
a, r := nvml.Device(d).GetAttributes()
return DeviceAttributes(a), Return(r)
}
// GetName returns the product name of a Device
func (d nvmlDevice) GetName() (string, Return) {
n, r := nvml.Device(d).GetName()
return n, Return(r)
}
// GetBrand returns the brand of a Device
func (d nvmlDevice) GetBrand() (BrandType, Return) {
b, r := nvml.Device(d).GetBrand()
return BrandType(b), Return(r)
}
// GetArchitecture returns the architecture of a Device
func (d nvmlDevice) GetArchitecture() (DeviceArchitecture, Return) {
a, r := nvml.Device(d).GetArchitecture()
return DeviceArchitecture(a), Return(r)
}
// RegisterEvents registers the specified event set and type with the device
func (d nvmlDevice) RegisterEvents(EventTypes uint64, Set EventSet) Return {
return Return(nvml.Device(d).RegisterEvents(EventTypes, nvml.EventSet(Set)))
}
// GetSupportedEventTypes returns the events supported by the device
func (d nvmlDevice) GetSupportedEventTypes() (uint64, Return) {
e, r := nvml.Device(d).GetSupportedEventTypes()
return e, Return(r)
}
// GetTopologyCommonAncestor retrieves the common ancestor for two devices.
func (d nvmlDevice) GetTopologyCommonAncestor(o Device) (GpuTopologyLevel, Return) {
other := o.nvmlDeviceHandle()
if other == nil {
return 0, ERROR_INVALID_ARGUMENT
}
l, r := nvml.Device(d).GetTopologyCommonAncestor(*other)
return GpuTopologyLevel(l), Return(r)
}
// GetNvLinkState retrieves the state of the device's NvLink for the link specified.
func (d nvmlDevice) GetNvLinkState(link int) (EnableState, Return) {
s, r := nvml.Device(d).GetNvLinkState(link)
return EnableState(s), Return(r)
}
// GetNvLinkRemotePciInfo retrieves the PCI information for the remote node on a NvLink link.
// Note: pciSubSystemId is not filled in this function and is indeterminate.
func (d nvmlDevice) GetNvLinkRemotePciInfo(link int) (PciInfo, Return) {
p, r := nvml.Device(d).GetNvLinkRemotePciInfo(link)
return PciInfo(p), Return(r)
}
// SetComputeMode sets the compute mode for the device.
func (d nvmlDevice) SetComputeMode(mode ComputeMode) Return {
r := nvml.Device(d).SetComputeMode(nvml.ComputeMode(mode))
return Return(r)
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,39 +0,0 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
package nvml
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// Wait watches for an event with the specified timeout
func (e EventSet) Wait(Timeoutms uint32) (EventData, Return) {
d, r := nvml.EventSet(e).Wait(Timeoutms)
eventData := EventData{
Device: nvmlDevice(d.Device),
EventType: d.EventType,
EventData: d.EventData,
GpuInstanceId: d.GpuInstanceId,
ComputeInstanceId: d.ComputeInstanceId,
}
return eventData, Return(r)
}
// Free deletes the event set
func (e EventSet) Free() Return {
return Return(nvml.EventSet(e).Free())
}

View File

@@ -1,71 +0,0 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
package nvml
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
type nvmlGpuInstance nvml.GpuInstance
var _ GpuInstance = (*nvmlGpuInstance)(nil)
// GetInfo returns info about a GPU Intsance
func (gi nvmlGpuInstance) GetInfo() (GpuInstanceInfo, Return) {
i, r := nvml.GpuInstance(gi).GetInfo()
info := GpuInstanceInfo{
Device: nvmlDevice(i.Device),
Id: i.Id,
ProfileId: i.ProfileId,
Placement: GpuInstancePlacement(i.Placement),
}
return info, Return(r)
}
// GetComputeInstanceById returns the Compute Instance associated with a particular ID.
func (gi nvmlGpuInstance) GetComputeInstanceById(id int) (ComputeInstance, Return) {
ci, r := nvml.GpuInstance(gi).GetComputeInstanceById(id)
return nvmlComputeInstance(ci), Return(r)
}
// GetComputeInstanceProfileInfo returns info about a given Compute Instance profile
func (gi nvmlGpuInstance) GetComputeInstanceProfileInfo(profile int, engProfile int) (ComputeInstanceProfileInfo, Return) {
p, r := nvml.GpuInstance(gi).GetComputeInstanceProfileInfo(profile, engProfile)
return ComputeInstanceProfileInfo(p), Return(r)
}
// CreateComputeInstance creates a Compute Instance within the GPU Instance
func (gi nvmlGpuInstance) CreateComputeInstance(info *ComputeInstanceProfileInfo) (ComputeInstance, Return) {
ci, r := nvml.GpuInstance(gi).CreateComputeInstance((*nvml.ComputeInstanceProfileInfo)(info))
return nvmlComputeInstance(ci), Return(r)
}
// GetComputeInstances returns the set of Compute Instances associated with a GPU Instance
func (gi nvmlGpuInstance) GetComputeInstances(info *ComputeInstanceProfileInfo) ([]ComputeInstance, Return) {
nvmlCis, r := nvml.GpuInstance(gi).GetComputeInstances((*nvml.ComputeInstanceProfileInfo)(info))
var cis []ComputeInstance
for _, ci := range nvmlCis {
cis = append(cis, nvmlComputeInstance(ci))
}
return cis, Return(r)
}
// Destroy destroys a GPU Instance
func (gi nvmlGpuInstance) Destroy() Return {
r := nvml.GpuInstance(gi).Destroy()
return Return(r)
}

View File

@@ -1,286 +0,0 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package nvml
import (
"sync"
)
// Ensure, that GpuInstanceMock does implement GpuInstance.
// If this is not the case, regenerate this file with moq.
var _ GpuInstance = &GpuInstanceMock{}
// GpuInstanceMock is a mock implementation of GpuInstance.
//
// func TestSomethingThatUsesGpuInstance(t *testing.T) {
//
// // make and configure a mocked GpuInstance
// mockedGpuInstance := &GpuInstanceMock{
// CreateComputeInstanceFunc: func(Info *ComputeInstanceProfileInfo) (ComputeInstance, Return) {
// panic("mock out the CreateComputeInstance method")
// },
// DestroyFunc: func() Return {
// panic("mock out the Destroy method")
// },
// GetComputeInstanceByIdFunc: func(ID int) (ComputeInstance, Return) {
// panic("mock out the GetComputeInstanceById method")
// },
// GetComputeInstanceProfileInfoFunc: func(Profile int, EngProfile int) (ComputeInstanceProfileInfo, Return) {
// panic("mock out the GetComputeInstanceProfileInfo method")
// },
// GetComputeInstancesFunc: func(Info *ComputeInstanceProfileInfo) ([]ComputeInstance, Return) {
// panic("mock out the GetComputeInstances method")
// },
// GetInfoFunc: func() (GpuInstanceInfo, Return) {
// panic("mock out the GetInfo method")
// },
// }
//
// // use mockedGpuInstance in code that requires GpuInstance
// // and then make assertions.
//
// }
type GpuInstanceMock struct {
// CreateComputeInstanceFunc mocks the CreateComputeInstance method.
CreateComputeInstanceFunc func(Info *ComputeInstanceProfileInfo) (ComputeInstance, Return)
// DestroyFunc mocks the Destroy method.
DestroyFunc func() Return
// GetComputeInstanceByIdFunc mocks the GetComputeInstanceById method.
GetComputeInstanceByIdFunc func(ID int) (ComputeInstance, Return)
// GetComputeInstanceProfileInfoFunc mocks the GetComputeInstanceProfileInfo method.
GetComputeInstanceProfileInfoFunc func(Profile int, EngProfile int) (ComputeInstanceProfileInfo, Return)
// GetComputeInstancesFunc mocks the GetComputeInstances method.
GetComputeInstancesFunc func(Info *ComputeInstanceProfileInfo) ([]ComputeInstance, Return)
// GetInfoFunc mocks the GetInfo method.
GetInfoFunc func() (GpuInstanceInfo, Return)
// calls tracks calls to the methods.
calls struct {
// CreateComputeInstance holds details about calls to the CreateComputeInstance method.
CreateComputeInstance []struct {
// Info is the Info argument value.
Info *ComputeInstanceProfileInfo
}
// Destroy holds details about calls to the Destroy method.
Destroy []struct {
}
// GetComputeInstanceById holds details about calls to the GetComputeInstanceById method.
GetComputeInstanceById []struct {
// ID is the ID argument value.
ID int
}
// GetComputeInstanceProfileInfo holds details about calls to the GetComputeInstanceProfileInfo method.
GetComputeInstanceProfileInfo []struct {
// Profile is the Profile argument value.
Profile int
// EngProfile is the EngProfile argument value.
EngProfile int
}
// GetComputeInstances holds details about calls to the GetComputeInstances method.
GetComputeInstances []struct {
// Info is the Info argument value.
Info *ComputeInstanceProfileInfo
}
// GetInfo holds details about calls to the GetInfo method.
GetInfo []struct {
}
}
lockCreateComputeInstance sync.RWMutex
lockDestroy sync.RWMutex
lockGetComputeInstanceById sync.RWMutex
lockGetComputeInstanceProfileInfo sync.RWMutex
lockGetComputeInstances sync.RWMutex
lockGetInfo sync.RWMutex
}
// CreateComputeInstance calls CreateComputeInstanceFunc.
func (mock *GpuInstanceMock) CreateComputeInstance(Info *ComputeInstanceProfileInfo) (ComputeInstance, Return) {
if mock.CreateComputeInstanceFunc == nil {
panic("GpuInstanceMock.CreateComputeInstanceFunc: method is nil but GpuInstance.CreateComputeInstance was just called")
}
callInfo := struct {
Info *ComputeInstanceProfileInfo
}{
Info: Info,
}
mock.lockCreateComputeInstance.Lock()
mock.calls.CreateComputeInstance = append(mock.calls.CreateComputeInstance, callInfo)
mock.lockCreateComputeInstance.Unlock()
return mock.CreateComputeInstanceFunc(Info)
}
// CreateComputeInstanceCalls gets all the calls that were made to CreateComputeInstance.
// Check the length with:
//
// len(mockedGpuInstance.CreateComputeInstanceCalls())
func (mock *GpuInstanceMock) CreateComputeInstanceCalls() []struct {
Info *ComputeInstanceProfileInfo
} {
var calls []struct {
Info *ComputeInstanceProfileInfo
}
mock.lockCreateComputeInstance.RLock()
calls = mock.calls.CreateComputeInstance
mock.lockCreateComputeInstance.RUnlock()
return calls
}
// Destroy calls DestroyFunc.
func (mock *GpuInstanceMock) Destroy() Return {
if mock.DestroyFunc == nil {
panic("GpuInstanceMock.DestroyFunc: method is nil but GpuInstance.Destroy was just called")
}
callInfo := struct {
}{}
mock.lockDestroy.Lock()
mock.calls.Destroy = append(mock.calls.Destroy, callInfo)
mock.lockDestroy.Unlock()
return mock.DestroyFunc()
}
// DestroyCalls gets all the calls that were made to Destroy.
// Check the length with:
//
// len(mockedGpuInstance.DestroyCalls())
func (mock *GpuInstanceMock) DestroyCalls() []struct {
} {
var calls []struct {
}
mock.lockDestroy.RLock()
calls = mock.calls.Destroy
mock.lockDestroy.RUnlock()
return calls
}
// GetComputeInstanceById calls GetComputeInstanceByIdFunc.
func (mock *GpuInstanceMock) GetComputeInstanceById(ID int) (ComputeInstance, Return) {
if mock.GetComputeInstanceByIdFunc == nil {
panic("GpuInstanceMock.GetComputeInstanceByIdFunc: method is nil but GpuInstance.GetComputeInstanceById was just called")
}
callInfo := struct {
ID int
}{
ID: ID,
}
mock.lockGetComputeInstanceById.Lock()
mock.calls.GetComputeInstanceById = append(mock.calls.GetComputeInstanceById, callInfo)
mock.lockGetComputeInstanceById.Unlock()
return mock.GetComputeInstanceByIdFunc(ID)
}
// GetComputeInstanceByIdCalls gets all the calls that were made to GetComputeInstanceById.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstanceByIdCalls())
func (mock *GpuInstanceMock) GetComputeInstanceByIdCalls() []struct {
ID int
} {
var calls []struct {
ID int
}
mock.lockGetComputeInstanceById.RLock()
calls = mock.calls.GetComputeInstanceById
mock.lockGetComputeInstanceById.RUnlock()
return calls
}
// GetComputeInstanceProfileInfo calls GetComputeInstanceProfileInfoFunc.
func (mock *GpuInstanceMock) GetComputeInstanceProfileInfo(Profile int, EngProfile int) (ComputeInstanceProfileInfo, Return) {
if mock.GetComputeInstanceProfileInfoFunc == nil {
panic("GpuInstanceMock.GetComputeInstanceProfileInfoFunc: method is nil but GpuInstance.GetComputeInstanceProfileInfo was just called")
}
callInfo := struct {
Profile int
EngProfile int
}{
Profile: Profile,
EngProfile: EngProfile,
}
mock.lockGetComputeInstanceProfileInfo.Lock()
mock.calls.GetComputeInstanceProfileInfo = append(mock.calls.GetComputeInstanceProfileInfo, callInfo)
mock.lockGetComputeInstanceProfileInfo.Unlock()
return mock.GetComputeInstanceProfileInfoFunc(Profile, EngProfile)
}
// GetComputeInstanceProfileInfoCalls gets all the calls that were made to GetComputeInstanceProfileInfo.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstanceProfileInfoCalls())
func (mock *GpuInstanceMock) GetComputeInstanceProfileInfoCalls() []struct {
Profile int
EngProfile int
} {
var calls []struct {
Profile int
EngProfile int
}
mock.lockGetComputeInstanceProfileInfo.RLock()
calls = mock.calls.GetComputeInstanceProfileInfo
mock.lockGetComputeInstanceProfileInfo.RUnlock()
return calls
}
// GetComputeInstances calls GetComputeInstancesFunc.
func (mock *GpuInstanceMock) GetComputeInstances(Info *ComputeInstanceProfileInfo) ([]ComputeInstance, Return) {
if mock.GetComputeInstancesFunc == nil {
panic("GpuInstanceMock.GetComputeInstancesFunc: method is nil but GpuInstance.GetComputeInstances was just called")
}
callInfo := struct {
Info *ComputeInstanceProfileInfo
}{
Info: Info,
}
mock.lockGetComputeInstances.Lock()
mock.calls.GetComputeInstances = append(mock.calls.GetComputeInstances, callInfo)
mock.lockGetComputeInstances.Unlock()
return mock.GetComputeInstancesFunc(Info)
}
// GetComputeInstancesCalls gets all the calls that were made to GetComputeInstances.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstancesCalls())
func (mock *GpuInstanceMock) GetComputeInstancesCalls() []struct {
Info *ComputeInstanceProfileInfo
} {
var calls []struct {
Info *ComputeInstanceProfileInfo
}
mock.lockGetComputeInstances.RLock()
calls = mock.calls.GetComputeInstances
mock.lockGetComputeInstances.RUnlock()
return calls
}
// GetInfo calls GetInfoFunc.
func (mock *GpuInstanceMock) GetInfo() (GpuInstanceInfo, Return) {
if mock.GetInfoFunc == nil {
panic("GpuInstanceMock.GetInfoFunc: method is nil but GpuInstance.GetInfo was just called")
}
callInfo := struct {
}{}
mock.lockGetInfo.Lock()
mock.calls.GetInfo = append(mock.calls.GetInfo, callInfo)
mock.lockGetInfo.Unlock()
return mock.GetInfoFunc()
}
// GetInfoCalls gets all the calls that were made to GetInfo.
// Check the length with:
//
// len(mockedGpuInstance.GetInfoCalls())
func (mock *GpuInstanceMock) GetInfoCalls() []struct {
} {
var calls []struct {
}
mock.lockGetInfo.RLock()
calls = mock.calls.GetInfo
mock.lockGetInfo.RUnlock()
return calls
}

View File

@@ -1,127 +0,0 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
package nvml
import (
"sync"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
type nvmlLib struct {
sync.Mutex
refcount int
}
var _ Interface = (*nvmlLib)(nil)
// New creates a new instance of the NVML Interface
func New(opts ...Option) Interface {
o := &options{}
for _, opt := range opts {
opt(o)
}
var nvmlOptions []nvml.LibraryOption
if o.libraryPath != "" {
nvmlOptions = append(nvmlOptions, nvml.WithLibraryPath(o.libraryPath))
}
nvml.SetLibraryOptions(nvmlOptions...)
return &nvmlLib{}
}
// Lookup checks whether the specified symbol exists in the configured NVML library.
func (n *nvmlLib) Lookup(name string) error {
// TODO: For now we rely on the default NVML library and perform the lookups against this.
return nvml.GetLibrary().Lookup(name)
}
// Init initializes an NVML Interface
func (n *nvmlLib) Init() Return {
ret := nvml.Init()
if ret != nvml.SUCCESS {
return Return(ret)
}
n.Lock()
defer n.Unlock()
if n.refcount == 0 {
errorStringFunc = nvml.ErrorString
}
n.refcount++
return SUCCESS
}
// Shutdown shuts down an NVML Interface
func (n *nvmlLib) Shutdown() Return {
ret := nvml.Shutdown()
if ret != nvml.SUCCESS {
return Return(ret)
}
n.Lock()
defer n.Unlock()
n.refcount--
if n.refcount == 0 {
errorStringFunc = defaultErrorStringFunc
}
return SUCCESS
}
// DeviceGetCount returns the total number of GPU Devices
func (n *nvmlLib) DeviceGetCount() (int, Return) {
c, r := nvml.DeviceGetCount()
return c, Return(r)
}
// DeviceGetHandleByIndex returns a Device handle given its index
func (n *nvmlLib) DeviceGetHandleByIndex(index int) (Device, Return) {
d, r := nvml.DeviceGetHandleByIndex(index)
return nvmlDevice(d), Return(r)
}
// DeviceGetHandleByUUID returns a Device handle given its UUID
func (n *nvmlLib) DeviceGetHandleByUUID(uuid string) (Device, Return) {
d, r := nvml.DeviceGetHandleByUUID(uuid)
return nvmlDevice(d), Return(r)
}
// SystemGetDriverVersion returns the version of the installed NVIDIA driver
func (n *nvmlLib) SystemGetDriverVersion() (string, Return) {
v, r := nvml.SystemGetDriverVersion()
return v, Return(r)
}
// SystemGetCudaDriverVersion returns the version of CUDA associated with the NVIDIA driver
func (n *nvmlLib) SystemGetCudaDriverVersion() (int, Return) {
v, r := nvml.SystemGetCudaDriverVersion()
return v, Return(r)
}
// ErrorString returns the error string associated with a given return value
func (n *nvmlLib) ErrorString(ret Return) string {
return nvml.ErrorString(nvml.Return(ret))
}
// EventSetCreate creates an event set
func (n *nvmlLib) EventSetCreate() (EventSet, Return) {
e, r := nvml.EventSetCreate()
return EventSet(e), Return(r)
}

View File

@@ -1,428 +0,0 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package nvml
import (
"sync"
)
// Ensure, that InterfaceMock does implement Interface.
// If this is not the case, regenerate this file with moq.
var _ Interface = &InterfaceMock{}
// InterfaceMock is a mock implementation of Interface.
//
// func TestSomethingThatUsesInterface(t *testing.T) {
//
// // make and configure a mocked Interface
// mockedInterface := &InterfaceMock{
// DeviceGetCountFunc: func() (int, Return) {
// panic("mock out the DeviceGetCount method")
// },
// DeviceGetHandleByIndexFunc: func(Index int) (Device, Return) {
// panic("mock out the DeviceGetHandleByIndex method")
// },
// DeviceGetHandleByUUIDFunc: func(UUID string) (Device, Return) {
// panic("mock out the DeviceGetHandleByUUID method")
// },
// ErrorStringFunc: func(r Return) string {
// panic("mock out the ErrorString method")
// },
// EventSetCreateFunc: func() (EventSet, Return) {
// panic("mock out the EventSetCreate method")
// },
// InitFunc: func() Return {
// panic("mock out the Init method")
// },
// LookupFunc: func(s string) error {
// panic("mock out the Lookup method")
// },
// ShutdownFunc: func() Return {
// panic("mock out the Shutdown method")
// },
// SystemGetCudaDriverVersionFunc: func() (int, Return) {
// panic("mock out the SystemGetCudaDriverVersion method")
// },
// SystemGetDriverVersionFunc: func() (string, Return) {
// panic("mock out the SystemGetDriverVersion method")
// },
// }
//
// // use mockedInterface in code that requires Interface
// // and then make assertions.
//
// }
type InterfaceMock struct {
// DeviceGetCountFunc mocks the DeviceGetCount method.
DeviceGetCountFunc func() (int, Return)
// DeviceGetHandleByIndexFunc mocks the DeviceGetHandleByIndex method.
DeviceGetHandleByIndexFunc func(Index int) (Device, Return)
// DeviceGetHandleByUUIDFunc mocks the DeviceGetHandleByUUID method.
DeviceGetHandleByUUIDFunc func(UUID string) (Device, Return)
// ErrorStringFunc mocks the ErrorString method.
ErrorStringFunc func(r Return) string
// EventSetCreateFunc mocks the EventSetCreate method.
EventSetCreateFunc func() (EventSet, Return)
// InitFunc mocks the Init method.
InitFunc func() Return
// LookupFunc mocks the Lookup method.
LookupFunc func(s string) error
// ShutdownFunc mocks the Shutdown method.
ShutdownFunc func() Return
// SystemGetCudaDriverVersionFunc mocks the SystemGetCudaDriverVersion method.
SystemGetCudaDriverVersionFunc func() (int, Return)
// SystemGetDriverVersionFunc mocks the SystemGetDriverVersion method.
SystemGetDriverVersionFunc func() (string, Return)
// calls tracks calls to the methods.
calls struct {
// DeviceGetCount holds details about calls to the DeviceGetCount method.
DeviceGetCount []struct {
}
// DeviceGetHandleByIndex holds details about calls to the DeviceGetHandleByIndex method.
DeviceGetHandleByIndex []struct {
// Index is the Index argument value.
Index int
}
// DeviceGetHandleByUUID holds details about calls to the DeviceGetHandleByUUID method.
DeviceGetHandleByUUID []struct {
// UUID is the UUID argument value.
UUID string
}
// ErrorString holds details about calls to the ErrorString method.
ErrorString []struct {
// R is the r argument value.
R Return
}
// EventSetCreate holds details about calls to the EventSetCreate method.
EventSetCreate []struct {
}
// Init holds details about calls to the Init method.
Init []struct {
}
// Lookup holds details about calls to the Lookup method.
Lookup []struct {
// S is the s argument value.
S string
}
// Shutdown holds details about calls to the Shutdown method.
Shutdown []struct {
}
// SystemGetCudaDriverVersion holds details about calls to the SystemGetCudaDriverVersion method.
SystemGetCudaDriverVersion []struct {
}
// SystemGetDriverVersion holds details about calls to the SystemGetDriverVersion method.
SystemGetDriverVersion []struct {
}
}
lockDeviceGetCount sync.RWMutex
lockDeviceGetHandleByIndex sync.RWMutex
lockDeviceGetHandleByUUID sync.RWMutex
lockErrorString sync.RWMutex
lockEventSetCreate sync.RWMutex
lockInit sync.RWMutex
lockLookup sync.RWMutex
lockShutdown sync.RWMutex
lockSystemGetCudaDriverVersion sync.RWMutex
lockSystemGetDriverVersion sync.RWMutex
}
// DeviceGetCount calls DeviceGetCountFunc.
func (mock *InterfaceMock) DeviceGetCount() (int, Return) {
if mock.DeviceGetCountFunc == nil {
panic("InterfaceMock.DeviceGetCountFunc: method is nil but Interface.DeviceGetCount was just called")
}
callInfo := struct {
}{}
mock.lockDeviceGetCount.Lock()
mock.calls.DeviceGetCount = append(mock.calls.DeviceGetCount, callInfo)
mock.lockDeviceGetCount.Unlock()
return mock.DeviceGetCountFunc()
}
// DeviceGetCountCalls gets all the calls that were made to DeviceGetCount.
// Check the length with:
//
// len(mockedInterface.DeviceGetCountCalls())
func (mock *InterfaceMock) DeviceGetCountCalls() []struct {
} {
var calls []struct {
}
mock.lockDeviceGetCount.RLock()
calls = mock.calls.DeviceGetCount
mock.lockDeviceGetCount.RUnlock()
return calls
}
// DeviceGetHandleByIndex calls DeviceGetHandleByIndexFunc.
func (mock *InterfaceMock) DeviceGetHandleByIndex(Index int) (Device, Return) {
if mock.DeviceGetHandleByIndexFunc == nil {
panic("InterfaceMock.DeviceGetHandleByIndexFunc: method is nil but Interface.DeviceGetHandleByIndex was just called")
}
callInfo := struct {
Index int
}{
Index: Index,
}
mock.lockDeviceGetHandleByIndex.Lock()
mock.calls.DeviceGetHandleByIndex = append(mock.calls.DeviceGetHandleByIndex, callInfo)
mock.lockDeviceGetHandleByIndex.Unlock()
return mock.DeviceGetHandleByIndexFunc(Index)
}
// DeviceGetHandleByIndexCalls gets all the calls that were made to DeviceGetHandleByIndex.
// Check the length with:
//
// len(mockedInterface.DeviceGetHandleByIndexCalls())
func (mock *InterfaceMock) DeviceGetHandleByIndexCalls() []struct {
Index int
} {
var calls []struct {
Index int
}
mock.lockDeviceGetHandleByIndex.RLock()
calls = mock.calls.DeviceGetHandleByIndex
mock.lockDeviceGetHandleByIndex.RUnlock()
return calls
}
// DeviceGetHandleByUUID calls DeviceGetHandleByUUIDFunc.
func (mock *InterfaceMock) DeviceGetHandleByUUID(UUID string) (Device, Return) {
if mock.DeviceGetHandleByUUIDFunc == nil {
panic("InterfaceMock.DeviceGetHandleByUUIDFunc: method is nil but Interface.DeviceGetHandleByUUID was just called")
}
callInfo := struct {
UUID string
}{
UUID: UUID,
}
mock.lockDeviceGetHandleByUUID.Lock()
mock.calls.DeviceGetHandleByUUID = append(mock.calls.DeviceGetHandleByUUID, callInfo)
mock.lockDeviceGetHandleByUUID.Unlock()
return mock.DeviceGetHandleByUUIDFunc(UUID)
}
// DeviceGetHandleByUUIDCalls gets all the calls that were made to DeviceGetHandleByUUID.
// Check the length with:
//
// len(mockedInterface.DeviceGetHandleByUUIDCalls())
func (mock *InterfaceMock) DeviceGetHandleByUUIDCalls() []struct {
UUID string
} {
var calls []struct {
UUID string
}
mock.lockDeviceGetHandleByUUID.RLock()
calls = mock.calls.DeviceGetHandleByUUID
mock.lockDeviceGetHandleByUUID.RUnlock()
return calls
}
// ErrorString calls ErrorStringFunc.
func (mock *InterfaceMock) ErrorString(r Return) string {
if mock.ErrorStringFunc == nil {
panic("InterfaceMock.ErrorStringFunc: method is nil but Interface.ErrorString was just called")
}
callInfo := struct {
R Return
}{
R: r,
}
mock.lockErrorString.Lock()
mock.calls.ErrorString = append(mock.calls.ErrorString, callInfo)
mock.lockErrorString.Unlock()
return mock.ErrorStringFunc(r)
}
// ErrorStringCalls gets all the calls that were made to ErrorString.
// Check the length with:
//
// len(mockedInterface.ErrorStringCalls())
func (mock *InterfaceMock) ErrorStringCalls() []struct {
R Return
} {
var calls []struct {
R Return
}
mock.lockErrorString.RLock()
calls = mock.calls.ErrorString
mock.lockErrorString.RUnlock()
return calls
}
// EventSetCreate calls EventSetCreateFunc.
func (mock *InterfaceMock) EventSetCreate() (EventSet, Return) {
if mock.EventSetCreateFunc == nil {
panic("InterfaceMock.EventSetCreateFunc: method is nil but Interface.EventSetCreate was just called")
}
callInfo := struct {
}{}
mock.lockEventSetCreate.Lock()
mock.calls.EventSetCreate = append(mock.calls.EventSetCreate, callInfo)
mock.lockEventSetCreate.Unlock()
return mock.EventSetCreateFunc()
}
// EventSetCreateCalls gets all the calls that were made to EventSetCreate.
// Check the length with:
//
// len(mockedInterface.EventSetCreateCalls())
func (mock *InterfaceMock) EventSetCreateCalls() []struct {
} {
var calls []struct {
}
mock.lockEventSetCreate.RLock()
calls = mock.calls.EventSetCreate
mock.lockEventSetCreate.RUnlock()
return calls
}
// Init calls InitFunc.
func (mock *InterfaceMock) Init() Return {
if mock.InitFunc == nil {
panic("InterfaceMock.InitFunc: method is nil but Interface.Init was just called")
}
callInfo := struct {
}{}
mock.lockInit.Lock()
mock.calls.Init = append(mock.calls.Init, callInfo)
mock.lockInit.Unlock()
return mock.InitFunc()
}
// InitCalls gets all the calls that were made to Init.
// Check the length with:
//
// len(mockedInterface.InitCalls())
func (mock *InterfaceMock) InitCalls() []struct {
} {
var calls []struct {
}
mock.lockInit.RLock()
calls = mock.calls.Init
mock.lockInit.RUnlock()
return calls
}
// Lookup calls LookupFunc.
func (mock *InterfaceMock) Lookup(s string) error {
if mock.LookupFunc == nil {
panic("InterfaceMock.LookupFunc: method is nil but Interface.Lookup was just called")
}
callInfo := struct {
S string
}{
S: s,
}
mock.lockLookup.Lock()
mock.calls.Lookup = append(mock.calls.Lookup, callInfo)
mock.lockLookup.Unlock()
return mock.LookupFunc(s)
}
// LookupCalls gets all the calls that were made to Lookup.
// Check the length with:
//
// len(mockedInterface.LookupCalls())
func (mock *InterfaceMock) LookupCalls() []struct {
S string
} {
var calls []struct {
S string
}
mock.lockLookup.RLock()
calls = mock.calls.Lookup
mock.lockLookup.RUnlock()
return calls
}
// Shutdown calls ShutdownFunc.
func (mock *InterfaceMock) Shutdown() Return {
if mock.ShutdownFunc == nil {
panic("InterfaceMock.ShutdownFunc: method is nil but Interface.Shutdown was just called")
}
callInfo := struct {
}{}
mock.lockShutdown.Lock()
mock.calls.Shutdown = append(mock.calls.Shutdown, callInfo)
mock.lockShutdown.Unlock()
return mock.ShutdownFunc()
}
// ShutdownCalls gets all the calls that were made to Shutdown.
// Check the length with:
//
// len(mockedInterface.ShutdownCalls())
func (mock *InterfaceMock) ShutdownCalls() []struct {
} {
var calls []struct {
}
mock.lockShutdown.RLock()
calls = mock.calls.Shutdown
mock.lockShutdown.RUnlock()
return calls
}
// SystemGetCudaDriverVersion calls SystemGetCudaDriverVersionFunc.
func (mock *InterfaceMock) SystemGetCudaDriverVersion() (int, Return) {
if mock.SystemGetCudaDriverVersionFunc == nil {
panic("InterfaceMock.SystemGetCudaDriverVersionFunc: method is nil but Interface.SystemGetCudaDriverVersion was just called")
}
callInfo := struct {
}{}
mock.lockSystemGetCudaDriverVersion.Lock()
mock.calls.SystemGetCudaDriverVersion = append(mock.calls.SystemGetCudaDriverVersion, callInfo)
mock.lockSystemGetCudaDriverVersion.Unlock()
return mock.SystemGetCudaDriverVersionFunc()
}
// SystemGetCudaDriverVersionCalls gets all the calls that were made to SystemGetCudaDriverVersion.
// Check the length with:
//
// len(mockedInterface.SystemGetCudaDriverVersionCalls())
func (mock *InterfaceMock) SystemGetCudaDriverVersionCalls() []struct {
} {
var calls []struct {
}
mock.lockSystemGetCudaDriverVersion.RLock()
calls = mock.calls.SystemGetCudaDriverVersion
mock.lockSystemGetCudaDriverVersion.RUnlock()
return calls
}
// SystemGetDriverVersion calls SystemGetDriverVersionFunc.
func (mock *InterfaceMock) SystemGetDriverVersion() (string, Return) {
if mock.SystemGetDriverVersionFunc == nil {
panic("InterfaceMock.SystemGetDriverVersionFunc: method is nil but Interface.SystemGetDriverVersion was just called")
}
callInfo := struct {
}{}
mock.lockSystemGetDriverVersion.Lock()
mock.calls.SystemGetDriverVersion = append(mock.calls.SystemGetDriverVersion, callInfo)
mock.lockSystemGetDriverVersion.Unlock()
return mock.SystemGetDriverVersionFunc()
}
// SystemGetDriverVersionCalls gets all the calls that were made to SystemGetDriverVersion.
// Check the length with:
//
// len(mockedInterface.SystemGetDriverVersionCalls())
func (mock *InterfaceMock) SystemGetDriverVersionCalls() []struct {
} {
var calls []struct {
}
mock.lockSystemGetDriverVersion.RLock()
calls = mock.calls.SystemGetDriverVersion
mock.lockSystemGetDriverVersion.RUnlock()
return calls
}

View File

@@ -1,93 +0,0 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
package nvml
import (
"fmt"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// String returns the string representation of a Return
func (r Return) String() string {
return errorStringFunc(nvml.Return(r))
}
// Error returns the string representation of a Return
func (r Return) Error() string {
return errorStringFunc(nvml.Return(r))
}
// Assigned to nvml.ErrorString if the system nvml library is in use
var errorStringFunc = defaultErrorStringFunc
var defaultErrorStringFunc = func(r nvml.Return) string {
switch Return(r) {
case SUCCESS:
return "SUCCESS"
case ERROR_UNINITIALIZED:
return "ERROR_UNINITIALIZED"
case ERROR_INVALID_ARGUMENT:
return "ERROR_INVALID_ARGUMENT"
case ERROR_NOT_SUPPORTED:
return "ERROR_NOT_SUPPORTED"
case ERROR_NO_PERMISSION:
return "ERROR_NO_PERMISSION"
case ERROR_ALREADY_INITIALIZED:
return "ERROR_ALREADY_INITIALIZED"
case ERROR_NOT_FOUND:
return "ERROR_NOT_FOUND"
case ERROR_INSUFFICIENT_SIZE:
return "ERROR_INSUFFICIENT_SIZE"
case ERROR_INSUFFICIENT_POWER:
return "ERROR_INSUFFICIENT_POWER"
case ERROR_DRIVER_NOT_LOADED:
return "ERROR_DRIVER_NOT_LOADED"
case ERROR_TIMEOUT:
return "ERROR_TIMEOUT"
case ERROR_IRQ_ISSUE:
return "ERROR_IRQ_ISSUE"
case ERROR_LIBRARY_NOT_FOUND:
return "ERROR_LIBRARY_NOT_FOUND"
case ERROR_FUNCTION_NOT_FOUND:
return "ERROR_FUNCTION_NOT_FOUND"
case ERROR_CORRUPTED_INFOROM:
return "ERROR_CORRUPTED_INFOROM"
case ERROR_GPU_IS_LOST:
return "ERROR_GPU_IS_LOST"
case ERROR_RESET_REQUIRED:
return "ERROR_RESET_REQUIRED"
case ERROR_OPERATING_SYSTEM:
return "ERROR_OPERATING_SYSTEM"
case ERROR_LIB_RM_VERSION_MISMATCH:
return "ERROR_LIB_RM_VERSION_MISMATCH"
case ERROR_IN_USE:
return "ERROR_IN_USE"
case ERROR_MEMORY:
return "ERROR_MEMORY"
case ERROR_NO_DATA:
return "ERROR_NO_DATA"
case ERROR_VGPU_ECC_NOT_SUPPORTED:
return "ERROR_VGPU_ECC_NOT_SUPPORTED"
case ERROR_INSUFFICIENT_RESOURCES:
return "ERROR_INSUFFICIENT_RESOURCES"
case ERROR_UNKNOWN:
return "ERROR_UNKNOWN"
default:
return fmt.Sprintf("Unknown return value: %d", r)
}
}

View File

@@ -1,162 +0,0 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
package nvml
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
// Interface defines the functions implemented by an NVML library
//
//go:generate moq -out nvml_mock.go . Interface
type Interface interface {
DeviceGetCount() (int, Return)
DeviceGetHandleByIndex(Index int) (Device, Return)
DeviceGetHandleByUUID(UUID string) (Device, Return)
ErrorString(r Return) string
EventSetCreate() (EventSet, Return)
Init() Return
Lookup(string) error
Shutdown() Return
SystemGetCudaDriverVersion() (int, Return)
SystemGetDriverVersion() (string, Return)
}
// Device defines the functions implemented by an NVML device
//
//go:generate moq -out device_mock.go . Device
type Device interface {
CreateGpuInstanceWithPlacement(*GpuInstanceProfileInfo, *GpuInstancePlacement) (GpuInstance, Return)
GetArchitecture() (DeviceArchitecture, Return)
GetAttributes() (DeviceAttributes, Return)
GetBrand() (BrandType, Return)
GetComputeInstanceId() (int, Return)
GetCudaComputeCapability() (int, int, Return)
GetDeviceHandleFromMigDeviceHandle() (Device, Return)
GetGpuInstanceById(ID int) (GpuInstance, Return)
GetGpuInstanceId() (int, Return)
GetGpuInstancePossiblePlacements(*GpuInstanceProfileInfo) ([]GpuInstancePlacement, Return)
GetGpuInstanceProfileInfo(Profile int) (GpuInstanceProfileInfo, Return)
GetGpuInstances(Info *GpuInstanceProfileInfo) ([]GpuInstance, Return)
GetIndex() (int, Return)
GetMaxMigDeviceCount() (int, Return)
GetMemoryInfo() (Memory, Return)
GetMigDeviceHandleByIndex(Index int) (Device, Return)
GetMigMode() (int, int, Return)
GetMinorNumber() (int, Return)
GetName() (string, Return)
GetNvLinkRemotePciInfo(int) (PciInfo, Return)
GetNvLinkState(int) (EnableState, Return)
GetPciInfo() (PciInfo, Return)
GetSupportedEventTypes() (uint64, Return)
GetTopologyCommonAncestor(Device) (GpuTopologyLevel, Return)
GetUUID() (string, Return)
IsMigDeviceHandle() (bool, Return)
RegisterEvents(uint64, EventSet) Return
SetComputeMode(ComputeMode) Return
SetMigMode(Mode int) (Return, Return)
// nvmlDeviceHandle returns a pointer to the underlying NVML device.
nvmlDeviceHandle() *nvml.Device
}
// GpuInstance defines the functions implemented by a GpuInstance
//
//go:generate moq -out gi_mock.go . GpuInstance
type GpuInstance interface {
CreateComputeInstance(Info *ComputeInstanceProfileInfo) (ComputeInstance, Return)
Destroy() Return
GetComputeInstanceById(ID int) (ComputeInstance, Return)
GetComputeInstanceProfileInfo(Profile int, EngProfile int) (ComputeInstanceProfileInfo, Return)
GetComputeInstances(Info *ComputeInstanceProfileInfo) ([]ComputeInstance, Return)
GetInfo() (GpuInstanceInfo, Return)
}
// ComputeInstance defines the functions implemented by a ComputeInstance
//
//go:generate moq -out ci_mock.go . ComputeInstance
type ComputeInstance interface {
Destroy() Return
GetInfo() (ComputeInstanceInfo, Return)
}
// GpuInstanceInfo holds info about a GPU Instance
type GpuInstanceInfo struct {
Device Device
Id uint32
ProfileId uint32
Placement GpuInstancePlacement
}
// ComputeInstanceInfo holds info about a Compute Instance
type ComputeInstanceInfo struct {
Device Device
GpuInstance GpuInstance
Id uint32
ProfileId uint32
Placement ComputeInstancePlacement
}
// EventData defines NVML event Data
type EventData struct {
Device Device
EventType uint64
EventData uint64
GpuInstanceId uint32
ComputeInstanceId uint32
}
// EventSet defines NVML event Data
type EventSet nvml.EventSet
// Return defines an NVML return type
type Return nvml.Return
// Memory holds info about GPU device memory
type Memory nvml.Memory
// PciInfo holds info about the PCI connections of a GPU dvice
type PciInfo nvml.PciInfo
// GpuInstanceProfileInfo holds info about a GPU Instance Profile
type GpuInstanceProfileInfo nvml.GpuInstanceProfileInfo
// GpuInstancePlacement holds placement info about a GPU Instance
type GpuInstancePlacement nvml.GpuInstancePlacement
// ComputeInstanceProfileInfo holds info about a Compute Instance Profile
type ComputeInstanceProfileInfo nvml.ComputeInstanceProfileInfo
// ComputeInstancePlacement holds placement info about a Compute Instance
type ComputeInstancePlacement nvml.ComputeInstancePlacement
// DeviceAttributes stores information about MIG devices
type DeviceAttributes nvml.DeviceAttributes
// DeviceArchitecture represents the hardware architecture of a GPU device
type DeviceArchitecture nvml.DeviceArchitecture
// BrandType represents the brand of a GPU device
type BrandType nvml.BrandType
// GpuTopologyLevel represents level relationships within a system between two GPUs
type GpuTopologyLevel nvml.GpuTopologyLevel
// EnableState represents a generic enable/disable enum
type EnableState nvml.EnableState
// ComputeMode represents the compute mode for a device
type ComputeMode nvml.ComputeMode

View File

@@ -21,12 +21,12 @@ import (
"unsafe"
)
// Raw returns just the bytes without any assumptions about layout
// Raw returns just the bytes without any assumptions about layout.
type Raw interface {
Raw() *[]byte
}
// Reader used to read various data sizes in the byte array
// Reader used to read various data sizes in the byte array.
type Reader interface {
Read8(pos int) uint8
Read16(pos int) uint16
@@ -35,7 +35,7 @@ type Reader interface {
Len() int
}
// Writer used to write various sizes of data in the byte array
// Writer used to write various sizes of data in the byte array.
type Writer interface {
Write8(pos int, value uint8)
Write16(pos int, value uint16)
@@ -44,7 +44,7 @@ type Writer interface {
Len() int
}
// Bytes object for manipulating arbitrary byte arrays
// Bytes object for manipulating arbitrary byte arrays.
type Bytes interface {
Raw
Reader
@@ -70,12 +70,12 @@ func init() {
}
}
// New raw bytearray
// New raw bytearray.
func New(data *[]byte) Bytes {
return (*native)(data)
}
// NewLittleEndian little endian ordering of bytes
// NewLittleEndian little endian ordering of bytes.
func NewLittleEndian(data *[]byte) Bytes {
if nativeByteOrder == binary.LittleEndian {
return (*native)(data)
@@ -84,7 +84,7 @@ func NewLittleEndian(data *[]byte) Bytes {
return (*swapbo)(data)
}
// NewBigEndian big endian ordering of bytes
// NewBigEndian big endian ordering of bytes.
func NewBigEndian(data *[]byte) Bytes {
if nativeByteOrder == binary.BigEndian {
return (*native)(data)

View File

@@ -24,24 +24,24 @@ import (
)
const (
// PCICfgSpaceStandardSize represents the size in bytes of the standard config space
// PCICfgSpaceStandardSize represents the size in bytes of the standard config space.
PCICfgSpaceStandardSize = 256
// PCICfgSpaceExtendedSize represents the size in bytes of the extended config space
// PCICfgSpaceExtendedSize represents the size in bytes of the extended config space.
PCICfgSpaceExtendedSize = 4096
// PCICapabilityListPointer represents offset for the capability list pointer
// PCICapabilityListPointer represents offset for the capability list pointer.
PCICapabilityListPointer = 0x34
// PCIStatusCapabilityList represents the status register bit which indicates capability list support
// PCIStatusCapabilityList represents the status register bit which indicates capability list support.
PCIStatusCapabilityList = 0x10
// PCIStatusBytePosition represents the position of the status register
// PCIStatusBytePosition represents the position of the status register.
PCIStatusBytePosition = 0x06
)
// ConfigSpace PCI configuration space (standard extended) file path
// ConfigSpace PCI configuration space (standard extended) file path.
type ConfigSpace struct {
Path string
}
// ConfigSpaceIO Interface for reading and writing raw and preconfigured values
// ConfigSpaceIO Interface for reading and writing raw and preconfigured values.
type ConfigSpaceIO interface {
bytes.Bytes
GetVendorID() uint16
@@ -53,18 +53,18 @@ type configSpaceIO struct {
bytes.Bytes
}
// PCIStandardCapability standard PCI config space
// PCIStandardCapability standard PCI config space.
type PCIStandardCapability struct {
bytes.Bytes
}
// PCIExtendedCapability extended PCI config space
// PCIExtendedCapability extended PCI config space.
type PCIExtendedCapability struct {
bytes.Bytes
Version uint8
}
// PCICapabilities combines the standard and extended config space
// PCICapabilities combines the standard and extended config space.
type PCICapabilities struct {
Standard map[uint8]*PCIStandardCapability
Extended map[uint16]*PCIExtendedCapability

View File

@@ -22,15 +22,15 @@ import (
)
const (
// PCIMellanoxVendorID represents PCI vendor id for Mellanox
// PCIMellanoxVendorID represents PCI vendor id for Mellanox.
PCIMellanoxVendorID uint16 = 0x15b3
// PCINetworkControllerClass represents the PCI class for network controllers
// PCINetworkControllerClass represents the PCI class for network controllers.
PCINetworkControllerClass uint32 = 0x020000
// PCIBridgeClass represents the PCI class for network controllers
// PCIBridgeClass represents the PCI class for network controllers.
PCIBridgeClass uint32 = 0x060400
)
// GetNetworkControllers returns all Mellanox Network Controller PCI devices on the system
// GetNetworkControllers returns all Mellanox Network Controller PCI devices on the system.
func (p *nvpci) GetNetworkControllers() ([]*NvidiaPCIDevice, error) {
devices, err := p.GetAllDevices()
if err != nil {
@@ -47,7 +47,7 @@ func (p *nvpci) GetNetworkControllers() ([]*NvidiaPCIDevice, error) {
return filtered, nil
}
// GetPciBridges retrieves all Mellanox PCI(e) Bridges
// GetPciBridges retrieves all Mellanox PCI(e) Bridges.
func (p *nvpci) GetPciBridges() ([]*NvidiaPCIDevice, error) {
devices, err := p.GetAllDevices()
if err != nil {
@@ -64,17 +64,17 @@ func (p *nvpci) GetPciBridges() ([]*NvidiaPCIDevice, error) {
return filtered, nil
}
// IsNetworkController if class == 0x300
// IsNetworkController if class == 0x300.
func (d *NvidiaPCIDevice) IsNetworkController() bool {
return d.Class == PCINetworkControllerClass
}
// IsPciBridge if class == 0x0604
// IsPciBridge if class == 0x0604.
func (d *NvidiaPCIDevice) IsPciBridge() bool {
return d.Class == PCIBridgeClass
}
// IsDPU returns if a device is a DPU
// IsDPU returns if a device is a DPU.
func (d *NvidiaPCIDevice) IsDPU() bool {
if !strings.Contains(d.DeviceName, "BlueField") {
return false
@@ -87,7 +87,7 @@ func (d *NvidiaPCIDevice) IsDPU() bool {
return false
}
// GetDPUs returns all Mellanox DPU devices on the system
// GetDPUs returns all Mellanox DPU devices on the system.
func (p *nvpci) GetDPUs() ([]*NvidiaPCIDevice, error) {
devices, err := p.GetNetworkControllers()
if err != nil {

View File

@@ -25,7 +25,7 @@ import (
"github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes"
)
// Mmio memory map a region
// Mmio memory map a region.
type Mmio interface {
bytes.Raw
bytes.Reader
@@ -84,12 +84,12 @@ func open(path string, offset int, size int, flags int) (Mmio, error) {
return &mmio{bytes.New(&mmap)}, nil
}
// OpenRO open region readonly
// OpenRO open region readonly.
func OpenRO(path string, offset int, size int) (Mmio, error) {
return open(path, offset, size, os.O_RDONLY)
}
// OpenRW open region read write
// OpenRW open region read write.
func OpenRW(path string, offset int, size int) (Mmio, error) {
return open(path, offset, size, os.O_RDWR)
}

View File

@@ -48,18 +48,21 @@ func mockOpen(source *[]byte, offset int, size int, rw bool) (Mmio, error) {
return m, nil
}
// MockOpenRO open read only
// MockOpenRO open read only.
func MockOpenRO(source *[]byte, offset int, size int) (Mmio, error) {
return mockOpen(source, offset, size, false)
}
// MockOpenRW open read write
// MockOpenRW open read write.
func MockOpenRW(source *[]byte, offset int, size int) (Mmio, error) {
return mockOpen(source, offset, size, true)
}
func (m *mockMmio) Close() error {
m = &mockMmio{}
m.Bytes = nil
m.source = nil
m.offset = 0
m.rw = false
return nil
}

View File

@@ -24,14 +24,14 @@ import (
"github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes"
)
// MockNvpci mock pci device
// MockNvpci mock pci device.
type MockNvpci struct {
*nvpci
}
var _ Interface = (*MockNvpci)(nil)
// NewMockNvpci create new mock PCI and remove old devices
// NewMockNvpci create new mock PCI and remove old devices.
func NewMockNvpci() (mock *MockNvpci, rerr error) {
rootDir, err := os.MkdirTemp(os.TempDir(), "")
if err != nil {
@@ -50,12 +50,12 @@ func NewMockNvpci() (mock *MockNvpci, rerr error) {
return mock, nil
}
// Cleanup remove the mocked PCI devices root folder
// Cleanup remove the mocked PCI devices root folder.
func (m *MockNvpci) Cleanup() {
os.RemoveAll(m.pciDevicesRoot)
}
// AddMockA100 Create an A100 like GPU mock device
// AddMockA100 Create an A100 like GPU mock device.
func (m *MockNvpci) AddMockA100(address string, numaNode int) error {
deviceDir := filepath.Join(m.pciDevicesRoot, address)
err := os.MkdirAll(deviceDir, 0755)

View File

@@ -29,23 +29,23 @@ import (
)
const (
// PCIDevicesRoot represents base path for all pci devices under sysfs
// PCIDevicesRoot represents base path for all pci devices under sysfs.
PCIDevicesRoot = "/sys/bus/pci/devices"
// PCINvidiaVendorID represents PCI vendor id for NVIDIA
// PCINvidiaVendorID represents PCI vendor id for NVIDIA.
PCINvidiaVendorID uint16 = 0x10de
// PCIVgaControllerClass represents the PCI class for VGA Controllers
// PCIVgaControllerClass represents the PCI class for VGA Controllers.
PCIVgaControllerClass uint32 = 0x030000
// PCI3dControllerClass represents the PCI class for 3D Graphics accellerators
// PCI3dControllerClass represents the PCI class for 3D Graphics accellerators.
PCI3dControllerClass uint32 = 0x030200
// PCINvSwitchClass represents the PCI class for NVSwitches
// PCINvSwitchClass represents the PCI class for NVSwitches.
PCINvSwitchClass uint32 = 0x068000
// UnknownDeviceString is the device name to set for devices not found in the PCI database
// UnknownDeviceString is the device name to set for devices not found in the PCI database.
UnknownDeviceString = "UNKNOWN_DEVICE"
// UnknownClassString is the class name to set for devices not found in the PCI database
// UnknownClassString is the class name to set for devices not found in the PCI database.
UnknownClassString = "UNKNOWN_CLASS"
)
// Interface allows us to get a list of all NVIDIA PCI devices
// Interface allows us to get a list of all NVIDIA PCI devices.
type Interface interface {
GetAllDevices() ([]*NvidiaPCIDevice, error)
Get3DControllers() ([]*NvidiaPCIDevice, error)
@@ -59,10 +59,10 @@ type Interface interface {
GetDPUs() ([]*NvidiaPCIDevice, error)
}
// MemoryResources a more human readable handle
// MemoryResources a more human readable handle.
type MemoryResources map[int]*MemoryResource
// ResourceInterface exposes some higher level functions of resources
// ResourceInterface exposes some higher level functions of resources.
type ResourceInterface interface {
GetTotalAddressableMemory(bool) (uint64, uint64)
}
@@ -76,7 +76,7 @@ type nvpci struct {
var _ Interface = (*nvpci)(nil)
var _ ResourceInterface = (*MemoryResources)(nil)
// NvidiaPCIDevice represents a PCI device for an NVIDIA product
// NvidiaPCIDevice represents a PCI device for an NVIDIA product.
type NvidiaPCIDevice struct {
Path string
Address string
@@ -93,34 +93,34 @@ type NvidiaPCIDevice struct {
IsVF bool
}
// IsVGAController if class == 0x300
// IsVGAController if class == 0x300.
func (d *NvidiaPCIDevice) IsVGAController() bool {
return d.Class == PCIVgaControllerClass
}
// Is3DController if class == 0x302
// Is3DController if class == 0x302.
func (d *NvidiaPCIDevice) Is3DController() bool {
return d.Class == PCI3dControllerClass
}
// IsNVSwitch if class == 0x068
// IsNVSwitch if class == 0x068.
func (d *NvidiaPCIDevice) IsNVSwitch() bool {
return d.Class == PCINvSwitchClass
}
// IsGPU either VGA for older cards or 3D for newer
// IsGPU either VGA for older cards or 3D for newer.
func (d *NvidiaPCIDevice) IsGPU() bool {
return d.IsVGAController() || d.Is3DController()
}
// IsResetAvailable some devices can be reset without rebooting,
// check if applicable
// check if applicable.
func (d *NvidiaPCIDevice) IsResetAvailable() bool {
_, err := os.Stat(path.Join(d.Path, "reset"))
return err == nil
}
// Reset perform a reset to apply a new configuration at HW level
// Reset perform a reset to apply a new configuration at HW level.
func (d *NvidiaPCIDevice) Reset() error {
err := os.WriteFile(path.Join(d.Path, "reset"), []byte("1"), 0)
if err != nil {
@@ -129,7 +129,7 @@ func (d *NvidiaPCIDevice) Reset() error {
return nil
}
// New interface that allows us to get a list of all NVIDIA PCI devices
// New interface that allows us to get a list of all NVIDIA PCI devices.
func New(opts ...Option) Interface {
n := &nvpci{}
for _, opt := range opts {
@@ -144,10 +144,10 @@ func New(opts ...Option) Interface {
return n
}
// Option defines a function for passing options to the New() call
// Option defines a function for passing options to the New() call.
type Option func(*nvpci)
// WithLogger provides an Option to set the logger for the library
// WithLogger provides an Option to set the logger for the library.
func WithLogger(logger logger) Option {
return func(n *nvpci) {
n.logger = logger
@@ -170,7 +170,7 @@ func WithPCIDatabasePath(path string) Option {
}
}
// GetAllDevices returns all Nvidia PCI devices on the system
// GetAllDevices returns all Nvidia PCI devices on the system.
func (p *nvpci) GetAllDevices() ([]*NvidiaPCIDevice, error) {
deviceDirs, err := os.ReadDir(p.pciDevicesRoot)
if err != nil {
@@ -204,7 +204,7 @@ func (p *nvpci) GetAllDevices() ([]*NvidiaPCIDevice, error) {
return nvdevices, nil
}
// GetGPUByPciBusID constructs an NvidiaPCIDevice for the specified address (PCI Bus ID)
// GetGPUByPciBusID constructs an NvidiaPCIDevice for the specified address (PCI Bus ID).
func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) {
devicePath := filepath.Join(p.pciDevicesRoot, address)
@@ -265,7 +265,7 @@ func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) {
return nil, fmt.Errorf("unable to detect iommu_group for %s: %v", address, err)
}
// device is a virtual function (VF) if "physfn" symlink exists
// device is a virtual function (VF) if "physfn" symlink exists.
var isVF bool
_, err = filepath.EvalSymlinks(path.Join(devicePath, "physfn"))
if err == nil {
@@ -347,7 +347,7 @@ func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) {
return nvdevice, nil
}
// Get3DControllers returns all NVIDIA 3D Controller PCI devices on the system
// Get3DControllers returns all NVIDIA 3D Controller PCI devices on the system.
func (p *nvpci) Get3DControllers() ([]*NvidiaPCIDevice, error) {
devices, err := p.GetAllDevices()
if err != nil {
@@ -364,7 +364,7 @@ func (p *nvpci) Get3DControllers() ([]*NvidiaPCIDevice, error) {
return filtered, nil
}
// GetVGAControllers returns all NVIDIA VGA Controller PCI devices on the system
// GetVGAControllers returns all NVIDIA VGA Controller PCI devices on the system.
func (p *nvpci) GetVGAControllers() ([]*NvidiaPCIDevice, error) {
devices, err := p.GetAllDevices()
if err != nil {
@@ -381,7 +381,7 @@ func (p *nvpci) GetVGAControllers() ([]*NvidiaPCIDevice, error) {
return filtered, nil
}
// GetNVSwitches returns all NVIDIA NVSwitch PCI devices on the system
// GetNVSwitches returns all NVIDIA NVSwitch PCI devices on the system.
func (p *nvpci) GetNVSwitches() ([]*NvidiaPCIDevice, error) {
devices, err := p.GetAllDevices()
if err != nil {
@@ -398,7 +398,7 @@ func (p *nvpci) GetNVSwitches() ([]*NvidiaPCIDevice, error) {
return filtered, nil
}
// GetGPUs returns all NVIDIA GPU devices on the system
// GetGPUs returns all NVIDIA GPU devices on the system.
func (p *nvpci) GetGPUs() ([]*NvidiaPCIDevice, error) {
devices, err := p.GetAllDevices()
if err != nil {
@@ -415,7 +415,7 @@ func (p *nvpci) GetGPUs() ([]*NvidiaPCIDevice, error) {
return filtered, nil
}
// GetGPUByIndex returns an NVIDIA GPU device at a particular index
// GetGPUByIndex returns an NVIDIA GPU device at a particular index.
func (p *nvpci) GetGPUByIndex(i int) (*NvidiaPCIDevice, error) {
gpus, err := p.GetGPUs()
if err != nil {

View File

@@ -29,7 +29,7 @@ const (
pmcBigEndian = 0x01000001
)
// MemoryResource represents a mmio region
// MemoryResource represents a mmio region.
type MemoryResource struct {
Start uintptr
End uintptr
@@ -37,7 +37,7 @@ type MemoryResource struct {
Path string
}
// OpenRW read write mmio region
// OpenRW read write mmio region.
func (mr *MemoryResource) OpenRW() (mmio.Mmio, error) {
rw, err := mmio.OpenRW(mr.Path, 0, int(mr.End-mr.Start+1))
if err != nil {
@@ -52,7 +52,7 @@ func (mr *MemoryResource) OpenRW() (mmio.Mmio, error) {
return nil, fmt.Errorf("unknown endianness for mmio: %v", err)
}
// OpenRO read only mmio region
// OpenRO read only mmio region.
func (mr *MemoryResource) OpenRO() (mmio.Mmio, error) {
ro, err := mmio.OpenRO(mr.Path, 0, int(mr.End-mr.Start+1))
if err != nil {
@@ -67,7 +67,7 @@ func (mr *MemoryResource) OpenRO() (mmio.Mmio, error) {
return nil, fmt.Errorf("unknown endianness for mmio: %v", err)
}
// From Bit Twiddling Hacks, great resource for all low level bit manipulations
// From Bit Twiddling Hacks, great resource for all low level bit manipulations.
func calcNextPowerOf2(n uint64) uint64 {
n--
n |= n >> 1
@@ -83,7 +83,7 @@ func calcNextPowerOf2(n uint64) uint64 {
// GetTotalAddressableMemory will accumulate the 32bit and 64bit memory windows
// of each BAR and round the value if needed to the next power of 2; first
// return value is the accumulated 32bit addresable memory size the second one
// return value is the accumulated 32bit addressable memory size the second one
// is the accumulated 64bit addressable memory size in bytes. These values are
// needed to configure virtualized environments.
func (mrs MemoryResources) GetTotalAddressableMemory(roundUp bool) (uint64, uint64) {

View File

@@ -11,42 +11,42 @@ import (
"strings"
)
// token what the Lexer retruns
// token what the Lexer retruns.
type token int
const (
// ILLEGAL a token which the Lexer does not understand
// ILLEGAL a token which the Lexer does not understand.
ILLEGAL token = iota
// EOF end of file
// EOF end of file.
EOF
// WS whitespace
// WS whitespace.
WS
// NEWLINE '\n'
// NEWLINE '\n'.
NEWLINE
// COMMENT '# something'
// COMMENT '# something'.
COMMENT
// VENDOR PCI vendor
// VENDOR PCI vendor.
VENDOR
// SUBVENDOR PCI subvendor
// SUBVENDOR PCI subvendor.
SUBVENDOR
// DEVICE PCI device
// DEVICE PCI device.
DEVICE
// CLASS PCI class
// CLASS PCI class.
CLASS
// SUBCLASS PCI subclass
// SUBCLASS PCI subclass.
SUBCLASS
// PROGIF PCI programming interface
// PROGIF PCI programming interface.
PROGIF
)
// literal values from the Lexer
// literal values from the Lexer.
type literal struct {
ID string
name string
SubName string
}
// scanner a lexical scanner
// scanner a lexical scanner.
type scanner struct {
r *bufio.Reader
isVendor bool
@@ -58,7 +58,7 @@ func newScanner(r io.Reader) *scanner {
}
// Since the pci.ids is line base we're consuming a whole line rather then only
// a single rune/char
// a single rune/char.
func (s *scanner) readline() []byte {
ln, err := s.r.ReadBytes('\n')
if err == io.EOF {
@@ -107,7 +107,7 @@ func isSubVendor(ln []byte) bool { return isLeadingTwoTabs(ln) }
func isDevice(ln []byte) bool { return isLeadingOneTab(ln) }
func isNewline(ln []byte) bool { return (ln[0] == '\n') }
// List of known device classes, subclasses and programming interfaces
// List of known device classes, subclasses and programming interfaces.
func isClass(ln []byte) bool { return (ln[0] == 'C') }
func isProgIf(ln []byte) bool { return isLeadingTwoTabs(ln) }
func isSubClass(ln []byte) bool { return isLeadingOneTab(ln) }
@@ -162,7 +162,7 @@ func (s *scanner) scan() (tok token, lit literal) {
return ILLEGAL, literal{ID: string(line)}
}
// parser reads the tokens returned by the Lexer and constructs the AST
// parser reads the tokens returned by the Lexer and constructs the AST.
type parser struct {
s *scanner
buf struct {
@@ -173,7 +173,7 @@ type parser struct {
}
// Various locations of pci.ids for different distributions. These may be more
// up to date then the embedded pci.ids db
// up to date then the embedded pci.ids db.
var defaultPCIdbPaths = []string{
"/usr/share/misc/pci.ids", // Ubuntu
"/usr/local/share/pci.ids", // RHEL like with manual update
@@ -202,7 +202,7 @@ func NewDB(opts ...Option) Interface {
return newParser(pcidbs).parse()
}
// Option defines a function for passing options to the NewDB() call
// Option defines a function for passing options to the NewDB() call.
type Option func(*pcidb)
// WithFilePath provides an Option to set the file path
@@ -216,7 +216,7 @@ func WithFilePath(path string) Option {
}
// newParser will attempt to read the db pci.ids from well known places or fall
// back to an internal db
// back to an internal db.
func newParser(pcidbs []string) *parser {
for _, db := range pcidbs {
@@ -229,7 +229,7 @@ func newParser(pcidbs []string) *parser {
}
// We're using go embed above to have the byte array
// correctly initialized with the internal shipped db
// if we cannot find an up to date in the filesystem
// if we cannot find an up to date in the filesystem.
return newParserFromReader(bufio.NewReader(bytes.NewReader(defaultPCIdb)))
}
@@ -252,13 +252,13 @@ func (p *parser) unscan() { p.buf.n = 1 }
var _ Interface = (*pcidb)(nil)
// Interface returns textual description of specific attributes of PCI devices
// Interface returns textual description of specific attributes of PCI devices.
type Interface interface {
GetDeviceName(uint16, uint16) (string, error)
GetClassName(uint32) (string, error)
}
// GetDeviceName return the textual description of the PCI device
// GetDeviceName return the textual description of the PCI device.
func (d *pcidb) GetDeviceName(vendorID uint16, deviceID uint16) (string, error) {
vendor, ok := d.vendors[vendorID]
if !ok {
@@ -273,7 +273,7 @@ func (d *pcidb) GetDeviceName(vendorID uint16, deviceID uint16) (string, error)
return device.name, nil
}
// GetClassName resturn the textual description of the PCI device class
// GetClassName resturn the textual description of the PCI device class.
func (d *pcidb) GetClassName(classID uint32) (string, error) {
class, ok := d.classes[classID]
if !ok {
@@ -282,53 +282,53 @@ func (d *pcidb) GetClassName(classID uint32) (string, error) {
return class.name, nil
}
// pcidb The complete set of PCI vendors and PCI classes
// pcidb The complete set of PCI vendors and PCI classes.
type pcidb struct {
vendors map[uint16]vendor
classes map[uint32]class
path string
}
// vendor PCI vendors/devices/subVendors/SubDevices
// vendor PCI vendors/devices/subVendors/SubDevices.
type vendor struct {
name string
devices map[uint16]device
}
// subVendor PCI subVendor
// subVendor PCI subVendor.
type subVendor struct {
SubDevices map[uint16]SubDevice
}
// SubDevice PCI SubDevice
// SubDevice PCI SubDevice.
type SubDevice struct {
name string
}
// device PCI device
// device PCI device.
type device struct {
name string
subVendors map[uint16]subVendor
}
// class PCI classes/subClasses/Programming Interfaces
// class PCI classes/subClasses/Programming Interfaces.
type class struct {
name string
subClasses map[uint32]subClass
}
// subClass PCI subClass
// subClass PCI subClass.
type subClass struct {
name string
progIfs map[uint8]progIf
}
// progIf PCI Programming Interface
// progIf PCI Programming Interface.
type progIf struct {
name string
}
// parse parses a PCI IDS entry
// parse parses a PCI IDS entry.
func (p *parser) parse() Interface {
db := &pcidb{
@@ -336,7 +336,7 @@ func (p *parser) parse() Interface {
classes: map[uint32]class{},
}
// Used for housekeeping, breadcrumb for aggregated types
// Used for housekeeping, breadcrumb for aggregated types.
var hkVendor vendor
var hkDevice device
@@ -349,8 +349,8 @@ func (p *parser) parse() Interface {
for {
tok, lit := p.scan()
// We're ignoring COMMENT, NEWLINE
// An EOF will break the loop
// We're ignoring COMMENT, NEWLINE.
// An EOF will break the loop.
if tok == EOF {
break
}
@@ -408,10 +408,10 @@ func (p *parser) parse() Interface {
}
hkSubClass = hkClass.subClasses[uint32(id)]
// Clear the last detected sub class
// Clear the last detected sub class.
hkFullID = hkFullID & 0xFFFF0000
hkFullID = hkFullID | uint32(id)<<8
// Clear the last detected prog iface
// Clear the last detected prog iface.
hkFullID = hkFullID & 0xFFFFFF00
hkFullName[1] = fmt.Sprintf("%s (%02x)", lit.name, id)

View File

@@ -16,22 +16,41 @@
package nvml
// Library defines a set of functions defined on the underlying dynamic library.
type Library interface {
Lookup(string) error
// ExtendedInterface defines a set of extensions to the core NVML API.
//
// TODO: For now the list of methods in this interface need to be kept in sync
// with the list of excluded methods for the Interface type in
// gen/nvml/generateapi.go. In the future we should automate this.
//
//go:generate moq -out mock/extendedinterface.go -pkg mock . ExtendedInterface:ExtendedInterface
type ExtendedInterface interface {
LookupSymbol(string) error
}
// dynamicLibrary is an interface for abstacting the underlying library.
// This also allows for mocking and testing.
//go:generate moq -stub -out dynamicLibrary_mock.go . dynamicLibrary
type dynamicLibrary interface {
Lookup(string) error
Open() error
Close() error
// libraryOptions hold the paramaters than can be set by a LibraryOption
type libraryOptions struct {
path string
flags int
}
// Interface represents the interface for the NVML library.
type Interface interface {
GetLibrary() Library
// LibraryOption represents a functional option to configure the underlying NVML library
type LibraryOption func(*libraryOptions)
// WithLibraryPath provides an option to set the library name to be used by the NVML library.
func WithLibraryPath(path string) LibraryOption {
return func(o *libraryOptions) {
o.path = path
}
}
// SetLibraryOptions applies the specified options to the NVML library.
// If this is called when a library is already loaded, an error is raised.
func SetLibraryOptions(opts ...LibraryOption) error {
libnvml.Lock()
defer libnvml.Unlock()
if libnvml.refcount != 0 {
return errLibraryAlreadyLoaded
}
libnvml.init(opts...)
return nil
}

View File

@@ -44,6 +44,17 @@ func uint32SliceToIntSlice(s []uint32) []int {
return ret
}
func convertSlice[T any, I any](input []T) []I {
output := make([]I, len(input))
for i, obj := range input {
switch v := any(obj).(type) {
case I:
output[i] = v
}
}
return output
}
// packPCharString creates a Go string backed by *C.char and avoids copying.
func packPCharString(p *C.char) (raw string) {
if p != nil && *p != 0 {

File diff suppressed because it is too large Load Diff

View File

@@ -14,29 +14,60 @@
package nvml
// EventData includes an interface type for Device instead of nvmlDevice
type EventData struct {
Device Device
EventType uint64
EventData uint64
GpuInstanceId uint32
ComputeInstanceId uint32
}
func (e EventData) convert() nvmlEventData {
out := nvmlEventData{
Device: e.Device.(nvmlDevice),
EventType: e.EventType,
EventData: e.EventData,
GpuInstanceId: e.GpuInstanceId,
ComputeInstanceId: e.ComputeInstanceId,
}
return out
}
func (e nvmlEventData) convert() EventData {
out := EventData{
Device: e.Device,
EventType: e.EventType,
EventData: e.EventData,
GpuInstanceId: e.GpuInstanceId,
ComputeInstanceId: e.ComputeInstanceId,
}
return out
}
// nvml.EventSetCreate()
func EventSetCreate() (EventSet, Return) {
var Set EventSet
func (l *library) EventSetCreate() (EventSet, Return) {
var Set nvmlEventSet
ret := nvmlEventSetCreate(&Set)
return Set, ret
}
// nvml.EventSetWait()
func EventSetWait(Set EventSet, Timeoutms uint32) (EventData, Return) {
var Data EventData
ret := nvmlEventSetWait(Set, &Data, Timeoutms)
return Data, ret
func (l *library) EventSetWait(set EventSet, timeoutms uint32) (EventData, Return) {
return set.Wait(timeoutms)
}
func (Set EventSet) Wait(Timeoutms uint32) (EventData, Return) {
return EventSetWait(Set, Timeoutms)
func (set nvmlEventSet) Wait(timeoutms uint32) (EventData, Return) {
var data nvmlEventData
ret := nvmlEventSetWait(set, &data, timeoutms)
return data.convert(), ret
}
// nvml.EventSetFree()
func EventSetFree(Set EventSet) Return {
return nvmlEventSetFree(Set)
func (l *library) EventSetFree(set EventSet) Return {
return set.Free()
}
func (Set EventSet) Free() Return {
return EventSetFree(Set)
func (set nvmlEventSet) Free() Return {
return nvmlEventSetFree(set)
}

View File

@@ -14,80 +14,128 @@
package nvml
// GpmMetricsGetType includes interface types for GpmSample instead of nvmlGpmSample
type GpmMetricsGetType struct {
Version uint32
NumMetrics uint32
Sample1 GpmSample
Sample2 GpmSample
Metrics [98]GpmMetric
}
func (g *GpmMetricsGetType) convert() *nvmlGpmMetricsGetType {
out := &nvmlGpmMetricsGetType{
Version: g.Version,
NumMetrics: g.NumMetrics,
Sample1: g.Sample1.(nvmlGpmSample),
Sample2: g.Sample2.(nvmlGpmSample),
}
for i := range g.Metrics {
out.Metrics[i] = g.Metrics[i]
}
return out
}
func (g *nvmlGpmMetricsGetType) convert() *GpmMetricsGetType {
out := &GpmMetricsGetType{
Version: g.Version,
NumMetrics: g.NumMetrics,
Sample1: g.Sample1,
Sample2: g.Sample2,
}
for i := range g.Metrics {
out.Metrics[i] = g.Metrics[i]
}
return out
}
// nvml.GpmMetricsGet()
type GpmMetricsGetVType struct {
metricsGet *GpmMetricsGetType
metricsGet *nvmlGpmMetricsGetType
}
func GpmMetricsGetV(MetricsGet *GpmMetricsGetType) GpmMetricsGetVType {
return GpmMetricsGetVType{MetricsGet}
func (l *library) GpmMetricsGetV(metricsGet *GpmMetricsGetType) GpmMetricsGetVType {
return GpmMetricsGetVType{metricsGet.convert()}
}
func (metricsGetV GpmMetricsGetVType) V1() Return {
metricsGetV.metricsGet.Version = 1
return nvmlGpmMetricsGet(metricsGetV.metricsGet)
}
func (MetricsGetV GpmMetricsGetVType) V1() Return {
MetricsGetV.metricsGet.Version = 1
return nvmlGpmMetricsGet(MetricsGetV.metricsGet)
}
func GpmMetricsGet(MetricsGet *GpmMetricsGetType) Return {
MetricsGet.Version = GPM_METRICS_GET_VERSION
return nvmlGpmMetricsGet(MetricsGet)
func (l *library) GpmMetricsGet(metricsGet *GpmMetricsGetType) Return {
metricsGet.Version = GPM_METRICS_GET_VERSION
return nvmlGpmMetricsGet(metricsGet.convert())
}
// nvml.GpmSampleFree()
func GpmSampleFree(GpmSample GpmSample) Return {
return nvmlGpmSampleFree(GpmSample)
func (l *library) GpmSampleFree(gpmSample GpmSample) Return {
return gpmSample.Free()
}
func (gpmSample nvmlGpmSample) Free() Return {
return nvmlGpmSampleFree(gpmSample)
}
// nvml.GpmSampleAlloc()
func GpmSampleAlloc(GpmSample *GpmSample) Return {
return nvmlGpmSampleAlloc(GpmSample)
func (l *library) GpmSampleAlloc() (GpmSample, Return) {
var gpmSample nvmlGpmSample
ret := nvmlGpmSampleAlloc(&gpmSample)
return gpmSample, ret
}
// nvml.GpmSampleGet()
func GpmSampleGet(Device Device, GpmSample GpmSample) Return {
return nvmlGpmSampleGet(Device, GpmSample)
func (l *library) GpmSampleGet(device Device, gpmSample GpmSample) Return {
return gpmSample.Get(device)
}
func (Device Device) GpmSampleGet(GpmSample GpmSample) Return {
return GpmSampleGet(Device, GpmSample)
func (device nvmlDevice) GpmSampleGet(gpmSample GpmSample) Return {
return gpmSample.Get(device)
}
func (gpmSample nvmlGpmSample) Get(device Device) Return {
return nvmlGpmSampleGet(nvmlDeviceHandle(device), gpmSample)
}
// nvml.GpmQueryDeviceSupport()
type GpmSupportV struct {
device Device
device nvmlDevice
}
func GpmQueryDeviceSupportV(Device Device) GpmSupportV {
return GpmSupportV{Device}
func (l *library) GpmQueryDeviceSupportV(device Device) GpmSupportV {
return device.GpmQueryDeviceSupportV()
}
func (Device Device) GpmQueryDeviceSupportV() GpmSupportV {
return GpmSupportV{Device}
func (device nvmlDevice) GpmQueryDeviceSupportV() GpmSupportV {
return GpmSupportV{device}
}
func (GpmSupportV GpmSupportV) V1() (GpmSupport, Return) {
var GpmSupport GpmSupport
GpmSupport.Version = 1
ret := nvmlGpmQueryDeviceSupport(GpmSupportV.device, &GpmSupport)
return GpmSupport, ret
func (gpmSupportV GpmSupportV) V1() (GpmSupport, Return) {
var gpmSupport GpmSupport
gpmSupport.Version = 1
ret := nvmlGpmQueryDeviceSupport(gpmSupportV.device, &gpmSupport)
return gpmSupport, ret
}
func GpmQueryDeviceSupport(Device Device) (GpmSupport, Return) {
var GpmSupport GpmSupport
GpmSupport.Version = GPM_SUPPORT_VERSION
ret := nvmlGpmQueryDeviceSupport(Device, &GpmSupport)
return GpmSupport, ret
func (l *library) GpmQueryDeviceSupport(device Device) (GpmSupport, Return) {
return device.GpmQueryDeviceSupport()
}
func (Device Device) GpmQueryDeviceSupport() (GpmSupport, Return) {
return GpmQueryDeviceSupport(Device)
func (device nvmlDevice) GpmQueryDeviceSupport() (GpmSupport, Return) {
var gpmSupport GpmSupport
gpmSupport.Version = GPM_SUPPORT_VERSION
ret := nvmlGpmQueryDeviceSupport(device, &gpmSupport)
return gpmSupport, ret
}
// nvml.GpmMigSampleGet()
func GpmMigSampleGet(Device Device, GpuInstanceId int, GpmSample GpmSample) Return {
return nvmlGpmMigSampleGet(Device, uint32(GpuInstanceId), GpmSample)
func (l *library) GpmMigSampleGet(device Device, gpuInstanceId int, gpmSample GpmSample) Return {
return gpmSample.MigGet(device, gpuInstanceId)
}
func (Device Device) GpmMigSampleGet(GpuInstanceId int, GpmSample GpmSample) Return {
return GpmMigSampleGet(Device, GpuInstanceId, GpmSample)
func (device nvmlDevice) GpmMigSampleGet(gpuInstanceId int, gpmSample GpmSample) Return {
return gpmSample.MigGet(device, gpuInstanceId)
}
func (gpmSample nvmlGpmSample) MigGet(device Device, gpuInstanceId int) Return {
return nvmlGpmMigSampleGet(nvmlDeviceHandle(device), uint32(gpuInstanceId), gpmSample)
}

View File

@@ -17,31 +17,31 @@ package nvml
import "C"
// nvml.Init()
func Init() Return {
if err := libnvml.load(); err != nil {
func (l *library) Init() Return {
if err := l.load(); err != nil {
return ERROR_LIBRARY_NOT_FOUND
}
return nvmlInit()
}
// nvml.InitWithFlags()
func InitWithFlags(Flags uint32) Return {
if err := libnvml.load(); err != nil {
func (l *library) InitWithFlags(flags uint32) Return {
if err := l.load(); err != nil {
return ERROR_LIBRARY_NOT_FOUND
}
return nvmlInitWithFlags(Flags)
return nvmlInitWithFlags(flags)
}
// nvml.Shutdown()
func Shutdown() Return {
func (l *library) Shutdown() Return {
ret := nvmlShutdown()
if ret != SUCCESS {
return ret
}
err := libnvml.close()
err := l.close()
if err != nil {
panic(err)
return ERROR_UNKNOWN
}
return ret

View File

@@ -34,48 +34,70 @@ const (
var errLibraryNotLoaded = errors.New("library not loaded")
var errLibraryAlreadyLoaded = errors.New("library already loaded")
// dynamicLibrary is an interface for abstacting the underlying library.
// This also allows for mocking and testing.
//go:generate moq -stub -out dynamicLibrary_mock.go . dynamicLibrary
type dynamicLibrary interface {
Lookup(string) error
Open() error
Close() error
}
// library represents an nvml library.
// This includes a reference to the underlying DynamicLibrary
type library struct {
sync.Mutex
path string
flags int
refcount refcount
dl dynamicLibrary
}
// libnvml is a global instance of the nvml library.
var libnvml = library{
path: defaultNvmlLibraryName,
flags: defaultNvmlLibraryLoadFlags,
}
var _ Interface = (*library)(nil)
// GetLibrary returns a the library as a Library interface.
func (l *library) GetLibrary() Library {
// libnvml is a global instance of the nvml library.
var libnvml = newLibrary()
func New(opts ...LibraryOption) Interface {
return newLibrary(opts...)
}
func newLibrary(opts ...LibraryOption) *library {
l := &library{}
l.init(opts...)
return l
}
// GetLibrary returns a representation of the underlying library that implements the Library interface.
func GetLibrary() Library {
return libnvml.GetLibrary()
func (l *library) init(opts ...LibraryOption) {
o := libraryOptions{}
for _, opt := range opts {
opt(&o)
}
if o.path == "" {
o.path = defaultNvmlLibraryName
}
if o.flags == 0 {
o.flags = defaultNvmlLibraryLoadFlags
}
l.path = o.path
l.dl = dl.New(o.path, o.flags)
}
// Lookup checks whether the specified library symbol exists in the library.
func (l *library) Extensions() ExtendedInterface {
return l
}
// LookupSymbol checks whether the specified library symbol exists in the library.
// Note that this requires that the library be loaded.
func (l *library) Lookup(name string) error {
if l == nil || l.dl == nil {
func (l *library) LookupSymbol(name string) error {
if l == nil || l.refcount == 0 {
return fmt.Errorf("error looking up %s: %w", name, errLibraryNotLoaded)
}
return l.dl.Lookup(name)
}
// newDynamicLibrary is a function variable that can be overridden for testing.
var newDynamicLibrary = func(path string, flags int) dynamicLibrary {
return dl.New(path, flags)
}
// load initializes the library and updates the versioned symbols.
// Multiple calls to an already loaded library will return without error.
func (l *library) load() (rerr error) {
@@ -87,12 +109,14 @@ func (l *library) load() (rerr error) {
return nil
}
dl := newDynamicLibrary(l.path, l.flags)
if err := dl.Open(); err != nil {
if err := l.dl.Open(); err != nil {
return fmt.Errorf("error opening %s: %w", l.path, err)
}
l.dl = dl
// Update the errorStringFunc to point to nvml.ErrorString
errorStringFunc = nvmlErrorString
// Update all versioned symbols
l.updateVersionedSymbols()
return nil
@@ -114,7 +138,8 @@ func (l *library) close() (rerr error) {
return fmt.Errorf("error closing %s: %w", l.path, err)
}
l.dl = nil
// Update the errorStringFunc to point to defaultErrorStringFunc
errorStringFunc = defaultErrorStringFunc
return nil
}
@@ -131,9 +156,9 @@ var nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v1
var nvmlEventSetWait = nvmlEventSetWait_v1
var nvmlDeviceGetAttributes = nvmlDeviceGetAttributes_v1
var nvmlComputeInstanceGetInfo = nvmlComputeInstanceGetInfo_v1
var DeviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v1
var DeviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v1
var DeviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v1
var deviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v1
var deviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v1
var deviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v1
var GetBlacklistDeviceCount = GetExcludedDeviceCount
var GetBlacklistDeviceInfoByIndex = GetExcludedDeviceInfoByIndex
var nvmlDeviceGetGpuInstancePossiblePlacements = nvmlDeviceGetGpuInstancePossiblePlacements_v1
@@ -173,127 +198,94 @@ func (pis ProcessInfo_v2Slice) ToProcessInfoSlice() []ProcessInfo {
// When new versioned symbols are added, these would have to be initialized above and have
// corresponding checks and subsequent assignments added below.
func (l *library) updateVersionedSymbols() {
err := l.Lookup("nvmlInit_v2")
err := l.dl.Lookup("nvmlInit_v2")
if err == nil {
nvmlInit = nvmlInit_v2
}
err = l.Lookup("nvmlDeviceGetPciInfo_v2")
err = l.dl.Lookup("nvmlDeviceGetPciInfo_v2")
if err == nil {
nvmlDeviceGetPciInfo = nvmlDeviceGetPciInfo_v2
}
err = l.Lookup("nvmlDeviceGetPciInfo_v3")
err = l.dl.Lookup("nvmlDeviceGetPciInfo_v3")
if err == nil {
nvmlDeviceGetPciInfo = nvmlDeviceGetPciInfo_v3
}
err = l.Lookup("nvmlDeviceGetCount_v2")
err = l.dl.Lookup("nvmlDeviceGetCount_v2")
if err == nil {
nvmlDeviceGetCount = nvmlDeviceGetCount_v2
}
err = l.Lookup("nvmlDeviceGetHandleByIndex_v2")
err = l.dl.Lookup("nvmlDeviceGetHandleByIndex_v2")
if err == nil {
nvmlDeviceGetHandleByIndex = nvmlDeviceGetHandleByIndex_v2
}
err = l.Lookup("nvmlDeviceGetHandleByPciBusId_v2")
err = l.dl.Lookup("nvmlDeviceGetHandleByPciBusId_v2")
if err == nil {
nvmlDeviceGetHandleByPciBusId = nvmlDeviceGetHandleByPciBusId_v2
}
err = l.Lookup("nvmlDeviceGetNvLinkRemotePciInfo_v2")
err = l.dl.Lookup("nvmlDeviceGetNvLinkRemotePciInfo_v2")
if err == nil {
nvmlDeviceGetNvLinkRemotePciInfo = nvmlDeviceGetNvLinkRemotePciInfo_v2
}
// Unable to overwrite nvmlDeviceRemoveGpu() because the v2 function takes
// a different set of parameters than the v1 function.
//err = l.Lookup("nvmlDeviceRemoveGpu_v2")
//err = l.dl.Lookup("nvmlDeviceRemoveGpu_v2")
//if err == nil {
// nvmlDeviceRemoveGpu = nvmlDeviceRemoveGpu_v2
//}
err = l.Lookup("nvmlDeviceGetGridLicensableFeatures_v2")
err = l.dl.Lookup("nvmlDeviceGetGridLicensableFeatures_v2")
if err == nil {
nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v2
}
err = l.Lookup("nvmlDeviceGetGridLicensableFeatures_v3")
err = l.dl.Lookup("nvmlDeviceGetGridLicensableFeatures_v3")
if err == nil {
nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v3
}
err = l.Lookup("nvmlDeviceGetGridLicensableFeatures_v4")
err = l.dl.Lookup("nvmlDeviceGetGridLicensableFeatures_v4")
if err == nil {
nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v4
}
err = l.Lookup("nvmlEventSetWait_v2")
err = l.dl.Lookup("nvmlEventSetWait_v2")
if err == nil {
nvmlEventSetWait = nvmlEventSetWait_v2
}
err = l.Lookup("nvmlDeviceGetAttributes_v2")
err = l.dl.Lookup("nvmlDeviceGetAttributes_v2")
if err == nil {
nvmlDeviceGetAttributes = nvmlDeviceGetAttributes_v2
}
err = l.Lookup("nvmlComputeInstanceGetInfo_v2")
err = l.dl.Lookup("nvmlComputeInstanceGetInfo_v2")
if err == nil {
nvmlComputeInstanceGetInfo = nvmlComputeInstanceGetInfo_v2
}
err = l.Lookup("nvmlDeviceGetComputeRunningProcesses_v2")
err = l.dl.Lookup("nvmlDeviceGetComputeRunningProcesses_v2")
if err == nil {
DeviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v2
deviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v2
}
err = l.Lookup("nvmlDeviceGetComputeRunningProcesses_v3")
err = l.dl.Lookup("nvmlDeviceGetComputeRunningProcesses_v3")
if err == nil {
DeviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v3
deviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v3
}
err = l.Lookup("nvmlDeviceGetGraphicsRunningProcesses_v2")
err = l.dl.Lookup("nvmlDeviceGetGraphicsRunningProcesses_v2")
if err == nil {
DeviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v2
deviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v2
}
err = l.Lookup("nvmlDeviceGetGraphicsRunningProcesses_v3")
err = l.dl.Lookup("nvmlDeviceGetGraphicsRunningProcesses_v3")
if err == nil {
DeviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v3
deviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v3
}
err = l.Lookup("nvmlDeviceGetMPSComputeRunningProcesses_v2")
err = l.dl.Lookup("nvmlDeviceGetMPSComputeRunningProcesses_v2")
if err == nil {
DeviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v2
deviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v2
}
err = l.Lookup("nvmlDeviceGetMPSComputeRunningProcesses_v3")
err = l.dl.Lookup("nvmlDeviceGetMPSComputeRunningProcesses_v3")
if err == nil {
DeviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v3
deviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v3
}
err = l.Lookup("nvmlDeviceGetGpuInstancePossiblePlacements_v2")
err = l.dl.Lookup("nvmlDeviceGetGpuInstancePossiblePlacements_v2")
if err == nil {
nvmlDeviceGetGpuInstancePossiblePlacements = nvmlDeviceGetGpuInstancePossiblePlacements_v2
}
err = l.Lookup("nvmlVgpuInstanceGetLicenseInfo_v2")
err = l.dl.Lookup("nvmlVgpuInstanceGetLicenseInfo_v2")
if err == nil {
nvmlVgpuInstanceGetLicenseInfo = nvmlVgpuInstanceGetLicenseInfo_v2
}
}
// LibraryOption represents a functional option to configure the underlying NVML library
type LibraryOption func(*library)
// WithLibraryPath provides an option to set the library name to be used by the NVML library.
func WithLibraryPath(path string) LibraryOption {
return func(l *library) {
l.path = path
}
}
// SetLibraryOptions applies the specified options to the NVML library.
// If this is called when a library is already loaded, and error is raised.
func SetLibraryOptions(opts ...LibraryOption) error {
libnvml.Lock()
defer libnvml.Unlock()
if libnvml.dl != nil {
return errLibraryAlreadyLoaded
}
for _, opt := range opts {
opt(&libnvml)
}
if libnvml.path == "" {
libnvml.path = defaultNvmlLibraryName
}
if libnvml.flags == 0 {
libnvml.flags = defaultNvmlLibraryLoadFlags
}
return nil
}

View File

@@ -1,40 +1,41 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package nvml
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that ComputeInstanceMock does implement ComputeInstance.
// Ensure, that ComputeInstance does implement nvml.ComputeInstance.
// If this is not the case, regenerate this file with moq.
var _ ComputeInstance = &ComputeInstanceMock{}
var _ nvml.ComputeInstance = &ComputeInstance{}
// ComputeInstanceMock is a mock implementation of ComputeInstance.
// ComputeInstance is a mock implementation of nvml.ComputeInstance.
//
// func TestSomethingThatUsesComputeInstance(t *testing.T) {
//
// // make and configure a mocked ComputeInstance
// mockedComputeInstance := &ComputeInstanceMock{
// DestroyFunc: func() Return {
// // make and configure a mocked nvml.ComputeInstance
// mockedComputeInstance := &ComputeInstance{
// DestroyFunc: func() nvml.Return {
// panic("mock out the Destroy method")
// },
// GetInfoFunc: func() (ComputeInstanceInfo, Return) {
// GetInfoFunc: func() (nvml.ComputeInstanceInfo, nvml.Return) {
// panic("mock out the GetInfo method")
// },
// }
//
// // use mockedComputeInstance in code that requires ComputeInstance
// // use mockedComputeInstance in code that requires nvml.ComputeInstance
// // and then make assertions.
//
// }
type ComputeInstanceMock struct {
type ComputeInstance struct {
// DestroyFunc mocks the Destroy method.
DestroyFunc func() Return
DestroyFunc func() nvml.Return
// GetInfoFunc mocks the GetInfo method.
GetInfoFunc func() (ComputeInstanceInfo, Return)
GetInfoFunc func() (nvml.ComputeInstanceInfo, nvml.Return)
// calls tracks calls to the methods.
calls struct {
@@ -50,9 +51,9 @@ type ComputeInstanceMock struct {
}
// Destroy calls DestroyFunc.
func (mock *ComputeInstanceMock) Destroy() Return {
func (mock *ComputeInstance) Destroy() nvml.Return {
if mock.DestroyFunc == nil {
panic("ComputeInstanceMock.DestroyFunc: method is nil but ComputeInstance.Destroy was just called")
panic("ComputeInstance.DestroyFunc: method is nil but ComputeInstance.Destroy was just called")
}
callInfo := struct {
}{}
@@ -66,7 +67,7 @@ func (mock *ComputeInstanceMock) Destroy() Return {
// Check the length with:
//
// len(mockedComputeInstance.DestroyCalls())
func (mock *ComputeInstanceMock) DestroyCalls() []struct {
func (mock *ComputeInstance) DestroyCalls() []struct {
} {
var calls []struct {
}
@@ -77,9 +78,9 @@ func (mock *ComputeInstanceMock) DestroyCalls() []struct {
}
// GetInfo calls GetInfoFunc.
func (mock *ComputeInstanceMock) GetInfo() (ComputeInstanceInfo, Return) {
func (mock *ComputeInstance) GetInfo() (nvml.ComputeInstanceInfo, nvml.Return) {
if mock.GetInfoFunc == nil {
panic("ComputeInstanceMock.GetInfoFunc: method is nil but ComputeInstance.GetInfo was just called")
panic("ComputeInstance.GetInfoFunc: method is nil but ComputeInstance.GetInfo was just called")
}
callInfo := struct {
}{}
@@ -93,7 +94,7 @@ func (mock *ComputeInstanceMock) GetInfo() (ComputeInstanceInfo, Return) {
// Check the length with:
//
// len(mockedComputeInstance.GetInfoCalls())
func (mock *ComputeInstanceMock) GetInfoCalls() []struct {
func (mock *ComputeInstance) GetInfoCalls() []struct {
} {
var calls []struct {
}

8283
vendor/github.com/NVIDIA/go-nvml/pkg/nvml/mock/device.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,112 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that EventSet does implement nvml.EventSet.
// If this is not the case, regenerate this file with moq.
var _ nvml.EventSet = &EventSet{}
// EventSet is a mock implementation of nvml.EventSet.
//
// func TestSomethingThatUsesEventSet(t *testing.T) {
//
// // make and configure a mocked nvml.EventSet
// mockedEventSet := &EventSet{
// FreeFunc: func() nvml.Return {
// panic("mock out the Free method")
// },
// WaitFunc: func(v uint32) (nvml.EventData, nvml.Return) {
// panic("mock out the Wait method")
// },
// }
//
// // use mockedEventSet in code that requires nvml.EventSet
// // and then make assertions.
//
// }
type EventSet struct {
// FreeFunc mocks the Free method.
FreeFunc func() nvml.Return
// WaitFunc mocks the Wait method.
WaitFunc func(v uint32) (nvml.EventData, nvml.Return)
// calls tracks calls to the methods.
calls struct {
// Free holds details about calls to the Free method.
Free []struct {
}
// Wait holds details about calls to the Wait method.
Wait []struct {
// V is the v argument value.
V uint32
}
}
lockFree sync.RWMutex
lockWait sync.RWMutex
}
// Free calls FreeFunc.
func (mock *EventSet) Free() nvml.Return {
if mock.FreeFunc == nil {
panic("EventSet.FreeFunc: method is nil but EventSet.Free was just called")
}
callInfo := struct {
}{}
mock.lockFree.Lock()
mock.calls.Free = append(mock.calls.Free, callInfo)
mock.lockFree.Unlock()
return mock.FreeFunc()
}
// FreeCalls gets all the calls that were made to Free.
// Check the length with:
//
// len(mockedEventSet.FreeCalls())
func (mock *EventSet) FreeCalls() []struct {
} {
var calls []struct {
}
mock.lockFree.RLock()
calls = mock.calls.Free
mock.lockFree.RUnlock()
return calls
}
// Wait calls WaitFunc.
func (mock *EventSet) Wait(v uint32) (nvml.EventData, nvml.Return) {
if mock.WaitFunc == nil {
panic("EventSet.WaitFunc: method is nil but EventSet.Wait was just called")
}
callInfo := struct {
V uint32
}{
V: v,
}
mock.lockWait.Lock()
mock.calls.Wait = append(mock.calls.Wait, callInfo)
mock.lockWait.Unlock()
return mock.WaitFunc(v)
}
// WaitCalls gets all the calls that were made to Wait.
// Check the length with:
//
// len(mockedEventSet.WaitCalls())
func (mock *EventSet) WaitCalls() []struct {
V uint32
} {
var calls []struct {
V uint32
}
mock.lockWait.RLock()
calls = mock.calls.Wait
mock.lockWait.RUnlock()
return calls
}

View File

@@ -0,0 +1,75 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that ExtendedInterface does implement nvml.ExtendedInterface.
// If this is not the case, regenerate this file with moq.
var _ nvml.ExtendedInterface = &ExtendedInterface{}
// ExtendedInterface is a mock implementation of nvml.ExtendedInterface.
//
// func TestSomethingThatUsesExtendedInterface(t *testing.T) {
//
// // make and configure a mocked nvml.ExtendedInterface
// mockedExtendedInterface := &ExtendedInterface{
// LookupSymbolFunc: func(s string) error {
// panic("mock out the LookupSymbol method")
// },
// }
//
// // use mockedExtendedInterface in code that requires nvml.ExtendedInterface
// // and then make assertions.
//
// }
type ExtendedInterface struct {
// LookupSymbolFunc mocks the LookupSymbol method.
LookupSymbolFunc func(s string) error
// calls tracks calls to the methods.
calls struct {
// LookupSymbol holds details about calls to the LookupSymbol method.
LookupSymbol []struct {
// S is the s argument value.
S string
}
}
lockLookupSymbol sync.RWMutex
}
// LookupSymbol calls LookupSymbolFunc.
func (mock *ExtendedInterface) LookupSymbol(s string) error {
if mock.LookupSymbolFunc == nil {
panic("ExtendedInterface.LookupSymbolFunc: method is nil but ExtendedInterface.LookupSymbol was just called")
}
callInfo := struct {
S string
}{
S: s,
}
mock.lockLookupSymbol.Lock()
mock.calls.LookupSymbol = append(mock.calls.LookupSymbol, callInfo)
mock.lockLookupSymbol.Unlock()
return mock.LookupSymbolFunc(s)
}
// LookupSymbolCalls gets all the calls that were made to LookupSymbol.
// Check the length with:
//
// len(mockedExtendedInterface.LookupSymbolCalls())
func (mock *ExtendedInterface) LookupSymbolCalls() []struct {
S string
} {
var calls []struct {
S string
}
mock.lockLookupSymbol.RLock()
calls = mock.calls.LookupSymbol
mock.lockLookupSymbol.RUnlock()
return calls
}

View File

@@ -0,0 +1,162 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that GpmSample does implement nvml.GpmSample.
// If this is not the case, regenerate this file with moq.
var _ nvml.GpmSample = &GpmSample{}
// GpmSample is a mock implementation of nvml.GpmSample.
//
// func TestSomethingThatUsesGpmSample(t *testing.T) {
//
// // make and configure a mocked nvml.GpmSample
// mockedGpmSample := &GpmSample{
// FreeFunc: func() nvml.Return {
// panic("mock out the Free method")
// },
// GetFunc: func(device nvml.Device) nvml.Return {
// panic("mock out the Get method")
// },
// MigGetFunc: func(device nvml.Device, n int) nvml.Return {
// panic("mock out the MigGet method")
// },
// }
//
// // use mockedGpmSample in code that requires nvml.GpmSample
// // and then make assertions.
//
// }
type GpmSample struct {
// FreeFunc mocks the Free method.
FreeFunc func() nvml.Return
// GetFunc mocks the Get method.
GetFunc func(device nvml.Device) nvml.Return
// MigGetFunc mocks the MigGet method.
MigGetFunc func(device nvml.Device, n int) nvml.Return
// calls tracks calls to the methods.
calls struct {
// Free holds details about calls to the Free method.
Free []struct {
}
// Get holds details about calls to the Get method.
Get []struct {
// Device is the device argument value.
Device nvml.Device
}
// MigGet holds details about calls to the MigGet method.
MigGet []struct {
// Device is the device argument value.
Device nvml.Device
// N is the n argument value.
N int
}
}
lockFree sync.RWMutex
lockGet sync.RWMutex
lockMigGet sync.RWMutex
}
// Free calls FreeFunc.
func (mock *GpmSample) Free() nvml.Return {
if mock.FreeFunc == nil {
panic("GpmSample.FreeFunc: method is nil but GpmSample.Free was just called")
}
callInfo := struct {
}{}
mock.lockFree.Lock()
mock.calls.Free = append(mock.calls.Free, callInfo)
mock.lockFree.Unlock()
return mock.FreeFunc()
}
// FreeCalls gets all the calls that were made to Free.
// Check the length with:
//
// len(mockedGpmSample.FreeCalls())
func (mock *GpmSample) FreeCalls() []struct {
} {
var calls []struct {
}
mock.lockFree.RLock()
calls = mock.calls.Free
mock.lockFree.RUnlock()
return calls
}
// Get calls GetFunc.
func (mock *GpmSample) Get(device nvml.Device) nvml.Return {
if mock.GetFunc == nil {
panic("GpmSample.GetFunc: method is nil but GpmSample.Get was just called")
}
callInfo := struct {
Device nvml.Device
}{
Device: device,
}
mock.lockGet.Lock()
mock.calls.Get = append(mock.calls.Get, callInfo)
mock.lockGet.Unlock()
return mock.GetFunc(device)
}
// GetCalls gets all the calls that were made to Get.
// Check the length with:
//
// len(mockedGpmSample.GetCalls())
func (mock *GpmSample) GetCalls() []struct {
Device nvml.Device
} {
var calls []struct {
Device nvml.Device
}
mock.lockGet.RLock()
calls = mock.calls.Get
mock.lockGet.RUnlock()
return calls
}
// MigGet calls MigGetFunc.
func (mock *GpmSample) MigGet(device nvml.Device, n int) nvml.Return {
if mock.MigGetFunc == nil {
panic("GpmSample.MigGetFunc: method is nil but GpmSample.MigGet was just called")
}
callInfo := struct {
Device nvml.Device
N int
}{
Device: device,
N: n,
}
mock.lockMigGet.Lock()
mock.calls.MigGet = append(mock.calls.MigGet, callInfo)
mock.lockMigGet.Unlock()
return mock.MigGetFunc(device, n)
}
// MigGetCalls gets all the calls that were made to MigGet.
// Check the length with:
//
// len(mockedGpmSample.MigGetCalls())
func (mock *GpmSample) MigGetCalls() []struct {
Device nvml.Device
N int
} {
var calls []struct {
Device nvml.Device
N int
}
mock.lockMigGet.RLock()
calls = mock.calls.MigGet
mock.lockMigGet.RUnlock()
return calls
}

View File

@@ -0,0 +1,475 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that GpuInstance does implement nvml.GpuInstance.
// If this is not the case, regenerate this file with moq.
var _ nvml.GpuInstance = &GpuInstance{}
// GpuInstance is a mock implementation of nvml.GpuInstance.
//
// func TestSomethingThatUsesGpuInstance(t *testing.T) {
//
// // make and configure a mocked nvml.GpuInstance
// mockedGpuInstance := &GpuInstance{
// CreateComputeInstanceFunc: func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) (nvml.ComputeInstance, nvml.Return) {
// panic("mock out the CreateComputeInstance method")
// },
// CreateComputeInstanceWithPlacementFunc: func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo, computeInstancePlacement *nvml.ComputeInstancePlacement) (nvml.ComputeInstance, nvml.Return) {
// panic("mock out the CreateComputeInstanceWithPlacement method")
// },
// DestroyFunc: func() nvml.Return {
// panic("mock out the Destroy method")
// },
// GetComputeInstanceByIdFunc: func(n int) (nvml.ComputeInstance, nvml.Return) {
// panic("mock out the GetComputeInstanceById method")
// },
// GetComputeInstancePossiblePlacementsFunc: func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) ([]nvml.ComputeInstancePlacement, nvml.Return) {
// panic("mock out the GetComputeInstancePossiblePlacements method")
// },
// GetComputeInstanceProfileInfoFunc: func(n1 int, n2 int) (nvml.ComputeInstanceProfileInfo, nvml.Return) {
// panic("mock out the GetComputeInstanceProfileInfo method")
// },
// GetComputeInstanceProfileInfoVFunc: func(n1 int, n2 int) nvml.ComputeInstanceProfileInfoV {
// panic("mock out the GetComputeInstanceProfileInfoV method")
// },
// GetComputeInstanceRemainingCapacityFunc: func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) (int, nvml.Return) {
// panic("mock out the GetComputeInstanceRemainingCapacity method")
// },
// GetComputeInstancesFunc: func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) ([]nvml.ComputeInstance, nvml.Return) {
// panic("mock out the GetComputeInstances method")
// },
// GetInfoFunc: func() (nvml.GpuInstanceInfo, nvml.Return) {
// panic("mock out the GetInfo method")
// },
// }
//
// // use mockedGpuInstance in code that requires nvml.GpuInstance
// // and then make assertions.
//
// }
type GpuInstance struct {
// CreateComputeInstanceFunc mocks the CreateComputeInstance method.
CreateComputeInstanceFunc func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) (nvml.ComputeInstance, nvml.Return)
// CreateComputeInstanceWithPlacementFunc mocks the CreateComputeInstanceWithPlacement method.
CreateComputeInstanceWithPlacementFunc func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo, computeInstancePlacement *nvml.ComputeInstancePlacement) (nvml.ComputeInstance, nvml.Return)
// DestroyFunc mocks the Destroy method.
DestroyFunc func() nvml.Return
// GetComputeInstanceByIdFunc mocks the GetComputeInstanceById method.
GetComputeInstanceByIdFunc func(n int) (nvml.ComputeInstance, nvml.Return)
// GetComputeInstancePossiblePlacementsFunc mocks the GetComputeInstancePossiblePlacements method.
GetComputeInstancePossiblePlacementsFunc func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) ([]nvml.ComputeInstancePlacement, nvml.Return)
// GetComputeInstanceProfileInfoFunc mocks the GetComputeInstanceProfileInfo method.
GetComputeInstanceProfileInfoFunc func(n1 int, n2 int) (nvml.ComputeInstanceProfileInfo, nvml.Return)
// GetComputeInstanceProfileInfoVFunc mocks the GetComputeInstanceProfileInfoV method.
GetComputeInstanceProfileInfoVFunc func(n1 int, n2 int) nvml.ComputeInstanceProfileInfoV
// GetComputeInstanceRemainingCapacityFunc mocks the GetComputeInstanceRemainingCapacity method.
GetComputeInstanceRemainingCapacityFunc func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) (int, nvml.Return)
// GetComputeInstancesFunc mocks the GetComputeInstances method.
GetComputeInstancesFunc func(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) ([]nvml.ComputeInstance, nvml.Return)
// GetInfoFunc mocks the GetInfo method.
GetInfoFunc func() (nvml.GpuInstanceInfo, nvml.Return)
// calls tracks calls to the methods.
calls struct {
// CreateComputeInstance holds details about calls to the CreateComputeInstance method.
CreateComputeInstance []struct {
// ComputeInstanceProfileInfo is the computeInstanceProfileInfo argument value.
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
// CreateComputeInstanceWithPlacement holds details about calls to the CreateComputeInstanceWithPlacement method.
CreateComputeInstanceWithPlacement []struct {
// ComputeInstanceProfileInfo is the computeInstanceProfileInfo argument value.
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
// ComputeInstancePlacement is the computeInstancePlacement argument value.
ComputeInstancePlacement *nvml.ComputeInstancePlacement
}
// Destroy holds details about calls to the Destroy method.
Destroy []struct {
}
// GetComputeInstanceById holds details about calls to the GetComputeInstanceById method.
GetComputeInstanceById []struct {
// N is the n argument value.
N int
}
// GetComputeInstancePossiblePlacements holds details about calls to the GetComputeInstancePossiblePlacements method.
GetComputeInstancePossiblePlacements []struct {
// ComputeInstanceProfileInfo is the computeInstanceProfileInfo argument value.
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
// GetComputeInstanceProfileInfo holds details about calls to the GetComputeInstanceProfileInfo method.
GetComputeInstanceProfileInfo []struct {
// N1 is the n1 argument value.
N1 int
// N2 is the n2 argument value.
N2 int
}
// GetComputeInstanceProfileInfoV holds details about calls to the GetComputeInstanceProfileInfoV method.
GetComputeInstanceProfileInfoV []struct {
// N1 is the n1 argument value.
N1 int
// N2 is the n2 argument value.
N2 int
}
// GetComputeInstanceRemainingCapacity holds details about calls to the GetComputeInstanceRemainingCapacity method.
GetComputeInstanceRemainingCapacity []struct {
// ComputeInstanceProfileInfo is the computeInstanceProfileInfo argument value.
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
// GetComputeInstances holds details about calls to the GetComputeInstances method.
GetComputeInstances []struct {
// ComputeInstanceProfileInfo is the computeInstanceProfileInfo argument value.
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
// GetInfo holds details about calls to the GetInfo method.
GetInfo []struct {
}
}
lockCreateComputeInstance sync.RWMutex
lockCreateComputeInstanceWithPlacement sync.RWMutex
lockDestroy sync.RWMutex
lockGetComputeInstanceById sync.RWMutex
lockGetComputeInstancePossiblePlacements sync.RWMutex
lockGetComputeInstanceProfileInfo sync.RWMutex
lockGetComputeInstanceProfileInfoV sync.RWMutex
lockGetComputeInstanceRemainingCapacity sync.RWMutex
lockGetComputeInstances sync.RWMutex
lockGetInfo sync.RWMutex
}
// CreateComputeInstance calls CreateComputeInstanceFunc.
func (mock *GpuInstance) CreateComputeInstance(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) (nvml.ComputeInstance, nvml.Return) {
if mock.CreateComputeInstanceFunc == nil {
panic("GpuInstance.CreateComputeInstanceFunc: method is nil but GpuInstance.CreateComputeInstance was just called")
}
callInfo := struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}{
ComputeInstanceProfileInfo: computeInstanceProfileInfo,
}
mock.lockCreateComputeInstance.Lock()
mock.calls.CreateComputeInstance = append(mock.calls.CreateComputeInstance, callInfo)
mock.lockCreateComputeInstance.Unlock()
return mock.CreateComputeInstanceFunc(computeInstanceProfileInfo)
}
// CreateComputeInstanceCalls gets all the calls that were made to CreateComputeInstance.
// Check the length with:
//
// len(mockedGpuInstance.CreateComputeInstanceCalls())
func (mock *GpuInstance) CreateComputeInstanceCalls() []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
} {
var calls []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
mock.lockCreateComputeInstance.RLock()
calls = mock.calls.CreateComputeInstance
mock.lockCreateComputeInstance.RUnlock()
return calls
}
// CreateComputeInstanceWithPlacement calls CreateComputeInstanceWithPlacementFunc.
func (mock *GpuInstance) CreateComputeInstanceWithPlacement(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo, computeInstancePlacement *nvml.ComputeInstancePlacement) (nvml.ComputeInstance, nvml.Return) {
if mock.CreateComputeInstanceWithPlacementFunc == nil {
panic("GpuInstance.CreateComputeInstanceWithPlacementFunc: method is nil but GpuInstance.CreateComputeInstanceWithPlacement was just called")
}
callInfo := struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
ComputeInstancePlacement *nvml.ComputeInstancePlacement
}{
ComputeInstanceProfileInfo: computeInstanceProfileInfo,
ComputeInstancePlacement: computeInstancePlacement,
}
mock.lockCreateComputeInstanceWithPlacement.Lock()
mock.calls.CreateComputeInstanceWithPlacement = append(mock.calls.CreateComputeInstanceWithPlacement, callInfo)
mock.lockCreateComputeInstanceWithPlacement.Unlock()
return mock.CreateComputeInstanceWithPlacementFunc(computeInstanceProfileInfo, computeInstancePlacement)
}
// CreateComputeInstanceWithPlacementCalls gets all the calls that were made to CreateComputeInstanceWithPlacement.
// Check the length with:
//
// len(mockedGpuInstance.CreateComputeInstanceWithPlacementCalls())
func (mock *GpuInstance) CreateComputeInstanceWithPlacementCalls() []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
ComputeInstancePlacement *nvml.ComputeInstancePlacement
} {
var calls []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
ComputeInstancePlacement *nvml.ComputeInstancePlacement
}
mock.lockCreateComputeInstanceWithPlacement.RLock()
calls = mock.calls.CreateComputeInstanceWithPlacement
mock.lockCreateComputeInstanceWithPlacement.RUnlock()
return calls
}
// Destroy calls DestroyFunc.
func (mock *GpuInstance) Destroy() nvml.Return {
if mock.DestroyFunc == nil {
panic("GpuInstance.DestroyFunc: method is nil but GpuInstance.Destroy was just called")
}
callInfo := struct {
}{}
mock.lockDestroy.Lock()
mock.calls.Destroy = append(mock.calls.Destroy, callInfo)
mock.lockDestroy.Unlock()
return mock.DestroyFunc()
}
// DestroyCalls gets all the calls that were made to Destroy.
// Check the length with:
//
// len(mockedGpuInstance.DestroyCalls())
func (mock *GpuInstance) DestroyCalls() []struct {
} {
var calls []struct {
}
mock.lockDestroy.RLock()
calls = mock.calls.Destroy
mock.lockDestroy.RUnlock()
return calls
}
// GetComputeInstanceById calls GetComputeInstanceByIdFunc.
func (mock *GpuInstance) GetComputeInstanceById(n int) (nvml.ComputeInstance, nvml.Return) {
if mock.GetComputeInstanceByIdFunc == nil {
panic("GpuInstance.GetComputeInstanceByIdFunc: method is nil but GpuInstance.GetComputeInstanceById was just called")
}
callInfo := struct {
N int
}{
N: n,
}
mock.lockGetComputeInstanceById.Lock()
mock.calls.GetComputeInstanceById = append(mock.calls.GetComputeInstanceById, callInfo)
mock.lockGetComputeInstanceById.Unlock()
return mock.GetComputeInstanceByIdFunc(n)
}
// GetComputeInstanceByIdCalls gets all the calls that were made to GetComputeInstanceById.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstanceByIdCalls())
func (mock *GpuInstance) GetComputeInstanceByIdCalls() []struct {
N int
} {
var calls []struct {
N int
}
mock.lockGetComputeInstanceById.RLock()
calls = mock.calls.GetComputeInstanceById
mock.lockGetComputeInstanceById.RUnlock()
return calls
}
// GetComputeInstancePossiblePlacements calls GetComputeInstancePossiblePlacementsFunc.
func (mock *GpuInstance) GetComputeInstancePossiblePlacements(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) ([]nvml.ComputeInstancePlacement, nvml.Return) {
if mock.GetComputeInstancePossiblePlacementsFunc == nil {
panic("GpuInstance.GetComputeInstancePossiblePlacementsFunc: method is nil but GpuInstance.GetComputeInstancePossiblePlacements was just called")
}
callInfo := struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}{
ComputeInstanceProfileInfo: computeInstanceProfileInfo,
}
mock.lockGetComputeInstancePossiblePlacements.Lock()
mock.calls.GetComputeInstancePossiblePlacements = append(mock.calls.GetComputeInstancePossiblePlacements, callInfo)
mock.lockGetComputeInstancePossiblePlacements.Unlock()
return mock.GetComputeInstancePossiblePlacementsFunc(computeInstanceProfileInfo)
}
// GetComputeInstancePossiblePlacementsCalls gets all the calls that were made to GetComputeInstancePossiblePlacements.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstancePossiblePlacementsCalls())
func (mock *GpuInstance) GetComputeInstancePossiblePlacementsCalls() []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
} {
var calls []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
mock.lockGetComputeInstancePossiblePlacements.RLock()
calls = mock.calls.GetComputeInstancePossiblePlacements
mock.lockGetComputeInstancePossiblePlacements.RUnlock()
return calls
}
// GetComputeInstanceProfileInfo calls GetComputeInstanceProfileInfoFunc.
func (mock *GpuInstance) GetComputeInstanceProfileInfo(n1 int, n2 int) (nvml.ComputeInstanceProfileInfo, nvml.Return) {
if mock.GetComputeInstanceProfileInfoFunc == nil {
panic("GpuInstance.GetComputeInstanceProfileInfoFunc: method is nil but GpuInstance.GetComputeInstanceProfileInfo was just called")
}
callInfo := struct {
N1 int
N2 int
}{
N1: n1,
N2: n2,
}
mock.lockGetComputeInstanceProfileInfo.Lock()
mock.calls.GetComputeInstanceProfileInfo = append(mock.calls.GetComputeInstanceProfileInfo, callInfo)
mock.lockGetComputeInstanceProfileInfo.Unlock()
return mock.GetComputeInstanceProfileInfoFunc(n1, n2)
}
// GetComputeInstanceProfileInfoCalls gets all the calls that were made to GetComputeInstanceProfileInfo.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstanceProfileInfoCalls())
func (mock *GpuInstance) GetComputeInstanceProfileInfoCalls() []struct {
N1 int
N2 int
} {
var calls []struct {
N1 int
N2 int
}
mock.lockGetComputeInstanceProfileInfo.RLock()
calls = mock.calls.GetComputeInstanceProfileInfo
mock.lockGetComputeInstanceProfileInfo.RUnlock()
return calls
}
// GetComputeInstanceProfileInfoV calls GetComputeInstanceProfileInfoVFunc.
func (mock *GpuInstance) GetComputeInstanceProfileInfoV(n1 int, n2 int) nvml.ComputeInstanceProfileInfoV {
if mock.GetComputeInstanceProfileInfoVFunc == nil {
panic("GpuInstance.GetComputeInstanceProfileInfoVFunc: method is nil but GpuInstance.GetComputeInstanceProfileInfoV was just called")
}
callInfo := struct {
N1 int
N2 int
}{
N1: n1,
N2: n2,
}
mock.lockGetComputeInstanceProfileInfoV.Lock()
mock.calls.GetComputeInstanceProfileInfoV = append(mock.calls.GetComputeInstanceProfileInfoV, callInfo)
mock.lockGetComputeInstanceProfileInfoV.Unlock()
return mock.GetComputeInstanceProfileInfoVFunc(n1, n2)
}
// GetComputeInstanceProfileInfoVCalls gets all the calls that were made to GetComputeInstanceProfileInfoV.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstanceProfileInfoVCalls())
func (mock *GpuInstance) GetComputeInstanceProfileInfoVCalls() []struct {
N1 int
N2 int
} {
var calls []struct {
N1 int
N2 int
}
mock.lockGetComputeInstanceProfileInfoV.RLock()
calls = mock.calls.GetComputeInstanceProfileInfoV
mock.lockGetComputeInstanceProfileInfoV.RUnlock()
return calls
}
// GetComputeInstanceRemainingCapacity calls GetComputeInstanceRemainingCapacityFunc.
func (mock *GpuInstance) GetComputeInstanceRemainingCapacity(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) (int, nvml.Return) {
if mock.GetComputeInstanceRemainingCapacityFunc == nil {
panic("GpuInstance.GetComputeInstanceRemainingCapacityFunc: method is nil but GpuInstance.GetComputeInstanceRemainingCapacity was just called")
}
callInfo := struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}{
ComputeInstanceProfileInfo: computeInstanceProfileInfo,
}
mock.lockGetComputeInstanceRemainingCapacity.Lock()
mock.calls.GetComputeInstanceRemainingCapacity = append(mock.calls.GetComputeInstanceRemainingCapacity, callInfo)
mock.lockGetComputeInstanceRemainingCapacity.Unlock()
return mock.GetComputeInstanceRemainingCapacityFunc(computeInstanceProfileInfo)
}
// GetComputeInstanceRemainingCapacityCalls gets all the calls that were made to GetComputeInstanceRemainingCapacity.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstanceRemainingCapacityCalls())
func (mock *GpuInstance) GetComputeInstanceRemainingCapacityCalls() []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
} {
var calls []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
mock.lockGetComputeInstanceRemainingCapacity.RLock()
calls = mock.calls.GetComputeInstanceRemainingCapacity
mock.lockGetComputeInstanceRemainingCapacity.RUnlock()
return calls
}
// GetComputeInstances calls GetComputeInstancesFunc.
func (mock *GpuInstance) GetComputeInstances(computeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo) ([]nvml.ComputeInstance, nvml.Return) {
if mock.GetComputeInstancesFunc == nil {
panic("GpuInstance.GetComputeInstancesFunc: method is nil but GpuInstance.GetComputeInstances was just called")
}
callInfo := struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}{
ComputeInstanceProfileInfo: computeInstanceProfileInfo,
}
mock.lockGetComputeInstances.Lock()
mock.calls.GetComputeInstances = append(mock.calls.GetComputeInstances, callInfo)
mock.lockGetComputeInstances.Unlock()
return mock.GetComputeInstancesFunc(computeInstanceProfileInfo)
}
// GetComputeInstancesCalls gets all the calls that were made to GetComputeInstances.
// Check the length with:
//
// len(mockedGpuInstance.GetComputeInstancesCalls())
func (mock *GpuInstance) GetComputeInstancesCalls() []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
} {
var calls []struct {
ComputeInstanceProfileInfo *nvml.ComputeInstanceProfileInfo
}
mock.lockGetComputeInstances.RLock()
calls = mock.calls.GetComputeInstances
mock.lockGetComputeInstances.RUnlock()
return calls
}
// GetInfo calls GetInfoFunc.
func (mock *GpuInstance) GetInfo() (nvml.GpuInstanceInfo, nvml.Return) {
if mock.GetInfoFunc == nil {
panic("GpuInstance.GetInfoFunc: method is nil but GpuInstance.GetInfo was just called")
}
callInfo := struct {
}{}
mock.lockGetInfo.Lock()
mock.calls.GetInfo = append(mock.calls.GetInfo, callInfo)
mock.lockGetInfo.Unlock()
return mock.GetInfoFunc()
}
// GetInfoCalls gets all the calls that were made to GetInfo.
// Check the length with:
//
// len(mockedGpuInstance.GetInfoCalls())
func (mock *GpuInstance) GetInfoCalls() []struct {
} {
var calls []struct {
}
mock.lockGetInfo.RLock()
calls = mock.calls.GetInfo
mock.lockGetInfo.RUnlock()
return calls
}

File diff suppressed because it is too large Load Diff

304
vendor/github.com/NVIDIA/go-nvml/pkg/nvml/mock/unit.go generated vendored Normal file
View File

@@ -0,0 +1,304 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that Unit does implement nvml.Unit.
// If this is not the case, regenerate this file with moq.
var _ nvml.Unit = &Unit{}
// Unit is a mock implementation of nvml.Unit.
//
// func TestSomethingThatUsesUnit(t *testing.T) {
//
// // make and configure a mocked nvml.Unit
// mockedUnit := &Unit{
// GetDevicesFunc: func() ([]nvml.Device, nvml.Return) {
// panic("mock out the GetDevices method")
// },
// GetFanSpeedInfoFunc: func() (nvml.UnitFanSpeeds, nvml.Return) {
// panic("mock out the GetFanSpeedInfo method")
// },
// GetLedStateFunc: func() (nvml.LedState, nvml.Return) {
// panic("mock out the GetLedState method")
// },
// GetPsuInfoFunc: func() (nvml.PSUInfo, nvml.Return) {
// panic("mock out the GetPsuInfo method")
// },
// GetTemperatureFunc: func(n int) (uint32, nvml.Return) {
// panic("mock out the GetTemperature method")
// },
// GetUnitInfoFunc: func() (nvml.UnitInfo, nvml.Return) {
// panic("mock out the GetUnitInfo method")
// },
// SetLedStateFunc: func(ledColor nvml.LedColor) nvml.Return {
// panic("mock out the SetLedState method")
// },
// }
//
// // use mockedUnit in code that requires nvml.Unit
// // and then make assertions.
//
// }
type Unit struct {
// GetDevicesFunc mocks the GetDevices method.
GetDevicesFunc func() ([]nvml.Device, nvml.Return)
// GetFanSpeedInfoFunc mocks the GetFanSpeedInfo method.
GetFanSpeedInfoFunc func() (nvml.UnitFanSpeeds, nvml.Return)
// GetLedStateFunc mocks the GetLedState method.
GetLedStateFunc func() (nvml.LedState, nvml.Return)
// GetPsuInfoFunc mocks the GetPsuInfo method.
GetPsuInfoFunc func() (nvml.PSUInfo, nvml.Return)
// GetTemperatureFunc mocks the GetTemperature method.
GetTemperatureFunc func(n int) (uint32, nvml.Return)
// GetUnitInfoFunc mocks the GetUnitInfo method.
GetUnitInfoFunc func() (nvml.UnitInfo, nvml.Return)
// SetLedStateFunc mocks the SetLedState method.
SetLedStateFunc func(ledColor nvml.LedColor) nvml.Return
// calls tracks calls to the methods.
calls struct {
// GetDevices holds details about calls to the GetDevices method.
GetDevices []struct {
}
// GetFanSpeedInfo holds details about calls to the GetFanSpeedInfo method.
GetFanSpeedInfo []struct {
}
// GetLedState holds details about calls to the GetLedState method.
GetLedState []struct {
}
// GetPsuInfo holds details about calls to the GetPsuInfo method.
GetPsuInfo []struct {
}
// GetTemperature holds details about calls to the GetTemperature method.
GetTemperature []struct {
// N is the n argument value.
N int
}
// GetUnitInfo holds details about calls to the GetUnitInfo method.
GetUnitInfo []struct {
}
// SetLedState holds details about calls to the SetLedState method.
SetLedState []struct {
// LedColor is the ledColor argument value.
LedColor nvml.LedColor
}
}
lockGetDevices sync.RWMutex
lockGetFanSpeedInfo sync.RWMutex
lockGetLedState sync.RWMutex
lockGetPsuInfo sync.RWMutex
lockGetTemperature sync.RWMutex
lockGetUnitInfo sync.RWMutex
lockSetLedState sync.RWMutex
}
// GetDevices calls GetDevicesFunc.
func (mock *Unit) GetDevices() ([]nvml.Device, nvml.Return) {
if mock.GetDevicesFunc == nil {
panic("Unit.GetDevicesFunc: method is nil but Unit.GetDevices was just called")
}
callInfo := struct {
}{}
mock.lockGetDevices.Lock()
mock.calls.GetDevices = append(mock.calls.GetDevices, callInfo)
mock.lockGetDevices.Unlock()
return mock.GetDevicesFunc()
}
// GetDevicesCalls gets all the calls that were made to GetDevices.
// Check the length with:
//
// len(mockedUnit.GetDevicesCalls())
func (mock *Unit) GetDevicesCalls() []struct {
} {
var calls []struct {
}
mock.lockGetDevices.RLock()
calls = mock.calls.GetDevices
mock.lockGetDevices.RUnlock()
return calls
}
// GetFanSpeedInfo calls GetFanSpeedInfoFunc.
func (mock *Unit) GetFanSpeedInfo() (nvml.UnitFanSpeeds, nvml.Return) {
if mock.GetFanSpeedInfoFunc == nil {
panic("Unit.GetFanSpeedInfoFunc: method is nil but Unit.GetFanSpeedInfo was just called")
}
callInfo := struct {
}{}
mock.lockGetFanSpeedInfo.Lock()
mock.calls.GetFanSpeedInfo = append(mock.calls.GetFanSpeedInfo, callInfo)
mock.lockGetFanSpeedInfo.Unlock()
return mock.GetFanSpeedInfoFunc()
}
// GetFanSpeedInfoCalls gets all the calls that were made to GetFanSpeedInfo.
// Check the length with:
//
// len(mockedUnit.GetFanSpeedInfoCalls())
func (mock *Unit) GetFanSpeedInfoCalls() []struct {
} {
var calls []struct {
}
mock.lockGetFanSpeedInfo.RLock()
calls = mock.calls.GetFanSpeedInfo
mock.lockGetFanSpeedInfo.RUnlock()
return calls
}
// GetLedState calls GetLedStateFunc.
func (mock *Unit) GetLedState() (nvml.LedState, nvml.Return) {
if mock.GetLedStateFunc == nil {
panic("Unit.GetLedStateFunc: method is nil but Unit.GetLedState was just called")
}
callInfo := struct {
}{}
mock.lockGetLedState.Lock()
mock.calls.GetLedState = append(mock.calls.GetLedState, callInfo)
mock.lockGetLedState.Unlock()
return mock.GetLedStateFunc()
}
// GetLedStateCalls gets all the calls that were made to GetLedState.
// Check the length with:
//
// len(mockedUnit.GetLedStateCalls())
func (mock *Unit) GetLedStateCalls() []struct {
} {
var calls []struct {
}
mock.lockGetLedState.RLock()
calls = mock.calls.GetLedState
mock.lockGetLedState.RUnlock()
return calls
}
// GetPsuInfo calls GetPsuInfoFunc.
func (mock *Unit) GetPsuInfo() (nvml.PSUInfo, nvml.Return) {
if mock.GetPsuInfoFunc == nil {
panic("Unit.GetPsuInfoFunc: method is nil but Unit.GetPsuInfo was just called")
}
callInfo := struct {
}{}
mock.lockGetPsuInfo.Lock()
mock.calls.GetPsuInfo = append(mock.calls.GetPsuInfo, callInfo)
mock.lockGetPsuInfo.Unlock()
return mock.GetPsuInfoFunc()
}
// GetPsuInfoCalls gets all the calls that were made to GetPsuInfo.
// Check the length with:
//
// len(mockedUnit.GetPsuInfoCalls())
func (mock *Unit) GetPsuInfoCalls() []struct {
} {
var calls []struct {
}
mock.lockGetPsuInfo.RLock()
calls = mock.calls.GetPsuInfo
mock.lockGetPsuInfo.RUnlock()
return calls
}
// GetTemperature calls GetTemperatureFunc.
func (mock *Unit) GetTemperature(n int) (uint32, nvml.Return) {
if mock.GetTemperatureFunc == nil {
panic("Unit.GetTemperatureFunc: method is nil but Unit.GetTemperature was just called")
}
callInfo := struct {
N int
}{
N: n,
}
mock.lockGetTemperature.Lock()
mock.calls.GetTemperature = append(mock.calls.GetTemperature, callInfo)
mock.lockGetTemperature.Unlock()
return mock.GetTemperatureFunc(n)
}
// GetTemperatureCalls gets all the calls that were made to GetTemperature.
// Check the length with:
//
// len(mockedUnit.GetTemperatureCalls())
func (mock *Unit) GetTemperatureCalls() []struct {
N int
} {
var calls []struct {
N int
}
mock.lockGetTemperature.RLock()
calls = mock.calls.GetTemperature
mock.lockGetTemperature.RUnlock()
return calls
}
// GetUnitInfo calls GetUnitInfoFunc.
func (mock *Unit) GetUnitInfo() (nvml.UnitInfo, nvml.Return) {
if mock.GetUnitInfoFunc == nil {
panic("Unit.GetUnitInfoFunc: method is nil but Unit.GetUnitInfo was just called")
}
callInfo := struct {
}{}
mock.lockGetUnitInfo.Lock()
mock.calls.GetUnitInfo = append(mock.calls.GetUnitInfo, callInfo)
mock.lockGetUnitInfo.Unlock()
return mock.GetUnitInfoFunc()
}
// GetUnitInfoCalls gets all the calls that were made to GetUnitInfo.
// Check the length with:
//
// len(mockedUnit.GetUnitInfoCalls())
func (mock *Unit) GetUnitInfoCalls() []struct {
} {
var calls []struct {
}
mock.lockGetUnitInfo.RLock()
calls = mock.calls.GetUnitInfo
mock.lockGetUnitInfo.RUnlock()
return calls
}
// SetLedState calls SetLedStateFunc.
func (mock *Unit) SetLedState(ledColor nvml.LedColor) nvml.Return {
if mock.SetLedStateFunc == nil {
panic("Unit.SetLedStateFunc: method is nil but Unit.SetLedState was just called")
}
callInfo := struct {
LedColor nvml.LedColor
}{
LedColor: ledColor,
}
mock.lockSetLedState.Lock()
mock.calls.SetLedState = append(mock.calls.SetLedState, callInfo)
mock.lockSetLedState.Unlock()
return mock.SetLedStateFunc(ledColor)
}
// SetLedStateCalls gets all the calls that were made to SetLedState.
// Check the length with:
//
// len(mockedUnit.SetLedStateCalls())
func (mock *Unit) SetLedStateCalls() []struct {
LedColor nvml.LedColor
} {
var calls []struct {
LedColor nvml.LedColor
}
mock.lockSetLedState.RLock()
calls = mock.calls.SetLedState
mock.lockSetLedState.RUnlock()
return calls
}

View File

@@ -0,0 +1,896 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that VgpuInstance does implement nvml.VgpuInstance.
// If this is not the case, regenerate this file with moq.
var _ nvml.VgpuInstance = &VgpuInstance{}
// VgpuInstance is a mock implementation of nvml.VgpuInstance.
//
// func TestSomethingThatUsesVgpuInstance(t *testing.T) {
//
// // make and configure a mocked nvml.VgpuInstance
// mockedVgpuInstance := &VgpuInstance{
// ClearAccountingPidsFunc: func() nvml.Return {
// panic("mock out the ClearAccountingPids method")
// },
// GetAccountingModeFunc: func() (nvml.EnableState, nvml.Return) {
// panic("mock out the GetAccountingMode method")
// },
// GetAccountingPidsFunc: func() ([]int, nvml.Return) {
// panic("mock out the GetAccountingPids method")
// },
// GetAccountingStatsFunc: func(n int) (nvml.AccountingStats, nvml.Return) {
// panic("mock out the GetAccountingStats method")
// },
// GetEccModeFunc: func() (nvml.EnableState, nvml.Return) {
// panic("mock out the GetEccMode method")
// },
// GetEncoderCapacityFunc: func() (int, nvml.Return) {
// panic("mock out the GetEncoderCapacity method")
// },
// GetEncoderSessionsFunc: func() (int, nvml.EncoderSessionInfo, nvml.Return) {
// panic("mock out the GetEncoderSessions method")
// },
// GetEncoderStatsFunc: func() (int, uint32, uint32, nvml.Return) {
// panic("mock out the GetEncoderStats method")
// },
// GetFBCSessionsFunc: func() (int, nvml.FBCSessionInfo, nvml.Return) {
// panic("mock out the GetFBCSessions method")
// },
// GetFBCStatsFunc: func() (nvml.FBCStats, nvml.Return) {
// panic("mock out the GetFBCStats method")
// },
// GetFbUsageFunc: func() (uint64, nvml.Return) {
// panic("mock out the GetFbUsage method")
// },
// GetFrameRateLimitFunc: func() (uint32, nvml.Return) {
// panic("mock out the GetFrameRateLimit method")
// },
// GetGpuInstanceIdFunc: func() (int, nvml.Return) {
// panic("mock out the GetGpuInstanceId method")
// },
// GetGpuPciIdFunc: func() (string, nvml.Return) {
// panic("mock out the GetGpuPciId method")
// },
// GetLicenseInfoFunc: func() (nvml.VgpuLicenseInfo, nvml.Return) {
// panic("mock out the GetLicenseInfo method")
// },
// GetLicenseStatusFunc: func() (int, nvml.Return) {
// panic("mock out the GetLicenseStatus method")
// },
// GetMdevUUIDFunc: func() (string, nvml.Return) {
// panic("mock out the GetMdevUUID method")
// },
// GetMetadataFunc: func() (nvml.VgpuMetadata, nvml.Return) {
// panic("mock out the GetMetadata method")
// },
// GetTypeFunc: func() (nvml.VgpuTypeId, nvml.Return) {
// panic("mock out the GetType method")
// },
// GetUUIDFunc: func() (string, nvml.Return) {
// panic("mock out the GetUUID method")
// },
// GetVmDriverVersionFunc: func() (string, nvml.Return) {
// panic("mock out the GetVmDriverVersion method")
// },
// GetVmIDFunc: func() (string, nvml.VgpuVmIdType, nvml.Return) {
// panic("mock out the GetVmID method")
// },
// SetEncoderCapacityFunc: func(n int) nvml.Return {
// panic("mock out the SetEncoderCapacity method")
// },
// }
//
// // use mockedVgpuInstance in code that requires nvml.VgpuInstance
// // and then make assertions.
//
// }
type VgpuInstance struct {
// ClearAccountingPidsFunc mocks the ClearAccountingPids method.
ClearAccountingPidsFunc func() nvml.Return
// GetAccountingModeFunc mocks the GetAccountingMode method.
GetAccountingModeFunc func() (nvml.EnableState, nvml.Return)
// GetAccountingPidsFunc mocks the GetAccountingPids method.
GetAccountingPidsFunc func() ([]int, nvml.Return)
// GetAccountingStatsFunc mocks the GetAccountingStats method.
GetAccountingStatsFunc func(n int) (nvml.AccountingStats, nvml.Return)
// GetEccModeFunc mocks the GetEccMode method.
GetEccModeFunc func() (nvml.EnableState, nvml.Return)
// GetEncoderCapacityFunc mocks the GetEncoderCapacity method.
GetEncoderCapacityFunc func() (int, nvml.Return)
// GetEncoderSessionsFunc mocks the GetEncoderSessions method.
GetEncoderSessionsFunc func() (int, nvml.EncoderSessionInfo, nvml.Return)
// GetEncoderStatsFunc mocks the GetEncoderStats method.
GetEncoderStatsFunc func() (int, uint32, uint32, nvml.Return)
// GetFBCSessionsFunc mocks the GetFBCSessions method.
GetFBCSessionsFunc func() (int, nvml.FBCSessionInfo, nvml.Return)
// GetFBCStatsFunc mocks the GetFBCStats method.
GetFBCStatsFunc func() (nvml.FBCStats, nvml.Return)
// GetFbUsageFunc mocks the GetFbUsage method.
GetFbUsageFunc func() (uint64, nvml.Return)
// GetFrameRateLimitFunc mocks the GetFrameRateLimit method.
GetFrameRateLimitFunc func() (uint32, nvml.Return)
// GetGpuInstanceIdFunc mocks the GetGpuInstanceId method.
GetGpuInstanceIdFunc func() (int, nvml.Return)
// GetGpuPciIdFunc mocks the GetGpuPciId method.
GetGpuPciIdFunc func() (string, nvml.Return)
// GetLicenseInfoFunc mocks the GetLicenseInfo method.
GetLicenseInfoFunc func() (nvml.VgpuLicenseInfo, nvml.Return)
// GetLicenseStatusFunc mocks the GetLicenseStatus method.
GetLicenseStatusFunc func() (int, nvml.Return)
// GetMdevUUIDFunc mocks the GetMdevUUID method.
GetMdevUUIDFunc func() (string, nvml.Return)
// GetMetadataFunc mocks the GetMetadata method.
GetMetadataFunc func() (nvml.VgpuMetadata, nvml.Return)
// GetTypeFunc mocks the GetType method.
GetTypeFunc func() (nvml.VgpuTypeId, nvml.Return)
// GetUUIDFunc mocks the GetUUID method.
GetUUIDFunc func() (string, nvml.Return)
// GetVmDriverVersionFunc mocks the GetVmDriverVersion method.
GetVmDriverVersionFunc func() (string, nvml.Return)
// GetVmIDFunc mocks the GetVmID method.
GetVmIDFunc func() (string, nvml.VgpuVmIdType, nvml.Return)
// SetEncoderCapacityFunc mocks the SetEncoderCapacity method.
SetEncoderCapacityFunc func(n int) nvml.Return
// calls tracks calls to the methods.
calls struct {
// ClearAccountingPids holds details about calls to the ClearAccountingPids method.
ClearAccountingPids []struct {
}
// GetAccountingMode holds details about calls to the GetAccountingMode method.
GetAccountingMode []struct {
}
// GetAccountingPids holds details about calls to the GetAccountingPids method.
GetAccountingPids []struct {
}
// GetAccountingStats holds details about calls to the GetAccountingStats method.
GetAccountingStats []struct {
// N is the n argument value.
N int
}
// GetEccMode holds details about calls to the GetEccMode method.
GetEccMode []struct {
}
// GetEncoderCapacity holds details about calls to the GetEncoderCapacity method.
GetEncoderCapacity []struct {
}
// GetEncoderSessions holds details about calls to the GetEncoderSessions method.
GetEncoderSessions []struct {
}
// GetEncoderStats holds details about calls to the GetEncoderStats method.
GetEncoderStats []struct {
}
// GetFBCSessions holds details about calls to the GetFBCSessions method.
GetFBCSessions []struct {
}
// GetFBCStats holds details about calls to the GetFBCStats method.
GetFBCStats []struct {
}
// GetFbUsage holds details about calls to the GetFbUsage method.
GetFbUsage []struct {
}
// GetFrameRateLimit holds details about calls to the GetFrameRateLimit method.
GetFrameRateLimit []struct {
}
// GetGpuInstanceId holds details about calls to the GetGpuInstanceId method.
GetGpuInstanceId []struct {
}
// GetGpuPciId holds details about calls to the GetGpuPciId method.
GetGpuPciId []struct {
}
// GetLicenseInfo holds details about calls to the GetLicenseInfo method.
GetLicenseInfo []struct {
}
// GetLicenseStatus holds details about calls to the GetLicenseStatus method.
GetLicenseStatus []struct {
}
// GetMdevUUID holds details about calls to the GetMdevUUID method.
GetMdevUUID []struct {
}
// GetMetadata holds details about calls to the GetMetadata method.
GetMetadata []struct {
}
// GetType holds details about calls to the GetType method.
GetType []struct {
}
// GetUUID holds details about calls to the GetUUID method.
GetUUID []struct {
}
// GetVmDriverVersion holds details about calls to the GetVmDriverVersion method.
GetVmDriverVersion []struct {
}
// GetVmID holds details about calls to the GetVmID method.
GetVmID []struct {
}
// SetEncoderCapacity holds details about calls to the SetEncoderCapacity method.
SetEncoderCapacity []struct {
// N is the n argument value.
N int
}
}
lockClearAccountingPids sync.RWMutex
lockGetAccountingMode sync.RWMutex
lockGetAccountingPids sync.RWMutex
lockGetAccountingStats sync.RWMutex
lockGetEccMode sync.RWMutex
lockGetEncoderCapacity sync.RWMutex
lockGetEncoderSessions sync.RWMutex
lockGetEncoderStats sync.RWMutex
lockGetFBCSessions sync.RWMutex
lockGetFBCStats sync.RWMutex
lockGetFbUsage sync.RWMutex
lockGetFrameRateLimit sync.RWMutex
lockGetGpuInstanceId sync.RWMutex
lockGetGpuPciId sync.RWMutex
lockGetLicenseInfo sync.RWMutex
lockGetLicenseStatus sync.RWMutex
lockGetMdevUUID sync.RWMutex
lockGetMetadata sync.RWMutex
lockGetType sync.RWMutex
lockGetUUID sync.RWMutex
lockGetVmDriverVersion sync.RWMutex
lockGetVmID sync.RWMutex
lockSetEncoderCapacity sync.RWMutex
}
// ClearAccountingPids calls ClearAccountingPidsFunc.
func (mock *VgpuInstance) ClearAccountingPids() nvml.Return {
if mock.ClearAccountingPidsFunc == nil {
panic("VgpuInstance.ClearAccountingPidsFunc: method is nil but VgpuInstance.ClearAccountingPids was just called")
}
callInfo := struct {
}{}
mock.lockClearAccountingPids.Lock()
mock.calls.ClearAccountingPids = append(mock.calls.ClearAccountingPids, callInfo)
mock.lockClearAccountingPids.Unlock()
return mock.ClearAccountingPidsFunc()
}
// ClearAccountingPidsCalls gets all the calls that were made to ClearAccountingPids.
// Check the length with:
//
// len(mockedVgpuInstance.ClearAccountingPidsCalls())
func (mock *VgpuInstance) ClearAccountingPidsCalls() []struct {
} {
var calls []struct {
}
mock.lockClearAccountingPids.RLock()
calls = mock.calls.ClearAccountingPids
mock.lockClearAccountingPids.RUnlock()
return calls
}
// GetAccountingMode calls GetAccountingModeFunc.
func (mock *VgpuInstance) GetAccountingMode() (nvml.EnableState, nvml.Return) {
if mock.GetAccountingModeFunc == nil {
panic("VgpuInstance.GetAccountingModeFunc: method is nil but VgpuInstance.GetAccountingMode was just called")
}
callInfo := struct {
}{}
mock.lockGetAccountingMode.Lock()
mock.calls.GetAccountingMode = append(mock.calls.GetAccountingMode, callInfo)
mock.lockGetAccountingMode.Unlock()
return mock.GetAccountingModeFunc()
}
// GetAccountingModeCalls gets all the calls that were made to GetAccountingMode.
// Check the length with:
//
// len(mockedVgpuInstance.GetAccountingModeCalls())
func (mock *VgpuInstance) GetAccountingModeCalls() []struct {
} {
var calls []struct {
}
mock.lockGetAccountingMode.RLock()
calls = mock.calls.GetAccountingMode
mock.lockGetAccountingMode.RUnlock()
return calls
}
// GetAccountingPids calls GetAccountingPidsFunc.
func (mock *VgpuInstance) GetAccountingPids() ([]int, nvml.Return) {
if mock.GetAccountingPidsFunc == nil {
panic("VgpuInstance.GetAccountingPidsFunc: method is nil but VgpuInstance.GetAccountingPids was just called")
}
callInfo := struct {
}{}
mock.lockGetAccountingPids.Lock()
mock.calls.GetAccountingPids = append(mock.calls.GetAccountingPids, callInfo)
mock.lockGetAccountingPids.Unlock()
return mock.GetAccountingPidsFunc()
}
// GetAccountingPidsCalls gets all the calls that were made to GetAccountingPids.
// Check the length with:
//
// len(mockedVgpuInstance.GetAccountingPidsCalls())
func (mock *VgpuInstance) GetAccountingPidsCalls() []struct {
} {
var calls []struct {
}
mock.lockGetAccountingPids.RLock()
calls = mock.calls.GetAccountingPids
mock.lockGetAccountingPids.RUnlock()
return calls
}
// GetAccountingStats calls GetAccountingStatsFunc.
func (mock *VgpuInstance) GetAccountingStats(n int) (nvml.AccountingStats, nvml.Return) {
if mock.GetAccountingStatsFunc == nil {
panic("VgpuInstance.GetAccountingStatsFunc: method is nil but VgpuInstance.GetAccountingStats was just called")
}
callInfo := struct {
N int
}{
N: n,
}
mock.lockGetAccountingStats.Lock()
mock.calls.GetAccountingStats = append(mock.calls.GetAccountingStats, callInfo)
mock.lockGetAccountingStats.Unlock()
return mock.GetAccountingStatsFunc(n)
}
// GetAccountingStatsCalls gets all the calls that were made to GetAccountingStats.
// Check the length with:
//
// len(mockedVgpuInstance.GetAccountingStatsCalls())
func (mock *VgpuInstance) GetAccountingStatsCalls() []struct {
N int
} {
var calls []struct {
N int
}
mock.lockGetAccountingStats.RLock()
calls = mock.calls.GetAccountingStats
mock.lockGetAccountingStats.RUnlock()
return calls
}
// GetEccMode calls GetEccModeFunc.
func (mock *VgpuInstance) GetEccMode() (nvml.EnableState, nvml.Return) {
if mock.GetEccModeFunc == nil {
panic("VgpuInstance.GetEccModeFunc: method is nil but VgpuInstance.GetEccMode was just called")
}
callInfo := struct {
}{}
mock.lockGetEccMode.Lock()
mock.calls.GetEccMode = append(mock.calls.GetEccMode, callInfo)
mock.lockGetEccMode.Unlock()
return mock.GetEccModeFunc()
}
// GetEccModeCalls gets all the calls that were made to GetEccMode.
// Check the length with:
//
// len(mockedVgpuInstance.GetEccModeCalls())
func (mock *VgpuInstance) GetEccModeCalls() []struct {
} {
var calls []struct {
}
mock.lockGetEccMode.RLock()
calls = mock.calls.GetEccMode
mock.lockGetEccMode.RUnlock()
return calls
}
// GetEncoderCapacity calls GetEncoderCapacityFunc.
func (mock *VgpuInstance) GetEncoderCapacity() (int, nvml.Return) {
if mock.GetEncoderCapacityFunc == nil {
panic("VgpuInstance.GetEncoderCapacityFunc: method is nil but VgpuInstance.GetEncoderCapacity was just called")
}
callInfo := struct {
}{}
mock.lockGetEncoderCapacity.Lock()
mock.calls.GetEncoderCapacity = append(mock.calls.GetEncoderCapacity, callInfo)
mock.lockGetEncoderCapacity.Unlock()
return mock.GetEncoderCapacityFunc()
}
// GetEncoderCapacityCalls gets all the calls that were made to GetEncoderCapacity.
// Check the length with:
//
// len(mockedVgpuInstance.GetEncoderCapacityCalls())
func (mock *VgpuInstance) GetEncoderCapacityCalls() []struct {
} {
var calls []struct {
}
mock.lockGetEncoderCapacity.RLock()
calls = mock.calls.GetEncoderCapacity
mock.lockGetEncoderCapacity.RUnlock()
return calls
}
// GetEncoderSessions calls GetEncoderSessionsFunc.
func (mock *VgpuInstance) GetEncoderSessions() (int, nvml.EncoderSessionInfo, nvml.Return) {
if mock.GetEncoderSessionsFunc == nil {
panic("VgpuInstance.GetEncoderSessionsFunc: method is nil but VgpuInstance.GetEncoderSessions was just called")
}
callInfo := struct {
}{}
mock.lockGetEncoderSessions.Lock()
mock.calls.GetEncoderSessions = append(mock.calls.GetEncoderSessions, callInfo)
mock.lockGetEncoderSessions.Unlock()
return mock.GetEncoderSessionsFunc()
}
// GetEncoderSessionsCalls gets all the calls that were made to GetEncoderSessions.
// Check the length with:
//
// len(mockedVgpuInstance.GetEncoderSessionsCalls())
func (mock *VgpuInstance) GetEncoderSessionsCalls() []struct {
} {
var calls []struct {
}
mock.lockGetEncoderSessions.RLock()
calls = mock.calls.GetEncoderSessions
mock.lockGetEncoderSessions.RUnlock()
return calls
}
// GetEncoderStats calls GetEncoderStatsFunc.
func (mock *VgpuInstance) GetEncoderStats() (int, uint32, uint32, nvml.Return) {
if mock.GetEncoderStatsFunc == nil {
panic("VgpuInstance.GetEncoderStatsFunc: method is nil but VgpuInstance.GetEncoderStats was just called")
}
callInfo := struct {
}{}
mock.lockGetEncoderStats.Lock()
mock.calls.GetEncoderStats = append(mock.calls.GetEncoderStats, callInfo)
mock.lockGetEncoderStats.Unlock()
return mock.GetEncoderStatsFunc()
}
// GetEncoderStatsCalls gets all the calls that were made to GetEncoderStats.
// Check the length with:
//
// len(mockedVgpuInstance.GetEncoderStatsCalls())
func (mock *VgpuInstance) GetEncoderStatsCalls() []struct {
} {
var calls []struct {
}
mock.lockGetEncoderStats.RLock()
calls = mock.calls.GetEncoderStats
mock.lockGetEncoderStats.RUnlock()
return calls
}
// GetFBCSessions calls GetFBCSessionsFunc.
func (mock *VgpuInstance) GetFBCSessions() (int, nvml.FBCSessionInfo, nvml.Return) {
if mock.GetFBCSessionsFunc == nil {
panic("VgpuInstance.GetFBCSessionsFunc: method is nil but VgpuInstance.GetFBCSessions was just called")
}
callInfo := struct {
}{}
mock.lockGetFBCSessions.Lock()
mock.calls.GetFBCSessions = append(mock.calls.GetFBCSessions, callInfo)
mock.lockGetFBCSessions.Unlock()
return mock.GetFBCSessionsFunc()
}
// GetFBCSessionsCalls gets all the calls that were made to GetFBCSessions.
// Check the length with:
//
// len(mockedVgpuInstance.GetFBCSessionsCalls())
func (mock *VgpuInstance) GetFBCSessionsCalls() []struct {
} {
var calls []struct {
}
mock.lockGetFBCSessions.RLock()
calls = mock.calls.GetFBCSessions
mock.lockGetFBCSessions.RUnlock()
return calls
}
// GetFBCStats calls GetFBCStatsFunc.
func (mock *VgpuInstance) GetFBCStats() (nvml.FBCStats, nvml.Return) {
if mock.GetFBCStatsFunc == nil {
panic("VgpuInstance.GetFBCStatsFunc: method is nil but VgpuInstance.GetFBCStats was just called")
}
callInfo := struct {
}{}
mock.lockGetFBCStats.Lock()
mock.calls.GetFBCStats = append(mock.calls.GetFBCStats, callInfo)
mock.lockGetFBCStats.Unlock()
return mock.GetFBCStatsFunc()
}
// GetFBCStatsCalls gets all the calls that were made to GetFBCStats.
// Check the length with:
//
// len(mockedVgpuInstance.GetFBCStatsCalls())
func (mock *VgpuInstance) GetFBCStatsCalls() []struct {
} {
var calls []struct {
}
mock.lockGetFBCStats.RLock()
calls = mock.calls.GetFBCStats
mock.lockGetFBCStats.RUnlock()
return calls
}
// GetFbUsage calls GetFbUsageFunc.
func (mock *VgpuInstance) GetFbUsage() (uint64, nvml.Return) {
if mock.GetFbUsageFunc == nil {
panic("VgpuInstance.GetFbUsageFunc: method is nil but VgpuInstance.GetFbUsage was just called")
}
callInfo := struct {
}{}
mock.lockGetFbUsage.Lock()
mock.calls.GetFbUsage = append(mock.calls.GetFbUsage, callInfo)
mock.lockGetFbUsage.Unlock()
return mock.GetFbUsageFunc()
}
// GetFbUsageCalls gets all the calls that were made to GetFbUsage.
// Check the length with:
//
// len(mockedVgpuInstance.GetFbUsageCalls())
func (mock *VgpuInstance) GetFbUsageCalls() []struct {
} {
var calls []struct {
}
mock.lockGetFbUsage.RLock()
calls = mock.calls.GetFbUsage
mock.lockGetFbUsage.RUnlock()
return calls
}
// GetFrameRateLimit calls GetFrameRateLimitFunc.
func (mock *VgpuInstance) GetFrameRateLimit() (uint32, nvml.Return) {
if mock.GetFrameRateLimitFunc == nil {
panic("VgpuInstance.GetFrameRateLimitFunc: method is nil but VgpuInstance.GetFrameRateLimit was just called")
}
callInfo := struct {
}{}
mock.lockGetFrameRateLimit.Lock()
mock.calls.GetFrameRateLimit = append(mock.calls.GetFrameRateLimit, callInfo)
mock.lockGetFrameRateLimit.Unlock()
return mock.GetFrameRateLimitFunc()
}
// GetFrameRateLimitCalls gets all the calls that were made to GetFrameRateLimit.
// Check the length with:
//
// len(mockedVgpuInstance.GetFrameRateLimitCalls())
func (mock *VgpuInstance) GetFrameRateLimitCalls() []struct {
} {
var calls []struct {
}
mock.lockGetFrameRateLimit.RLock()
calls = mock.calls.GetFrameRateLimit
mock.lockGetFrameRateLimit.RUnlock()
return calls
}
// GetGpuInstanceId calls GetGpuInstanceIdFunc.
func (mock *VgpuInstance) GetGpuInstanceId() (int, nvml.Return) {
if mock.GetGpuInstanceIdFunc == nil {
panic("VgpuInstance.GetGpuInstanceIdFunc: method is nil but VgpuInstance.GetGpuInstanceId was just called")
}
callInfo := struct {
}{}
mock.lockGetGpuInstanceId.Lock()
mock.calls.GetGpuInstanceId = append(mock.calls.GetGpuInstanceId, callInfo)
mock.lockGetGpuInstanceId.Unlock()
return mock.GetGpuInstanceIdFunc()
}
// GetGpuInstanceIdCalls gets all the calls that were made to GetGpuInstanceId.
// Check the length with:
//
// len(mockedVgpuInstance.GetGpuInstanceIdCalls())
func (mock *VgpuInstance) GetGpuInstanceIdCalls() []struct {
} {
var calls []struct {
}
mock.lockGetGpuInstanceId.RLock()
calls = mock.calls.GetGpuInstanceId
mock.lockGetGpuInstanceId.RUnlock()
return calls
}
// GetGpuPciId calls GetGpuPciIdFunc.
func (mock *VgpuInstance) GetGpuPciId() (string, nvml.Return) {
if mock.GetGpuPciIdFunc == nil {
panic("VgpuInstance.GetGpuPciIdFunc: method is nil but VgpuInstance.GetGpuPciId was just called")
}
callInfo := struct {
}{}
mock.lockGetGpuPciId.Lock()
mock.calls.GetGpuPciId = append(mock.calls.GetGpuPciId, callInfo)
mock.lockGetGpuPciId.Unlock()
return mock.GetGpuPciIdFunc()
}
// GetGpuPciIdCalls gets all the calls that were made to GetGpuPciId.
// Check the length with:
//
// len(mockedVgpuInstance.GetGpuPciIdCalls())
func (mock *VgpuInstance) GetGpuPciIdCalls() []struct {
} {
var calls []struct {
}
mock.lockGetGpuPciId.RLock()
calls = mock.calls.GetGpuPciId
mock.lockGetGpuPciId.RUnlock()
return calls
}
// GetLicenseInfo calls GetLicenseInfoFunc.
func (mock *VgpuInstance) GetLicenseInfo() (nvml.VgpuLicenseInfo, nvml.Return) {
if mock.GetLicenseInfoFunc == nil {
panic("VgpuInstance.GetLicenseInfoFunc: method is nil but VgpuInstance.GetLicenseInfo was just called")
}
callInfo := struct {
}{}
mock.lockGetLicenseInfo.Lock()
mock.calls.GetLicenseInfo = append(mock.calls.GetLicenseInfo, callInfo)
mock.lockGetLicenseInfo.Unlock()
return mock.GetLicenseInfoFunc()
}
// GetLicenseInfoCalls gets all the calls that were made to GetLicenseInfo.
// Check the length with:
//
// len(mockedVgpuInstance.GetLicenseInfoCalls())
func (mock *VgpuInstance) GetLicenseInfoCalls() []struct {
} {
var calls []struct {
}
mock.lockGetLicenseInfo.RLock()
calls = mock.calls.GetLicenseInfo
mock.lockGetLicenseInfo.RUnlock()
return calls
}
// GetLicenseStatus calls GetLicenseStatusFunc.
func (mock *VgpuInstance) GetLicenseStatus() (int, nvml.Return) {
if mock.GetLicenseStatusFunc == nil {
panic("VgpuInstance.GetLicenseStatusFunc: method is nil but VgpuInstance.GetLicenseStatus was just called")
}
callInfo := struct {
}{}
mock.lockGetLicenseStatus.Lock()
mock.calls.GetLicenseStatus = append(mock.calls.GetLicenseStatus, callInfo)
mock.lockGetLicenseStatus.Unlock()
return mock.GetLicenseStatusFunc()
}
// GetLicenseStatusCalls gets all the calls that were made to GetLicenseStatus.
// Check the length with:
//
// len(mockedVgpuInstance.GetLicenseStatusCalls())
func (mock *VgpuInstance) GetLicenseStatusCalls() []struct {
} {
var calls []struct {
}
mock.lockGetLicenseStatus.RLock()
calls = mock.calls.GetLicenseStatus
mock.lockGetLicenseStatus.RUnlock()
return calls
}
// GetMdevUUID calls GetMdevUUIDFunc.
func (mock *VgpuInstance) GetMdevUUID() (string, nvml.Return) {
if mock.GetMdevUUIDFunc == nil {
panic("VgpuInstance.GetMdevUUIDFunc: method is nil but VgpuInstance.GetMdevUUID was just called")
}
callInfo := struct {
}{}
mock.lockGetMdevUUID.Lock()
mock.calls.GetMdevUUID = append(mock.calls.GetMdevUUID, callInfo)
mock.lockGetMdevUUID.Unlock()
return mock.GetMdevUUIDFunc()
}
// GetMdevUUIDCalls gets all the calls that were made to GetMdevUUID.
// Check the length with:
//
// len(mockedVgpuInstance.GetMdevUUIDCalls())
func (mock *VgpuInstance) GetMdevUUIDCalls() []struct {
} {
var calls []struct {
}
mock.lockGetMdevUUID.RLock()
calls = mock.calls.GetMdevUUID
mock.lockGetMdevUUID.RUnlock()
return calls
}
// GetMetadata calls GetMetadataFunc.
func (mock *VgpuInstance) GetMetadata() (nvml.VgpuMetadata, nvml.Return) {
if mock.GetMetadataFunc == nil {
panic("VgpuInstance.GetMetadataFunc: method is nil but VgpuInstance.GetMetadata was just called")
}
callInfo := struct {
}{}
mock.lockGetMetadata.Lock()
mock.calls.GetMetadata = append(mock.calls.GetMetadata, callInfo)
mock.lockGetMetadata.Unlock()
return mock.GetMetadataFunc()
}
// GetMetadataCalls gets all the calls that were made to GetMetadata.
// Check the length with:
//
// len(mockedVgpuInstance.GetMetadataCalls())
func (mock *VgpuInstance) GetMetadataCalls() []struct {
} {
var calls []struct {
}
mock.lockGetMetadata.RLock()
calls = mock.calls.GetMetadata
mock.lockGetMetadata.RUnlock()
return calls
}
// GetType calls GetTypeFunc.
func (mock *VgpuInstance) GetType() (nvml.VgpuTypeId, nvml.Return) {
if mock.GetTypeFunc == nil {
panic("VgpuInstance.GetTypeFunc: method is nil but VgpuInstance.GetType was just called")
}
callInfo := struct {
}{}
mock.lockGetType.Lock()
mock.calls.GetType = append(mock.calls.GetType, callInfo)
mock.lockGetType.Unlock()
return mock.GetTypeFunc()
}
// GetTypeCalls gets all the calls that were made to GetType.
// Check the length with:
//
// len(mockedVgpuInstance.GetTypeCalls())
func (mock *VgpuInstance) GetTypeCalls() []struct {
} {
var calls []struct {
}
mock.lockGetType.RLock()
calls = mock.calls.GetType
mock.lockGetType.RUnlock()
return calls
}
// GetUUID calls GetUUIDFunc.
func (mock *VgpuInstance) GetUUID() (string, nvml.Return) {
if mock.GetUUIDFunc == nil {
panic("VgpuInstance.GetUUIDFunc: method is nil but VgpuInstance.GetUUID was just called")
}
callInfo := struct {
}{}
mock.lockGetUUID.Lock()
mock.calls.GetUUID = append(mock.calls.GetUUID, callInfo)
mock.lockGetUUID.Unlock()
return mock.GetUUIDFunc()
}
// GetUUIDCalls gets all the calls that were made to GetUUID.
// Check the length with:
//
// len(mockedVgpuInstance.GetUUIDCalls())
func (mock *VgpuInstance) GetUUIDCalls() []struct {
} {
var calls []struct {
}
mock.lockGetUUID.RLock()
calls = mock.calls.GetUUID
mock.lockGetUUID.RUnlock()
return calls
}
// GetVmDriverVersion calls GetVmDriverVersionFunc.
func (mock *VgpuInstance) GetVmDriverVersion() (string, nvml.Return) {
if mock.GetVmDriverVersionFunc == nil {
panic("VgpuInstance.GetVmDriverVersionFunc: method is nil but VgpuInstance.GetVmDriverVersion was just called")
}
callInfo := struct {
}{}
mock.lockGetVmDriverVersion.Lock()
mock.calls.GetVmDriverVersion = append(mock.calls.GetVmDriverVersion, callInfo)
mock.lockGetVmDriverVersion.Unlock()
return mock.GetVmDriverVersionFunc()
}
// GetVmDriverVersionCalls gets all the calls that were made to GetVmDriverVersion.
// Check the length with:
//
// len(mockedVgpuInstance.GetVmDriverVersionCalls())
func (mock *VgpuInstance) GetVmDriverVersionCalls() []struct {
} {
var calls []struct {
}
mock.lockGetVmDriverVersion.RLock()
calls = mock.calls.GetVmDriverVersion
mock.lockGetVmDriverVersion.RUnlock()
return calls
}
// GetVmID calls GetVmIDFunc.
func (mock *VgpuInstance) GetVmID() (string, nvml.VgpuVmIdType, nvml.Return) {
if mock.GetVmIDFunc == nil {
panic("VgpuInstance.GetVmIDFunc: method is nil but VgpuInstance.GetVmID was just called")
}
callInfo := struct {
}{}
mock.lockGetVmID.Lock()
mock.calls.GetVmID = append(mock.calls.GetVmID, callInfo)
mock.lockGetVmID.Unlock()
return mock.GetVmIDFunc()
}
// GetVmIDCalls gets all the calls that were made to GetVmID.
// Check the length with:
//
// len(mockedVgpuInstance.GetVmIDCalls())
func (mock *VgpuInstance) GetVmIDCalls() []struct {
} {
var calls []struct {
}
mock.lockGetVmID.RLock()
calls = mock.calls.GetVmID
mock.lockGetVmID.RUnlock()
return calls
}
// SetEncoderCapacity calls SetEncoderCapacityFunc.
func (mock *VgpuInstance) SetEncoderCapacity(n int) nvml.Return {
if mock.SetEncoderCapacityFunc == nil {
panic("VgpuInstance.SetEncoderCapacityFunc: method is nil but VgpuInstance.SetEncoderCapacity was just called")
}
callInfo := struct {
N int
}{
N: n,
}
mock.lockSetEncoderCapacity.Lock()
mock.calls.SetEncoderCapacity = append(mock.calls.SetEncoderCapacity, callInfo)
mock.lockSetEncoderCapacity.Unlock()
return mock.SetEncoderCapacityFunc(n)
}
// SetEncoderCapacityCalls gets all the calls that were made to SetEncoderCapacity.
// Check the length with:
//
// len(mockedVgpuInstance.SetEncoderCapacityCalls())
func (mock *VgpuInstance) SetEncoderCapacityCalls() []struct {
N int
} {
var calls []struct {
N int
}
mock.lockSetEncoderCapacity.RLock()
calls = mock.calls.SetEncoderCapacity
mock.lockSetEncoderCapacity.RUnlock()
return calls
}

View File

@@ -0,0 +1,496 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"github.com/NVIDIA/go-nvml/pkg/nvml"
"sync"
)
// Ensure, that VgpuTypeId does implement nvml.VgpuTypeId.
// If this is not the case, regenerate this file with moq.
var _ nvml.VgpuTypeId = &VgpuTypeId{}
// VgpuTypeId is a mock implementation of nvml.VgpuTypeId.
//
// func TestSomethingThatUsesVgpuTypeId(t *testing.T) {
//
// // make and configure a mocked nvml.VgpuTypeId
// mockedVgpuTypeId := &VgpuTypeId{
// GetCapabilitiesFunc: func(vgpuCapability nvml.VgpuCapability) (bool, nvml.Return) {
// panic("mock out the GetCapabilities method")
// },
// GetClassFunc: func() (string, nvml.Return) {
// panic("mock out the GetClass method")
// },
// GetDeviceIDFunc: func() (uint64, uint64, nvml.Return) {
// panic("mock out the GetDeviceID method")
// },
// GetFrameRateLimitFunc: func() (uint32, nvml.Return) {
// panic("mock out the GetFrameRateLimit method")
// },
// GetFramebufferSizeFunc: func() (uint64, nvml.Return) {
// panic("mock out the GetFramebufferSize method")
// },
// GetGpuInstanceProfileIdFunc: func() (uint32, nvml.Return) {
// panic("mock out the GetGpuInstanceProfileId method")
// },
// GetLicenseFunc: func() (string, nvml.Return) {
// panic("mock out the GetLicense method")
// },
// GetMaxInstancesFunc: func(device nvml.Device) (int, nvml.Return) {
// panic("mock out the GetMaxInstances method")
// },
// GetMaxInstancesPerVmFunc: func() (int, nvml.Return) {
// panic("mock out the GetMaxInstancesPerVm method")
// },
// GetNameFunc: func() (string, nvml.Return) {
// panic("mock out the GetName method")
// },
// GetNumDisplayHeadsFunc: func() (int, nvml.Return) {
// panic("mock out the GetNumDisplayHeads method")
// },
// GetResolutionFunc: func(n int) (uint32, uint32, nvml.Return) {
// panic("mock out the GetResolution method")
// },
// }
//
// // use mockedVgpuTypeId in code that requires nvml.VgpuTypeId
// // and then make assertions.
//
// }
type VgpuTypeId struct {
// GetCapabilitiesFunc mocks the GetCapabilities method.
GetCapabilitiesFunc func(vgpuCapability nvml.VgpuCapability) (bool, nvml.Return)
// GetClassFunc mocks the GetClass method.
GetClassFunc func() (string, nvml.Return)
// GetDeviceIDFunc mocks the GetDeviceID method.
GetDeviceIDFunc func() (uint64, uint64, nvml.Return)
// GetFrameRateLimitFunc mocks the GetFrameRateLimit method.
GetFrameRateLimitFunc func() (uint32, nvml.Return)
// GetFramebufferSizeFunc mocks the GetFramebufferSize method.
GetFramebufferSizeFunc func() (uint64, nvml.Return)
// GetGpuInstanceProfileIdFunc mocks the GetGpuInstanceProfileId method.
GetGpuInstanceProfileIdFunc func() (uint32, nvml.Return)
// GetLicenseFunc mocks the GetLicense method.
GetLicenseFunc func() (string, nvml.Return)
// GetMaxInstancesFunc mocks the GetMaxInstances method.
GetMaxInstancesFunc func(device nvml.Device) (int, nvml.Return)
// GetMaxInstancesPerVmFunc mocks the GetMaxInstancesPerVm method.
GetMaxInstancesPerVmFunc func() (int, nvml.Return)
// GetNameFunc mocks the GetName method.
GetNameFunc func() (string, nvml.Return)
// GetNumDisplayHeadsFunc mocks the GetNumDisplayHeads method.
GetNumDisplayHeadsFunc func() (int, nvml.Return)
// GetResolutionFunc mocks the GetResolution method.
GetResolutionFunc func(n int) (uint32, uint32, nvml.Return)
// calls tracks calls to the methods.
calls struct {
// GetCapabilities holds details about calls to the GetCapabilities method.
GetCapabilities []struct {
// VgpuCapability is the vgpuCapability argument value.
VgpuCapability nvml.VgpuCapability
}
// GetClass holds details about calls to the GetClass method.
GetClass []struct {
}
// GetDeviceID holds details about calls to the GetDeviceID method.
GetDeviceID []struct {
}
// GetFrameRateLimit holds details about calls to the GetFrameRateLimit method.
GetFrameRateLimit []struct {
}
// GetFramebufferSize holds details about calls to the GetFramebufferSize method.
GetFramebufferSize []struct {
}
// GetGpuInstanceProfileId holds details about calls to the GetGpuInstanceProfileId method.
GetGpuInstanceProfileId []struct {
}
// GetLicense holds details about calls to the GetLicense method.
GetLicense []struct {
}
// GetMaxInstances holds details about calls to the GetMaxInstances method.
GetMaxInstances []struct {
// Device is the device argument value.
Device nvml.Device
}
// GetMaxInstancesPerVm holds details about calls to the GetMaxInstancesPerVm method.
GetMaxInstancesPerVm []struct {
}
// GetName holds details about calls to the GetName method.
GetName []struct {
}
// GetNumDisplayHeads holds details about calls to the GetNumDisplayHeads method.
GetNumDisplayHeads []struct {
}
// GetResolution holds details about calls to the GetResolution method.
GetResolution []struct {
// N is the n argument value.
N int
}
}
lockGetCapabilities sync.RWMutex
lockGetClass sync.RWMutex
lockGetDeviceID sync.RWMutex
lockGetFrameRateLimit sync.RWMutex
lockGetFramebufferSize sync.RWMutex
lockGetGpuInstanceProfileId sync.RWMutex
lockGetLicense sync.RWMutex
lockGetMaxInstances sync.RWMutex
lockGetMaxInstancesPerVm sync.RWMutex
lockGetName sync.RWMutex
lockGetNumDisplayHeads sync.RWMutex
lockGetResolution sync.RWMutex
}
// GetCapabilities calls GetCapabilitiesFunc.
func (mock *VgpuTypeId) GetCapabilities(vgpuCapability nvml.VgpuCapability) (bool, nvml.Return) {
if mock.GetCapabilitiesFunc == nil {
panic("VgpuTypeId.GetCapabilitiesFunc: method is nil but VgpuTypeId.GetCapabilities was just called")
}
callInfo := struct {
VgpuCapability nvml.VgpuCapability
}{
VgpuCapability: vgpuCapability,
}
mock.lockGetCapabilities.Lock()
mock.calls.GetCapabilities = append(mock.calls.GetCapabilities, callInfo)
mock.lockGetCapabilities.Unlock()
return mock.GetCapabilitiesFunc(vgpuCapability)
}
// GetCapabilitiesCalls gets all the calls that were made to GetCapabilities.
// Check the length with:
//
// len(mockedVgpuTypeId.GetCapabilitiesCalls())
func (mock *VgpuTypeId) GetCapabilitiesCalls() []struct {
VgpuCapability nvml.VgpuCapability
} {
var calls []struct {
VgpuCapability nvml.VgpuCapability
}
mock.lockGetCapabilities.RLock()
calls = mock.calls.GetCapabilities
mock.lockGetCapabilities.RUnlock()
return calls
}
// GetClass calls GetClassFunc.
func (mock *VgpuTypeId) GetClass() (string, nvml.Return) {
if mock.GetClassFunc == nil {
panic("VgpuTypeId.GetClassFunc: method is nil but VgpuTypeId.GetClass was just called")
}
callInfo := struct {
}{}
mock.lockGetClass.Lock()
mock.calls.GetClass = append(mock.calls.GetClass, callInfo)
mock.lockGetClass.Unlock()
return mock.GetClassFunc()
}
// GetClassCalls gets all the calls that were made to GetClass.
// Check the length with:
//
// len(mockedVgpuTypeId.GetClassCalls())
func (mock *VgpuTypeId) GetClassCalls() []struct {
} {
var calls []struct {
}
mock.lockGetClass.RLock()
calls = mock.calls.GetClass
mock.lockGetClass.RUnlock()
return calls
}
// GetDeviceID calls GetDeviceIDFunc.
func (mock *VgpuTypeId) GetDeviceID() (uint64, uint64, nvml.Return) {
if mock.GetDeviceIDFunc == nil {
panic("VgpuTypeId.GetDeviceIDFunc: method is nil but VgpuTypeId.GetDeviceID was just called")
}
callInfo := struct {
}{}
mock.lockGetDeviceID.Lock()
mock.calls.GetDeviceID = append(mock.calls.GetDeviceID, callInfo)
mock.lockGetDeviceID.Unlock()
return mock.GetDeviceIDFunc()
}
// GetDeviceIDCalls gets all the calls that were made to GetDeviceID.
// Check the length with:
//
// len(mockedVgpuTypeId.GetDeviceIDCalls())
func (mock *VgpuTypeId) GetDeviceIDCalls() []struct {
} {
var calls []struct {
}
mock.lockGetDeviceID.RLock()
calls = mock.calls.GetDeviceID
mock.lockGetDeviceID.RUnlock()
return calls
}
// GetFrameRateLimit calls GetFrameRateLimitFunc.
func (mock *VgpuTypeId) GetFrameRateLimit() (uint32, nvml.Return) {
if mock.GetFrameRateLimitFunc == nil {
panic("VgpuTypeId.GetFrameRateLimitFunc: method is nil but VgpuTypeId.GetFrameRateLimit was just called")
}
callInfo := struct {
}{}
mock.lockGetFrameRateLimit.Lock()
mock.calls.GetFrameRateLimit = append(mock.calls.GetFrameRateLimit, callInfo)
mock.lockGetFrameRateLimit.Unlock()
return mock.GetFrameRateLimitFunc()
}
// GetFrameRateLimitCalls gets all the calls that were made to GetFrameRateLimit.
// Check the length with:
//
// len(mockedVgpuTypeId.GetFrameRateLimitCalls())
func (mock *VgpuTypeId) GetFrameRateLimitCalls() []struct {
} {
var calls []struct {
}
mock.lockGetFrameRateLimit.RLock()
calls = mock.calls.GetFrameRateLimit
mock.lockGetFrameRateLimit.RUnlock()
return calls
}
// GetFramebufferSize calls GetFramebufferSizeFunc.
func (mock *VgpuTypeId) GetFramebufferSize() (uint64, nvml.Return) {
if mock.GetFramebufferSizeFunc == nil {
panic("VgpuTypeId.GetFramebufferSizeFunc: method is nil but VgpuTypeId.GetFramebufferSize was just called")
}
callInfo := struct {
}{}
mock.lockGetFramebufferSize.Lock()
mock.calls.GetFramebufferSize = append(mock.calls.GetFramebufferSize, callInfo)
mock.lockGetFramebufferSize.Unlock()
return mock.GetFramebufferSizeFunc()
}
// GetFramebufferSizeCalls gets all the calls that were made to GetFramebufferSize.
// Check the length with:
//
// len(mockedVgpuTypeId.GetFramebufferSizeCalls())
func (mock *VgpuTypeId) GetFramebufferSizeCalls() []struct {
} {
var calls []struct {
}
mock.lockGetFramebufferSize.RLock()
calls = mock.calls.GetFramebufferSize
mock.lockGetFramebufferSize.RUnlock()
return calls
}
// GetGpuInstanceProfileId calls GetGpuInstanceProfileIdFunc.
func (mock *VgpuTypeId) GetGpuInstanceProfileId() (uint32, nvml.Return) {
if mock.GetGpuInstanceProfileIdFunc == nil {
panic("VgpuTypeId.GetGpuInstanceProfileIdFunc: method is nil but VgpuTypeId.GetGpuInstanceProfileId was just called")
}
callInfo := struct {
}{}
mock.lockGetGpuInstanceProfileId.Lock()
mock.calls.GetGpuInstanceProfileId = append(mock.calls.GetGpuInstanceProfileId, callInfo)
mock.lockGetGpuInstanceProfileId.Unlock()
return mock.GetGpuInstanceProfileIdFunc()
}
// GetGpuInstanceProfileIdCalls gets all the calls that were made to GetGpuInstanceProfileId.
// Check the length with:
//
// len(mockedVgpuTypeId.GetGpuInstanceProfileIdCalls())
func (mock *VgpuTypeId) GetGpuInstanceProfileIdCalls() []struct {
} {
var calls []struct {
}
mock.lockGetGpuInstanceProfileId.RLock()
calls = mock.calls.GetGpuInstanceProfileId
mock.lockGetGpuInstanceProfileId.RUnlock()
return calls
}
// GetLicense calls GetLicenseFunc.
func (mock *VgpuTypeId) GetLicense() (string, nvml.Return) {
if mock.GetLicenseFunc == nil {
panic("VgpuTypeId.GetLicenseFunc: method is nil but VgpuTypeId.GetLicense was just called")
}
callInfo := struct {
}{}
mock.lockGetLicense.Lock()
mock.calls.GetLicense = append(mock.calls.GetLicense, callInfo)
mock.lockGetLicense.Unlock()
return mock.GetLicenseFunc()
}
// GetLicenseCalls gets all the calls that were made to GetLicense.
// Check the length with:
//
// len(mockedVgpuTypeId.GetLicenseCalls())
func (mock *VgpuTypeId) GetLicenseCalls() []struct {
} {
var calls []struct {
}
mock.lockGetLicense.RLock()
calls = mock.calls.GetLicense
mock.lockGetLicense.RUnlock()
return calls
}
// GetMaxInstances calls GetMaxInstancesFunc.
func (mock *VgpuTypeId) GetMaxInstances(device nvml.Device) (int, nvml.Return) {
if mock.GetMaxInstancesFunc == nil {
panic("VgpuTypeId.GetMaxInstancesFunc: method is nil but VgpuTypeId.GetMaxInstances was just called")
}
callInfo := struct {
Device nvml.Device
}{
Device: device,
}
mock.lockGetMaxInstances.Lock()
mock.calls.GetMaxInstances = append(mock.calls.GetMaxInstances, callInfo)
mock.lockGetMaxInstances.Unlock()
return mock.GetMaxInstancesFunc(device)
}
// GetMaxInstancesCalls gets all the calls that were made to GetMaxInstances.
// Check the length with:
//
// len(mockedVgpuTypeId.GetMaxInstancesCalls())
func (mock *VgpuTypeId) GetMaxInstancesCalls() []struct {
Device nvml.Device
} {
var calls []struct {
Device nvml.Device
}
mock.lockGetMaxInstances.RLock()
calls = mock.calls.GetMaxInstances
mock.lockGetMaxInstances.RUnlock()
return calls
}
// GetMaxInstancesPerVm calls GetMaxInstancesPerVmFunc.
func (mock *VgpuTypeId) GetMaxInstancesPerVm() (int, nvml.Return) {
if mock.GetMaxInstancesPerVmFunc == nil {
panic("VgpuTypeId.GetMaxInstancesPerVmFunc: method is nil but VgpuTypeId.GetMaxInstancesPerVm was just called")
}
callInfo := struct {
}{}
mock.lockGetMaxInstancesPerVm.Lock()
mock.calls.GetMaxInstancesPerVm = append(mock.calls.GetMaxInstancesPerVm, callInfo)
mock.lockGetMaxInstancesPerVm.Unlock()
return mock.GetMaxInstancesPerVmFunc()
}
// GetMaxInstancesPerVmCalls gets all the calls that were made to GetMaxInstancesPerVm.
// Check the length with:
//
// len(mockedVgpuTypeId.GetMaxInstancesPerVmCalls())
func (mock *VgpuTypeId) GetMaxInstancesPerVmCalls() []struct {
} {
var calls []struct {
}
mock.lockGetMaxInstancesPerVm.RLock()
calls = mock.calls.GetMaxInstancesPerVm
mock.lockGetMaxInstancesPerVm.RUnlock()
return calls
}
// GetName calls GetNameFunc.
func (mock *VgpuTypeId) GetName() (string, nvml.Return) {
if mock.GetNameFunc == nil {
panic("VgpuTypeId.GetNameFunc: method is nil but VgpuTypeId.GetName was just called")
}
callInfo := struct {
}{}
mock.lockGetName.Lock()
mock.calls.GetName = append(mock.calls.GetName, callInfo)
mock.lockGetName.Unlock()
return mock.GetNameFunc()
}
// GetNameCalls gets all the calls that were made to GetName.
// Check the length with:
//
// len(mockedVgpuTypeId.GetNameCalls())
func (mock *VgpuTypeId) GetNameCalls() []struct {
} {
var calls []struct {
}
mock.lockGetName.RLock()
calls = mock.calls.GetName
mock.lockGetName.RUnlock()
return calls
}
// GetNumDisplayHeads calls GetNumDisplayHeadsFunc.
func (mock *VgpuTypeId) GetNumDisplayHeads() (int, nvml.Return) {
if mock.GetNumDisplayHeadsFunc == nil {
panic("VgpuTypeId.GetNumDisplayHeadsFunc: method is nil but VgpuTypeId.GetNumDisplayHeads was just called")
}
callInfo := struct {
}{}
mock.lockGetNumDisplayHeads.Lock()
mock.calls.GetNumDisplayHeads = append(mock.calls.GetNumDisplayHeads, callInfo)
mock.lockGetNumDisplayHeads.Unlock()
return mock.GetNumDisplayHeadsFunc()
}
// GetNumDisplayHeadsCalls gets all the calls that were made to GetNumDisplayHeads.
// Check the length with:
//
// len(mockedVgpuTypeId.GetNumDisplayHeadsCalls())
func (mock *VgpuTypeId) GetNumDisplayHeadsCalls() []struct {
} {
var calls []struct {
}
mock.lockGetNumDisplayHeads.RLock()
calls = mock.calls.GetNumDisplayHeads
mock.lockGetNumDisplayHeads.RUnlock()
return calls
}
// GetResolution calls GetResolutionFunc.
func (mock *VgpuTypeId) GetResolution(n int) (uint32, uint32, nvml.Return) {
if mock.GetResolutionFunc == nil {
panic("VgpuTypeId.GetResolutionFunc: method is nil but VgpuTypeId.GetResolution was just called")
}
callInfo := struct {
N int
}{
N: n,
}
mock.lockGetResolution.Lock()
mock.calls.GetResolution = append(mock.calls.GetResolution, callInfo)
mock.lockGetResolution.Unlock()
return mock.GetResolutionFunc(n)
}
// GetResolutionCalls gets all the calls that were made to GetResolution.
// Check the length with:
//
// len(mockedVgpuTypeId.GetResolutionCalls())
func (mock *VgpuTypeId) GetResolutionCalls() []struct {
N int
} {
var calls []struct {
N int
}
mock.lockGetResolution.RLock()
calls = mock.calls.GetResolution
mock.lockGetResolution.RUnlock()
return calls
}

File diff suppressed because it is too large Load Diff

View File

@@ -19,17 +19,27 @@ import (
)
// nvml.ErrorString()
func ErrorString(r Return) string {
if err := GetLibrary().Lookup("nvmlErrorString"); err != nil {
return fallbackErrorStringFunc(r)
}
return nvmlErrorString(r)
func (l *library) ErrorString(r Return) string {
return r.Error()
}
// fallbackErrorStringFunc provides a basic nvmlErrorString implementation.
// String returns the string representation of a Return.
func (r Return) String() string {
return r.Error()
}
// Error returns the string representation of a Return.
func (r Return) Error() string {
return errorStringFunc(r)
}
// Assigned to nvml.ErrorString if the system nvml library is in use.
var errorStringFunc = defaultErrorStringFunc
// defaultErrorStringFunc provides a basic nvmlErrorString implementation.
// This allows the nvml.ErrorString function to be used even if the NVML library
// is not loaded.
var fallbackErrorStringFunc = func(r Return) string {
var defaultErrorStringFunc = func(r Return) string {
switch r {
case SUCCESS:
return "SUCCESS"

View File

@@ -15,67 +15,67 @@
package nvml
// nvml.SystemGetDriverVersion()
func SystemGetDriverVersion() (string, Return) {
func (l *library) SystemGetDriverVersion() (string, Return) {
Version := make([]byte, SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
ret := nvmlSystemGetDriverVersion(&Version[0], SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
return string(Version[:clen(Version)]), ret
}
// nvml.SystemGetNVMLVersion()
func SystemGetNVMLVersion() (string, Return) {
func (l *library) SystemGetNVMLVersion() (string, Return) {
Version := make([]byte, SYSTEM_NVML_VERSION_BUFFER_SIZE)
ret := nvmlSystemGetNVMLVersion(&Version[0], SYSTEM_NVML_VERSION_BUFFER_SIZE)
return string(Version[:clen(Version)]), ret
}
// nvml.SystemGetCudaDriverVersion()
func SystemGetCudaDriverVersion() (int, Return) {
func (l *library) SystemGetCudaDriverVersion() (int, Return) {
var CudaDriverVersion int32
ret := nvmlSystemGetCudaDriverVersion(&CudaDriverVersion)
return int(CudaDriverVersion), ret
}
// nvml.SystemGetCudaDriverVersion_v2()
func SystemGetCudaDriverVersion_v2() (int, Return) {
func (l *library) SystemGetCudaDriverVersion_v2() (int, Return) {
var CudaDriverVersion int32
ret := nvmlSystemGetCudaDriverVersion_v2(&CudaDriverVersion)
return int(CudaDriverVersion), ret
}
// nvml.SystemGetProcessName()
func SystemGetProcessName(Pid int) (string, Return) {
Name := make([]byte, SYSTEM_PROCESS_NAME_BUFFER_SIZE)
ret := nvmlSystemGetProcessName(uint32(Pid), &Name[0], SYSTEM_PROCESS_NAME_BUFFER_SIZE)
return string(Name[:clen(Name)]), ret
func (l *library) SystemGetProcessName(pid int) (string, Return) {
name := make([]byte, SYSTEM_PROCESS_NAME_BUFFER_SIZE)
ret := nvmlSystemGetProcessName(uint32(pid), &name[0], SYSTEM_PROCESS_NAME_BUFFER_SIZE)
return string(name[:clen(name)]), ret
}
// nvml.SystemGetHicVersion()
func SystemGetHicVersion() ([]HwbcEntry, Return) {
var HwbcCount uint32 = 1 // Will be reduced upon returning
func (l *library) SystemGetHicVersion() ([]HwbcEntry, Return) {
var hwbcCount uint32 = 1 // Will be reduced upon returning
for {
HwbcEntries := make([]HwbcEntry, HwbcCount)
ret := nvmlSystemGetHicVersion(&HwbcCount, &HwbcEntries[0])
hwbcEntries := make([]HwbcEntry, hwbcCount)
ret := nvmlSystemGetHicVersion(&hwbcCount, &hwbcEntries[0])
if ret == SUCCESS {
return HwbcEntries[:HwbcCount], ret
return hwbcEntries[:hwbcCount], ret
}
if ret != ERROR_INSUFFICIENT_SIZE {
return nil, ret
}
HwbcCount *= 2
hwbcCount *= 2
}
}
// nvml.SystemGetTopologyGpuSet()
func SystemGetTopologyGpuSet(CpuNumber int) ([]Device, Return) {
var Count uint32
ret := nvmlSystemGetTopologyGpuSet(uint32(CpuNumber), &Count, nil)
func (l *library) SystemGetTopologyGpuSet(cpuNumber int) ([]Device, Return) {
var count uint32
ret := nvmlSystemGetTopologyGpuSet(uint32(cpuNumber), &count, nil)
if ret != SUCCESS {
return nil, ret
}
if Count == 0 {
if count == 0 {
return []Device{}, ret
}
DeviceArray := make([]Device, Count)
ret = nvmlSystemGetTopologyGpuSet(uint32(CpuNumber), &Count, &DeviceArray[0])
return DeviceArray, ret
deviceArray := make([]nvmlDevice, count)
ret = nvmlSystemGetTopologyGpuSet(uint32(cpuNumber), &count, &deviceArray[0])
return convertSlice[nvmlDevice, Device](deviceArray), ret
}

View File

@@ -5,7 +5,7 @@ package nvml
import "unsafe"
type Device struct {
type nvmlDevice struct {
Handle *_Ctype_struct_nvmlDevice_st
}
@@ -143,9 +143,9 @@ type ClkMonStatus struct {
ClkMonList [32]ClkMonFaultInfo
}
type VgpuTypeId uint32
type nvmlVgpuTypeId uint32
type VgpuInstance uint32
type nvmlVgpuInstance uint32
type VgpuInstanceUtilizationSample struct {
VgpuInstance uint32
@@ -316,7 +316,7 @@ type FieldValue struct {
Value [8]byte
}
type Unit struct {
type nvmlUnit struct {
Handle *_Ctype_struct_nvmlUnit_st
}
@@ -354,12 +354,12 @@ type UnitFanSpeeds struct {
Count uint32
}
type EventSet struct {
type nvmlEventSet struct {
Handle *_Ctype_struct_nvmlEventSet_st
}
type EventData struct {
Device Device
type nvmlEventData struct {
Device nvmlDevice
EventType uint64
EventData uint64
GpuInstanceId uint32
@@ -494,14 +494,14 @@ type GpuInstanceProfileInfo_v2 struct {
Name [96]int8
}
type GpuInstanceInfo struct {
Device Device
type nvmlGpuInstanceInfo struct {
Device nvmlDevice
Id uint32
ProfileId uint32
Placement GpuInstancePlacement
}
type GpuInstance struct {
type nvmlGpuInstance struct {
Handle *_Ctype_struct_nvmlGpuInstance_st
}
@@ -536,19 +536,19 @@ type ComputeInstanceProfileInfo_v2 struct {
Name [96]int8
}
type ComputeInstanceInfo struct {
Device Device
GpuInstance GpuInstance
type nvmlComputeInstanceInfo struct {
Device nvmlDevice
GpuInstance nvmlGpuInstance
Id uint32
ProfileId uint32
Placement ComputeInstancePlacement
}
type ComputeInstance struct {
type nvmlComputeInstance struct {
Handle *_Ctype_struct_nvmlComputeInstance_st
}
type GpmSample struct {
type nvmlGpmSample struct {
Handle *_Ctype_struct_nvmlGpmSample_st
}
@@ -565,11 +565,11 @@ type GpmMetric struct {
MetricInfo GpmMetricMetricInfo
}
type GpmMetricsGetType struct {
type nvmlGpmMetricsGetType struct {
Version uint32
NumMetrics uint32
Sample1 GpmSample
Sample2 GpmSample
Sample1 nvmlGpmSample
Sample2 nvmlGpmSample
Metrics [98]GpmMetric
}

View File

@@ -15,99 +15,99 @@
package nvml
// nvml.UnitGetCount()
func UnitGetCount() (int, Return) {
func (l *library) UnitGetCount() (int, Return) {
var UnitCount uint32
ret := nvmlUnitGetCount(&UnitCount)
return int(UnitCount), ret
}
// nvml.UnitGetHandleByIndex()
func UnitGetHandleByIndex(Index int) (Unit, Return) {
var Unit Unit
ret := nvmlUnitGetHandleByIndex(uint32(Index), &Unit)
return Unit, ret
func (l *library) UnitGetHandleByIndex(index int) (Unit, Return) {
var unit nvmlUnit
ret := nvmlUnitGetHandleByIndex(uint32(index), &unit)
return unit, ret
}
// nvml.UnitGetUnitInfo()
func UnitGetUnitInfo(Unit Unit) (UnitInfo, Return) {
var Info UnitInfo
ret := nvmlUnitGetUnitInfo(Unit, &Info)
return Info, ret
func (l *library) UnitGetUnitInfo(unit Unit) (UnitInfo, Return) {
return unit.GetUnitInfo()
}
func (Unit Unit) GetUnitInfo() (UnitInfo, Return) {
return UnitGetUnitInfo(Unit)
func (unit nvmlUnit) GetUnitInfo() (UnitInfo, Return) {
var info UnitInfo
ret := nvmlUnitGetUnitInfo(unit, &info)
return info, ret
}
// nvml.UnitGetLedState()
func UnitGetLedState(Unit Unit) (LedState, Return) {
var State LedState
ret := nvmlUnitGetLedState(Unit, &State)
return State, ret
func (l *library) UnitGetLedState(unit Unit) (LedState, Return) {
return unit.GetLedState()
}
func (Unit Unit) GetLedState() (LedState, Return) {
return UnitGetLedState(Unit)
func (unit nvmlUnit) GetLedState() (LedState, Return) {
var state LedState
ret := nvmlUnitGetLedState(unit, &state)
return state, ret
}
// nvml.UnitGetPsuInfo()
func UnitGetPsuInfo(Unit Unit) (PSUInfo, Return) {
var Psu PSUInfo
ret := nvmlUnitGetPsuInfo(Unit, &Psu)
return Psu, ret
func (l *library) UnitGetPsuInfo(unit Unit) (PSUInfo, Return) {
return unit.GetPsuInfo()
}
func (Unit Unit) GetPsuInfo() (PSUInfo, Return) {
return UnitGetPsuInfo(Unit)
func (unit nvmlUnit) GetPsuInfo() (PSUInfo, Return) {
var psu PSUInfo
ret := nvmlUnitGetPsuInfo(unit, &psu)
return psu, ret
}
// nvml.UnitGetTemperature()
func UnitGetTemperature(Unit Unit, Type int) (uint32, Return) {
var Temp uint32
ret := nvmlUnitGetTemperature(Unit, uint32(Type), &Temp)
return Temp, ret
func (l *library) UnitGetTemperature(unit Unit, ttype int) (uint32, Return) {
return unit.GetTemperature(ttype)
}
func (Unit Unit) GetTemperature(Type int) (uint32, Return) {
return UnitGetTemperature(Unit, Type)
func (unit nvmlUnit) GetTemperature(ttype int) (uint32, Return) {
var temp uint32
ret := nvmlUnitGetTemperature(unit, uint32(ttype), &temp)
return temp, ret
}
// nvml.UnitGetFanSpeedInfo()
func UnitGetFanSpeedInfo(Unit Unit) (UnitFanSpeeds, Return) {
var FanSpeeds UnitFanSpeeds
ret := nvmlUnitGetFanSpeedInfo(Unit, &FanSpeeds)
return FanSpeeds, ret
func (l *library) UnitGetFanSpeedInfo(unit Unit) (UnitFanSpeeds, Return) {
return unit.GetFanSpeedInfo()
}
func (Unit Unit) GetFanSpeedInfo() (UnitFanSpeeds, Return) {
return UnitGetFanSpeedInfo(Unit)
func (unit nvmlUnit) GetFanSpeedInfo() (UnitFanSpeeds, Return) {
var fanSpeeds UnitFanSpeeds
ret := nvmlUnitGetFanSpeedInfo(unit, &fanSpeeds)
return fanSpeeds, ret
}
// nvml.UnitGetDevices()
func UnitGetDevices(Unit Unit) ([]Device, Return) {
var DeviceCount uint32 = 1 // Will be reduced upon returning
func (l *library) UnitGetDevices(unit Unit) ([]Device, Return) {
return unit.GetDevices()
}
func (unit nvmlUnit) GetDevices() ([]Device, Return) {
var deviceCount uint32 = 1 // Will be reduced upon returning
for {
Devices := make([]Device, DeviceCount)
ret := nvmlUnitGetDevices(Unit, &DeviceCount, &Devices[0])
devices := make([]nvmlDevice, deviceCount)
ret := nvmlUnitGetDevices(unit, &deviceCount, &devices[0])
if ret == SUCCESS {
return Devices[:DeviceCount], ret
return convertSlice[nvmlDevice, Device](devices[:deviceCount]), ret
}
if ret != ERROR_INSUFFICIENT_SIZE {
return nil, ret
}
DeviceCount *= 2
deviceCount *= 2
}
}
func (Unit Unit) GetDevices() ([]Device, Return) {
return UnitGetDevices(Unit)
}
// nvml.UnitSetLedState()
func UnitSetLedState(Unit Unit, Color LedColor) Return {
return nvmlUnitSetLedState(Unit, Color)
func (l *library) UnitSetLedState(unit Unit, color LedColor) Return {
return unit.SetLedState(color)
}
func (Unit Unit) SetLedState(Color LedColor) Return {
return UnitSetLedState(Unit, Color)
func (unit nvmlUnit) SetLedState(color LedColor) Return {
return nvmlUnitSetLedState(unit, color)
}

View File

@@ -31,450 +31,450 @@ type VgpuPgpuMetadata struct {
}
// nvml.VgpuTypeGetClass()
func VgpuTypeGetClass(VgpuTypeId VgpuTypeId) (string, Return) {
var Size uint32 = DEVICE_NAME_BUFFER_SIZE
VgpuTypeClass := make([]byte, DEVICE_NAME_BUFFER_SIZE)
ret := nvmlVgpuTypeGetClass(VgpuTypeId, &VgpuTypeClass[0], &Size)
return string(VgpuTypeClass[:clen(VgpuTypeClass)]), ret
func (l *library) VgpuTypeGetClass(vgpuTypeId VgpuTypeId) (string, Return) {
return vgpuTypeId.GetClass()
}
func (VgpuTypeId VgpuTypeId) GetClass() (string, Return) {
return VgpuTypeGetClass(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetClass() (string, Return) {
var size uint32 = DEVICE_NAME_BUFFER_SIZE
vgpuTypeClass := make([]byte, DEVICE_NAME_BUFFER_SIZE)
ret := nvmlVgpuTypeGetClass(vgpuTypeId, &vgpuTypeClass[0], &size)
return string(vgpuTypeClass[:clen(vgpuTypeClass)]), ret
}
// nvml.VgpuTypeGetName()
func VgpuTypeGetName(VgpuTypeId VgpuTypeId) (string, Return) {
var Size uint32 = DEVICE_NAME_BUFFER_SIZE
VgpuTypeName := make([]byte, DEVICE_NAME_BUFFER_SIZE)
ret := nvmlVgpuTypeGetName(VgpuTypeId, &VgpuTypeName[0], &Size)
return string(VgpuTypeName[:clen(VgpuTypeName)]), ret
func (l *library) VgpuTypeGetName(vgpuTypeId VgpuTypeId) (string, Return) {
return vgpuTypeId.GetName()
}
func (VgpuTypeId VgpuTypeId) GetName() (string, Return) {
return VgpuTypeGetName(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetName() (string, Return) {
var size uint32 = DEVICE_NAME_BUFFER_SIZE
vgpuTypeName := make([]byte, DEVICE_NAME_BUFFER_SIZE)
ret := nvmlVgpuTypeGetName(vgpuTypeId, &vgpuTypeName[0], &size)
return string(vgpuTypeName[:clen(vgpuTypeName)]), ret
}
// nvml.VgpuTypeGetGpuInstanceProfileId()
func VgpuTypeGetGpuInstanceProfileId(VgpuTypeId VgpuTypeId) (uint32, Return) {
var Size uint32
ret := nvmlVgpuTypeGetGpuInstanceProfileId(VgpuTypeId, &Size)
return Size, ret
func (l *library) VgpuTypeGetGpuInstanceProfileId(vgpuTypeId VgpuTypeId) (uint32, Return) {
return vgpuTypeId.GetGpuInstanceProfileId()
}
func (VgpuTypeId VgpuTypeId) GetGpuInstanceProfileId() (uint32, Return) {
return VgpuTypeGetGpuInstanceProfileId(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetGpuInstanceProfileId() (uint32, Return) {
var size uint32
ret := nvmlVgpuTypeGetGpuInstanceProfileId(vgpuTypeId, &size)
return size, ret
}
// nvml.VgpuTypeGetDeviceID()
func VgpuTypeGetDeviceID(VgpuTypeId VgpuTypeId) (uint64, uint64, Return) {
var DeviceID, SubsystemID uint64
ret := nvmlVgpuTypeGetDeviceID(VgpuTypeId, &DeviceID, &SubsystemID)
return DeviceID, SubsystemID, ret
func (l *library) VgpuTypeGetDeviceID(vgpuTypeId VgpuTypeId) (uint64, uint64, Return) {
return vgpuTypeId.GetDeviceID()
}
func (VgpuTypeId VgpuTypeId) GetDeviceID() (uint64, uint64, Return) {
return VgpuTypeGetDeviceID(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetDeviceID() (uint64, uint64, Return) {
var deviceID, subsystemID uint64
ret := nvmlVgpuTypeGetDeviceID(vgpuTypeId, &deviceID, &subsystemID)
return deviceID, subsystemID, ret
}
// nvml.VgpuTypeGetFramebufferSize()
func VgpuTypeGetFramebufferSize(VgpuTypeId VgpuTypeId) (uint64, Return) {
var FbSize uint64
ret := nvmlVgpuTypeGetFramebufferSize(VgpuTypeId, &FbSize)
return FbSize, ret
func (l *library) VgpuTypeGetFramebufferSize(vgpuTypeId VgpuTypeId) (uint64, Return) {
return vgpuTypeId.GetFramebufferSize()
}
func (VgpuTypeId VgpuTypeId) GetFramebufferSize() (uint64, Return) {
return VgpuTypeGetFramebufferSize(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetFramebufferSize() (uint64, Return) {
var fbSize uint64
ret := nvmlVgpuTypeGetFramebufferSize(vgpuTypeId, &fbSize)
return fbSize, ret
}
// nvml.VgpuTypeGetNumDisplayHeads()
func VgpuTypeGetNumDisplayHeads(VgpuTypeId VgpuTypeId) (int, Return) {
var NumDisplayHeads uint32
ret := nvmlVgpuTypeGetNumDisplayHeads(VgpuTypeId, &NumDisplayHeads)
return int(NumDisplayHeads), ret
func (l *library) VgpuTypeGetNumDisplayHeads(vgpuTypeId VgpuTypeId) (int, Return) {
return vgpuTypeId.GetNumDisplayHeads()
}
func (VgpuTypeId VgpuTypeId) GetNumDisplayHeads() (int, Return) {
return VgpuTypeGetNumDisplayHeads(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetNumDisplayHeads() (int, Return) {
var numDisplayHeads uint32
ret := nvmlVgpuTypeGetNumDisplayHeads(vgpuTypeId, &numDisplayHeads)
return int(numDisplayHeads), ret
}
// nvml.VgpuTypeGetResolution()
func VgpuTypeGetResolution(VgpuTypeId VgpuTypeId, DisplayIndex int) (uint32, uint32, Return) {
var Xdim, Ydim uint32
ret := nvmlVgpuTypeGetResolution(VgpuTypeId, uint32(DisplayIndex), &Xdim, &Ydim)
return Xdim, Ydim, ret
func (l *library) VgpuTypeGetResolution(vgpuTypeId VgpuTypeId, displayIndex int) (uint32, uint32, Return) {
return vgpuTypeId.GetResolution(displayIndex)
}
func (VgpuTypeId VgpuTypeId) GetResolution(DisplayIndex int) (uint32, uint32, Return) {
return VgpuTypeGetResolution(VgpuTypeId, DisplayIndex)
func (vgpuTypeId nvmlVgpuTypeId) GetResolution(displayIndex int) (uint32, uint32, Return) {
var xdim, ydim uint32
ret := nvmlVgpuTypeGetResolution(vgpuTypeId, uint32(displayIndex), &xdim, &ydim)
return xdim, ydim, ret
}
// nvml.VgpuTypeGetLicense()
func VgpuTypeGetLicense(VgpuTypeId VgpuTypeId) (string, Return) {
VgpuTypeLicenseString := make([]byte, GRID_LICENSE_BUFFER_SIZE)
ret := nvmlVgpuTypeGetLicense(VgpuTypeId, &VgpuTypeLicenseString[0], GRID_LICENSE_BUFFER_SIZE)
return string(VgpuTypeLicenseString[:clen(VgpuTypeLicenseString)]), ret
func (l *library) VgpuTypeGetLicense(vgpuTypeId VgpuTypeId) (string, Return) {
return vgpuTypeId.GetLicense()
}
func (VgpuTypeId VgpuTypeId) GetLicense() (string, Return) {
return VgpuTypeGetLicense(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetLicense() (string, Return) {
vgpuTypeLicenseString := make([]byte, GRID_LICENSE_BUFFER_SIZE)
ret := nvmlVgpuTypeGetLicense(vgpuTypeId, &vgpuTypeLicenseString[0], GRID_LICENSE_BUFFER_SIZE)
return string(vgpuTypeLicenseString[:clen(vgpuTypeLicenseString)]), ret
}
// nvml.VgpuTypeGetFrameRateLimit()
func VgpuTypeGetFrameRateLimit(VgpuTypeId VgpuTypeId) (uint32, Return) {
var FrameRateLimit uint32
ret := nvmlVgpuTypeGetFrameRateLimit(VgpuTypeId, &FrameRateLimit)
return FrameRateLimit, ret
func (l *library) VgpuTypeGetFrameRateLimit(vgpuTypeId VgpuTypeId) (uint32, Return) {
return vgpuTypeId.GetFrameRateLimit()
}
func (VgpuTypeId VgpuTypeId) GetFrameRateLimit() (uint32, Return) {
return VgpuTypeGetFrameRateLimit(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetFrameRateLimit() (uint32, Return) {
var frameRateLimit uint32
ret := nvmlVgpuTypeGetFrameRateLimit(vgpuTypeId, &frameRateLimit)
return frameRateLimit, ret
}
// nvml.VgpuTypeGetMaxInstances()
func VgpuTypeGetMaxInstances(Device Device, VgpuTypeId VgpuTypeId) (int, Return) {
var VgpuInstanceCount uint32
ret := nvmlVgpuTypeGetMaxInstances(Device, VgpuTypeId, &VgpuInstanceCount)
return int(VgpuInstanceCount), ret
func (l *library) VgpuTypeGetMaxInstances(device Device, vgpuTypeId VgpuTypeId) (int, Return) {
return vgpuTypeId.GetMaxInstances(device)
}
func (Device Device) VgpuTypeGetMaxInstances(VgpuTypeId VgpuTypeId) (int, Return) {
return VgpuTypeGetMaxInstances(Device, VgpuTypeId)
func (device nvmlDevice) VgpuTypeGetMaxInstances(vgpuTypeId VgpuTypeId) (int, Return) {
return vgpuTypeId.GetMaxInstances(device)
}
func (VgpuTypeId VgpuTypeId) GetMaxInstances(Device Device) (int, Return) {
return VgpuTypeGetMaxInstances(Device, VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetMaxInstances(device Device) (int, Return) {
var vgpuInstanceCount uint32
ret := nvmlVgpuTypeGetMaxInstances(nvmlDeviceHandle(device), vgpuTypeId, &vgpuInstanceCount)
return int(vgpuInstanceCount), ret
}
// nvml.VgpuTypeGetMaxInstancesPerVm()
func VgpuTypeGetMaxInstancesPerVm(VgpuTypeId VgpuTypeId) (int, Return) {
var VgpuInstanceCountPerVm uint32
ret := nvmlVgpuTypeGetMaxInstancesPerVm(VgpuTypeId, &VgpuInstanceCountPerVm)
return int(VgpuInstanceCountPerVm), ret
func (l *library) VgpuTypeGetMaxInstancesPerVm(vgpuTypeId VgpuTypeId) (int, Return) {
return vgpuTypeId.GetMaxInstancesPerVm()
}
func (VgpuTypeId VgpuTypeId) GetMaxInstancesPerVm() (int, Return) {
return VgpuTypeGetMaxInstancesPerVm(VgpuTypeId)
func (vgpuTypeId nvmlVgpuTypeId) GetMaxInstancesPerVm() (int, Return) {
var vgpuInstanceCountPerVm uint32
ret := nvmlVgpuTypeGetMaxInstancesPerVm(vgpuTypeId, &vgpuInstanceCountPerVm)
return int(vgpuInstanceCountPerVm), ret
}
// nvml.VgpuInstanceGetVmID()
func VgpuInstanceGetVmID(VgpuInstance VgpuInstance) (string, VgpuVmIdType, Return) {
var VmIdType VgpuVmIdType
VmId := make([]byte, DEVICE_UUID_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetVmID(VgpuInstance, &VmId[0], DEVICE_UUID_BUFFER_SIZE, &VmIdType)
return string(VmId[:clen(VmId)]), VmIdType, ret
func (l *library) VgpuInstanceGetVmID(vgpuInstance VgpuInstance) (string, VgpuVmIdType, Return) {
return vgpuInstance.GetVmID()
}
func (VgpuInstance VgpuInstance) GetVmID() (string, VgpuVmIdType, Return) {
return VgpuInstanceGetVmID(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetVmID() (string, VgpuVmIdType, Return) {
var vmIdType VgpuVmIdType
vmId := make([]byte, DEVICE_UUID_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetVmID(vgpuInstance, &vmId[0], DEVICE_UUID_BUFFER_SIZE, &vmIdType)
return string(vmId[:clen(vmId)]), vmIdType, ret
}
// nvml.VgpuInstanceGetUUID()
func VgpuInstanceGetUUID(VgpuInstance VgpuInstance) (string, Return) {
Uuid := make([]byte, DEVICE_UUID_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetUUID(VgpuInstance, &Uuid[0], DEVICE_UUID_BUFFER_SIZE)
return string(Uuid[:clen(Uuid)]), ret
func (l *library) VgpuInstanceGetUUID(vgpuInstance VgpuInstance) (string, Return) {
return vgpuInstance.GetUUID()
}
func (VgpuInstance VgpuInstance) GetUUID() (string, Return) {
return VgpuInstanceGetUUID(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetUUID() (string, Return) {
uuid := make([]byte, DEVICE_UUID_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetUUID(vgpuInstance, &uuid[0], DEVICE_UUID_BUFFER_SIZE)
return string(uuid[:clen(uuid)]), ret
}
// nvml.VgpuInstanceGetVmDriverVersion()
func VgpuInstanceGetVmDriverVersion(VgpuInstance VgpuInstance) (string, Return) {
Version := make([]byte, SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetVmDriverVersion(VgpuInstance, &Version[0], SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
return string(Version[:clen(Version)]), ret
func (l *library) VgpuInstanceGetVmDriverVersion(vgpuInstance VgpuInstance) (string, Return) {
return vgpuInstance.GetVmDriverVersion()
}
func (VgpuInstance VgpuInstance) GetVmDriverVersion() (string, Return) {
return VgpuInstanceGetVmDriverVersion(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetVmDriverVersion() (string, Return) {
version := make([]byte, SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetVmDriverVersion(vgpuInstance, &version[0], SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
return string(version[:clen(version)]), ret
}
// nvml.VgpuInstanceGetFbUsage()
func VgpuInstanceGetFbUsage(VgpuInstance VgpuInstance) (uint64, Return) {
var FbUsage uint64
ret := nvmlVgpuInstanceGetFbUsage(VgpuInstance, &FbUsage)
return FbUsage, ret
func (l *library) VgpuInstanceGetFbUsage(vgpuInstance VgpuInstance) (uint64, Return) {
return vgpuInstance.GetFbUsage()
}
func (VgpuInstance VgpuInstance) GetFbUsage() (uint64, Return) {
return VgpuInstanceGetFbUsage(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetFbUsage() (uint64, Return) {
var fbUsage uint64
ret := nvmlVgpuInstanceGetFbUsage(vgpuInstance, &fbUsage)
return fbUsage, ret
}
// nvml.VgpuInstanceGetLicenseInfo()
func VgpuInstanceGetLicenseInfo(VgpuInstance VgpuInstance) (VgpuLicenseInfo, Return) {
var LicenseInfo VgpuLicenseInfo
ret := nvmlVgpuInstanceGetLicenseInfo(VgpuInstance, &LicenseInfo)
return LicenseInfo, ret
func (l *library) VgpuInstanceGetLicenseInfo(vgpuInstance VgpuInstance) (VgpuLicenseInfo, Return) {
return vgpuInstance.GetLicenseInfo()
}
func (VgpuInstance VgpuInstance) GetLicenseInfo() (VgpuLicenseInfo, Return) {
return VgpuInstanceGetLicenseInfo(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetLicenseInfo() (VgpuLicenseInfo, Return) {
var licenseInfo VgpuLicenseInfo
ret := nvmlVgpuInstanceGetLicenseInfo(vgpuInstance, &licenseInfo)
return licenseInfo, ret
}
// nvml.VgpuInstanceGetLicenseStatus()
func VgpuInstanceGetLicenseStatus(VgpuInstance VgpuInstance) (int, Return) {
var Licensed uint32
ret := nvmlVgpuInstanceGetLicenseStatus(VgpuInstance, &Licensed)
return int(Licensed), ret
func (l *library) VgpuInstanceGetLicenseStatus(vgpuInstance VgpuInstance) (int, Return) {
return vgpuInstance.GetLicenseStatus()
}
func (VgpuInstance VgpuInstance) GetLicenseStatus() (int, Return) {
return VgpuInstanceGetLicenseStatus(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetLicenseStatus() (int, Return) {
var licensed uint32
ret := nvmlVgpuInstanceGetLicenseStatus(vgpuInstance, &licensed)
return int(licensed), ret
}
// nvml.VgpuInstanceGetType()
func VgpuInstanceGetType(VgpuInstance VgpuInstance) (VgpuTypeId, Return) {
var VgpuTypeId VgpuTypeId
ret := nvmlVgpuInstanceGetType(VgpuInstance, &VgpuTypeId)
return VgpuTypeId, ret
func (l *library) VgpuInstanceGetType(vgpuInstance VgpuInstance) (VgpuTypeId, Return) {
return vgpuInstance.GetType()
}
func (VgpuInstance VgpuInstance) GetType() (VgpuTypeId, Return) {
return VgpuInstanceGetType(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetType() (VgpuTypeId, Return) {
var vgpuTypeId nvmlVgpuTypeId
ret := nvmlVgpuInstanceGetType(vgpuInstance, &vgpuTypeId)
return vgpuTypeId, ret
}
// nvml.VgpuInstanceGetFrameRateLimit()
func VgpuInstanceGetFrameRateLimit(VgpuInstance VgpuInstance) (uint32, Return) {
var FrameRateLimit uint32
ret := nvmlVgpuInstanceGetFrameRateLimit(VgpuInstance, &FrameRateLimit)
return FrameRateLimit, ret
func (l *library) VgpuInstanceGetFrameRateLimit(vgpuInstance VgpuInstance) (uint32, Return) {
return vgpuInstance.GetFrameRateLimit()
}
func (VgpuInstance VgpuInstance) GetFrameRateLimit() (uint32, Return) {
return VgpuInstanceGetFrameRateLimit(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetFrameRateLimit() (uint32, Return) {
var frameRateLimit uint32
ret := nvmlVgpuInstanceGetFrameRateLimit(vgpuInstance, &frameRateLimit)
return frameRateLimit, ret
}
// nvml.VgpuInstanceGetEccMode()
func VgpuInstanceGetEccMode(VgpuInstance VgpuInstance) (EnableState, Return) {
var EccMode EnableState
ret := nvmlVgpuInstanceGetEccMode(VgpuInstance, &EccMode)
return EccMode, ret
func (l *library) VgpuInstanceGetEccMode(vgpuInstance VgpuInstance) (EnableState, Return) {
return vgpuInstance.GetEccMode()
}
func (VgpuInstance VgpuInstance) GetEccMode() (EnableState, Return) {
return VgpuInstanceGetEccMode(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetEccMode() (EnableState, Return) {
var eccMode EnableState
ret := nvmlVgpuInstanceGetEccMode(vgpuInstance, &eccMode)
return eccMode, ret
}
// nvml.VgpuInstanceGetEncoderCapacity()
func VgpuInstanceGetEncoderCapacity(VgpuInstance VgpuInstance) (int, Return) {
var EncoderCapacity uint32
ret := nvmlVgpuInstanceGetEncoderCapacity(VgpuInstance, &EncoderCapacity)
return int(EncoderCapacity), ret
func (l *library) VgpuInstanceGetEncoderCapacity(vgpuInstance VgpuInstance) (int, Return) {
return vgpuInstance.GetEncoderCapacity()
}
func (VgpuInstance VgpuInstance) GetEncoderCapacity() (int, Return) {
return VgpuInstanceGetEncoderCapacity(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetEncoderCapacity() (int, Return) {
var encoderCapacity uint32
ret := nvmlVgpuInstanceGetEncoderCapacity(vgpuInstance, &encoderCapacity)
return int(encoderCapacity), ret
}
// nvml.VgpuInstanceSetEncoderCapacity()
func VgpuInstanceSetEncoderCapacity(VgpuInstance VgpuInstance, EncoderCapacity int) Return {
return nvmlVgpuInstanceSetEncoderCapacity(VgpuInstance, uint32(EncoderCapacity))
func (l *library) VgpuInstanceSetEncoderCapacity(vgpuInstance VgpuInstance, encoderCapacity int) Return {
return vgpuInstance.SetEncoderCapacity(encoderCapacity)
}
func (VgpuInstance VgpuInstance) SetEncoderCapacity(EncoderCapacity int) Return {
return VgpuInstanceSetEncoderCapacity(VgpuInstance, EncoderCapacity)
func (vgpuInstance nvmlVgpuInstance) SetEncoderCapacity(encoderCapacity int) Return {
return nvmlVgpuInstanceSetEncoderCapacity(vgpuInstance, uint32(encoderCapacity))
}
// nvml.VgpuInstanceGetEncoderStats()
func VgpuInstanceGetEncoderStats(VgpuInstance VgpuInstance) (int, uint32, uint32, Return) {
var SessionCount, AverageFps, AverageLatency uint32
ret := nvmlVgpuInstanceGetEncoderStats(VgpuInstance, &SessionCount, &AverageFps, &AverageLatency)
return int(SessionCount), AverageFps, AverageLatency, ret
func (l *library) VgpuInstanceGetEncoderStats(vgpuInstance VgpuInstance) (int, uint32, uint32, Return) {
return vgpuInstance.GetEncoderStats()
}
func (VgpuInstance VgpuInstance) GetEncoderStats() (int, uint32, uint32, Return) {
return VgpuInstanceGetEncoderStats(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetEncoderStats() (int, uint32, uint32, Return) {
var sessionCount, averageFps, averageLatency uint32
ret := nvmlVgpuInstanceGetEncoderStats(vgpuInstance, &sessionCount, &averageFps, &averageLatency)
return int(sessionCount), averageFps, averageLatency, ret
}
// nvml.VgpuInstanceGetEncoderSessions()
func VgpuInstanceGetEncoderSessions(VgpuInstance VgpuInstance) (int, EncoderSessionInfo, Return) {
var SessionCount uint32
var SessionInfo EncoderSessionInfo
ret := nvmlVgpuInstanceGetEncoderSessions(VgpuInstance, &SessionCount, &SessionInfo)
return int(SessionCount), SessionInfo, ret
func (l *library) VgpuInstanceGetEncoderSessions(vgpuInstance VgpuInstance) (int, EncoderSessionInfo, Return) {
return vgpuInstance.GetEncoderSessions()
}
func (VgpuInstance VgpuInstance) GetEncoderSessions() (int, EncoderSessionInfo, Return) {
return VgpuInstanceGetEncoderSessions(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetEncoderSessions() (int, EncoderSessionInfo, Return) {
var sessionCount uint32
var sessionInfo EncoderSessionInfo
ret := nvmlVgpuInstanceGetEncoderSessions(vgpuInstance, &sessionCount, &sessionInfo)
return int(sessionCount), sessionInfo, ret
}
// nvml.VgpuInstanceGetFBCStats()
func VgpuInstanceGetFBCStats(VgpuInstance VgpuInstance) (FBCStats, Return) {
var FbcStats FBCStats
ret := nvmlVgpuInstanceGetFBCStats(VgpuInstance, &FbcStats)
return FbcStats, ret
func (l *library) VgpuInstanceGetFBCStats(vgpuInstance VgpuInstance) (FBCStats, Return) {
return vgpuInstance.GetFBCStats()
}
func (VgpuInstance VgpuInstance) GetFBCStats() (FBCStats, Return) {
return VgpuInstanceGetFBCStats(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetFBCStats() (FBCStats, Return) {
var fbcStats FBCStats
ret := nvmlVgpuInstanceGetFBCStats(vgpuInstance, &fbcStats)
return fbcStats, ret
}
// nvml.VgpuInstanceGetFBCSessions()
func VgpuInstanceGetFBCSessions(VgpuInstance VgpuInstance) (int, FBCSessionInfo, Return) {
var SessionCount uint32
var SessionInfo FBCSessionInfo
ret := nvmlVgpuInstanceGetFBCSessions(VgpuInstance, &SessionCount, &SessionInfo)
return int(SessionCount), SessionInfo, ret
func (l *library) VgpuInstanceGetFBCSessions(vgpuInstance VgpuInstance) (int, FBCSessionInfo, Return) {
return vgpuInstance.GetFBCSessions()
}
func (VgpuInstance VgpuInstance) GetFBCSessions() (int, FBCSessionInfo, Return) {
return VgpuInstanceGetFBCSessions(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetFBCSessions() (int, FBCSessionInfo, Return) {
var sessionCount uint32
var sessionInfo FBCSessionInfo
ret := nvmlVgpuInstanceGetFBCSessions(vgpuInstance, &sessionCount, &sessionInfo)
return int(sessionCount), sessionInfo, ret
}
// nvml.VgpuInstanceGetGpuInstanceId()
func VgpuInstanceGetGpuInstanceId(VgpuInstance VgpuInstance) (int, Return) {
func (l *library) VgpuInstanceGetGpuInstanceId(vgpuInstance VgpuInstance) (int, Return) {
return vgpuInstance.GetGpuInstanceId()
}
func (vgpuInstance nvmlVgpuInstance) GetGpuInstanceId() (int, Return) {
var gpuInstanceId uint32
ret := nvmlVgpuInstanceGetGpuInstanceId(VgpuInstance, &gpuInstanceId)
ret := nvmlVgpuInstanceGetGpuInstanceId(vgpuInstance, &gpuInstanceId)
return int(gpuInstanceId), ret
}
func (VgpuInstance VgpuInstance) GetGpuInstanceId() (int, Return) {
return VgpuInstanceGetGpuInstanceId(VgpuInstance)
// nvml.VgpuInstanceGetGpuPciId()
func (l *library) VgpuInstanceGetGpuPciId(vgpuInstance VgpuInstance) (string, Return) {
return vgpuInstance.GetGpuPciId()
}
// nvml.VgpuInstanceGetGpuPciId()
func VgpuInstanceGetGpuPciId(VgpuInstance VgpuInstance) (string, Return) {
var Length uint32 = 1 // Will be reduced upon returning
func (vgpuInstance nvmlVgpuInstance) GetGpuPciId() (string, Return) {
var length uint32 = 1 // Will be reduced upon returning
for {
VgpuPciId := make([]byte, Length)
ret := nvmlVgpuInstanceGetGpuPciId(VgpuInstance, &VgpuPciId[0], &Length)
vgpuPciId := make([]byte, length)
ret := nvmlVgpuInstanceGetGpuPciId(vgpuInstance, &vgpuPciId[0], &length)
if ret == SUCCESS {
return string(VgpuPciId[:clen(VgpuPciId)]), ret
return string(vgpuPciId[:clen(vgpuPciId)]), ret
}
if ret != ERROR_INSUFFICIENT_SIZE {
return "", ret
}
Length *= 2
length *= 2
}
}
func (VgpuInstance VgpuInstance) GetGpuPciId() (string, Return) {
return VgpuInstanceGetGpuPciId(VgpuInstance)
}
// nvml.VgpuInstanceGetMetadata()
func VgpuInstanceGetMetadata(VgpuInstance VgpuInstance) (VgpuMetadata, Return) {
var VgpuMetadata VgpuMetadata
OpaqueDataSize := unsafe.Sizeof(VgpuMetadata.nvmlVgpuMetadata.OpaqueData)
VgpuMetadataSize := unsafe.Sizeof(VgpuMetadata.nvmlVgpuMetadata) - OpaqueDataSize
func (l *library) VgpuInstanceGetMetadata(vgpuInstance VgpuInstance) (VgpuMetadata, Return) {
return vgpuInstance.GetMetadata()
}
func (vgpuInstance nvmlVgpuInstance) GetMetadata() (VgpuMetadata, Return) {
var vgpuMetadata VgpuMetadata
opaqueDataSize := unsafe.Sizeof(vgpuMetadata.nvmlVgpuMetadata.OpaqueData)
vgpuMetadataSize := unsafe.Sizeof(vgpuMetadata.nvmlVgpuMetadata) - opaqueDataSize
for {
BufferSize := uint32(VgpuMetadataSize + OpaqueDataSize)
Buffer := make([]byte, BufferSize)
nvmlVgpuMetadataPtr := (*nvmlVgpuMetadata)(unsafe.Pointer(&Buffer[0]))
ret := nvmlVgpuInstanceGetMetadata(VgpuInstance, nvmlVgpuMetadataPtr, &BufferSize)
bufferSize := uint32(vgpuMetadataSize + opaqueDataSize)
buffer := make([]byte, bufferSize)
nvmlVgpuMetadataPtr := (*nvmlVgpuMetadata)(unsafe.Pointer(&buffer[0]))
ret := nvmlVgpuInstanceGetMetadata(vgpuInstance, nvmlVgpuMetadataPtr, &bufferSize)
if ret == SUCCESS {
VgpuMetadata.nvmlVgpuMetadata = *nvmlVgpuMetadataPtr
VgpuMetadata.OpaqueData = Buffer[VgpuMetadataSize:BufferSize]
return VgpuMetadata, ret
vgpuMetadata.nvmlVgpuMetadata = *nvmlVgpuMetadataPtr
vgpuMetadata.OpaqueData = buffer[vgpuMetadataSize:bufferSize]
return vgpuMetadata, ret
}
if ret != ERROR_INSUFFICIENT_SIZE {
return VgpuMetadata, ret
return vgpuMetadata, ret
}
OpaqueDataSize = 2 * OpaqueDataSize
opaqueDataSize = 2 * opaqueDataSize
}
}
func (VgpuInstance VgpuInstance) GetMetadata() (VgpuMetadata, Return) {
return VgpuInstanceGetMetadata(VgpuInstance)
}
// nvml.VgpuInstanceGetAccountingMode()
func VgpuInstanceGetAccountingMode(VgpuInstance VgpuInstance) (EnableState, Return) {
var Mode EnableState
ret := nvmlVgpuInstanceGetAccountingMode(VgpuInstance, &Mode)
return Mode, ret
func (l *library) VgpuInstanceGetAccountingMode(vgpuInstance VgpuInstance) (EnableState, Return) {
return vgpuInstance.GetAccountingMode()
}
func (VgpuInstance VgpuInstance) GetAccountingMode() (EnableState, Return) {
return VgpuInstanceGetAccountingMode(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetAccountingMode() (EnableState, Return) {
var mode EnableState
ret := nvmlVgpuInstanceGetAccountingMode(vgpuInstance, &mode)
return mode, ret
}
// nvml.VgpuInstanceGetAccountingPids()
func VgpuInstanceGetAccountingPids(VgpuInstance VgpuInstance) ([]int, Return) {
var Count uint32 = 1 // Will be reduced upon returning
func (l *library) VgpuInstanceGetAccountingPids(vgpuInstance VgpuInstance) ([]int, Return) {
return vgpuInstance.GetAccountingPids()
}
func (vgpuInstance nvmlVgpuInstance) GetAccountingPids() ([]int, Return) {
var count uint32 = 1 // Will be reduced upon returning
for {
Pids := make([]uint32, Count)
ret := nvmlVgpuInstanceGetAccountingPids(VgpuInstance, &Count, &Pids[0])
pids := make([]uint32, count)
ret := nvmlVgpuInstanceGetAccountingPids(vgpuInstance, &count, &pids[0])
if ret == SUCCESS {
return uint32SliceToIntSlice(Pids[:Count]), ret
return uint32SliceToIntSlice(pids[:count]), ret
}
if ret != ERROR_INSUFFICIENT_SIZE {
return nil, ret
}
Count *= 2
count *= 2
}
}
func (VgpuInstance VgpuInstance) GetAccountingPids() ([]int, Return) {
return VgpuInstanceGetAccountingPids(VgpuInstance)
}
// nvml.VgpuInstanceGetAccountingStats()
func VgpuInstanceGetAccountingStats(VgpuInstance VgpuInstance, Pid int) (AccountingStats, Return) {
var Stats AccountingStats
ret := nvmlVgpuInstanceGetAccountingStats(VgpuInstance, uint32(Pid), &Stats)
return Stats, ret
func (l *library) VgpuInstanceGetAccountingStats(vgpuInstance VgpuInstance, pid int) (AccountingStats, Return) {
return vgpuInstance.GetAccountingStats(pid)
}
func (VgpuInstance VgpuInstance) GetAccountingStats(Pid int) (AccountingStats, Return) {
return VgpuInstanceGetAccountingStats(VgpuInstance, Pid)
func (vgpuInstance nvmlVgpuInstance) GetAccountingStats(pid int) (AccountingStats, Return) {
var stats AccountingStats
ret := nvmlVgpuInstanceGetAccountingStats(vgpuInstance, uint32(pid), &stats)
return stats, ret
}
// nvml.GetVgpuCompatibility()
func GetVgpuCompatibility(nvmlVgpuMetadata *nvmlVgpuMetadata, PgpuMetadata *nvmlVgpuPgpuMetadata) (VgpuPgpuCompatibility, Return) {
var CompatibilityInfo VgpuPgpuCompatibility
ret := nvmlGetVgpuCompatibility(nvmlVgpuMetadata, PgpuMetadata, &CompatibilityInfo)
return CompatibilityInfo, ret
func (l *library) GetVgpuCompatibility(vgpuMetadata *VgpuMetadata, pgpuMetadata *VgpuPgpuMetadata) (VgpuPgpuCompatibility, Return) {
var compatibilityInfo VgpuPgpuCompatibility
ret := nvmlGetVgpuCompatibility(&vgpuMetadata.nvmlVgpuMetadata, &pgpuMetadata.nvmlVgpuPgpuMetadata, &compatibilityInfo)
return compatibilityInfo, ret
}
// nvml.GetVgpuVersion()
func GetVgpuVersion() (VgpuVersion, VgpuVersion, Return) {
var Supported, Current VgpuVersion
ret := nvmlGetVgpuVersion(&Supported, &Current)
return Supported, Current, ret
func (l *library) GetVgpuVersion() (VgpuVersion, VgpuVersion, Return) {
var supported, current VgpuVersion
ret := nvmlGetVgpuVersion(&supported, &current)
return supported, current, ret
}
// nvml.SetVgpuVersion()
func SetVgpuVersion(VgpuVersion *VgpuVersion) Return {
return nvmlSetVgpuVersion(VgpuVersion)
func (l *library) SetVgpuVersion(vgpuVersion *VgpuVersion) Return {
return nvmlSetVgpuVersion(vgpuVersion)
}
// nvml.VgpuInstanceClearAccountingPids()
func VgpuInstanceClearAccountingPids(VgpuInstance VgpuInstance) Return {
return nvmlVgpuInstanceClearAccountingPids(VgpuInstance)
func (l *library) VgpuInstanceClearAccountingPids(vgpuInstance VgpuInstance) Return {
return vgpuInstance.ClearAccountingPids()
}
func (VgpuInstance VgpuInstance) ClearAccountingPids() Return {
return VgpuInstanceClearAccountingPids(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) ClearAccountingPids() Return {
return nvmlVgpuInstanceClearAccountingPids(vgpuInstance)
}
// nvml.VgpuInstanceGetMdevUUID()
func VgpuInstanceGetMdevUUID(VgpuInstance VgpuInstance) (string, Return) {
MdevUuid := make([]byte, DEVICE_UUID_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetMdevUUID(VgpuInstance, &MdevUuid[0], DEVICE_UUID_BUFFER_SIZE)
return string(MdevUuid[:clen(MdevUuid)]), ret
func (l *library) VgpuInstanceGetMdevUUID(vgpuInstance VgpuInstance) (string, Return) {
return vgpuInstance.GetMdevUUID()
}
func (VgpuInstance VgpuInstance) GetMdevUUID() (string, Return) {
return VgpuInstanceGetMdevUUID(VgpuInstance)
func (vgpuInstance nvmlVgpuInstance) GetMdevUUID() (string, Return) {
mdevUUID := make([]byte, DEVICE_UUID_BUFFER_SIZE)
ret := nvmlVgpuInstanceGetMdevUUID(vgpuInstance, &mdevUUID[0], DEVICE_UUID_BUFFER_SIZE)
return string(mdevUUID[:clen(mdevUUID)]), ret
}
// nvml.VgpuTypeGetCapabilities()
func VgpuTypeGetCapabilities(VgpuTypeId VgpuTypeId, Capability VgpuCapability) (bool, Return) {
var CapResult uint32
ret := nvmlVgpuTypeGetCapabilities(VgpuTypeId, Capability, &CapResult)
return (CapResult != 0), ret
func (l *library) VgpuTypeGetCapabilities(vgpuTypeId VgpuTypeId, capability VgpuCapability) (bool, Return) {
return vgpuTypeId.GetCapabilities(capability)
}
func (VgpuTypeId VgpuTypeId) GetCapabilities(Capability VgpuCapability) (bool, Return) {
return VgpuTypeGetCapabilities(VgpuTypeId, Capability)
func (vgpuTypeId nvmlVgpuTypeId) GetCapabilities(capability VgpuCapability) (bool, Return) {
var capResult uint32
ret := nvmlVgpuTypeGetCapabilities(vgpuTypeId, capability, &capResult)
return (capResult != 0), ret
}
// nvml.GetVgpuDriverCapabilities()
func GetVgpuDriverCapabilities(Capability VgpuDriverCapability) (bool, Return) {
var CapResult uint32
ret := nvmlGetVgpuDriverCapabilities(Capability, &CapResult)
return (CapResult != 0), ret
func (l *library) GetVgpuDriverCapabilities(capability VgpuDriverCapability) (bool, Return) {
var capResult uint32
ret := nvmlGetVgpuDriverCapabilities(capability, &capResult)
return (capResult != 0), ret
}

View File

@@ -0,0 +1,919 @@
/**
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
**/
// Generated Code; DO NOT EDIT.
package nvml
// The variables below represent package level methods from the library type.
var (
ComputeInstanceDestroy = libnvml.ComputeInstanceDestroy
ComputeInstanceGetInfo = libnvml.ComputeInstanceGetInfo
DeviceCcuGetStreamState = libnvml.DeviceCcuGetStreamState
DeviceCcuSetStreamState = libnvml.DeviceCcuSetStreamState
DeviceClearAccountingPids = libnvml.DeviceClearAccountingPids
DeviceClearCpuAffinity = libnvml.DeviceClearCpuAffinity
DeviceClearEccErrorCounts = libnvml.DeviceClearEccErrorCounts
DeviceClearFieldValues = libnvml.DeviceClearFieldValues
DeviceCreateGpuInstance = libnvml.DeviceCreateGpuInstance
DeviceCreateGpuInstanceWithPlacement = libnvml.DeviceCreateGpuInstanceWithPlacement
DeviceDiscoverGpus = libnvml.DeviceDiscoverGpus
DeviceFreezeNvLinkUtilizationCounter = libnvml.DeviceFreezeNvLinkUtilizationCounter
DeviceGetAPIRestriction = libnvml.DeviceGetAPIRestriction
DeviceGetAccountingBufferSize = libnvml.DeviceGetAccountingBufferSize
DeviceGetAccountingMode = libnvml.DeviceGetAccountingMode
DeviceGetAccountingPids = libnvml.DeviceGetAccountingPids
DeviceGetAccountingStats = libnvml.DeviceGetAccountingStats
DeviceGetActiveVgpus = libnvml.DeviceGetActiveVgpus
DeviceGetAdaptiveClockInfoStatus = libnvml.DeviceGetAdaptiveClockInfoStatus
DeviceGetApplicationsClock = libnvml.DeviceGetApplicationsClock
DeviceGetArchitecture = libnvml.DeviceGetArchitecture
DeviceGetAttributes = libnvml.DeviceGetAttributes
DeviceGetAutoBoostedClocksEnabled = libnvml.DeviceGetAutoBoostedClocksEnabled
DeviceGetBAR1MemoryInfo = libnvml.DeviceGetBAR1MemoryInfo
DeviceGetBoardId = libnvml.DeviceGetBoardId
DeviceGetBoardPartNumber = libnvml.DeviceGetBoardPartNumber
DeviceGetBrand = libnvml.DeviceGetBrand
DeviceGetBridgeChipInfo = libnvml.DeviceGetBridgeChipInfo
DeviceGetBusType = libnvml.DeviceGetBusType
DeviceGetClkMonStatus = libnvml.DeviceGetClkMonStatus
DeviceGetClock = libnvml.DeviceGetClock
DeviceGetClockInfo = libnvml.DeviceGetClockInfo
DeviceGetComputeInstanceId = libnvml.DeviceGetComputeInstanceId
DeviceGetComputeMode = libnvml.DeviceGetComputeMode
DeviceGetComputeRunningProcesses = libnvml.DeviceGetComputeRunningProcesses
DeviceGetCount = libnvml.DeviceGetCount
DeviceGetCpuAffinity = libnvml.DeviceGetCpuAffinity
DeviceGetCpuAffinityWithinScope = libnvml.DeviceGetCpuAffinityWithinScope
DeviceGetCreatableVgpus = libnvml.DeviceGetCreatableVgpus
DeviceGetCudaComputeCapability = libnvml.DeviceGetCudaComputeCapability
DeviceGetCurrPcieLinkGeneration = libnvml.DeviceGetCurrPcieLinkGeneration
DeviceGetCurrPcieLinkWidth = libnvml.DeviceGetCurrPcieLinkWidth
DeviceGetCurrentClocksThrottleReasons = libnvml.DeviceGetCurrentClocksThrottleReasons
DeviceGetDecoderUtilization = libnvml.DeviceGetDecoderUtilization
DeviceGetDefaultApplicationsClock = libnvml.DeviceGetDefaultApplicationsClock
DeviceGetDefaultEccMode = libnvml.DeviceGetDefaultEccMode
DeviceGetDetailedEccErrors = libnvml.DeviceGetDetailedEccErrors
DeviceGetDeviceHandleFromMigDeviceHandle = libnvml.DeviceGetDeviceHandleFromMigDeviceHandle
DeviceGetDisplayActive = libnvml.DeviceGetDisplayActive
DeviceGetDisplayMode = libnvml.DeviceGetDisplayMode
DeviceGetDriverModel = libnvml.DeviceGetDriverModel
DeviceGetDynamicPstatesInfo = libnvml.DeviceGetDynamicPstatesInfo
DeviceGetEccMode = libnvml.DeviceGetEccMode
DeviceGetEncoderCapacity = libnvml.DeviceGetEncoderCapacity
DeviceGetEncoderSessions = libnvml.DeviceGetEncoderSessions
DeviceGetEncoderStats = libnvml.DeviceGetEncoderStats
DeviceGetEncoderUtilization = libnvml.DeviceGetEncoderUtilization
DeviceGetEnforcedPowerLimit = libnvml.DeviceGetEnforcedPowerLimit
DeviceGetFBCSessions = libnvml.DeviceGetFBCSessions
DeviceGetFBCStats = libnvml.DeviceGetFBCStats
DeviceGetFanControlPolicy_v2 = libnvml.DeviceGetFanControlPolicy_v2
DeviceGetFanSpeed = libnvml.DeviceGetFanSpeed
DeviceGetFanSpeed_v2 = libnvml.DeviceGetFanSpeed_v2
DeviceGetFieldValues = libnvml.DeviceGetFieldValues
DeviceGetGpcClkMinMaxVfOffset = libnvml.DeviceGetGpcClkMinMaxVfOffset
DeviceGetGpcClkVfOffset = libnvml.DeviceGetGpcClkVfOffset
DeviceGetGpuFabricInfo = libnvml.DeviceGetGpuFabricInfo
DeviceGetGpuInstanceById = libnvml.DeviceGetGpuInstanceById
DeviceGetGpuInstanceId = libnvml.DeviceGetGpuInstanceId
DeviceGetGpuInstancePossiblePlacements = libnvml.DeviceGetGpuInstancePossiblePlacements
DeviceGetGpuInstanceProfileInfo = libnvml.DeviceGetGpuInstanceProfileInfo
DeviceGetGpuInstanceProfileInfoV = libnvml.DeviceGetGpuInstanceProfileInfoV
DeviceGetGpuInstanceRemainingCapacity = libnvml.DeviceGetGpuInstanceRemainingCapacity
DeviceGetGpuInstances = libnvml.DeviceGetGpuInstances
DeviceGetGpuMaxPcieLinkGeneration = libnvml.DeviceGetGpuMaxPcieLinkGeneration
DeviceGetGpuOperationMode = libnvml.DeviceGetGpuOperationMode
DeviceGetGraphicsRunningProcesses = libnvml.DeviceGetGraphicsRunningProcesses
DeviceGetGridLicensableFeatures = libnvml.DeviceGetGridLicensableFeatures
DeviceGetGspFirmwareMode = libnvml.DeviceGetGspFirmwareMode
DeviceGetGspFirmwareVersion = libnvml.DeviceGetGspFirmwareVersion
DeviceGetHandleByIndex = libnvml.DeviceGetHandleByIndex
DeviceGetHandleByPciBusId = libnvml.DeviceGetHandleByPciBusId
DeviceGetHandleBySerial = libnvml.DeviceGetHandleBySerial
DeviceGetHandleByUUID = libnvml.DeviceGetHandleByUUID
DeviceGetHostVgpuMode = libnvml.DeviceGetHostVgpuMode
DeviceGetIndex = libnvml.DeviceGetIndex
DeviceGetInforomConfigurationChecksum = libnvml.DeviceGetInforomConfigurationChecksum
DeviceGetInforomImageVersion = libnvml.DeviceGetInforomImageVersion
DeviceGetInforomVersion = libnvml.DeviceGetInforomVersion
DeviceGetIrqNum = libnvml.DeviceGetIrqNum
DeviceGetMPSComputeRunningProcesses = libnvml.DeviceGetMPSComputeRunningProcesses
DeviceGetMaxClockInfo = libnvml.DeviceGetMaxClockInfo
DeviceGetMaxCustomerBoostClock = libnvml.DeviceGetMaxCustomerBoostClock
DeviceGetMaxMigDeviceCount = libnvml.DeviceGetMaxMigDeviceCount
DeviceGetMaxPcieLinkGeneration = libnvml.DeviceGetMaxPcieLinkGeneration
DeviceGetMaxPcieLinkWidth = libnvml.DeviceGetMaxPcieLinkWidth
DeviceGetMemClkMinMaxVfOffset = libnvml.DeviceGetMemClkMinMaxVfOffset
DeviceGetMemClkVfOffset = libnvml.DeviceGetMemClkVfOffset
DeviceGetMemoryAffinity = libnvml.DeviceGetMemoryAffinity
DeviceGetMemoryBusWidth = libnvml.DeviceGetMemoryBusWidth
DeviceGetMemoryErrorCounter = libnvml.DeviceGetMemoryErrorCounter
DeviceGetMemoryInfo = libnvml.DeviceGetMemoryInfo
DeviceGetMemoryInfo_v2 = libnvml.DeviceGetMemoryInfo_v2
DeviceGetMigDeviceHandleByIndex = libnvml.DeviceGetMigDeviceHandleByIndex
DeviceGetMigMode = libnvml.DeviceGetMigMode
DeviceGetMinMaxClockOfPState = libnvml.DeviceGetMinMaxClockOfPState
DeviceGetMinMaxFanSpeed = libnvml.DeviceGetMinMaxFanSpeed
DeviceGetMinorNumber = libnvml.DeviceGetMinorNumber
DeviceGetMultiGpuBoard = libnvml.DeviceGetMultiGpuBoard
DeviceGetName = libnvml.DeviceGetName
DeviceGetNumFans = libnvml.DeviceGetNumFans
DeviceGetNumGpuCores = libnvml.DeviceGetNumGpuCores
DeviceGetNvLinkCapability = libnvml.DeviceGetNvLinkCapability
DeviceGetNvLinkErrorCounter = libnvml.DeviceGetNvLinkErrorCounter
DeviceGetNvLinkRemoteDeviceType = libnvml.DeviceGetNvLinkRemoteDeviceType
DeviceGetNvLinkRemotePciInfo = libnvml.DeviceGetNvLinkRemotePciInfo
DeviceGetNvLinkState = libnvml.DeviceGetNvLinkState
DeviceGetNvLinkUtilizationControl = libnvml.DeviceGetNvLinkUtilizationControl
DeviceGetNvLinkUtilizationCounter = libnvml.DeviceGetNvLinkUtilizationCounter
DeviceGetNvLinkVersion = libnvml.DeviceGetNvLinkVersion
DeviceGetP2PStatus = libnvml.DeviceGetP2PStatus
DeviceGetPciInfo = libnvml.DeviceGetPciInfo
DeviceGetPcieLinkMaxSpeed = libnvml.DeviceGetPcieLinkMaxSpeed
DeviceGetPcieReplayCounter = libnvml.DeviceGetPcieReplayCounter
DeviceGetPcieSpeed = libnvml.DeviceGetPcieSpeed
DeviceGetPcieThroughput = libnvml.DeviceGetPcieThroughput
DeviceGetPerformanceState = libnvml.DeviceGetPerformanceState
DeviceGetPersistenceMode = libnvml.DeviceGetPersistenceMode
DeviceGetPgpuMetadataString = libnvml.DeviceGetPgpuMetadataString
DeviceGetPowerManagementDefaultLimit = libnvml.DeviceGetPowerManagementDefaultLimit
DeviceGetPowerManagementLimit = libnvml.DeviceGetPowerManagementLimit
DeviceGetPowerManagementLimitConstraints = libnvml.DeviceGetPowerManagementLimitConstraints
DeviceGetPowerManagementMode = libnvml.DeviceGetPowerManagementMode
DeviceGetPowerSource = libnvml.DeviceGetPowerSource
DeviceGetPowerState = libnvml.DeviceGetPowerState
DeviceGetPowerUsage = libnvml.DeviceGetPowerUsage
DeviceGetProcessUtilization = libnvml.DeviceGetProcessUtilization
DeviceGetRemappedRows = libnvml.DeviceGetRemappedRows
DeviceGetRetiredPages = libnvml.DeviceGetRetiredPages
DeviceGetRetiredPagesPendingStatus = libnvml.DeviceGetRetiredPagesPendingStatus
DeviceGetRetiredPages_v2 = libnvml.DeviceGetRetiredPages_v2
DeviceGetRowRemapperHistogram = libnvml.DeviceGetRowRemapperHistogram
DeviceGetSamples = libnvml.DeviceGetSamples
DeviceGetSerial = libnvml.DeviceGetSerial
DeviceGetSupportedClocksThrottleReasons = libnvml.DeviceGetSupportedClocksThrottleReasons
DeviceGetSupportedEventTypes = libnvml.DeviceGetSupportedEventTypes
DeviceGetSupportedGraphicsClocks = libnvml.DeviceGetSupportedGraphicsClocks
DeviceGetSupportedMemoryClocks = libnvml.DeviceGetSupportedMemoryClocks
DeviceGetSupportedPerformanceStates = libnvml.DeviceGetSupportedPerformanceStates
DeviceGetSupportedVgpus = libnvml.DeviceGetSupportedVgpus
DeviceGetTargetFanSpeed = libnvml.DeviceGetTargetFanSpeed
DeviceGetTemperature = libnvml.DeviceGetTemperature
DeviceGetTemperatureThreshold = libnvml.DeviceGetTemperatureThreshold
DeviceGetThermalSettings = libnvml.DeviceGetThermalSettings
DeviceGetTopologyCommonAncestor = libnvml.DeviceGetTopologyCommonAncestor
DeviceGetTopologyNearestGpus = libnvml.DeviceGetTopologyNearestGpus
DeviceGetTotalEccErrors = libnvml.DeviceGetTotalEccErrors
DeviceGetTotalEnergyConsumption = libnvml.DeviceGetTotalEnergyConsumption
DeviceGetUUID = libnvml.DeviceGetUUID
DeviceGetUtilizationRates = libnvml.DeviceGetUtilizationRates
DeviceGetVbiosVersion = libnvml.DeviceGetVbiosVersion
DeviceGetVgpuCapabilities = libnvml.DeviceGetVgpuCapabilities
DeviceGetVgpuMetadata = libnvml.DeviceGetVgpuMetadata
DeviceGetVgpuProcessUtilization = libnvml.DeviceGetVgpuProcessUtilization
DeviceGetVgpuSchedulerCapabilities = libnvml.DeviceGetVgpuSchedulerCapabilities
DeviceGetVgpuSchedulerLog = libnvml.DeviceGetVgpuSchedulerLog
DeviceGetVgpuSchedulerState = libnvml.DeviceGetVgpuSchedulerState
DeviceGetVgpuUtilization = libnvml.DeviceGetVgpuUtilization
DeviceGetViolationStatus = libnvml.DeviceGetViolationStatus
DeviceGetVirtualizationMode = libnvml.DeviceGetVirtualizationMode
DeviceIsMigDeviceHandle = libnvml.DeviceIsMigDeviceHandle
DeviceModifyDrainState = libnvml.DeviceModifyDrainState
DeviceOnSameBoard = libnvml.DeviceOnSameBoard
DeviceQueryDrainState = libnvml.DeviceQueryDrainState
DeviceRegisterEvents = libnvml.DeviceRegisterEvents
DeviceRemoveGpu = libnvml.DeviceRemoveGpu
DeviceRemoveGpu_v2 = libnvml.DeviceRemoveGpu_v2
DeviceResetApplicationsClocks = libnvml.DeviceResetApplicationsClocks
DeviceResetGpuLockedClocks = libnvml.DeviceResetGpuLockedClocks
DeviceResetMemoryLockedClocks = libnvml.DeviceResetMemoryLockedClocks
DeviceResetNvLinkErrorCounters = libnvml.DeviceResetNvLinkErrorCounters
DeviceResetNvLinkUtilizationCounter = libnvml.DeviceResetNvLinkUtilizationCounter
DeviceSetAPIRestriction = libnvml.DeviceSetAPIRestriction
DeviceSetAccountingMode = libnvml.DeviceSetAccountingMode
DeviceSetApplicationsClocks = libnvml.DeviceSetApplicationsClocks
DeviceSetAutoBoostedClocksEnabled = libnvml.DeviceSetAutoBoostedClocksEnabled
DeviceSetComputeMode = libnvml.DeviceSetComputeMode
DeviceSetCpuAffinity = libnvml.DeviceSetCpuAffinity
DeviceSetDefaultAutoBoostedClocksEnabled = libnvml.DeviceSetDefaultAutoBoostedClocksEnabled
DeviceSetDefaultFanSpeed_v2 = libnvml.DeviceSetDefaultFanSpeed_v2
DeviceSetDriverModel = libnvml.DeviceSetDriverModel
DeviceSetEccMode = libnvml.DeviceSetEccMode
DeviceSetFanControlPolicy = libnvml.DeviceSetFanControlPolicy
DeviceSetFanSpeed_v2 = libnvml.DeviceSetFanSpeed_v2
DeviceSetGpcClkVfOffset = libnvml.DeviceSetGpcClkVfOffset
DeviceSetGpuLockedClocks = libnvml.DeviceSetGpuLockedClocks
DeviceSetGpuOperationMode = libnvml.DeviceSetGpuOperationMode
DeviceSetMemClkVfOffset = libnvml.DeviceSetMemClkVfOffset
DeviceSetMemoryLockedClocks = libnvml.DeviceSetMemoryLockedClocks
DeviceSetMigMode = libnvml.DeviceSetMigMode
DeviceSetNvLinkDeviceLowPowerThreshold = libnvml.DeviceSetNvLinkDeviceLowPowerThreshold
DeviceSetNvLinkUtilizationControl = libnvml.DeviceSetNvLinkUtilizationControl
DeviceSetPersistenceMode = libnvml.DeviceSetPersistenceMode
DeviceSetPowerManagementLimit = libnvml.DeviceSetPowerManagementLimit
DeviceSetTemperatureThreshold = libnvml.DeviceSetTemperatureThreshold
DeviceSetVgpuSchedulerState = libnvml.DeviceSetVgpuSchedulerState
DeviceSetVirtualizationMode = libnvml.DeviceSetVirtualizationMode
DeviceValidateInforom = libnvml.DeviceValidateInforom
ErrorString = libnvml.ErrorString
EventSetCreate = libnvml.EventSetCreate
EventSetFree = libnvml.EventSetFree
EventSetWait = libnvml.EventSetWait
Extensions = libnvml.Extensions
GetExcludedDeviceCount = libnvml.GetExcludedDeviceCount
GetExcludedDeviceInfoByIndex = libnvml.GetExcludedDeviceInfoByIndex
GetVgpuCompatibility = libnvml.GetVgpuCompatibility
GetVgpuDriverCapabilities = libnvml.GetVgpuDriverCapabilities
GetVgpuVersion = libnvml.GetVgpuVersion
GpmMetricsGet = libnvml.GpmMetricsGet
GpmMetricsGetV = libnvml.GpmMetricsGetV
GpmMigSampleGet = libnvml.GpmMigSampleGet
GpmQueryDeviceSupport = libnvml.GpmQueryDeviceSupport
GpmQueryDeviceSupportV = libnvml.GpmQueryDeviceSupportV
GpmSampleAlloc = libnvml.GpmSampleAlloc
GpmSampleFree = libnvml.GpmSampleFree
GpmSampleGet = libnvml.GpmSampleGet
GpuInstanceCreateComputeInstance = libnvml.GpuInstanceCreateComputeInstance
GpuInstanceCreateComputeInstanceWithPlacement = libnvml.GpuInstanceCreateComputeInstanceWithPlacement
GpuInstanceDestroy = libnvml.GpuInstanceDestroy
GpuInstanceGetComputeInstanceById = libnvml.GpuInstanceGetComputeInstanceById
GpuInstanceGetComputeInstancePossiblePlacements = libnvml.GpuInstanceGetComputeInstancePossiblePlacements
GpuInstanceGetComputeInstanceProfileInfo = libnvml.GpuInstanceGetComputeInstanceProfileInfo
GpuInstanceGetComputeInstanceProfileInfoV = libnvml.GpuInstanceGetComputeInstanceProfileInfoV
GpuInstanceGetComputeInstanceRemainingCapacity = libnvml.GpuInstanceGetComputeInstanceRemainingCapacity
GpuInstanceGetComputeInstances = libnvml.GpuInstanceGetComputeInstances
GpuInstanceGetInfo = libnvml.GpuInstanceGetInfo
Init = libnvml.Init
InitWithFlags = libnvml.InitWithFlags
SetVgpuVersion = libnvml.SetVgpuVersion
Shutdown = libnvml.Shutdown
SystemGetCudaDriverVersion = libnvml.SystemGetCudaDriverVersion
SystemGetCudaDriverVersion_v2 = libnvml.SystemGetCudaDriverVersion_v2
SystemGetDriverVersion = libnvml.SystemGetDriverVersion
SystemGetHicVersion = libnvml.SystemGetHicVersion
SystemGetNVMLVersion = libnvml.SystemGetNVMLVersion
SystemGetProcessName = libnvml.SystemGetProcessName
SystemGetTopologyGpuSet = libnvml.SystemGetTopologyGpuSet
UnitGetCount = libnvml.UnitGetCount
UnitGetDevices = libnvml.UnitGetDevices
UnitGetFanSpeedInfo = libnvml.UnitGetFanSpeedInfo
UnitGetHandleByIndex = libnvml.UnitGetHandleByIndex
UnitGetLedState = libnvml.UnitGetLedState
UnitGetPsuInfo = libnvml.UnitGetPsuInfo
UnitGetTemperature = libnvml.UnitGetTemperature
UnitGetUnitInfo = libnvml.UnitGetUnitInfo
UnitSetLedState = libnvml.UnitSetLedState
VgpuInstanceClearAccountingPids = libnvml.VgpuInstanceClearAccountingPids
VgpuInstanceGetAccountingMode = libnvml.VgpuInstanceGetAccountingMode
VgpuInstanceGetAccountingPids = libnvml.VgpuInstanceGetAccountingPids
VgpuInstanceGetAccountingStats = libnvml.VgpuInstanceGetAccountingStats
VgpuInstanceGetEccMode = libnvml.VgpuInstanceGetEccMode
VgpuInstanceGetEncoderCapacity = libnvml.VgpuInstanceGetEncoderCapacity
VgpuInstanceGetEncoderSessions = libnvml.VgpuInstanceGetEncoderSessions
VgpuInstanceGetEncoderStats = libnvml.VgpuInstanceGetEncoderStats
VgpuInstanceGetFBCSessions = libnvml.VgpuInstanceGetFBCSessions
VgpuInstanceGetFBCStats = libnvml.VgpuInstanceGetFBCStats
VgpuInstanceGetFbUsage = libnvml.VgpuInstanceGetFbUsage
VgpuInstanceGetFrameRateLimit = libnvml.VgpuInstanceGetFrameRateLimit
VgpuInstanceGetGpuInstanceId = libnvml.VgpuInstanceGetGpuInstanceId
VgpuInstanceGetGpuPciId = libnvml.VgpuInstanceGetGpuPciId
VgpuInstanceGetLicenseInfo = libnvml.VgpuInstanceGetLicenseInfo
VgpuInstanceGetLicenseStatus = libnvml.VgpuInstanceGetLicenseStatus
VgpuInstanceGetMdevUUID = libnvml.VgpuInstanceGetMdevUUID
VgpuInstanceGetMetadata = libnvml.VgpuInstanceGetMetadata
VgpuInstanceGetType = libnvml.VgpuInstanceGetType
VgpuInstanceGetUUID = libnvml.VgpuInstanceGetUUID
VgpuInstanceGetVmDriverVersion = libnvml.VgpuInstanceGetVmDriverVersion
VgpuInstanceGetVmID = libnvml.VgpuInstanceGetVmID
VgpuInstanceSetEncoderCapacity = libnvml.VgpuInstanceSetEncoderCapacity
VgpuTypeGetCapabilities = libnvml.VgpuTypeGetCapabilities
VgpuTypeGetClass = libnvml.VgpuTypeGetClass
VgpuTypeGetDeviceID = libnvml.VgpuTypeGetDeviceID
VgpuTypeGetFrameRateLimit = libnvml.VgpuTypeGetFrameRateLimit
VgpuTypeGetFramebufferSize = libnvml.VgpuTypeGetFramebufferSize
VgpuTypeGetGpuInstanceProfileId = libnvml.VgpuTypeGetGpuInstanceProfileId
VgpuTypeGetLicense = libnvml.VgpuTypeGetLicense
VgpuTypeGetMaxInstances = libnvml.VgpuTypeGetMaxInstances
VgpuTypeGetMaxInstancesPerVm = libnvml.VgpuTypeGetMaxInstancesPerVm
VgpuTypeGetName = libnvml.VgpuTypeGetName
VgpuTypeGetNumDisplayHeads = libnvml.VgpuTypeGetNumDisplayHeads
VgpuTypeGetResolution = libnvml.VgpuTypeGetResolution
)
// Interface represents the interface for the library type.
//
//go:generate moq -out mock/interface.go -pkg mock . Interface:Interface
type Interface interface {
ComputeInstanceDestroy(ComputeInstance) Return
ComputeInstanceGetInfo(ComputeInstance) (ComputeInstanceInfo, Return)
DeviceCcuGetStreamState(Device) (int, Return)
DeviceCcuSetStreamState(Device, int) Return
DeviceClearAccountingPids(Device) Return
DeviceClearCpuAffinity(Device) Return
DeviceClearEccErrorCounts(Device, EccCounterType) Return
DeviceClearFieldValues(Device, []FieldValue) Return
DeviceCreateGpuInstance(Device, *GpuInstanceProfileInfo) (GpuInstance, Return)
DeviceCreateGpuInstanceWithPlacement(Device, *GpuInstanceProfileInfo, *GpuInstancePlacement) (GpuInstance, Return)
DeviceDiscoverGpus() (PciInfo, Return)
DeviceFreezeNvLinkUtilizationCounter(Device, int, int, EnableState) Return
DeviceGetAPIRestriction(Device, RestrictedAPI) (EnableState, Return)
DeviceGetAccountingBufferSize(Device) (int, Return)
DeviceGetAccountingMode(Device) (EnableState, Return)
DeviceGetAccountingPids(Device) ([]int, Return)
DeviceGetAccountingStats(Device, uint32) (AccountingStats, Return)
DeviceGetActiveVgpus(Device) ([]VgpuInstance, Return)
DeviceGetAdaptiveClockInfoStatus(Device) (uint32, Return)
DeviceGetApplicationsClock(Device, ClockType) (uint32, Return)
DeviceGetArchitecture(Device) (DeviceArchitecture, Return)
DeviceGetAttributes(Device) (DeviceAttributes, Return)
DeviceGetAutoBoostedClocksEnabled(Device) (EnableState, EnableState, Return)
DeviceGetBAR1MemoryInfo(Device) (BAR1Memory, Return)
DeviceGetBoardId(Device) (uint32, Return)
DeviceGetBoardPartNumber(Device) (string, Return)
DeviceGetBrand(Device) (BrandType, Return)
DeviceGetBridgeChipInfo(Device) (BridgeChipHierarchy, Return)
DeviceGetBusType(Device) (BusType, Return)
DeviceGetClkMonStatus(Device) (ClkMonStatus, Return)
DeviceGetClock(Device, ClockType, ClockId) (uint32, Return)
DeviceGetClockInfo(Device, ClockType) (uint32, Return)
DeviceGetComputeInstanceId(Device) (int, Return)
DeviceGetComputeMode(Device) (ComputeMode, Return)
DeviceGetComputeRunningProcesses(Device) ([]ProcessInfo, Return)
DeviceGetCount() (int, Return)
DeviceGetCpuAffinity(Device, int) ([]uint, Return)
DeviceGetCpuAffinityWithinScope(Device, int, AffinityScope) ([]uint, Return)
DeviceGetCreatableVgpus(Device) ([]VgpuTypeId, Return)
DeviceGetCudaComputeCapability(Device) (int, int, Return)
DeviceGetCurrPcieLinkGeneration(Device) (int, Return)
DeviceGetCurrPcieLinkWidth(Device) (int, Return)
DeviceGetCurrentClocksThrottleReasons(Device) (uint64, Return)
DeviceGetDecoderUtilization(Device) (uint32, uint32, Return)
DeviceGetDefaultApplicationsClock(Device, ClockType) (uint32, Return)
DeviceGetDefaultEccMode(Device) (EnableState, Return)
DeviceGetDetailedEccErrors(Device, MemoryErrorType, EccCounterType) (EccErrorCounts, Return)
DeviceGetDeviceHandleFromMigDeviceHandle(Device) (Device, Return)
DeviceGetDisplayActive(Device) (EnableState, Return)
DeviceGetDisplayMode(Device) (EnableState, Return)
DeviceGetDriverModel(Device) (DriverModel, DriverModel, Return)
DeviceGetDynamicPstatesInfo(Device) (GpuDynamicPstatesInfo, Return)
DeviceGetEccMode(Device) (EnableState, EnableState, Return)
DeviceGetEncoderCapacity(Device, EncoderType) (int, Return)
DeviceGetEncoderSessions(Device) ([]EncoderSessionInfo, Return)
DeviceGetEncoderStats(Device) (int, uint32, uint32, Return)
DeviceGetEncoderUtilization(Device) (uint32, uint32, Return)
DeviceGetEnforcedPowerLimit(Device) (uint32, Return)
DeviceGetFBCSessions(Device) ([]FBCSessionInfo, Return)
DeviceGetFBCStats(Device) (FBCStats, Return)
DeviceGetFanControlPolicy_v2(Device, int) (FanControlPolicy, Return)
DeviceGetFanSpeed(Device) (uint32, Return)
DeviceGetFanSpeed_v2(Device, int) (uint32, Return)
DeviceGetFieldValues(Device, []FieldValue) Return
DeviceGetGpcClkMinMaxVfOffset(Device) (int, int, Return)
DeviceGetGpcClkVfOffset(Device) (int, Return)
DeviceGetGpuFabricInfo(Device) (GpuFabricInfo, Return)
DeviceGetGpuInstanceById(Device, int) (GpuInstance, Return)
DeviceGetGpuInstanceId(Device) (int, Return)
DeviceGetGpuInstancePossiblePlacements(Device, *GpuInstanceProfileInfo) ([]GpuInstancePlacement, Return)
DeviceGetGpuInstanceProfileInfo(Device, int) (GpuInstanceProfileInfo, Return)
DeviceGetGpuInstanceProfileInfoV(Device, int) GpuInstanceProfileInfoV
DeviceGetGpuInstanceRemainingCapacity(Device, *GpuInstanceProfileInfo) (int, Return)
DeviceGetGpuInstances(Device, *GpuInstanceProfileInfo) ([]GpuInstance, Return)
DeviceGetGpuMaxPcieLinkGeneration(Device) (int, Return)
DeviceGetGpuOperationMode(Device) (GpuOperationMode, GpuOperationMode, Return)
DeviceGetGraphicsRunningProcesses(Device) ([]ProcessInfo, Return)
DeviceGetGridLicensableFeatures(Device) (GridLicensableFeatures, Return)
DeviceGetGspFirmwareMode(Device) (bool, bool, Return)
DeviceGetGspFirmwareVersion(Device) (string, Return)
DeviceGetHandleByIndex(int) (Device, Return)
DeviceGetHandleByPciBusId(string) (Device, Return)
DeviceGetHandleBySerial(string) (Device, Return)
DeviceGetHandleByUUID(string) (Device, Return)
DeviceGetHostVgpuMode(Device) (HostVgpuMode, Return)
DeviceGetIndex(Device) (int, Return)
DeviceGetInforomConfigurationChecksum(Device) (uint32, Return)
DeviceGetInforomImageVersion(Device) (string, Return)
DeviceGetInforomVersion(Device, InforomObject) (string, Return)
DeviceGetIrqNum(Device) (int, Return)
DeviceGetMPSComputeRunningProcesses(Device) ([]ProcessInfo, Return)
DeviceGetMaxClockInfo(Device, ClockType) (uint32, Return)
DeviceGetMaxCustomerBoostClock(Device, ClockType) (uint32, Return)
DeviceGetMaxMigDeviceCount(Device) (int, Return)
DeviceGetMaxPcieLinkGeneration(Device) (int, Return)
DeviceGetMaxPcieLinkWidth(Device) (int, Return)
DeviceGetMemClkMinMaxVfOffset(Device) (int, int, Return)
DeviceGetMemClkVfOffset(Device) (int, Return)
DeviceGetMemoryAffinity(Device, int, AffinityScope) ([]uint, Return)
DeviceGetMemoryBusWidth(Device) (uint32, Return)
DeviceGetMemoryErrorCounter(Device, MemoryErrorType, EccCounterType, MemoryLocation) (uint64, Return)
DeviceGetMemoryInfo(Device) (Memory, Return)
DeviceGetMemoryInfo_v2(Device) (Memory_v2, Return)
DeviceGetMigDeviceHandleByIndex(Device, int) (Device, Return)
DeviceGetMigMode(Device) (int, int, Return)
DeviceGetMinMaxClockOfPState(Device, ClockType, Pstates) (uint32, uint32, Return)
DeviceGetMinMaxFanSpeed(Device) (int, int, Return)
DeviceGetMinorNumber(Device) (int, Return)
DeviceGetMultiGpuBoard(Device) (int, Return)
DeviceGetName(Device) (string, Return)
DeviceGetNumFans(Device) (int, Return)
DeviceGetNumGpuCores(Device) (int, Return)
DeviceGetNvLinkCapability(Device, int, NvLinkCapability) (uint32, Return)
DeviceGetNvLinkErrorCounter(Device, int, NvLinkErrorCounter) (uint64, Return)
DeviceGetNvLinkRemoteDeviceType(Device, int) (IntNvLinkDeviceType, Return)
DeviceGetNvLinkRemotePciInfo(Device, int) (PciInfo, Return)
DeviceGetNvLinkState(Device, int) (EnableState, Return)
DeviceGetNvLinkUtilizationControl(Device, int, int) (NvLinkUtilizationControl, Return)
DeviceGetNvLinkUtilizationCounter(Device, int, int) (uint64, uint64, Return)
DeviceGetNvLinkVersion(Device, int) (uint32, Return)
DeviceGetP2PStatus(Device, Device, GpuP2PCapsIndex) (GpuP2PStatus, Return)
DeviceGetPciInfo(Device) (PciInfo, Return)
DeviceGetPcieLinkMaxSpeed(Device) (uint32, Return)
DeviceGetPcieReplayCounter(Device) (int, Return)
DeviceGetPcieSpeed(Device) (int, Return)
DeviceGetPcieThroughput(Device, PcieUtilCounter) (uint32, Return)
DeviceGetPerformanceState(Device) (Pstates, Return)
DeviceGetPersistenceMode(Device) (EnableState, Return)
DeviceGetPgpuMetadataString(Device) (string, Return)
DeviceGetPowerManagementDefaultLimit(Device) (uint32, Return)
DeviceGetPowerManagementLimit(Device) (uint32, Return)
DeviceGetPowerManagementLimitConstraints(Device) (uint32, uint32, Return)
DeviceGetPowerManagementMode(Device) (EnableState, Return)
DeviceGetPowerSource(Device) (PowerSource, Return)
DeviceGetPowerState(Device) (Pstates, Return)
DeviceGetPowerUsage(Device) (uint32, Return)
DeviceGetProcessUtilization(Device, uint64) ([]ProcessUtilizationSample, Return)
DeviceGetRemappedRows(Device) (int, int, bool, bool, Return)
DeviceGetRetiredPages(Device, PageRetirementCause) ([]uint64, Return)
DeviceGetRetiredPagesPendingStatus(Device) (EnableState, Return)
DeviceGetRetiredPages_v2(Device, PageRetirementCause) ([]uint64, []uint64, Return)
DeviceGetRowRemapperHistogram(Device) (RowRemapperHistogramValues, Return)
DeviceGetSamples(Device, SamplingType, uint64) (ValueType, []Sample, Return)
DeviceGetSerial(Device) (string, Return)
DeviceGetSupportedClocksThrottleReasons(Device) (uint64, Return)
DeviceGetSupportedEventTypes(Device) (uint64, Return)
DeviceGetSupportedGraphicsClocks(Device, int) (int, uint32, Return)
DeviceGetSupportedMemoryClocks(Device) (int, uint32, Return)
DeviceGetSupportedPerformanceStates(Device) ([]Pstates, Return)
DeviceGetSupportedVgpus(Device) ([]VgpuTypeId, Return)
DeviceGetTargetFanSpeed(Device, int) (int, Return)
DeviceGetTemperature(Device, TemperatureSensors) (uint32, Return)
DeviceGetTemperatureThreshold(Device, TemperatureThresholds) (uint32, Return)
DeviceGetThermalSettings(Device, uint32) (GpuThermalSettings, Return)
DeviceGetTopologyCommonAncestor(Device, Device) (GpuTopologyLevel, Return)
DeviceGetTopologyNearestGpus(Device, GpuTopologyLevel) ([]Device, Return)
DeviceGetTotalEccErrors(Device, MemoryErrorType, EccCounterType) (uint64, Return)
DeviceGetTotalEnergyConsumption(Device) (uint64, Return)
DeviceGetUUID(Device) (string, Return)
DeviceGetUtilizationRates(Device) (Utilization, Return)
DeviceGetVbiosVersion(Device) (string, Return)
DeviceGetVgpuCapabilities(Device, DeviceVgpuCapability) (bool, Return)
DeviceGetVgpuMetadata(Device) (VgpuPgpuMetadata, Return)
DeviceGetVgpuProcessUtilization(Device, uint64) ([]VgpuProcessUtilizationSample, Return)
DeviceGetVgpuSchedulerCapabilities(Device) (VgpuSchedulerCapabilities, Return)
DeviceGetVgpuSchedulerLog(Device) (VgpuSchedulerLog, Return)
DeviceGetVgpuSchedulerState(Device) (VgpuSchedulerGetState, Return)
DeviceGetVgpuUtilization(Device, uint64) (ValueType, []VgpuInstanceUtilizationSample, Return)
DeviceGetViolationStatus(Device, PerfPolicyType) (ViolationTime, Return)
DeviceGetVirtualizationMode(Device) (GpuVirtualizationMode, Return)
DeviceIsMigDeviceHandle(Device) (bool, Return)
DeviceModifyDrainState(*PciInfo, EnableState) Return
DeviceOnSameBoard(Device, Device) (int, Return)
DeviceQueryDrainState(*PciInfo) (EnableState, Return)
DeviceRegisterEvents(Device, uint64, EventSet) Return
DeviceRemoveGpu(*PciInfo) Return
DeviceRemoveGpu_v2(*PciInfo, DetachGpuState, PcieLinkState) Return
DeviceResetApplicationsClocks(Device) Return
DeviceResetGpuLockedClocks(Device) Return
DeviceResetMemoryLockedClocks(Device) Return
DeviceResetNvLinkErrorCounters(Device, int) Return
DeviceResetNvLinkUtilizationCounter(Device, int, int) Return
DeviceSetAPIRestriction(Device, RestrictedAPI, EnableState) Return
DeviceSetAccountingMode(Device, EnableState) Return
DeviceSetApplicationsClocks(Device, uint32, uint32) Return
DeviceSetAutoBoostedClocksEnabled(Device, EnableState) Return
DeviceSetComputeMode(Device, ComputeMode) Return
DeviceSetCpuAffinity(Device) Return
DeviceSetDefaultAutoBoostedClocksEnabled(Device, EnableState, uint32) Return
DeviceSetDefaultFanSpeed_v2(Device, int) Return
DeviceSetDriverModel(Device, DriverModel, uint32) Return
DeviceSetEccMode(Device, EnableState) Return
DeviceSetFanControlPolicy(Device, int, FanControlPolicy) Return
DeviceSetFanSpeed_v2(Device, int, int) Return
DeviceSetGpcClkVfOffset(Device, int) Return
DeviceSetGpuLockedClocks(Device, uint32, uint32) Return
DeviceSetGpuOperationMode(Device, GpuOperationMode) Return
DeviceSetMemClkVfOffset(Device, int) Return
DeviceSetMemoryLockedClocks(Device, uint32, uint32) Return
DeviceSetMigMode(Device, int) (Return, Return)
DeviceSetNvLinkDeviceLowPowerThreshold(Device, *NvLinkPowerThres) Return
DeviceSetNvLinkUtilizationControl(Device, int, int, *NvLinkUtilizationControl, bool) Return
DeviceSetPersistenceMode(Device, EnableState) Return
DeviceSetPowerManagementLimit(Device, uint32) Return
DeviceSetTemperatureThreshold(Device, TemperatureThresholds, int) Return
DeviceSetVgpuSchedulerState(Device, *VgpuSchedulerSetState) Return
DeviceSetVirtualizationMode(Device, GpuVirtualizationMode) Return
DeviceValidateInforom(Device) Return
ErrorString(Return) string
EventSetCreate() (EventSet, Return)
EventSetFree(EventSet) Return
EventSetWait(EventSet, uint32) (EventData, Return)
Extensions() ExtendedInterface
GetExcludedDeviceCount() (int, Return)
GetExcludedDeviceInfoByIndex(int) (ExcludedDeviceInfo, Return)
GetVgpuCompatibility(*VgpuMetadata, *VgpuPgpuMetadata) (VgpuPgpuCompatibility, Return)
GetVgpuDriverCapabilities(VgpuDriverCapability) (bool, Return)
GetVgpuVersion() (VgpuVersion, VgpuVersion, Return)
GpmMetricsGet(*GpmMetricsGetType) Return
GpmMetricsGetV(*GpmMetricsGetType) GpmMetricsGetVType
GpmMigSampleGet(Device, int, GpmSample) Return
GpmQueryDeviceSupport(Device) (GpmSupport, Return)
GpmQueryDeviceSupportV(Device) GpmSupportV
GpmSampleAlloc() (GpmSample, Return)
GpmSampleFree(GpmSample) Return
GpmSampleGet(Device, GpmSample) Return
GpuInstanceCreateComputeInstance(GpuInstance, *ComputeInstanceProfileInfo) (ComputeInstance, Return)
GpuInstanceCreateComputeInstanceWithPlacement(GpuInstance, *ComputeInstanceProfileInfo, *ComputeInstancePlacement) (ComputeInstance, Return)
GpuInstanceDestroy(GpuInstance) Return
GpuInstanceGetComputeInstanceById(GpuInstance, int) (ComputeInstance, Return)
GpuInstanceGetComputeInstancePossiblePlacements(GpuInstance, *ComputeInstanceProfileInfo) ([]ComputeInstancePlacement, Return)
GpuInstanceGetComputeInstanceProfileInfo(GpuInstance, int, int) (ComputeInstanceProfileInfo, Return)
GpuInstanceGetComputeInstanceProfileInfoV(GpuInstance, int, int) ComputeInstanceProfileInfoV
GpuInstanceGetComputeInstanceRemainingCapacity(GpuInstance, *ComputeInstanceProfileInfo) (int, Return)
GpuInstanceGetComputeInstances(GpuInstance, *ComputeInstanceProfileInfo) ([]ComputeInstance, Return)
GpuInstanceGetInfo(GpuInstance) (GpuInstanceInfo, Return)
Init() Return
InitWithFlags(uint32) Return
SetVgpuVersion(*VgpuVersion) Return
Shutdown() Return
SystemGetCudaDriverVersion() (int, Return)
SystemGetCudaDriverVersion_v2() (int, Return)
SystemGetDriverVersion() (string, Return)
SystemGetHicVersion() ([]HwbcEntry, Return)
SystemGetNVMLVersion() (string, Return)
SystemGetProcessName(int) (string, Return)
SystemGetTopologyGpuSet(int) ([]Device, Return)
UnitGetCount() (int, Return)
UnitGetDevices(Unit) ([]Device, Return)
UnitGetFanSpeedInfo(Unit) (UnitFanSpeeds, Return)
UnitGetHandleByIndex(int) (Unit, Return)
UnitGetLedState(Unit) (LedState, Return)
UnitGetPsuInfo(Unit) (PSUInfo, Return)
UnitGetTemperature(Unit, int) (uint32, Return)
UnitGetUnitInfo(Unit) (UnitInfo, Return)
UnitSetLedState(Unit, LedColor) Return
VgpuInstanceClearAccountingPids(VgpuInstance) Return
VgpuInstanceGetAccountingMode(VgpuInstance) (EnableState, Return)
VgpuInstanceGetAccountingPids(VgpuInstance) ([]int, Return)
VgpuInstanceGetAccountingStats(VgpuInstance, int) (AccountingStats, Return)
VgpuInstanceGetEccMode(VgpuInstance) (EnableState, Return)
VgpuInstanceGetEncoderCapacity(VgpuInstance) (int, Return)
VgpuInstanceGetEncoderSessions(VgpuInstance) (int, EncoderSessionInfo, Return)
VgpuInstanceGetEncoderStats(VgpuInstance) (int, uint32, uint32, Return)
VgpuInstanceGetFBCSessions(VgpuInstance) (int, FBCSessionInfo, Return)
VgpuInstanceGetFBCStats(VgpuInstance) (FBCStats, Return)
VgpuInstanceGetFbUsage(VgpuInstance) (uint64, Return)
VgpuInstanceGetFrameRateLimit(VgpuInstance) (uint32, Return)
VgpuInstanceGetGpuInstanceId(VgpuInstance) (int, Return)
VgpuInstanceGetGpuPciId(VgpuInstance) (string, Return)
VgpuInstanceGetLicenseInfo(VgpuInstance) (VgpuLicenseInfo, Return)
VgpuInstanceGetLicenseStatus(VgpuInstance) (int, Return)
VgpuInstanceGetMdevUUID(VgpuInstance) (string, Return)
VgpuInstanceGetMetadata(VgpuInstance) (VgpuMetadata, Return)
VgpuInstanceGetType(VgpuInstance) (VgpuTypeId, Return)
VgpuInstanceGetUUID(VgpuInstance) (string, Return)
VgpuInstanceGetVmDriverVersion(VgpuInstance) (string, Return)
VgpuInstanceGetVmID(VgpuInstance) (string, VgpuVmIdType, Return)
VgpuInstanceSetEncoderCapacity(VgpuInstance, int) Return
VgpuTypeGetCapabilities(VgpuTypeId, VgpuCapability) (bool, Return)
VgpuTypeGetClass(VgpuTypeId) (string, Return)
VgpuTypeGetDeviceID(VgpuTypeId) (uint64, uint64, Return)
VgpuTypeGetFrameRateLimit(VgpuTypeId) (uint32, Return)
VgpuTypeGetFramebufferSize(VgpuTypeId) (uint64, Return)
VgpuTypeGetGpuInstanceProfileId(VgpuTypeId) (uint32, Return)
VgpuTypeGetLicense(VgpuTypeId) (string, Return)
VgpuTypeGetMaxInstances(Device, VgpuTypeId) (int, Return)
VgpuTypeGetMaxInstancesPerVm(VgpuTypeId) (int, Return)
VgpuTypeGetName(VgpuTypeId) (string, Return)
VgpuTypeGetNumDisplayHeads(VgpuTypeId) (int, Return)
VgpuTypeGetResolution(VgpuTypeId, int) (uint32, uint32, Return)
}
// Device represents the interface for the nvmlDevice type.
//
//go:generate moq -out mock/device.go -pkg mock . Device:Device
type Device interface {
CcuGetStreamState() (int, Return)
CcuSetStreamState(int) Return
ClearAccountingPids() Return
ClearCpuAffinity() Return
ClearEccErrorCounts(EccCounterType) Return
ClearFieldValues([]FieldValue) Return
CreateGpuInstance(*GpuInstanceProfileInfo) (GpuInstance, Return)
CreateGpuInstanceWithPlacement(*GpuInstanceProfileInfo, *GpuInstancePlacement) (GpuInstance, Return)
FreezeNvLinkUtilizationCounter(int, int, EnableState) Return
GetAPIRestriction(RestrictedAPI) (EnableState, Return)
GetAccountingBufferSize() (int, Return)
GetAccountingMode() (EnableState, Return)
GetAccountingPids() ([]int, Return)
GetAccountingStats(uint32) (AccountingStats, Return)
GetActiveVgpus() ([]VgpuInstance, Return)
GetAdaptiveClockInfoStatus() (uint32, Return)
GetApplicationsClock(ClockType) (uint32, Return)
GetArchitecture() (DeviceArchitecture, Return)
GetAttributes() (DeviceAttributes, Return)
GetAutoBoostedClocksEnabled() (EnableState, EnableState, Return)
GetBAR1MemoryInfo() (BAR1Memory, Return)
GetBoardId() (uint32, Return)
GetBoardPartNumber() (string, Return)
GetBrand() (BrandType, Return)
GetBridgeChipInfo() (BridgeChipHierarchy, Return)
GetBusType() (BusType, Return)
GetClkMonStatus() (ClkMonStatus, Return)
GetClock(ClockType, ClockId) (uint32, Return)
GetClockInfo(ClockType) (uint32, Return)
GetComputeInstanceId() (int, Return)
GetComputeMode() (ComputeMode, Return)
GetComputeRunningProcesses() ([]ProcessInfo, Return)
GetCpuAffinity(int) ([]uint, Return)
GetCpuAffinityWithinScope(int, AffinityScope) ([]uint, Return)
GetCreatableVgpus() ([]VgpuTypeId, Return)
GetCudaComputeCapability() (int, int, Return)
GetCurrPcieLinkGeneration() (int, Return)
GetCurrPcieLinkWidth() (int, Return)
GetCurrentClocksThrottleReasons() (uint64, Return)
GetDecoderUtilization() (uint32, uint32, Return)
GetDefaultApplicationsClock(ClockType) (uint32, Return)
GetDefaultEccMode() (EnableState, Return)
GetDetailedEccErrors(MemoryErrorType, EccCounterType) (EccErrorCounts, Return)
GetDeviceHandleFromMigDeviceHandle() (Device, Return)
GetDisplayActive() (EnableState, Return)
GetDisplayMode() (EnableState, Return)
GetDriverModel() (DriverModel, DriverModel, Return)
GetDynamicPstatesInfo() (GpuDynamicPstatesInfo, Return)
GetEccMode() (EnableState, EnableState, Return)
GetEncoderCapacity(EncoderType) (int, Return)
GetEncoderSessions() ([]EncoderSessionInfo, Return)
GetEncoderStats() (int, uint32, uint32, Return)
GetEncoderUtilization() (uint32, uint32, Return)
GetEnforcedPowerLimit() (uint32, Return)
GetFBCSessions() ([]FBCSessionInfo, Return)
GetFBCStats() (FBCStats, Return)
GetFanControlPolicy_v2(int) (FanControlPolicy, Return)
GetFanSpeed() (uint32, Return)
GetFanSpeed_v2(int) (uint32, Return)
GetFieldValues([]FieldValue) Return
GetGpcClkMinMaxVfOffset() (int, int, Return)
GetGpcClkVfOffset() (int, Return)
GetGpuFabricInfo() (GpuFabricInfo, Return)
GetGpuInstanceById(int) (GpuInstance, Return)
GetGpuInstanceId() (int, Return)
GetGpuInstancePossiblePlacements(*GpuInstanceProfileInfo) ([]GpuInstancePlacement, Return)
GetGpuInstanceProfileInfo(int) (GpuInstanceProfileInfo, Return)
GetGpuInstanceProfileInfoV(int) GpuInstanceProfileInfoV
GetGpuInstanceRemainingCapacity(*GpuInstanceProfileInfo) (int, Return)
GetGpuInstances(*GpuInstanceProfileInfo) ([]GpuInstance, Return)
GetGpuMaxPcieLinkGeneration() (int, Return)
GetGpuOperationMode() (GpuOperationMode, GpuOperationMode, Return)
GetGraphicsRunningProcesses() ([]ProcessInfo, Return)
GetGridLicensableFeatures() (GridLicensableFeatures, Return)
GetGspFirmwareMode() (bool, bool, Return)
GetGspFirmwareVersion() (string, Return)
GetHostVgpuMode() (HostVgpuMode, Return)
GetIndex() (int, Return)
GetInforomConfigurationChecksum() (uint32, Return)
GetInforomImageVersion() (string, Return)
GetInforomVersion(InforomObject) (string, Return)
GetIrqNum() (int, Return)
GetMPSComputeRunningProcesses() ([]ProcessInfo, Return)
GetMaxClockInfo(ClockType) (uint32, Return)
GetMaxCustomerBoostClock(ClockType) (uint32, Return)
GetMaxMigDeviceCount() (int, Return)
GetMaxPcieLinkGeneration() (int, Return)
GetMaxPcieLinkWidth() (int, Return)
GetMemClkMinMaxVfOffset() (int, int, Return)
GetMemClkVfOffset() (int, Return)
GetMemoryAffinity(int, AffinityScope) ([]uint, Return)
GetMemoryBusWidth() (uint32, Return)
GetMemoryErrorCounter(MemoryErrorType, EccCounterType, MemoryLocation) (uint64, Return)
GetMemoryInfo() (Memory, Return)
GetMemoryInfo_v2() (Memory_v2, Return)
GetMigDeviceHandleByIndex(int) (Device, Return)
GetMigMode() (int, int, Return)
GetMinMaxClockOfPState(ClockType, Pstates) (uint32, uint32, Return)
GetMinMaxFanSpeed() (int, int, Return)
GetMinorNumber() (int, Return)
GetMultiGpuBoard() (int, Return)
GetName() (string, Return)
GetNumFans() (int, Return)
GetNumGpuCores() (int, Return)
GetNvLinkCapability(int, NvLinkCapability) (uint32, Return)
GetNvLinkErrorCounter(int, NvLinkErrorCounter) (uint64, Return)
GetNvLinkRemoteDeviceType(int) (IntNvLinkDeviceType, Return)
GetNvLinkRemotePciInfo(int) (PciInfo, Return)
GetNvLinkState(int) (EnableState, Return)
GetNvLinkUtilizationControl(int, int) (NvLinkUtilizationControl, Return)
GetNvLinkUtilizationCounter(int, int) (uint64, uint64, Return)
GetNvLinkVersion(int) (uint32, Return)
GetP2PStatus(Device, GpuP2PCapsIndex) (GpuP2PStatus, Return)
GetPciInfo() (PciInfo, Return)
GetPcieLinkMaxSpeed() (uint32, Return)
GetPcieReplayCounter() (int, Return)
GetPcieSpeed() (int, Return)
GetPcieThroughput(PcieUtilCounter) (uint32, Return)
GetPerformanceState() (Pstates, Return)
GetPersistenceMode() (EnableState, Return)
GetPgpuMetadataString() (string, Return)
GetPowerManagementDefaultLimit() (uint32, Return)
GetPowerManagementLimit() (uint32, Return)
GetPowerManagementLimitConstraints() (uint32, uint32, Return)
GetPowerManagementMode() (EnableState, Return)
GetPowerSource() (PowerSource, Return)
GetPowerState() (Pstates, Return)
GetPowerUsage() (uint32, Return)
GetProcessUtilization(uint64) ([]ProcessUtilizationSample, Return)
GetRemappedRows() (int, int, bool, bool, Return)
GetRetiredPages(PageRetirementCause) ([]uint64, Return)
GetRetiredPagesPendingStatus() (EnableState, Return)
GetRetiredPages_v2(PageRetirementCause) ([]uint64, []uint64, Return)
GetRowRemapperHistogram() (RowRemapperHistogramValues, Return)
GetSamples(SamplingType, uint64) (ValueType, []Sample, Return)
GetSerial() (string, Return)
GetSupportedClocksThrottleReasons() (uint64, Return)
GetSupportedEventTypes() (uint64, Return)
GetSupportedGraphicsClocks(int) (int, uint32, Return)
GetSupportedMemoryClocks() (int, uint32, Return)
GetSupportedPerformanceStates() ([]Pstates, Return)
GetSupportedVgpus() ([]VgpuTypeId, Return)
GetTargetFanSpeed(int) (int, Return)
GetTemperature(TemperatureSensors) (uint32, Return)
GetTemperatureThreshold(TemperatureThresholds) (uint32, Return)
GetThermalSettings(uint32) (GpuThermalSettings, Return)
GetTopologyCommonAncestor(Device) (GpuTopologyLevel, Return)
GetTopologyNearestGpus(GpuTopologyLevel) ([]Device, Return)
GetTotalEccErrors(MemoryErrorType, EccCounterType) (uint64, Return)
GetTotalEnergyConsumption() (uint64, Return)
GetUUID() (string, Return)
GetUtilizationRates() (Utilization, Return)
GetVbiosVersion() (string, Return)
GetVgpuCapabilities(DeviceVgpuCapability) (bool, Return)
GetVgpuMetadata() (VgpuPgpuMetadata, Return)
GetVgpuProcessUtilization(uint64) ([]VgpuProcessUtilizationSample, Return)
GetVgpuSchedulerCapabilities() (VgpuSchedulerCapabilities, Return)
GetVgpuSchedulerLog() (VgpuSchedulerLog, Return)
GetVgpuSchedulerState() (VgpuSchedulerGetState, Return)
GetVgpuUtilization(uint64) (ValueType, []VgpuInstanceUtilizationSample, Return)
GetViolationStatus(PerfPolicyType) (ViolationTime, Return)
GetVirtualizationMode() (GpuVirtualizationMode, Return)
GpmMigSampleGet(int, GpmSample) Return
GpmQueryDeviceSupport() (GpmSupport, Return)
GpmQueryDeviceSupportV() GpmSupportV
GpmSampleGet(GpmSample) Return
IsMigDeviceHandle() (bool, Return)
OnSameBoard(Device) (int, Return)
RegisterEvents(uint64, EventSet) Return
ResetApplicationsClocks() Return
ResetGpuLockedClocks() Return
ResetMemoryLockedClocks() Return
ResetNvLinkErrorCounters(int) Return
ResetNvLinkUtilizationCounter(int, int) Return
SetAPIRestriction(RestrictedAPI, EnableState) Return
SetAccountingMode(EnableState) Return
SetApplicationsClocks(uint32, uint32) Return
SetAutoBoostedClocksEnabled(EnableState) Return
SetComputeMode(ComputeMode) Return
SetCpuAffinity() Return
SetDefaultAutoBoostedClocksEnabled(EnableState, uint32) Return
SetDefaultFanSpeed_v2(int) Return
SetDriverModel(DriverModel, uint32) Return
SetEccMode(EnableState) Return
SetFanControlPolicy(int, FanControlPolicy) Return
SetFanSpeed_v2(int, int) Return
SetGpcClkVfOffset(int) Return
SetGpuLockedClocks(uint32, uint32) Return
SetGpuOperationMode(GpuOperationMode) Return
SetMemClkVfOffset(int) Return
SetMemoryLockedClocks(uint32, uint32) Return
SetMigMode(int) (Return, Return)
SetNvLinkDeviceLowPowerThreshold(*NvLinkPowerThres) Return
SetNvLinkUtilizationControl(int, int, *NvLinkUtilizationControl, bool) Return
SetPersistenceMode(EnableState) Return
SetPowerManagementLimit(uint32) Return
SetTemperatureThreshold(TemperatureThresholds, int) Return
SetVgpuSchedulerState(*VgpuSchedulerSetState) Return
SetVirtualizationMode(GpuVirtualizationMode) Return
ValidateInforom() Return
VgpuTypeGetMaxInstances(VgpuTypeId) (int, Return)
}
// GpuInstance represents the interface for the nvmlGpuInstance type.
//
//go:generate moq -out mock/gpuinstance.go -pkg mock . GpuInstance:GpuInstance
type GpuInstance interface {
CreateComputeInstance(*ComputeInstanceProfileInfo) (ComputeInstance, Return)
CreateComputeInstanceWithPlacement(*ComputeInstanceProfileInfo, *ComputeInstancePlacement) (ComputeInstance, Return)
Destroy() Return
GetComputeInstanceById(int) (ComputeInstance, Return)
GetComputeInstancePossiblePlacements(*ComputeInstanceProfileInfo) ([]ComputeInstancePlacement, Return)
GetComputeInstanceProfileInfo(int, int) (ComputeInstanceProfileInfo, Return)
GetComputeInstanceProfileInfoV(int, int) ComputeInstanceProfileInfoV
GetComputeInstanceRemainingCapacity(*ComputeInstanceProfileInfo) (int, Return)
GetComputeInstances(*ComputeInstanceProfileInfo) ([]ComputeInstance, Return)
GetInfo() (GpuInstanceInfo, Return)
}
// ComputeInstance represents the interface for the nvmlComputeInstance type.
//
//go:generate moq -out mock/computeinstance.go -pkg mock . ComputeInstance:ComputeInstance
type ComputeInstance interface {
Destroy() Return
GetInfo() (ComputeInstanceInfo, Return)
}
// EventSet represents the interface for the nvmlEventSet type.
//
//go:generate moq -out mock/eventset.go -pkg mock . EventSet:EventSet
type EventSet interface {
Free() Return
Wait(uint32) (EventData, Return)
}
// GpmSample represents the interface for the nvmlGpmSample type.
//
//go:generate moq -out mock/gpmsample.go -pkg mock . GpmSample:GpmSample
type GpmSample interface {
Free() Return
Get(Device) Return
MigGet(Device, int) Return
}
// Unit represents the interface for the nvmlUnit type.
//
//go:generate moq -out mock/unit.go -pkg mock . Unit:Unit
type Unit interface {
GetDevices() ([]Device, Return)
GetFanSpeedInfo() (UnitFanSpeeds, Return)
GetLedState() (LedState, Return)
GetPsuInfo() (PSUInfo, Return)
GetTemperature(int) (uint32, Return)
GetUnitInfo() (UnitInfo, Return)
SetLedState(LedColor) Return
}
// VgpuInstance represents the interface for the nvmlVgpuInstance type.
//
//go:generate moq -out mock/vgpuinstance.go -pkg mock . VgpuInstance:VgpuInstance
type VgpuInstance interface {
ClearAccountingPids() Return
GetAccountingMode() (EnableState, Return)
GetAccountingPids() ([]int, Return)
GetAccountingStats(int) (AccountingStats, Return)
GetEccMode() (EnableState, Return)
GetEncoderCapacity() (int, Return)
GetEncoderSessions() (int, EncoderSessionInfo, Return)
GetEncoderStats() (int, uint32, uint32, Return)
GetFBCSessions() (int, FBCSessionInfo, Return)
GetFBCStats() (FBCStats, Return)
GetFbUsage() (uint64, Return)
GetFrameRateLimit() (uint32, Return)
GetGpuInstanceId() (int, Return)
GetGpuPciId() (string, Return)
GetLicenseInfo() (VgpuLicenseInfo, Return)
GetLicenseStatus() (int, Return)
GetMdevUUID() (string, Return)
GetMetadata() (VgpuMetadata, Return)
GetType() (VgpuTypeId, Return)
GetUUID() (string, Return)
GetVmDriverVersion() (string, Return)
GetVmID() (string, VgpuVmIdType, Return)
SetEncoderCapacity(int) Return
}
// VgpuTypeId represents the interface for the nvmlVgpuTypeId type.
//
//go:generate moq -out mock/vgputypeid.go -pkg mock . VgpuTypeId:VgpuTypeId
type VgpuTypeId interface {
GetCapabilities(VgpuCapability) (bool, Return)
GetClass() (string, Return)
GetDeviceID() (uint64, uint64, Return)
GetFrameRateLimit() (uint32, Return)
GetFramebufferSize() (uint64, Return)
GetGpuInstanceProfileId() (uint32, Return)
GetLicense() (string, Return)
GetMaxInstances(Device) (int, Return)
GetMaxInstancesPerVm() (int, Return)
GetName() (string, Return)
GetNumDisplayHeads() (int, Return)
GetResolution(int) (uint32, uint32, Return)
}

View File

@@ -9,6 +9,8 @@ func Render(doc []byte) []byte {
renderer := NewRoffRenderer()
return blackfriday.Run(doc,
[]blackfriday.Option{blackfriday.WithRenderer(renderer),
blackfriday.WithExtensions(renderer.GetExtensions())}...)
[]blackfriday.Option{
blackfriday.WithRenderer(renderer),
blackfriday.WithExtensions(renderer.GetExtensions()),
}...)
}

View File

@@ -1,6 +1,8 @@
package md2man
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
@@ -20,34 +22,35 @@ type roffRenderer struct {
}
const (
titleHeader = ".TH "
topLevelHeader = "\n\n.SH "
secondLevelHdr = "\n.SH "
otherHeader = "\n.SS "
crTag = "\n"
emphTag = "\\fI"
emphCloseTag = "\\fP"
strongTag = "\\fB"
strongCloseTag = "\\fP"
breakTag = "\n.br\n"
paraTag = "\n.PP\n"
hruleTag = "\n.ti 0\n\\l'\\n(.lu'\n"
linkTag = "\n\\[la]"
linkCloseTag = "\\[ra]"
codespanTag = "\\fB\\fC"
codespanCloseTag = "\\fR"
codeTag = "\n.PP\n.RS\n\n.nf\n"
codeCloseTag = "\n.fi\n.RE\n"
quoteTag = "\n.PP\n.RS\n"
quoteCloseTag = "\n.RE\n"
listTag = "\n.RS\n"
listCloseTag = "\n.RE\n"
dtTag = "\n.TP\n"
dd2Tag = "\n"
tableStart = "\n.TS\nallbox;\n"
tableEnd = ".TE\n"
tableCellStart = "T{\n"
tableCellEnd = "\nT}\n"
titleHeader = ".TH "
topLevelHeader = "\n\n.SH "
secondLevelHdr = "\n.SH "
otherHeader = "\n.SS "
crTag = "\n"
emphTag = "\\fI"
emphCloseTag = "\\fP"
strongTag = "\\fB"
strongCloseTag = "\\fP"
breakTag = "\n.br\n"
paraTag = "\n.PP\n"
hruleTag = "\n.ti 0\n\\l'\\n(.lu'\n"
linkTag = "\n\\[la]"
linkCloseTag = "\\[ra]"
codespanTag = "\\fB"
codespanCloseTag = "\\fR"
codeTag = "\n.EX\n"
codeCloseTag = ".EE\n" // Do not prepend a newline character since code blocks, by definition, include a newline already (or at least as how blackfriday gives us on).
quoteTag = "\n.PP\n.RS\n"
quoteCloseTag = "\n.RE\n"
listTag = "\n.RS\n"
listCloseTag = "\n.RE\n"
dtTag = "\n.TP\n"
dd2Tag = "\n"
tableStart = "\n.TS\nallbox;\n"
tableEnd = ".TE\n"
tableCellStart = "T{\n"
tableCellEnd = "\nT}\n"
tablePreprocessor = `'\" t`
)
// NewRoffRenderer creates a new blackfriday Renderer for generating roff documents
@@ -74,6 +77,16 @@ func (r *roffRenderer) GetExtensions() blackfriday.Extensions {
// RenderHeader handles outputting the header at document start
func (r *roffRenderer) RenderHeader(w io.Writer, ast *blackfriday.Node) {
// We need to walk the tree to check if there are any tables.
// If there are, we need to enable the roff table preprocessor.
ast.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
if node.Type == blackfriday.Table {
out(w, tablePreprocessor+"\n")
return blackfriday.Terminate
}
return blackfriday.GoToNext
})
// disable hyphenation
out(w, ".nh\n")
}
@@ -86,8 +99,7 @@ func (r *roffRenderer) RenderFooter(w io.Writer, ast *blackfriday.Node) {
// RenderNode is called for each node in a markdown document; based on the node
// type the equivalent roff output is sent to the writer
func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
var walkAction = blackfriday.GoToNext
walkAction := blackfriday.GoToNext
switch node.Type {
case blackfriday.Text:
@@ -109,9 +121,16 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
out(w, strongCloseTag)
}
case blackfriday.Link:
if !entering {
out(w, linkTag+string(node.LinkData.Destination)+linkCloseTag)
// Don't render the link text for automatic links, because this
// will only duplicate the URL in the roff output.
// See https://daringfireball.net/projects/markdown/syntax#autolink
if !bytes.Equal(node.LinkData.Destination, node.FirstChild.Literal) {
out(w, string(node.FirstChild.Literal))
}
// Hyphens in a link must be escaped to avoid word-wrap in the rendered man page.
escapedLink := strings.ReplaceAll(string(node.LinkData.Destination), "-", "\\-")
out(w, linkTag+escapedLink+linkCloseTag)
walkAction = blackfriday.SkipChildren
case blackfriday.Image:
// ignore images
walkAction = blackfriday.SkipChildren
@@ -160,6 +179,11 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
r.handleTableCell(w, node, entering)
case blackfriday.HTMLSpan:
// ignore other HTML tags
case blackfriday.HTMLBlock:
if bytes.HasPrefix(node.Literal, []byte("<!--")) {
break // ignore comments, no warning
}
fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String())
default:
fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String())
}
@@ -254,7 +278,7 @@ func (r *roffRenderer) handleTableCell(w io.Writer, node *blackfriday.Node, ente
start = "\t"
}
if node.IsHeader {
start += codespanTag
start += strongTag
} else if nodeLiteralSize(node) > 30 {
start += tableCellStart
}
@@ -262,7 +286,7 @@ func (r *roffRenderer) handleTableCell(w io.Writer, node *blackfriday.Node, ente
} else {
var end string
if node.IsHeader {
end = codespanCloseTag
end = strongCloseTag
} else if nodeLiteralSize(node) > 30 {
end = tableCellEnd
}
@@ -310,6 +334,28 @@ func out(w io.Writer, output string) {
}
func escapeSpecialChars(w io.Writer, text []byte) {
scanner := bufio.NewScanner(bytes.NewReader(text))
// count the number of lines in the text
// we need to know this to avoid adding a newline after the last line
n := bytes.Count(text, []byte{'\n'})
idx := 0
for scanner.Scan() {
dt := scanner.Bytes()
if idx < n {
idx++
dt = append(dt, '\n')
}
escapeSpecialCharsLine(w, dt)
}
if err := scanner.Err(); err != nil {
panic(err)
}
}
func escapeSpecialCharsLine(w io.Writer, text []byte) {
for i := 0; i < len(text); i++ {
// escape initial apostrophe or period
if len(text) >= 1 && (text[0] == '\'' || text[0] == '.') {

View File

@@ -229,8 +229,6 @@ func (a *App) Setup() {
a.separator.disabled = true
}
var newCommands []*Command
for _, c := range a.Commands {
cname := c.Name
if c.HelpName != "" {
@@ -239,9 +237,7 @@ func (a *App) Setup() {
c.separator = a.separator
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, cname)
c.flagCategories = newFlagCategoriesFromFlags(c.Flags)
newCommands = append(newCommands, c)
}
a.Commands = newCommands
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
if !a.HideHelpCommand {

View File

@@ -104,7 +104,7 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
var categorized bool
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cat := cf.GetCategory(); cat != "" {
if cat := cf.GetCategory(); cat != "" && cf.IsVisible() {
fc.AddFlag(cat, cf)
categorized = true
}
@@ -114,7 +114,7 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
if categorized {
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cf.GetCategory() == "" {
if cf.GetCategory() == "" && cf.IsVisible() {
fc.AddFlag("", fl)
}
}

View File

@@ -132,15 +132,12 @@ func (c *Command) setup(ctx *Context) {
}
sort.Sort(c.categories.(*commandCategories))
var newCmds []*Command
for _, scmd := range c.Subcommands {
if scmd.HelpName == "" {
scmd.HelpName = fmt.Sprintf("%s %s", c.HelpName, scmd.Name)
}
scmd.separator = c.separator
newCmds = append(newCmds, scmd)
}
c.Subcommands = newCmds
if c.BashComplete == nil {
c.BashComplete = DefaultCompleteWithFlags(c)

View File

@@ -1,7 +1,7 @@
package cli
var helpNameTemplate = `{{$v := offset .HelpName 6}}{{wrap .HelpName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}`
var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}[arguments...]{{end}}{{end}}`
var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}`
var descriptionTemplate = `{{wrap .Description 3}}`
var authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
{{range $index, $author := .Authors}}{{if $index}}

View File

@@ -6,36 +6,58 @@ import (
// The Soundex encoding. It is a phonetic algorithm that considers how the words sound in English. Soundex maps a string to a 4-byte code consisting of the first letter of the original string and three numbers. Strings that sound similar should map to the same code.
func Soundex(s string) string {
m := map[byte]string{
'B': "1", 'P': "1", 'F': "1", 'V': "1",
'C': "2", 'S': "2", 'K': "2", 'G': "2", 'J': "2", 'Q': "2", 'X': "2", 'Z': "2",
'D': "3", 'T': "3",
'L': "4",
'M': "5", 'N': "5",
'R': "6",
}
b := strings.Builder{}
b.Grow(4)
s = strings.ToUpper(s)
r := string(s[0])
p := s[0]
for i := 1; i < len(s) && len(r) < 4; i++ {
if p <= 'z' && p >= 'a' {
p -= 32 // convert to uppercase
}
b.WriteByte(p)
n := 0
for i := 1; i < len(s); i++ {
c := s[i]
if (c < 'A' || c > 'Z') || (c == p) {
if c <= 'z' && c >= 'a' {
c -= 32 // convert to uppercase
} else if c < 'A' || c > 'Z' {
continue
}
if c == p {
continue
}
p = c
if n, ok := m[c]; ok {
r += n
switch c {
case 'B', 'P', 'F', 'V':
c = '1'
case 'C', 'S', 'K', 'G', 'J', 'Q', 'X', 'Z':
c = '2'
case 'D', 'T':
c = '3'
case 'L':
c = '4'
case 'M', 'N':
c = '5'
case 'R':
c = '6'
default:
continue
}
b.WriteByte(c)
n++
if n == 3 {
break
}
}
for i := len(r); i < 4; i++ {
r += "0"
for i := n; i < 3; i++ {
b.WriteByte('0')
}
return r
return b.String()
}

View File

@@ -9,9 +9,11 @@
#define PSALAA 1208(R0)
#define GTAB64(x) 80(x)
#define LCA64(x) 88(x)
#define SAVSTACK_ASYNC(x) 336(x) // in the LCA
#define CAA(x) 8(x)
#define EDCHPXV(x) 1016(x) // in the CAA
#define SAVSTACK_ASYNC(x) 336(x) // in the LCA
#define CEECAATHDID(x) 976(x) // in the CAA
#define EDCHPXV(x) 1016(x) // in the CAA
#define GOCB(x) 1104(x) // in the CAA
// SS_*, where x=SAVSTACK_ASYNC
#define SS_LE(x) 0(x)
@@ -19,394 +21,125 @@
#define SS_ERRNO(x) 16(x)
#define SS_ERRNOJR(x) 20(x)
#define LE_CALL BYTE $0x0D; BYTE $0x76; // BL R7, R6
// Function Descriptor Offsets
#define __errno 0x156*16
#define __err2ad 0x16C*16
TEXT ·clearErrno(SB),NOSPLIT,$0-0
BL addrerrno<>(SB)
MOVD $0, 0(R3)
// Call Instructions
#define LE_CALL BYTE $0x0D; BYTE $0x76 // BL R7, R6
#define SVC_LOAD BYTE $0x0A; BYTE $0x08 // SVC 08 LOAD
#define SVC_DELETE BYTE $0x0A; BYTE $0x09 // SVC 09 DELETE
DATA zosLibVec<>(SB)/8, $0
GLOBL zosLibVec<>(SB), NOPTR, $8
TEXT ·initZosLibVec(SB), NOSPLIT|NOFRAME, $0-0
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVD CAA(R8), R8
MOVD EDCHPXV(R8), R8
MOVD R8, zosLibVec<>(SB)
RET
TEXT ·GetZosLibVec(SB), NOSPLIT|NOFRAME, $0-0
MOVD zosLibVec<>(SB), R8
MOVD R8, ret+0(FP)
RET
TEXT ·clearErrno(SB), NOSPLIT, $0-0
BL addrerrno<>(SB)
MOVD $0, 0(R3)
RET
// Returns the address of errno in R3.
TEXT addrerrno<>(SB),NOSPLIT|NOFRAME,$0-0
TEXT addrerrno<>(SB), NOSPLIT|NOFRAME, $0-0
// Get library control area (LCA).
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVW PSALAA, R8
MOVD LCA64(R8), R8
// Get __errno FuncDesc.
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
ADD $(0x156*16), R9
LMG 0(R9), R5, R6
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
ADD $(__errno), R9
LMG 0(R9), R5, R6
// Switch to saved LE stack.
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
// Call __errno function.
LE_CALL
NOPH
// Switch back to Go stack.
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
RET
TEXT ·syscall_syscall(SB),NOSPLIT,$0-56
BL runtime·entersyscall(SB)
MOVD a1+8(FP), R1
MOVD a2+16(FP), R2
MOVD a3+24(FP), R3
// Get library control area (LCA).
MOVW PSALAA, R8
MOVD LCA64(R8), R8
// Get function.
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
MOVD trap+0(FP), R5
SLD $4, R5
ADD R5, R9
LMG 0(R9), R5, R6
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
// Call function.
LE_CALL
NOPH
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
MOVD R3, r1+32(FP)
MOVD R0, r2+40(FP)
MOVD R0, err+48(FP)
MOVW R3, R4
CMP R4, $-1
BNE done
BL addrerrno<>(SB)
MOVWZ 0(R3), R3
MOVD R3, err+48(FP)
done:
BL runtime·exitsyscall(SB)
RET
TEXT ·syscall_rawsyscall(SB),NOSPLIT,$0-56
MOVD a1+8(FP), R1
MOVD a2+16(FP), R2
MOVD a3+24(FP), R3
// Get library control area (LCA).
MOVW PSALAA, R8
MOVD LCA64(R8), R8
// Get function.
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
MOVD trap+0(FP), R5
SLD $4, R5
ADD R5, R9
LMG 0(R9), R5, R6
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
// Call function.
LE_CALL
NOPH
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
MOVD R3, r1+32(FP)
MOVD R0, r2+40(FP)
MOVD R0, err+48(FP)
MOVW R3, R4
CMP R4, $-1
BNE done
BL addrerrno<>(SB)
MOVWZ 0(R3), R3
MOVD R3, err+48(FP)
done:
RET
TEXT ·syscall_syscall6(SB),NOSPLIT,$0-80
BL runtime·entersyscall(SB)
MOVD a1+8(FP), R1
MOVD a2+16(FP), R2
MOVD a3+24(FP), R3
// Get library control area (LCA).
MOVW PSALAA, R8
MOVD LCA64(R8), R8
// Get function.
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
MOVD trap+0(FP), R5
SLD $4, R5
ADD R5, R9
LMG 0(R9), R5, R6
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
// Fill in parameter list.
MOVD a4+32(FP), R12
MOVD R12, (2176+24)(R4)
MOVD a5+40(FP), R12
MOVD R12, (2176+32)(R4)
MOVD a6+48(FP), R12
MOVD R12, (2176+40)(R4)
// Call function.
LE_CALL
NOPH
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
MOVD R3, r1+56(FP)
MOVD R0, r2+64(FP)
MOVD R0, err+72(FP)
MOVW R3, R4
CMP R4, $-1
BNE done
BL addrerrno<>(SB)
MOVWZ 0(R3), R3
MOVD R3, err+72(FP)
done:
BL runtime·exitsyscall(SB)
RET
TEXT ·syscall_rawsyscall6(SB),NOSPLIT,$0-80
MOVD a1+8(FP), R1
MOVD a2+16(FP), R2
MOVD a3+24(FP), R3
// Get library control area (LCA).
MOVW PSALAA, R8
MOVD LCA64(R8), R8
// Get function.
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
MOVD trap+0(FP), R5
SLD $4, R5
ADD R5, R9
LMG 0(R9), R5, R6
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
// Fill in parameter list.
MOVD a4+32(FP), R12
MOVD R12, (2176+24)(R4)
MOVD a5+40(FP), R12
MOVD R12, (2176+32)(R4)
MOVD a6+48(FP), R12
MOVD R12, (2176+40)(R4)
// Call function.
LE_CALL
NOPH
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
MOVD R3, r1+56(FP)
MOVD R0, r2+64(FP)
MOVD R0, err+72(FP)
MOVW R3, R4
CMP R4, $-1
BNE done
BL ·rrno<>(SB)
MOVWZ 0(R3), R3
MOVD R3, err+72(FP)
done:
RET
TEXT ·syscall_syscall9(SB),NOSPLIT,$0
BL runtime·entersyscall(SB)
MOVD a1+8(FP), R1
MOVD a2+16(FP), R2
MOVD a3+24(FP), R3
// Get library control area (LCA).
MOVW PSALAA, R8
MOVD LCA64(R8), R8
// Get function.
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
MOVD trap+0(FP), R5
SLD $4, R5
ADD R5, R9
LMG 0(R9), R5, R6
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
// Fill in parameter list.
MOVD a4+32(FP), R12
MOVD R12, (2176+24)(R4)
MOVD a5+40(FP), R12
MOVD R12, (2176+32)(R4)
MOVD a6+48(FP), R12
MOVD R12, (2176+40)(R4)
MOVD a7+56(FP), R12
MOVD R12, (2176+48)(R4)
MOVD a8+64(FP), R12
MOVD R12, (2176+56)(R4)
MOVD a9+72(FP), R12
MOVD R12, (2176+64)(R4)
// Call function.
LE_CALL
NOPH
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
MOVD R3, r1+80(FP)
MOVD R0, r2+88(FP)
MOVD R0, err+96(FP)
MOVW R3, R4
CMP R4, $-1
BNE done
BL addrerrno<>(SB)
MOVWZ 0(R3), R3
MOVD R3, err+96(FP)
done:
BL runtime·exitsyscall(SB)
RET
TEXT ·syscall_rawsyscall9(SB),NOSPLIT,$0
MOVD a1+8(FP), R1
MOVD a2+16(FP), R2
MOVD a3+24(FP), R3
// Get library control area (LCA).
MOVW PSALAA, R8
MOVD LCA64(R8), R8
// Get function.
MOVD CAA(R8), R9
MOVD EDCHPXV(R9), R9
MOVD trap+0(FP), R5
SLD $4, R5
ADD R5, R9
LMG 0(R9), R5, R6
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R4
MOVD $0, 0(R9)
// Fill in parameter list.
MOVD a4+32(FP), R12
MOVD R12, (2176+24)(R4)
MOVD a5+40(FP), R12
MOVD R12, (2176+32)(R4)
MOVD a6+48(FP), R12
MOVD R12, (2176+40)(R4)
MOVD a7+56(FP), R12
MOVD R12, (2176+48)(R4)
MOVD a8+64(FP), R12
MOVD R12, (2176+56)(R4)
MOVD a9+72(FP), R12
MOVD R12, (2176+64)(R4)
// Call function.
LE_CALL
NOPH
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
MOVD R3, r1+80(FP)
MOVD R0, r2+88(FP)
MOVD R0, err+96(FP)
MOVW R3, R4
CMP R4, $-1
BNE done
BL addrerrno<>(SB)
MOVWZ 0(R3), R3
MOVD R3, err+96(FP)
done:
XOR R0, R0 // Restore R0 to $0.
MOVD R4, 0(R9) // Save stack pointer.
RET
// func svcCall(fnptr unsafe.Pointer, argv *unsafe.Pointer, dsa *uint64)
TEXT ·svcCall(SB),NOSPLIT,$0
BL runtime·save_g(SB) // Save g and stack pointer
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVD SAVSTACK_ASYNC(R8), R9
MOVD R15, 0(R9)
TEXT ·svcCall(SB), NOSPLIT, $0
BL runtime·save_g(SB) // Save g and stack pointer
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVD SAVSTACK_ASYNC(R8), R9
MOVD R15, 0(R9)
MOVD argv+8(FP), R1 // Move function arguments into registers
MOVD dsa+16(FP), g
MOVD fnptr+0(FP), R15
MOVD argv+8(FP), R1 // Move function arguments into registers
MOVD dsa+16(FP), g
MOVD fnptr+0(FP), R15
BYTE $0x0D // Branch to function
BYTE $0xEF
BYTE $0x0D // Branch to function
BYTE $0xEF
BL runtime·load_g(SB) // Restore g and stack pointer
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R15
BL runtime·load_g(SB) // Restore g and stack pointer
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVD SAVSTACK_ASYNC(R8), R9
MOVD 0(R9), R15
RET
// func svcLoad(name *byte) unsafe.Pointer
TEXT ·svcLoad(SB),NOSPLIT,$0
MOVD R15, R2 // Save go stack pointer
MOVD name+0(FP), R0 // Move SVC args into registers
MOVD $0x80000000, R1
MOVD $0, R15
BYTE $0x0A // SVC 08 LOAD
BYTE $0x08
MOVW R15, R3 // Save return code from SVC
MOVD R2, R15 // Restore go stack pointer
CMP R3, $0 // Check SVC return code
BNE error
TEXT ·svcLoad(SB), NOSPLIT, $0
MOVD R15, R2 // Save go stack pointer
MOVD name+0(FP), R0 // Move SVC args into registers
MOVD $0x80000000, R1
MOVD $0, R15
SVC_LOAD
MOVW R15, R3 // Save return code from SVC
MOVD R2, R15 // Restore go stack pointer
CMP R3, $0 // Check SVC return code
BNE error
MOVD $-2, R3 // Reset last bit of entry point to zero
AND R0, R3
MOVD R3, addr+8(FP) // Return entry point returned by SVC
CMP R0, R3 // Check if last bit of entry point was set
BNE done
MOVD $-2, R3 // Reset last bit of entry point to zero
AND R0, R3
MOVD R3, ret+8(FP) // Return entry point returned by SVC
CMP R0, R3 // Check if last bit of entry point was set
BNE done
MOVD R15, R2 // Save go stack pointer
MOVD $0, R15 // Move SVC args into registers (entry point still in r0 from SVC 08)
BYTE $0x0A // SVC 09 DELETE
BYTE $0x09
MOVD R2, R15 // Restore go stack pointer
MOVD R15, R2 // Save go stack pointer
MOVD $0, R15 // Move SVC args into registers (entry point still in r0 from SVC 08)
SVC_DELETE
MOVD R2, R15 // Restore go stack pointer
error:
MOVD $0, addr+8(FP) // Return 0 on failure
MOVD $0, ret+8(FP) // Return 0 on failure
done:
XOR R0, R0 // Reset r0 to 0
XOR R0, R0 // Reset r0 to 0
RET
// func svcUnload(name *byte, fnptr unsafe.Pointer) int64
TEXT ·svcUnload(SB),NOSPLIT,$0
MOVD R15, R2 // Save go stack pointer
MOVD name+0(FP), R0 // Move SVC args into registers
MOVD addr+8(FP), R15
BYTE $0x0A // SVC 09
BYTE $0x09
XOR R0, R0 // Reset r0 to 0
MOVD R15, R1 // Save SVC return code
MOVD R2, R15 // Restore go stack pointer
MOVD R1, rc+0(FP) // Return SVC return code
TEXT ·svcUnload(SB), NOSPLIT, $0
MOVD R15, R2 // Save go stack pointer
MOVD name+0(FP), R0 // Move SVC args into registers
MOVD fnptr+8(FP), R15
SVC_DELETE
XOR R0, R0 // Reset r0 to 0
MOVD R15, R1 // Save SVC return code
MOVD R2, R15 // Restore go stack pointer
MOVD R1, ret+16(FP) // Return SVC return code
RET
// func gettid() uint64
@@ -417,7 +150,233 @@ TEXT ·gettid(SB), NOSPLIT, $0
// Get CEECAATHDID
MOVD CAA(R8), R9
MOVD 0x3D0(R9), R9
MOVD CEECAATHDID(R9), R9
MOVD R9, ret+0(FP)
RET
//
// Call LE function, if the return is -1
// errno and errno2 is retrieved
//
TEXT ·CallLeFuncWithErr(SB), NOSPLIT, $0
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVD CAA(R8), R9
MOVD g, GOCB(R9)
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9 // R9-> LE stack frame saving address
MOVD 0(R9), R4 // R4-> restore previously saved stack frame pointer
MOVD parms_base+8(FP), R7 // R7 -> argument array
MOVD parms_len+16(FP), R8 // R8 number of arguments
// arg 1 ---> R1
CMP R8, $0
BEQ docall
SUB $1, R8
MOVD 0(R7), R1
// arg 2 ---> R2
CMP R8, $0
BEQ docall
SUB $1, R8
ADD $8, R7
MOVD 0(R7), R2
// arg 3 --> R3
CMP R8, $0
BEQ docall
SUB $1, R8
ADD $8, R7
MOVD 0(R7), R3
CMP R8, $0
BEQ docall
MOVD $2176+16, R6 // starting LE stack address-8 to store 4th argument
repeat:
ADD $8, R7
MOVD 0(R7), R0 // advance arg pointer by 8 byte
ADD $8, R6 // advance LE argument address by 8 byte
MOVD R0, (R4)(R6*1) // copy argument from go-slice to le-frame
SUB $1, R8
CMP R8, $0
BNE repeat
docall:
MOVD funcdesc+0(FP), R8 // R8-> function descriptor
LMG 0(R8), R5, R6
MOVD $0, 0(R9) // R9 address of SAVSTACK_ASYNC
LE_CALL // balr R7, R6 (return #1)
NOPH
MOVD R3, ret+32(FP)
CMP R3, $-1 // compare result to -1
BNE done
// retrieve errno and errno2
MOVD zosLibVec<>(SB), R8
ADD $(__errno), R8
LMG 0(R8), R5, R6
LE_CALL // balr R7, R6 __errno (return #3)
NOPH
MOVWZ 0(R3), R3
MOVD R3, err+48(FP)
MOVD zosLibVec<>(SB), R8
ADD $(__err2ad), R8
LMG 0(R8), R5, R6
LE_CALL // balr R7, R6 __err2ad (return #2)
NOPH
MOVW (R3), R2 // retrieve errno2
MOVD R2, errno2+40(FP) // store in return area
done:
MOVD R4, 0(R9) // Save stack pointer.
RET
//
// Call LE function, if the return is 0
// errno and errno2 is retrieved
//
TEXT ·CallLeFuncWithPtrReturn(SB), NOSPLIT, $0
MOVW PSALAA, R8
MOVD LCA64(R8), R8
MOVD CAA(R8), R9
MOVD g, GOCB(R9)
// Restore LE stack.
MOVD SAVSTACK_ASYNC(R8), R9 // R9-> LE stack frame saving address
MOVD 0(R9), R4 // R4-> restore previously saved stack frame pointer
MOVD parms_base+8(FP), R7 // R7 -> argument array
MOVD parms_len+16(FP), R8 // R8 number of arguments
// arg 1 ---> R1
CMP R8, $0
BEQ docall
SUB $1, R8
MOVD 0(R7), R1
// arg 2 ---> R2
CMP R8, $0
BEQ docall
SUB $1, R8
ADD $8, R7
MOVD 0(R7), R2
// arg 3 --> R3
CMP R8, $0
BEQ docall
SUB $1, R8
ADD $8, R7
MOVD 0(R7), R3
CMP R8, $0
BEQ docall
MOVD $2176+16, R6 // starting LE stack address-8 to store 4th argument
repeat:
ADD $8, R7
MOVD 0(R7), R0 // advance arg pointer by 8 byte
ADD $8, R6 // advance LE argument address by 8 byte
MOVD R0, (R4)(R6*1) // copy argument from go-slice to le-frame
SUB $1, R8
CMP R8, $0
BNE repeat
docall:
MOVD funcdesc+0(FP), R8 // R8-> function descriptor
LMG 0(R8), R5, R6
MOVD $0, 0(R9) // R9 address of SAVSTACK_ASYNC
LE_CALL // balr R7, R6 (return #1)
NOPH
MOVD R3, ret+32(FP)
CMP R3, $0 // compare result to 0
BNE done
// retrieve errno and errno2
MOVD zosLibVec<>(SB), R8
ADD $(__errno), R8
LMG 0(R8), R5, R6
LE_CALL // balr R7, R6 __errno (return #3)
NOPH
MOVWZ 0(R3), R3
MOVD R3, err+48(FP)
MOVD zosLibVec<>(SB), R8
ADD $(__err2ad), R8
LMG 0(R8), R5, R6
LE_CALL // balr R7, R6 __err2ad (return #2)
NOPH
MOVW (R3), R2 // retrieve errno2
MOVD R2, errno2+40(FP) // store in return area
XOR R2, R2
MOVWZ R2, (R3) // clear errno2
done:
MOVD R4, 0(R9) // Save stack pointer.
RET
//
// function to test if a pointer can be safely dereferenced (content read)
// return 0 for succces
//
TEXT ·ptrtest(SB), NOSPLIT, $0-16
MOVD arg+0(FP), R10 // test pointer in R10
// set up R2 to point to CEECAADMC
BYTE $0xE3; BYTE $0x20; BYTE $0x04; BYTE $0xB8; BYTE $0x00; BYTE $0x17 // llgt 2,1208
BYTE $0xB9; BYTE $0x17; BYTE $0x00; BYTE $0x22 // llgtr 2,2
BYTE $0xA5; BYTE $0x26; BYTE $0x7F; BYTE $0xFF // nilh 2,32767
BYTE $0xE3; BYTE $0x22; BYTE $0x00; BYTE $0x58; BYTE $0x00; BYTE $0x04 // lg 2,88(2)
BYTE $0xE3; BYTE $0x22; BYTE $0x00; BYTE $0x08; BYTE $0x00; BYTE $0x04 // lg 2,8(2)
BYTE $0x41; BYTE $0x22; BYTE $0x03; BYTE $0x68 // la 2,872(2)
// set up R5 to point to the "shunt" path which set 1 to R3 (failure)
BYTE $0xB9; BYTE $0x82; BYTE $0x00; BYTE $0x33 // xgr 3,3
BYTE $0xA7; BYTE $0x55; BYTE $0x00; BYTE $0x04 // bras 5,lbl1
BYTE $0xA7; BYTE $0x39; BYTE $0x00; BYTE $0x01 // lghi 3,1
// if r3 is not zero (failed) then branch to finish
BYTE $0xB9; BYTE $0x02; BYTE $0x00; BYTE $0x33 // lbl1 ltgr 3,3
BYTE $0xA7; BYTE $0x74; BYTE $0x00; BYTE $0x08 // brc b'0111',lbl2
// stomic store shunt address in R5 into CEECAADMC
BYTE $0xE3; BYTE $0x52; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x24 // stg 5,0(2)
// now try reading from the test pointer in R10, if it fails it branches to the "lghi" instruction above
BYTE $0xE3; BYTE $0x9A; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x04 // lg 9,0(10)
// finish here, restore 0 into CEECAADMC
BYTE $0xB9; BYTE $0x82; BYTE $0x00; BYTE $0x99 // lbl2 xgr 9,9
BYTE $0xE3; BYTE $0x92; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x24 // stg 9,0(2)
MOVD R3, ret+8(FP) // result in R3
RET
//
// function to test if a untptr can be loaded from a pointer
// return 1: the 8-byte content
// 2: 0 for success, 1 for failure
//
// func safeload(ptr uintptr) ( value uintptr, error uintptr)
TEXT ·safeload(SB), NOSPLIT, $0-24
MOVD ptr+0(FP), R10 // test pointer in R10
MOVD $0x0, R6
BYTE $0xE3; BYTE $0x20; BYTE $0x04; BYTE $0xB8; BYTE $0x00; BYTE $0x17 // llgt 2,1208
BYTE $0xB9; BYTE $0x17; BYTE $0x00; BYTE $0x22 // llgtr 2,2
BYTE $0xA5; BYTE $0x26; BYTE $0x7F; BYTE $0xFF // nilh 2,32767
BYTE $0xE3; BYTE $0x22; BYTE $0x00; BYTE $0x58; BYTE $0x00; BYTE $0x04 // lg 2,88(2)
BYTE $0xE3; BYTE $0x22; BYTE $0x00; BYTE $0x08; BYTE $0x00; BYTE $0x04 // lg 2,8(2)
BYTE $0x41; BYTE $0x22; BYTE $0x03; BYTE $0x68 // la 2,872(2)
BYTE $0xB9; BYTE $0x82; BYTE $0x00; BYTE $0x33 // xgr 3,3
BYTE $0xA7; BYTE $0x55; BYTE $0x00; BYTE $0x04 // bras 5,lbl1
BYTE $0xA7; BYTE $0x39; BYTE $0x00; BYTE $0x01 // lghi 3,1
BYTE $0xB9; BYTE $0x02; BYTE $0x00; BYTE $0x33 // lbl1 ltgr 3,3
BYTE $0xA7; BYTE $0x74; BYTE $0x00; BYTE $0x08 // brc b'0111',lbl2
BYTE $0xE3; BYTE $0x52; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x24 // stg 5,0(2)
BYTE $0xE3; BYTE $0x6A; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x04 // lg 6,0(10)
BYTE $0xB9; BYTE $0x82; BYTE $0x00; BYTE $0x99 // lbl2 xgr 9,9
BYTE $0xE3; BYTE $0x92; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x24 // stg 9,0(2)
MOVD R6, value+8(FP) // result in R6
MOVD R3, error+16(FP) // error in R3
RET

657
vendor/golang.org/x/sys/unix/bpxsvc_zos.go generated vendored Normal file
View File

@@ -0,0 +1,657 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build zos
package unix
import (
"bytes"
"fmt"
"unsafe"
)
//go:noescape
func bpxcall(plist []unsafe.Pointer, bpx_offset int64)
//go:noescape
func A2e([]byte)
//go:noescape
func E2a([]byte)
const (
BPX4STA = 192 // stat
BPX4FST = 104 // fstat
BPX4LST = 132 // lstat
BPX4OPN = 156 // open
BPX4CLO = 72 // close
BPX4CHR = 500 // chattr
BPX4FCR = 504 // fchattr
BPX4LCR = 1180 // lchattr
BPX4CTW = 492 // cond_timed_wait
BPX4GTH = 1056 // __getthent
BPX4PTQ = 412 // pthread_quiesc
BPX4PTR = 320 // ptrace
)
const (
//options
//byte1
BPX_OPNFHIGH = 0x80
//byte2
BPX_OPNFEXEC = 0x80
//byte3
BPX_O_NOLARGEFILE = 0x08
BPX_O_LARGEFILE = 0x04
BPX_O_ASYNCSIG = 0x02
BPX_O_SYNC = 0x01
//byte4
BPX_O_CREXCL = 0xc0
BPX_O_CREAT = 0x80
BPX_O_EXCL = 0x40
BPX_O_NOCTTY = 0x20
BPX_O_TRUNC = 0x10
BPX_O_APPEND = 0x08
BPX_O_NONBLOCK = 0x04
BPX_FNDELAY = 0x04
BPX_O_RDWR = 0x03
BPX_O_RDONLY = 0x02
BPX_O_WRONLY = 0x01
BPX_O_ACCMODE = 0x03
BPX_O_GETFL = 0x0f
//mode
// byte1 (file type)
BPX_FT_DIR = 1
BPX_FT_CHARSPEC = 2
BPX_FT_REGFILE = 3
BPX_FT_FIFO = 4
BPX_FT_SYMLINK = 5
BPX_FT_SOCKET = 6
//byte3
BPX_S_ISUID = 0x08
BPX_S_ISGID = 0x04
BPX_S_ISVTX = 0x02
BPX_S_IRWXU1 = 0x01
BPX_S_IRUSR = 0x01
//byte4
BPX_S_IRWXU2 = 0xc0
BPX_S_IWUSR = 0x80
BPX_S_IXUSR = 0x40
BPX_S_IRWXG = 0x38
BPX_S_IRGRP = 0x20
BPX_S_IWGRP = 0x10
BPX_S_IXGRP = 0x08
BPX_S_IRWXOX = 0x07
BPX_S_IROTH = 0x04
BPX_S_IWOTH = 0x02
BPX_S_IXOTH = 0x01
CW_INTRPT = 1
CW_CONDVAR = 32
CW_TIMEOUT = 64
PGTHA_NEXT = 2
PGTHA_CURRENT = 1
PGTHA_FIRST = 0
PGTHA_LAST = 3
PGTHA_PROCESS = 0x80
PGTHA_CONTTY = 0x40
PGTHA_PATH = 0x20
PGTHA_COMMAND = 0x10
PGTHA_FILEDATA = 0x08
PGTHA_THREAD = 0x04
PGTHA_PTAG = 0x02
PGTHA_COMMANDLONG = 0x01
PGTHA_THREADFAST = 0x80
PGTHA_FILEPATH = 0x40
PGTHA_THDSIGMASK = 0x20
// thread quiece mode
QUIESCE_TERM int32 = 1
QUIESCE_FORCE int32 = 2
QUIESCE_QUERY int32 = 3
QUIESCE_FREEZE int32 = 4
QUIESCE_UNFREEZE int32 = 5
FREEZE_THIS_THREAD int32 = 6
FREEZE_EXIT int32 = 8
QUIESCE_SRB int32 = 9
)
type Pgtha struct {
Pid uint32 // 0
Tid0 uint32 // 4
Tid1 uint32
Accesspid byte // C
Accesstid byte // D
Accessasid uint16 // E
Loginname [8]byte // 10
Flag1 byte // 18
Flag1b2 byte // 19
}
type Bpxystat_t struct { // DSECT BPXYSTAT
St_id [4]uint8 // 0
St_length uint16 // 0x4
St_version uint16 // 0x6
St_mode uint32 // 0x8
St_ino uint32 // 0xc
St_dev uint32 // 0x10
St_nlink uint32 // 0x14
St_uid uint32 // 0x18
St_gid uint32 // 0x1c
St_size uint64 // 0x20
St_atime uint32 // 0x28
St_mtime uint32 // 0x2c
St_ctime uint32 // 0x30
St_rdev uint32 // 0x34
St_auditoraudit uint32 // 0x38
St_useraudit uint32 // 0x3c
St_blksize uint32 // 0x40
St_createtime uint32 // 0x44
St_auditid [4]uint32 // 0x48
St_res01 uint32 // 0x58
Ft_ccsid uint16 // 0x5c
Ft_flags uint16 // 0x5e
St_res01a [2]uint32 // 0x60
St_res02 uint32 // 0x68
St_blocks uint32 // 0x6c
St_opaque [3]uint8 // 0x70
St_visible uint8 // 0x73
St_reftime uint32 // 0x74
St_fid uint64 // 0x78
St_filefmt uint8 // 0x80
St_fspflag2 uint8 // 0x81
St_res03 [2]uint8 // 0x82
St_ctimemsec uint32 // 0x84
St_seclabel [8]uint8 // 0x88
St_res04 [4]uint8 // 0x90
// end of version 1
_ uint32 // 0x94
St_atime64 uint64 // 0x98
St_mtime64 uint64 // 0xa0
St_ctime64 uint64 // 0xa8
St_createtime64 uint64 // 0xb0
St_reftime64 uint64 // 0xb8
_ uint64 // 0xc0
St_res05 [16]uint8 // 0xc8
// end of version 2
}
type BpxFilestatus struct {
Oflag1 byte
Oflag2 byte
Oflag3 byte
Oflag4 byte
}
type BpxMode struct {
Ftype byte
Mode1 byte
Mode2 byte
Mode3 byte
}
// Thr attribute structure for extended attributes
type Bpxyatt_t struct { // DSECT BPXYATT
Att_id [4]uint8
Att_version uint16
Att_res01 [2]uint8
Att_setflags1 uint8
Att_setflags2 uint8
Att_setflags3 uint8
Att_setflags4 uint8
Att_mode uint32
Att_uid uint32
Att_gid uint32
Att_opaquemask [3]uint8
Att_visblmaskres uint8
Att_opaque [3]uint8
Att_visibleres uint8
Att_size_h uint32
Att_size_l uint32
Att_atime uint32
Att_mtime uint32
Att_auditoraudit uint32
Att_useraudit uint32
Att_ctime uint32
Att_reftime uint32
// end of version 1
Att_filefmt uint8
Att_res02 [3]uint8
Att_filetag uint32
Att_res03 [8]uint8
// end of version 2
Att_atime64 uint64
Att_mtime64 uint64
Att_ctime64 uint64
Att_reftime64 uint64
Att_seclabel [8]uint8
Att_ver3res02 [8]uint8
// end of version 3
}
func BpxOpen(name string, options *BpxFilestatus, mode *BpxMode) (rv int32, rc int32, rn int32) {
if len(name) < 1024 {
var namebuf [1024]byte
sz := int32(copy(namebuf[:], name))
A2e(namebuf[:sz])
var parms [7]unsafe.Pointer
parms[0] = unsafe.Pointer(&sz)
parms[1] = unsafe.Pointer(&namebuf[0])
parms[2] = unsafe.Pointer(options)
parms[3] = unsafe.Pointer(mode)
parms[4] = unsafe.Pointer(&rv)
parms[5] = unsafe.Pointer(&rc)
parms[6] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4OPN)
return rv, rc, rn
}
return -1, -1, -1
}
func BpxClose(fd int32) (rv int32, rc int32, rn int32) {
var parms [4]unsafe.Pointer
parms[0] = unsafe.Pointer(&fd)
parms[1] = unsafe.Pointer(&rv)
parms[2] = unsafe.Pointer(&rc)
parms[3] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4CLO)
return rv, rc, rn
}
func BpxFileFStat(fd int32, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
st.St_version = 2
stat_sz := uint32(unsafe.Sizeof(*st))
var parms [6]unsafe.Pointer
parms[0] = unsafe.Pointer(&fd)
parms[1] = unsafe.Pointer(&stat_sz)
parms[2] = unsafe.Pointer(st)
parms[3] = unsafe.Pointer(&rv)
parms[4] = unsafe.Pointer(&rc)
parms[5] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4FST)
return rv, rc, rn
}
func BpxFileStat(name string, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
if len(name) < 1024 {
var namebuf [1024]byte
sz := int32(copy(namebuf[:], name))
A2e(namebuf[:sz])
st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
st.St_version = 2
stat_sz := uint32(unsafe.Sizeof(*st))
var parms [7]unsafe.Pointer
parms[0] = unsafe.Pointer(&sz)
parms[1] = unsafe.Pointer(&namebuf[0])
parms[2] = unsafe.Pointer(&stat_sz)
parms[3] = unsafe.Pointer(st)
parms[4] = unsafe.Pointer(&rv)
parms[5] = unsafe.Pointer(&rc)
parms[6] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4STA)
return rv, rc, rn
}
return -1, -1, -1
}
func BpxFileLStat(name string, st *Bpxystat_t) (rv int32, rc int32, rn int32) {
if len(name) < 1024 {
var namebuf [1024]byte
sz := int32(copy(namebuf[:], name))
A2e(namebuf[:sz])
st.St_id = [4]uint8{0xe2, 0xe3, 0xc1, 0xe3}
st.St_version = 2
stat_sz := uint32(unsafe.Sizeof(*st))
var parms [7]unsafe.Pointer
parms[0] = unsafe.Pointer(&sz)
parms[1] = unsafe.Pointer(&namebuf[0])
parms[2] = unsafe.Pointer(&stat_sz)
parms[3] = unsafe.Pointer(st)
parms[4] = unsafe.Pointer(&rv)
parms[5] = unsafe.Pointer(&rc)
parms[6] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4LST)
return rv, rc, rn
}
return -1, -1, -1
}
func BpxChattr(path string, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
if len(path) >= 1024 {
return -1, -1, -1
}
var namebuf [1024]byte
sz := int32(copy(namebuf[:], path))
A2e(namebuf[:sz])
attr_sz := uint32(unsafe.Sizeof(*attr))
var parms [7]unsafe.Pointer
parms[0] = unsafe.Pointer(&sz)
parms[1] = unsafe.Pointer(&namebuf[0])
parms[2] = unsafe.Pointer(&attr_sz)
parms[3] = unsafe.Pointer(attr)
parms[4] = unsafe.Pointer(&rv)
parms[5] = unsafe.Pointer(&rc)
parms[6] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4CHR)
return rv, rc, rn
}
func BpxLchattr(path string, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
if len(path) >= 1024 {
return -1, -1, -1
}
var namebuf [1024]byte
sz := int32(copy(namebuf[:], path))
A2e(namebuf[:sz])
attr_sz := uint32(unsafe.Sizeof(*attr))
var parms [7]unsafe.Pointer
parms[0] = unsafe.Pointer(&sz)
parms[1] = unsafe.Pointer(&namebuf[0])
parms[2] = unsafe.Pointer(&attr_sz)
parms[3] = unsafe.Pointer(attr)
parms[4] = unsafe.Pointer(&rv)
parms[5] = unsafe.Pointer(&rc)
parms[6] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4LCR)
return rv, rc, rn
}
func BpxFchattr(fd int32, attr *Bpxyatt_t) (rv int32, rc int32, rn int32) {
attr_sz := uint32(unsafe.Sizeof(*attr))
var parms [6]unsafe.Pointer
parms[0] = unsafe.Pointer(&fd)
parms[1] = unsafe.Pointer(&attr_sz)
parms[2] = unsafe.Pointer(attr)
parms[3] = unsafe.Pointer(&rv)
parms[4] = unsafe.Pointer(&rc)
parms[5] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4FCR)
return rv, rc, rn
}
func BpxCondTimedWait(sec uint32, nsec uint32, events uint32, secrem *uint32, nsecrem *uint32) (rv int32, rc int32, rn int32) {
var parms [8]unsafe.Pointer
parms[0] = unsafe.Pointer(&sec)
parms[1] = unsafe.Pointer(&nsec)
parms[2] = unsafe.Pointer(&events)
parms[3] = unsafe.Pointer(secrem)
parms[4] = unsafe.Pointer(nsecrem)
parms[5] = unsafe.Pointer(&rv)
parms[6] = unsafe.Pointer(&rc)
parms[7] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4CTW)
return rv, rc, rn
}
func BpxGetthent(in *Pgtha, outlen *uint32, out unsafe.Pointer) (rv int32, rc int32, rn int32) {
var parms [7]unsafe.Pointer
inlen := uint32(26) // nothing else will work. Go says Pgtha is 28-byte because of alignment, but Pgtha is "packed" and must be 26-byte
parms[0] = unsafe.Pointer(&inlen)
parms[1] = unsafe.Pointer(&in)
parms[2] = unsafe.Pointer(outlen)
parms[3] = unsafe.Pointer(&out)
parms[4] = unsafe.Pointer(&rv)
parms[5] = unsafe.Pointer(&rc)
parms[6] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4GTH)
return rv, rc, rn
}
func ZosJobname() (jobname string, err error) {
var pgtha Pgtha
pgtha.Pid = uint32(Getpid())
pgtha.Accesspid = PGTHA_CURRENT
pgtha.Flag1 = PGTHA_PROCESS
var out [256]byte
var outlen uint32
outlen = 256
rv, rc, rn := BpxGetthent(&pgtha, &outlen, unsafe.Pointer(&out[0]))
if rv == 0 {
gthc := []byte{0x87, 0xa3, 0x88, 0x83} // 'gthc' in ebcdic
ix := bytes.Index(out[:], gthc)
if ix == -1 {
err = fmt.Errorf("BPX4GTH: gthc return data not found")
return
}
jn := out[ix+80 : ix+88] // we didn't declare Pgthc, but jobname is 8-byte at offset 80
E2a(jn)
jobname = string(bytes.TrimRight(jn, " "))
} else {
err = fmt.Errorf("BPX4GTH: rc=%d errno=%d reason=code=0x%x", rv, rc, rn)
}
return
}
func Bpx4ptq(code int32, data string) (rv int32, rc int32, rn int32) {
var userdata [8]byte
var parms [5]unsafe.Pointer
copy(userdata[:], data+" ")
A2e(userdata[:])
parms[0] = unsafe.Pointer(&code)
parms[1] = unsafe.Pointer(&userdata[0])
parms[2] = unsafe.Pointer(&rv)
parms[3] = unsafe.Pointer(&rc)
parms[4] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4PTQ)
return rv, rc, rn
}
const (
PT_TRACE_ME = 0 // Debug this process
PT_READ_I = 1 // Read a full word
PT_READ_D = 2 // Read a full word
PT_READ_U = 3 // Read control info
PT_WRITE_I = 4 //Write a full word
PT_WRITE_D = 5 //Write a full word
PT_CONTINUE = 7 //Continue the process
PT_KILL = 8 //Terminate the process
PT_READ_GPR = 11 // Read GPR, CR, PSW
PT_READ_FPR = 12 // Read FPR
PT_READ_VR = 13 // Read VR
PT_WRITE_GPR = 14 // Write GPR, CR, PSW
PT_WRITE_FPR = 15 // Write FPR
PT_WRITE_VR = 16 // Write VR
PT_READ_BLOCK = 17 // Read storage
PT_WRITE_BLOCK = 19 // Write storage
PT_READ_GPRH = 20 // Read GPRH
PT_WRITE_GPRH = 21 // Write GPRH
PT_REGHSET = 22 // Read all GPRHs
PT_ATTACH = 30 // Attach to a process
PT_DETACH = 31 // Detach from a process
PT_REGSET = 32 // Read all GPRs
PT_REATTACH = 33 // Reattach to a process
PT_LDINFO = 34 // Read loader info
PT_MULTI = 35 // Multi process mode
PT_LD64INFO = 36 // RMODE64 Info Area
PT_BLOCKREQ = 40 // Block request
PT_THREAD_INFO = 60 // Read thread info
PT_THREAD_MODIFY = 61
PT_THREAD_READ_FOCUS = 62
PT_THREAD_WRITE_FOCUS = 63
PT_THREAD_HOLD = 64
PT_THREAD_SIGNAL = 65
PT_EXPLAIN = 66
PT_EVENTS = 67
PT_THREAD_INFO_EXTENDED = 68
PT_REATTACH2 = 71
PT_CAPTURE = 72
PT_UNCAPTURE = 73
PT_GET_THREAD_TCB = 74
PT_GET_ALET = 75
PT_SWAPIN = 76
PT_EXTENDED_EVENT = 98
PT_RECOVER = 99 // Debug a program check
PT_GPR0 = 0 // General purpose register 0
PT_GPR1 = 1 // General purpose register 1
PT_GPR2 = 2 // General purpose register 2
PT_GPR3 = 3 // General purpose register 3
PT_GPR4 = 4 // General purpose register 4
PT_GPR5 = 5 // General purpose register 5
PT_GPR6 = 6 // General purpose register 6
PT_GPR7 = 7 // General purpose register 7
PT_GPR8 = 8 // General purpose register 8
PT_GPR9 = 9 // General purpose register 9
PT_GPR10 = 10 // General purpose register 10
PT_GPR11 = 11 // General purpose register 11
PT_GPR12 = 12 // General purpose register 12
PT_GPR13 = 13 // General purpose register 13
PT_GPR14 = 14 // General purpose register 14
PT_GPR15 = 15 // General purpose register 15
PT_FPR0 = 16 // Floating point register 0
PT_FPR1 = 17 // Floating point register 1
PT_FPR2 = 18 // Floating point register 2
PT_FPR3 = 19 // Floating point register 3
PT_FPR4 = 20 // Floating point register 4
PT_FPR5 = 21 // Floating point register 5
PT_FPR6 = 22 // Floating point register 6
PT_FPR7 = 23 // Floating point register 7
PT_FPR8 = 24 // Floating point register 8
PT_FPR9 = 25 // Floating point register 9
PT_FPR10 = 26 // Floating point register 10
PT_FPR11 = 27 // Floating point register 11
PT_FPR12 = 28 // Floating point register 12
PT_FPR13 = 29 // Floating point register 13
PT_FPR14 = 30 // Floating point register 14
PT_FPR15 = 31 // Floating point register 15
PT_FPC = 32 // Floating point control register
PT_PSW = 40 // PSW
PT_PSW0 = 40 // Left half of the PSW
PT_PSW1 = 41 // Right half of the PSW
PT_CR0 = 42 // Control register 0
PT_CR1 = 43 // Control register 1
PT_CR2 = 44 // Control register 2
PT_CR3 = 45 // Control register 3
PT_CR4 = 46 // Control register 4
PT_CR5 = 47 // Control register 5
PT_CR6 = 48 // Control register 6
PT_CR7 = 49 // Control register 7
PT_CR8 = 50 // Control register 8
PT_CR9 = 51 // Control register 9
PT_CR10 = 52 // Control register 10
PT_CR11 = 53 // Control register 11
PT_CR12 = 54 // Control register 12
PT_CR13 = 55 // Control register 13
PT_CR14 = 56 // Control register 14
PT_CR15 = 57 // Control register 15
PT_GPRH0 = 58 // GP High register 0
PT_GPRH1 = 59 // GP High register 1
PT_GPRH2 = 60 // GP High register 2
PT_GPRH3 = 61 // GP High register 3
PT_GPRH4 = 62 // GP High register 4
PT_GPRH5 = 63 // GP High register 5
PT_GPRH6 = 64 // GP High register 6
PT_GPRH7 = 65 // GP High register 7
PT_GPRH8 = 66 // GP High register 8
PT_GPRH9 = 67 // GP High register 9
PT_GPRH10 = 68 // GP High register 10
PT_GPRH11 = 69 // GP High register 11
PT_GPRH12 = 70 // GP High register 12
PT_GPRH13 = 71 // GP High register 13
PT_GPRH14 = 72 // GP High register 14
PT_GPRH15 = 73 // GP High register 15
PT_VR0 = 74 // Vector register 0
PT_VR1 = 75 // Vector register 1
PT_VR2 = 76 // Vector register 2
PT_VR3 = 77 // Vector register 3
PT_VR4 = 78 // Vector register 4
PT_VR5 = 79 // Vector register 5
PT_VR6 = 80 // Vector register 6
PT_VR7 = 81 // Vector register 7
PT_VR8 = 82 // Vector register 8
PT_VR9 = 83 // Vector register 9
PT_VR10 = 84 // Vector register 10
PT_VR11 = 85 // Vector register 11
PT_VR12 = 86 // Vector register 12
PT_VR13 = 87 // Vector register 13
PT_VR14 = 88 // Vector register 14
PT_VR15 = 89 // Vector register 15
PT_VR16 = 90 // Vector register 16
PT_VR17 = 91 // Vector register 17
PT_VR18 = 92 // Vector register 18
PT_VR19 = 93 // Vector register 19
PT_VR20 = 94 // Vector register 20
PT_VR21 = 95 // Vector register 21
PT_VR22 = 96 // Vector register 22
PT_VR23 = 97 // Vector register 23
PT_VR24 = 98 // Vector register 24
PT_VR25 = 99 // Vector register 25
PT_VR26 = 100 // Vector register 26
PT_VR27 = 101 // Vector register 27
PT_VR28 = 102 // Vector register 28
PT_VR29 = 103 // Vector register 29
PT_VR30 = 104 // Vector register 30
PT_VR31 = 105 // Vector register 31
PT_PSWG = 106 // PSWG
PT_PSWG0 = 106 // Bytes 0-3
PT_PSWG1 = 107 // Bytes 4-7
PT_PSWG2 = 108 // Bytes 8-11 (IA high word)
PT_PSWG3 = 109 // Bytes 12-15 (IA low word)
)
func Bpx4ptr(request int32, pid int32, addr unsafe.Pointer, data unsafe.Pointer, buffer unsafe.Pointer) (rv int32, rc int32, rn int32) {
var parms [8]unsafe.Pointer
parms[0] = unsafe.Pointer(&request)
parms[1] = unsafe.Pointer(&pid)
parms[2] = unsafe.Pointer(&addr)
parms[3] = unsafe.Pointer(&data)
parms[4] = unsafe.Pointer(&buffer)
parms[5] = unsafe.Pointer(&rv)
parms[6] = unsafe.Pointer(&rc)
parms[7] = unsafe.Pointer(&rn)
bpxcall(parms[:], BPX4PTR)
return rv, rc, rn
}
func copyU8(val uint8, dest []uint8) int {
if len(dest) < 1 {
return 0
}
dest[0] = val
return 1
}
func copyU8Arr(src, dest []uint8) int {
if len(dest) < len(src) {
return 0
}
for i, v := range src {
dest[i] = v
}
return len(src)
}
func copyU16(val uint16, dest []uint16) int {
if len(dest) < 1 {
return 0
}
dest[0] = val
return 1
}
func copyU32(val uint32, dest []uint32) int {
if len(dest) < 1 {
return 0
}
dest[0] = val
return 1
}
func copyU32Arr(src, dest []uint32) int {
if len(dest) < len(src) {
return 0
}
for i, v := range src {
dest[i] = v
}
return len(src)
}
func copyU64(val uint64, dest []uint64) int {
if len(dest) < 1 {
return 0
}
dest[0] = val
return 1
}

192
vendor/golang.org/x/sys/unix/bpxsvc_zos.s generated vendored Normal file
View File

@@ -0,0 +1,192 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "go_asm.h"
#include "textflag.h"
// function to call USS assembly language services
//
// doc: https://www.ibm.com/support/knowledgecenter/en/SSLTBW_3.1.0/com.ibm.zos.v3r1.bpxb100/bit64env.htm
//
// arg1 unsafe.Pointer array that ressembles an OS PLIST
//
// arg2 function offset as in
// doc: https://www.ibm.com/support/knowledgecenter/en/SSLTBW_3.1.0/com.ibm.zos.v3r1.bpxb100/bpx2cr_List_of_offsets.htm
//
// func bpxcall(plist []unsafe.Pointer, bpx_offset int64)
TEXT ·bpxcall(SB), NOSPLIT|NOFRAME, $0
MOVD plist_base+0(FP), R1 // r1 points to plist
MOVD bpx_offset+24(FP), R2 // r2 offset to BPX vector table
MOVD R14, R7 // save r14
MOVD R15, R8 // save r15
MOVWZ 16(R0), R9
MOVWZ 544(R9), R9
MOVWZ 24(R9), R9 // call vector in r9
ADD R2, R9 // add offset to vector table
MOVWZ (R9), R9 // r9 points to entry point
BYTE $0x0D // BL R14,R9 --> basr r14,r9
BYTE $0xE9 // clobbers 0,1,14,15
MOVD R8, R15 // restore 15
JMP R7 // return via saved return address
// func A2e(arr [] byte)
// code page conversion from 819 to 1047
TEXT ·A2e(SB), NOSPLIT|NOFRAME, $0
MOVD arg_base+0(FP), R2 // pointer to arry of characters
MOVD arg_len+8(FP), R3 // count
XOR R0, R0
XOR R1, R1
BYTE $0xA7; BYTE $0x15; BYTE $0x00; BYTE $0x82 // BRAS 1,(2+(256/2))
// ASCII -> EBCDIC conversion table:
BYTE $0x00; BYTE $0x01; BYTE $0x02; BYTE $0x03
BYTE $0x37; BYTE $0x2d; BYTE $0x2e; BYTE $0x2f
BYTE $0x16; BYTE $0x05; BYTE $0x15; BYTE $0x0b
BYTE $0x0c; BYTE $0x0d; BYTE $0x0e; BYTE $0x0f
BYTE $0x10; BYTE $0x11; BYTE $0x12; BYTE $0x13
BYTE $0x3c; BYTE $0x3d; BYTE $0x32; BYTE $0x26
BYTE $0x18; BYTE $0x19; BYTE $0x3f; BYTE $0x27
BYTE $0x1c; BYTE $0x1d; BYTE $0x1e; BYTE $0x1f
BYTE $0x40; BYTE $0x5a; BYTE $0x7f; BYTE $0x7b
BYTE $0x5b; BYTE $0x6c; BYTE $0x50; BYTE $0x7d
BYTE $0x4d; BYTE $0x5d; BYTE $0x5c; BYTE $0x4e
BYTE $0x6b; BYTE $0x60; BYTE $0x4b; BYTE $0x61
BYTE $0xf0; BYTE $0xf1; BYTE $0xf2; BYTE $0xf3
BYTE $0xf4; BYTE $0xf5; BYTE $0xf6; BYTE $0xf7
BYTE $0xf8; BYTE $0xf9; BYTE $0x7a; BYTE $0x5e
BYTE $0x4c; BYTE $0x7e; BYTE $0x6e; BYTE $0x6f
BYTE $0x7c; BYTE $0xc1; BYTE $0xc2; BYTE $0xc3
BYTE $0xc4; BYTE $0xc5; BYTE $0xc6; BYTE $0xc7
BYTE $0xc8; BYTE $0xc9; BYTE $0xd1; BYTE $0xd2
BYTE $0xd3; BYTE $0xd4; BYTE $0xd5; BYTE $0xd6
BYTE $0xd7; BYTE $0xd8; BYTE $0xd9; BYTE $0xe2
BYTE $0xe3; BYTE $0xe4; BYTE $0xe5; BYTE $0xe6
BYTE $0xe7; BYTE $0xe8; BYTE $0xe9; BYTE $0xad
BYTE $0xe0; BYTE $0xbd; BYTE $0x5f; BYTE $0x6d
BYTE $0x79; BYTE $0x81; BYTE $0x82; BYTE $0x83
BYTE $0x84; BYTE $0x85; BYTE $0x86; BYTE $0x87
BYTE $0x88; BYTE $0x89; BYTE $0x91; BYTE $0x92
BYTE $0x93; BYTE $0x94; BYTE $0x95; BYTE $0x96
BYTE $0x97; BYTE $0x98; BYTE $0x99; BYTE $0xa2
BYTE $0xa3; BYTE $0xa4; BYTE $0xa5; BYTE $0xa6
BYTE $0xa7; BYTE $0xa8; BYTE $0xa9; BYTE $0xc0
BYTE $0x4f; BYTE $0xd0; BYTE $0xa1; BYTE $0x07
BYTE $0x20; BYTE $0x21; BYTE $0x22; BYTE $0x23
BYTE $0x24; BYTE $0x25; BYTE $0x06; BYTE $0x17
BYTE $0x28; BYTE $0x29; BYTE $0x2a; BYTE $0x2b
BYTE $0x2c; BYTE $0x09; BYTE $0x0a; BYTE $0x1b
BYTE $0x30; BYTE $0x31; BYTE $0x1a; BYTE $0x33
BYTE $0x34; BYTE $0x35; BYTE $0x36; BYTE $0x08
BYTE $0x38; BYTE $0x39; BYTE $0x3a; BYTE $0x3b
BYTE $0x04; BYTE $0x14; BYTE $0x3e; BYTE $0xff
BYTE $0x41; BYTE $0xaa; BYTE $0x4a; BYTE $0xb1
BYTE $0x9f; BYTE $0xb2; BYTE $0x6a; BYTE $0xb5
BYTE $0xbb; BYTE $0xb4; BYTE $0x9a; BYTE $0x8a
BYTE $0xb0; BYTE $0xca; BYTE $0xaf; BYTE $0xbc
BYTE $0x90; BYTE $0x8f; BYTE $0xea; BYTE $0xfa
BYTE $0xbe; BYTE $0xa0; BYTE $0xb6; BYTE $0xb3
BYTE $0x9d; BYTE $0xda; BYTE $0x9b; BYTE $0x8b
BYTE $0xb7; BYTE $0xb8; BYTE $0xb9; BYTE $0xab
BYTE $0x64; BYTE $0x65; BYTE $0x62; BYTE $0x66
BYTE $0x63; BYTE $0x67; BYTE $0x9e; BYTE $0x68
BYTE $0x74; BYTE $0x71; BYTE $0x72; BYTE $0x73
BYTE $0x78; BYTE $0x75; BYTE $0x76; BYTE $0x77
BYTE $0xac; BYTE $0x69; BYTE $0xed; BYTE $0xee
BYTE $0xeb; BYTE $0xef; BYTE $0xec; BYTE $0xbf
BYTE $0x80; BYTE $0xfd; BYTE $0xfe; BYTE $0xfb
BYTE $0xfc; BYTE $0xba; BYTE $0xae; BYTE $0x59
BYTE $0x44; BYTE $0x45; BYTE $0x42; BYTE $0x46
BYTE $0x43; BYTE $0x47; BYTE $0x9c; BYTE $0x48
BYTE $0x54; BYTE $0x51; BYTE $0x52; BYTE $0x53
BYTE $0x58; BYTE $0x55; BYTE $0x56; BYTE $0x57
BYTE $0x8c; BYTE $0x49; BYTE $0xcd; BYTE $0xce
BYTE $0xcb; BYTE $0xcf; BYTE $0xcc; BYTE $0xe1
BYTE $0x70; BYTE $0xdd; BYTE $0xde; BYTE $0xdb
BYTE $0xdc; BYTE $0x8d; BYTE $0x8e; BYTE $0xdf
retry:
WORD $0xB9931022 // TROO 2,2,b'0001'
BVS retry
RET
// func e2a(arr [] byte)
// code page conversion from 1047 to 819
TEXT ·E2a(SB), NOSPLIT|NOFRAME, $0
MOVD arg_base+0(FP), R2 // pointer to arry of characters
MOVD arg_len+8(FP), R3 // count
XOR R0, R0
XOR R1, R1
BYTE $0xA7; BYTE $0x15; BYTE $0x00; BYTE $0x82 // BRAS 1,(2+(256/2))
// EBCDIC -> ASCII conversion table:
BYTE $0x00; BYTE $0x01; BYTE $0x02; BYTE $0x03
BYTE $0x9c; BYTE $0x09; BYTE $0x86; BYTE $0x7f
BYTE $0x97; BYTE $0x8d; BYTE $0x8e; BYTE $0x0b
BYTE $0x0c; BYTE $0x0d; BYTE $0x0e; BYTE $0x0f
BYTE $0x10; BYTE $0x11; BYTE $0x12; BYTE $0x13
BYTE $0x9d; BYTE $0x0a; BYTE $0x08; BYTE $0x87
BYTE $0x18; BYTE $0x19; BYTE $0x92; BYTE $0x8f
BYTE $0x1c; BYTE $0x1d; BYTE $0x1e; BYTE $0x1f
BYTE $0x80; BYTE $0x81; BYTE $0x82; BYTE $0x83
BYTE $0x84; BYTE $0x85; BYTE $0x17; BYTE $0x1b
BYTE $0x88; BYTE $0x89; BYTE $0x8a; BYTE $0x8b
BYTE $0x8c; BYTE $0x05; BYTE $0x06; BYTE $0x07
BYTE $0x90; BYTE $0x91; BYTE $0x16; BYTE $0x93
BYTE $0x94; BYTE $0x95; BYTE $0x96; BYTE $0x04
BYTE $0x98; BYTE $0x99; BYTE $0x9a; BYTE $0x9b
BYTE $0x14; BYTE $0x15; BYTE $0x9e; BYTE $0x1a
BYTE $0x20; BYTE $0xa0; BYTE $0xe2; BYTE $0xe4
BYTE $0xe0; BYTE $0xe1; BYTE $0xe3; BYTE $0xe5
BYTE $0xe7; BYTE $0xf1; BYTE $0xa2; BYTE $0x2e
BYTE $0x3c; BYTE $0x28; BYTE $0x2b; BYTE $0x7c
BYTE $0x26; BYTE $0xe9; BYTE $0xea; BYTE $0xeb
BYTE $0xe8; BYTE $0xed; BYTE $0xee; BYTE $0xef
BYTE $0xec; BYTE $0xdf; BYTE $0x21; BYTE $0x24
BYTE $0x2a; BYTE $0x29; BYTE $0x3b; BYTE $0x5e
BYTE $0x2d; BYTE $0x2f; BYTE $0xc2; BYTE $0xc4
BYTE $0xc0; BYTE $0xc1; BYTE $0xc3; BYTE $0xc5
BYTE $0xc7; BYTE $0xd1; BYTE $0xa6; BYTE $0x2c
BYTE $0x25; BYTE $0x5f; BYTE $0x3e; BYTE $0x3f
BYTE $0xf8; BYTE $0xc9; BYTE $0xca; BYTE $0xcb
BYTE $0xc8; BYTE $0xcd; BYTE $0xce; BYTE $0xcf
BYTE $0xcc; BYTE $0x60; BYTE $0x3a; BYTE $0x23
BYTE $0x40; BYTE $0x27; BYTE $0x3d; BYTE $0x22
BYTE $0xd8; BYTE $0x61; BYTE $0x62; BYTE $0x63
BYTE $0x64; BYTE $0x65; BYTE $0x66; BYTE $0x67
BYTE $0x68; BYTE $0x69; BYTE $0xab; BYTE $0xbb
BYTE $0xf0; BYTE $0xfd; BYTE $0xfe; BYTE $0xb1
BYTE $0xb0; BYTE $0x6a; BYTE $0x6b; BYTE $0x6c
BYTE $0x6d; BYTE $0x6e; BYTE $0x6f; BYTE $0x70
BYTE $0x71; BYTE $0x72; BYTE $0xaa; BYTE $0xba
BYTE $0xe6; BYTE $0xb8; BYTE $0xc6; BYTE $0xa4
BYTE $0xb5; BYTE $0x7e; BYTE $0x73; BYTE $0x74
BYTE $0x75; BYTE $0x76; BYTE $0x77; BYTE $0x78
BYTE $0x79; BYTE $0x7a; BYTE $0xa1; BYTE $0xbf
BYTE $0xd0; BYTE $0x5b; BYTE $0xde; BYTE $0xae
BYTE $0xac; BYTE $0xa3; BYTE $0xa5; BYTE $0xb7
BYTE $0xa9; BYTE $0xa7; BYTE $0xb6; BYTE $0xbc
BYTE $0xbd; BYTE $0xbe; BYTE $0xdd; BYTE $0xa8
BYTE $0xaf; BYTE $0x5d; BYTE $0xb4; BYTE $0xd7
BYTE $0x7b; BYTE $0x41; BYTE $0x42; BYTE $0x43
BYTE $0x44; BYTE $0x45; BYTE $0x46; BYTE $0x47
BYTE $0x48; BYTE $0x49; BYTE $0xad; BYTE $0xf4
BYTE $0xf6; BYTE $0xf2; BYTE $0xf3; BYTE $0xf5
BYTE $0x7d; BYTE $0x4a; BYTE $0x4b; BYTE $0x4c
BYTE $0x4d; BYTE $0x4e; BYTE $0x4f; BYTE $0x50
BYTE $0x51; BYTE $0x52; BYTE $0xb9; BYTE $0xfb
BYTE $0xfc; BYTE $0xf9; BYTE $0xfa; BYTE $0xff
BYTE $0x5c; BYTE $0xf7; BYTE $0x53; BYTE $0x54
BYTE $0x55; BYTE $0x56; BYTE $0x57; BYTE $0x58
BYTE $0x59; BYTE $0x5a; BYTE $0xb2; BYTE $0xd4
BYTE $0xd6; BYTE $0xd2; BYTE $0xd3; BYTE $0xd5
BYTE $0x30; BYTE $0x31; BYTE $0x32; BYTE $0x33
BYTE $0x34; BYTE $0x35; BYTE $0x36; BYTE $0x37
BYTE $0x38; BYTE $0x39; BYTE $0xb3; BYTE $0xdb
BYTE $0xdc; BYTE $0xd9; BYTE $0xda; BYTE $0x9f
retry:
WORD $0xB9931022 // TROO 2,2,b'0001'
BVS retry
RET

View File

@@ -1,220 +0,0 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build zos && s390x
package unix
import (
"sync"
)
// This file simulates epoll on z/OS using poll.
// Analogous to epoll_event on Linux.
// TODO(neeilan): Pad is because the Linux kernel expects a 96-bit struct. We never pass this to the kernel; remove?
type EpollEvent struct {
Events uint32
Fd int32
Pad int32
}
const (
EPOLLERR = 0x8
EPOLLHUP = 0x10
EPOLLIN = 0x1
EPOLLMSG = 0x400
EPOLLOUT = 0x4
EPOLLPRI = 0x2
EPOLLRDBAND = 0x80
EPOLLRDNORM = 0x40
EPOLLWRBAND = 0x200
EPOLLWRNORM = 0x100
EPOLL_CTL_ADD = 0x1
EPOLL_CTL_DEL = 0x2
EPOLL_CTL_MOD = 0x3
// The following constants are part of the epoll API, but represent
// currently unsupported functionality on z/OS.
// EPOLL_CLOEXEC = 0x80000
// EPOLLET = 0x80000000
// EPOLLONESHOT = 0x40000000
// EPOLLRDHUP = 0x2000 // Typically used with edge-triggered notis
// EPOLLEXCLUSIVE = 0x10000000 // Exclusive wake-up mode
// EPOLLWAKEUP = 0x20000000 // Relies on Linux's BLOCK_SUSPEND capability
)
// TODO(neeilan): We can eliminate these epToPoll / pToEpoll calls by using identical mask values for POLL/EPOLL
// constants where possible The lower 16 bits of epoll events (uint32) can fit any system poll event (int16).
// epToPollEvt converts epoll event field to poll equivalent.
// In epoll, Events is a 32-bit field, while poll uses 16 bits.
func epToPollEvt(events uint32) int16 {
var ep2p = map[uint32]int16{
EPOLLIN: POLLIN,
EPOLLOUT: POLLOUT,
EPOLLHUP: POLLHUP,
EPOLLPRI: POLLPRI,
EPOLLERR: POLLERR,
}
var pollEvts int16 = 0
for epEvt, pEvt := range ep2p {
if (events & epEvt) != 0 {
pollEvts |= pEvt
}
}
return pollEvts
}
// pToEpollEvt converts 16 bit poll event bitfields to 32-bit epoll event fields.
func pToEpollEvt(revents int16) uint32 {
var p2ep = map[int16]uint32{
POLLIN: EPOLLIN,
POLLOUT: EPOLLOUT,
POLLHUP: EPOLLHUP,
POLLPRI: EPOLLPRI,
POLLERR: EPOLLERR,
}
var epollEvts uint32 = 0
for pEvt, epEvt := range p2ep {
if (revents & pEvt) != 0 {
epollEvts |= epEvt
}
}
return epollEvts
}
// Per-process epoll implementation.
type epollImpl struct {
mu sync.Mutex
epfd2ep map[int]*eventPoll
nextEpfd int
}
// eventPoll holds a set of file descriptors being watched by the process. A process can have multiple epoll instances.
// On Linux, this is an in-kernel data structure accessed through a fd.
type eventPoll struct {
mu sync.Mutex
fds map[int]*EpollEvent
}
// epoll impl for this process.
var impl epollImpl = epollImpl{
epfd2ep: make(map[int]*eventPoll),
nextEpfd: 0,
}
func (e *epollImpl) epollcreate(size int) (epfd int, err error) {
e.mu.Lock()
defer e.mu.Unlock()
epfd = e.nextEpfd
e.nextEpfd++
e.epfd2ep[epfd] = &eventPoll{
fds: make(map[int]*EpollEvent),
}
return epfd, nil
}
func (e *epollImpl) epollcreate1(flag int) (fd int, err error) {
return e.epollcreate(4)
}
func (e *epollImpl) epollctl(epfd int, op int, fd int, event *EpollEvent) (err error) {
e.mu.Lock()
defer e.mu.Unlock()
ep, ok := e.epfd2ep[epfd]
if !ok {
return EBADF
}
switch op {
case EPOLL_CTL_ADD:
// TODO(neeilan): When we make epfds and fds disjoint, detect epoll
// loops here (instances watching each other) and return ELOOP.
if _, ok := ep.fds[fd]; ok {
return EEXIST
}
ep.fds[fd] = event
case EPOLL_CTL_MOD:
if _, ok := ep.fds[fd]; !ok {
return ENOENT
}
ep.fds[fd] = event
case EPOLL_CTL_DEL:
if _, ok := ep.fds[fd]; !ok {
return ENOENT
}
delete(ep.fds, fd)
}
return nil
}
// Must be called while holding ep.mu
func (ep *eventPoll) getFds() []int {
fds := make([]int, len(ep.fds))
for fd := range ep.fds {
fds = append(fds, fd)
}
return fds
}
func (e *epollImpl) epollwait(epfd int, events []EpollEvent, msec int) (n int, err error) {
e.mu.Lock() // in [rare] case of concurrent epollcreate + epollwait
ep, ok := e.epfd2ep[epfd]
if !ok {
e.mu.Unlock()
return 0, EBADF
}
pollfds := make([]PollFd, 4)
for fd, epollevt := range ep.fds {
pollfds = append(pollfds, PollFd{Fd: int32(fd), Events: epToPollEvt(epollevt.Events)})
}
e.mu.Unlock()
n, err = Poll(pollfds, msec)
if err != nil {
return n, err
}
i := 0
for _, pFd := range pollfds {
if pFd.Revents != 0 {
events[i] = EpollEvent{Fd: pFd.Fd, Events: pToEpollEvt(pFd.Revents)}
i++
}
if i == n {
break
}
}
return n, nil
}
func EpollCreate(size int) (fd int, err error) {
return impl.epollcreate(size)
}
func EpollCreate1(flag int) (fd int, err error) {
return impl.epollcreate1(flag)
}
func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) {
return impl.epollctl(epfd, op, fd, event)
}
// Because EpollWait mutates events, the caller is expected to coordinate
// concurrent access if calling with the same epfd from multiple goroutines.
func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) {
return impl.epollwait(epfd, events, msec)
}

View File

@@ -1,163 +0,0 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build zos && s390x
package unix
import (
"unsafe"
)
// This file simulates fstatfs on z/OS using fstatvfs and w_getmntent.
func Fstatfs(fd int, stat *Statfs_t) (err error) {
var stat_v Statvfs_t
err = Fstatvfs(fd, &stat_v)
if err == nil {
// populate stat
stat.Type = 0
stat.Bsize = stat_v.Bsize
stat.Blocks = stat_v.Blocks
stat.Bfree = stat_v.Bfree
stat.Bavail = stat_v.Bavail
stat.Files = stat_v.Files
stat.Ffree = stat_v.Ffree
stat.Fsid = stat_v.Fsid
stat.Namelen = stat_v.Namemax
stat.Frsize = stat_v.Frsize
stat.Flags = stat_v.Flag
for passn := 0; passn < 5; passn++ {
switch passn {
case 0:
err = tryGetmntent64(stat)
break
case 1:
err = tryGetmntent128(stat)
break
case 2:
err = tryGetmntent256(stat)
break
case 3:
err = tryGetmntent512(stat)
break
case 4:
err = tryGetmntent1024(stat)
break
default:
break
}
//proceed to return if: err is nil (found), err is nonnil but not ERANGE (another error occurred)
if err == nil || err != nil && err != ERANGE {
break
}
}
}
return err
}
func tryGetmntent64(stat *Statfs_t) (err error) {
var mnt_ent_buffer struct {
header W_Mnth
filesys_info [64]W_Mntent
}
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer))
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size)
if err != nil {
return err
}
err = ERANGE //return ERANGE if no match is found in this batch
for i := 0; i < fs_count; i++ {
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) {
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0])
err = nil
break
}
}
return err
}
func tryGetmntent128(stat *Statfs_t) (err error) {
var mnt_ent_buffer struct {
header W_Mnth
filesys_info [128]W_Mntent
}
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer))
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size)
if err != nil {
return err
}
err = ERANGE //return ERANGE if no match is found in this batch
for i := 0; i < fs_count; i++ {
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) {
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0])
err = nil
break
}
}
return err
}
func tryGetmntent256(stat *Statfs_t) (err error) {
var mnt_ent_buffer struct {
header W_Mnth
filesys_info [256]W_Mntent
}
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer))
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size)
if err != nil {
return err
}
err = ERANGE //return ERANGE if no match is found in this batch
for i := 0; i < fs_count; i++ {
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) {
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0])
err = nil
break
}
}
return err
}
func tryGetmntent512(stat *Statfs_t) (err error) {
var mnt_ent_buffer struct {
header W_Mnth
filesys_info [512]W_Mntent
}
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer))
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size)
if err != nil {
return err
}
err = ERANGE //return ERANGE if no match is found in this batch
for i := 0; i < fs_count; i++ {
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) {
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0])
err = nil
break
}
}
return err
}
func tryGetmntent1024(stat *Statfs_t) (err error) {
var mnt_ent_buffer struct {
header W_Mnth
filesys_info [1024]W_Mntent
}
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer))
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size)
if err != nil {
return err
}
err = ERANGE //return ERANGE if no match is found in this batch
for i := 0; i < fs_count; i++ {
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) {
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0])
err = nil
break
}
}
return err
}

View File

@@ -263,6 +263,7 @@ struct ltchars {
#include <linux/sched.h>
#include <linux/seccomp.h>
#include <linux/serial.h>
#include <linux/sock_diag.h>
#include <linux/sockios.h>
#include <linux/taskstats.h>
#include <linux/tipc.h>
@@ -549,6 +550,7 @@ ccflags="$@"
$2 !~ "NLA_TYPE_MASK" &&
$2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ &&
$2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ ||
$2 ~ /^SOCK_|SK_DIAG_|SKNLGRP_$/ ||
$2 ~ /^FIORDCHK$/ ||
$2 ~ /^SIOC/ ||
$2 ~ /^TIOC/ ||

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos
// For Unix, get the pagesize from the runtime.

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin
//go:build darwin || zos
package unix

58
vendor/golang.org/x/sys/unix/sockcmsg_zos.go generated vendored Normal file
View File

@@ -0,0 +1,58 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Socket control messages
package unix
import "unsafe"
// UnixCredentials encodes credentials into a socket control message
// for sending to another process. This can be used for
// authentication.
func UnixCredentials(ucred *Ucred) []byte {
b := make([]byte, CmsgSpace(SizeofUcred))
h := (*Cmsghdr)(unsafe.Pointer(&b[0]))
h.Level = SOL_SOCKET
h.Type = SCM_CREDENTIALS
h.SetLen(CmsgLen(SizeofUcred))
*(*Ucred)(h.data(0)) = *ucred
return b
}
// ParseUnixCredentials decodes a socket control message that contains
// credentials in a Ucred structure. To receive such a message, the
// SO_PASSCRED option must be enabled on the socket.
func ParseUnixCredentials(m *SocketControlMessage) (*Ucred, error) {
if m.Header.Level != SOL_SOCKET {
return nil, EINVAL
}
if m.Header.Type != SCM_CREDENTIALS {
return nil, EINVAL
}
ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0]))
return &ucred, nil
}
// PktInfo4 encodes Inet4Pktinfo into a socket control message of type IP_PKTINFO.
func PktInfo4(info *Inet4Pktinfo) []byte {
b := make([]byte, CmsgSpace(SizeofInet4Pktinfo))
h := (*Cmsghdr)(unsafe.Pointer(&b[0]))
h.Level = SOL_IP
h.Type = IP_PKTINFO
h.SetLen(CmsgLen(SizeofInet4Pktinfo))
*(*Inet4Pktinfo)(h.data(0)) = *info
return b
}
// PktInfo6 encodes Inet6Pktinfo into a socket control message of type IPV6_PKTINFO.
func PktInfo6(info *Inet6Pktinfo) []byte {
b := make([]byte, CmsgSpace(SizeofInet6Pktinfo))
h := (*Cmsghdr)(unsafe.Pointer(&b[0]))
h.Level = SOL_IPV6
h.Type = IPV6_PKTINFO
h.SetLen(CmsgLen(SizeofInet6Pktinfo))
*(*Inet6Pktinfo)(h.data(0)) = *info
return b
}

Some files were not shown because too many files have changed in this diff Show More