Cuda Error in NCHWToNCHW

using Jetson xavier and Jetpack 4.1,TensorRT 5.0,caffe model parser

Hello,

I have already successfully implements the priorbox plugin to parse caffe model,but, when calling the buildCudaEngine to create engine,it always occurs to the following errors:

ERROR: cuda/reformat.cu (408) - Cuda Error in NCHWToNCHW: 11
ERROR: cuda/reformat.cu (408) - Cuda Error in NCHWToNCHW: 11
sample_detection: TensorRtCaffeModel.cpp:59: void caffeToGIEModel(const string&, const string&, const std::vector<std::__cxx11::basic_string<char> >&, unsigned int, nvcaffeparser1::IPluginFactoryExt*, nvinfer1::IHostMemory*&): Assertion `engine' failed.
Aborted (core dumped)

In the class PriorBoxPlugin : nvinfer1::IPluginExt,I have implemented the functions of supportsFormat.From the error log,I don’t know where is wrong,whether I should declare the format,and where do i need to declare?

please explain the cause of this problem and privode solutions,thanks a lot.

bool supportsFormat(DataType type, PluginFormat format) const override
{ 
	return (type == DataType::kFLOAT || type == DataType::kHALF) && format == PluginFormat::kNCHW; 
}
void configureWithFormat(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, DataType type, PluginFormat format, int maxBatchSize) override
{
	assert((type == DataType::kFLOAT || type == DataType::kHALF) && format == PluginFormat::kNCHW);
	assert(nbInputs == 2);
        .......
}

Hello,
In order to better analyze the problem, the code files in the project are uploaded to the following website, hoping to reply to the problem mentioned above as soon as possible.
thanks a lot.
https://github.com/Penny-J/Detection_test

Moving this over to the Jetson forums for support.

hi,
according to your suggestion, the modification had done as follows:

//the return value of getOutputDimensions function change from (1,2,top_data_size)to(2,top_data_size)
 Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims)override
 {
 assert(index == 0 && nbInputDims == 2 && inputs[0].nbDims==3  );

 //dim=layer_height * layer_width * num_priors_ * 4; 
 top_data_size = inputs[0].d[1] * inputs[0].d[2] *mPriorBoxParamters.numPriors *4;

 std::cout << "getOutputDimensions top_data_size:" << top_data_size << " inputs[0]d[0]:"<< inputs[0].d[0] << " d[1]:" << inputs[0].d[2] << " d[2]:" << inputs[0].d[1] <<"  num_priors_:" << mPriorBoxParamters.numPriors << std::endl;
 //std::cout << "getOutputDimensions inputs[1]d[0]:"<< inputs[1].d[0] << " d[1]:" << inputs[1].d[2] << " d[2]:" << inputs[1].d[1] << std::endl;
 
 return Dims2(2, top_data_size);
 }
//modify the output of enquen function
int PriorBoxPlugin::enqueue(int batchSize, const void*const *inputs, void** outputs, void* workspace,cudaStream_t stream)

{
    ……

    //Before the change
   //cudaMemcpy(outputs[0],top_data,(dim*sizeof(float)),cudaMemcpyHostToDevice);
   //cudaMemcpy(outputs[1],variance_data,(dim*sizeof(float)),cudaMemcpyHostToDevice);

   //after the change
   cudaMalloc(&outputs[0],top_data_size*2*sizeof(float));
   cudaMemcpy(outputs[0],top_data,(top_data_size*2*sizeof(float)),cudaMemcpyHostToDevice);
   return 0;
}

After modification, the problem did not appear, but the new one(Segmentation fault) occured as follows:
i don’t know where and how to called the funciton of makeEngineFromGraphy and buildsignallayer,
and What kind of mistakes will lead to this problem, so, how can i do for solve this problem ? thanks for your reply.

Thread 1 "face_detection" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) where
#0  0x0000000000000000 in  ()
#1  0x0000007faf148fcc in nvinfer1::builder::<b>buildSingleLayer</b>(nvinfer1::rt::EngineBuildContext&, nvinfer1::builder::Node&, std::unordered_map<std::string, std::unique_ptr<nvinfer1::rt::Region, std::default_delete<nvinfer1::rt::Region> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::unique_ptr<nvinfer1::rt::Region, std::default_delete<nvinfer1::rt::Region> > > > > const&, nvinfer1::CpuMemoryGroup&, 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> > > > >*, bool) ()
    at /usr/lib/aarch64-linux-gnu/libnvinfer.so.5
#2  0x0000007faf14cd84 in nvinfer1::builder::<b>makeEngineFromGraph</b>(nvinfer1::CudaEngineBuildConfig const&, nvinfer1::rt::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) () at /usr/lib/aarch64-linux-gnu/libnvinfer.so.5
#3  0x0000007faf14facc in nvinfer1::builder::<b>buildEngine</b>(nvinfer1::CudaEngineBuildConfig&, nvinfer1::rt::HardwareContext const&, nvinfer1::Network const&) ()
    at /usr/lib/aarch64-linux-gnu/libnvinfer.so.5
#4  0x0000007faf1ba2ec in nvinfer1::builder::Builder::<b>buildCudaEngine</b>(nvinfer1::INetworkDefinition&) () at /usr/lib/aarch64-linux-gnu/libnvinfer.so.5
#5  0x000000555555cd24 in <b>caffeToGIEModel</b>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, unsigned int, nvcaffeparser1::IPluginFactoryExt*, nvinfer1::IHostMemory*&) ()
#6  0x0000005555564894 in main ()

Hi,

CUDA error 11 indicates that one or more of the parameters passed to the API call is not within an acceptable range of values.
Could you double check if any issue in your implementation?

Here is a plugin sample for your reference:

Thanks.

Hello,
This problem has been solved with the code as follows before create the engine.

initLibNvInferPlugins(&gLogger,"");

Can you tell me what this function means? Thanks for your apply.

Hi,

This function is required by the plugin layer.
You can also find this information in our document:

https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html#add_custom_layer
----------------------------------------------------
Note: To use TensorRT registered plugins in your application, the libnvinfer_plugin.so library must be loaded and all plugins must be registered. This can be done by calling initLibNvInferPlugins(void* logger, const char* libNamespace)() in your application code.
----------------------------------------------------

Thanks.