Skip to content

Commit

Permalink
Add unit tests for work div
Browse files Browse the repository at this point in the history
  • Loading branch information
sbastrakov authored and BenjaminW3 committed Jul 23, 2020
1 parent 15c510b commit 8bf4639
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ add_subdirectory("rand/")
add_subdirectory("time/")
add_subdirectory("vec/")
add_subdirectory("warp/")
add_subdirectory("workDiv/")
24 changes: 24 additions & 0 deletions test/unit/workDiv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright 2014-2020 Benjamin Worpitz, Axel Huebl, Jan Stephan
#
# This file is part of alpaka.
#
# 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/.
#

set(_TARGET_NAME "workDiv")

append_recursive_files_add_to_src_group("src/" "src/" "cpp" _FILES_SOURCE)

alpaka_add_executable(
${_TARGET_NAME}
${_FILES_SOURCE})
target_link_libraries(
${_TARGET_NAME}
PRIVATE common)

set_target_properties(${_TARGET_NAME} PROPERTIES FOLDER "test/unit")

add_test(NAME ${_TARGET_NAME} COMMAND ${_TARGET_NAME} ${_ALPAKA_TEST_OPTIONS})
68 changes: 68 additions & 0 deletions test/unit/workDiv/src/WorkDivHelpersTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Copyright 2020 Sergei Bastrakov
*
* This file is part of alpaka.
*
* 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 <alpaka/acc/AccDevProps.hpp>
#include <alpaka/core/Unused.hpp>
#include <alpaka/workdiv/WorkDivHelpers.hpp>

#include <alpaka/test/acc/TestAccs.hpp>
#include <alpaka/test/KernelExecutionFixture.hpp>

#include <catch2/catch.hpp>

//-----------------------------------------------------------------------------
namespace
{
template< typename TAcc >
auto getWorkDiv()
{
using Dev = alpaka::dev::Dev<TAcc>;
using Pltf = alpaka::pltf::Pltf<Dev>;
using Dim = alpaka::dim::Dim<TAcc>;
using Idx = alpaka::idx::Idx<TAcc>;

Dev const dev(alpaka::pltf::getDevByIdx<Pltf>(0u));
auto const gridThreadExtent = alpaka::vec::Vec<Dim, Idx>::all(10);
auto const threadElementExtent = alpaka::vec::Vec<Dim, Idx>::ones();
auto workDiv = alpaka::workdiv::getValidWorkDiv<TAcc>(
dev,
gridThreadExtent,
threadElementExtent,
false,
alpaka::workdiv::GridBlockExtentSubDivRestrictions::Unrestricted);
return workDiv;
}
}

//-----------------------------------------------------------------------------
TEMPLATE_LIST_TEST_CASE( "getValidWorkDiv", "[workDiv]", alpaka::test::acc::TestAccs)
{
using Acc = TestType;
// Note: getValidWorkDiv() is called inside getWorkDiv
auto workDiv = getWorkDiv< Acc >();
alpaka::ignore_unused( workDiv );
}

//-----------------------------------------------------------------------------
TEMPLATE_LIST_TEST_CASE( "isValidWorkDiv", "[workDiv]", alpaka::test::acc::TestAccs)
{
using Acc = TestType;
using Dev = alpaka::dev::Dev<Acc>;
using Pltf = alpaka::pltf::Pltf<Dev>;

Dev dev(alpaka::pltf::getDevByIdx<Pltf>(0u));
auto workDiv = getWorkDiv< Acc >();
// Test both overloads
REQUIRE( alpaka::workdiv::isValidWorkDiv(
alpaka::acc::getAccDevProps< Acc >( dev ),
workDiv));
REQUIRE( alpaka::workdiv::isValidWorkDiv<Acc>(
dev,
workDiv));
}

0 comments on commit 8bf4639

Please sign in to comment.