release layer wgs and version update
This commit is contained in:
+52
-12
@@ -108,24 +108,64 @@ public:
|
||||
|
||||
// additional bias for DCN
|
||||
bool additional_bias;
|
||||
dnnType *bias2_h, *bias2_d;
|
||||
dnnType *bias2_h = nullptr, *bias2_d = nullptr;
|
||||
|
||||
//batchnorm
|
||||
bool batchnorm;
|
||||
dnnType *power_h;
|
||||
dnnType *scales_h, *scales_d;
|
||||
dnnType *mean_h, *mean_d;
|
||||
dnnType *variance_h, *variance_d;
|
||||
dnnType *power_h = nullptr;
|
||||
dnnType *scales_h = nullptr, *scales_d = nullptr;
|
||||
dnnType *mean_h = nullptr, *mean_d = nullptr;
|
||||
dnnType *variance_h = nullptr, *variance_d = nullptr;
|
||||
|
||||
//fp16
|
||||
__half *data16_h, *bias16_h;
|
||||
__half *data16_d, *bias16_d;
|
||||
__half *bias216_h, *bias216_d;
|
||||
__half *data16_h = nullptr, *bias16_h = nullptr;
|
||||
__half *data16_d = nullptr, *bias16_d = nullptr;
|
||||
__half *bias216_h = nullptr, *bias216_d = nullptr;
|
||||
|
||||
__half *power16_h, *power16_d;
|
||||
__half *scales16_h, *scales16_d;
|
||||
__half *mean16_h, *mean16_d;
|
||||
__half *variance16_h, *variance16_d;
|
||||
__half *power16_h = nullptr;
|
||||
__half *scales16_h = nullptr, *scales16_d = nullptr;
|
||||
__half *mean16_h = nullptr, *mean16_d = nullptr;
|
||||
__half *variance16_h = nullptr, *variance16_d = nullptr;
|
||||
|
||||
void releaseHost(bool release32 = true, bool release16 = true) {
|
||||
if(release32) {
|
||||
if( data_h != nullptr) { delete [] data_h; data_h = nullptr; }
|
||||
if( bias_h != nullptr) { delete [] bias_h; bias_h = nullptr; }
|
||||
if( bias2_h != nullptr) { delete [] bias2_h; bias2_h = nullptr; }
|
||||
if( scales_h != nullptr) { delete [] scales_h; scales_h = nullptr; }
|
||||
if( mean_h != nullptr) { delete [] mean_h; mean_h = nullptr; }
|
||||
if(variance_h != nullptr) { delete [] variance_h; variance_h = nullptr; }
|
||||
if( power_h != nullptr) { delete [] power_h; power_h = nullptr; }
|
||||
}
|
||||
if(net->fp16 && release16) {
|
||||
if( data16_h != nullptr) { delete [] data16_h; data16_h = nullptr; }
|
||||
if( bias16_h != nullptr) { delete [] bias16_h; bias16_h = nullptr; }
|
||||
if( bias216_h != nullptr) { delete [] bias216_h; bias216_h = nullptr; }
|
||||
if( scales16_h != nullptr) { delete [] scales16_h; scales16_h = nullptr; }
|
||||
if( mean16_h != nullptr) { delete [] mean16_h; mean16_h = nullptr; }
|
||||
if(variance16_h != nullptr) { delete [] variance16_h; variance16_h = nullptr; }
|
||||
if( power16_h != nullptr) { delete [] power16_h; power16_h = nullptr; }
|
||||
|
||||
}
|
||||
}
|
||||
void releaseDevice(bool release32 = true, bool release16 = true) {
|
||||
if(release32) {
|
||||
if( data_d != nullptr) { cudaFree( data_d); data_d = nullptr; }
|
||||
if( bias_d != nullptr) { cudaFree( bias_d); bias_d = nullptr; }
|
||||
if( bias2_d != nullptr) { cudaFree( bias2_d); bias2_d = nullptr; }
|
||||
if( scales_d != nullptr) { cudaFree( scales_d); scales_d = nullptr; }
|
||||
if( mean_d != nullptr) { cudaFree( mean_d); mean_d = nullptr; }
|
||||
if(variance_d != nullptr) { cudaFree(variance_d); variance_d = nullptr; }
|
||||
}
|
||||
if(net->fp16 && release16) {
|
||||
if( data16_d != nullptr) { cudaFree( data16_d); data16_d = nullptr; }
|
||||
if( bias16_d != nullptr) { cudaFree( bias16_d); bias16_d = nullptr; }
|
||||
if( bias216_d != nullptr) { cudaFree( bias216_d); bias216_d = nullptr; }
|
||||
if( scales16_d != nullptr) { cudaFree( scales16_d); scales16_d = nullptr; }
|
||||
if( mean16_d != nullptr) { cudaFree( mean16_d); mean16_d = nullptr; }
|
||||
if(variance16_d != nullptr) { cudaFree(variance16_d); variance16_d = nullptr; }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
#include "Layer.h"
|
||||
#include "NetworkRT.h"
|
||||
|
||||
#define TKDNN_VERSION 400
|
||||
#define TKDNN_VERSION 500
|
||||
|
||||
+7
-18
@@ -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,11 +91,10 @@ 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);
|
||||
float2half(tmp_d, mean16_d, b_size);
|
||||
cudaMemcpy(mean16_h, mean16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
@@ -109,24 +108,14 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs,
|
||||
//conver scales
|
||||
float2half(scales_d, scales16_d, b_size);
|
||||
cudaMemcpy(scales16_h, scales16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
|
||||
cudaFree(tmp_d);
|
||||
}
|
||||
}
|
||||
|
||||
LayerWgs::~LayerWgs() {
|
||||
|
||||
delete [] data_h;
|
||||
delete [] bias_h;
|
||||
checkCuda( cudaFree(data_d) );
|
||||
checkCuda( cudaFree(bias_d) );
|
||||
|
||||
if(batchnorm) {
|
||||
delete [] scales_h;
|
||||
delete [] mean_h;
|
||||
delete [] variance_h;
|
||||
checkCuda( cudaFree(scales_d) );
|
||||
checkCuda( cudaFree(mean_d) );
|
||||
checkCuda( cudaFree(variance_d) );
|
||||
}
|
||||
releaseHost();
|
||||
releaseDevice();
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user