25 #ifndef TVM_RUNTIME_HEXAGON_OPS_CONV2D_H_ 26 #define TVM_RUNTIME_HEXAGON_OPS_CONV2D_H_ 31 static constexpr
auto hexagon_device = DLDevice{
static_cast<DLDeviceType
>(
kDLHexagon), 0};
35 template <
size_t NDIM>
38 SDLTensor(
void* data_ptr, DLDataType data_type,
void* data_space,
const int64_t* data_dims)
39 :
SDLTensor(data_ptr, data_type, data_space) {
40 for (
size_t i = 0; i < NDIM; ++i) dims[i] = data_dims[i];
43 SDLTensor(
void* data_ptr, DLDataType data_type,
void* data_space,
44 std::initializer_list<int64_t> data_dims)
45 :
SDLTensor(data_ptr, data_type, data_space, data_dims.begin()) {}
60 SDLTensor(
void* data_ptr, DLDataType data_type,
void* data_space) : data_space(data_space) {
62 device = hexagon_device;
70 void* data_space =
nullptr;
74 inline void*
to_ptr(uintptr_t v) {
return reinterpret_cast<void*
>(v); }
76 inline uintptr_t
to_uint(
void* ptr) {
return reinterpret_cast<uintptr_t
>(ptr); }
82 assert(y >= 0 && x >= 0 && c >= 0);
83 return y << 7 | (x & 2) << 5 | c << 1 | (x & 1);
92 assert(y >= 0 && x >= 0 && i >= 0 && o >= 0);
93 int p = y * width + (width - 1 - x);
94 return p << 10 | (i & 0x1e) << 5 | o << 1 | (i & 1);
97 inline constexpr
int round_up(
int v,
int p2) {
return (v + p2 - 1) & -p2; }
103 inline uintptr_t
nhwc_at(
const DLTensor& a,
int n,
int y,
int x,
int c) {
104 if (y < 0 || y >= a.shape[1])
return uintptr_t(0);
105 auto p =
static_cast<uintptr_t*
>(a.data);
107 return p[y * a.shape[2] * a.shape[3] + x * a.shape[3] + c];
113 inline uintptr_t
hwio_at(
const DLTensor& f,
int y,
int x,
int i,
int o) {
114 auto p =
static_cast<uintptr_t*
>(f.data);
115 return p[y * f.shape[1] * f.shape[2] * f.shape[3] + x * f.shape[2] * f.shape[3] + i * f.shape[3] +
136 void blockize_hwc_16b(
void* out,
void* inp_flat,
int height,
int width,
int depth);
176 void chunkify_hwio_16b(
void** out_ptr,
int out_ptr_size,
void* out,
void* inp,
int height,
177 int width,
int idepth,
int odepth);
185 int num_chunks,
void** ptr_table);
198 #endif // TVM_RUNTIME_HEXAGON_OPS_CONV2D_H_ void * GetDataSpace() const
Definition: conv2d.h:47
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
TVM Runtime Device API, abstracts the device specific interface for memory management.
Definition: device_api.h:71
void chunkify_hwio_16b(void **out_ptr, int out_ptr_size, void *out, void *inp, int height, int width, int idepth, int odepth)
Convert the layout of weights from flat to "chunked". The term chunked is explained below: ...
virtual void FreeDataSpace(Device dev, void *ptr)=0
Free a data space on device.
void release(tvm::runtime::DeviceAPI *device_api, const SDLTensor< N > &tensor)
Definition: conv2d.h:188
SDLTensor< 4 > prepare_hwio(tvm::runtime::DeviceAPI *device_api, const DLTensor *hwio_flat, int num_chunks, void **ptr_table)
constexpr int xyc_to_sm_16b(int y, int x, int c)
Definition: conv2d.h:78
void * to_ptr(uintptr_t v)
Definition: conv2d.h:74
SDLTensor(void *data_ptr, DLDataType data_type, void *data_space, const int64_t *data_dims)
Definition: conv2d.h:38
Definition: c_runtime_api.h:89
uintptr_t hwio_at(const DLTensor &f, int y, int x, int i, int o)
Definition: conv2d.h:113
void blockize_hwc_16b(void *out, void *inp_flat, int height, int width, int depth)
Function to "blockize" the flat input data The term "blockize" is used to mention that the data is st...
uintptr_t to_uint(void *ptr)
Definition: conv2d.h:76
Abstract device memory management API.
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1758
SDLTensor(void *data_ptr, DLDataType data_type, void *data_space, std::initializer_list< int64_t > data_dims)
Definition: conv2d.h:43
uintptr_t nhwc_at(const DLTensor &a, int n, int y, int x, int c)
Definition: conv2d.h:103
void deblockize_hwc_16b(void *out_flat, void *inp, int height, int width, int depth)
Convert back from non-contguous layout to a flat layout.
SDLTensor< 4 > prepare_nhwc(tvm::runtime::DeviceAPI *device_api, const DLTensor *nhwc_flat, bool copy_data)
constexpr int round_up(int v, int p2)
Definition: conv2d.h:97
int calculate_num_weight_chunks(int64_t *shape_hwio)
constexpr int hwio_to_sm_16b(int width, int y, int x, int i, int o)
Definition: conv2d.h:86