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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
//@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
#include <Kokkos_Core.hpp>
#include "tools/include/ToolTestingUtilities.hpp"
TEST(TEST_CATEGORY, resize_realloc_no_init) {
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableKernels());
Kokkos::View<int**** [1][2][3][4], TEST_EXECSPACE> bla("bla", 5, 6, 7, 8);
auto success = validate_absence(
[&]() {
Kokkos::resize(Kokkos::WithoutInitializing, bla, 5, 6, 7, 9);
Kokkos::realloc(Kokkos::WithoutInitializing, bla, 8, 8, 8, 8);
Kokkos::realloc(Kokkos::view_alloc(Kokkos::WithoutInitializing), bla, 5,
6, 7, 8);
},
[&](BeginParallelForEvent event) {
if (event.descriptor().find("initialization") != std::string::npos)
return MatchDiagnostic{true, {"Found begin event"}};
return MatchDiagnostic{false};
},
[&](EndParallelForEvent event) {
if (event.descriptor().find("initialization") != std::string::npos)
return MatchDiagnostic{true, {"Found end event"}};
return MatchDiagnostic{false};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, resize_realloc_no_alloc) {
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableKernels(),
Config::EnableAllocs());
Kokkos::View<int**** [1][2][3][4], TEST_EXECSPACE> bla("bla", 8, 7, 6, 5);
auto success = validate_absence(
[&]() {
Kokkos::resize(bla, 8, 7, 6, 5);
Kokkos::realloc(Kokkos::WithoutInitializing, bla, 8, 7, 6, 5);
},
[&](BeginParallelForEvent) {
return MatchDiagnostic{true, {"Found begin event"}};
},
[&](EndParallelForEvent) {
return MatchDiagnostic{true, {"Found end event"}};
},
[&](AllocateDataEvent) {
return MatchDiagnostic{true, {"Found alloc event"}};
},
[&](DeallocateDataEvent) {
return MatchDiagnostic{true, {"Found dealloc event"}};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, realloc_exec_space) {
#ifdef KOKKOS_ENABLE_CUDA
if (std::is_same_v<typename TEST_EXECSPACE::memory_space,
Kokkos::CudaUVMSpace>)
GTEST_SKIP() << "skipping since CudaUVMSpace requires additional fences";
#endif
// FIXME_OPENMPTARGET The OpenMPTarget backend doesn't implement allocate taking
// an execution space instance properly so it needs another fence
#ifdef KOKKOS_ENABLE_OPENMPTARGET
if (std::is_same<TEST_EXECSPACE, Kokkos::Experimental::OpenMPTarget>::value)
GTEST_SKIP() << "skipping since the OpenMPTarget backend doesn't implement "
"allocate taking an execution space instance properly";
#endif
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableFences());
using view_type = Kokkos::View<int*, TEST_EXECSPACE>;
view_type outer_view, outer_view2;
auto success = validate_absence(
[&]() {
view_type inner_view(Kokkos::view_alloc(TEST_EXECSPACE{}, "bla"), 8);
// Avoid testing the destructor
outer_view = inner_view;
Kokkos::realloc(
Kokkos::view_alloc(Kokkos::WithoutInitializing, TEST_EXECSPACE{}),
inner_view, 10);
outer_view2 = inner_view;
Kokkos::realloc(Kokkos::view_alloc(TEST_EXECSPACE{}), inner_view, 10);
},
[&](BeginFenceEvent event) {
if ((event.descriptor().find("Debug Only Check for Execution Error") !=
std::string::npos) ||
(event.descriptor().find("HostSpace fence") != std::string::npos))
return MatchDiagnostic{false};
return MatchDiagnostic{true, {"Found fence event!"}};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
namespace {
struct NonTriviallyCopyable {
KOKKOS_FUNCTION NonTriviallyCopyable() {}
KOKKOS_FUNCTION NonTriviallyCopyable(const NonTriviallyCopyable&) {}
};
} // namespace
TEST(TEST_CATEGORY, view_alloc) {
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableFences());
using view_type = Kokkos::View<NonTriviallyCopyable*, TEST_EXECSPACE>;
view_type outer_view;
auto success = validate_existence(
[&]() {
view_type inner_view(Kokkos::view_alloc("bla"), 8);
// Avoid testing the destructor
outer_view = inner_view;
},
[&](BeginFenceEvent event) {
return MatchDiagnostic{
event.descriptor().find("Kokkos::View::initialization") !=
std::string::npos};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, view_alloc_exec_space) {
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableFences());
using view_type = Kokkos::View<NonTriviallyCopyable*, TEST_EXECSPACE>;
view_type outer_view;
auto success = validate_absence(
[&]() {
view_type inner_view(Kokkos::view_alloc(TEST_EXECSPACE{}, "bla"), 8);
// Avoid testing the destructor
outer_view = inner_view;
},
[&](BeginFenceEvent event) {
return MatchDiagnostic{
event.descriptor().find("Kokkos::View::initialization") !=
std::string::npos};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, view_alloc_int) {
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableFences());
using view_type = Kokkos::View<int*, TEST_EXECSPACE>;
view_type outer_view;
auto success = validate_existence(
[&]() {
view_type inner_view("bla", 8);
// Avoid testing the destructor
outer_view = inner_view;
},
[&](BeginFenceEvent event) {
return MatchDiagnostic{
event.descriptor().find("Kokkos::View::initialization") !=
std::string::npos};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, view_alloc_exec_space_int) {
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableFences());
using view_type = Kokkos::View<int*, TEST_EXECSPACE>;
view_type outer_view;
auto success = validate_absence(
[&]() {
view_type inner_view(Kokkos::view_alloc(TEST_EXECSPACE{}, "bla"), 8);
// Avoid testing the destructor
outer_view = inner_view;
},
[&](BeginFenceEvent event) {
return MatchDiagnostic{
event.descriptor().find("Kokkos::View::initialization") !=
std::string::npos};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, deep_copy_zero_memset) {
// FIXME_OPENMPTARGET The OpenMPTarget backend doesn't implement ZeroMemset
#ifdef KOKKOS_ENABLE_OPENMPTARGET
if (std::is_same<TEST_EXECSPACE, Kokkos::Experimental::OpenMPTarget>::value)
GTEST_SKIP() << "skipping since the OpenMPTarget backend doesn't implement "
"ZeroMemset";
#endif
// FIXME_OPENACC: The OpenACC backend doesn't implement ZeroMemset
#ifdef KOKKOS_ENABLE_OPENACC
if (std::is_same<TEST_EXECSPACE, Kokkos::Experimental::OpenACC>::value)
GTEST_SKIP() << "skipping since the OpenACC backend doesn't implement "
"ZeroMemset";
#endif
#ifdef KOKKOS_ENABLE_OPENMP
if (std::is_same_v<TEST_EXECSPACE, Kokkos::OpenMP>)
GTEST_SKIP() << "skipping since the OpenMP backend doesn't use ZeroMemset";
#endif
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableKernels());
Kokkos::View<int*, TEST_EXECSPACE> bla("bla", 8);
// for MI300A with unified memory, ZeroMemset uses a parallel for
auto success = false;
#ifdef KOKKOS_IMPL_HIP_UNIFIED_MEMORY
if constexpr (!std::is_same_v<TEST_EXECSPACE::memory_space,
Kokkos::HostSpace>)
success = validate_existence(
[&]() { Kokkos::deep_copy(bla, 0); },
[&](BeginParallelForEvent e) {
const bool found =
(e.descriptor().find("Kokkos::ZeroMemset via parallel_for") !=
std::string::npos);
return MatchDiagnostic{found, {"Found expected parallel_for label"}};
});
else
#endif
success =
validate_absence([&]() { Kokkos::deep_copy(bla, 0); },
[&](BeginParallelForEvent) {
return MatchDiagnostic{true, {"Found begin event"}};
},
[&](EndParallelForEvent) {
return MatchDiagnostic{true, {"Found end event"}};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, resize_exec_space) {
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::DisableAll(), Config::EnableFences(),
Config::EnableKernels());
Kokkos::View<int**** [1][2][3][4], TEST_EXECSPACE> bla("bla", 8, 7, 6, 5);
auto success = validate_absence(
[&]() {
Kokkos::resize(
Kokkos::view_alloc(TEST_EXECSPACE{}, Kokkos::WithoutInitializing),
bla, 5, 6, 7, 8);
},
[&](BeginFenceEvent event) {
if (event.descriptor().find("Kokkos::resize(View)") !=
std::string::npos)
return MatchDiagnostic{true, {"Found begin event"}};
return MatchDiagnostic{false};
},
[&](EndFenceEvent event) {
if (event.descriptor().find("Kokkos::resize(View)") !=
std::string::npos)
return MatchDiagnostic{true, {"Found end event"}};
return MatchDiagnostic{false};
},
[&](BeginParallelForEvent event) {
if (event.descriptor().find("initialization") != std::string::npos)
return MatchDiagnostic{true, {"Found begin event"}};
return MatchDiagnostic{false};
},
[&](EndParallelForEvent event) {
if (event.descriptor().find("initialization") != std::string::npos)
return MatchDiagnostic{true, {"Found end event"}};
return MatchDiagnostic{false};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, view_allocation_int) {
// FIXME_OPENMPTARGET
#ifdef KOKKOS_ENABLE_OPENMPTARGET
if (std::is_same<TEST_EXECSPACE, Kokkos::Experimental::OpenMPTarget>::value)
GTEST_SKIP() << "skipping since the OpenMPTarget has unexpected fences";
#endif
using ExecutionSpace = TEST_EXECSPACE;
if (Kokkos::SpaceAccessibility<
/*AccessSpace=*/Kokkos::HostSpace,
/*MemorySpace=*/ExecutionSpace::memory_space>::accessible) {
GTEST_SKIP() << "skipping since the fence checked for isn't necessary";
}
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::EnableAll());
using view_type = Kokkos::View<int*, TEST_EXECSPACE>;
view_type outer_view;
auto success = validate_existence(
[&]() {
view_type inner_view(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "bla"), 8);
// Avoid testing the destructor
outer_view = inner_view;
},
[&](BeginFenceEvent event) {
return MatchDiagnostic{
event.descriptor().find(
"fence after copying header from HostSpace") !=
std::string::npos};
});
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
TEST(TEST_CATEGORY, view_allocation_exec_space_int) {
#ifdef KOKKOS_ENABLE_OPENMPTARGET // FIXME_OPENMPTARGET
if (std::is_same<TEST_EXECSPACE, Kokkos::Experimental::OpenMPTarget>::value)
GTEST_SKIP() << "skipping since the OpenMPTarget has unexpected fences";
#endif
#ifdef KOKKOS_ENABLE_CUDA
if (std::is_same_v<TEST_EXECSPACE::memory_space, Kokkos::CudaUVMSpace>)
GTEST_SKIP()
<< "skipping since the CudaUVMSpace requires additiional fences";
#endif
using namespace Kokkos::Test::Tools;
listen_tool_events(Config::EnableAll());
using view_type = Kokkos::View<int*, TEST_EXECSPACE>;
view_type outer_view;
auto success = validate_absence(
[&]() {
view_type inner_view(Kokkos::view_alloc(Kokkos::WithoutInitializing,
TEST_EXECSPACE{}, "bla"),
8);
// Avoid testing the destructor
outer_view = inner_view;
},
[&](BeginFenceEvent) { return MatchDiagnostic{true}; });
ASSERT_TRUE(success);
listen_tool_events(Config::DisableAll());
}
struct NotDefaultConstructible {
NotDefaultConstructible() = delete;
};
TEST(TEST_CATEGORY, view_not_default_constructible) {
using Space = TEST_EXECSPACE;
Kokkos::View<NotDefaultConstructible, Space> my_view(Kokkos::view_alloc(
"not_default_constructible", Kokkos::WithoutInitializing));
}
|