add destructor for infer

This commit is contained in:
xuanyue 2021-03-26 14:21:03 +08:00
parent b589483cd1
commit b9cc44ef16
1 changed files with 12 additions and 1 deletions

View File

@ -15,15 +15,26 @@
*/
#include "nnacl/infer/infer_register.h"
InferShape *g_infer_func;
InferShape *g_infer_func = NULL;
__attribute__((constructor(101))) void InitInferFuncBuf() {
if (g_infer_func != NULL) {
return;
}
g_infer_func = malloc(PrimType_MAX * sizeof(InferShape));
if (g_infer_func != NULL) {
memset(g_infer_func, 0, PrimType_MAX * sizeof(InferShape));
}
}
__attribute__((destructor)) void FreeInferFuncBuf() {
if (g_infer_func == NULL) {
return;
}
free(g_infer_func);
g_infer_func = NULL;
}
InferShape GetInferFunc(int prim_type) {
if (g_infer_func != NULL && prim_type < PrimType_MAX) {
return g_infer_func[prim_type];