Skip to content

Commit

Permalink
Add warning for device type template parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Aug 29, 2023
1 parent dd6c4d7 commit e219018
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cajita/src/Cajita_FastFourierTransform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ class FastFourierTransform
using mesh_type = MeshType;
//! Scalar value type.
using value_type = Scalar;

// FIXME: extracting the self type for backwards compatibility with previous
// template on DeviceType. Should simply be MemorySpace after next release.
//! Kokkos memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Cabana::Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Kokkos execution space.
using execution_space = typename memory_space::execution_space;
//! Kokkos execution space.
Expand Down Expand Up @@ -479,10 +483,14 @@ class HeffteFastFourierTransform
public:
//! Scalar value type.
using value_type = Scalar;

// FIXME: extracting the self type for backwards compatibility with previous
// template on DeviceType. Should simply be MemorySpace after next release.
//! Kokkos memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Cabana::Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Kokkos execution space.
using execution_space = ExecSpace;
//! Kokkos execution space.
Expand Down
5 changes: 5 additions & 0 deletions cajita/src/Cajita_LocalMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <Cajita_LocalGrid.hpp>
#include <Cajita_Types.hpp>

#include <Cabana_Utils.hpp>

#include <Kokkos_Core.hpp>

namespace Cajita
Expand Down Expand Up @@ -310,6 +312,9 @@ class LocalMesh<MemorySpace, NonUniformMesh<Scalar, NumSpaceDim>>
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Cabana::Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
//! Default execution space.
Expand Down
1 change: 1 addition & 0 deletions core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(HEADERS_PUBLIC
Cabana_Sort.hpp
Cabana_Tuple.hpp
Cabana_Types.hpp
Cabana_Utils.hpp
Cabana_VerletList.hpp
Cabana_Version.hpp
)
Expand Down
4 changes: 4 additions & 0 deletions core/src/Cabana_AoSoA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Cabana_SoA.hpp>
#include <Cabana_Tuple.hpp>
#include <Cabana_Types.hpp>
#include <Cabana_Utils.hpp>
#include <impl/Cabana_Index.hpp>
#include <impl/Cabana_PerformanceTraits.hpp>

Expand Down Expand Up @@ -136,6 +137,9 @@ class AoSoA
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
//! Default execution space.
Expand Down
3 changes: 3 additions & 0 deletions core/src/Cabana_CommunicationPlan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define CABANA_COMMUNICATIONPLAN_HPP

#include <CabanaCore_config.hpp>
#include <Cabana_Utils.hpp>

#include <Kokkos_Core.hpp>
#include <Kokkos_ScatterView.hpp>
Expand Down Expand Up @@ -423,6 +424,8 @@ class CommunicationPlan
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
Expand Down
1 change: 1 addition & 0 deletions core/src/Cabana_Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <Cabana_Sort.hpp>
#include <Cabana_Tuple.hpp>
#include <Cabana_Types.hpp>
#include <Cabana_Utils.hpp>
#include <Cabana_VerletList.hpp>
#include <Cabana_Version.hpp>

Expand Down
4 changes: 4 additions & 0 deletions core/src/Cabana_LinkedCellList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <Cabana_Slice.hpp>
#include <Cabana_Sort.hpp>
#include <Cabana_Utils.hpp>
#include <impl/Cabana_CartesianGrid.hpp>

#include <Kokkos_Core.hpp>
Expand All @@ -42,6 +43,9 @@ class LinkedCellList
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
//! Default execution space.
Expand Down
4 changes: 4 additions & 0 deletions core/src/Cabana_Slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define CABANA_SLICE_HPP

#include <Cabana_Types.hpp>
#include <Cabana_Utils.hpp>
#include <impl/Cabana_Index.hpp>
#include <impl/Cabana_TypeTraits.hpp>

Expand Down Expand Up @@ -512,6 +513,9 @@ class Slice
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
//! Default execution space.
Expand Down
6 changes: 4 additions & 2 deletions core/src/Cabana_Sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <Cabana_AoSoA.hpp>
#include <Cabana_DeepCopy.hpp>
#include <Cabana_Slice.hpp>
#include <Cabana_Utils.hpp>

#include <Kokkos_Core.hpp>
#include <Kokkos_Sort.hpp>
Expand All @@ -36,12 +37,13 @@ template <class MemorySpace>
class BinningData
{
public:
// FIXME: add static_assert that this is a valid MemorySpace.

// FIXME: extracting the self type for backwards compatibility with previous
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert( Impl::warn( Kokkos::is_device<MemorySpace>() ) );

//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
//! Default execution space.
Expand Down
39 changes: 39 additions & 0 deletions core/src/Cabana_Utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/****************************************************************************
* Copyright (c) 2018-2022 by the Cabana authors *
* All rights reserved. *
* *
* This file is part of the Cabana library. Cabana is distributed under a *
* BSD 3-clause license. For the licensing terms see the LICENSE file in *
* the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

/*!
\file Cabana_Utils.hpp
\brief Cabana utilities.
*/
#ifndef CABANA_UTILS_HPP
#define CABANA_UTILS_HPP

namespace Cabana
{
namespace Impl
{
//! \cond Impl

// Custom warning for switch from device_type to memory_space.
constexpr bool warn( std::false_type ) { return true; }

[[deprecated( "Template parameter should be converted from device type to "
"memory space." )]] constexpr bool
warn( std::true_type )
{
return true;
}
//! \endcond

} // namespace Impl
} // namespace Cabana

#endif

0 comments on commit e219018

Please sign in to comment.