Skip to content

Commit

Permalink
Merge pull request #10 from uliegecsm/concepts-exec-mem
Browse files Browse the repository at this point in the history
 concepts(core): ExecutionSpace, MemorySpace and Space concepts for C++20
  • Loading branch information
maartenarnst authored Jun 26, 2024
2 parents 179d42c + 7d55d87 commit 3af8ccf
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 1 deletion.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dockerFile": "dockerfile",
"extensions" : [
"ms-vscode.cmake-tools",
"eamodio.gitlens",
"mhutchie.git-graph",
"ms-azuretools.vscode-docker"
],
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ target_sources(
include/kokkos-utils/atomics/InsertOp.hpp

include/kokkos-utils/concepts/DualView.hpp

include/kokkos-utils/concepts/ExecutionSpace.hpp
include/kokkos-utils/concepts/MemorySpace.hpp
include/kokkos-utils/concepts/Space.hpp
include/kokkos-utils/concepts/View.hpp
)

Expand Down
15 changes: 15 additions & 0 deletions include/kokkos-utils/concepts/ExecutionSpace.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef KOKKOS_UTILS_CONCEPTS_EXECUTIONSPACE_HPP
#define KOKKOS_UTILS_CONCEPTS_EXECUTIONSPACE_HPP

#include "Kokkos_Concepts.hpp"

namespace Kokkos::utils::concepts
{

//! Concept to specify that a type is a @c Kokkos execution space.
template <typename T>
concept ExecutionSpace = Kokkos::is_execution_space_v<T>;

} // namespace Kokkos::utils::concepts

#endif // KOKKOS_UTILS_CONCEPTS_EXECUTIONSPACE_HPP
15 changes: 15 additions & 0 deletions include/kokkos-utils/concepts/MemorySpace.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef KOKKOS_UTILS_CONCEPTS_MEMORYSPACE_HPP
#define KOKKOS_UTILS_CONCEPTS_MEMORYSPACE_HPP

#include "Kokkos_Concepts.hpp"

namespace Kokkos::utils::concepts
{

//! Concept to specify that a type is a @c Kokkos memory space.
template <typename T>
concept MemorySpace = Kokkos::is_memory_space_v<T>;

} // namespace Kokkos::utils::concepts

#endif // KOKKOS_UTILS_CONCEPTS_MEMORYSPACE_HPP
15 changes: 15 additions & 0 deletions include/kokkos-utils/concepts/Space.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef KOKKOS_UTILS_CONCEPTS_SPACE_HPP
#define KOKKOS_UTILS_CONCEPTS_SPACE_HPP

#include "Kokkos_Concepts.hpp"

namespace Kokkos::utils::concepts
{

//! Concept to specify that a type is a @c Kokkos space.
template <typename T>
concept Space = Kokkos::is_space<T>::value;

} // namespace Kokkos::utils::concepts

#endif // KOKKOS_UTILS_CONCEPTS_SPACE_HPP
16 changes: 15 additions & 1 deletion tests/concepts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ add_one_test(
TEST_NAME DualView
)

### TEST : ExecutionSpace ###
add_one_test(
TEST_NAME ExecutionSpace
)

### TEST : MemorySpace ###
add_one_test(
TEST_NAME MemorySpace
)

### TEST : Space ###
add_one_test(
TEST_NAME Space
)

### TEST : View ###
add_one_test(
TEST_NAME View
)

30 changes: 30 additions & 0 deletions tests/concepts/test_ExecutionSpace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "gtest/gtest.h"

#include "Kokkos_Core.hpp"

#include "kokkos-utils/concepts/ExecutionSpace.hpp"

using execution_space = Kokkos::DefaultExecutionSpace;

/**
* @file
*
* @addtogroup unittests
*
* **Concepts related to @c Kokkos execution space**
*
* This group of tests check the behavior of our concepts related to @c Kokkos execution space.
*/

namespace Kokkos::utils::tests::concepts
{

//! @test Check that @ref Kokkos::utils::concepts::ExecutionSpace works as expected.
TEST(concepts, ExecutionSpace)
{
static_assert( Kokkos::utils::concepts::ExecutionSpace<typename execution_space::execution_space>);
static_assert(! Kokkos::utils::concepts::ExecutionSpace<typename execution_space::memory_space>);
static_assert(! Kokkos::utils::concepts::ExecutionSpace<Kokkos::Device<typename execution_space::execution_space, typename execution_space::memory_space>>);
}

} // namespace Kokkos::utils::tests::concepts
30 changes: 30 additions & 0 deletions tests/concepts/test_MemorySpace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "gtest/gtest.h"

#include "Kokkos_Core.hpp"

#include "kokkos-utils/concepts/MemorySpace.hpp"

using execution_space = Kokkos::DefaultExecutionSpace;

/**
* @file
*
* @addtogroup unittests
*
* **Concepts related to @c Kokkos memory space**
*
* This group of tests check the behavior of our concepts related to @c Kokkos memory space.
*/

namespace Kokkos::utils::tests::concepts
{

//! @test Check that @ref Kokkos::utils::concepts::MemorySpace works as expected.
TEST(concepts, MemorySpace)
{
static_assert(! Kokkos::utils::concepts::MemorySpace<typename execution_space::execution_space>);
static_assert( Kokkos::utils::concepts::MemorySpace<typename execution_space::memory_space>);
static_assert(! Kokkos::utils::concepts::MemorySpace<Kokkos::Device<typename execution_space::execution_space, typename execution_space::memory_space>>);
}

} // namespace Kokkos::utils::tests::concepts
30 changes: 30 additions & 0 deletions tests/concepts/test_Space.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "gtest/gtest.h"

#include "Kokkos_Core.hpp"

#include "kokkos-utils/concepts/Space.hpp"

using execution_space = Kokkos::DefaultExecutionSpace;

/**
* @file
*
* @addtogroup unittests
*
* **Concepts related to @c Kokkos space**
*
* This group of tests check the behavior of our concepts related to @c Kokkos space.
*/

namespace Kokkos::utils::tests::concepts
{

//! @test Check that @ref Kokkos::utils::concepts::Space works as expected.
TEST(concepts, Space)
{
static_assert(Kokkos::utils::concepts::Space<typename execution_space::execution_space>);
static_assert(Kokkos::utils::concepts::Space<typename execution_space::memory_space>);
static_assert(Kokkos::utils::concepts::Space<Kokkos::Device<typename execution_space::execution_space, typename execution_space::memory_space>>);
}

} // namespace Kokkos::utils::tests::concepts

0 comments on commit 3af8ccf

Please sign in to comment.