mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-05 23:36:53 +08:00
Match-id-736351bcbab9825232a29001080a89b7d32c4ff3
This commit is contained in:
@@ -28,6 +28,7 @@ const (
|
|||||||
hookDefaultFilePath = "/usr/local/bin/ascend-docker-hook"
|
hookDefaultFilePath = "/usr/local/bin/ascend-docker-hook"
|
||||||
dockerRuncFile = "docker-runc"
|
dockerRuncFile = "docker-runc"
|
||||||
runcFile = "runc"
|
runcFile = "runc"
|
||||||
|
envLength = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -108,6 +109,19 @@ func addHook(spec *specs.Spec) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasVirtualFlag := false
|
||||||
|
for _, line := range spec.Process.Env {
|
||||||
|
words := strings.Split(line, "=")
|
||||||
|
if len(words) == envLength && strings.TrimSpace(words[0]) == "ASCEND_RUNTIME_OPTIONS" {
|
||||||
|
if strings.Contains(words[1], "VIRTUAL") {
|
||||||
|
hasVirtualFlag = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasVirtualFlag {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
vdevice, err := dcmi.CreateVDevice(&dcmi.NpuWorker{}, spec)
|
vdevice, err := dcmi.CreateVDevice(&dcmi.NpuWorker{}, spec)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -126,12 +140,11 @@ func updateEnvAndPostHook(spec *specs.Spec, vdevice dcmi.VDeviceInfo) {
|
|||||||
needAddVirtualFlag := true
|
needAddVirtualFlag := true
|
||||||
for _, line := range spec.Process.Env {
|
for _, line := range spec.Process.Env {
|
||||||
words := strings.Split(line, "=")
|
words := strings.Split(line, "=")
|
||||||
const LENGTH int = 2
|
if len(words) == envLength && strings.TrimSpace(words[0]) == "ASCEND_VISIBLE_DEVICES" {
|
||||||
if len(words) == LENGTH && strings.TrimSpace(words[0]) == "ASCEND_VISIBLE_DEVICES" {
|
|
||||||
newEnv = append(newEnv, fmt.Sprintf("ASCEND_VISIBLE_DEVICES=%d", vdevice.VdeviceID))
|
newEnv = append(newEnv, fmt.Sprintf("ASCEND_VISIBLE_DEVICES=%d", vdevice.VdeviceID))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(words) == LENGTH && strings.TrimSpace(words[0]) == "ASCEND_RUNTIME_OPTIONS" {
|
if len(words) == envLength && strings.TrimSpace(words[0]) == "ASCEND_RUNTIME_OPTIONS" {
|
||||||
needAddVirtualFlag = false
|
needAddVirtualFlag = false
|
||||||
if strings.Contains(words[1], "VIRTUAL") {
|
if strings.Contains(words[1], "VIRTUAL") {
|
||||||
newEnv = append(newEnv, line)
|
newEnv = append(newEnv, line)
|
||||||
|
Reference in New Issue
Block a user