From c43aa105ecbbb8778dbe00da0e4212e839809543 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Mon, 18 Nov 2024 18:36:00 -0500 Subject: [PATCH] Buffer: handle constness in connection with smart pointers Signed-off-by: Joseph Schuchart --- ttg/ttg/parsec/buffer.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/ttg/ttg/parsec/buffer.h b/ttg/ttg/parsec/buffer.h index 22b8c51de..46ba5d3a5 100644 --- a/ttg/ttg/parsec/buffer.h +++ b/ttg/ttg/parsec/buffer.h @@ -94,7 +94,7 @@ namespace detail { constexpr const bool is_empty_allocator = std::is_same_v>; assert(is_empty_allocator); m_ptr = std::move(ptr); - this->device_private = to_address(m_ptr); + this->device_private = const_cast(to_address(m_ptr)); } void construct(std::size_t size, @@ -132,7 +132,7 @@ namespace detail { const allocator_type& allocator = allocator_type()) { parsec_data_t *data = PARSEC_OBJ_NEW(parsec_data_t); data->owner_device = 0; - data->nb_elts = size; + data->nb_elts = size*sizeof(value_type); /* create the host copy and allocate host memory */ data_copy_type *copy = PARSEC_OBJ_NEW(data_copy_type); @@ -151,7 +151,7 @@ namespace detail { static parsec_data_t * create_data(PtrT& ptr, std::size_t size, ttg::scope scope) { parsec_data_t *data = PARSEC_OBJ_NEW(parsec_data_t); data->owner_device = 0; - data->nb_elts = size; + data->nb_elts = size*sizeof(value_type); /* create the host copy and allocate host memory */ data_copy_type *copy = PARSEC_OBJ_NEW(data_copy_type); @@ -195,7 +195,6 @@ struct Buffer { private: using delete_fn_t = std::function; - using host_data_ptr = std::add_pointer_t; parsec_data_t *m_data = nullptr; std::size_t m_count = 0; @@ -217,7 +216,7 @@ struct Buffer { { } Buffer(std::size_t n, ttg::scope scope = ttg::scope::SyncIn) - : m_data(detail::ttg_parsec_data_types::create_data(n*sizeof(element_type), scope)) + : m_data(detail::ttg_parsec_data_types::create_data(n, scope)) , m_count(n) { } @@ -226,20 +225,20 @@ struct Buffer { * The shared_ptr will ensure that the memory is not free'd before * the runtime has released all of its references. */ - Buffer(std::shared_ptr ptr, std::size_t n, + Buffer(std::shared_ptr ptr, std::size_t n, ttg::scope scope = ttg::scope::SyncIn) - : m_data(detail::ttg_parsec_data_types, - detail::empty_allocator> - ::create_data(ptr, n*sizeof(element_type), scope)) + : m_data(detail::ttg_parsec_data_types, + detail::empty_allocator> + ::create_data(ptr, n, scope)) , m_count(n) { } template - Buffer(std::unique_ptr ptr, std::size_t n, + Buffer(std::unique_ptr ptr, std::size_t n, ttg::scope scope = ttg::scope::SyncIn) - : m_data(detail::ttg_parsec_data_types, - detail::empty_allocator> - ::create_data(ptr, n*sizeof(element_type), scope)) + : m_data(detail::ttg_parsec_data_types, + detail::empty_allocator> + ::create_data(ptr, n, scope)) , m_count(n) { } @@ -405,7 +404,7 @@ struct Buffer { void reset(std::size_t n, ttg::scope scope = ttg::scope::SyncIn) { release_data(); - m_data = detail::ttg_parsec_data_types::create_data(n*sizeof(element_type), scope); + m_data = detail::ttg_parsec_data_types::create_data(n, scope); m_count = n; } @@ -496,4 +495,4 @@ namespace detail { } // namespace ttg_parsec -#endif // TTG_PARSEC_BUFFER_H \ No newline at end of file +#endif // TTG_PARSEC_BUFFER_H