Skip to content

Commit

Permalink
[feature](mlu-ops): fix the check of protoc version
Browse files Browse the repository at this point in the history
  • Loading branch information
chqy99 committed Jan 19, 2024
1 parent bc1cc23 commit f69353b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ MLU-OPS 提供了以下功能:
- 寒武纪 MLU 驱动:
- 运行时依赖驱动 v5.10.15 或更高版本
- 外部链接库:
- libxml2-dev、libprotobuf-dev<=3.8.0、protobuf-compiler<=3.8.0、llvm-6.0-dev、libeigen3-dev>=3.4
- libxml2-dev、libprotobuf-dev、protobuf-compiler、llvm-6.0-dev、libeigen3-dev>=3.4
- Python环境:
- 依赖Python-3版本(默认版本 python 3.8.0,最低要求 python 3.6.0)

Expand Down
2 changes: 1 addition & 1 deletion build.property
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"driver": "5.10.15",
"eigen3": "3.4.0",
"libxml2": "2.9.0",
"protoc": "3.8.0"},
"protoc": "3.6.0"},
"package_type": ["rpm","deb"]
}
79 changes: 48 additions & 31 deletions version_pre_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def get_build_requires(print_mode=1):
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)
print("Warning: Not found toolkit")
return 2

# check cntoolkit
with open(toolkit_ver_path) as tk_f:
Expand All @@ -42,19 +42,21 @@ def check_cntoolkit():
cur_tk_ver
):
print(
"The version of cntoolkit must be at least "
"Warning: The version of cntoolkit needs to be at least "
+ required_version["cntoolkit"]
+ ", but local version is "
+ cur_tk_ver
)
exit(1)
return 1

return 0


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)
print("Warning: Not found cnnl")
return 2

# check cnnl
for filePath in os.listdir(cnnl_ver_pre):
Expand All @@ -64,64 +66,71 @@ def check_cnnl():
cur_cnnl_ver = filePath[11:]
if LooseVersion(required_version["cnnl"]) > LooseVersion(cur_cnnl_ver):
print(
"The version of cnnl must be at least "
"Warning: The version of cnnl needs to be at least "
+ required_version["cnnl"]
+ ", but local version is "
+ cur_cnnl_ver
)
exit(1)
return 1

return 0


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
return 2

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 "
"Warning: The version of driver needs to be at least "
+ required_version["driver"]
+ ", but local version is "
+ sys_out
)
exit(1)
return 1

return 0


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

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

return 0


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

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

return 0


def check_eigen3():
Expand All @@ -130,8 +139,8 @@ def check_eigen3():
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)
print("Warning: Not found eigen3")
return 2

line = h_file.readline()
eigen_ver = ""
Expand All @@ -147,22 +156,30 @@ def check_eigen3():

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

return 0


def check_build_requires():
get_build_requires(0)
check_cntoolkit()
check_cnnl()
check_driver()
check_protoc()
check_libxml2()
check_eigen3()
if check_cntoolkit() != 0:
print("If compilation failed, please check cntoolkit version")
if check_cnnl() != 0:
print("If compilation failed, please check cnnl version")
if check_driver() != 0:
print("If compilation failed, please check driver version")
if check_protoc() != 0:
print("If compilation failed, please check protoc version")
if check_libxml2() != 0:
print("If compilation failed, please check libxml2 version")
if check_eigen3() != 0:
print("If compilation failed, please check eigen3 version")


argvs = sys.argv[1:]
Expand Down

0 comments on commit f69353b

Please sign in to comment.