nvinfer1::builder::ChoiceTupleMap<T>::ChoiceTupleMap(unsigned int, T) [with T = float]: Assertion `rank <= ChoiceTuple::kMAX_RANK' failed
Dear TensorRT Development Team: I was troubled by a problem for a few days......It's about using TensorRT to accelerate caffe inference. I use TensorRT's C++ API to add every layer in caffe‘s prototxt to INetworkDefinition object. Then I invoke 'buildCudaEngine' function, just like this:
builder->buildCudaEngine(*network);
I get the following error message:
../builder/costTensor.h:271: nvinfer1::builder::ChoiceTupleMap<T>::ChoiceTupleMap(unsigned int, T) [with T = float]: Assertion `rank <= ChoiceTuple::kMAX_RANK' failed.
Then I debug it with gdb and get the following backtrace:
**[#0]** 0x0000002017498528 in __GI_raise (sig=sig@entry=0x6) at ../sysdeps/unix/sysv/linux/raise.c:54
**[#1]** 0x00000020174999e0 in __GI_abort () at abort.c:89
**[#2]** 0x0000002017491c04 in __assert_fail_base (fmt=0x201757e290 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x2000d81cc0 "rank <= ChoiceTuple::kMAX_RANK", file=file@entry=0x2000d81f70 "../builder/costTensor.h", line=line@entry=0x10f, function=function@entry=0x2000d80a20 "nvinfer1::builder::ChoiceTupleMap<T>::ChoiceTupleMap(unsigned int, T) [with T = float]") at assert.c:92
**[#3]** 0x0000002017491cac in __GI___assert_fail (assertion=0x2000d81cc0 "rank <= ChoiceTuple::kMAX_RANK", file=0x2000d81f70 "../builder/costTensor.h", line=0x10f, function=0x2000d80a20 "nvinfer1::builder::ChoiceTupleMap<T>::ChoiceTupleMap(unsigned int, T) [with T = float]") at assert.c:101
**[#4]** 0x0000002000ad021c in nvinfer1::builder::ChoiceTupleMap<float>::ChoiceTupleMap(unsigned int, float) () from /usr/lib/aarch64-linux-gnu/libnvinfer.so.4
**[#5]** 0x0000002000ac99a0 in ?? () from /usr/lib/aarch64-linux-gnu/libnvinfer.so.4
**[#6]** 0x0000002000ace910 in nvinfer1::builder::chooseFormatsAndTactics(nvinfer1::builder::Graph&, nvinfer1::builder::TacticSupply&, std::unordered_map<std::string, std::vector<float, std::allocator<float> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::vector<float, std::allocator<float> > > > >*) () from /usr/lib/aarch64-linux-gnu/libnvinfer.so.4
**[#7]** 0x0000002000aa2dfc in nvinfer1::builder::makeEngineFromGraph(nvinfer1::CudaEngineBuildConfig const&, nvinfer1::cudnn::HardwareContext const&, nvinfer1::builder::Graph&, std::unordered_map<std::string, std::vector<float, std::allocator<float> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::vector<float, std::allocator<float> > > > >*, int) () from /usr/lib/aarch64-linux-gnu/libnvinfer.so.4
**[#8]** 0x0000002000aa49bc in nvinfer1::builder::buildEngine(nvinfer1::CudaEngineBuildConfig&, nvinfer1::cudnn::HardwareContext const&, nvinfer1::Network const&) () from /usr/lib/aarch64-linux-gnu/libnvinfer.so.4
**[#9]** 0x0000002000b02a44 in ?? () from /usr/lib/aarch64-linux-gnu/libnvinfer.so.4
Then I just have a look at the disassemble code:
Dump of assembler code for function _ZN8nvinfer17builder14ChoiceTupleMapIfEC2Ejf:
0x0000002000ad0150 <+0>: stp x29, x30, [sp,#-64]!
0x0000002000ad0154 <+4>: mov x29, sp
0x0000002000ad0158 <+8>: stp x19, x20, [sp,#16]
0x0000002000ad015c <+12>: str d8, [sp,#40]
0x0000002000ad0160 <+16>: str x21, [sp,#32]
0x0000002000ad0164 <+20>: mov x19, x0
0x0000002000ad0168 <+24>: str w1, [x19]
0x0000002000ad016c <+28>: str w1, [x19,#4]
0x0000002000ad0170 <+32>: str xzr, [x0,#16]
0x0000002000ad0174 <+36>: str xzr, [x0,#24]
0x0000002000ad0178 <+40>: str xzr, [x0,#32]
0x0000002000ad017c <+44>: fmov s1, #1.000000000000000000e+00
0x0000002000ad0180 <+48>: add x0, x0, #0x28
0x0000002000ad0184 <+52>: str s1, [x19,#40]
0x0000002000ad0188 <+56>: mov w20, w1
0x0000002000ad018c <+60>: str xzr, [x0,#8]
0x0000002000ad0190 <+64>: mov x1, #0x0 // #0
0x0000002000ad0194 <+68>: fmov s8, s0
0x0000002000ad0198 <+72>: bl 0x2000a04280 <_ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEm@plt>
0x0000002000ad019c <+76>: mov x1, #0x1fffffffffffffff // #2305843009213693951
0x0000002000ad01a0 <+80>: str x0, [x19,#16]
0x0000002000ad01a4 <+84>: cmp x0, x1
0x0000002000ad01a8 <+88>: b.hi 0x2000ad01f4 <_ZN8nvinfer17builder14ChoiceTupleMapIfEC2Ejf+164>
0x0000002000ad01ac <+92>: lsl x2, x0, #3
0x0000002000ad01b0 <+96>: mov x0, x2
0x0000002000ad01b4 <+100>: str x2, [x29,#56]
0x0000002000ad01b8 <+104>: bl 0x2000a04fc0 <_Znwm@plt>
0x0000002000ad01bc <+108>: ldr x2, [x29,#56]
0x0000002000ad01c0 <+112>: mov w1, #0x0 // #0
0x0000002000ad01c4 <+116>: mov x21, x0
0x0000002000ad01c8 <+120>: bl 0x2000a03aa0 <memset@plt>
0x0000002000ad01cc <+124>: cmp w20, #0x8
0x0000002000ad01d0 <+128>: str x21, [x19,#8]
0x0000002000ad01d4 <+132>: str w20, [x19,#56]
0x0000002000ad01d8 <+136>: str s8, [x19,#60]
0x0000002000ad01dc <+140>: b.hi 0x2000ad01f8 <_ZN8nvinfer17builder14ChoiceTupleMapIfEC2Ejf+168>
0x0000002000ad01e0 <+144>: ldp x19, x20, [sp,#16]
0x0000002000ad01e4 <+148>: ldr x21, [sp,#32]
0x0000002000ad01e8 <+152>: ldr d8, [sp,#40]
0x0000002000ad01ec <+156>: ldp x29, x30, [sp],#64
0x0000002000ad01f0 <+160>: ret
0x0000002000ad01f4 <+164>: bl 0x2000a031a0 <_ZSt17__throw_bad_allocv@plt>
0x0000002000ad01f8 <+168>: adrp x3, 0x2000d80000
0x0000002000ad01fc <+172>: adrp x0, 0x2000d81000
0x0000002000ad0200 <+176>: adrp x1, 0x2000d81000
0x0000002000ad0204 <+180>: add x3, x3, #0x4f0
0x0000002000ad0208 <+184>: add x0, x0, #0xcc0
0x0000002000ad020c <+188>: add x1, x1, #0xf70
0x0000002000ad0210 <+192>: mov w2, #0x10f // #271
0x0000002000ad0214 <+196>: add x3, x3, #0x530
0x0000002000ad0218 <+200>: bl 0x2000a03930 <__assert_fail@plt>
End of assembler dump.
I notice that the program execute '0x0000002000ad01dc <+140>', then jump to '0x0000002000ad01f8 <+168>' and finally my program crashed. From the previous compare operation '0x0000002000ad01cc <+124>', I get the assumption that 'ChoiceTuple::kMAX_RANK = 8' and w20<-w1 is the paramter of 'nvinfer1::builder::ChoiceTupleMap
The Slice layer was like this: layer { name: "slice1" bottom: "reduce2" type: "Slice" top: "slice1_1" top: "slice1_2" top: "slice1_3" top: "slice1_4" top: "slice1_5" top: "slice1_6" top: "slice1_7" top: "slice1_8" top: "slice1_9" top: "slice1_10" top: "slice1_11" top: "slice1_12" top: "slice1_13" top: "slice1_14" top: "slice1_15" top: "slice1_16" top: "slice1_17" top: "slice1_18" top: "slice1_19" top: "slice1_20" top: "slice1_21" top: "slice1_22" top: "slice1_23" top: "slice1_24" top: "slice1_25" top: "slice1_26" top: "slice1_27" top: "slice1_28" top: "slice1_29" top: "slice1_30" top: "slice1_31" top: "slice1_32" top: "slice1_33" top: "slice1_34" top: "slice1_35" top: "slice1_36" top: "slice1_37" top: "slice1_38" top: "slice1_39" top: "slice1_40" top: "slice1_41" top: "slice1_42" top: "slice1_43" top: "slice1_44" top: "slice1_45" top: "slice1_46" top: "slice1_47" top: "slice1_48" top: "slice1_49" top: "slice1_50" top: "slice1_51" top: "slice1_52" top: "slice1_53" top: "slice1_54" top: "slice1_55" top: "slice1_56" top: "slice1_57" top: "slice1_58" top: "slice1_59" top: "slice1_60" slice_param { axis: 2 slice_point: 1 slice_point: 2 slice_point: 3 slice_point: 4 slice_point: 5 slice_point: 6 slice_point: 7 slice_point: 8 slice_point: 9 slice_point: 10 slice_point: 11 slice_point: 12 slice_point: 13 slice_point: 14 slice_point: 15 slice_point: 16 slice_point: 17 slice_point: 18 slice_point: 19 slice_point: 20 slice_point: 21 slice_point: 22 slice_point: 23 slice_point: 24 slice_point: 25 slice_point: 26 slice_point: 27 slice_point: 28 slice_point: 29 slice_point: 30 slice_point: 31 slice_point: 32 slice_point: 33 slice_point: 34 slice_point: 35 slice_point: 36 slice_point: 37 slice_point: 38 slice_point: 39 slice_point: 40 slice_point: 41 slice_point: 42 slice_point: 43 slice_point: 44 slice_point: 45 slice_point: 46 slice_point: 47 slice_point: 48 slice_point: 49 slice_point: 50 slice_point: 51 slice_point: 52 slice_point: 53 slice_point: 54 slice_point: 55 slice_point: 56 slice_point: 57 slice_point: 58 slice_point: 59 } }
Hi @Eclipsehelio,
I use TensorRT's C++ API to add every layer in caffe‘s prototxt to INetworkDefinition object.
Did you do this manually with the API? Pseudocode:
network = INetworkDefinition
network.add_layer()
network.add_layer()
...
Or did you use the Caffe parser similar to this sample?
void SampleFasterRCNN::constructNetwork(SampleUniquePtr<nvcaffeparser1::ICaffeParser>& parser,
SampleUniquePtr<nvinfer1::IBuilder>& builder, SampleUniquePtr<nvinfer1::INetworkDefinition>& network,
SampleUniquePtr<nvinfer1::IBuilderConfig>& config)
{
const nvcaffeparser1::IBlobNameToTensor* blobNameToTensor
= parser->parse(locateFile(mParams.prototxtFileName, mParams.dataDirs).c_str(),
locateFile(mParams.weightsFileName, mParams.dataDirs).c_str(), *network, nvinfer1::DataType::kFLOAT);
for (auto& s : mParams.outputTensorNames)
{
network->markOutput(*blobNameToTensor->find(s.c_str()));
}
builder->setMaxBatchSize(mParams.batchSize);
config->setMaxWorkspaceSize(16_MiB);
samplesCommon::enableDLA(builder.get(), config.get(), mParams.dlaCore);
}
https://github.com/NVIDIA/TensorRT/blob/master/samples/opensource/sampleFasterRCNN/sampleFasterRCNN.cpp#L181-L197
Thank you for your replying! I did this manually with the API, just like
network = INetworkDefinition
network.add_layer()
network.add_layer()
@eclipsehelio Sorry, I haven't seen this error before - seems like something implementation specific (like bad parameter in your network or something)
Can you try something simpler like using trtexec (https://github.com/NVIDIA/TensorRT/blob/release/6.0/samples/opensource/trtexec/README.md#example-1-simple-mnist-model-from-caffe) or the Caffe Parser to parse your Caffe model and see if you get the same error?
I'm facing the same error when trying to build a serialized engine from an onnx file using the C++ API:
Engine generation failed with backend strategy 3.
Error message: [costTensor.h::ChoiceTupleMap::312] Error Code 2: Internal Error (Assertion rank <= ChoiceTuple::kMAX_RANK failed. ).
Skipping this backend strategy.
Segmentation fault (core dumped)
I'm using TRT 8.6.1.6 on a 2080Ti GPU and the stack trace shows me that the segfault is happening in buildSerializedNetwork. Strangely, trtexec can do the conversion without error! And I'm using an instance of nvonnxparser::IParser to parse the onnx file.
Any possible reason for this segfault? Let me add that I'm not calling setMemoryPoolLimit and according to the documentation, the default value is the whole device memory. So it's unlikely that such an error will happen because of limited workspace size