1717#include " mli_helpers_api.h"
1818#include " mli_math.h"
1919#include " mli_math_macros.h"
20+ #include " mli_mem_info.h"
2021#include " mli_prv_activation_lut.h"
2122#include " mli_prv_tensor.h"
2223#include " mli_types.h"
2324
24- #if _ARC
25- #include < arc/arc_reg.h>
26- #endif
2725#pragma MLI_CODE_SECTION_START(".mli_lib")
28- #define SUPPORT_NON_ALIGNMENT 22
29- #define DISABLE_ALIGNMENT_CHECK 19
30-
31-
32- #if core_config_dccm_size
33- static MLI_FORCE_INLINE bool mli_chk_inside_dccm (const void *ptr) {
34- return ((uint32_t )ptr >= core_config_dccm_base) &&
35- ((uint32_t )ptr < core_config_dccm_base + core_config_dccm_size);
36- }
37- #endif
38-
39- #if core_config_xy_size
40- static MLI_FORCE_INLINE bool mli_chk_inside_yccm (const void *ptr) {
41- #ifdef core_config_xy_y_base
42- return ((uint32_t )ptr >= core_config_xy_y_base) &&
43- ((uint32_t )ptr < core_config_xy_y_base + core_config_xy_size);
44- #else
45- return false ;
46- #endif
47- }
4826
49- static MLI_FORCE_INLINE bool mli_chk_inside_xccm (const void *ptr) {
50- #ifdef core_config_xy_x_base
51- return ((uint32_t )ptr >= core_config_xy_x_base) &&
52- ((uint32_t )ptr < core_config_xy_x_base + core_config_xy_size);
53- #else
54- return false ;
55- #endif
56- }
57- #endif
58-
59- #if core_config_xy_size || core_config_dccm_size
60- static MLI_FORCE_INLINE bool mli_chk_inside_ccm (const void *ptr) {
61- #if core_config_xy_size
62- if (mli_chk_inside_xccm (ptr) || mli_chk_inside_yccm (ptr)) {
63- return true ;
64- }
65- #endif
66- #if core_config_dccm_size
67- if (mli_chk_inside_dccm (ptr)) {
68- return true ;
69- }
70- #endif
71- return false ;
72- }
73- #endif
7427
75- static MLI_FORCE_INLINE mli_status mli_chk_ptr (void *p, uint32_t align_mask, bool check_bank, bool vccm_chk_bank) {
76- #if MLI_PTR_IS_VCCM
77- bool is_inside_vccm = mli_prv_is_inside_vccm (p);
78- if (vccm_chk_bank && (!is_inside_vccm))
79- return MLI_STATUS_MEM_BANK_MISMATCH;
80- // Check the alignment if the pointer is inside the VCCM memory or the non_alignment isn't supported
81- if (is_inside_vccm ||
82- (((_lr (ISA_CONFIG)&(1 <<SUPPORT_NON_ALIGNMENT)) == 0 ) || ((_lr (STATUS32)&(1 <<DISABLE_ALIGNMENT_CHECK)) == 0 ))) {
83- if (((uint32_t )p & align_mask) != 0 )
84- return MLI_STATUS_MISALIGNMENT_ERROR;
85- }
86- #endif
87- #if MLI_PTR_IS_XY
88- if (check_bank && (!mli_chk_inside_ccm (p)))
89- return MLI_STATUS_MEM_BANK_MISMATCH;
90- #endif
91- #if (PLATFORM == V2DSP_XY) || ((PLATFORM == V2DSP_VECTOR) && (!MLI_PTR_IS_VCCM))
92- if (((_lr (ISA_CONFIG)&(1 <<SUPPORT_NON_ALIGNMENT)) == 0 ) || ((_lr (STATUS32)&(1 <<DISABLE_ALIGNMENT_CHECK)) == 0 )) {
93- if (((uint32_t )p & align_mask) != 0 )
94- return MLI_STATUS_MISALIGNMENT_ERROR;
95- }
96- #endif
97- return MLI_STATUS_OK;
98- }
9928// vccm_chk_bank will be false for the APIs that does't require the tensor to be in VCCM like data Movement API.
10029template <bool vccm_chk_bank = true >
10130/* check_bank checks whether the tensor buffer have to be allocated in ccm memory or not and its value will be:
@@ -106,7 +35,7 @@ static MLI_FORCE_INLINE mli_status mli_mem_chk(const mli_tensor *t, bool check_b
10635#if (PLATFORM == V2DSP_XY) || (PLATFORM == V2DSP_VECTOR)
10736 void *p = t->data .mem .void_p ;
10837 uint32_t align_mask = mli_hlp_tensor_element_size (t) - 1 ;
109- return mli_chk_ptr (p, align_mask, check_bank, vccm_chk_bank);
38+ return mli_mem_chk_ptr (p, align_mask, check_bank, vccm_chk_bank);
11039#else
11140 return MLI_STATUS_OK;
11241#endif
@@ -163,7 +92,7 @@ mli_status mli_chk_lut(const mli_lut * lut, int buff_size) {
16392 mli_tensor dummy = { .el_type = lut->type };
16493 uint32_t align_mask = mli_hlp_tensor_element_size (&dummy) - 1 ;
16594
166- mli_status ret = mli_chk_ptr (p, align_mask, true , true );
95+ mli_status ret = mli_mem_chk_ptr (p, align_mask, true , true );
16796 return ret;
16897#else
16998 return MLI_STATUS_OK;
@@ -416,19 +345,6 @@ static MLI_FORCE_INLINE bool check_quantized_on_tensor(const mli_tensor *t1, con
416345 return !fail;
417346}
418347
419- /* This function returns maximum value can be stored in tensor according to its type */
420- static MLI_FORCE_INLINE const uint32_t mli_hlp_tensor_element_positive_limit (const mli_tensor *in) {
421- switch (in->el_type ) {
422- case MLI_EL_FX_8: return (uint32_t )mli_math_limit_fx<int8_t >(1 );
423- case MLI_EL_SA_8: return (uint32_t )mli_math_limit_fx<int8_t >(1 );
424- case MLI_EL_FX_16: return (uint32_t )mli_math_limit_fx<int16_t >(1 );
425- case MLI_EL_SA_32: return (uint32_t )mli_math_limit_fx<int32_t >(1 );
426- default :
427- MLI_ASSERT (0 );
428- return 0 ;
429- }
430- }
431-
432348/* *****************************************************
433349 * mli_krn_conv2d_hwc parameters checking function
434350 ******************************************************/
0 commit comments