Skip to content

Commit

Permalink
310b 适配davinci_manager_docker改名,修复挂载so的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
funnyfunny committed Jul 6, 2023
1 parent 6eb271e commit 6dcd798
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 76 deletions.
4 changes: 1 addition & 3 deletions build/scripts/base.list_A500A2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/var/slogd
/usr/lib64/libsemanage.so.2
/usr/lib64/libmmpa.so
/usr/lib64/libcrypto.so.1.1
/usr/lib64/libdrvdsmi.so
/usr/lib64/libdcmi.so
/usr/lib64/libstackcore.so
Expand All @@ -18,5 +17,4 @@
/usr/lib64/libaicpu_sharder.so
/usr/lib64/libadump.so
/usr/lib64/libtsd_eventclient.so
/usr/lib64/aicpu_kernels
/usr/lib64/libyaml-0.so.2
/usr/lib64/aicpu_kernels
43 changes: 19 additions & 24 deletions build/scripts/run_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ function save_install_args() {
} >> "${INSTALL_PATH}"/ascend_docker_runtime_install.info
}

function add_so() {
if grep -qi "ubuntu" "/etc/os-release"; then
echo "[info]: os is Ubuntu"
echo -e "\n/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
echo "/usr/lib/aarch64-linux-gnu/libyaml-0.so.2" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
elif grep -qi "euler" "/etc/os-release"; then
echo "[info]: os is Euler/OpenEuler"
echo -e "\n/usr/lib64/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
echo "/usr/lib64/libyaml-0.so.2" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
else
echo "ERROR: not support this os"
exit
fi
}

function install()
{
echo 'installing ascend docker runtime'
Expand Down Expand Up @@ -89,20 +104,10 @@ function install()
cp -f ./base.list_A200ISoC ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
elif [ "${a500a2}" == "y" ]; then
cp -f ./base.list_A500A2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
add_so
elif [ "${a200ia2}" == "y" ]; then
cp -f ./base.list_A200IA2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
if grep -qi "ubuntu" "/etc/os-release"; then
echo "[info]: A200IA2 os is Ubuntu"
echo -e "\n/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
echo "/usr/lib/aarch64-linux-gnu/libyaml-0.so.2.0.6" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
elif grep -qi "euler" "/etc/os-release"; then
echo "[info]: A200IA2 os is Euler/OpenEuler"
echo -e "\n/usr/lib64/libcrypto.so.1.1.1m" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
echo "/usr/lib64/libyaml-0.so.2.0.9" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
else
echo "ERROR: not support this os"
exit
fi
add_so
else
cp -f ./base.list ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
fi
Expand Down Expand Up @@ -185,6 +190,7 @@ function upgrade()
elif [ "$(grep "a500a2=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "a500a2=y" ]; then
a500a2=y
cp -f ./base.list_A500A2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
add_so
elif [ "$(grep "a200=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "a200=y" ]; then
a200=y
cp -f ./base.list_A200 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
Expand All @@ -194,18 +200,7 @@ function upgrade()
elif [ "x$(grep "a200ia2=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "xa200ia2=y" ]; then
a200ia2=y
cp -f ./base.list_A200IA2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
if grep -qi "ubuntu" "/etc/os-release"; then
echo "[info]: A200IA2 os is Ubuntu"
echo -e "\n/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
echo -e "/usr/lib/aarch64-linux-gnu/libyaml-0.so.2.0.6" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
elif grep -qi "euler" "/etc/os-release"; then
echo "[info]: A200IA2 os is Euler/OpenEuler"
echo -e "\n/usr/lib64/libcrypto.so.1.1.1m" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
echo -e "/usr/lib64/libyaml-0.so.2.0.9" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
else
echo "ERROR: not support this os"
exit
fi
add_so
else
cp -f ./base.list ${ASCEND_RUNTIME_CONFIG_DIR}/base.list
fi
Expand Down
5 changes: 2 additions & 3 deletions cli/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ static bool CheckWhiteList(const char* fileName)
{"/usr/lib64/libmpi_dvpp_adapter.so"}, {"/usr/lib64/libaicpu_scheduler.so"},
{"/usr/lib64/libaicpu_processer.so"}, {"/usr/lib64/libaicpu_prof.so"}, {"/usr/lib64/libaicpu_sharder.so"},
{"/usr/lib64/libadump.so"}, {"/usr/lib64/libtsd_eventclient.so"},
{"/usr/lib64/aicpu_kernels"}, {"/usr/lib64/libyaml-0.so.2"}, {"/usr/lib64/libcrypto.so.1.1.1m"},
{"/usr/lib64/libyaml-0.so.2.0.9"}, {"/usr/lib/aarch64-linux-gnu/libyaml-0.so.2.0.6"},
{"/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1"}
{"/usr/lib64/aicpu_kernels"}, {"/usr/lib64/libyaml-0.so.2"},
{"/usr/lib/aarch64-linux-gnu/libyaml-0.so.2"}, {"/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1"}
};

for (size_t iLoop = 0; iLoop < WHITE_LIST_NUM; iLoop++) {
Expand Down
6 changes: 3 additions & 3 deletions hook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ func main() {
log.Fatal("command error")
}
if err := doPrestartHook(); err != nil {
hwlog.RunLog.Errorf("ascend docker hook failed")
hwlog.OpLog.Errorf("%v ascend docker hook failed", logPrefixWords)
log.Fatal(fmt.Errorf("failed in runtime.doProcess "))
hwlog.RunLog.Errorf("ascend docker hook failed: %#v", err)
hwlog.OpLog.Errorf("%v ascend docker hook failed: %#v", logPrefixWords, err)
log.Fatal(fmt.Errorf("failed in runtime.doProcess: %#v", err))
}
}
88 changes: 48 additions & 40 deletions runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,24 @@ const (
// Ascend910 ascend 910 chip
Ascend910 = "Ascend910"

devicePath = "/dev/"
davinciName = "davinci"
davinciManager = "davinci_manager"
devmmSvm = "devmm_svm"
hisiHdc = "hisi_hdc"
svm0 = "svm0"
tsAisle = "ts_aisle"
upgrade = "upgrade"
sys = "sys"
vdec = "vdec"
vpc = "vpc"
pngd = "pngd"
venc = "venc"
dvppCmdList = "dvpp_cmdlist"
logDrv = "log_drv"
devicePath = "/dev/"
davinciName = "davinci"
virtualDavinciName = "vdavinci"
davinciManager = "davinci_manager"
davinciManagerDocker = "davinci_manager_docker"
notRenameDeviceType = ""
devmmSvm = "devmm_svm"
hisiHdc = "hisi_hdc"
svm0 = "svm0"
tsAisle = "ts_aisle"
upgrade = "upgrade"
sys = "sys"
vdec = "vdec"
vpc = "vpc"
pngd = "pngd"
venc = "venc"
dvppCmdList = "dvpp_cmdlist"
logDrv = "log_drv"
)

type args struct {
Expand Down Expand Up @@ -346,20 +349,23 @@ func getValueByKey(data []string, name string) string {
return ""
}

func addDeviceToSpec(spec *specs.Spec, dPath string, vdevice bool) error {
func addDeviceToSpec(spec *specs.Spec, dPath string, deviceType string) error {
device, err := oci.DeviceFromPath(dPath)
if err != nil {
return fmt.Errorf("failed to get %s info : %#v", dPath, err)
}

if vdevice {
re := regexp.MustCompile("[0-9]+")
vDeviceNumber := re.FindAllString(dPath, -1)
switch deviceType {
case virtualDavinciName:
vDeviceNumber := regexp.MustCompile("[0-9]+").FindAllString(dPath, -1)
if len(vDeviceNumber) != 1 {
return fmt.Errorf("error vdevice : %s", dPath)
return fmt.Errorf("invalid vdavinci path: %s", dPath)
}
vPath := devicePath + davinciName + vDeviceNumber[0]
device.Path = vPath
device.Path = devicePath + davinciName + vDeviceNumber[0]
case davinciManagerDocker:
device.Path = devicePath + davinciManager
default:
// do nothing
}

spec.Linux.Devices = append(spec.Linux.Devices, *device)
Expand Down Expand Up @@ -390,12 +396,20 @@ func addAscend310BManagerDevice(spec *specs.Spec) error {

for _, device := range Ascend310BManageDevices {
dPath := devicePath + device
if err := addDeviceToSpec(spec, dPath, false); err != nil {
if err := addDeviceToSpec(spec, dPath, notRenameDeviceType); err != nil {
hwlog.RunLog.Warnf("failed to add %s to spec : %#v", dPath, err)
}
}

return nil
davinciManagerPath := devicePath + davinciManagerDocker
if _, err := os.Stat(davinciManagerPath); err != nil {
hwlog.RunLog.Warnf("failed to get davinci manager docker, err: %#v", err)
davinciManagerPath = devicePath + davinciManager
if _, err := os.Stat(davinciManagerPath); err != nil {
return fmt.Errorf("failed to get davinci manager, err: %#v", err)
}
}
return addDeviceToSpec(spec, davinciManagerPath, davinciManagerDocker)
}

func addCommonManagerDevice(spec *specs.Spec) error {
Expand All @@ -406,7 +420,7 @@ func addCommonManagerDevice(spec *specs.Spec) error {

for _, device := range commonManagerDevices {
dPath := devicePath + device
if err := addDeviceToSpec(spec, dPath, false); err != nil {
if err := addDeviceToSpec(spec, dPath, notRenameDeviceType); err != nil {
return fmt.Errorf("failed to add common manage device to spec : %#v", err)
}
}
Expand All @@ -415,22 +429,18 @@ func addCommonManagerDevice(spec *specs.Spec) error {
}

func addManagerDevice(spec *specs.Spec) error {
managerPath := devicePath + davinciManager
if err := addDeviceToSpec(spec, managerPath, false); err != nil {
return fmt.Errorf("add davinci_manager to spec error: %#v", err)
}

chipName, err := dcmi.GetChipName()
if err != nil {
return fmt.Errorf("get chip name error: %#v", err)
}
devType := GetDeviceTypeByChipName(chipName)
hwlog.RunLog.Infof("device type is: %s", devType)
if devType == Ascend310B {
if err = addAscend310BManagerDevice(spec); err != nil {
return fmt.Errorf("add 310B manage device error: %#v", err)
}
return nil
return addAscend310BManagerDevice(spec)
}

if err := addDeviceToSpec(spec, devicePath+davinciManager, notRenameDeviceType); err != nil {
return fmt.Errorf("add davinci_manager to spec error: %#v", err)
}

productType, err := dcmi.GetProductType(&dcmi.NpuWorker{})
Expand Down Expand Up @@ -462,16 +472,14 @@ func addDevice(spec *specs.Spec) error {
return fmt.Errorf("failed to parse device : %#v", err)
}
hwlog.RunLog.Infof("devices is: %#v", devices)
devciename := davinciName
vdevice := false
deviceName := davinciName
virtual := getValueByKey(spec.Process.Env, ascendRuntimeOptions)
if strings.Contains(virtual, "VIRTUAL") {
devciename = "v" + devciename
vdevice = true
deviceName = virtualDavinciName
}
for _, deviceId := range devices {
dPath := devicePath + devciename + strconv.Itoa(deviceId)
if err = addDeviceToSpec(spec, dPath, vdevice); err != nil {
dPath := devicePath + deviceName + strconv.Itoa(deviceId)
if err = addDeviceToSpec(spec, dPath, deviceName); err != nil {
return fmt.Errorf("failed to add davinci device to spec: %v", err)
}
}
Expand Down
11 changes: 8 additions & 3 deletions runtime/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,22 @@ func TestAddDeviceToSpec0(t *testing.T) {
},
}

err := addDeviceToSpec(&spec, devPath, false)
err := addDeviceToSpec(&spec, devPath, notRenameDeviceType)
assert.Nil(t, err)
assert.Contains(t, spec.Linux.Devices[0].Path, devPath)
}

func TestAddAscend310BManagerDevice(t *testing.T) {
statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, vdevice bool) error {
statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, deviceType string) error {
return nil
})
defer statStub.Reset()

pathStub := gomonkey.ApplyFunc(os.Stat, func(name string) (os.FileInfo, error) {
return nil, nil
})
defer pathStub.Reset()

spec := specs.Spec{
Linux: &specs.Linux{
Devices: []specs.LinuxDevice{},
Expand All @@ -422,7 +427,7 @@ func TestAddAscend310BManagerDevice(t *testing.T) {
}

func TestAddCommonManagerDevice(t *testing.T) {
statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, vdevice bool) error {
statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, deviceType string) error {
return nil
})
defer statStub.Reset()
Expand Down

0 comments on commit 6dcd798

Please sign in to comment.