memory release

This commit is contained in:
Francesco Gatti
2020-06-02 12:43:06 +02:00
parent 8c79b75227
commit 4f907dde40
7 changed files with 20 additions and 5 deletions
+3 -2
View File
@@ -50,7 +50,7 @@ public:
} }
void setFinal() { this->final = true; } void setFinal() { this->final = true; }
dataDim_t input_dim, output_dim; dataDim_t input_dim, output_dim;
dnnType *dstData; //where results will be putted dnnType *dstData = nullptr; //where results will be putted
int id = 0; int id = 0;
bool final; //if the layer is the final one bool final; //if the layer is the final one
@@ -122,7 +122,7 @@ public:
__half *data16_d = nullptr, *bias16_d = nullptr; __half *data16_d = nullptr, *bias16_d = nullptr;
__half *bias216_h = nullptr, *bias216_d = nullptr; __half *bias216_h = nullptr, *bias216_d = nullptr;
__half *power16_h = nullptr; __half *power16_h = nullptr, *power16_d = nullptr;
__half *scales16_h = nullptr, *scales16_d = nullptr; __half *scales16_h = nullptr, *scales16_d = nullptr;
__half *mean16_h = nullptr, *mean16_d = nullptr; __half *mean16_h = nullptr, *mean16_d = nullptr;
__half *variance16_h = nullptr, *variance16_d = nullptr; __half *variance16_h = nullptr, *variance16_d = nullptr;
@@ -164,6 +164,7 @@ public:
if( scales16_d != nullptr) { cudaFree( scales16_d); scales16_d = nullptr; } if( scales16_d != nullptr) { cudaFree( scales16_d); scales16_d = nullptr; }
if( mean16_d != nullptr) { cudaFree( mean16_d); mean16_d = nullptr; } if( mean16_d != nullptr) { cudaFree( mean16_d); mean16_d = nullptr; }
if(variance16_d != nullptr) { cudaFree(variance16_d); variance16_d = nullptr; } if(variance16_d != nullptr) { cudaFree(variance16_d); variance16_d = nullptr; }
if( power16_d != nullptr) { cudaFree( power16_d); power16_d = nullptr; }
} }
} }
}; };
+1
View File
@@ -116,5 +116,6 @@ void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData,
dnnType* add_vector, int dim, dnnType mul); dnnType* add_vector, int dim, dnnType mul);
void getMemUsage(double& vm_usage_kb, double& resident_set_kb); void getMemUsage(double& vm_usage_kb, double& resident_set_kb);
void printCudaMemUsage();
void removePathAndExtension(const std::string &full_string, std::string &name); void removePathAndExtension(const std::string &full_string, std::string &name);
#endif //UTILS_H #endif //UTILS_H
+5
View File
@@ -24,6 +24,11 @@ Layer::~Layer() {
checkCUDNN( cudnnDestroyTensorDescriptor(srcTensorDesc) ); checkCUDNN( cudnnDestroyTensorDescriptor(srcTensorDesc) );
checkCUDNN( cudnnDestroyTensorDescriptor(dstTensorDesc) ); 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]; variance16_h = new __half[b_size];
scales16_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(&mean16_d, b_size*sizeof(__half));
cudaMalloc(&variance16_d, b_size*sizeof(__half)); cudaMalloc(&variance16_d, b_size*sizeof(__half));
cudaMalloc(&scales16_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 //init power array of ones
cudaMemcpy(tmp_d, power_h, b_size*sizeof(float), cudaMemcpyHostToDevice); cudaMemcpy(tmp_d, power_h, b_size*sizeof(float), cudaMemcpyHostToDevice);
//float2half(tmp_d, power16_d, b_size); float2half(tmp_d, power16_d, b_size);
//cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
//mean array //mean array
cudaMemcpy(tmp_d, mean_h, b_size*sizeof(float), cudaMemcpyHostToDevice); cudaMemcpy(tmp_d, mean_h, b_size*sizeof(float), cudaMemcpyHostToDevice);
+1
View File
@@ -128,6 +128,7 @@ void Network::print() {
} }
printCenteredTitle("", '=', 60); printCenteredTitle("", '=', 60);
std::cout<<"\n"; std::cout<<"\n";
printCudaMemUsage();
} }
const char *Network::getNetworkRTName(const char *network_name){ const char *Network::getNetworkRTName(const char *network_name){
networkName = network_name; networkName = network_name;
+1
View File
@@ -134,6 +134,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
networkRT->markOutput(*input); networkRT->markOutput(*input);
std::cout<<"Selected maxBatchSize: "<<builderRT->getMaxBatchSize()<<"\n"; std::cout<<"Selected maxBatchSize: "<<builderRT->getMaxBatchSize()<<"\n";
printCudaMemUsage();
std::cout<<"Building tensorRT cuda engine...\n"; std::cout<<"Building tensorRT cuda engine...\n";
#if NV_TENSORRT_MAJOR >= 6 #if NV_TENSORRT_MAJOR >= 6
engineRT = builderRT->buildEngineWithConfig(*networkRT, *configRT); 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; 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){ void removePathAndExtension(const std::string &full_string, std::string &name){
name = full_string; name = full_string;
std::string tmp_str = full_string; std::string tmp_str = full_string;