Loading...
Searching...
No Matches
buffer.h
1
5#pragma once
6
7#include <memory>
8
9#include <ucxx/log.h>
10
11namespace ucxx {
17enum class BufferType {
18 Host = 0,
19 CCCL,
20 Invalid,
21};
22
31class Buffer {
32 protected:
33 BufferType _bufferType{BufferType::Invalid};
34 size_t _size;
35
45 Buffer(const BufferType bufferType, const size_t size);
46
47 public:
48 Buffer() = delete;
49 Buffer(const Buffer&) = delete;
50 Buffer& operator=(Buffer const&) = delete;
51 Buffer(Buffer&& o) = delete;
52 Buffer& operator=(Buffer&& o) = delete;
53
59 virtual ~Buffer();
60
69 [[nodiscard]] BufferType getType() const noexcept;
70
78 [[nodiscard]] size_t getSize() const noexcept;
79
89 [[nodiscard]] virtual void* data() = 0;
90};
91
97class HostBuffer : public Buffer {
98 private:
99 void* _buffer;
100
101 public:
102 HostBuffer() = delete;
103 HostBuffer(const HostBuffer&) = delete;
104 HostBuffer& operator=(HostBuffer const&) = delete;
105 HostBuffer(HostBuffer&& o) = delete;
106 HostBuffer& operator=(HostBuffer&& o) = delete;
107
121 explicit HostBuffer(const size_t size);
122
133 HostBuffer(const void* buffer, const size_t size);
134
142
168 [[nodiscard]] void* release();
169
189 [[nodiscard]] void* data() override;
190};
191
192#if UCXX_ENABLE_CCCL
197struct CCCLBufferImpl;
198
204class CCCLBuffer : public Buffer {
205 private:
206 std::unique_ptr<CCCLBufferImpl> _impl;
207
208 public:
209 CCCLBuffer() = delete;
210 CCCLBuffer(const CCCLBuffer&) = delete;
211 CCCLBuffer& operator=(CCCLBuffer const&) = delete;
212 CCCLBuffer(CCCLBuffer&& o) = delete;
213 CCCLBuffer& operator=(CCCLBuffer&& o) = delete;
214
215 ~CCCLBuffer() override;
216
231 explicit CCCLBuffer(const size_t size);
232
248 [[nodiscard]] void* data() override;
249};
250#endif
251
263[[nodiscard]] std::shared_ptr<Buffer> allocateBuffer(BufferType bufferType, const size_t size);
264
265} // namespace ucxx
A simple object to simplify managing buffers.
Definition buffer.h:31
Buffer(const BufferType bufferType, const size_t size)
Protected constructor of abstract type Buffer.
virtual ~Buffer()
Virtual destructor.
BufferType _bufferType
Buffer type.
Definition buffer.h:33
size_t getSize() const noexcept
Get the size of the contained buffer.
virtual void * data()=0
Abstract method returning void pointer to buffer.
BufferType getType() const noexcept
Get the type of buffer the object holds.
size_t _size
Buffer size.
Definition buffer.h:34
~HostBuffer()
Destructor of concrete type HostBuffer.
HostBuffer(const void *buffer, const size_t size)
Construct a host buffer by deep copying the contents of another buffer.
HostBuffer(const size_t size)
Constructor of concrete type HostBuffer.
void * release()
Release the allocated host buffer to the caller.
void * data() override
Get a pointer to the allocated raw host buffer.
Definition address.h:16
std::shared_ptr< Buffer > allocateBuffer(BufferType bufferType, const size_t size)
Allocate a buffer of specified type and size.
BufferType
The type of a buffer.
Definition buffer.h:17