File: Test01_execspace.hpp

package info (click to toggle)
kokkos 5.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,148 kB
  • sloc: cpp: 225,388; sh: 1,250; python: 78; makefile: 16; fortran: 4; ansic: 2
file content (85 lines) | stat: -rw-r--r-- 2,613 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project

/// @Kokkos_Feature_Level_Required:1

#include <Kokkos_Macros.hpp>
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
import kokkos.core;
#else
#include <Kokkos_Core.hpp>
#endif
#include <cstdio>
#include <sstream>
#include <type_traits>
#include <gtest/gtest.h>

namespace Test {

// Unit test for Execution Space
// Test1 - testing for memory_space, execution_space, scratch space and
// array_layout of an execution space
// Test2 - Test if the is_execution_space evaluation is working correctly

template <class ExecSpace>
struct TestIncrExecSpaceTypedef {
  void testit() {
    const bool passed =
        (!std::is_void_v<typename ExecSpace::memory_space>)&&std::is_same_v<
            ExecSpace, typename ExecSpace::execution_space> &&
        !std::is_void_v<typename ExecSpace::scratch_memory_space> &&
        !std::is_void_v<typename ExecSpace::array_layout>;
    static_assert(passed == true,
                  "The memory and execution spaces are defined");
  }
};

template <class ExecSpace>
struct TestIncrExecSpace {
  void testit() {
    using device_type     = typename ExecSpace::device_type;
    using memory_space    = typename device_type::memory_space;
    using execution_space = typename device_type::execution_space;

    const bool passed =
        std::is_same_v<device_type,
                       Kokkos::Device<execution_space, memory_space>>;

    static_assert(passed == true,
                  "Checking if the is_execution_space is evaluated correctly");

    ExecSpace().print_configuration(std::cout);
    ExecSpace().fence();

    auto concurrency = ExecSpace().concurrency();
    ASSERT_GT(concurrency, 0);

#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
    KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH()
#endif
    int in_parallel = ExecSpace::in_parallel();
#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
    KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP()
#endif
    ASSERT_FALSE(in_parallel);
#endif

    const char* name = ExecSpace::name();
    std::cout << name << std::endl;
  }
};

TEST(TEST_CATEGORY, IncrTest_01_execspace_typedef) {
  TestIncrExecSpaceTypedef<TEST_EXECSPACE> test;
  test.testit();
}

TEST(TEST_CATEGORY, IncrTest_01_execspace) {
  ASSERT_FALSE(!Kokkos::is_execution_space<TEST_EXECSPACE>::value);
  ASSERT_FALSE(Kokkos::is_execution_space<
               TestIncrExecSpaceTypedef<TEST_EXECSPACE>>::value);
  TestIncrExecSpace<TEST_EXECSPACE> test;
  test.testit();
}
}  // namespace Test