Cuda Error in allocate: 2 (out of memory) - GPU Memory Leak?
Description
I am running a simple benchmarking script that has a function that takes a Pytorch model, converts it to TensorRT (via ONNX), then runs inference on it multiple times and measures the time.
The function is called from main inside a loop with different models.
What I've noticed is that after each model finishes running, the GPU isn't cleared completely, until the point where I start getting the following errors:
[TensorRT] WARNING: /usr/src/tensorrt/onnx-tensorrt/onnx2trt_utils.cpp:232: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
[TensorRT] WARNING: /usr/src/tensorrt/onnx-tensorrt/onnx2trt_utils.cpp:232: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
[TensorRT] ERROR: ../rtSafe/safeRuntime.cpp (25) - Cuda Error in allocate: 2 (out of memory)
[TensorRT] WARNING: GPU memory allocation error during getBestTactic: Conv_3 + Relu_5
[TensorRT] ERROR: ../rtSafe/safeRuntime.cpp (25) - Cuda Error in allocate: 2 (out of memory)
[TensorRT] WARNING: GPU memory allocation error during getBestTactic: Conv_3 + Relu_5
[TensorRT] ERROR: ../rtSafe/safeRuntime.cpp (25) - Cuda Error in allocate: 2 (out of memory)
[TensorRT] WARNING: GPU memory allocation error during getBestTactic: Conv_3 + Relu_5
[TensorRT] ERROR: ../rtSafe/safeRuntime.cpp (25) - Cuda Error in allocate: 2 (out of memory)
[TensorRT] WARNING: GPU memory allocation error during getBestTactic: Conv_3 + Relu_5
[TensorRT] ERROR: ../rtSafe/safeRuntime.cpp (25) - Cuda Error in allocate: 2 (out of memory)
[TensorRT] WARNING: GPU memory allocation error during getBestTactic: Conv_3 + Relu_5
[TensorRT] ERROR: ../rtSafe/safeRuntime.cpp (25) - Cuda Error in allocate: 2 (out of memory)
[TensorRT] WARNING: GPU memory allocation error during getBestTactic: Conv_3 + Relu_5
[TensorRT] ERROR: Try increasing the workspace size with IBuilderConfig::setMaxWorkspaceSize() if using IBuilder::buildEngineWithConfig, or IBuilder::setMaxWorkspaceSize() if using IBuilder::buildCudaEngine.
[TensorRT] ERROR: ../builder/tacticOptimizer.cpp (1715) - TRTInternal Error in computeCosts: 0 (Could not find any implementation for node Conv_3 + Relu_5.)
[TensorRT] ERROR: ../builder/tacticOptimizer.cpp (1715) - TRTInternal Error in computeCosts: 0 (Could not find any implementation for node Conv_3 + Relu_5.)
Exception: 'NoneType' object has no attribute 'serialize' - Couldnt convert model to TRT
The conversion and inference is run using code based on @rmccorm4 's GitHub repo with dynamic batching (and max_workspace_size = 2 << 30).
When I convert only a single model, there is never a problem, which leads me to believe that the GPU isn't being cleared at the end of each conversion.
Environment
TensorRT Version: 7.1.3.4 GPU Type: Ti2080 Nvidia Driver Version: 450.66 CUDA Version: 11.0 CUDNN Version: 8.0.3 Operating System + Version: Ubuntu 18.04.5 LTS Python Version (if applicable): 3.7.5 PyTorch Version (if applicable): 1.6
Same problem. But this problem only happens when my system is 1080ti+tensorRT7.0+cuda10.0+centos7.6. When I change to 2080ti+tensorRT7.0, everything works fine. So it's really wired! Does it mean tensorRT7.0 not support 1080ti?
Hello @yoni-f , thanks for reporting Could you try TRT7.2 to see if this is fixed in latest version? Thanks
I will close this since no response in more than 3 weeks, please reopen if you still see issue, thanks!
@ttyio please stop closing tickets for no reason! You have the trace log, you should reproduce the bug and fix it. We paid Nvidia and we want a stable software.
Hello @jasseur2017 , only the log without a repro is insufficient for debug. At least we need know more like the available memory in your system (might other application also consumes GPU memory), could you try a small batch size and a small workspace size, and if all of these not helps, we need you to provide repro, and the policy is that we will close issue if we have no response in 3 weeks.
@jasseur2017 It is very hard to determine what the problems is just based on the log and the description. To fix this problem we'll need a way to reproduce it, we don't see this in our own testing. If you or anyone else has a repro case, please post it here, and we'll reopen this issue and resume investigation. As @ttyio mentioned, we close issues where we don't get a response to our requests for 3 weeks. Since we track all open issues, this policy helps filter ones that have probably been fixed in a later release or ones where users have discovered bug in their own code.
@ttyio @mk-nvidia Can you provide some debugging means? I search on google, and some blog said change the cuDNN version will solve the problem. But people will feel confused when changing the version.
I face the problem with 1080 and no problem on 2080. And I don't found any debug means.
nvinfer1::ICudaEngine *engine = builder_->buildCudaEngine(*network_);
Doesn’t even output the wrong type, but just nullptr.
Hello @daohu527 , could you enable verbose log to see the detail failure? thanks!
Thanks for your quick reply, I set the logger like below, could you pls give some help!
class RTLogger : public nvinfer1::ILogger {
void log(Severity severity, const char *msg) override {
if (severity != Severity::kINFO) {
AINFO << msg;
}
}
} rt_gLogger;
builder_ = nvinfer1::createInferBuilder(rt_gLogger);
How can I open the debug info, you can use AINFO as log output
@daohu527 , your code is right, and the debug info is dumped with severity equal to Severity::kINFO and Severity::kVERBOSE. Could you remove the severity check and attach the full log here? thanks!
Thanks, I will try and reply to the result later.
The log is below, if you need more information, please let me know.
W0111 17:51:28.923498 19092 rt_net.cc:453] unknown layer type:Silence
I0111 17:51:28.924904 19092 rt_net.cc:645] Device Works on FP32 Mode.
E0111 17:51:28.924913 19092 rt_net.cc:633] rt_net buildCudaEngine
I0111 17:51:28.925493 19092 rt_net.cc:30] Original: 59 layers
I0111 17:51:28.925582 19092 rt_net.cc:30] After dead-layer removal: 59 layers
I0111 17:51:28.925683 19092 rt_net.cc:30] After scale fusion: 59 layers
I0111 17:51:28.925696 19092 rt_net.cc:30] Fusing conv0_1 with activation relu_conv0_1
I0111 17:51:28.925830 19092 rt_net.cc:30] Fusing conv0 with activation relu_conv0
I0111 17:51:28.925887 19092 rt_net.cc:30] Fusing conv1_1 with activation relu_conv1_1
I0111 17:51:28.925930 19092 rt_net.cc:30] Fusing conv1 with activation relu_conv1
I0111 17:51:28.925969 19092 rt_net.cc:30] Fusing conv2_1 with activation relu_conv2_1
I0111 17:51:28.926007 19092 rt_net.cc:30] Fusing conv2_2 with activation relu_conv2_2
I0111 17:51:28.926043 19092 rt_net.cc:30] Fusing conv2 with activation relu_conv2
I0111 17:51:28.926080 19092 rt_net.cc:30] Fusing conv3_1 with activation relu_conv3_1
I0111 17:51:28.926117 19092 rt_net.cc:30] Fusing conv3_2 with activation relu_conv3_2
I0111 17:51:28.926153 19092 rt_net.cc:30] Fusing conv3 with activation relu_conv3
I0111 17:51:28.926188 19092 rt_net.cc:30] Fusing conv4_1 with activation relu_conv4_1
I0111 17:51:28.926223 19092 rt_net.cc:30] Fusing conv4_2 with activation relu_conv4_2
I0111 17:51:28.926257 19092 rt_net.cc:30] Fusing conv4 with activation relu_conv4
I0111 17:51:28.926291 19092 rt_net.cc:30] Fusing conv5_1 with activation relu_conv5_1
I0111 17:51:28.926323 19092 rt_net.cc:30] Fusing conv5 with activation relu_conv5
I0111 17:51:28.926357 19092 rt_net.cc:30] Fusing deconv5_1 with activation relu_deconv5_1
I0111 17:51:28.926388 19092 rt_net.cc:30] Fusing deconv4_1 with activation relu_deconv4_1
I0111 17:51:28.926419 19092 rt_net.cc:30] Fusing deconv3_1 with activation relu_deconv3_1
I0111 17:51:28.926450 19092 rt_net.cc:30] Fusing deconv2_1 with activation relu_deconv2_1
I0111 17:51:28.926479 19092 rt_net.cc:30] Fusing deconv1_1 with activation relu_deconv1_1
I0111 17:51:28.926529 19092 rt_net.cc:30] After conv-act fusion: 39 layers
I0111 17:51:28.926580 19092 rt_net.cc:30] After tensor merging: 39 layers
I0111 17:51:28.926595 19092 rt_net.cc:30] Eliminating contatenation Concat_concat4
I0111 17:51:28.926599 19092 rt_net.cc:30] Retargeting conv4_relu_conv4 to concat4
I0111 17:51:28.926604 19092 rt_net.cc:30] Retargeting deconv4_relu_deconv4 to concat4
I0111 17:51:28.926640 19092 rt_net.cc:30] Eliminating contatenation Concat_concat3
I0111 17:51:28.926645 19092 rt_net.cc:30] Retargeting conv3_relu_conv3 to concat3
I0111 17:51:28.926647 19092 rt_net.cc:30] Retargeting deconv3_relu_deconv3 to concat3
I0111 17:51:28.926674 19092 rt_net.cc:30] Eliminating contatenation Concat_concat2
I0111 17:51:28.926678 19092 rt_net.cc:30] Retargeting conv2_relu_conv2 to concat2
I0111 17:51:28.926682 19092 rt_net.cc:30] Retargeting deconv2_relu_deconv2 to concat2
I0111 17:51:28.926708 19092 rt_net.cc:30] Eliminating contatenation Concat_concat1
I0111 17:51:28.926712 19092 rt_net.cc:30] Retargeting conv1_relu_conv1 to concat1
I0111 17:51:28.926717 19092 rt_net.cc:30] Retargeting deconv1_relu_deconv1 to concat1
I0111 17:51:28.926762 19092 rt_net.cc:30] After concat removal: 35 layers
I0111 17:51:29.275362 19092 rt_net.cc:30]
I0111 17:51:29.275379 19092 rt_net.cc:30] --------------- Timing conv0_1 + relu_conv0_1(3)
I0111 17:51:29.275501 19092 rt_net.cc:30]
I0111 17:51:29.275507 19092 rt_net.cc:30] --------------- Timing conv0_1 + relu_conv0_1(2)
I0111 17:51:29.280285 19092 rt_net.cc:30] Tactic 8 time 0.76384
I0111 17:51:29.282014 19092 rt_net.cc:30] Tactic 9 time 0.564032
I0111 17:51:29.284884 19092 rt_net.cc:30] Tactic 20 time 0.654848
I0111 17:51:29.286579 19092 rt_net.cc:30] Tactic 28 time 0.574304
I0111 17:51:29.288545 19092 rt_net.cc:30] Tactic 32 time 0.688128
I0111 17:51:29.290541 19092 rt_net.cc:30] Tactic 34 time 0.70288
I0111 17:51:29.292511 19092 rt_net.cc:30] Tactic 40 time 0.690176
I0111 17:51:29.294221 19092 rt_net.cc:30] Tactic 55 time 0.66672
I0111 17:51:29.295944 19092 rt_net.cc:30] Tactic 59 time 0.610944
I0111 17:51:29.297951 19092 rt_net.cc:30] Tactic 68 time 0.757952
I0111 17:51:29.299887 19092 rt_net.cc:30] Tactic 86 time 0.69408
I0111 17:51:29.302925 19092 rt_net.cc:30] Tactic 91 time 0.68848
I0111 17:51:29.304864 19092 rt_net.cc:30] Tactic 114 time 0.730496
I0111 17:51:29.306488 19092 rt_net.cc:30] Tactic 155 time 0.66336
I0111 17:51:29.308213 19092 rt_net.cc:30]
I0111 17:51:29.308225 19092 rt_net.cc:30] --------------- Timing conv0_1 + relu_conv0_1(14)
I0111 17:51:29.308512 19092 rt_net.cc:30]
I0111 17:51:29.308521 19092 rt_net.cc:30] --------------- Timing conv0_1 + relu_conv0_1(1)
I0111 17:51:29.308746 19092 rt_net.cc:30] cudnnConvolutionLayer.cpp (254) - Cuda Error in execute: 7
I0111 17:51:29.311440 19092 rt_net.cc:30] cudnnConvolutionLayer.cpp (254) - Cuda Error in execute: 7
below is the code, and I found int8_mode is false, and calibrator_ is nullptr
builder_ = nvinfer1::createInferBuilder(rt_gLogger);
network_ = builder_->createNetwork();
nvinfer1::ICaffePoolOutputDimensionsFormula poolFormula;
network_->setPoolingOutputDimensionsFormula(&poolFormula);
parse_with_api(shapes);
builder_->setMaxBatchSize(max_batch_size_);
workspaceSize_ = 1 << 30;
builder_->setMaxWorkspaceSize(workspaceSize_);
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, gpu_id_);
bool int8_mode = checkInt8(prop.name, calibrator_);
builder_->setInt8Mode(int8_mode); \\ false
builder_->setInt8Calibrator(calibrator_); \\ calibrator_ is nullptr
builder_->setDebugSync(true);
nvinfer1::ICudaEngine *engine = builder_->buildCudaEngine(*network_);
context_ = engine->createExecutionContext();
buffers_.resize(input_names_.size() + output_names_.size());
Hello @daohu527, the error information is
cudnnConvolutionLayer.cpp (254) - Cuda Error in execute: 7
from google we can see that the error 7 means "too many resources requested for launch", by upgrading cudnn, you will have more optimized cuda kernels that might request less resources like reg, smem, then the kernel might fit 1080.
reason
Thanks for your help, I found "too many resources requested for launch" on Google, and there are some ways to solve it
what can I do
I found below code in "tensorrt/plugins", can I adjust resources by modifying "nthreads" ? Still say I can't do anything about the build process ?
Slice // NOLINT_NEXT_LINE(whitespace/operators)
<< < block_num, 512, 0, stream >> > (
nthreads, (const float *) (inputs[0]), num_slices, slice_size,
input_dims_.d[axis_], top_slice_axis,
offset_slice_axis, reinterpret_cast<float *>(outputs[i]));
offset_slice_axis += top_slice_axis;
@daohu527 the core part is not open sourced yet, so you cannot manually fix this.
Could you try upgrade both TRT and cudnn in your machine? You TRT is also not the latest from the log.
OK, I will try, thank for you help