File: TestSIMD_MaskOps.hpp

package info (click to toggle)
kokkos 4.7.01-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,636 kB
  • sloc: cpp: 223,676; sh: 2,446; makefile: 2,437; python: 91; fortran: 4; ansic: 2
file content (120 lines) | stat: -rw-r--r-- 3,902 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//@HEADER
// ************************************************************************
//
//                        Kokkos v. 4.0
//       Copyright (2022) National Technology & Engineering
//               Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#ifndef KOKKOS_TEST_SIMD_MASK_OPS_HPP
#define KOKKOS_TEST_SIMD_MASK_OPS_HPP

#include <Kokkos_SIMD.hpp>
#include <SIMDTesting_Utilities.hpp>

template <typename Abi, typename DataType>
inline void host_check_mask_ops() {
  if constexpr (is_simd_avail_v<DataType, Abi>) {
    using mask_type = Kokkos::Experimental::basic_simd_mask<DataType, Abi>;

    EXPECT_FALSE(none_of(mask_type(true)));
    EXPECT_TRUE(none_of(mask_type(false)));
    EXPECT_TRUE(all_of(mask_type(true)));
    EXPECT_FALSE(all_of(mask_type(false)));
    EXPECT_TRUE(any_of(mask_type(true)));
    EXPECT_FALSE(any_of(mask_type(false)));

    for (std::size_t i = 0; i < mask_type::size(); ++i) {
      mask_type test_mask(KOKKOS_LAMBDA(std::size_t j) { return i == j; });

      EXPECT_TRUE(any_of(test_mask));
      EXPECT_FALSE(none_of(test_mask));

      if constexpr (mask_type::size() > 1) {
        EXPECT_FALSE(all_of(test_mask));
      } else {
        EXPECT_TRUE(all_of(test_mask));
      }
    }
  }
}

template <typename Abi, typename... DataTypes>
inline void host_check_mask_ops_all_types(
    Kokkos::Experimental::Impl::data_types<DataTypes...>) {
  (host_check_mask_ops<Abi, DataTypes>(), ...);
}

template <typename... Abis>
inline void host_check_mask_ops_all_abis(
    Kokkos::Experimental::Impl::abi_set<Abis...>) {
  using DataTypes = Kokkos::Experimental::Impl::data_type_set;
  (host_check_mask_ops_all_types<Abis>(DataTypes()), ...);
}

template <typename Abi, typename DataType>
KOKKOS_INLINE_FUNCTION void device_check_mask_ops() {
  if constexpr (is_type_v<Kokkos::Experimental::basic_simd<DataType, Abi>>) {
    using mask_type = Kokkos::Experimental::basic_simd_mask<DataType, Abi>;
    kokkos_checker checker;
    checker.truth(!none_of(mask_type(true)));
    checker.truth(none_of(mask_type(false)));
    checker.truth(all_of(mask_type(true)));
    checker.truth(!all_of(mask_type(false)));
    checker.truth(any_of(mask_type(true)));
    checker.truth(!any_of(mask_type(false)));

    for (std::size_t i = 0; i < mask_type::size(); ++i) {
      mask_type test_mask(KOKKOS_LAMBDA(std::size_t j) { return i == j; });

      checker.truth(any_of(test_mask));
      checker.truth(!none_of(test_mask));

      if constexpr (mask_type::size() > 1) {
        checker.truth(!all_of(test_mask));
      } else {
        checker.truth(all_of(test_mask));
      }
    }
  }
}

template <typename Abi, typename... DataTypes>
KOKKOS_INLINE_FUNCTION void device_check_mask_ops_all_types(
    Kokkos::Experimental::Impl::data_types<DataTypes...>) {
  (device_check_mask_ops<Abi, DataTypes>(), ...);
}

template <typename... Abis>
KOKKOS_INLINE_FUNCTION void device_check_mask_ops_all_abis(
    Kokkos::Experimental::Impl::abi_set<Abis...>) {
  using DataTypes = Kokkos::Experimental::Impl::data_type_set;
  (device_check_mask_ops_all_types<Abis>(DataTypes()), ...);
}

class simd_device_mask_ops_functor {
 public:
  KOKKOS_INLINE_FUNCTION void operator()(int) const {
    device_check_mask_ops_all_abis(
        Kokkos::Experimental::Impl::device_abi_set());
  }
};

TEST(simd, host_mask_ops) {
  host_check_mask_ops_all_abis(Kokkos::Experimental::Impl::host_abi_set());
}

TEST(simd, device_mask_ops) {
  Kokkos::parallel_for(Kokkos::RangePolicy<Kokkos::IndexType<int>>(0, 1),
                       simd_device_mask_ops_functor());
}

#endif