memory release

This commit is contained in:
Francesco Gatti
2020-06-02 12:43:06 +02:00
parent 0458f361b1
commit 62e4a3f779
7 changed files with 20 additions and 5 deletions
+5
View File
@@ -24,6 +24,11 @@ Layer::~Layer() {
checkCUDNN( cudnnDestroyTensorDescriptor(srcTensorDesc) );
checkCUDNN( cudnnDestroyTensorDescriptor(dstTensorDesc) );
if(dstData != nullptr) {
cudaFree(dstData);
dstData = nullptr;
}
}
}}
+3 -3
View File
@@ -80,7 +80,7 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs,
variance16_h = new __half[b_size];
scales16_h = new __half[b_size];
//cudaMalloc(&power16_d, b_size*sizeof(__half));
cudaMalloc(&power16_d, b_size*sizeof(__half));
cudaMalloc(&mean16_d, b_size*sizeof(__half));
cudaMalloc(&variance16_d, b_size*sizeof(__half));
cudaMalloc(&scales16_d, b_size*sizeof(__half));
@@ -91,8 +91,8 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs,
//init power array of ones
cudaMemcpy(tmp_d, power_h, b_size*sizeof(float), cudaMemcpyHostToDevice);
//float2half(tmp_d, power16_d, b_size);
//cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
float2half(tmp_d, power16_d, b_size);
cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
//mean array
cudaMemcpy(tmp_d, mean_h, b_size*sizeof(float), cudaMemcpyHostToDevice);
+1
View File
@@ -128,6 +128,7 @@ void Network::print() {
}
printCenteredTitle("", '=', 60);
std::cout<<"\n";
printCudaMemUsage();
}
const char *Network::getNetworkRTName(const char *network_name){
networkName = network_name;
+1
View File
@@ -134,6 +134,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
networkRT->markOutput(*input);
std::cout<<"Selected maxBatchSize: "<<builderRT->getMaxBatchSize()<<"\n";
printCudaMemUsage();
std::cout<<"Building tensorRT cuda engine...\n";
#if NV_TENSORRT_MAJOR >= 6
engineRT = builderRT->buildEngineWithConfig(*networkRT, *configRT);
+6
View File
@@ -197,6 +197,12 @@ void getMemUsage(double& vm_usage_kb, double& resident_set_kb){
resident_set_kb = rss * page_size_kb;
}
void printCudaMemUsage() {
size_t free, total;
checkCuda( cudaMemGetInfo(&free, &total) );
std::cout<<"GPU free memory: "<<double(free)/1e6<<" mb.\n";
}
void removePathAndExtension(const std::string &full_string, std::string &name){
name = full_string;
std::string tmp_str = full_string;