CYNQ  0.3.0
Framework to develop FPGA applications in C++ with the easiness of PYNQ
memory.hpp
1 /*
2  * See LICENSE for more information about licensing
3  *
4  * Copyright 2023
5  * Author: Luis G. Leon-Vega <luis.leon@ieee.org>
6  * Diego Arturo Avila Torres <diego.avila@uned.cr>
7  *
8  */
9 #pragma once
10 #include <cynq/enums.hpp>
11 #include <cynq/execution-graph.hpp>
12 #include <cynq/status.hpp>
13 #include <memory>
14 
15 namespace cynq {
21 class IMemory {
22  public:
28  virtual ~IMemory() = default;
35  enum Type {
37  None = 0,
39  XRT
40  };
50  virtual Status Sync(const SyncType type) = 0;
63  virtual Status Sync(std::shared_ptr<IExecutionGraph> graph,
64  const SyncType type);
71  virtual size_t Size() = 0;
82  template <typename T>
83  std::shared_ptr<T> HostAddress() {
84  return std::reinterpret_pointer_cast<T>(this->GetHostAddress());
85  }
96  template <typename T>
97  std::shared_ptr<T> DeviceAddress() {
98  return std::reinterpret_pointer_cast<T>(this->GetDeviceAddress());
99  }
100 
132  static std::shared_ptr<IMemory> Create(IMemory::Type impl,
133  const std::size_t size,
134  uint8_t* hostptr, uint8_t* devptr,
135  void* moverptr);
136 
137  protected:
145  virtual std::shared_ptr<uint8_t> GetHostAddress() = 0;
153  virtual std::shared_ptr<uint8_t> GetDeviceAddress() = 0;
154 };
155 } // namespace cynq
Interface for standardising the API of Memory devices: XRTMemory.
Definition: memory.hpp:21
virtual std::shared_ptr< uint8_t > GetDeviceAddress()=0
GetDeviceAddress method Get the Address that belongs to the device. [Reference] shared memory pointer...
virtual ~IMemory()=default
~IMemory destructor method Destroy the IMemory object.
virtual Status Sync(const SyncType type)=0
Sync method Synchronizes the memory in terms of transactions.
std::shared_ptr< T > DeviceAddress()
DeviceAddress method Getter for the address of the device.
Definition: memory.hpp:97
static std::shared_ptr< IMemory > Create(IMemory::Type impl, const std::size_t size, uint8_t *hostptr, uint8_t *devptr, void *moverptr)
Create method Factory method to create specific subclasses of IMemory.
Definition: memory.cpp:14
virtual std::shared_ptr< uint8_t > GetHostAddress()=0
GetHostAddress method Get the Address that belongs to the host. [Reference] shared memory pointer wit...
virtual size_t Size()=0
Size method Gives the value for the memory size in bytes.
Type
Type Type of runtime supported by the IMemory.
Definition: memory.hpp:35
@ XRT
Definition: memory.hpp:39
@ None
Definition: memory.hpp:37
std::shared_ptr< T > HostAddress()
HostAddress method Getter for the address of the host.
Definition: memory.hpp:83
Structure to define the return characteristics of each function.
Definition: status.hpp:19