Skip to content

Commit ba5a6cc

Browse files
committed
ENH: Add ability to specify if NumberOfThreads is required.
Select the patch that renames NumberOfThreads to NumberOfWorkUnits. Use a cmake driven option to indicate which code spelling should be used.
1 parent cf39692 commit ba5a6cc

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ endif()
4242

4343
project(PerformanceBenchmarking)
4444

45+
option(ITK_USES_NUMBEROFTHREADS "If ITKv5 uses NumberOfThreads (not NumberOfWorkUnits" OFF)
46+
4547
set(PerformanceBenchmarking_LIBRARIES PerformanceBenchmarking)
4648

4749
include_directories(${CMAKE_BINARY_DIR})

evaluate-itk-performance.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __call__(self, parser, namespace, values, option_string=None):
4343
help='ITK performance benchmarks build directory', action = FullPaths)
4444
run_parser.add_argument('-r', '--rev-list',
4545
help='Arguments for "git rev-list" to select the range of commits to benchmark, for example: "--first-parent v4.10.0..v5.0rc1"',
46-
default='--no-merges HEAD~1..')
46+
default='--first-parent HEAD~1..')
4747

4848
upload_parser = subparsers.add_parser('upload',
4949
help='upload the benchmarks to data.kitware.com')
@@ -154,20 +154,41 @@ def check_for_build_information(itk_src):
154154
has_itkbuildinformation = True
155155
return has_itkbuildinformation
156156

157+
# 2075084be6f9988b1ae2231bca607830fe6d772b is sha1 that rename NumberOfThreads into NumberOfWorkUnits in filters
158+
# Author: Dzenan Zukic <[email protected]>
159+
# Date: Tue Jul 17 19:30:02 2018
160+
# so all ancestors need to prevent the benchmarking from using
161+
def check_for_NumberOfThreads(itk_src):
162+
os.chdir(itk_src)
163+
try:
164+
cmd = ['git', 'merge-base',
165+
'--is-ancestor', 'HEAD',
166+
'2075084be6f9988b1ae2231bca607830fe6d772b']
167+
has_itkNumberOfThreads = not bool(subprocess.check_call( cmd ) )
168+
except subprocess.CalledProcessError:
169+
has_itkNumberOfThreads = False
170+
return has_itkNumberOfThreads
171+
157172
def build_benchmarks(benchmark_src, benchmark_bin,
158173
itk_bin,
159-
itk_has_buildinformation):
174+
itk_has_buildinformation,
175+
itk_has_NumberOfThreads):
160176
os.chdir(benchmark_bin)
161177
if itk_has_buildinformation:
162178
build_information_arg = '-DITK_HAS_INFORMATION_H:BOOL=ON'
163179
else:
164180
build_information_arg = '-DITK_HAS_INFORMATION_H:BOOL=OFF'
181+
if itk_has_NumberOfThreads:
182+
NumberOfThreads_arg = '-DITK_USES_NUMBEROFTHREADS:BOOL=ON'
183+
else:
184+
NumberOfThreads_arg = '-DITK_USES_NUMBEROFTHREADS:BOOL=OFF'
165185
subprocess.check_call(['cmake',
166186
'-G', 'Ninja',
167187
'-DCMAKE_BUILD_TYPE:STRING=Release',
168188
'-DCMAKE_CXX_STANDARD:STRING=11',
169189
'-DITK_DIR:PATH=' + itk_bin,
170190
build_information_arg,
191+
NumberOfThreads_arg,
171192
benchmark_src])
172193
subprocess.check_call(['ninja'])
173194

@@ -328,10 +349,11 @@ def has_sha(filepath):
328349
build_itk(args.src, args.bin)
329350

330351
itk_has_buildinformation = check_for_build_information(args.src)
352+
itk_has_NumberOfThreads = check_for_NumberOfThreads(args.src)
331353

332354
print('\nBuilding benchmarks...')
333355
build_benchmarks(benchmark_src, args.benchmark_bin, args.bin,
334-
itk_has_buildinformation)
356+
itk_has_buildinformation, itk_has_NumberOfThreads)
335357

336358
print('\nRunning benchmarks...')
337359
run_benchmarks(args.benchmark_bin, itk_information)

include/PerformanceBenchmarkingUtilities.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
#ifndef PerformanceBenchmarkingUtilities_h
66
#define PerformanceBenchmarkingUtilities_h
77

8-
#include "PerformanceBenchmarkingExport.h"
8+
#include "PerformanceBenchmarkingInformation.h"
99

1010
#include "jsonxx.h"
1111
#include <ctime> //TODO: Move to utiliites
1212
#include "itkHighPriorityRealTimeProbesCollector.h"
1313

14-
#if ITK_VERSION_MAJOR >= 5
15-
#include "itkMultiThreaderBase.h"
16-
using MultiThreaderName = itk::MultiThreaderBase;
17-
#define SET_PARALLEL_UNITS( x ) SetNumberOfWorkUnits( x )
18-
#else
14+
#if ITK_VERSION_MAJOR < 5 || defined(ITK_USES_NUMBEROFTHREADS)
1915
#include "itkMultiThreader.h"
2016
using MultiThreaderName = itk::MultiThreader;
2117
#define SET_PARALLEL_UNITS( x ) SetNumberOfThreads( x )
18+
#else
19+
#include "itkMultiThreaderBase.h"
20+
using MultiThreaderName = itk::MultiThreaderBase;
21+
#define SET_PARALLEL_UNITS( x ) SetNumberOfWorkUnits( x )
2222
#endif
2323

2424
PerformanceBenchmarking_EXPORT

src/PerformanceBenchmarkingInformation.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include "PerformanceBenchmarkingExport.h"
3232

33+
#cmakedefine ITK_USES_NUMBEROFTHREADS
34+
3335

3436
namespace itk
3537
{

0 commit comments

Comments
 (0)