espressif / esp-dl

Espressif deep-learning library for AIoT applications
MIT License
548 stars 118 forks source link

assert failed: block_merge_prev heap_tlsf.c:350 (block_is_free(prev) && "prev block is not free though marked as such") (AIV-421) #65

Closed PureHing closed 3 years ago

PureHing commented 3 years ago

@Auroragan @yehangyang

I'm sorry to bother you.

simple main code:

    int8_t *score = model.l12.get_output().get_element_ptr();//model.out_layer.get_output()
    if (NULL == score)
    {
        printf("failed\n");
    }
    float *result = (float *)malloc(size_out);
    for(int i=0;i<size_out;i++)
    {
        printf("%d:",i);
        // printf("%d,",score[i]);
        result[i]=score[i]*pow(2.f,-3);
        printf("%f,",result[i]);
    }
    printf("\nsuccess\n");
    //......

What is the cause of this problem? Log:

Size_out:450
0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:91:92:93:94:95:96:97:98:99:100:101:102:103:104:105:106:107:108:109:110:111:112:113:114:115:116:117:118:119:120:121:122:123:124:125:126:127:128:129:130:131:132:133:134:135:136:137:138:139:140:141:142:143:144:145:146:147:148:149:150:151:152:153:154:155:156:157:158:159:160:161:162:163:164:165:166:167:168:169:170:171:172:173:174:175:176:177:178:179:180:181:182:183:184:185:186:187:188:189:190:191:192:193:194:195:196:197:198:199:200:201:202:203:204:205:206:207:208:209:210:211:212:213:214:215:216:217:218:219:220:221:222:223:224:225:226:227:228:229:230:231:232:233:234:235:236:237:238:239:240:241:242:243:244:245:246:247:248:249:250:251:252:253:254:255:256:257:258:259:260:261:262:263:264:265:266:267:268:269:270:271:272:273:274:275:276:277:278:279:280:281:282:283:284:285:286:287:288:289:290:291:292:293:294:295:296:297:298:299:300:301:302:303:304:305:306:307:308:309:310:311:312:313:314:315:316:317:318:319:320:321:322:323:324:325:326:327:328:329:330:331:332:333:334:335:336:337:338:339:340:341:342:343:344:345:346:347:348:349:350:351:352:353:354:355:356:357:358:359:360:361:362:363:364:365:366:367:368:369:370:371:372:373:374:375:376:377:378:379:380:381:382:383:384:385:386:387:388:389:390:391:392:393:394:395:396:397:398:399:400:401:402:403:404:405:406:407:408:409:410:411:412:413:414:415:416:417:418:419:420:421:422:423:424:425:426:427:428:429:430:431:432:433:434:435:436:437:438:439:440:441:442:443:444:445:446:447:448:449:
success

assert failed: block_merge_prev heap_tlsf.c:350 (block_is_free(prev) && "prev block is not free though marked as such")

Backtrace:0x40379b02:0x3fcb72d00x40396db9:0x3fcb72f0 0x4039bf66:0x3fcb7310 0x4039b589:0x3fcb7430 0x4039bbe6:0x3fcb7450 0x40379cc9:0x3fcb7470 0x4039bfb5:0x3fcb7490 0x4200be19:0x3fcb74b0 0x42005857:0x3fcb74d0 0x420078fc:0x3fcb74f0 0x4201cc55:0x3fcb78f0 
0x40379b02: panic_abort at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/esp_system/panic.c:402

0x40396db9: esp_system_abort at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/esp_system/esp_system.c:129

0x4039bf66: __assert_func at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/newlib/assert.c:85

0x4039b589: block_merge_prev at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/heap/heap_tlsf.c:350
 (inlined by) tlsf_free at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/heap/heap_tlsf.c:868

0x4039bbe6: multi_heap_free_impl at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/heap/multi_heap.c:220
 (inlined by) multi_heap_free_impl at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/heap/multi_heap.c:209

0x40379cc9: heap_caps_free at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/heap/heap_caps.c:305

0x4039bfb5: free at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/newlib/heap.c:46

0x4200be19: operator delete(void*) at /builds/idf/crosstool-NG/.build/xtensa-esp32s3-elf/src/gcc/libstdc++-v3/libsupc++/del_op.cc:49

0x42005857: __gnu_cxx::new_allocator<int>::deallocate(int*, unsigned int) at /home/librazxc/.espressif/tools/xtensa-esp32s3-elf/esp-2021r1-8.4.0/xtensa-esp32s3-elf/xtensa-esp32s3-elf/include/c++/8.4.0/ext/new_allocator.h:125
 (inlined by) std::allocator_traits<std::allocator<int> >::deallocate(std::allocator<int>&, int*, unsigned int) at /home/librazxc/.espressif/tools/xtensa-esp32s3-elf/esp-2021r1-8.4.0/xtensa-esp32s3-elf/xtensa-esp32s3-elf/include/c++/8.4.0/bits/alloc_traits.h:462
 (inlined by) std::_Vector_base<int, std::allocator<int> >::_M_deallocate(int*, unsigned int) at /home/librazxc/.espressif/tools/xtensa-esp32s3-elf/esp-2021r1-8.4.0/xtensa-esp32s3-elf/xtensa-esp32s3-elf/include/c++/8.4.0/bits/stl_vector.h:304
 (inlined by) std::_Vector_base<int, std::allocator<int> >::~_Vector_base() at /home/librazxc/.espressif/tools/xtensa-esp32s3-elf/esp-2021r1-8.4.0/xtensa-esp32s3-elf/xtensa-esp32s3-elf/include/c++/8.4.0/bits/stl_vector.h:285
 (inlined by) std::vector<int, std::allocator<int> >::~vector() at /home/librazxc/.espressif/tools/xtensa-esp32s3-elf/esp-2021r1-8.4.0/xtensa-esp32s3-elf/xtensa-esp32s3-elf/include/c++/8.4.0/bits/stl_vector.h:570
 (inlined by) dl::Tensor<signed char>::~Tensor() at /home/librazxc/SoftwareDevelop/esp/esp-dl/include/typedef/dl_variable.hpp:78
 (inlined by) dl::layer::MaxPool2D<signed char>::~MaxPool2D() at /home/librazxc/SoftwareDevelop/esp/esp-dl/include/layer/dl_layer_max_pool2d.hpp:67
 (inlined by) DMMODEL::~DMMODEL() at /home/librazxc/SoftwareDevelop/esp/dl_dm_detection_esp32s3/build/../model/dm_model.hpp:21

0x420078fc: app_main at /home/librazxc/SoftwareDevelop/esp/dl_dm_detection_esp32s3/build/../main/app_main.cpp:82

0x4201cc55: main_task at /home/librazxc/SoftwareDevelop/esp/esp-idf/components/freertos/port/port_common.c:136
Auroragan commented 3 years ago

did you free the output of maxpool layer?

PureHing commented 3 years ago

As shown above, one(lm_0) of the maxpool layers is in l2_concat, I released l2_concat layer. and lm_1 & lm_2 & lm_3 is also maxpooling layer.

yehangyang commented 3 years ago

int8_t *score = model.out_layer.get_output().get_element_ptr();

@PureHing, I can not find the out_layer in the call() function.

PureHing commented 3 years ago

@yehangyang sorry ,out_layer is l12

yehangyang commented 3 years ago

@PureHing, the error happens in MaxPool2D's deconstruction. We'll check the source code. Is the score result right?

PureHing commented 3 years ago

@yehangyang The model is a regression network, now I can’t parse the score result data. It interrupt here

result[i]=score[i]*pow(2.f,-3);

yehangyang commented 3 years ago

@PureHing, I saw your log printed 'success'.

printf("%f,",result[i]); // It didn't work?

How about replace with score[i]*0.125?

PureHing commented 3 years ago

@yehangyang

How about replace with score[i]*0.125?

the same as pow

yehangyang commented 3 years ago

0x420079ca: app_main at /home/librazxc/SoftwareDevelop/esp/dl_dm_detection_esp32s3/build/../main/app_main.cpp:127 @PureHing, What is line 127?

PureHing commented 3 years ago

@yehangyang

dbox boxes = (dbox )calloc(box * (1 + 4), sizeof(dbox));

yehangyang commented 3 years ago

float result = (float )malloc(size_out);

@PureHing should be

float *result = (float *)malloc(size_out*sizeof(float));
PureHing commented 3 years ago

@yehangyang Oh, it's very awkward.

yehangyang commented 3 years ago

(inlined by) DMMODEL::~DMMODEL() at /home/librazxc/SoftwareDevelop/esp/dl_dm_detection_esp32s3/build/../model/dm_model.hpp:21 @PureHing What is this?

yehangyang commented 3 years ago

@PureHing , What your DMMODEL::~DMMODEL()?

PureHing commented 3 years ago

@yehangyang Call the parent Model class destructor, I did not define. dm_model.hpp structure modified from mnist_model.hpp

yehangyang commented 3 years ago

@PureHing, is l12 declared in public?

Please help me to locate which layer's deconstructor cause this error. By adding printf("%s\n",this->name); in each layer's deconstructor. For example Conv2D, add print() here

PureHing commented 3 years ago

yes. adding printf("%s\n",this->name),output : l12 l11 l10 l9 l8 l7 l6 l5 l4 l3 l2 l1 l0 it seems no problem,i will check it later.

@yehangyang Thanks so much.