Skip to content

Commit 62b0866

Browse files
committed
Add PPC_ASAN_RUN logic and refactor task/test macros
Introduce `PPC_ASAN_RUN` to handle ASAN-specific configurations, replacing `USE_ASAN`. Refactor task initialization and testing macros for improved readability and flexibility. Adjust test and build scripts to incorporate new environment variables and settings management.
1 parent bb8a044 commit 62b0866

10 files changed

Lines changed: 94 additions & 43 deletions

File tree

modules/core/util/include/func_test_util.hpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,27 @@ auto ExpandToValues(const Tuple& t) {
7474
return ExpandToValuesImpl(t, std::make_index_sequence<kN>{});
7575
}
7676

77-
#define INIT_TASK_GENERATOR(InTypeParam, SizesParam) \
78-
template <typename Task, std::size_t... Is> \
79-
auto GenTaskTuplesImpl(std::index_sequence<Is...>) { \
80-
return std::make_tuple( \
81-
std::make_tuple(ppc::core::TaskGetter<Task, InTypeParam>, \
82-
std::string(ppc::util::GetNamespace<Task>()) + std::string("_") + \
83-
ppc::core::GetStringTaskType(Task::GetStaticTypeOfTask(), PPC_STUDENT_SETTINGS), \
84-
SizesParam[Is])...); \
85-
} \
86-
\
87-
template <typename Task> \
88-
auto TaskListGenerator() { \
89-
return GenTaskTuplesImpl<Task>(std::make_index_sequence<SizesParam.size()>{}); \
77+
#define INIT_TASK_GENERATOR(InTypeParam, SizesParam, SettingsPath) \
78+
template <typename Task, std::size_t... Is> \
79+
auto GenTaskTuplesImpl(std::index_sequence<Is...>) { \
80+
return std::make_tuple( \
81+
std::make_tuple(ppc::core::TaskGetter<Task, InTypeParam>, \
82+
std::string(ppc::util::GetNamespace<Task>()) + std::string("_") + \
83+
ppc::core::GetStringTaskType(Task::GetStaticTypeOfTask(), SettingsPath), \
84+
SizesParam[Is])...); \
85+
} \
86+
\
87+
template <typename Task> \
88+
auto TaskListGenerator() { \
89+
return GenTaskTuplesImpl<Task>(std::make_index_sequence<SizesParam.size()>{}); \
9090
}
9191

92+
#define ADD_FUNC_TASK_THREADS(TASK) TaskListGenerator<TASK>()
93+
94+
#ifndef PPC_ASAN_RUN
95+
#define ADD_FUNC_TASK_PROCESS(TASK) TaskListGenerator<TASK>()
96+
#else
97+
#define ADD_FUNC_TASK_PROCESS(TASK) std::tuple<>()
98+
#endif
99+
92100
} // namespace ppc::util

modules/core/util/include/perf_test_util.hpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
7979
throw std::runtime_error(err_msg.str().c_str());
8080
}
8181

82+
#ifndef PPC_ASAN_RUN
8283
int rank = -1;
8384
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
8485
if (rank == 0) {
8586
perf.PrintPerfStatistic(test_name);
8687
}
88+
#else
89+
perf.PrintPerfStatistic(test_name);
90+
#endif
91+
8792
OutType output_data = task_->GetOutput();
8893
ASSERT_TRUE(CheckTestOutputData(output_data));
8994
}
@@ -92,14 +97,39 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
9297
ppc::core::TaskPtr<InType, OutType> task_;
9398
};
9499

95-
#define ADD_PERF_TASK(TaskType, InputTypeParam) \
96-
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
97-
std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \
98-
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), PPC_STUDENT_SETTINGS), \
99-
ppc::core::PerfResults::TypeOfRunning::kPipeline), \
100-
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
101-
std::string(ppc::util::GetNamespace<TaskType>()) + std::string("_") + \
102-
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), PPC_STUDENT_SETTINGS), \
103-
ppc::core::PerfResults::TypeOfRunning::kTaskRun)
100+
#define ADD_PERF_TASK_THREADS(TaskType, InputTypeParam, SettingsPath) \
101+
std::tuple(std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
102+
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
103+
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), SettingsPath), \
104+
ppc::core::PerfResults::TypeOfRunning::kPipeline), \
105+
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
106+
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
107+
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), SettingsPath), \
108+
ppc::core::PerfResults::TypeOfRunning::kTaskRun))
109+
110+
template <typename Tuple, std::size_t... I>
111+
auto TupleToGTestValuesImpl(Tuple&& tup, std::index_sequence<I...>) {
112+
return ::testing::Values(std::get<I>(std::forward<Tuple>(tup))...);
113+
}
114+
115+
template <typename Tuple>
116+
auto TupleToGTestValues(Tuple&& tup) {
117+
constexpr size_t size = std::tuple_size<std::decay_t<Tuple>>::value;
118+
return TupleToGTestValuesImpl(std::forward<Tuple>(tup), std::make_index_sequence<size>{});
119+
}
120+
121+
#ifndef PPC_ASAN_RUN
122+
#define ADD_PERF_TASK_PROCESS(TaskType, InputTypeParam, SettingsPath) \
123+
std::tuple(std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
124+
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
125+
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), SettingsPath), \
126+
ppc::core::PerfResults::TypeOfRunning::kPipeline), \
127+
std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
128+
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \
129+
ppc::core::GetStringTaskType(TaskType::GetStaticTypeOfTask(), SettingsPath), \
130+
ppc::core::PerfResults::TypeOfRunning::kTaskRun))
131+
#else
132+
#define ADD_PERF_TASK_PROCESS(TaskType, InputTypeParam, SettingsPath) std::make_tuple()
133+
#endif
104134

105135
} // namespace ppc::util

scripts/run_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def run_performance_list(self):
123123
ppc_runner = PPCRunner()
124124
ppc_runner.setup_env(os.environ.copy())
125125

126-
if args_dict["running_type"] in ["threads", "processes"]:
127-
ppc_runner.run_core()
126+
# if args_dict["running_type"] in ["threads", "processes"]:
127+
# ppc_runner.run_core()
128128

129129
if args_dict["running_type"] == "threads":
130130
ppc_runner.run_threads()

tasks/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ if (USE_PERF_TESTS)
1717
list(APPEND list_of_exec_tests ${exec_perf_tests})
1818
endif (USE_PERF_TESTS)
1919

20+
if((DEFINED ENV{PPC_ASAN_RUN}) AND ("$ENV{PPC_ASAN_RUN}" STREQUAL "1"))
21+
add_compile_definitions(PPC_ASAN_RUN)
22+
endif()
23+
2024
SUBDIRLIST(subdirs ${CMAKE_CURRENT_LIST_DIR})
2125
foreach(subd ${subdirs})
2226
if (subd STREQUAL "common")
2327
continue()
2428
endif ()
29+
30+
set(SETTINGS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${subd}/settings.json")
31+
add_compile_definitions(PPC_SETTINGS_${subd}=\"${SETTINGS_PATH}\")
32+
2533
add_subdirectory(${subd})
2634
endforeach()
2735

tasks/common/runners/functional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
7171
};
7272

7373
int main(int argc, char** argv) {
74-
#ifndef USE_ASAN
74+
#ifndef PPC_ASAN_RUN
7575
MPI_Init(&argc, &argv);
7676

7777
// Limit the number of threads in TBB

tasks/common/runners/performance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
7171
};
7272

7373
int main(int argc, char** argv) {
74-
#ifndef USE_ASAN
74+
#ifndef PPC_ASAN_RUN
7575
MPI_Init(&argc, &argv);
7676

7777
// Limit the number of threads in TBB

tasks/example/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
get_filename_component(CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
22
project(CURRENT_DIR_NAME)
33

4-
add_library("${CURRENT_DIR_NAME}_common" INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/common/include/common.hpp")
5-
get_filename_component(SETTINGS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/settings.json" ABSOLUTE)
6-
target_compile_definitions("${CURRENT_DIR_NAME}_common" INTERFACE PPC_STUDENT_SETTINGS=\"${SETTINGS_PATH}\")
7-
84
set(exec_func_tests "ppc_func_tests")
95
set(exec_perf_tests "ppc_perf_tests")
106
set(test_base_dir "${CMAKE_CURRENT_SOURCE_DIR}/tests")
@@ -28,8 +24,13 @@ endif (USE_PERF_TESTS)
2824
get_filename_component(TASK_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
2925
message(STATUS "-- ${TASK_NAME}")
3026

27+
set(technologies "omp" "seq" "stl" "tbb")
28+
if((NOT DEFINED ENV{PPC_ASAN_RUN}) OR ("$ENV{PPC_ASAN_RUN}" STREQUAL "0"))
29+
list(APPEND technologies "all" "mpi")
30+
endif()
31+
3132
# Create lib
32-
foreach (dir_type "all" "mpi" "omp" "seq" "stl" "tbb")
33+
foreach (dir_type ${technologies})
3334
# Check directory existing
3435
set(base_dir "${CMAKE_CURRENT_SOURCE_DIR}/${dir_type}")
3536
if (NOT EXISTS "${base_dir}")
@@ -51,7 +52,7 @@ foreach (dir_type "all" "mpi" "omp" "seq" "stl" "tbb")
5152
add_library(${name_lib} STATIC ${lib_source_files})
5253
endif()
5354
set_target_properties(${name_lib} PROPERTIES LINKER_LANGUAGE CXX)
54-
target_link_libraries(${name_lib} PUBLIC core_module_lib "${CURRENT_DIR_NAME}_common")
55+
target_link_libraries(${name_lib} PUBLIC core_module_lib)
5556

5657
# Link core library
5758
foreach (exec_func ${list_of_exec_tests})

tasks/example/info.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"first_name": "Нестеров",
44
"last_name": "Александр",
55
"middle_name": "Юрьевич",
6-
"group_number": "АБВ-123"
6+
"group_number": "АБВ-123",
7+
"tasks_type": "threads"
78
}
89
}

tasks/example/tests/functional/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ TEST_P(NesterovARunFuncTests, MatmulFromPic) { ExecuteTest(GetParam()); }
6363

6464
const std::array<TestType, 3> kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")};
6565

66-
INIT_TASK_GENERATOR(InType, kTestParam)
66+
INIT_TASK_GENERATOR(InType, kTestParam, PPC_SETTINGS_example)
6767

6868
const auto kTestTasksList =
69-
std::tuple_cat(TaskListGenerator<NesterovATestTaskALL>(), TaskListGenerator<NesterovATestTaskMPI>(),
70-
TaskListGenerator<NesterovATestTaskOMP>(), TaskListGenerator<NesterovATestTaskSEQ>(),
71-
TaskListGenerator<NesterovATestTaskSTL>(), TaskListGenerator<NesterovATestTaskTBB>());
69+
std::tuple_cat(ADD_FUNC_TASK_PROCESS(NesterovATestTaskALL), ADD_FUNC_TASK_PROCESS(NesterovATestTaskMPI),
70+
ADD_FUNC_TASK_THREADS(NesterovATestTaskOMP), ADD_FUNC_TASK_THREADS(NesterovATestTaskSEQ),
71+
ADD_FUNC_TASK_THREADS(NesterovATestTaskSTL), ADD_FUNC_TASK_THREADS(NesterovATestTaskTBB));
7272

7373
INSTANTIATE_TEST_SUITE_P_NOLINT(PicMatrixTests, NesterovARunFuncTests, ppc::util::ExpandToValues(kTestTasksList),
7474
NesterovARunFuncTests::PrintFuncTestName<NesterovARunFuncTests>);

tasks/example/tests/performance/main.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ class ExampleRunPerfTest : public ppc::util::BaseRunPerfTests<InType, OutType> {
2929
InType GetTestInputData() final { return input_data_; }
3030
};
3131

32+
const auto all_perf_tasks = std::tuple_cat(ADD_PERF_TASK_PROCESS(NesterovATestTaskALL, InType, PPC_SETTINGS_example),
33+
ADD_PERF_TASK_PROCESS(NesterovATestTaskMPI, InType, PPC_SETTINGS_example),
34+
ADD_PERF_TASK_THREADS(NesterovATestTaskOMP, InType, PPC_SETTINGS_example),
35+
ADD_PERF_TASK_THREADS(NesterovATestTaskSEQ, InType, PPC_SETTINGS_example),
36+
ADD_PERF_TASK_THREADS(NesterovATestTaskSTL, InType, PPC_SETTINGS_example),
37+
ADD_PERF_TASK_THREADS(NesterovATestTaskTBB, InType, PPC_SETTINGS_example));
38+
3239
TEST_P(ExampleRunPerfTest, RunPerfModes) { ExecuteTest(GetParam()); }
3340

34-
INSTANTIATE_TEST_SUITE_P_NOLINT(
35-
RunModeTests, ExampleRunPerfTest,
36-
::testing::Values(ADD_PERF_TASK(NesterovATestTaskALL, InType), ADD_PERF_TASK(NesterovATestTaskMPI, InType),
37-
ADD_PERF_TASK(NesterovATestTaskOMP, InType), ADD_PERF_TASK(NesterovATestTaskSEQ, InType),
38-
ADD_PERF_TASK(NesterovATestTaskSTL, InType), ADD_PERF_TASK(NesterovATestTaskTBB, InType)),
39-
ExampleRunPerfTest::CustomPerfTestName);
41+
INSTANTIATE_TEST_SUITE_P_NOLINT(RunModeTests, ExampleRunPerfTest, ppc::util::TupleToGTestValues(all_perf_tasks),
42+
ExampleRunPerfTest::CustomPerfTestName);
4043

4144
} // namespace nesterov_a_test_task

0 commit comments

Comments
 (0)