From c45e839361e2621b7e893eeb6899225b9ef5470f Mon Sep 17 00:00:00 2001 From: zofia <110436990+zufangzhu@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:01:26 +0800 Subject: [PATCH] [Docker] update for driver version (#2719) --- docker/README.md | 4 +- docker/build.sh | 14 ++-- docker/itex-xpu.Dockerfile | 2 +- tools/python/config.json | 142 ++++++++++++++++++++++++------------- tools/python/env_check.py | 128 ++++++++++++++++++--------------- 5 files changed, 173 insertions(+), 117 deletions(-) diff --git a/docker/README.md b/docker/README.md index d4b32e6c..aa26bc0a 100644 --- a/docker/README.md +++ b/docker/README.md @@ -31,13 +31,13 @@ wget 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!") + exit("\033[31mYour Python version is too high, please downgrade to 3.\033[0m" + + str(config['python_version']['max_python_version'][itex_version]) + "\033[31m or lower!\033[0m") print("\t Python " + str(python_major_version) + "." + str(python_minor_version) + "." + str(python_micro_version) + " is Supported.") - print("Check Python Passed\n") + print("\033[32mCheck Python Passed\033[0m\n") return itex_version -def check_os(): +def check_os(config, itex_version): print("Check OS") + import platform system_type = platform.system() if system_type != 'Linux': - exit("We only Support Linux System\n") + exit("\033[31mWe only Support Linux System!\033[0m\n") with open('/etc/os-release', 'r') as f: for line in f: @@ -67,29 +61,35 @@ def check_os(): 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") + exit("\033[31mIntel GPU Driver Does Not Support OS \033[0m" + os_id + " : " + os_version + "\n \033[33mCheck OS failed. \033[0m\n") + print("\033[32mCheck OS Passed\033[0m\n") return os_id, os_version -def check_tensorflow(): +def check_tensorflow(config, itex_version): print("Check Tensorflow") + import subprocess + import importlib + import os tf_found = importlib.util.find_spec("tensorflow") if tf_found is None: - exit("Please Install TensorFlow first.\n") + exit("\033[31mPlease Install TensorFlow first.\033[0m\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] + #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] + import tensorflow as tf + tf_version = tf.__version__ + print("\tTensorflow " + tf_version + " is installed.") 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(): +def check_driver(config, os_id): print("Check Intel GPU Driver") + import os # tf_version = str(res.stdout)[14:20] if os_id == "ubuntu": cmd = "dpkg -s " @@ -99,49 +99,65 @@ def check_driver(): elif os_id == "sles": cmd = "zypper se --installed-only " else: - exit("Unsupported OS \n Check Intel GPU Driver Failed\n") + exit("\033[31mUnsupported OS \n Check Intel GPU Driver Failed\033[0m\n") for driver in config['intel_gpu_driver_list'][os_id]: if os.system(cmd + driver) != 0: - exit("\tCheck Intel GPU Driver Failed\n") + exit("\033[31m\tCheck Intel GPU Driver Failed\033[0m\n") print("Check Intel GPU Driver Passsed\n") -def check_oneapi(): +def check_oneapi(config, itex_version): print("Check OneAPI") + import subprocess + import os 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" ) + for oneapi in config['oneapi']: + for lib in config['oneapi_lib'][oneapi]: + cmd = 'grep ' + lib + ' /tmp/log' + res = os.system(cmd) + if res != 0: + exit("\033[31m\tCan't find \033[0m" + lib + "\n\033[31m Check OneAPI Failed\033[0m\n" ) print("\t" + config['oneapi'][oneapi] + " is Installed.") - print("Check OneAPI Passed\n") + print("Recommended " + oneapi + " version is " + config['oneapi_version'][itex_version][oneapi]) + print("\033[32mCheck OneAPI Passed\033[0m\n") -def check_py_lib(): +def check_py_lib(config): print("Check Tensorflow Requirements\n") + import importlib 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") + print("\t" + lib + "\033[31m should be installed.\033[0m") + print("\033[32mCheck Intel(R) Extension for TensorFlow* Requirements Passed\033[0m") 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("\t" + lib + "\033[31m should be installed.\033[0m") print("\n") -if __name__ == '__main__': +def check(): print("\nCheck Environment for Intel(R) Extension for TensorFlow*...\n") + print('__file__: ', __file__) + import configparser + import os + + # the latest version url="https://raw.githubusercontent.com/intel/intel-extension-for-tensorflow/master/tools/python/config.json" - configfile="./config.json" + + # the local version + configfile="config.json" + configfile_path=os.path.dirname(__file__) + os.sep + configfile os_id="" - config = getConfig(url) - itex_version = check_python() - os_id, os_version = check_os() - check_tensorflow() - check_driver() - check_oneapi() - check_py_lib() + config = getConfig(url, configfile_path) + itex_version = check_python(config) + os_id, os_version = check_os(config, itex_version) + check_tensorflow(config, itex_version) + check_driver(config, os_id) + check_oneapi(config, itex_version) + check_py_lib(config) + +if __name__ == '__main__': + check() \ No newline at end of file