Skip to content

Commit 3aef98e

Browse files
committed
Modify OMP env variables setting
1 parent d144bd8 commit 3aef98e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

runner.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def is_ht_enabled():
9797
with open(args.config.name, 'r') as config_file:
9898
config = json.load(config_file)
9999

100+
if 'omp_env' not in config.keys():
101+
config['omp_env'] = []
102+
100103
# make directory for data if it doesn't exist
101104
os.makedirs('data', exist_ok=True)
102105

@@ -168,6 +171,11 @@ def is_ht_enabled():
168171
cpu_count = multiprocessing.cpu_count()
169172
omp_num_threads = str(cpu_count // 2) if is_ht_enabled() else str(cpu_count)
170173

174+
omp_env = {
175+
'OMP_PLACES': f'{{0}}:{cpu_count}:1',
176+
'OMP_NUM_THREADS': omp_num_threads
177+
}
178+
171179
# get parameters that are common for all cases
172180
common_params = config['common']
173181
for params_set in config['cases']:
@@ -261,8 +269,8 @@ class GenerationArgs:
261269
for lib in libs:
262270
env = os.environ.copy()
263271
if lib == 'xgboost':
264-
env['OMP_NUM_THREADS'] = omp_num_threads
265-
272+
for var in config['omp_env']:
273+
env[var] = omp_env[var]
266274
for i, case in enumerate(cases):
267275
command = f'python {lib}/{algorithm}.py --batch {batch} ' \
268276
+ f'--arch {hostname} --header --output-format ' \

xgboost/gbt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
import numpy as np
1111
import xgboost as xgb
12+
import os
1213

1314

1415
def convert_probs_to_classes(y_prob):
@@ -97,6 +98,9 @@ def convert_xgb_predictions(y_pred, objective):
9798
if params.threads != -1:
9899
xgb_params.update({'nthread': params.threads})
99100

101+
if 'OMP_NUM_THREADS' in os.environ.keys():
102+
xgb_params['nthread'] = int(os.environ['OMP_NUM_THREADS'])
103+
100104
columns = ('batch', 'arch', 'prefix', 'function', 'threads', 'dtype', 'size',
101105
'num_trees')
102106

0 commit comments

Comments
 (0)