Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix core binding strategies for different cpu topologies #143

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ output/
tools/docker/models*
.ipynb_checkpoints
nc_workspace

benchmarks/horovod
data_connector/credentials.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "models/aidd/pytorch/alphafold2/inference/alphafold"]
path = models/aidd/pytorch/alphafold2/inference/alphafold
url = https://github.com/deepmind/alphafold
8 changes: 5 additions & 3 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

# These owners will be the default owners for everything in the repo,
# but PR owner should be able to assign other contributors when appropriate
* @ashahba @claynerobison @dmsuehir
* [email protected] @ashahba @claynerobison
datasets @ashahba @claynerobison @dzungductran
docs @claynerobison @mhbuehler
k8s @ashahba @dzungductran @kkasravi
models @agramesh1 @ashraf-bhuiyan @riverliuintel @wei-v-wang
k8s @ashahba @dzungductran
models @ashraf-bhuiyan @riverliuintel
models @riverliuintel
models/**/pytorch/ @leslie-fang-intel @jiayisunx @zhuhaozhe
quickstart [email protected]
quickstart/**/pytorch/ @leslie-fang-intel @jiayisunx @zhuhaozhe

# Order is important. The last matching pattern has the most precedence.
Expand Down
187 changes: 117 additions & 70 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Please report security issues or vulnerabilities to the [Intel® Security Center
For more information on how Intel® works to resolve security issues, see
[Vulnerability Handling Guidelines].

[Intel® Security Center]:https://www.intel.com/security
[Intel® Security Center]:https://www.intel.com/content/www/us/en/security-center/default.html

[Vulnerability Handling Guidelines]:https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html
203 changes: 85 additions & 118 deletions benchmarks/README.md

Large diffs are not rendered by default.

36 changes: 31 additions & 5 deletions benchmarks/common/base_benchmark_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018-2019 Intel Corporation
# Copyright (c) 2018-2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -68,8 +68,8 @@ def _define_args(self):

self._common_arg_parser.add_argument(
"-p", "--precision",
help="Specify the model precision to use: fp32, int8, or bfloat16",
required=required_arg, choices=["fp32", "int8", "bfloat16"],
help="Specify the model precision to use: fp32, int8, bfloat16 or fp16",
required=required_arg, choices=["fp32", "int8", "bfloat16", "fp16"],
dest="precision")

self._common_arg_parser.add_argument(
Expand Down Expand Up @@ -170,6 +170,10 @@ def _define_args(self):
"--weight-sharing",
help="Enables experimental weight-sharing feature for RN50 int8/bf16 inference only",
dest="weight_sharing", action="store_true")
self._common_arg_parser.add_argument(
"--synthetic-data",
help="Enables synthetic data layer for some models like SSD-ResNet34 where support exists",
dest="synthetic_data", action="store_true")

self._common_arg_parser.add_argument(
"-c", "--checkpoint",
Expand Down Expand Up @@ -224,6 +228,13 @@ def _define_args(self):
dest="experimental_gelu", choices=["True", "False"],
default=False)

self._common_arg_parser.add_argument(
"--amp",
help="use grappler auto-mixed precision as opposed to \
keras mixed precision",
dest="amp", choices=["True", "False"],
default=False)

# Note this can't be a normal boolean flag, because we need to know when the user
# does not explicitly set the arg value so that we can apply the appropriate
# default value, depending on the the precision.
Expand Down Expand Up @@ -270,6 +281,12 @@ def _define_args(self):
help="Additional command line arguments (prefix flag start with"
" '--').")

# Check if GPU is enabled.
self._common_arg_parser.add_argument(
"--gpu",
help="Run the benchmark script using GPU",
dest="gpu", action="store_true")

def _validate_args(self):
"""validate the args and initializes platform_util"""
# check if socket id is in socket number range
Expand Down Expand Up @@ -300,8 +317,9 @@ def _validate_args(self):
format(system_num_cores))

if args.output_results and ((args.model_name != "resnet50" and
args.model_name != "resnet50v1_5") or args.precision != "fp32"):
raise ValueError("--output-results is currently only supported for resnet50 FP32 inference.")
args.model_name != "resnet50v1_5") or
(args.precision != "fp32" and args.precision != "fp16")):
raise ValueError("--output-results is currently only supported for resnet50 FP32 or FP16 inference.")
elif args.output_results and (args.mode != "inference" or not args.data_location):
raise ValueError("--output-results can only be used when running inference with a dataset.")

Expand Down Expand Up @@ -344,6 +362,14 @@ def _validate_args(self):
"This is less than the number of cores per socket on the system ({})".
format(args.socket_id, cpuset_len_for_socket, self._platform_util.num_cores_per_socket))

if args.gpu:
if args.socket_id != -1:
raise ValueError("--socket-id cannot be used with --gpu parameter.")
if args.num_intra_threads is not None:
raise ValueError("--num-intra-threads cannot be used with --gpu parameter.")
if args.num_inter_threads is not None:
raise ValueError("--num-inter-threads cannot be used with --gpu parameter.")

def initialize_model(self, args, unknown_args):
"""Create model initializer for the specified model"""
model_initializer = None
Expand Down
45 changes: 31 additions & 14 deletions benchmarks/common/platform_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _get_list_from_string_ranges(self, str_ranges):
start, end = section.split("-")
section_list = range(int(start), int(end) + 1)
result_list += section_list
elif(len(section)):
elif len(section):
# This section is either empty or just a single number and not a range
result_list.append(int(section))

Expand All @@ -253,6 +253,33 @@ def _get_cpuset(self):
print("cpuset.cpus: {}".format(cpuset))
return cpuset

def get_cpu_cores(self):
with open('/proc/cpuinfo', 'r') as f:
lines = f.readlines()
cpu_cores = {}
bind_cpu_cores = []
core_id = None
numa_id = None
for line in lines:
if line.startswith('processor'):
cpu_id = int(line.split(':')[-1].strip())
elif line.startswith('physical id'):
numa_id = int(line.split(':')[-1].strip())
elif line.startswith('core id'):
core_id = int(line.split(':')[-1].strip())
if numa_id not in cpu_cores:
cpu_cores[numa_id] = {}
if core_id not in cpu_cores[numa_id]:
cpu_cores[numa_id][core_id] = []
cpu_cores[numa_id][core_id].append(cpu_id)

for numa_id, cores in cpu_cores.items():
numa_slice = []
for core_id, cpu_ids in cores.items():
numa_slice.append(str(cpu_ids[0]))
bind_cpu_cores.append(numa_slice)
return bind_cpu_cores

def linux_init(self):
lscpu_cmd = "lscpu"
try:
Expand Down Expand Up @@ -326,17 +353,7 @@ def linux_init(self):
if self.num_numa_nodes > 0 and self.args.numa_cores_per_instance is not None:
try:
# Get the list of cores
cpu_array_command = \
"numactl -H | grep 'node [0-9]* cpus:' |" \
"sed 's/.*node [0-9]* cpus: *//' | head -{0} |cut -f1-{1} -d' '".format(
self.num_numa_nodes, int(cores_per_node))
cpu_array = subprocess.Popen(
cpu_array_command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines()

for node_cpus in cpu_array:
node_cpus = str(node_cpus).lstrip("b'").replace("\\n'", " ")
self.cpu_core_list.append([x for x in node_cpus.split(" ") if x != ''])
self.cpu_core_list = self.get_cpu_cores()

# If we have the cpuset list, cross check that list with our core list and
# remove cores that are not part of the cpuset list
Expand All @@ -348,8 +365,8 @@ def linux_init(self):
print("Core list: {}".format(self.cpu_core_list), flush=True)

except Exception as e:
print("Warning: An error occured when getting the list of cores using '{}':\n {}".
format(cpu_array_command, e))
print("Warning: An error occured when getting the list of cores:\n {}".
format(e))

if self.cpuset_cpus is not None:
# Reformat the cpuset_cpus list so that it's split up by node
Expand Down
Loading