Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ target_sources(emucore
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/detail/dlpack_types.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/expected.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/functor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/fwd.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/hash.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/host/location_policy.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/host/mdcontainer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/host/mdspan.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/host/container.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/host/span.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/info.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/location_policy.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/macro.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/managed_object.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/math.hpp
Expand All @@ -81,7 +78,6 @@ target_sources(emucore
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/scoped.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/container.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/span.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/mdalgo.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/mdspan.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/assert.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/core/emu/capsule.hpp
Expand Down Expand Up @@ -158,7 +154,6 @@ if (emu_build_cuda)
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/device/mdspan.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/device/container.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/device/span.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/device/location_policy.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/allocator.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/device.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/error.hpp
Expand All @@ -167,7 +162,6 @@ if (emu_build_cuda)
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/pointer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/stream.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/managed/container.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/managed/location_policy.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/managed/mdcontainer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/managed/mdspan.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cuda/emu/cuda/managed/span.hpp
Expand Down Expand Up @@ -234,7 +228,7 @@ target_sources(emupython INTERFACE FILE_SET HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/cuda/stream.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/detail/capsule.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/detail/layout_adaptor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/detail/location_adaptor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/detail/accessor_adaptor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/detail/mdspan_caster.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/mdcontainer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/python/emu/pybind11/cast/mdspan.hpp
Expand Down
32 changes: 13 additions & 19 deletions include/core/emu/capsule.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "type_traits.hpp"
#include <emu/fwd.hpp>
#include <emu/config.hpp>
#include <emu/concepts.hpp>
#include <emu/utility.hpp>
Expand All @@ -15,6 +13,19 @@
namespace emu
{

struct capsule;

namespace cpts
{

template <typename T>
concept capsule_owner = requires (const T& t) {
{ t.capsule() } -> std::convertible_to<capsule>;
};

} // namespace cpts


template<typename T>
struct copy
{
Expand Down Expand Up @@ -276,23 +287,6 @@ namespace emu
return {};
}

namespace spe
{

/// std::array are not relocatable regardless if it is a reference or not.
template <typename T, size_t N>
inline constexpr bool enable_relocatable_owning_range< std::array<T, N> > = false;

/// C arrays are not relocatable regardless if it is a reference or not.
///TODO: check if it is useful to have this.
template <typename T>
inline constexpr bool enable_relocatable_owning_range<T[]> = false;
/// C arrays are not relocatable regardless if it is a reference or not.
template <typename T, size_t N>
inline constexpr bool enable_relocatable_owning_range<T[N]> = false;

} // namespace spe

} // namespace emu

template<>
Expand Down
182 changes: 49 additions & 133 deletions include/core/emu/concepts.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#pragma once

#include <emu/fwd.hpp>
#include <emu/type_traits.hpp>

#include <fmt/core.h>

#include <concepts>
#include <ranges>
#include <type_traits>
#include <span>
#include <array>
#include <ranges>

namespace emu
Expand Down Expand Up @@ -69,25 +68,12 @@ namespace cpts
// # utility type concepts #
// #########################

template <typename T>
concept expected = specialization_of<T, tl::expected>;

template <typename T>
concept optional = specialization_of<T, tl::optional>
or specialization_of<T, std::optional>;

template <typename T>
concept opt_like = expected<T> or optional<T>;

// ############
// # std view #
// ############

template <typename T>
concept std_span = same_as<T, std::span<typename T::element_type, T::extent>>;

template <typename T>
concept std_mdspan = specialization_of<T, std::experimental::mdspan>;

// ############
// # emu view #
Expand All @@ -96,96 +82,44 @@ namespace cpts
//TODO: using derived_from allow container to be considered to be a span.
// Which is true, but may not be what we want.

template <typename T>
concept emu_span = std::derived_from<T, detail::basic_span<
typename T::element_type, T::extent,
typename T::location_type, typename T::actual_type>>;

template <typename T>
concept emu_mdspan = std::derived_from<T, detail::basic_mdspan<
typename T::element_type, typename T::extents_type,
typename T::layout_type, typename T::accessor_type,
typename T::location_type, typename T::actual_type>>;

// #################
// # span concepts #
// #################

// cannot use is_specialization here because second span argument is not a type.
template <typename T>
concept span = std_span<T>
or emu_span<T>;

template <typename T>
concept const_span = span<T> and is_const<typename T::element_type>;

template <typename T>
concept mutable_span = span<T> and (not is_const<typename T::element_type>);

// ######################
// # container concepts #
// ######################

template <typename T>
concept container = std::derived_from<T, detail::basic_container<typename T::element_type, T::extent, typename T::location_type, typename T::actual_type>>;

template <typename T>
concept const_container = container<T> and std::is_const_v<typename T::element_type>;

template <typename T>
concept mutable_container = container<T> and (not std::is_const_v<typename T::element_type>);

// ###################
// # mdspan concepts #
// ###################

template <typename T>
concept mdspan = std_mdspan<T>
or emu_mdspan<T>;

template <typename T>
concept const_mdspan = mdspan<T> and std::is_const_v<typename T::element_type>;

template <typename T>
concept mutable_mdspan = mdspan<T> and (not std::is_const_v<typename T::element_type>);

// ########################
// # mdcontainer concepts #
// ########################

template <typename T>
concept mdcontainer = std::derived_from<T, detail::basic_mdcontainer<
typename T::element_type, typename T::extents_type,
typename T::layout_type, typename T::accessor_type,
typename T::location_type, typename T::actual_type>>;

template <typename T>
concept const_mdcontainer = mdspan<T> and std::is_const_v<typename T::element_type>;

template <typename T>
concept mutable_mdcontainer = mdspan<T> and (not std::is_const_v<typename T::element_type>);

// #################
// # view concepts #
// #################

template <typename T>
concept view = span<T> or mdspan<T>;
// template <typename T>
// concept view = span<T> or mdspan<T>;

template <typename T>
concept const_view = const_span<T> or const_mdspan<T>;
// template <typename T>
// concept const_view = const_span<T> or const_mdspan<T>;

template <typename T>
concept mutable_view = mutable_span<T> or mutable_mdspan<T>;
// template <typename T>
// concept mutable_view = mutable_span<T> or mutable_mdspan<T>;

// ####################
// # capsule concetps #
// ####################

template <typename T>
concept capsule_owner = requires (const T& t) {
{ t.capsule() } -> std::convertible_to<capsule>;
};

// ###################
// # layout concepts #
Expand All @@ -195,25 +129,7 @@ namespace cpts
concept contiguous_sized_range = std::ranges::contiguous_range<T>
and std::ranges::sized_range<T>;

template <typename T>
concept extents = is_extents<T>;

template <typename T>
concept mapping = requires (const T& m) {
// TODO: complete the list...
{ m.required_span_size() } -> std::convertible_to<std::size_t>;

{ m.is_always_unique() } -> std::convertible_to<bool>;
{ m.is_always_exhaustive() } -> std::convertible_to<bool>;
{ m.is_always_strided() } -> std::convertible_to<bool>;
{ m.is_unique() } -> std::convertible_to<bool>;
{ m.is_exhaustive() } -> std::convertible_to<bool>;
{ m.is_strided() } -> std::convertible_to<bool>;
};

template <typename T>
// the only thing that determine a layout is the inner mapping type.
concept layout = mapping< typename T::template mapping<std::experimental::extents<std::size_t>> >;

namespace detail
{
Expand Down Expand Up @@ -251,7 +167,7 @@ namespace detail
bool(spe::enable_relocatable_owning_range<rm_cvref<T>>),
// otherwise, the type is relocatable if it's not a view nor a lvalue reference
bool((not std::ranges::view<rm_ref<T>>)
and (not is_lref<T>) )>;
and (not is_lref<T>) )>;

template <typename T>
concept formattable = requires (const T& v, fmt::format_context ctx) {
Expand All @@ -270,65 +186,65 @@ namespace detail
} // namespace cpts


namespace host::cpts
{
// namespace host::cpts
// {

template <typename T>
concept span = std::derived_from<T, host::span<
typename T::element_type, T::extent>>;
// template <typename T>
// concept span = std::derived_from<T, host::span<
// typename T::element_type, T::extent>>;

template <typename T>
concept container = std::derived_from<T, host::container<
typename T::element_type, T::extent>>;
// template <typename T>
// concept container = std::derived_from<T, host::container<
// typename T::element_type, T::extent>>;

template <typename T>
concept mdspan = emu::cpts::specialization_of<T, host::mdspan>;
// template <typename T>
// concept mdspan = emu::cpts::specialization_of<T, host::mdspan>;

template <typename T>
concept mdcontainer = emu::cpts::specialization_of<T, host::mdcontainer>;
// template <typename T>
// concept mdcontainer = emu::cpts::specialization_of<T, host::mdcontainer>;

} // namespace host::cpts
// } // namespace host::cpts

namespace cuda::device::cpts
{
// namespace cuda::device::cpts
// {

template <typename T>
concept span = std::derived_from<T, cuda::device::span<
typename T::element_type, T::extent>>;
// template <typename T>
// concept span = std::derived_from<T, cuda::device::span<
// typename T::element_type, T::extent>>;

template <typename T>
concept container = std::derived_from<T, cuda::device::container<
typename T::element_type, T::extent>>;
// template <typename T>
// concept container = std::derived_from<T, cuda::device::container<
// typename T::element_type, T::extent>>;

template <typename T>
concept mdspan = emu::cpts::specialization_of<T, cuda::device::mdspan>;
// template <typename T>
// concept mdspan = emu::cpts::specialization_of<T, cuda::device::mdspan>;

template <typename T>
concept mdcontainer = emu::cpts::specialization_of<T, cuda::device::mdcontainer>;
// template <typename T>
// concept mdcontainer = emu::cpts::specialization_of<T, cuda::device::mdcontainer>;

} // namespace cuda::device::cpts
// } // namespace cuda::device::cpts

namespace cpts
{
// namespace cpts
// {

template<typename T>
concept any_span = span<T> or host::cpts::span<T> or cuda::device::cpts::span<T>;
// template<typename T>
// concept any_span = span<T> or host::cpts::span<T> or cuda::device::cpts::span<T>;

template<typename T>
concept any_container = container<T> or host::cpts::container<T> or cuda::device::cpts::container<T>;
// template<typename T>
// concept any_container = container<T> or host::cpts::container<T> or cuda::device::cpts::container<T>;

template<typename T>
concept any_mdspan = mdspan<T> or host::cpts::mdspan<T> or cuda::device::cpts::mdspan<T>;
// template<typename T>
// concept any_mdspan = mdspan<T> or host::cpts::mdspan<T> or cuda::device::cpts::mdspan<T>;

template<typename T>
concept any_mdcontainer = mdcontainer<T> or host::cpts::mdcontainer<T> or cuda::device::cpts::mdcontainer<T>;
// template<typename T>
// concept any_mdcontainer = mdcontainer<T> or host::cpts::mdcontainer<T> or cuda::device::cpts::mdcontainer<T>;

template<typename T>
concept any_view = any_span<T> or any_mdspan<T>;
// template<typename T>
// concept any_view = any_span<T> or any_mdspan<T>;

template<typename T>
concept any_owning = any_container<T> or any_mdcontainer<T>;
// template<typename T>
// concept any_owning = any_container<T> or any_mdcontainer<T>;

} // namespace cpts
// } // namespace cpts

} // namespace emu
Loading