//@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 #include namespace { template void test_view_bad_alloc() { bool did_throw = false; auto too_large = std::numeric_limits::max() - 42; std::string label = "my_label"; try { auto should_always_fail = Kokkos::View(label, too_large); } catch (std::runtime_error const &error) { std::string msg = error.what(); ASSERT_PRED_FORMAT2( ::testing::IsSubstring, std::string(MemorySpace::name()) + " memory space failed to allocate", msg) << "memory space name is missing"; ASSERT_PRED_FORMAT2(::testing::IsSubstring, std::string("(label=\"") + label + "\")", msg) << "label is missing"; did_throw = true; } ASSERT_TRUE(did_throw); } TEST(TEST_CATEGORY, view_bad_alloc) { using ExecutionSpace = TEST_EXECSPACE; using MemorySpace = ExecutionSpace::memory_space; #if defined(__has_feature) #if __has_feature(address_sanitizer) if (std::is_same_v) { GTEST_SKIP() << "AddressSanitizer detects allocating too much memory " "preventing our checks to run"; } #endif #endif #if ((HIP_VERSION_MAJOR == 5) && (HIP_VERSION_MINOR == 3)) if (std::is_same_v) { GTEST_SKIP() << "ROCm 5.3 segfaults when trying to allocate too much memory"; } #endif #if defined(KOKKOS_ENABLE_OPENACC) // FIXME_OPENACC if (std::is_same_v) { GTEST_SKIP() << "acc_malloc() not properly returning nullptr"; } #endif #if defined(_WIN32) && defined(KOKKOS_ENABLE_CUDA) if (std::is_same_v) { GTEST_SKIP() << "MSVC/CUDA segfaults when allocating too much memory"; } #endif test_view_bad_alloc(); constexpr bool execution_space_is_device = std::is_same_v && !std::is_same_v; if constexpr (execution_space_is_device) { #ifdef KOKKOS_HAS_SHARED_SPACE test_view_bad_alloc(); #endif #ifdef KOKKOS_HAS_SHARED_HOST_PINNED_SPACE test_view_bad_alloc(); #endif } } } // namespace