-
Create
/src/cpp/modules/yourModule/CMakeLists.txt
with the following content whereYourModule
is the name of your module:project("ADBench_YourModule" CXX) add_library("YourModule" MODULE)
Note that global runner expects the directory name to be equal to the module binary name but with a lowercase first letter.
-
Add the following line to
/src/cpp/modules/CMakeLists.txt
:add_subdirectory ("YourModule")
-
For each objective create a class implementing the interface
ITest<TInput,TOutput>
whereT
is an objective type (GMM
,BA
etc.). You can find this interface in../../shared/ITest.h
(the path is relative to the directory of your module).TInput
andTOutput
are input and output types specific for the objective there. They are defined in../../shared/TData.h
(the path is relative to the directory of your module).The functions you need to implement:
-
Converts the input data from the format in which it is provided by the calling benchmark runner into the format optimized for use with the tested AD framework. It also allocates memory for internal buffers and results structure.
virtual void prepare(TInput&& input)
-
Repeatedly computes one of the objective functions given number of times, saving results into a pre-allocated internal structure.
virtual void calculate_objective(int times)
-
Repeatedly computes a derivative of one of the objective functions given number of times, saving results into a pre-allocated internal structure.
virtual void calculate_jacobian(int times)
-
Converts internally saved outputs into the format specified by the runner.
virtual TOutput output()
-
-
For each class add an exported factory function just below class implementation as follows:
extern "C" DLL_PUBLIC ITest<TInput, TOutput>* get_T_test() { return new YourClass(); }
where
T
is still an objective type here.DLL_PUBLIC
is a macro defined in/src/shared/ITest.h
. It is made to export functions from shared libraries both on Windows and Linux with GCC and MSVC compilers. -
Specify target sources in the project
CMakeLists.txt
. -
Compile, run via C++ runner and enjoy!
Please, don't forget to add unit tests.
GTest and GMock are used to test C++ modules in this project.
AD Bench already contains some tests for each objective. When you add a new module, the first thing you should do is to test your module with the existing tests. Follow these steps for every objective you want to test:
-
Open
/test/cpp/modules/common/TTests.cpp
whereT
is the short name of the testing objective. You will see the following lines:INSTANTIATE_TEST_CASE_P(T, TModuleTest, ::testing::Values( std::make_tuple("../../../../src/cpp/modules/manual/Manual.dll", 1e-8), std::make_tuple("../../../../src/cpp/modules/manualEigen/ManualEigen.dll", 1e-8), ... ), get_module_name<ModuleTest::ParamType>);
-
Add a tuple containing the module's path and a
tolerance
for test results to the list of test parameters:INSTANTIATE_TEST_CASE_P(T, TModuleTest, ::testing::Values( std::make_tuple("../../../../src/cpp/modules/manual/Manual.dll", 1e-8), std::make_tuple("../../../../src/cpp/modules/manualEigen/ManualEigen.dll", 1e-8), ... std::make_tuple(your_path, absolute_error), ), get_module_name<ModuleTest::ParamType>);
tolerance
is a number used to compare results of the current module execution with the "golden" results. If an absolute difference between at least one of them exceeds this value then the test is failed.
Follow these steps to add a new test case for objective:
-
Open
/test/cpp/modules/common/TTests.cpp
whereT
is the short name of the testing objective. -
Add the following lines to the end of the file:
TEST_P(TModuleTest, TestCaseName) { ... test_code ... }
In a test case you should generally:
- load the module
- load input data
- prepare the module
- perform computations
- compare the results of computations with the previously known correct ones
You might want to add a new type of objective to test. In that case just do the following:
- Create
/test/cpp/modules/common/TTests.cpp
. - Include
gtest/gtest.h
in it. - Use
INSTANTIATE_TEST_CASE_P
macro to list all modules supportingT
objective type as it described in the "Adding tests for a new module" section. - Use
TEST_P
macro to add new test cases as it described in the "Adding a new test case" section. - Open
/test/cpp/modules/common/CMakeLists.txt
and markTTests.cpp
as source viatarget_sources
command there.