VART-X  0.3.0
vart_memory.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024-2026 Advanced Micro Devices Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
24 #include <cstdint>
25 #include <string>
26 #include "vart_device.hpp"
27 #include "vart_memory_types.hpp"
28 
31 namespace vart {
32 
36 class MemoryImplBase;
37 
43 class Memory {
44  public:
61  Memory(MemoryImplType type, size_t size, uint8_t mbank_idx, std::shared_ptr<Device> device);
62 
81  Memory(MemoryImplType type, uint8_t* data, size_t size, std::shared_ptr<Device> device);
82 
91  Memory(std::shared_ptr<MemoryImplBase> ptr);
92 
115  Memory(MemoryImplType type, int dma_fd, size_t size, std::shared_ptr<Device> device);
116 
117  ~Memory() = default;
118 
131  const uint8_t* map(DataMapFlags map_flags);
132 
139  void unmap();
140 
147  const std::shared_ptr<MemoryImplBase>& get_pimpl_handle() const;
148 
156  std::shared_ptr<Device> get_device_handle() const;
157 
164  size_t get_size();
165 
177  uint64_t get_physical_addr();
178 
186  int export_buffer() const;
187 
188  private:
189  std::shared_ptr<MemoryImplBase> pimpl;
190 };
191 } // namespace vart
This module is responsible for allocating and managing memory on the device.
Definition: vart_memory.hpp:43
Memory(MemoryImplType type, uint8_t *data, size_t size, std::shared_ptr< Device > device)
Memory() - Constructor to create Memory instance using user provided data pointer.
const uint8_t * map(DataMapFlags map_flags)
map() - Maps allocated memory to user space.
const std::shared_ptr< MemoryImplBase > & get_pimpl_handle() const
get_pimpl_handle() - Retrieves pointer to Memory Implementation Base class
void unmap()
unmap() - Unmaps allocated memory from user space.
uint64_t get_physical_addr()
get_physical_addr() - Retrieves the physical address of the allocated memory.
Memory(std::shared_ptr< MemoryImplBase > ptr)
Memory() - Constructor for using user defined implementation.
std::shared_ptr< Device > get_device_handle() const
get_device_handle() - Retrieves the device handle associated with memory allocation
~Memory()=default
size_t get_size()
get_size() - gets the size of the allocated memory
Memory(MemoryImplType type, int dma_fd, size_t size, std::shared_ptr< Device > device)
Memory() - Constructor to create Memory instance from a dma-buf file descriptor.
int export_buffer() const
export_buffer() - Export the underlying buffer as a dma-buf file descriptor
Memory(MemoryImplType type, size_t size, uint8_t mbank_idx, std::shared_ptr< Device > device)
Memory() - Constructor to allocate memory using implementation specific method based on input 'type'.
VART (Vitis AI Runtime) public API namespace.
MemoryImplType
Definition: vart_memory_types.hpp:39
DataMapFlags
Definition: vart_memory_types.hpp:30
Device module managing hardware context and xclbin loading.