forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQnnExecuTorch.h
More file actions
81 lines (70 loc) · 2.35 KB
/
QnnExecuTorch.h
File metadata and controls
81 lines (70 loc) · 2.35 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) Qualcomm Innovation Center, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
#ifdef __cplusplus
#include <cstddef>
#include <cstdint>
#else
#include <stddef.h>
#include <stdint.h>
#endif
#define QNN_BACKEND "QnnBackend"
#define QNN_RUNTIME_LOG_LEVEL "qnn_runtime_log_level"
#define QNN_RUNTIME_HTP_PERFORMANCE_MODE "qnn_runtime_htp_performance_mode"
#define QNN_RUNTIME_PROFILE_LEVEL "qnn_runtime_profile_level"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
// This could be:
// 1. qnn_context_binary
// 2. QnnContextCustomProtocol
// To check if it is custom protocol, users can deserialize the binary using
// QnnCustomProtocol and check the status
typedef struct {
/// qnn_context_binary_blob
void* buffer;
/// number of bytes of buffer
uint64_t nbytes;
} QnnExecuTorchContextBinary;
// clang-format off
#define QNN_EXECUTORCH_CONTEXT_BINARY \
{ \
nullptr, /*buffer*/ \
0, /*nbytes*/ \
}
// clang-format on
/// Allocate memory in different way, check qnn document for more details.
enum QnnMemDescriptor { kIon, kCustom };
struct CustomMemTensorInfo {
void* custom_mem;
void* tensor_addr;
size_t pos;
size_t tensor_bytes;
uint32_t* shape;
uint32_t rank;
executorch::aten::ScalarType dtype;
};
/// Allocate specific tensors (usually graph inputs and outputs) on shared
/// memory. Users are responsible to allocate "enough" tensor bytes, and set
/// alignment as MemoryAllocator::kDefaultAlignment.
/// See runtime/core/memory_allocator.h. The function returns a valid pointer
/// if allocation is successful.
__attribute__((__visibility__("default"))) void* QnnExecuTorchAllocCustomMem(
size_t bytes,
size_t alignment);
/// Add tensor to custom memory with custom type descriptor. Create memory
/// handle to tensor wrapper during execution
__attribute__((__visibility__("default"))) void
QnnExecuTorchAddCustomMemTensorAddr(void* tensor_addr, void* custom_mem);
/// Free the allocated shared memory.
__attribute__((__visibility__("default"))) void QnnExecuTorchFreeCustomMem(
void* buffer_ptr);
#ifdef __cplusplus
}
#endif // __cplusplus