ONE - On-device Neural Engine
Loading...
Searching...
No Matches
MappedMemory Class Referencefinal

#include <Memory.h>

Collaboration diagram for MappedMemory:

Public Member Functions

 MappedMemory ()=default
 
 ~MappedMemory ()
 
int set (size_t size, int prot, int fd, size_t offset)
 
int getPointer (uint8_t **buffer) const override
 
bool validateSize (uint32_t offset, uint32_t length) const override
 
- Public Member Functions inherited from Memory
 Memory ()=default
 
virtual ~Memory ()=default
 
 Memory (const Memory &)=delete
 
Memoryoperator= (const Memory &)=delete
 

Detailed Description

Definition at line 41 of file Memory.h.

Constructor & Destructor Documentation

◆ MappedMemory()

MappedMemory::MappedMemory ( )
default

◆ ~MappedMemory()

MappedMemory::~MappedMemory ( )

Definition at line 25 of file Memory.cpp.

26{
27 if (_base)
28 {
29 munmap(_base, _size);
30 }
31}

Member Function Documentation

◆ getPointer()

int MappedMemory::getPointer ( uint8_t **  buffer) const
overridevirtual

Implements Memory.

Definition at line 66 of file Memory.cpp.

67{
68 *buffer = _base;
70}
@ ANEURALNETWORKS_NO_ERROR

References ANEURALNETWORKS_NO_ERROR.

◆ set()

int MappedMemory::set ( size_t  size,
int  prot,
int  fd,
size_t  offset 
)

Definition at line 33 of file Memory.cpp.

34{
35#if 0
36 if (fd < 0)
37 {
38 LOG(ERROR) << "ANeuralNetworksMemory_createFromFd invalid fd " << fd;
40 }
41 if (size == 0 || fd < 0)
42 {
43 LOG(ERROR) << "Invalid size or fd";
45 }
46 int dupfd = dup(fd);
47 if (dupfd == -1)
48 {
49 LOG(ERROR) << "Failed to dup the fd";
51 }
52#endif
53 void * const base = mmap(nullptr, size, prot, MAP_PRIVATE, fd, offset);
54
55 if (base == MAP_FAILED)
56 {
58 }
59
60 _base = static_cast<uint8_t *>(base);
61 _size = size;
62
64}
#define LOG(...)
Definition Logging.h:36
@ ANEURALNETWORKS_UNEXPECTED_NULL
@ ANEURALNETWORKS_BAD_DATA
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
int32_t size[5]
Definition Slice.cpp:35

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_NO_ERROR, ANEURALNETWORKS_UNEXPECTED_NULL, LOG, offset(), and size.

◆ validateSize()

bool MappedMemory::validateSize ( uint32_t  offset,
uint32_t  length 
) const
overridevirtual

Implements Memory.

Definition at line 72 of file Memory.cpp.

73{
74 return true;
75}

The documentation for this class was generated from the following files: