Skip to content

Commit

Permalink
add memory visibility to raw pointer view
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonEhrig committed May 14, 2024
1 parent 893c367 commit 2db4b35
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 76 deletions.
1 change: 0 additions & 1 deletion include/alpaka/alpaka.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
#include "alpaka/meta/Integral.hpp"
#include "alpaka/meta/IsArrayOrVector.hpp"
#include "alpaka/meta/IsStrictBase.hpp"
#include "alpaka/meta/IsTuple.hpp"
#include "alpaka/meta/NdLoop.hpp"
#include "alpaka/meta/NonZero.hpp"
#include "alpaka/meta/Set.hpp"
Expand Down
11 changes: 7 additions & 4 deletions include/alpaka/mem/Visibility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

#pragma once

#include "alpaka/acc/Traits.hpp"
#include "alpaka/dev/Traits.hpp"
#include "alpaka/mem/view/ViewAccessOps.hpp"
#include "alpaka/meta/ForEachType.hpp"
#include "alpaka/meta/IsTuple.hpp"
#include "alpaka/meta/TypeListOps.hpp"
#include "alpaka/platform/Traits.hpp"

#include <iostream>
#include <sstream>
Expand All @@ -17,7 +19,7 @@
#define CREATE_MEM_VISIBILITY(mem_name) \
struct mem_name \
{ \
static std::string name() \
static std::string get_name() \
{ \
return #mem_name; \
} \
Expand Down Expand Up @@ -49,7 +51,7 @@ namespace alpaka
template<typename TTYPE>
void operator()(std::vector<std::string>& vs)
{
vs.push_back(TTYPE::name());
vs.push_back(TTYPE::get_name());
}
};
} // namespace detail
Expand Down Expand Up @@ -84,7 +86,7 @@ namespace alpaka
}
else
{
return MemVisibilityType::name();
return MemVisibilityType::get_name();
}
}

Expand Down Expand Up @@ -115,6 +117,7 @@ namespace alpaka
typename alpaka::trait::MemVisibility<TBuf>::type,
typename alpaka::trait::MemVisibility<T>::type>::value;
}
ALPAKA_UNREACHABLE({});
}

template<typename TDev, typename TBuf>
Expand Down
70 changes: 46 additions & 24 deletions include/alpaka/mem/view/ViewPlainPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
#include "alpaka/dev/DevCpu.hpp"
#include "alpaka/dev/DevGenericSycl.hpp"
#include "alpaka/dev/DevUniformCudaHipRt.hpp"
#include "alpaka/mem/Visibility.hpp"
#include "alpaka/mem/view/Traits.hpp"
#include "alpaka/mem/view/ViewAccessOps.hpp"
#include "alpaka/meta/DependentFalseType.hpp"
#include "alpaka/meta/TypeListOps.hpp"
#include "alpaka/platform/PlatformCpu.hpp"
#include "alpaka/platform/PlatformCpuSycl.hpp"
#include "alpaka/platform/PlatformCudaRt.hpp"
#include "alpaka/platform/PlatformFpgaSyclIntel.hpp"
#include "alpaka/platform/PlatformGenericSycl.hpp"
#include "alpaka/platform/PlatformGpuSyclIntel.hpp"
#include "alpaka/platform/PlatformHipRt.hpp"
#include "alpaka/vec/Vec.hpp"

#include <type_traits>
Expand All @@ -19,8 +28,14 @@
namespace alpaka
{
//! The memory view to wrap plain pointers.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct ViewPlainPtr final : internal::ViewAccessOps<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<
typename TDev,
typename TElem,
typename TDim,
typename TIdx,
typename TMemVisibility =
typename alpaka::meta::toTuple<typename alpaka::trait::MemVisibility<alpaka::Platform<TDev>>::type>::type>
struct ViewPlainPtr final : internal::ViewAccessOps<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
static_assert(!std::is_const_v<TIdx>, "The idx type of the view can not be const!");

Expand Down Expand Up @@ -49,15 +64,21 @@ namespace alpaka
namespace trait
{
//! The ViewPlainPtr device type trait specialization.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct DevType<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct DevType<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
using type = alpaka::Dev<TDev>;
};

template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct MemVisibility<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
using type = TMemVisibility;
};

//! The ViewPlainPtr device get trait specialization.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct GetDev<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct GetDev<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
static auto getDev(ViewPlainPtr<TDev, TElem, TDim, TIdx> const& view) -> alpaka::Dev<TDev>
{
Expand All @@ -66,48 +87,48 @@ namespace alpaka
};

//! The ViewPlainPtr dimension getter trait.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct DimType<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct DimType<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
using type = TDim;
};

//! The ViewPlainPtr memory element type get trait specialization.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct ElemType<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct ElemType<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
using type = TElem;
};
} // namespace trait

namespace trait
{
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct GetExtents<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct GetExtents<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
ALPAKA_FN_HOST auto operator()(ViewPlainPtr<TDev, TElem, TDim, TIdx> const& view) const
ALPAKA_FN_HOST auto operator()(ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility> const& view) const
{
return view.m_extentElements;
}
};

//! The ViewPlainPtr native pointer get trait specialization.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct GetPtrNative<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct GetPtrNative<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
static auto getPtrNative(ViewPlainPtr<TDev, TElem, TDim, TIdx> const& view) -> TElem const*
static auto getPtrNative(ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility> const& view) -> TElem const*
{
return view.m_pMem;
}

static auto getPtrNative(ViewPlainPtr<TDev, TElem, TDim, TIdx>& view) -> TElem*
static auto getPtrNative(ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>& view) -> TElem*
{
return view.m_pMem;
}
};

template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct GetPitchesInBytes<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct GetPitchesInBytes<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
ALPAKA_FN_HOST auto operator()(ViewPlainPtr<TDev, TElem, TDim, TIdx> const& view) const
{
Expand Down Expand Up @@ -174,18 +195,19 @@ namespace alpaka
};
#endif
//! The ViewPlainPtr offset get trait specialization.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct GetOffsets<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct GetOffsets<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
ALPAKA_FN_HOST auto operator()(ViewPlainPtr<TDev, TElem, TDim, TIdx> const&) const -> Vec<TDim, TIdx>
ALPAKA_FN_HOST auto operator()(ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility> const&) const
-> Vec<TDim, TIdx>
{
return Vec<TDim, TIdx>::zeros();
}
};

//! The ViewPlainPtr idx type trait specialization.
template<typename TDev, typename TElem, typename TDim, typename TIdx>
struct IdxType<ViewPlainPtr<TDev, TElem, TDim, TIdx>>
template<typename TDev, typename TElem, typename TDim, typename TIdx, typename TMemVisibility>
struct IdxType<ViewPlainPtr<TDev, TElem, TDim, TIdx, TMemVisibility>>
{
using type = TIdx;
};
Expand Down
29 changes: 0 additions & 29 deletions include/alpaka/meta/IsTuple.hpp

This file was deleted.

33 changes: 32 additions & 1 deletion include/alpaka/meta/TypeListOps.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* Copyright 2022 Bernhard Manfred Gruber
/* Copyright 2024 Bernhard Manfred Gruber, Simeon Ehrig
* SPDX-License-Identifier: MPL-2.0
*/

#pragma once

#include <tuple>
#include <type_traits>

namespace alpaka::meta
Expand Down Expand Up @@ -35,4 +36,34 @@ namespace alpaka::meta
{
static constexpr bool value = std::is_same_v<Head, Value> || Contains<List<Tail...>, Value>::value;
};

// copied from https://stackoverflow.com/a/51073558/22035743
template<typename T>
struct IsTuple : std::false_type
{
};

template<typename... U>
struct IsTuple<std::tuple<U...>> : std::true_type
{
};

template<typename T>
constexpr bool isTuple()
{
return IsTuple<std::decay_t<T>>::value;
}

template<typename... T>
struct toTuple
{
using type = std::tuple<T...>;
};

template<typename... U>
struct toTuple<std::tuple<U...>>
{
using type = std::tuple<U...>;
};

} // namespace alpaka::meta
Loading

0 comments on commit 2db4b35

Please sign in to comment.