-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from SimeonEhrig/addBenchmarks
add benchmarks
- Loading branch information
Showing
19 changed files
with
888 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Testing and Benchmarking | ||
======================== | ||
|
||
Vikunja offers different types of tests. The source code is tested via unit and integration tests with `Catch2 <https://github.com/catchorg/Catch2/tree/v2.x>`_. The CMake code is tested with integration tests and custom scripts. | ||
|
||
Source Code Tests | ||
----------------- | ||
|
||
Before you start writing source code tests, you should read the `Catch2 documentation <https://github.com/catchorg/Catch2/blob/v2.x/docs/tutorial.md#top>`_. Tests written with Catch2 are standalone executables. They have their own source code files and ``CMakeLists.txt`` files located in the ``test/unit`` and ``test/integ`` folders. If you set the CMake argument ``-DBUILD_TESTING=ON``, the tests will be built automatically. All test executables are registered via the CMake function ``add_test``. Therefore, you can automatically run all tests from the build folder with the ``ctest`` command: | ||
|
||
.. code-block:: bash | ||
mkdir build && cd build | ||
cmake .. -DBUILD_TESTING=ON | ||
cmake --build . | ||
ctest | ||
For more CMake arguments for the tests, see the :ref:`CMake section <cmake-test>`. | ||
|
||
If you only want to run a single test, you can run the test executable directly. All test executables are located in ``<build_folder>/tests``. It is also possible to run the executable with the ``--help`` flag to show additional options. For example, the ``-s`` flag displays additional information created with the Catch2 function ``INFO()``. | ||
|
||
.. code-block:: bash | ||
mkdir build && cd build | ||
cmake .. -DBUILD_TESTING=ON | ||
cmake --build . | ||
# display extra test options | ||
test/integ/reduce/test_reduce --help | ||
# run test with extra output | ||
test/integ/reduce/test_reduce -s | ||
.. tip:: | ||
|
||
Each test is a CMake target that you can build separately. A test target always starts with ``test_``. To get all available test CMake targets, run ``cmake --build . -t help | grep 'test_'`` in the build folder. You can build a specific test with ``cmake --build . -t test_IndividualTestCase``. | ||
|
||
CMake Tests | ||
----------- | ||
|
||
The CMake integration tests check whether vikunja can be used correctly in another project via the CMake functions ``find_package()`` or ``add_subdirectory``. The CI contains test jobs which create dummy projects that use the vikunja library. The job names start with ``integration``. All associated files for the tests are in ``script/integration_test``. | ||
|
||
CXX Test | ||
++++++++ | ||
|
||
There is a special Catch2 test that tests vikunja's build system to see if the C++ standard is set correctly. The name of the test is ``test_cxx``. It compares the C++ standard set by the compiler with an expected standard passed as an argument. By default, ``ctest`` automatically passes the expected C++ standard depending on the CMake variable ``ALPAKA_CXX_STANDARD``. If you run the test manually, you must pass it yourself: | ||
|
||
.. code-block:: bash | ||
# expects, that the code was compiled with C++ 17 | ||
test/unit/cxx/test_cxx --cxx 17 | ||
Benchmarks | ||
---------- | ||
|
||
Vikunja uses `Catch2 benchmark <https://github.com/catchorg/Catch2/blob/v2.x/docs/benchmarks.md#top>`_ to automatically run benchmarks. By default, benchmarks are not enabled. To enable them, the CMake arguments ``-DBUILD_TESTING=ON -DVIKUNJA_ENABLE_BENCHMARKS=ON`` must be set. The benchmarks are created automatically and can be run with ``ctest``. As with the tests, you can run a particular benchmark directly from the executable file, e.g. ``test/benchmarks/transform/bench_vikunja_transform``. All benchmark executables are located in ``<build_folder>/test/benchmarks``. | ||
|
||
.. tip:: | ||
|
||
If you run ``<benchmark_exe> --help``, you get benchmark specific options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2022 Simeon Ehrig | ||
# | ||
# This file is part of vikunja. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
cmake_minimum_required(VERSION 3.18) | ||
|
||
add_library(vikunjaBenchSetup INTERFACE) | ||
target_compile_definitions(vikunjaBenchSetup INTERFACE CATCH_CONFIG_ENABLE_BENCHMARKING) | ||
target_include_directories(vikunjaBenchSetup INTERFACE include) | ||
add_library(vikunja::benchSetup ALIAS vikunjaBenchSetup) | ||
|
||
add_subdirectory("helper/") | ||
add_subdirectory("transform/") | ||
add_subdirectory("reduce/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2022 Simeon Ehrig | ||
# | ||
# This file is part of vikunja. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
cmake_minimum_required(VERSION 3.18) | ||
|
||
set(_TARGET_NAME "test_bench_helper") | ||
|
||
alpaka_add_executable( | ||
${_TARGET_NAME} | ||
test_bench_helper.cpp | ||
) | ||
|
||
target_link_libraries(${_TARGET_NAME} | ||
PRIVATE | ||
vikunja::testSetup | ||
vikunja::benchSetup | ||
vikunja::internalvikunja | ||
) | ||
|
||
add_test(NAME ${_TARGET_NAME} COMMAND ${_TARGET_NAME} ${_VIKUNJA_TEST_OPTIONS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* Copyright 2022 Simeon Ehrig | ||
* | ||
* This file is part of vikunja. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <vikunja/bench/memory.hpp> | ||
#include <vikunja/test/AlpakaSetup.hpp> | ||
#include <vikunja/test/utility.hpp> | ||
|
||
#include <alpaka/alpaka.hpp> | ||
#include <alpaka/example/ExampleDefaultAcc.hpp> | ||
|
||
#include <catch2/catch.hpp> | ||
|
||
|
||
TEMPLATE_TEST_CASE("allocate_mem_iota compare std::iota", "[iota]", int, float, double) | ||
{ | ||
using Data = TestType; | ||
using Setup = vikunja::test::TestAlpakaSetup< | ||
alpaka::DimInt<1u>, // dim | ||
int, // Idx | ||
alpaka::AccCpuSerial, // host type | ||
alpaka::ExampleDefaultAcc, // device type | ||
alpaka::Blocking // queue type | ||
>; | ||
using Vec = alpaka::Vec<Setup::Dim, Setup::Idx>; | ||
|
||
Setup::Idx size = GENERATE(1, 10, 3045, 2'000'000); | ||
Data begin = GENERATE(0, 1, 45, -42); | ||
|
||
INFO((vikunja::test::print_acc_info<Setup::Dim>(size))); | ||
INFO("begin: " + std::to_string(begin)); | ||
|
||
Setup setup; | ||
Vec extent = Vec::all(static_cast<Setup::Idx>(size)); | ||
|
||
auto devMem = vikunja::bench::allocate_mem_iota<Data>(setup, extent, begin); | ||
auto hostMem(alpaka::allocBuf<Data, typename Setup::Idx>(setup.devHost, extent)); | ||
Data* const hostMemPtr(alpaka::getPtrNative(hostMem)); | ||
|
||
alpaka::memcpy(setup.queueAcc, hostMem, devMem, extent); | ||
|
||
std::vector<Data> expected_result(size); | ||
std::iota(std::begin(expected_result), std::end(expected_result), begin); | ||
|
||
for(Setup::Idx i = 0; i < size; ++i) | ||
{ | ||
REQUIRE(static_cast<Data>(expected_result[i]) == hostMemPtr[i]); | ||
} | ||
} | ||
|
||
TEMPLATE_TEST_CASE("allocate_mem_iota different increment", "[iota]", int, float, double) | ||
{ | ||
using Data = TestType; | ||
using Setup = vikunja::test::TestAlpakaSetup< | ||
alpaka::DimInt<1u>, // dim | ||
int, // Idx | ||
alpaka::AccCpuSerial, // host type | ||
alpaka::ExampleDefaultAcc, // device type | ||
alpaka::Blocking // queue type | ||
>; | ||
using Vec = alpaka::Vec<Setup::Dim, Setup::Idx>; | ||
|
||
Setup::Idx size = GENERATE(1, 10, 3045); | ||
Data begin = GENERATE(0, 1, 45, -42); | ||
Data increment = GENERATE(1, -1, 45, -42); | ||
|
||
INFO((vikunja::test::print_acc_info<Setup::Dim>(size))); | ||
INFO("begin: " + std::to_string(begin)); | ||
INFO("increment: " + std::to_string(increment)); | ||
|
||
Setup setup; | ||
Vec extent = Vec::all(static_cast<Setup::Idx>(size)); | ||
|
||
auto devMem = vikunja::bench::allocate_mem_iota<Data>(setup, extent, begin, increment); | ||
auto hostMem(alpaka::allocBuf<Data, typename Setup::Idx>(setup.devHost, extent)); | ||
Data* const hostMemPtr(alpaka::getPtrNative(hostMem)); | ||
|
||
alpaka::memcpy(setup.queueAcc, hostMem, devMem, extent); | ||
|
||
for(Setup::Idx i = 0; i < size; ++i) | ||
{ | ||
Data expected_result = begin + static_cast<Data>(i) * increment; | ||
REQUIRE_MESSAGE(expected_result == hostMemPtr[i], "failed with index: " + std::to_string(i)); | ||
} | ||
} | ||
|
||
TEMPLATE_TEST_CASE("allocate_mem_constant", "[iota]", int, float, double) | ||
{ | ||
using Data = TestType; | ||
using Setup = vikunja::test::TestAlpakaSetup< | ||
alpaka::DimInt<1u>, // dim | ||
int, // Idx | ||
alpaka::AccCpuSerial, // host type | ||
alpaka::ExampleDefaultAcc, // device type | ||
alpaka::Blocking // queue type | ||
>; | ||
using Vec = alpaka::Vec<Setup::Dim, Setup::Idx>; | ||
|
||
Setup::Idx size = GENERATE(1, 10, 3045, 2'000'000); | ||
Data constant = GENERATE(0, 1, 45, -42); | ||
|
||
INFO((vikunja::test::print_acc_info<Setup::Dim>(size))); | ||
INFO("constant: " + std::to_string(constant)); | ||
|
||
Setup setup; | ||
Vec extent = Vec::all(static_cast<Setup::Idx>(size)); | ||
|
||
auto devMem = vikunja::bench::allocate_mem_constant<Data>(setup, extent, constant); | ||
auto hostMem(alpaka::allocBuf<Data, typename Setup::Idx>(setup.devHost, extent)); | ||
Data* const hostMemPtr(alpaka::getPtrNative(hostMem)); | ||
|
||
alpaka::memcpy(setup.queueAcc, hostMem, devMem, extent); | ||
|
||
for(Setup::Idx i = 0; i < size; ++i) | ||
{ | ||
REQUIRE(static_cast<Data>(constant) == hostMemPtr[i]); | ||
} | ||
} |
Oops, something went wrong.