Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
buffer.hpp
Go to the documentation of this file.
1// Copyright 2025 Eric Hermosis
2//
3// This file is part of the Tannic Tensor Library.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17
18#ifndef BUFFER_HPP
19#define BUFFER_HPP
20
38#include <cstddef>
39#include "resources.hpp"
40
41namespace tannic {
42
56class Buffer {
57public:
64
65 // Non-copyable to maintain clear ownership
66 Buffer(const Buffer&) = delete;
67 Buffer& operator=(const Buffer&) = delete;
68
73 Buffer(Buffer&& other) noexcept;
74
80 Buffer& operator=(Buffer&& other) noexcept;
81
86
91 void* address();
92
97 const void* address() const;
98
103 std::size_t nbytes() const;
104
109 Environment const& environment() const;
110
111private:
112 void* address_ = nullptr;
113 std::size_t nbytes_ = 0;
114 Environment environment_ = Host{};
115};
116
117} // namespace TANNIC
118
119#endif // BUFFER_HPP
Managed memory buffer with explicit ownership.
Definition: buffer.hpp:56
Buffer(Buffer &&other) noexcept
Move constructor transfers ownership.
~Buffer()
Destructor releases owned memory.
const void * address() const
Gets read-only pointer to memory
Buffer(const Buffer &)=delete
std::size_t nbytes() const
Gets buffer size in bytes.
Buffer & operator=(const Buffer &)=delete
Buffer(std::size_t nbytes, Environment environment=Host{})
Constructs a buffer with specified size and environment.
void * address()
Gets writable pointer to memory.
Buffer & operator=(Buffer &&other) noexcept
Move assignment transfers ownership.
Environment const & environment() const
Gets the environment used for this buffer.
Host memory domain.
Definition: resources.hpp:60
Definition: buffer.hpp:41
std::variant< Host, Device > Environment
Memory environment variant type.
Definition: resources.hpp:204