Now , we have a new NPU and we want to use tensorize to extend TVM to support our NPU. But unfortunately we meet a problem.
The following is the schedule after tensorize:
We can see that tvm_address_of(A[(ko16)])* will set the offset of the address of A in each loop. but for our NPU , A’s address is not the NPU’s address. A is a struct that contains the NPU’s address.
So A[(ko16)]* doesn’t change the NPU’s address, just change the struct address.
Is there any method that we can control the offset in A’s member address, not A’s address?
So Any one can help me?
you can see the return value is the bm_device_mem_t type. the bm_device_mem_t is that struct I said.
The following is the bm_device_mem_t
typedef struct bm_mem_desc {
union {
struct {
unsigned long device_addr;
unsigned int revesved;
int dmabuf_fd;
} device;
struct {
HOST_MEM host_mem;
unsigned int reserved0;
int reserved1;
} host;
struct {
void * system_addr;
unsigned int reserved0;
int reserved1;
} system;
} u;
bm_mem_flags_t flags;
unsigned int size;
} bm_mem_desc_t;
typedef struct bm_mem_desc bm_device_mem_t;
we can see that bm_device_mem_t has a member that is device_addr. this device_addr is that member address I said.
Do you understand? I’m sorry that my expression is not clear
Please figure out if I misunderstand anything. If my understanding is correct, you want to use your struct to build a buffer. In traditional C++ code, we usually have int A[1024], which is an int buffer with size 1024. For now, you want to have a buffer like bm_mem_desc A[1024] and you want to control the member of that struct. Is that right?
I am afraid we do not have such API since it is very rare in traditional hardware even on accelerators. Can you calculate the device_addr using struct offset? If so, you can pass Buffer.data and Buffer. elem_offset separately (see https://docs.tvm.ai/api/python/tvm.html#tvm.decl_buffer) in your packed function.
Thanks for your replay。
Our new hardward just has one type of memory. So we don’t want to use buffer in tensorize. So is there any others method to resovle my problem?