diff --git a/Contribute.md b/Contribute.md index 84e1b2f64..55d2b7e44 100644 --- a/Contribute.md +++ b/Contribute.md @@ -17,11 +17,25 @@ required: ![Benchmarks Directory Structure](benchmarks_directory_structure.png) 2. Next, in the leaf folder that was created in the previous step, you - will need to create a `model_init.py` file: + will need to create `config.json` and `model_init.py` files: - ![Add model init](add_model_init.png) + ![Add model init](add_model_init_and_config.png) - This file is used to initialize the best known configuration for the + The `config.json` file contains the best known KMP environment variable + settings to get optimal performance for the model. Below default settings are recommended for most of + the models in Model Zoo. + + ``` + { + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } + } + ``` + + The `model_init.py` file is used to initialize the best known configuration for the model, and then start executing inference or training. When the [launch script](/docs/general/tensorflow/LaunchBenchmark.md) is run, it will look for the appropriate `model_init.py` file to use @@ -33,7 +47,7 @@ required: [base model init class](/benchmarks/common/base_model_init.py) that includes functions for doing common tasks such as setting up the best known environment variables (like `KMP_BLOCKTIME`, `KMP_SETTINGS`, - `KMP_AFFINITY`, and `OMP_NUM_THREADS`), num intra threads, and num + `KMP_AFFINITY` by loading **config.json** and `OMP_NUM_THREADS`), num intra threads, and num inter threads. The `model_init.py` file also sets up the string that will ultimately be used to run inference or model training, which normally includes the use of `numactl` and sending all of the @@ -93,7 +107,7 @@ Optional step: the original repository, then it can be added to the [models](/models) directory in the zoo repo. As with the first step in the previous section, the directory structure should be setup like: - `/models/////`: + `/models/////`. ![Models Directory Structure](models_directory_structure.png) diff --git a/add_model_init.png b/add_model_init.png deleted file mode 100644 index 6bacd1bb6..000000000 Binary files a/add_model_init.png and /dev/null differ diff --git a/add_model_init_and_config.png b/add_model_init_and_config.png new file mode 100644 index 000000000..ef9b88290 Binary files /dev/null and b/add_model_init_and_config.png differ diff --git a/add_readme.png b/add_readme.png index 4899a9fa3..f28783bad 100644 Binary files a/add_readme.png and b/add_readme.png differ diff --git a/benchmarks/adversarial_networks/tensorflow/dcgan/inference/fp32/config.json b/benchmarks/adversarial_networks/tensorflow/dcgan/inference/fp32/config.json new file mode 100644 index 000000000..dfac18793 --- /dev/null +++ b/benchmarks/adversarial_networks/tensorflow/dcgan/inference/fp32/config.json @@ -0,0 +1,8 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1, + "KMP_HW_SUBSET": "1T" + } +} diff --git a/benchmarks/adversarial_networks/tensorflow/dcgan/inference/fp32/model_init.py b/benchmarks/adversarial_networks/tensorflow/dcgan/inference/fp32/model_init.py index aed323e94..8f4602c2c 100644 --- a/benchmarks/adversarial_networks/tensorflow/dcgan/inference/fp32/model_init.py +++ b/benchmarks/adversarial_networks/tensorflow/dcgan/inference/fp32/model_init.py @@ -37,8 +37,8 @@ def __init__(self, args, custom_args=[], platform_util=None): self.set_num_inter_intra_threads() # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() - set_env_var("KMP_HW_SUBSET", "1T") + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) benchmark_script = os.path.join( self.args.intelai_models, args.mode, args.precision, diff --git a/benchmarks/common/base_model_init.py b/benchmarks/common/base_model_init.py index 6294190d8..9a25ca92a 100644 --- a/benchmarks/common/base_model_init.py +++ b/benchmarks/common/base_model_init.py @@ -18,6 +18,7 @@ # SPDX-License-Identifier: EPL-2.0 # +import json import os @@ -135,14 +136,28 @@ def set_num_inter_intra_threads(self, num_inter_threads=None, num_intra_threads= print("num_inter_threads: {}\nnum_intra_threads: {}".format( self.args.num_inter_threads, self.args.num_intra_threads)) - def set_kmp_vars(self, kmp_settings="1", kmp_blocktime="1", kmp_affinity="granularity=fine,verbose,compact,1,0"): + def set_kmp_vars(self, config_file_path, kmp_settings=None, kmp_blocktime=None, kmp_affinity=None): """ Sets KMP_* environment variables to the specified value, if the environment variable has not already been set. - The default values for this function's args are the most common values that we have seen in the model zoo. + The default values in the json file are the best known settings for the model. """ + if os.path.exists(config_file_path): + with open(config_file_path, 'r') as config: + config_object = json.load(config) + + # First sets default from config file + for param in config_object.keys(): + for env in config_object[param].keys(): + set_env_var(env, config_object[param][env]) + + else: + print("Warning: File {} does not exist and \ + cannot be used to set KMP environment variables".format(config_file_path)) + + # Override user provided envs if kmp_settings: - set_env_var("KMP_SETTINGS", kmp_settings) + set_env_var("KMP_SETTINGS", kmp_settings, overwrite_existing=True) if kmp_blocktime: - set_env_var("KMP_BLOCKTIME", kmp_blocktime) + set_env_var("KMP_BLOCKTIME", kmp_blocktime, overwrite_existing=True) if kmp_affinity: - set_env_var("KMP_AFFINITY", kmp_affinity) + set_env_var("KMP_AFFINITY", kmp_affinity, overwrite_existing=True) diff --git a/benchmarks/content_creation/tensorflow/draw/inference/fp32/config.json b/benchmarks/content_creation/tensorflow/draw/inference/fp32/config.json new file mode 100644 index 000000000..dfac18793 --- /dev/null +++ b/benchmarks/content_creation/tensorflow/draw/inference/fp32/config.json @@ -0,0 +1,8 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1, + "KMP_HW_SUBSET": "1T" + } +} diff --git a/benchmarks/content_creation/tensorflow/draw/inference/fp32/model_init.py b/benchmarks/content_creation/tensorflow/draw/inference/fp32/model_init.py index 390bcae82..08c145bca 100644 --- a/benchmarks/content_creation/tensorflow/draw/inference/fp32/model_init.py +++ b/benchmarks/content_creation/tensorflow/draw/inference/fp32/model_init.py @@ -22,7 +22,6 @@ import os import sys from common.base_model_init import BaseModelInitializer -from common.base_model_init import set_env_var class ModelInitializer(BaseModelInitializer): @@ -32,8 +31,8 @@ def __init__(self, args, custom_args=[], platform_util=None): super(ModelInitializer, self).__init__(args, custom_args, platform_util) # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() - set_env_var("KMP_HW_SUBSET", "1T") + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) if self.args.accuracy_only: print("Accuracy testing for DRAW inference is not supported yet.") diff --git a/benchmarks/face_detection_and_alignment/tensorflow/facenet/inference/fp32/config.json b/benchmarks/face_detection_and_alignment/tensorflow/facenet/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/face_detection_and_alignment/tensorflow/facenet/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/face_detection_and_alignment/tensorflow/facenet/inference/fp32/model_init.py b/benchmarks/face_detection_and_alignment/tensorflow/facenet/inference/fp32/model_init.py index 9bd9c6243..bf4b8132c 100644 --- a/benchmarks/face_detection_and_alignment/tensorflow/facenet/inference/fp32/model_init.py +++ b/benchmarks/face_detection_and_alignment/tensorflow/facenet/inference/fp32/model_init.py @@ -34,7 +34,8 @@ def __init__(self, args, custom_args=[], platform_util=None): self.python_exe + " " # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) pairs_file = os.path.join(self.args.model_source_dir, "data/pairs.txt") diff --git a/benchmarks/face_detection_and_alignment/tensorflow/mtcc/inference/fp32/config.json b/benchmarks/face_detection_and_alignment/tensorflow/mtcc/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/face_detection_and_alignment/tensorflow/mtcc/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/face_detection_and_alignment/tensorflow/mtcc/inference/fp32/model_init.py b/benchmarks/face_detection_and_alignment/tensorflow/mtcc/inference/fp32/model_init.py index 34409b702..4ef889b36 100644 --- a/benchmarks/face_detection_and_alignment/tensorflow/mtcc/inference/fp32/model_init.py +++ b/benchmarks/face_detection_and_alignment/tensorflow/mtcc/inference/fp32/model_init.py @@ -33,7 +33,8 @@ def __init__(self, args, custom_args, platform_util=None): self.set_num_inter_intra_threads() # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) diff --git a/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/fp32/config.json b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/fp32/model_init.py b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/fp32/model_init.py index 064bf7848..641821520 100644 --- a/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/fp32/model_init.py +++ b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/fp32/model_init.py @@ -32,7 +32,8 @@ def __init__(self, args, custom_args=[], platform_util=None): self.cmd = self.get_numactl_command(self.args.socket_id) + self.python_exe + " " # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # use default batch size if -1 if self.args.batch_size == -1: diff --git a/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/int8/config.json b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/int8/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/int8/model_init.py b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/int8/model_init.py index f2e2e1469..0d7dda4db 100644 --- a/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/int8/model_init.py +++ b/benchmarks/image_recognition/tensorflow/inception_resnet_v2/inference/int8/model_init.py @@ -31,7 +31,11 @@ class ModelInitializer(BaseModelInitializer): def __init__(self, args, custom_args=[], platform_util=None): super(ModelInitializer, self).__init__(args, custom_args, platform_util) - self.set_kmp_vars() + + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) + self.cmd = self.get_numactl_command(self.args.socket_id) + "{} ".format(self.python_exe) # use default batch size if -1 diff --git a/benchmarks/image_recognition/tensorflow/inceptionv3/inference/fp32/config.json b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/inceptionv3/inference/fp32/model_init.py b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/fp32/model_init.py index dd504259e..53c2643bd 100644 --- a/benchmarks/image_recognition/tensorflow/inceptionv3/inference/fp32/model_init.py +++ b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/fp32/model_init.py @@ -60,8 +60,10 @@ def __init__(self, args, custom_args=[], platform_util=None): self.args = arg_parser.parse_args(self.custom_args, namespace=self.args) - # Use default KMP variable values, but override the default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime=str(self.args.kmp_blocktime)) + # Set KMP env vars, if they haven't already been set, but override the default KMP_BLOCKTIME value + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path, kmp_blocktime=str(self.args.kmp_blocktime)) + set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) benchmark_script = os.path.join( diff --git a/benchmarks/image_recognition/tensorflow/inceptionv3/inference/int8/config.json b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/int8/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/inceptionv3/inference/int8/model_init.py b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/int8/model_init.py index 6d586ea80..bd4794638 100644 --- a/benchmarks/image_recognition/tensorflow/inceptionv3/inference/int8/model_init.py +++ b/benchmarks/image_recognition/tensorflow/inceptionv3/inference/int8/model_init.py @@ -60,8 +60,9 @@ def parse_args(self): self.args = parser.parse_args(self.custom_args, namespace=self.args) - # Use default KMP variable values, but override the default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime=str(self.args.kmp_blocktime)) + # Set KMP env vars, if they haven't already been set, but override the default KMP_BLOCKTIME value + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path, kmp_blocktime=str(self.args.kmp_blocktime)) def run_benchmark(self): benchmark_script = os.path.join(self.args.intelai_models, diff --git a/benchmarks/image_recognition/tensorflow/inceptionv4/inference/config.json b/benchmarks/image_recognition/tensorflow/inceptionv4/inference/config.json new file mode 100644 index 000000000..6f1228ba7 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/inceptionv4/inference/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/inceptionv4/inference/inceptionv4_model_init.py b/benchmarks/image_recognition/tensorflow/inceptionv4/inference/inceptionv4_model_init.py index c7d546477..d4294a179 100644 --- a/benchmarks/image_recognition/tensorflow/inceptionv4/inference/inceptionv4_model_init.py +++ b/benchmarks/image_recognition/tensorflow/inceptionv4/inference/inceptionv4_model_init.py @@ -38,7 +38,11 @@ def __init__(self, args, custom_args=[], platform_util=None): # Environment variables set_env_var("OMP_NUM_THREADS", platform_util.num_cores_per_socket if self.args.num_cores == -1 else self.args.num_cores) - self.set_kmp_vars(kmp_blocktime="0") + + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) + self.set_num_inter_intra_threads(num_inter_threads=platform_util.num_threads_per_core, num_intra_threads=platform_util.num_cores_per_socket) diff --git a/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/fp32/config.json b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/fp32/config.json new file mode 100644 index 000000000..f0b327528 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/fp32/config.json @@ -0,0 +1,6 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/fp32/model_init.py b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/fp32/model_init.py index e75c72194..d4e3ca5d7 100644 --- a/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/fp32/model_init.py +++ b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/fp32/model_init.py @@ -33,8 +33,9 @@ def __init__(self, args, custom_args=[], platform_util=None): if self.args.batch_size == -1: self.args.batch_size = 128 - # Set KMP env vars (except KMP_SETTINGS is not set) - self.set_kmp_vars(kmp_settings=None) + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # set num_inter_threads and num_intra_threads (override inter threads to 2) self.set_num_inter_intra_threads(num_inter_threads=2) diff --git a/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/int8/config.json b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/int8/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/int8/model_init.py b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/int8/model_init.py index 0823604c0..6f22fd12a 100644 --- a/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/int8/model_init.py +++ b/benchmarks/image_recognition/tensorflow/mobilenet_v1/inference/int8/model_init.py @@ -37,7 +37,8 @@ def __init__(self, args, custom_args=[], platform_util=None): self.cmd = self.get_numactl_command(self.args.socket_id) + "python " # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # Set the num_inter_threads and num_intra_threads self.set_num_inter_intra_threads() diff --git a/benchmarks/image_recognition/tensorflow/resnet101/inference/fp32/config.json b/benchmarks/image_recognition/tensorflow/resnet101/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/resnet101/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/resnet101/inference/fp32/model_init.py b/benchmarks/image_recognition/tensorflow/resnet101/inference/fp32/model_init.py index 5e35e462b..43f862159 100644 --- a/benchmarks/image_recognition/tensorflow/resnet101/inference/fp32/model_init.py +++ b/benchmarks/image_recognition/tensorflow/resnet101/inference/fp32/model_init.py @@ -60,8 +60,10 @@ def __init__(self, args, custom_args=[], platform_util=None): self.args = arg_parser.parse_args(self.custom_args, namespace=self.args) - # Use default KMP variable values, but override the default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime=str(self.args.kmp_blocktime)) + # Set KMP env vars, if they haven't already been set, but override the default KMP_BLOCKTIME value + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path, kmp_blocktime=str(self.args.kmp_blocktime)) + set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) benchmark_script = os.path.join( diff --git a/benchmarks/image_recognition/tensorflow/resnet101/inference/int8/config.json b/benchmarks/image_recognition/tensorflow/resnet101/inference/int8/config.json new file mode 100644 index 000000000..6f1228ba7 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/resnet101/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/resnet101/inference/int8/model_init.py b/benchmarks/image_recognition/tensorflow/resnet101/inference/int8/model_init.py index 5e32d3e92..4bd21a12e 100644 --- a/benchmarks/image_recognition/tensorflow/resnet101/inference/int8/model_init.py +++ b/benchmarks/image_recognition/tensorflow/resnet101/inference/int8/model_init.py @@ -41,8 +41,9 @@ def __init__(self, args, custom_args=[], platform_util=None): set_env_var("OMP_NUM_THREADS", platform_util.num_cores_per_socket if args.num_cores == -1 else args.num_cores) - # Set KMP env vars, but override default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime="0") + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) def parse_args(self): parser = argparse.ArgumentParser() diff --git a/benchmarks/image_recognition/tensorflow/resnet50/inference/fp32/config.json b/benchmarks/image_recognition/tensorflow/resnet50/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/resnet50/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/resnet50/inference/fp32/model_init.py b/benchmarks/image_recognition/tensorflow/resnet50/inference/fp32/model_init.py index a2e6be8a3..4c3dfbd1d 100644 --- a/benchmarks/image_recognition/tensorflow/resnet50/inference/fp32/model_init.py +++ b/benchmarks/image_recognition/tensorflow/resnet50/inference/fp32/model_init.py @@ -61,8 +61,10 @@ def __init__(self, args, custom_args=[], platform_util=None): self.args = arg_parser.parse_args(self.custom_args, namespace=self.args) - # Use default KMP variable values, but override the default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime=str(self.args.kmp_blocktime)) + # Set KMP env vars, if they haven't already been set, but override the default KMP_BLOCKTIME value + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path, kmp_blocktime=str(self.args.kmp_blocktime)) + set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) benchmark_script = os.path.join( diff --git a/benchmarks/image_recognition/tensorflow/resnet50/inference/int8/config.json b/benchmarks/image_recognition/tensorflow/resnet50/inference/int8/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/image_recognition/tensorflow/resnet50/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_recognition/tensorflow/resnet50/inference/int8/model_init.py b/benchmarks/image_recognition/tensorflow/resnet50/inference/int8/model_init.py index 07dfa5d2f..75e9db07c 100644 --- a/benchmarks/image_recognition/tensorflow/resnet50/inference/int8/model_init.py +++ b/benchmarks/image_recognition/tensorflow/resnet50/inference/int8/model_init.py @@ -65,8 +65,9 @@ def parse_args(self): self.args = parser.parse_args(self.custom_args, namespace=self.args) - # Use default KMP variable values, but override the default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime=str(self.args.kmp_blocktime)) + # Set KMP env vars, if they haven't already been set, but override the default KMP_BLOCKTIME value + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path, kmp_blocktime=str(self.args.kmp_blocktime)) def run_benchmark_or_accuracy(self): cmd = os.path.join( diff --git a/benchmarks/image_segmentation/tensorflow/maskrcnn/inference/fp32/config.json b/benchmarks/image_segmentation/tensorflow/maskrcnn/inference/fp32/config.json new file mode 100644 index 000000000..23d5de76e --- /dev/null +++ b/benchmarks/image_segmentation/tensorflow/maskrcnn/inference/fp32/config.json @@ -0,0 +1,8 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1, + "KMP_HW_SUBSET": "1T" + } +} diff --git a/benchmarks/image_segmentation/tensorflow/maskrcnn/inference/fp32/model_init.py b/benchmarks/image_segmentation/tensorflow/maskrcnn/inference/fp32/model_init.py index 1fe96fe2b..43f9cdacc 100644 --- a/benchmarks/image_segmentation/tensorflow/maskrcnn/inference/fp32/model_init.py +++ b/benchmarks/image_segmentation/tensorflow/maskrcnn/inference/fp32/model_init.py @@ -37,8 +37,8 @@ def __init__(self, args, custom_args=[], platform_util=None): self.set_num_inter_intra_threads() # Set KMP env vars, if they haven't already been set - self.set_kmp_vars(kmp_affinity="granularity=fine, compact, 1, 0") - set_env_var("KMP_HW_SUBSET", "1T") + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) benchmark_script = os.path.join( self.args.intelai_models, "coco.py") diff --git a/benchmarks/image_segmentation/tensorflow/unet/inference/fp32/config.json b/benchmarks/image_segmentation/tensorflow/unet/inference/fp32/config.json new file mode 100644 index 000000000..ca15cfe6d --- /dev/null +++ b/benchmarks/image_segmentation/tensorflow/unet/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine, compact", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/image_segmentation/tensorflow/unet/inference/fp32/model_init.py b/benchmarks/image_segmentation/tensorflow/unet/inference/fp32/model_init.py index cd4f5837d..d4998afae 100644 --- a/benchmarks/image_segmentation/tensorflow/unet/inference/fp32/model_init.py +++ b/benchmarks/image_segmentation/tensorflow/unet/inference/fp32/model_init.py @@ -41,7 +41,8 @@ def __init__(self, args, custom_args=[], platform_util=None): self.set_num_inter_intra_threads() # Set KMP env vars, if they haven't already been set - self.set_kmp_vars(kmp_affinity="granularity=fine, compact") + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # Get path to the inference script script_path = os.path.join( diff --git a/benchmarks/language_modeling/tensorflow/lm-1b/inference/fp32/config.json b/benchmarks/language_modeling/tensorflow/lm-1b/inference/fp32/config.json new file mode 100644 index 000000000..8ae78e72a --- /dev/null +++ b/benchmarks/language_modeling/tensorflow/lm-1b/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/language_modeling/tensorflow/lm-1b/inference/fp32/model_init.py b/benchmarks/language_modeling/tensorflow/lm-1b/inference/fp32/model_init.py index 77d903020..6a2b7244f 100644 --- a/benchmarks/language_modeling/tensorflow/lm-1b/inference/fp32/model_init.py +++ b/benchmarks/language_modeling/tensorflow/lm-1b/inference/fp32/model_init.py @@ -35,8 +35,9 @@ def __init__(self, args, custom_args, platform_util=None): self.set_num_inter_intra_threads() - # Set the KMP env vars - self.set_kmp_vars(kmp_blocktime="0", kmp_affinity="granularity=fine,compact,1,0") + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) diff --git a/benchmarks/language_translation/tensorflow/gnmt/inference/fp32/config.json b/benchmarks/language_translation/tensorflow/gnmt/inference/fp32/config.json new file mode 100644 index 000000000..4d0e2acf5 --- /dev/null +++ b/benchmarks/language_translation/tensorflow/gnmt/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/language_translation/tensorflow/gnmt/inference/fp32/model_init.py b/benchmarks/language_translation/tensorflow/gnmt/inference/fp32/model_init.py index 61ef1bda6..a23403eb0 100644 --- a/benchmarks/language_translation/tensorflow/gnmt/inference/fp32/model_init.py +++ b/benchmarks/language_translation/tensorflow/gnmt/inference/fp32/model_init.py @@ -37,8 +37,9 @@ def __init__(self, args, custom_args=[], platform_util=None): (str(self.args.num_cores - 1)) + " " self.cmd += "{} ".format(self.python_exe) - # Set the KMP env vars - self.set_kmp_vars(kmp_affinity="granularity=fine,compact,1,0") + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # use default batch size if -1 if self.args.batch_size == -1: diff --git a/benchmarks/language_translation/tensorflow/transformer_language/inference/fp32/config.json b/benchmarks/language_translation/tensorflow/transformer_language/inference/fp32/config.json new file mode 100644 index 000000000..8ae78e72a --- /dev/null +++ b/benchmarks/language_translation/tensorflow/transformer_language/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/language_translation/tensorflow/transformer_language/inference/fp32/model_init.py b/benchmarks/language_translation/tensorflow/transformer_language/inference/fp32/model_init.py index 20790b541..4e1519e03 100644 --- a/benchmarks/language_translation/tensorflow/transformer_language/inference/fp32/model_init.py +++ b/benchmarks/language_translation/tensorflow/transformer_language/inference/fp32/model_init.py @@ -37,8 +37,9 @@ def __init__(self, args, custom_args, platform_util=None): self.set_num_inter_intra_threads() - # Set the KMP env vars - self.set_kmp_vars(kmp_blocktime="0", kmp_affinity="granularity=fine,compact,1,0") + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) TEMP_DIR = str(self.args.model_source_dir) + "/out_dir" if os.path.exists(TEMP_DIR): diff --git a/benchmarks/language_translation/tensorflow/transformer_lt_official/inference/fp32/config.json b/benchmarks/language_translation/tensorflow/transformer_lt_official/inference/fp32/config.json new file mode 100644 index 000000000..8ae78e72a --- /dev/null +++ b/benchmarks/language_translation/tensorflow/transformer_lt_official/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/language_translation/tensorflow/transformer_lt_official/inference/fp32/model_init.py b/benchmarks/language_translation/tensorflow/transformer_lt_official/inference/fp32/model_init.py index b598191f0..00f8b9f3f 100644 --- a/benchmarks/language_translation/tensorflow/transformer_lt_official/inference/fp32/model_init.py +++ b/benchmarks/language_translation/tensorflow/transformer_lt_official/inference/fp32/model_init.py @@ -36,8 +36,9 @@ def __init__(self, args, custom_args, platform_util=None): self.set_num_inter_intra_threads() - # Set the KMP env vars - self.set_kmp_vars(kmp_blocktime="0", kmp_affinity="granularity=fine,compact,1,0") + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) MODEL_EXEC_DIR = str(self.args.model_source_dir) + "/official/transformer/" diff --git a/benchmarks/object_detection/tensorflow/faster_rcnn/inference/fp32/config.json b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/object_detection/tensorflow/faster_rcnn/inference/fp32/model_init.py b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/fp32/model_init.py index 3e0167f75..a605cc8e3 100644 --- a/benchmarks/object_detection/tensorflow/faster_rcnn/inference/fp32/model_init.py +++ b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/fp32/model_init.py @@ -43,7 +43,8 @@ def __init__(self, args, custom_args, platform_util=None): self.set_num_inter_intra_threads() # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) diff --git a/benchmarks/object_detection/tensorflow/faster_rcnn/inference/int8/config.json b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/int8/config.json new file mode 100644 index 000000000..6f1228ba7 --- /dev/null +++ b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/object_detection/tensorflow/faster_rcnn/inference/int8/model_init.py b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/int8/model_init.py index 749026f3c..705ef72c1 100644 --- a/benchmarks/object_detection/tensorflow/faster_rcnn/inference/int8/model_init.py +++ b/benchmarks/object_detection/tensorflow/faster_rcnn/inference/int8/model_init.py @@ -41,8 +41,9 @@ def __init__(self, args, custom_args=[], platform_util=None): self.args.intelai_models, self.args.mode, self.args.precision, self.RFCN_ACCURACY_SCRIPT) - # Set KMP env vars, except override the default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime="0") + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) self.validate_args() diff --git a/benchmarks/object_detection/tensorflow/rfcn/inference/fp32/config.json b/benchmarks/object_detection/tensorflow/rfcn/inference/fp32/config.json new file mode 100644 index 000000000..d7f51a4c2 --- /dev/null +++ b/benchmarks/object_detection/tensorflow/rfcn/inference/fp32/config.json @@ -0,0 +1,6 @@ +{ + "optimization_parameters": { + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/object_detection/tensorflow/rfcn/inference/fp32/model_init.py b/benchmarks/object_detection/tensorflow/rfcn/inference/fp32/model_init.py index 712da5777..a4ab51dfa 100644 --- a/benchmarks/object_detection/tensorflow/rfcn/inference/fp32/model_init.py +++ b/benchmarks/object_detection/tensorflow/rfcn/inference/fp32/model_init.py @@ -45,8 +45,9 @@ def __init__(self, args, custom_args, platform_util): self.args.intelai_models, self.args.mode, self.args.precision, "eval.py") - # Set KMP env vars, except override the default KMP_BLOCKTIME and KMP_AFFINITY values - self.set_kmp_vars(kmp_blocktime="0", kmp_affinity=None) + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) self.run_inference_sanity_checks(self.args, self.custom_args) self.parse_custom_args() diff --git a/benchmarks/object_detection/tensorflow/rfcn/inference/int8/config.json b/benchmarks/object_detection/tensorflow/rfcn/inference/int8/config.json new file mode 100644 index 000000000..6f1228ba7 --- /dev/null +++ b/benchmarks/object_detection/tensorflow/rfcn/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/object_detection/tensorflow/rfcn/inference/int8/model_init.py b/benchmarks/object_detection/tensorflow/rfcn/inference/int8/model_init.py index eec69455d..d6cb2cc97 100755 --- a/benchmarks/object_detection/tensorflow/rfcn/inference/int8/model_init.py +++ b/benchmarks/object_detection/tensorflow/rfcn/inference/int8/model_init.py @@ -54,8 +54,9 @@ def __init__(self, args, custom_args=[], platform_util=None): self.parse_args() - # Set KMP env vars with defaults, except for KMP_BLOCKTIME - self.set_kmp_vars(kmp_blocktime=0) + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # Set num_inter_threads and num_intra_threads self.set_num_inter_intra_threads() diff --git a/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/fp32/config.json b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/fp32/config.json new file mode 100644 index 000000000..6f1228ba7 --- /dev/null +++ b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/fp32/model_init.py b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/fp32/model_init.py index 379e47c67..585d3ed0e 100644 --- a/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/fp32/model_init.py +++ b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/fp32/model_init.py @@ -44,8 +44,9 @@ def __init__(self, args, custom_args, platform_util): self.run_inference_sanity_checks(self.args, self.custom_args) self.research_dir = os.path.join(args.model_source_dir, "research") - # Set KMP env vars, except override the default KMP_BLOCKTIME value - self.set_kmp_vars(kmp_blocktime="0") + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # set num_inter_threads and num_intra_threads (override inter threads to 2) self.set_num_inter_intra_threads(num_inter_threads=2) diff --git a/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/int8/config.json b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/int8/config.json new file mode 100644 index 000000000..6f1228ba7 --- /dev/null +++ b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/int8/model_init.py b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/int8/model_init.py index 5959abaf2..57114447a 100644 --- a/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/int8/model_init.py +++ b/benchmarks/object_detection/tensorflow/ssd-mobilenet/inference/int8/model_init.py @@ -31,7 +31,10 @@ class ModelInitializer(BaseModelInitializer): def __init__(self, args, custom_args=[], platform_util=None): super(ModelInitializer, self).__init__(args, custom_args, platform_util) - self.set_kmp_vars(kmp_blocktime="0") + + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # set num_inter_threads and num_intra_threads (override inter threads to 2) self.set_num_inter_intra_threads(num_inter_threads=2) diff --git a/benchmarks/object_detection/tensorflow/ssd-resnet34/inference/fp32/config.json b/benchmarks/object_detection/tensorflow/ssd-resnet34/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/object_detection/tensorflow/ssd-resnet34/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/object_detection/tensorflow/ssd-resnet34/inference/fp32/model_init.py b/benchmarks/object_detection/tensorflow/ssd-resnet34/inference/fp32/model_init.py index 0e6657a11..1ad534ed9 100644 --- a/benchmarks/object_detection/tensorflow/ssd-resnet34/inference/fp32/model_init.py +++ b/benchmarks/object_detection/tensorflow/ssd-resnet34/inference/fp32/model_init.py @@ -42,7 +42,11 @@ def __init__(self, args, custom_args, platform_util): super(ModelInitializer, self).__init__(args, custom_args, platform_util) self.run_inference_sanity_checks(self.args, self.custom_args) - self.set_kmp_vars() + + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) + self.set_num_inter_intra_threads() set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) diff --git a/benchmarks/recommendation/tensorflow/ncf/inference/fp32/config.json b/benchmarks/recommendation/tensorflow/ncf/inference/fp32/config.json new file mode 100644 index 000000000..273b45b40 --- /dev/null +++ b/benchmarks/recommendation/tensorflow/ncf/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/recommendation/tensorflow/ncf/inference/fp32/model_init.py b/benchmarks/recommendation/tensorflow/ncf/inference/fp32/model_init.py index 1b6eb1eda..1704839cb 100644 --- a/benchmarks/recommendation/tensorflow/ncf/inference/fp32/model_init.py +++ b/benchmarks/recommendation/tensorflow/ncf/inference/fp32/model_init.py @@ -40,7 +40,8 @@ def __init__(self, args, custom_args=[], platform_util=None): self.args.batch_size = 256 # Set KMP env vars, if they haven't already been set - self.set_kmp_vars() + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # set num_inter_threads and num_intra_threads self.set_num_inter_intra_threads() diff --git a/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/fp32/config.json b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/fp32/config.json new file mode 100644 index 000000000..4efe60b15 --- /dev/null +++ b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/fp32/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "noverbose,warnings,respect,granularity=core,none", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/fp32/model_init.py b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/fp32/model_init.py index 8f3e15359..6655dce85 100755 --- a/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/fp32/model_init.py +++ b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/fp32/model_init.py @@ -36,9 +36,10 @@ def __init__(self, args, custom_args=[], platform_util=None): # Set the num_inter_threads and num_intra_threads self.set_num_inter_intra_threads(num_inter_threads=platform_util.num_cores_per_socket, num_intra_threads=1) - # Use default KMP AFFINITY values, override KMP_BLOCKTIME & enable KMP SETTINGS - self.set_kmp_vars(kmp_settings="1", kmp_blocktime="0", - kmp_affinity="noverbose,warnings,respect,granularity=core,none") + + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # Set env vars, if they haven't already been set set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) diff --git a/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/int8/config.json b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/int8/config.json new file mode 100644 index 000000000..4efe60b15 --- /dev/null +++ b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/int8/config.json @@ -0,0 +1,7 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "noverbose,warnings,respect,granularity=core,none", + "KMP_BLOCKTIME": 0, + "KMP_SETTINGS": 1 + } +} diff --git a/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/int8/model_init.py b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/int8/model_init.py index 2bd55b5a5..9fdef4537 100755 --- a/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/int8/model_init.py +++ b/benchmarks/recommendation/tensorflow/wide_deep_large_ds/inference/int8/model_init.py @@ -36,9 +36,10 @@ def __init__(self, args, custom_args=[], platform_util=None): # Set the num_inter_threads and num_intra_threads self.set_num_inter_intra_threads(num_inter_threads=platform_util.num_cores_per_socket, num_intra_threads=1) - # Use default KMP AFFINITY values, override KMP_BLOCKTIME & enable KMP SETTINGS - self.set_kmp_vars(kmp_settings="1", kmp_blocktime="0", - kmp_affinity="noverbose,warnings,respect,granularity=core,none") + + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) # Set env vars, if they haven't already been set set_env_var("OMP_NUM_THREADS", self.args.num_intra_threads) diff --git a/benchmarks/text_to_speech/tensorflow/wavenet/inference/fp32/config.json b/benchmarks/text_to_speech/tensorflow/wavenet/inference/fp32/config.json new file mode 100644 index 000000000..f0b327528 --- /dev/null +++ b/benchmarks/text_to_speech/tensorflow/wavenet/inference/fp32/config.json @@ -0,0 +1,6 @@ +{ + "optimization_parameters": { + "KMP_AFFINITY": "granularity=fine,verbose,compact,1,0", + "KMP_BLOCKTIME": 1 + } +} diff --git a/benchmarks/text_to_speech/tensorflow/wavenet/inference/fp32/model_init.py b/benchmarks/text_to_speech/tensorflow/wavenet/inference/fp32/model_init.py index 91ebe227c..1756e33ae 100644 --- a/benchmarks/text_to_speech/tensorflow/wavenet/inference/fp32/model_init.py +++ b/benchmarks/text_to_speech/tensorflow/wavenet/inference/fp32/model_init.py @@ -32,8 +32,9 @@ def __init__(self, args, custom_args, platform_util): self.command = "" command_prefix = "{} generate.py".format(self.python_exe) - # Set default KMP env vars, except for KMP_SETTINGS - self.set_kmp_vars(kmp_settings=None) + # Set KMP env vars, if they haven't already been set + config_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "config.json") + self.set_kmp_vars(config_file_path) self.parse_custom_args() # Set the num_inter_threads and num_intra_threads (override inter threads to 1) diff --git a/tests/unit/common/test_base_model_init.py b/tests/unit/common/test_base_model_init.py index 43f3076f1..979a6ac4c 100644 --- a/tests/unit/common/test_base_model_init.py +++ b/tests/unit/common/test_base_model_init.py @@ -17,8 +17,22 @@ # # SPDX-License-Identifier: EPL-2.0 # - +from contextlib import contextmanager import os +import pytest +import sys +import tempfile + +try: + # python 2 + from cStringIO import StringIO +except ImportError: + # python 3 + # only supports unicode so can't be used in python 2 for sys.stdout + # because (from `print` documentation) + # "All non-keyword arguments are converted to strings like str() does" + from io import StringIO + from mock import MagicMock, patch @@ -26,6 +40,22 @@ from benchmarks.common.base_model_init import set_env_var +@contextmanager +def catch_stdout(): + _stdout = sys.stdout + sys.stdout = caught_output = StringIO() + try: + yield caught_output + finally: + sys.stdout = _stdout + caught_output.close() + + +@pytest.fixture +def mock_json(patch): + return patch('json') + + # Example args and output strings for testing mocks test_model_name = "resnet50" test_framework = "tensorflow" @@ -109,3 +139,34 @@ def test_env_var_not_already_set(): finally: if os.environ.get(env_var): del os.environ[env_var] + + +def test_set_kmp_vars_config_json_does_not_exists(): + """Test config.json does not exist""" + # Setup base model init with test settings + platform_util = MagicMock() + args = MagicMock(verbose=True, model_name=test_model_name) + os.environ["PYTHON_EXE"] = "python" + base_model_init = BaseModelInitializer(args, [], platform_util) + + config_file_path = '/test/foo/config.json' + + with catch_stdout() as caught_output: + base_model_init.set_kmp_vars(config_file_path) + output = caught_output.getvalue() + + assert "Warning: File {} does not exist and \ + cannot be used to set KMP environment variables".format(config_file_path) == output.strip() + + +def test_set_kmp_vars_config_json_exists(mock_json): + """Test config.json when exists""" + # Setup base model init with test settings + platform_util = MagicMock() + args = MagicMock(verbose=True, model_name=test_model_name) + os.environ["PYTHON_EXE"] = "python" + base_model_init = BaseModelInitializer(args, [], platform_util) + + file_descriptor, config_file_path = tempfile.mkstemp(suffix=".json") + + base_model_init.set_kmp_vars(config_file_path)