NVIDIA / NVIDIA/cccl

[FEA]: `cuda::empty_like(buffer)`

Open
#10,214 3 comments 0 reactions 1 assignee Claimed by @pciolkosz View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

It is common to want to create an identical `cuda::buffer` that shares the same properties, stream, and memory resource as another without copying any of the elements. This is analogous to [`numpy.empty_like()`](https://numpy.org/devdocs/reference/generated/numpy.empty_like.html).

As with `numpy`, specifying the size of the new buffer is also desirable.

It would be nice to have a function which does this:
```c++
namespace cuda {

// Either a member function
class buffer {
public:

buffer empty_like(size_t size) const
{
return buffer{
this->stream(), this->memory_resource(), size, cuda::no_init,
execution::prop{allocation_alignment, this->alignment()}
};
}

buffer empty_like() const { return empty_like(this->size()); }
};

// or free function
buffer make_empty_like(const buffer& src, size_t size)
{
return buffer{...};
}

buffer make_empty_like(const buffer& src)
{
return make_empty_like(src, src.size());
}

} //

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.