Skip to content

Commit

Permalink
Buffer: handle constness in connection with smart pointers
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Schuchart <[email protected]>
  • Loading branch information
devreal committed Nov 18, 2024
1 parent d96b584 commit c43aa10
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions ttg/ttg/parsec/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace detail {
constexpr const bool is_empty_allocator = std::is_same_v<Allocator, empty_allocator<value_type>>;
assert(is_empty_allocator);
m_ptr = std::move(ptr);
this->device_private = to_address(m_ptr);
this->device_private = const_cast<value_type*>(to_address(m_ptr));
}

void construct(std::size_t size,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -195,7 +195,6 @@ struct Buffer {
private:
using delete_fn_t = std::function<void(element_type*)>;

using host_data_ptr = std::add_pointer_t<element_type>;
parsec_data_t *m_data = nullptr;
std::size_t m_count = 0;

Expand All @@ -217,7 +216,7 @@ struct Buffer {
{ }

Buffer(std::size_t n, ttg::scope scope = ttg::scope::SyncIn)
: m_data(detail::ttg_parsec_data_types<T*, Allocator>::create_data(n*sizeof(element_type), scope))
: m_data(detail::ttg_parsec_data_types<T*, Allocator>::create_data(n, scope))
, m_count(n)
{ }

Expand All @@ -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<element_type[]> ptr, std::size_t n,
Buffer(std::shared_ptr<value_type[]> ptr, std::size_t n,
ttg::scope scope = ttg::scope::SyncIn)
: m_data(detail::ttg_parsec_data_types<std::shared_ptr<element_type[]>,
detail::empty_allocator<element_type>>
::create_data(ptr, n*sizeof(element_type), scope))
: m_data(detail::ttg_parsec_data_types<std::shared_ptr<value_type[]>,
detail::empty_allocator<value_type>>
::create_data(ptr, n, scope))
, m_count(n)
{ }

template<typename Deleter>
Buffer(std::unique_ptr<element_type[], Deleter> ptr, std::size_t n,
Buffer(std::unique_ptr<value_type[], Deleter> ptr, std::size_t n,
ttg::scope scope = ttg::scope::SyncIn)
: m_data(detail::ttg_parsec_data_types<std::unique_ptr<element_type[], Deleter>,
detail::empty_allocator<element_type>>
::create_data(ptr, n*sizeof(element_type), scope))
: m_data(detail::ttg_parsec_data_types<std::unique_ptr<value_type[], Deleter>,
detail::empty_allocator<value_type>>
::create_data(ptr, n, scope))
, m_count(n)
{ }

Expand Down Expand Up @@ -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<T*, Allocator>::create_data(n*sizeof(element_type), scope);
m_data = detail::ttg_parsec_data_types<T*, Allocator>::create_data(n, scope);
m_count = n;
}

Expand Down Expand Up @@ -496,4 +495,4 @@ namespace detail {

} // namespace ttg_parsec

#endif // TTG_PARSEC_BUFFER_H
#endif // TTG_PARSEC_BUFFER_H

0 comments on commit c43aa10

Please sign in to comment.