From 651ca44083aa3ad71d6e413bc0babbaf313efeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Thu, 20 Jun 2024 17:03:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91=E5=8E=BB=E9=99=A4deviceIdList?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/main.go | 14 ++++++-------- runtime/main_test.go | 16 ++++++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/runtime/main.go b/runtime/main.go index 444fd7d..d64fe59 100644 --- a/runtime/main.go +++ b/runtime/main.go @@ -64,7 +64,6 @@ var ( hookDefaultFile = hookDefaultFilePath dockerRuncName = dockerRuncFile runcName = runcFile - deviceIdList []int ) const ( @@ -198,7 +197,7 @@ func addAscendDockerEnv(spec *specs.Spec) { spec.Process.Env = append(spec.Process.Env, useAscendDocker) } -func addHook(spec *specs.Spec) error { +func addHook(spec *specs.Spec, deviceIdList []int) error { currentExecPath, err := os.Executable() if err != nil { return fmt.Errorf("cannot get the path of ascend-docker-runtime: %v", err) @@ -248,7 +247,7 @@ func addHook(spec *specs.Spec) error { hwlog.RunLog.Infof("vnpu split done: vdevice: %v", vdevice.VdeviceID) if vdevice.VdeviceID != -1 { - updateEnvAndPostHook(spec, vdevice) + updateEnvAndPostHook(spec, vdevice, deviceIdList) } return nil @@ -528,7 +527,7 @@ func checkVisibleDevice(spec *specs.Spec) ([]int, error) { return devices, err } -func addDevice(spec *specs.Spec) error { +func addDevice(spec *specs.Spec, deviceIdList []int) error { deviceName := davinciName if strings.Contains(getValueByKey(spec.Process.Env, ascendRuntimeOptions), "VIRTUAL") { deviceName = virtualDavinciName @@ -547,7 +546,7 @@ func addDevice(spec *specs.Spec) error { return nil } -func updateEnvAndPostHook(spec *specs.Spec, vdevice dcmi.VDeviceInfo) { +func updateEnvAndPostHook(spec *specs.Spec, vdevice dcmi.VDeviceInfo, deviceIdList []int) { newEnv := make([]string, 0, len(spec.Process.Env)+1) needAddVirtualFlag := true deviceIdList = []int{int(vdevice.VdeviceID)} @@ -618,12 +617,11 @@ func modifySpecFile(path string) error { return fmt.Errorf("failed to check ASCEND_VISIBLE_DEVICES parameter, err: %v", err) } if len(devices) != 0 { - deviceIdList = devices - if err = addHook(&spec); err != nil { + if err = addHook(&spec, devices); err != nil { hwlog.RunLog.Errorf("failed to inject hook, err: %v", err) return fmt.Errorf("failed to inject hook, err: %v", err) } - if err = addDevice(&spec); err != nil { + if err = addDevice(&spec, devices); err != nil { return fmt.Errorf("failed to add device to env: %v", err) } } diff --git a/runtime/main_test.go b/runtime/main_test.go index 87eb513..a73459d 100644 --- a/runtime/main_test.go +++ b/runtime/main_test.go @@ -41,6 +41,10 @@ const ( needToMkdir = "./test" ) +var ( + deviceList = []int{1} +) + func TestArgsIsCreate(t *testing.T) { t.Log("进入测试用例") @@ -190,7 +194,7 @@ func TestModifySpecFileCase3(t *testing.T) { func TestAddHook(t *testing.T) { var specArgs = &specs.Spec{} - if err := addHook(specArgs); err != nil { + if err := addHook(specArgs, deviceList); err != nil { } } @@ -199,7 +203,7 @@ func TestAddHookCase1(t *testing.T) { stub := gomonkey.ApplyGlobalVar(&hookCliPath, ".") defer stub.Reset() - err := addHook(specArgs) + err := addHook(specArgs, deviceList) assert.NotNil(t, err) } @@ -208,7 +212,7 @@ func TestAddHookCase2(t *testing.T) { stub := gomonkey.ApplyGlobalVar(&hookCliPath, ".") defer stub.Reset() stub.ApplyGlobalVar(&hookDefaultFile, ".") - err := addHook(specArgs) + err := addHook(specArgs, deviceList) assert.NotNil(t, err) } @@ -220,7 +224,7 @@ func TestAddHookCase3(t *testing.T) { t.Log("rename ", file) } var specArgs = &specs.Spec{} - err := addHook(specArgs) + err := addHook(specArgs, deviceList) assert.NotNil(t, err) if err := os.Rename(filenew, file); err != nil { @@ -399,7 +403,7 @@ func TestUpdateEnvAndPostHook(t *testing.T) { Hooks: &specs.Hooks{}, } - updateEnvAndPostHook(&spec, vdvice) + updateEnvAndPostHook(&spec, vdvice, deviceList) assert.Contains(t, spec.Process.Env, "ASCEND_VISIBLE_DEVICES=100") assert.Contains(t, spec.Process.Env, "ASCEND_RUNTIME_OPTIONS=VIRTUAL") assert.Contains(t, spec.Hooks.Poststop[0].Path, destroyHookCli) @@ -537,7 +541,7 @@ func TestAddDevice(t *testing.T) { ctx, _ := context.WithCancel(context.Background()) err := initLogModule(ctx) assert.Nil(t, err) - err = addDevice(&spec) + err = addDevice(&spec, deviceList) assert.Nil(t, err) assert.Contains(t, spec.Linux.Devices[0].Path, devPath) } -- Gitee From 5a7e3f62420713ab6e6917503d96f8ebaa34b059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Fri, 21 Jun 2024 09:17:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91=E5=8E=BB=E9=99=A4deviceIdList?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- runtime/main_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6321d0b..bbc7820 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ root@#:/home/test/ascend-docker-runtime/output# ll ``` # 组件安装 -请参考[《MindX DL用户指南》--Ascend Docker Runtime用户指南](https://www.hiascend.com/document/detail/zh/mindx-dl/50rc2/dockerruntime/dockerruntimeug/dlruntime_ug_005.html)中“安装Ascend Docker Runtime”章节进行。 +请参考[《MindX DL用户指南》--Ascend Docker Runtime用户指南](https://www.hiascend.com/document/detail/zh/mindx-dl/60rc1/clusterscheduling/dockerruntimeug/dlruntime_ug_005.html)中“安装Ascend Docker Runtime”章节进行。 # 更新日志 diff --git a/runtime/main_test.go b/runtime/main_test.go index a73459d..5603c25 100644 --- a/runtime/main_test.go +++ b/runtime/main_test.go @@ -195,6 +195,7 @@ func TestModifySpecFileCase3(t *testing.T) { func TestAddHook(t *testing.T) { var specArgs = &specs.Spec{} if err := addHook(specArgs, deviceList); err != nil { + t.Logf("addHook failed, error: %v", err) } } -- Gitee