Skip to content

Commit

Permalink
[Feature](mlu-ops): check dependency of mlu-ops (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
chqy99 authored Jan 18, 2024
1 parent ce2e19c commit 3f5f16d
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</a>
</b>
</div>

<div>&nbsp;</div>

[![ci](https://github.com/Cambricon/mlu-ops/actions/workflows/ci.yaml/badge.svg)](https://github.com/Cambricon/mlu-ops/actions/workflows/ci.yaml)
Expand Down Expand Up @@ -54,7 +54,7 @@ MLU-OPS 提供了以下功能:
- 外部链接库:
- libxml2-dev、libprotobuf-dev<=3.8.0、protobuf-compiler<=3.8.0、llvm-6.0-dev
- Python环境:
- 依赖Python-3.8.0版本
- 依赖Python-3版本(默认版本 python 3.8.0,最低要求 python 3.6.0)


## 依赖环境准备
Expand Down
8 changes: 7 additions & 1 deletion build.property
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"version": "0.11.0-1",
"build_requires": {"cntoolkit": ["release","3.8.4-1"], "cnnl":["release","1.21.1-1"]},
"python": "3.6.0",
"build_requires": {"cntoolkit": ["release","3.8.4-1"],
"cnnl":["release","1.21.1-1"],
"driver": "5.10.15",
"eigen3": "3.4.0",
"libxml2": "2.9.0",
"protoc": "3.8.0"},
"package_type": ["rpm","deb"]
}
59 changes: 38 additions & 21 deletions independent_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ add_mlu_arch_support () {
MLUOP_MLU_ARCH_LIST+=${bang_arch}
}

# check python
python3_version_check() {
cur_python_ver=(`python3 --version`)
stat=$?
if [ ${stat} != 0 ]; then
echo "Not found python3"
exit ${stat}
fi
required_python_version=$(cat build.property|grep "python"|cut -d ':' -f2|cut -d '"' -f2)
if [[ "$(printf '%s\n' "${cur_python_ver[1]}" "${required_python_version}" \
| sort -V | head -n1)" == "${cur_python_ver[1]}" ]]; then
echo "python version should no less than ${required_python_version}"
exit 1
fi
}
python3_version_check

build_requires_version_check() {
# check build_requires
python3 version_pre_check.py check_build_requires
stat=$?
if [ ${stat} != 0 ]; then
exit ${stat}
fi
}

usage () {
echo "USAGE: ./independent_build.sh <options>"
echo
Expand Down Expand Up @@ -99,33 +125,21 @@ usage () {
}

prepare_cntoolkit () {
python2 json_parser.py
output='dependency.txt'
MODULE_VERSION=""
PACKAGE_ARCH="$(uname -m)"

# dep-package-version
PACKAGE_MODULES=`cat $output | awk -F ':' '{print $1}'`
prog_log_info "PACKAGE_MODULES: $PACKAGE_MODULES"

PACKAGE_BRANCH=`cat $output | awk -F ':' '{print $2}'`
prog_log_info "PACKAGE_BRANCH: $PACKAGE_BRANCH"

PACKAGE_MODULE_VERS=`cat $output | awk -F ':' '{print $3}'`
prog_log_info "PACKAGE_MODULE_VERS: $PACKAGE_MODULE_VERS"

PACKAGE_SERVER="http://daily.software.cambricon.com"
PACKAGE_OS="Linux"


arr_modules=(`echo $PACKAGE_MODULES`)
arr_branch=(`echo $PACKAGE_BRANCH`)
arr_vers=(`echo $PACKAGE_MODULE_VERS`)
# read build.property, print cntoolkit and cnnl dep-package-version
build_requires=(`python version_pre_check.py get_build_requires`)
# build_requires is an array(cntoolkit release cntoolkit-version cnnl release cnnl-version)
arr_modules=(${build_requires[0]} ${build_requires[3]})
arr_branch=(${build_requires[1]} ${build_requires[4]})
arr_vers=(${build_requires[2]} ${build_requires[5]})

n=${#arr_vers[@]}

sub_pkg_to_extract=(cncc cnas cnperf cngdb cndrv cnrt cnbin cnpapi cndev cntoolkit-cloud)

if [ -d ${PACKAGE_EXTRACT_DIR} ]; then
rm -rf ${PACKAGE_EXTRACT_DIR}
fi
Expand All @@ -142,7 +156,7 @@ prepare_cntoolkit () {
REAL_PATH=`echo ${PACKAGE_PATH} | awk -F '//' '{print $2}'`
prog_log_info "${arr_modules[$i]} url: ${REAL_PATH}"
wget -A deb -m -p -E -k -K -np -q --reject-regex 'static' ${PACKAGE_PATH}

pushd ${PACKAGE_EXTRACT_DIR} > /dev/null
for filename in ../${REAL_PATH}*.deb; do
dpkg -x --force-overwrite ${filename} .
Expand Down Expand Up @@ -290,7 +304,7 @@ if [ $# != 0 ]; then
export BUILD_JOBS=$1
shift
;;
-t)
-t)
shift
export RELEASE_TYPE=$1
export MLUOP_PACKAGE_INFO_SET="ON"
Expand Down Expand Up @@ -371,6 +385,9 @@ if [ "${MLUOP_BUILD_PREPARE_ONLY}" = "ON" ]; then
exit -1
elif [ "${MLUOP_BUILD_PREPARE}" = "ON" ]; then
prepare_cntoolkit
build_requires_version_check
else
build_requires_version_check
fi

if [ ! -z "${NEUWARE_HOME}" ]; then
Expand Down
19 changes: 0 additions & 19 deletions json_parser.py

This file was deleted.

176 changes: 176 additions & 0 deletions version_pre_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import sys
import json
import os
from distutils.version import LooseVersion

build_file = "build.property"
required_version = {}

# cntoolkit, cnnl
modules = ["cntoolkit", "cnnl"]
# NEUWARE_HOME = env_vars["NEUWARE_HOME"]
env_vars = dict(os.environ)


def get_build_requires(print_mode=1):
global required_version
with open(build_file) as build_property:
data = json.load(build_property)
required_version = data["build_requires"]
for key in modules:
if print_mode == 1:
print(
"%s %s %s"
% (key, required_version[key][0], required_version[key][1])
)
required_version[key] = required_version[key][1].split("-")[0]


def check_cntoolkit():
toolkit_ver_path = env_vars["NEUWARE_HOME"] + "/version.txt"
if not os.path.exists(toolkit_ver_path):
print("Not found toolkit")
exit(2)

# check cntoolkit
with open(toolkit_ver_path) as tk_f:
data = tk_f.readlines()
for line in data:
if "Neuware Version" in line:
cur_tk_ver = line.strip("\n").split(" ")[-1]
if LooseVersion(required_version["cntoolkit"]) > LooseVersion(
cur_tk_ver
):
print(
"The version of cntoolkit must be at least "
+ required_version["cntoolkit"]
+ ", but local version is "
+ cur_tk_ver
)
exit(1)


def check_cnnl():
cnnl_ver_pre = env_vars["NEUWARE_HOME"] + "/lib64/"
if not os.path.exists(cnnl_ver_pre):
print("Not found cnnl")
exit(2)

# check cnnl
for filePath in os.listdir(cnnl_ver_pre):
if "libcnnl.so." in filePath:
tmp = filePath.split(".")
if len(tmp) > 3:
cur_cnnl_ver = filePath[11:]
if LooseVersion(required_version["cnnl"]) > LooseVersion(cur_cnnl_ver):
print(
"The version of cnnl must be at least "
+ required_version["cnnl"]
+ ", but local version is "
+ cur_cnnl_ver
)
exit(1)


def check_driver():
sys_out = os.popen("cnmon version").readline()
if len(sys_out) == 0:
print("Warning: not found cnmon.")
print("If compilation failed, please check driver version")
return

sys_out = sys_out.strip("\n").split(":")[-1]
if LooseVersion(required_version["driver"]) > LooseVersion(sys_out):
print(
"The version of driver must be at least "
+ required_version["driver"]
+ ", but local version is "
+ sys_out
)
exit(1)


def check_protoc():
sys_out = os.popen("protoc --version").readline()
if len(sys_out) == 0:
print("Not found protoc")
exit(2)

sys_out = sys_out.strip("\n").split(" ")[-1]
if LooseVersion(required_version["protoc"]) < LooseVersion(sys_out):
print(
"The version of protoc must be at most "
+ required_version["protoc"]
+ ", but local version is "
+ sys_out
)
exit(1)


def check_libxml2():
sys_out = os.popen("xml2-config --version").readline()
if len(sys_out) == 0:
print("Not found libxml2")
exit(2)

sys_out = sys_out.strip("\n")
if LooseVersion(required_version["libxml2"]) > LooseVersion(sys_out):
print(
"The version of libxml2 must be at least "
+ required_version["libxml2"]
+ ", but local version is "
+ sys_out
)
exit(1)


def check_eigen3():
if os.path.exists("/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h"):
h_file = open("/usr/local/include/eigen3/Eigen/src/Core/util/Macros.h")
elif os.path.exists("/usr/include/eigen3/Eigen/src/Core/util/Macros.h"):
h_file = open("/usr/include/eigen3/Eigen/src/Core/util/Macros.h")
else:
print("Not found eigen3")
exit(2)

line = h_file.readline()
eigen_ver = ""
while len(line) > 0:
if "Eigen version and basic defaults" in line:
line = h_file.readline()
line = h_file.readline()
eigen_ver = h_file.readline()[28:-1]
eigen_ver += "." + h_file.readline()[28:-1]
eigen_ver += "." + h_file.readline()[28:-1]
break
line = h_file.readline()

if LooseVersion(required_version["eigen3"]) > LooseVersion(eigen_ver):
print(
"The version of eigen3 must be at least "
+ required_version["eigen3"]
+ ", but local version is "
+ eigen_ver
)
exit(1)


def check_build_requires():
get_build_requires(0)
check_cntoolkit()
check_cnnl()
check_driver()
check_protoc()
check_libxml2()
check_eigen3()


argvs = sys.argv[1:]
if len(argvs) == 1:
eval(argvs[0])()
elif len(argvs) == 2:
eval(argvs[0])(argvs[1])
elif len(argvs) == 3:
eval(argvs[0])(argvs[1], argvs[2])
else:
exit(3)

0 comments on commit 3f5f16d

Please sign in to comment.