Skip to content

Commit 66947f3

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 4e30a0d commit 66947f3

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
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_NUMEROFTHREADS "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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,42 @@ def check_for_build_information(itk_src):
152152
has_itkbuildinformation = True
153153
return has_itkbuildinformation
154154

155+
# 2075084be6f9988b1ae2231bca607830fe6d772b is sha1 that rename NumberOfThreads into NumberOfWorkUnits in filters
156+
# Author: Dzenan Zukic <[email protected]>
157+
# Date: Tue Jul 17 19:30:02 2018
158+
# so all ancestors need to prevent the benchmarking from using
159+
def check_for_NumberOfThreads(itk_src):
160+
os.chdir(itk_src)
161+
try:
162+
cmd = ['git', 'merge-base',
163+
'--is-ancestor', 'HEAD',
164+
'2075084be6f9988b1ae2231bca607830fe6d772b']
165+
has_itkNumberOfThreads = not bool(subprocess.check_call( cmd ) )
166+
except subprocess.CalledProcessError:
167+
has_itkNumberOfThreads = False
168+
return has_itkNumberOfThreads
169+
155170
def build_benchmarks(benchmark_src, benchmark_bin,
156171
itk_bin,
157-
itk_has_buildinformation):
172+
itk_has_buildinformation,
173+
itk_has_NumberOfThreads):
158174
os.chdir(benchmark_bin)
159175
if itk_has_buildinformation:
160176
build_information_arg = '-DITK_HAS_INFORMATION_H:BOOL=ON'
161177
else:
162178
build_information_arg = '-DITK_HAS_INFORMATION_H:BOOL=OFF'
179+
if itk_has_NumberOfThreads:
180+
print("HERE!!!!")
181+
NumberOfThreads_arg = '-DITK_USES_NUMEROFTHREADS:BOOL=ON'
182+
else:
183+
NumberOfThreads_arg = '-DITK_USES_NUMEROFTHREADS:BOOL=OFF'
163184
subprocess.check_call(['cmake',
164185
'-G', 'Ninja',
165186
'-DCMAKE_BUILD_TYPE:STRING=Release',
166187
'-DCMAKE_CXX_STANDARD:STRING=11',
167188
'-DITK_DIR:PATH=' + itk_bin,
168189
build_information_arg,
190+
NumberOfThreads_arg,
169191
benchmark_src])
170192
subprocess.check_call(['ninja'])
171193

@@ -314,10 +336,11 @@ def has_sha(filepath):
314336
build_itk(args.src, args.bin)
315337

316338
itk_has_buildinformation = check_for_build_information(args.src)
339+
itk_has_NumberOfThreads = check_for_NumberOfThreads(args.src)
317340

318341
print('\nBuilding benchmarks...')
319342
build_benchmarks(benchmark_src, args.benchmark_bin, args.bin,
320-
itk_has_buildinformation)
343+
itk_has_buildinformation, itk_has_NumberOfThreads)
321344

322345
print('\nRunning benchmarks...')
323346
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_NUMEROFTHREADS)
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_NUMEROFTHREADS
34+
3335

3436
namespace itk
3537
{

0 commit comments

Comments
 (0)