diff --git a/runtime/main.go b/runtime/main.go index 8d5fedd2c47fdb28dc85c7fb885bdacf3867c36b..917e3296f6e4e05feb77bc9c4fcfa8170392c9e4 100644 --- a/runtime/main.go +++ b/runtime/main.go @@ -378,9 +378,8 @@ func getValueByKey(data []string, name string) string { func getValueByDeviceKey(data []string) string { res := "" - isKeyExist := false - for _, envLine := range data { - words := strings.SplitN(envLine, "=", kvPairSize) + for i := len(data) - 1; i >= 0; i-- { + words := strings.SplitN(data[i], "=", kvPairSize) if len(words) != kvPairSize { hwlog.RunLog.Error("environment error") return "" @@ -388,16 +387,12 @@ func getValueByDeviceKey(data []string) string { if words[0] == ascendVisibleDevices { res = words[1] - if strings.Contains(res, ascend) { - return res - } - isKeyExist = true + break } } - if isKeyExist && res == "" { + if res == "" { hwlog.RunLog.Error("ASCEND_VISIBLE_DEVICES env variable is empty, will not mount any ascend device") } - return res }