# PhasicFlow: src/phasicFlow/Kokkos/KokkosUtilities.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

KokkosUtilities.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __KokkosUtilities_hpp__
#define __KokkosUtilities_hpp__
#include "KokkosTypes.hpp"
#include "dataIO.hpp"
#include "iOstream.hpp"
#include "pFlowMacros.hpp"
#include "span.hpp"
#include "types.hpp"
namespace pFlow
{
template<typename ExecutionSpace>
INLINE_FUNCTION_H bool constexpr isHostAccessible()
{
return Kokkos::SpaceAccessibility<ExecutionSpace, HostSpace>::accessible;
}
template<typename ExecutionSpace>
INLINE_FUNCTION_H bool constexpr isDeviceAccessible()
{
return Kokkos::SpaceAccessibility<
ExecutionSpace,
DefaultExecutionSpace::memory_space>::accessible;
}
template<typename ExecutionSpace, typename MemoerySpace>
INLINE_FUNCTION_H bool constexpr areAccessible()
{
return Kokkos::SpaceAccessibility<ExecutionSpace, MemoerySpace>::accessible;
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocInit(ViewType1D<Type, Properties...>& view, uint32 len)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocNoInit(ViewType1D<Type, Properties...>& view, uint32 len)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocFill(ViewType1D<Type, Properties...>& view, uint32 len, Type val)
{
reallocNoInit(view, len);
Kokkos::deep_copy(view, val);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocInit(ViewType2D<Type, Properties...>& view, uint32 len1, uint32 len2)
{
Kokkos::realloc(view, len1, len2);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocNoInit(ViewType2D<Type, Properties...>& view, uint32 len1, uint32 len2)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocFill(
ViewType2D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
Type val
)
{
reallocNoInit(view, len1, len2);
Kokkos::deep_copy(view, val);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocInit(
ViewType3D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
uint32 len3
)
{
Kokkos::realloc(view, len1, len2, len3);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocNoInit(
ViewType3D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
uint32 len3
)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2, len3);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocFill(
ViewType3D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
uint32 len3,
Type val
)
{
reallocNoInit(view, len1, len2, len3);
Kokkos::deep_copy(view, val);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
resizeInit(ViewType1D<Type, Properties...>& view, uint32 newLen)
{
Kokkos::resize(view, newLen);
}
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
resizeNoInit(ViewType1D<Type, Properties...>& view, uint32 newLen)
{
Kokkos::resize(Kokkos::WithoutInitializing, view, newLen);
}
template<typename ViewType>
INLINE_FUNCTION_H void
swapViews(ViewType& v1, ViewType& v2)
{
static_assert(
std::is_move_assignable_v<ViewType> &&
std::is_move_constructible_v<ViewType>,
"swapViews arguments must be move assignable and move constructible"
);
ViewType tmp = std::move(v1);
v1 = std::move(v2);
v2 = std::move(tmp);
}
template<typename T1, typename T2>
INLINE_FUNCTION_H iOstream&
operator<<(iOstream& os, const Pair<T1, T2>& p)
{
os << '(' << p.first << " " << p.second << ')';
return os;
}
template<typename T, typename... properties>
INLINE_FUNCTION_H span<T>
makeSpan(ViewType1D<T, properties...>& v)
{
return span<T>(v.data(), v.size());
}
template<typename T, typename... properties>
INLINE_FUNCTION_H span<T>
makeSpan(ViewType1D<T, properties...>& v, uint32 size)
{
return span<T>(v.data(), size);
}
template<typename T, typename... properties>
INLINE_FUNCTION_H span<T>
makeSpan(const ViewType1D<T, properties...>& v)
{
return span<T>(const_cast<T*>(v.data()), v.size());
}
template<typename T, typename... properties>
INLINE_FUNCTION_H span<T>
makeSpan(const ViewType1D<T, properties...>& v, uint32 size)
{
return span<T>(const_cast<T*>(v.data()), size);
}
template<typename T, typename... properties>
INLINE_FUNCTION_H iOstream&
operator<<(iOstream& os, const ViewType1D<T, properties...>& v)
{
using ExSpace = typename ViewType1D<T, properties...>::execution_space;
static_assert(
isHostAccessible<ExSpace>(), "View memory is not accessible from Host"
);
span<T> spn(v.data(), v.size());
os << spn;
return os;
}
} // pFlow
#endif //__KokkosUtilities_hpp__
pFlow::span
Definition: span.hpp:31
pFlow::isDeviceAccessible
INLINE_FUNCTION_H constexpr bool isDeviceAccessible()
Definition: KokkosUtilities.hpp:41
pFlow::reallocFill
INLINE_FUNCTION_H void reallocFill(ViewType1D< Type, Properties... > &view, uint32 len, Type val)
Definition: KokkosUtilities.hpp:71
pFlow::resizeNoInit
INLINE_FUNCTION_H void resizeNoInit(ViewType1D< Type, Properties... > &view, uint32 newLen)
Definition: KokkosUtilities.hpp:151
pFlow::reallocInit
INLINE_FUNCTION_H void reallocInit(ViewType1D< Type, Properties... > &view, uint32 len)
Definition: KokkosUtilities.hpp:57
types.hpp
pFlow::Pair
Kokkos::pair< T1, T2 > Pair
Pair of two variables.
Definition: KokkosTypes.hpp:85
pFlow::ViewType2D
Kokkos::View< T **, properties... > ViewType2D
2D view as an array
Definition: KokkosTypes.hpp:97
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, uint32 len)
Definition: KokkosUtilities.hpp:64
KokkosTypes.hpp
pFlow
Definition: demGeometry.hpp:27
pFlowMacros.hpp
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:57
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::resizeInit
INLINE_FUNCTION_H void resizeInit(ViewType1D< Type, Properties... > &view, uint32 newLen)
Definition: KokkosUtilities.hpp:144
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Definition: KokkosTypes.hpp:93
dataIO.hpp
pFlow::ViewType3D
Kokkos::View< T ***, properties... > ViewType3D
3D view as an array
Definition: KokkosTypes.hpp:101
pFlow::areAccessible
INLINE_FUNCTION_H constexpr bool areAccessible()
Is MemoerySpace accessible from ExecutionSpace.
Definition: KokkosUtilities.hpp:50
iOstream.hpp
pFlow::isHostAccessible
INLINE_FUNCTION_H constexpr bool isHostAccessible()
Definition: KokkosUtilities.hpp:35
pFlow::makeSpan
span< T > makeSpan(std::vector< T > &container)
Definition: stdVectorHelper.hpp:53
span.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::swapViews
INLINE_FUNCTION_H void swapViews(ViewType &v1, ViewType &v2)
Definition: KokkosUtilities.hpp:158