-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathenv_check.py
147 lines (129 loc) · 5.17 KB
/
env_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import configparser
import importlib.util
import json
import os
import platform
import pip
import sys
import subprocess
import wget
def getConfig(url):
filename = './local_config.json'
if os.path.exists(filename) is False:
wget.download(url, filename)
with open(filename, 'r') as f:
config = json.load(f)
return config
def check_python():
print("Check Python")
itex_found = importlib.util.find_spec("intel_extension_for_tensorflow")
if itex_found is None:
exit("Please Install Intel(R) Extension for TensorFlow* first.\n")
location = ''.join(itex_found.submodule_search_locations) + "/python/"
sys.path.append(location)
try:
from version import __version__
if __version__ > config['latest_release']:
itex_version = "latest"
else:
itex_version = __version__
except Exception:
print("Intel(R) Extension for TensorFlow* Version is Unknown.\n")
python_major_version = sys.version_info.major
python_minor_version = sys.version_info.minor
python_micro_version = sys.version_info.micro
if python_major_version < 2 :
exit("Python2 is not supported, please install Python3!")
elif python_minor_version < config['python_version']['min_python_version'][itex_version]:
exit("Your Python version is too low, please upgrade to 3." +
str(config['python_version']['min_python_version'][itex_version]) + " or higher!")
elif python_minor_version > config['python_version']['max_python_version'][itex_version]:
exit("Your Python version is too high, please downgrade to 3." +
str(config['python_version']['max_python_version'][itex_version]) + " or lower!")
print("\t Python " + str(python_major_version) + "." + str(python_minor_version) + "." +
str(python_micro_version) + " is Supported.")
print("Check Python Passed\n")
return itex_version
def check_os():
print("Check OS")
system_type = platform.system()
if system_type != 'Linux':
exit("We only Support Linux System\n")
with open('/etc/os-release', 'r') as f:
for line in f:
if line.startswith('NAME='):
os_id = line.strip().split('=')[1].lower().strip('"')
if line.startswith('VERSION_ID='):
os_version = line.strip().split('=')[1].strip('"')
if os_id in config['os_list']:
if os_version in config['os_version'][os_id][itex_version]:
print("\tOS " + os_id + ":" + os_version + " is Supported")
else:
exit("Intel GPU Driver Does Not Support OS " + os_id + " : " + os_version + "\n Check OS failed. \n")
print("Check OS Passed\n")
return os_id, os_version
def check_tensorflow():
print("Check Tensorflow")
tf_found = importlib.util.find_spec("tensorflow")
if tf_found is None:
exit("Please Install TensorFlow first.\n")
file = ''.join(tf_found.submodule_search_locations) + "/tools/pip_package/setup.py"
cmd = "cat " + file + '|grep "_VERSION ="'
res = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
tf_version = str(res.stdout)[14:20]
if tf_version < config['tensorflow_version']['min_tensorflow_version'][itex_version]:
exit("Your Tensorflow version is too low, please upgrade to " +
str(config['tensorflow_version']['min_tensorflow_version'][itex_version]) + "!")
print("\tTensorflow " + tf_version + " is installed.")
print("Check Tensorflow Passed\n")
def check_driver():
print("Check Intel GPU Driver")
# tf_version = str(res.stdout)[14:20]
if os_id == "ubuntu":
cmd = "dpkg -s "
elif os_id == "rhel":
cmd = "yum info installed "
print(res)
elif os_id == "sles":
cmd = "zypper se --installed-only "
else:
exit("Unsupported OS \n Check Intel GPU Driver Failed\n")
for driver in config['intel_gpu_driver_list'][os_id]:
if os.system(cmd + driver) != 0:
exit("\tCheck Intel GPU Driver Failed\n")
print("Check Intel GPU Driver Passsed\n")
def check_oneapi():
print("Check OneAPI")
cmd = 'LD_DEBUG=libs python -c "import intel_extension_for_tensorflow" 2>&1 |tee /tmp/log'
subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for oneapi in config['oneapi_lib']:
cmd = 'grep ' + oneapi + ' /tmp/log'
res = os.system(cmd)
if res != 0:
exit("\tCan't find " + oneapi + "\n Check OneAPI Failed\n" )
print("\t" + config['oneapi'][oneapi] + " is Installed.")
print("Check OneAPI Passed\n")
def check_py_lib():
print("Check Tensorflow Requirements\n")
for lib in config['tf_requirements']:
lib_found = importlib.util.find_spec(lib)
if lib_found is None:
print("\t" + lib + " should be installed.")
print("Check Intel(R) Extension for TensorFlow* Requirements")
for lib in config['itex_requirements']:
lib_found = importlib.util.find_spec(lib)
if lib_found is None:
print("\t" + lib + " should be installed.")
print("\n")
if __name__ == '__main__':
print("\nCheck Environment for Intel(R) Extension for TensorFlow*...\n")
url="https://raw.githubusercontent.com/intel/intel-extension-for-tensorflow/master/tools/python/config.json"
configfile="./config.json"
os_id=""
config = getConfig(url)
itex_version = check_python()
os_id, os_version = check_os()
check_tensorflow()
check_driver()
check_oneapi()
check_py_lib()