|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 Synopsys |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include "mli_api.h" |
| 8 | +#include <assert.h> |
| 9 | +#include <zephyr.h> |
| 10 | +#include <stdio.h> |
| 11 | +#include "mli_config.h" |
| 12 | + |
| 13 | +#if (PLATFORM == V2DSP_XY) |
| 14 | +#define DATA_ATTR __xy __attribute__((section(".Xdata"))) |
| 15 | + |
| 16 | +#elif (PLATFORM == V2DSP_VECTOR) |
| 17 | +#define DATA_ATTR __vccm __attribute__((section(".vecmem_data"))) |
| 18 | + |
| 19 | +#else |
| 20 | +#define DATA_ATTR |
| 21 | + |
| 22 | +#endif |
| 23 | + |
| 24 | +#define NUM_ELEMS 8 |
| 25 | + |
| 26 | +int16_t DATA_ATTR data_in1[NUM_ELEMS] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 27 | +int16_t DATA_ATTR data_in2[NUM_ELEMS] = { 10, 20, 30, 40, 50, 60, 70, 80 }; |
| 28 | +int16_t DATA_ATTR data_out[NUM_ELEMS] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 29 | + |
| 30 | +int main() { |
| 31 | + mli_tensor in1 = { 0 }; |
| 32 | + in1.el_type = MLI_EL_FX_16; |
| 33 | + in1.rank = 1; |
| 34 | + in1.shape[0] = NUM_ELEMS; |
| 35 | + in1.mem_stride[0] = 1; |
| 36 | + in1.data.capacity = sizeof(data_in1); |
| 37 | + in1.data.mem.pi16 = (int16_t *)data_in1; |
| 38 | + |
| 39 | + mli_tensor in2 = { 0 }; |
| 40 | + in2.el_type = MLI_EL_FX_16; |
| 41 | + in2.rank = 1; |
| 42 | + in2.shape[0] = NUM_ELEMS; |
| 43 | + in2.mem_stride[0] = 1; |
| 44 | + in2.data.capacity = sizeof(data_in2); |
| 45 | + in2.data.mem.pi16 = (int16_t *)data_in2; |
| 46 | + |
| 47 | + mli_tensor out = { 0 }; |
| 48 | + out.el_type = MLI_EL_FX_16; |
| 49 | + out.rank = 1; |
| 50 | + out.shape[0] = NUM_ELEMS; |
| 51 | + out.mem_stride[0] = 1; |
| 52 | + out.data.capacity = sizeof(data_out); |
| 53 | + out.data.mem.pi16 = (int16_t *)data_out; |
| 54 | + |
| 55 | + printf("in1:\n"); |
| 56 | + for (int i = 0; i < NUM_ELEMS; i++) { |
| 57 | + printf("%d ", in1.data.mem.pi16[i]); |
| 58 | + } |
| 59 | + printf("\nin2:\n"); |
| 60 | + for (int i = 0; i < NUM_ELEMS; i++) { |
| 61 | + printf("%d ", in2.data.mem.pi16[i]); |
| 62 | + } |
| 63 | + |
| 64 | + mli_status status; |
| 65 | + status = mli_krn_eltwise_add_fx16(&in1, &in2, &out); |
| 66 | + assert(status == MLI_STATUS_OK); |
| 67 | + |
| 68 | + printf("\nmli_krn_eltwise_add_fx16 output:\n"); |
| 69 | + for (int i = 0; i < NUM_ELEMS; i++) { |
| 70 | + printf("%d ", out.data.mem.pi16[i]); |
| 71 | + } |
| 72 | + |
| 73 | + status = mli_krn_eltwise_sub_fx16(&in1, &in2, &out); |
| 74 | + assert(status == MLI_STATUS_OK); |
| 75 | + |
| 76 | + printf("\nmli_krn_eltwise_sub_fx16 output:\n"); |
| 77 | + for (int i = 0; i < NUM_ELEMS; i++) { |
| 78 | + printf("%d ", out.data.mem.pi16[i]); |
| 79 | + } |
| 80 | + printf("\n"); |
| 81 | + |
| 82 | + return 0; |
| 83 | +} |
0 commit comments