Skip to content

Commit

Permalink
Update export and checkpoint commands to also persist NVML connection
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <kklues@nvidia.com>
  • Loading branch information
klueska committed May 30, 2022
1 parent 9d0af27 commit 1b95caa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/checkpoint/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"

checkpoint "github.com/NVIDIA/mig-parted/api/checkpoint/v1"
"github.com/NVIDIA/mig-parted/cmd/util"
"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/NVIDIA/mig-parted/pkg/mig/state"
"github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"
Expand Down Expand Up @@ -83,6 +85,13 @@ func checkpointWrapper(c *cli.Context, f *Flags) error {
return err
}

nvml := nvml.New()
err = util.NvmlInit(nvml)
if err != nil {
return fmt.Errorf("error initializing NVML: %v", err)
}
defer util.TryNvmlShutdown(nvml)

migState, err := state.NewMigStateManager().Fetch()
if err != nil {
return fmt.Errorf("error fetching MIG state: %v", err)
Expand Down
6 changes: 6 additions & 0 deletions cmd/export/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ import (
)

func ExportMigConfigs(c *Context) (*v1.Spec, error) {
err := util.NvmlInit(c.Nvml)
if err != nil {
return nil, fmt.Errorf("error initializing NVML: %v", err)
}
defer util.TryNvmlShutdown(c.Nvml)

nvpci := nvpci.New()
gpus, err := nvpci.GetGPUs()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"

"github.com/NVIDIA/mig-parted/api/spec/v1"
"github.com/NVIDIA/mig-parted/internal/nvml"
"github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"

Expand All @@ -49,6 +50,7 @@ type Flags struct {
type Context struct {
*cli.Context
Flags *Flags
Nvml nvml.Interface
}

func BuildCommand() *cli.Command {
Expand Down Expand Up @@ -96,6 +98,7 @@ func exportWrapper(c *cli.Context, f *Flags) error {
context := Context{
Context: c,
Flags: f,
Nvml: nvml.New(),
}

spec, err := ExportMigConfigs(&context)
Expand Down

0 comments on commit 1b95caa

Please sign in to comment.