aboutsummaryrefslogtreecommitdiff
path: root/include/armnn/backends/ICustomAllocator.hpp
blob: 59ad27c6f45ffa35a3463e273cedb601b499b330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

#include <cstddef>
#include <memory>
#include <armnn/MemorySources.hpp>
#include <armnn/utility/IgnoreUnused.hpp>

namespace armnn
{
/** Custom Allocator interface */
class ICustomAllocator
{
public:
    /** Default virtual destructor. */
    virtual ~ICustomAllocator() = default;

    /** Interface to be implemented by the child class to allocate bytes
     *
     * @param[in] size      Size to allocate
     * @param[in] alignment Alignment that the returned pointer should comply with
     *
     * @return A pointer to the allocated memory
     * The returned pointer must be host write accessible
     */
    virtual void* allocate(size_t size, size_t alignment) = 0;

    /** Interface to be implemented by the child class to free the allocated bytes */
    virtual void free(void* ptr) = 0;

    /**  Used to specify what type of memory is being allocated by this allocator.
     *  Supported types are:
     *       MemorySource::Malloc
     *       MemorySource::DmaBuf
     *       MemorySource::DmaBufProtected
     */
    virtual armnn::MemorySource GetMemorySourceType() = 0;

    /** Interface that may be implemented to allow retrieval of Memory Region
     *  from allocated buffer at a certain offset
     */
    virtual void* GetMemoryRegionAtOffset(void* buffer, size_t offset, size_t alignment = 0)
    {
        IgnoreUnused(offset);
        IgnoreUnused(alignment);
        IgnoreUnused(buffer);
        throw armnn::Exception(
                "ICustomerAllocator::GetMemoryRegionAtOffset(): This function should be overridden in subclass.");
    }

};
} // namespace armnn