Skip to content

Commit

Permalink
fix: get cuda version (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
aby913 authored Dec 20, 2024
1 parent 6908e2b commit ad18422
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pkg/gpu/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,20 @@ func (m *InstallPluginModule) Init() {
installGPUShared,
}
}

type GetCudaVersionModule struct {
common.KubeModule
}

func (g *GetCudaVersionModule) Init() {
g.Name = "GetCudaVersion"

getCudaVersion := &task.LocalTask{
Name: "GetCudaVersion",
Action: new(GetCudaVersion),
}

g.Tasks = []task.Interface{
getCudaVersion,
}
}
48 changes: 48 additions & 0 deletions pkg/gpu/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,51 @@ func (t *InstallGPUShared) Execute(runtime connector.Runtime) error {

return nil
}

type GetCudaVersion struct {
common.KubeAction
}

func (g *GetCudaVersion) Execute(runtime connector.Runtime) error {
var nvidiaSmiFile string
var systemInfo = runtime.GetSystemInfo()

switch {
case systemInfo.IsWsl():
nvidiaSmiFile = "/usr/lib/wsl/lib/nvidia-smi"
default:
nvidiaSmiFile = "/usr/bin/nvidia-smi"
}

if !util.IsExist(nvidiaSmiFile) {
logger.Info("nvidia-smi not exists")
return nil
}

var cudaVersion string
res, err := runtime.GetRunner().Host.Cmd(fmt.Sprintf("%s --version", nvidiaSmiFile), false, true)
if err != nil {
logger.Errorf("get cuda version error %v", err)
return nil
}

lines := strings.Split(res, "\n")

if lines == nil || len(lines) == 0 {
return nil
}
for _, line := range lines {
if strings.Contains(line, "CUDA Version") {
parts := strings.Split(line, ":")
if len(parts) != 2 {
break
}
cudaVersion = strings.TrimSpace(parts[1])
}
}
if cudaVersion != "" {
common.TerminusGlobalEnvs["CUDA_VERSION"] = cudaVersion
}

return nil
}
1 change: 1 addition & 0 deletions pkg/phase/cluster/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (l *linuxInstallPhaseBuilder) installGpuPlugin() phase {
return []module.Module{
&gpu.RestartK3sServiceModule{Skip: !(l.runtime.Arg.Kubetype == common.K3s)},
&gpu.InstallPluginModule{Skip: skipGpuPlugin},
&gpu.GetCudaVersionModule{},
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/terminus/ossystem.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package terminus

import (
"bytetrade.io/web3os/installer/pkg/core/logger"
"bytetrade.io/web3os/installer/pkg/storage"
"context"
"fmt"
"path"
"time"

"bytetrade.io/web3os/installer/pkg/core/logger"
"bytetrade.io/web3os/installer/pkg/storage"

"bytetrade.io/web3os/installer/pkg/clientset"
"bytetrade.io/web3os/installer/pkg/common"
cc "bytetrade.io/web3os/installer/pkg/core/common"
Expand Down

0 comments on commit ad18422

Please sign in to comment.