Skip to content

Commit

Permalink
Add test for current CTAD support with RangePolicy (kokkos#6803)
Browse files Browse the repository at this point in the history
* Add test for current CTAD support with RangePolicy

Co-authored-by: Nevin Liber <nliber@anl.gov>

* Rework CTAD test to avoid "memeber <bla> was declared but never referenced" warnings with icpc 19

* Attempt to fix CI

* Attempt to eliminate maybe unused warning in icpc

* Disable CTAD tests for nvcc < 11.2
as compiler bugs prevent CTAD expressions inside decltype

---------

Co-authored-by: Nevin Liber <nliber@anl.gov>
Co-authored-by: Nevin ":-)" Liber <nliber+github@gmail.com>
  • Loading branch information
3 people committed Feb 27, 2024
1 parent e2689ab commit 24f251a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ SET(COMPILE_ONLY_SOURCES
TestDetectionIdiom.cpp
TestBitManipulation.cpp
TestInterOp.cpp
TestRangePolicyCTAD.cpp
TestStringManipulation.cpp
TestVersionMacros.cpp
TestViewRank.cpp
Expand Down
87 changes: 87 additions & 0 deletions core/unit_test/TestRangePolicyCTAD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//@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 "Kokkos_Core_fwd.hpp"

namespace {

template <class... Args>
using PolicyMaker = decltype(::Kokkos::RangePolicy(std::declval<Args>()...));

template <class Policy, class... Args>
inline constexpr bool IsSamePolicy =
std::is_same_v<Policy, PolicyMaker<Args...>>;

#define KOKKOS_TEST_RANGE_POLICY(...) static_assert(IsSamePolicy<__VA_ARGS__>)

struct TestRangePolicyCTAD {
struct ImplicitlyConvertibleToDefaultExecutionSpace {
operator Kokkos::DefaultExecutionSpace() const {
return Kokkos::DefaultExecutionSpace();
}
};
static_assert(!Kokkos::is_execution_space_v<
ImplicitlyConvertibleToDefaultExecutionSpace>);

using des = Kokkos::DefaultExecutionSpace;
using nes = ImplicitlyConvertibleToDefaultExecutionSpace;
using i64 = int64_t;
using i32 = int32_t;
using cs = Kokkos::ChunkSize;

// RangePolicy()

// Guard against GGC 8.4 bug
// error: cannot deduce template arguments for ‘RangePolicy’ from ()
// error: template argument 2 is invalid
#if !defined(KOKKOS_COMPILER_GNU) || (KOKKOS_COMPILER_GNU > 900)
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<> /*, no argument */);
#endif

// RangePolicy(index_type, index_type)

#if !defined(KOKKOS_COMPILER_NVCC) || KOKKOS_COMPILER_NVCC >= 1120
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i64, i64);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i64, i32);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i32, i64);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i32, i32);

// RangePolicy(index_type, index_type, Args...)

KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i64, i64, cs);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i64, i32, cs);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i32, i64, cs);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, i32, i32, cs);

// RangePolicy(execution_space, index_type, index_type)

// none (ambiguous deduction for template arguments)

// RangePolicy(execution_space, index_type, index_type, Args...)

KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, des, i64, i64, cs);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, des, i32, i32, cs);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, nes, i64, i64, cs);
KOKKOS_TEST_RANGE_POLICY(Kokkos::RangePolicy<>, nes, i32, i32, cs);
#endif
}; // TestRangePolicyCTAD struct

// To eliminate maybe_unused warning on some compilers
const Kokkos::DefaultExecutionSpace des =
TestRangePolicyCTAD::ImplicitlyConvertibleToDefaultExecutionSpace();

} // namespace

0 comments on commit 24f251a

Please sign in to comment.