Skip to content

Commit 6b2363b

Browse files
authored
Breaking down perf_tests into time and memory tests (#114)
This revision includes: * Splitting the perf_tests app into time_perf_tests and mem_perf_tests * Introducing Google Benchmark library for time_perf_tests * API for changing number of threads
1 parent 96d32de commit 6b2363b

39 files changed

Lines changed: 779 additions & 780 deletions

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "external/pybind11"]
55
path = external/pybind11
66
url = https://github.com/pybind/pybind11.git
7+
[submodule "external/googlebenchmark"]
8+
path = external/googlebenchmark
9+
url = https://github.com/google/benchmark.git

3RD_PARTY.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,22 @@ hereby grant the following license: a non-exclusive, royalty-free perpetual
483483
license to install, use, modify, prepare derivative works, incorporate into
484484
other computer software, distribute, and sublicense such enhancements or
485485
derivative works thereof, in binary and source code form.
486+
487+
---
488+
489+
Jet uses Google Benchmark for perf testing.
490+
491+
Copyright 2017, Google Inc.
492+
All rights reserved.
493+
494+
Licensed under the Apache License, Version 2.0 (the "License");
495+
you may not use this file except in compliance with the License.
496+
You may obtain a copy of the License at
497+
498+
http://www.apache.org/licenses/LICENSE-2.0
499+
500+
Unless required by applicable law or agreed to in writing, software
501+
distributed under the License is distributed on an "AS IS" BASIS,
502+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
503+
See the License for the specific language governing permissions and
504+
limitations under the License.

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ add_subdirectory(external/googletest EXCLUDE_FROM_ALL)
6262
if ((CMAKE_VERSION VERSION_EQUAL 3.3) OR (CMAKE_VERSION VERSION_GREATER 3.3))
6363
cmake_policy(SET CMP0063 NEW)
6464
endif()
65+
set(BENCHMARK_ENABLE_TESTING 0)
66+
add_subdirectory(external/googlebenchmark)
6567
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6668
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
6769
add_subdirectory(external/cnpy)
6870
add_subdirectory(external/pystring)
6971
add_subdirectory(src/jet)
7072
add_subdirectory(src/tests/manual_tests)
71-
add_subdirectory(src/tests/perf_tests)
73+
add_subdirectory(src/tests/mem_perf_tests)
74+
add_subdirectory(src/tests/time_perf_tests)
7275
add_subdirectory(src/tests/unit_tests)
7376
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
7477
add_subdirectory(src/winix)

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bin\Release\unit_tests.exe
9797

9898
### Running Tests
9999

100-
There are four different tests in the codebase including the unit test, manual test, performance test, and Python API test. For the detailed instruction on how to run those tests, please checkout the documentation page from [the project website](http://doyubkim.github.io/fluid-engine-dev/documentation/).
100+
There are four different tests in the codebase including the unit test, manual test, time/memory performance tests, and Python API test. For the detailed instruction on how to run those tests, please checkout the documentation page from [the project website](http://doyubkim.github.io/fluid-engine-dev/documentation/).
101101

102102
### Installing C++ SDK
103103

cmake/CompileOptions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
7272
# /wd4592 # -> disable warning: 'identifier': symbol will be dynamically initialized (implementation limitation)
7373
# /wd4201 # -> disable warning: nonstandard extension used: nameless struct/union (caused by GLM)
7474
# /wd4127 # -> disable warning: conditional expression is constant (caused by Qt)
75+
/wd4717 # -> disable warning: recursive on all control paths, function will cause runtime stack overflow (wrong warning)
7576

7677
#$<$<CONFIG:Debug>:
7778
#/RTCc # -> value is assigned to a smaller data type and results in a data loss

external/googlebenchmark

Submodule googlebenchmark added at d704179

include/jet/detail/parallel-inl.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ void parallelFor(IndexType start, IndexType end, const Function& func,
116116
}
117117

118118
// Estimate number of threads in the pool
119-
static const unsigned int numThreadsHint =
120-
std::thread::hardware_concurrency();
119+
unsigned int numThreadsHint = maxNUmberOfThreads();
121120
const unsigned int numThreads =
122121
(policy == ExecutionPolicy::kParallel)
123122
? (numThreadsHint == 0u ? 8u : numThreadsHint)
@@ -166,8 +165,7 @@ void parallelRangeFor(IndexType start, IndexType end, const Function& func,
166165
}
167166

168167
// Estimate number of threads in the pool
169-
static const unsigned int numThreadsHint =
170-
std::thread::hardware_concurrency();
168+
unsigned int numThreadsHint = maxNUmberOfThreads();
171169
const unsigned int numThreads =
172170
(policy == ExecutionPolicy::kParallel)
173171
? (numThreadsHint == 0u ? 8u : numThreadsHint)
@@ -264,8 +262,7 @@ Value parallelReduce(IndexType start, IndexType end, const Value& identity,
264262
}
265263

266264
// Estimate number of threads in the pool
267-
static const unsigned int numThreadsHint =
268-
std::thread::hardware_concurrency();
265+
unsigned int numThreadsHint = maxNUmberOfThreads();
269266
const unsigned int numThreads =
270267
(policy == ExecutionPolicy::kParallel)
271268
? (numThreadsHint == 0u ? 8u : numThreadsHint)
@@ -282,7 +279,6 @@ Value parallelReduce(IndexType start, IndexType end, const Value& identity,
282279

283280
// [Helper] Inner loop
284281
auto launchRange = [&](IndexType k1, IndexType k2, unsigned int tid) {
285-
// TODO: This is bad in terms of performance!
286282
results[tid] = func(k1, k2, identity);
287283
};
288284

@@ -331,8 +327,7 @@ void parallelSort(RandomIterator begin, RandomIterator end,
331327
std::vector<value_type> temp(size);
332328

333329
// Estimate number of threads in the pool
334-
static const unsigned int numThreadsHint =
335-
std::thread::hardware_concurrency();
330+
unsigned int numThreadsHint = maxNUmberOfThreads();
336331
const unsigned int numThreads =
337332
(policy == ExecutionPolicy::kParallel)
338333
? (numThreadsHint == 0u ? 8u : numThreadsHint)

include/jet/parallel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ void parallelSort(RandomIterator begin, RandomIterator end,
237237
CompareFunction compare,
238238
ExecutionPolicy policy = ExecutionPolicy::kParallel);
239239

240+
//! Sets maximum number of threads to use.
241+
void setMaxNumberOfThreads(unsigned int numThreads);
242+
243+
//! Returns maximum number of threads to use.
244+
unsigned int maxNUmberOfThreads();
245+
240246
} // namespace jet
241247

242248
#include "detail/parallel-inl.h"

src/jet/parallel.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2017 Doyub Kim
2+
//
3+
// I am making my contributions/submissions to this project solely in my
4+
// personal capacity and am not conveying any rights to any intellectual
5+
// property of any third parties.
6+
7+
#include <jet/parallel.h>
8+
9+
#include <thread>
10+
11+
static unsigned int sMaxNumberOfThreads = std::thread::hardware_concurrency();
12+
13+
namespace jet {
14+
15+
void setMaxNumberOfThreads(unsigned int numThreads) {
16+
sMaxNumberOfThreads = std::max(numThreads, 1u);
17+
}
18+
19+
unsigned int maxNUmberOfThreads() {
20+
return sMaxNumberOfThreads;
21+
}
22+
23+
} // namespace jet
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88

99
# Target name
10-
set(target perf_tests)
10+
set(target mem_perf_tests)
1111

1212
# Includes
1313
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

0 commit comments

Comments
 (0)