Skip to content

Commit

Permalink
Move around type traits for buffer, scratch, and ptr
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Schuchart <[email protected]>
  • Loading branch information
devreal committed Oct 29, 2024
1 parent 587d8fd commit 44b0a48
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
20 changes: 20 additions & 0 deletions ttg/ttg/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@
#include <memory>

#include "ttg/fwd.h"
#include "ttg/util/meta.h"

namespace ttg {

template<typename T, typename Allocator = std::allocator<std::decay_t<T>>>
using Buffer = TTG_IMPL_NS::Buffer<T, Allocator>;

namespace meta {

/* Specialize some traits */

template<typename T, typename A>
struct is_buffer<ttg::Buffer<T, A>> : std::true_type
{ };

template<typename T, typename A>
struct is_buffer<const ttg::Buffer<T, A>> : std::true_type
{ };

/* buffers are const if their value types are const */
template<typename T, typename A>
struct is_const<ttg::Buffer<T, A>> : std::is_const<T>
{ };

} // namespace meta

} // namespace ttg

#endif // TTG_buffer_H
5 changes: 3 additions & 2 deletions ttg/ttg/device/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ namespace ttg::device {
/* extract buffer information from to_device_t */
template<typename... Ts, std::size_t... Is>
auto extract_buffer_data(detail::to_device_t<Ts...>& a, std::index_sequence<Is...>) {
using arg_types = std::tuple<Ts...>;
return std::array{
device_input_data_t{TTG_IMPL_NS::buffer_data(std::get<Is>(a.ties)),
std::get<Is>(a.ties).scope(),
std::is_const_v<std::tuple_element<Is, decltype(a.ties)>>,
ttg::meta::is_devicescratch_v<std::tuple_element<Is, decltype(a.ties)>>}...};
ttg::meta::is_const_v<std::tuple_element<Is, arg_types>>,
ttg::meta::is_devicescratch_v<std::tuple_element<Is, arg_types>>}...};
}
} // namespace detail

Expand Down
19 changes: 19 additions & 0 deletions ttg/ttg/devicescratch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "ttg/devicescope.h"
#include "ttg/fwd.h"
#include "ttg/util/meta.h"

namespace ttg {

Expand All @@ -14,6 +15,24 @@ auto make_scratch(T* val, ttg::scope scope, std::size_t count = 1) {
return devicescratch<T>(val, scope, count);
}

namespace meta {

/* Specialize some traits */

template<typename T>
struct is_devicescratch<ttg::devicescratch<T>> : std::true_type
{ };

template<typename T>
struct is_devicescratch<const ttg::devicescratch<T>> : std::true_type
{ };

template<typename T>
struct is_const<ttg::devicescratch<T>> : std::is_const<T>
{ };

} // namespace meta

} // namespace ttg

#endif // TTG_DEVICESCRATCH_H
3 changes: 1 addition & 2 deletions ttg/ttg/parsec/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ttg/util/iovec.h"
#include "ttg/device/device.h"
#include "ttg/parsec/device.h"
#include "ttg/devicescope.h"

#if defined(PARSEC_HAVE_DEV_CUDA_SUPPORT)
#include <cuda_runtime.h>
Expand Down Expand Up @@ -457,8 +458,6 @@ struct Buffer : public detail::ttg_parsec_data_wrapper_t
}
}
#endif // TTG_SERIALIZATION_SUPPORTS_MADNESS


};

namespace detail {
Expand Down
12 changes: 12 additions & 0 deletions ttg/ttg/ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "ttg/fwd.h"

#include "ttg/util/meta.h"

namespace ttg {

template<typename T>
Expand All @@ -18,6 +20,16 @@ inline Ptr<std::decay_t<T>> get_ptr(T&& obj) {
return TTG_IMPL_NS::get_ptr(std::forward<T>(obj));
}

namespace meta {

/* specialize some traits */

template<typename T>
struct is_ptr<ttg::Ptr<T>> : std::true_type
{ };

} // namespace ptr

#if 0
namespace detail {

Expand Down
24 changes: 4 additions & 20 deletions ttg/ttg/util/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

#include "ttg/util/span.h"
#include "ttg/util/typelist.h"
#include "ttg/buffer.h"
#include "ttg/ptr.h"
#include "ttg/devicescratch.h"

namespace ttg {

Expand Down Expand Up @@ -302,25 +299,14 @@ namespace ttg {
struct is_ptr : std::false_type
{ };

template<typename T>
struct is_ptr<ttg::Ptr<T>> : std::true_type
{ };

template<typename T>
constexpr bool is_ptr_v = is_ptr<T>::value;

/* specialized by the implementation */
template<typename T>
struct is_buffer : std::false_type
{ };

template<typename T, typename A>
struct is_buffer<ttg::Buffer<T, A>> : std::true_type
{ };

template<typename T, typename A>
struct is_buffer<const ttg::Buffer<T, A>> : std::true_type
{ };

template<typename T>
constexpr bool is_buffer_v = is_buffer<T>::value;

Expand All @@ -329,16 +315,14 @@ namespace ttg {
{ };

template<typename T>
struct is_devicescratch<ttg::devicescratch<T>> : std::true_type
{ };
constexpr bool is_devicescratch_v = is_devicescratch<T>::value;

template<typename T>
struct is_devicescratch<const ttg::devicescratch<T>> : std::true_type
struct is_const : std::is_const<T>
{ };

template<typename T>
constexpr bool is_devicescratch_v = is_devicescratch<T>::value;

constexpr bool is_const_v = is_const<T>::value;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// typelist metafunctions
Expand Down

0 comments on commit 44b0a48

Please sign in to comment.