diff --git a/mindspore/lite/nnacl/infer/infer_register.c b/mindspore/lite/nnacl/infer/infer_register.c index b5ebf09b60..46dfe4479b 100644 --- a/mindspore/lite/nnacl/infer/infer_register.c +++ b/mindspore/lite/nnacl/infer/infer_register.c @@ -15,17 +15,24 @@ */ #include "nnacl/infer/infer_register.h" -InferShape g_infer_func[PrimType_MAX]; +InferShape *g_infer_func; + +__attribute__((constructor(101))) void InitInferFuncBuf() { + g_infer_func = malloc(PrimType_MAX * sizeof(InferShape)); + if (g_infer_func != NULL) { + memset(g_infer_func, 0, PrimType_MAX * sizeof(InferShape)); + } +} InferShape GetInferFunc(int prim_type) { - if (prim_type < PrimType_MAX) { + if (g_infer_func != NULL && prim_type < PrimType_MAX) { return g_infer_func[prim_type]; } return NULL; } void RegInfer(int prim_type, InferShape func) { - if (prim_type < PrimType_MAX) { + if (g_infer_func != NULL && prim_type < PrimType_MAX) { g_infer_func[prim_type] = func; } } diff --git a/mindspore/lite/nnacl/infer/infer_register.h b/mindspore/lite/nnacl/infer/infer_register.h index 7e2ca85535..edb7325570 100644 --- a/mindspore/lite/nnacl/infer/infer_register.h +++ b/mindspore/lite/nnacl/infer/infer_register.h @@ -219,7 +219,7 @@ enum PrimType { void RegInfer(int prim_type, InferShape func); #define REG_INFER(op, type, func) \ - __attribute__((constructor)) void Reg##op##Infer() { RegInfer(type, func); } + __attribute__((constructor(102))) void Reg##op##Infer() { RegInfer(type, func); } #ifdef __cplusplus } #endif