Skip to content

Commit

Permalink
implement memory visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonEhrig committed Oct 11, 2023
1 parent 2b64195 commit 5fdcb22
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccCpuOmp2Blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ namespace alpaka
{
using type = alpaka::AccCpuOmp2Blocks<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleCPU;
};
} // namespace trait
} // namespace alpaka

Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccCpuOmp2Threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ namespace alpaka
{
using type = alpaka::AccCpuOmp2Threads<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleCPU;
};
} // namespace trait
} // namespace alpaka

Expand Down
7 changes: 7 additions & 0 deletions include/alpaka/acc/AccCpuSerial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "alpaka/acc/Tag.hpp"
#include "alpaka/core/Concepts.hpp"
#include "alpaka/dev/DevCpu.hpp"
#include "alpaka/mem/Visibility.hpp"

#include <memory>
#include <typeinfo>
Expand Down Expand Up @@ -200,6 +201,12 @@ namespace alpaka
{
using type = alpaka::AccCpuSerial<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleCPU;
};
} // namespace trait
} // namespace alpaka

Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccCpuSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ namespace alpaka::trait
{
using type = alpaka::AccCpuSycl<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleCPU;
};
} // namespace alpaka::trait

#endif
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccCpuTbbBlocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ namespace alpaka
{
using type = alpaka::AccCpuTbbBlocks<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleCPU;
};
} // namespace trait
} // namespace alpaka

Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccCpuThreads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ namespace alpaka
{
using type = alpaka::AccCpuThreads<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleCPU;
};
} // namespace trait
} // namespace alpaka

Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccFpgaSyclIntel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ namespace alpaka::trait
{
using type = alpaka::AccFpgaSyclIntel<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleFpgaSyclIntel;
};
} // namespace alpaka::trait

#endif
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccGenericSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ namespace alpaka::trait
using type = TAcc<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleGenericSycl;
};

//! The SYCL accelerator device properties get trait specialization.
template<template<typename, typename> typename TAcc, typename TDim, typename TIdx>
struct GetAccDevProps<
Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccGpuCudaRt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ namespace alpaka
{
using type = alpaka::AccGpuCudaRt<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleGpuCudaRt;
};
} // namespace trait
} // namespace alpaka

Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccGpuHipRt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ namespace alpaka
{
using type = alpaka::AccGpuHipRt<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleGpuHipRt;
};
} // namespace trait
} // namespace alpaka

Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/acc/AccGpuSyclIntel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ namespace alpaka::trait
{
using type = alpaka::AccGpuSyclIntel<TDim, TIdx>;
};

template<typename TDim, typename TIdx>
struct MemVisibility<alpaka::AccCpuSerial<TDim, TIdx>>
{
using type = alpaka::MemVisibleGpuSyclIntel;
};
} // namespace alpaka::trait

#endif
47 changes: 47 additions & 0 deletions include/alpaka/mem/Visibility.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright 2023 Simeon Ehrig
* SPDX-License-Identifier: MPL-2.0
*/

#pragma once

#include "alpaka/meta/TypeListOps.hpp"

#include <iostream>

#define CREATE_MEM_VISIBILITY(mem_name) \
struct mem_name \
{ \
static std::string get_name() \
{ \
return #mem_name; \
} \
}

namespace alpaka
{
CREATE_MEM_VISIBILITY(MemVisibleCPU);
CREATE_MEM_VISIBILITY(MemVisibleFpgaSyclIntel);
CREATE_MEM_VISIBILITY(MemVisibleGenericSycl);
CREATE_MEM_VISIBILITY(MemVisibleGpuCudaRt);
CREATE_MEM_VISIBILITY(MemVisibleGpuHipRt);
CREATE_MEM_VISIBILITY(MemVisibleGpuSyclIntel);

namespace trait
{
//! Get memory visibility from a type.
//! Normally it is acc or buffer type.
//!
//! \tparam Type which implements the trait
//! \return Memory visibility type
template<typename TType>
struct MemVisibility;
} // namespace trait

template<typename TAcc, typename TBuf>
inline constexpr bool hasSameMemView()
{
return alpaka::meta::Contains<
typename alpaka::trait::MemVisibility<TBuf>::type,
typename alpaka::trait::MemVisibility<TAcc>::type>::value;
}
} // namespace alpaka
8 changes: 8 additions & 0 deletions include/alpaka/mem/buf/BufCpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "alpaka/core/Vectorize.hpp"
#include "alpaka/dev/DevCpu.hpp"
#include "alpaka/dev/Traits.hpp"
#include "alpaka/mem/Visibility.hpp"
#include "alpaka/mem/alloc/AllocCpuAligned.hpp"
#include "alpaka/mem/buf/Traits.hpp"
#include "alpaka/mem/view/ViewAccessOps.hpp"
Expand Down Expand Up @@ -307,6 +308,13 @@ namespace alpaka
{
using type = TIdx;
};

template<typename TElem, typename TDim, typename TIdx>
struct MemVisibility<BufCpu<TElem, TDim, TIdx>>
{
using type = std::tuple<alpaka::MemVisibleCPU>;
};

} // namespace trait
} // namespace alpaka

Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/mem/buf/BufCpuSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace alpaka
{
template<typename TElem, typename TDim, typename TIdx>
using BufCpuSycl = BufGenericSycl<TElem, TDim, TIdx, PlatformCpuSycl>;

template<typename TElem, typename TDim, typename TIdx>
struct MemVisibility<BufCpuSycl<TElem, TDim, TIdx>>
{
using type = std::tuple<alpaka::MemVisibleCPU>;
};
} // namespace alpaka

#endif
6 changes: 6 additions & 0 deletions include/alpaka/mem/buf/BufCudaRt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace alpaka
{
template<typename TElem, typename TDim, typename TIdx>
using BufCudaRt = BufUniformCudaHipRt<ApiCudaRt, TElem, TDim, TIdx>;

template<typename TElem, typename TDim, typename TIdx>
struct MemVisibility<BufCudaRt<TElem, TDim, TIdx>>
{
using type = std::tuple<alpaka::MemVisibleGpuCudaRt>;
};
} // namespace alpaka

#endif // ALPAKA_ACC_GPU_CUDA_ENABLED
6 changes: 6 additions & 0 deletions include/alpaka/mem/buf/BufFpgaSyclIntel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace alpaka
{
template<typename TElem, typename TDim, typename TIdx>
using BufFpgaSyclIntel = BufGenericSycl<TElem, TDim, TIdx, DevFpgaSyclIntel>;

template<typename TElem, typename TDim, typename TIdx>
struct MemVisibility<BufFpgaSyclIntel<TElem, TDim, TIdx>>
{
using type = std::tuple<alpaka::MemVisibleFpgaSyclIntel>;
};
} // namespace alpaka

#endif
6 changes: 6 additions & 0 deletions include/alpaka/mem/buf/BufGenericSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ namespace alpaka::trait
return getPtrNative(buf);
}
};

template<typename TElem, typename TDim, typename TIdx>
struct MemVisibility<BufGenericSycl<TElem, TDim, TIdx>>
{
using type = std::tuple<alpaka::MemVisibleGenericSycl>;
};
} // namespace alpaka::trait

# include "alpaka/mem/buf/sycl/Copy.hpp"
Expand Down
6 changes: 6 additions & 0 deletions include/alpaka/mem/buf/BufGpuSyclIntel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace alpaka
{
template<typename TElem, typename TDim, typename TIdx>
using BufGpuSyclIntel = BufGenericSycl<TElem, TDim, TIdx, PlatformGpuSyclIntel>;

template<typename TElem, typename TDim, typename TIdx>
struct MemVisibility<BufGpuSyclIntel<TElem, TDim, TIdx>>
{
using type = std::tuple<alpaka::MemVisibleGpuSyclIntel>;
};
} // namespace alpaka

#endif
6 changes: 6 additions & 0 deletions include/alpaka/mem/buf/BufHipRt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace alpaka
{
template<typename TElem, typename TDim, typename TIdx>
using BufHipRt = BufUniformCudaHipRt<ApiHipRt, TElem, TDim, TIdx>;

template<typename TElem, typename TDim, typename TIdx>
struct MemVisibility<BufUniformCudaHipRt<TElem, TDim, TIdx>>
{
using type = std::tuple<alpaka::MemVisibleGpuHipRt>;
};
} // namespace alpaka

#endif // ALPAKA_ACC_GPU_HIP_ENABLED

0 comments on commit 5fdcb22

Please sign in to comment.