Merge commit '04bd5d7ff46270c732b76cd9656e22de930e138e' into tree
This commit is contained in:
@@ -102,13 +102,13 @@ dnnType* DeformConv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
dcnV2CudaForward(stat, handle,
|
||||
srcData, this->data_d,
|
||||
this->bias2_d, ones_d1,
|
||||
offset, mask,
|
||||
offset, mask,
|
||||
dstData, ones_d2,
|
||||
this->kernelH, this->kernelW,
|
||||
this->strideH, this->strideW,
|
||||
this->paddingH, this->paddingW,
|
||||
1, 1,
|
||||
this->deformableGroup,
|
||||
this->deformableGroup, 0, //batch_id for cudnn is set to 0 (no batch)
|
||||
preconv->input_dim.n, preconv->input_dim.c, preconv->input_dim.h, preconv->input_dim.w,
|
||||
this->output_dim.n, this->output_dim.c, this->output_dim.h, this->output_dim.w,
|
||||
chunk_dim);
|
||||
|
||||
@@ -34,6 +34,10 @@ Network::Network(dataDim_t input_dim) {
|
||||
int8 = true;
|
||||
}
|
||||
}
|
||||
maxBatchSize = 1;
|
||||
if(const char* env_p = std::getenv("TKDNN_BATCHSIZE")) {
|
||||
maxBatchSize = atoi(env_p);
|
||||
}
|
||||
if(const char* env_p = std::getenv("TKDNN_CALIB_IMG_PATH"))
|
||||
fileImgList = env_p;
|
||||
|
||||
|
||||
+22
-14
@@ -58,7 +58,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
dataDim_t dim = net->layers[0]->input_dim;
|
||||
dtRT = DataType::kFLOAT;
|
||||
|
||||
builderRT->setMaxBatchSize(1);
|
||||
builderRT->setMaxBatchSize(net->maxBatchSize);
|
||||
builderRT->setMaxWorkspaceSize(1 << 30);
|
||||
|
||||
if(net->fp16 && builderRT->platformHasFastFp16()) {
|
||||
@@ -133,6 +133,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
input->setName("out");
|
||||
networkRT->markOutput(*input);
|
||||
|
||||
std::cout<<"Selected maxBatchSize: "<<builderRT->getMaxBatchSize()<<"\n";
|
||||
std::cout<<"Building tensorRT cuda engine...\n";
|
||||
#if NV_TENSORRT_MAJOR >= 6
|
||||
engineRT = builderRT->buildEngineWithConfig(*networkRT, *configRT);
|
||||
@@ -181,9 +182,11 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
// create GPU buffers and a stream
|
||||
for(int i=0; i<engineRT->getNbBindings(); i++) {
|
||||
Dims dim = engineRT->getBindingDimensions(i);
|
||||
checkCuda(cudaMalloc(&buffersRT[i], dim.d[0]*dim.d[1]*dim.d[2]*sizeof(dnnType)));
|
||||
buffersDIM[i] = dataDim_t(1, dim.d[0], dim.d[1], dim.d[2]);
|
||||
std::cout<<"RtBuffer "<<i<<" dim: "; buffersDIM[i].print();
|
||||
checkCuda(cudaMalloc(&buffersRT[i], engineRT->getMaxBatchSize()*dim.d[0]*dim.d[1]*dim.d[2]*sizeof(dnnType)));
|
||||
}
|
||||
checkCuda(cudaMalloc(&output, output_dim.tot()*sizeof(dnnType)));
|
||||
checkCuda(cudaMalloc(&output, engineRT->getMaxBatchSize()*output_dim.tot()*sizeof(dnnType)));
|
||||
checkCuda(cudaStreamCreate(&stream));
|
||||
}
|
||||
|
||||
@@ -192,19 +195,24 @@ NetworkRT::~NetworkRT() {
|
||||
}
|
||||
|
||||
dnnType* NetworkRT::infer(dataDim_t &dim, dnnType* data) {
|
||||
int batches = dim.n;
|
||||
if(batches > getMaxBatchSize()) {
|
||||
FatalError("input batch size too large");
|
||||
}
|
||||
|
||||
checkCuda(cudaMemcpyAsync(buffersRT[buf_input_idx], data, input_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream));
|
||||
contextRT->enqueue(1, buffersRT, stream, nullptr);
|
||||
checkCuda(cudaMemcpyAsync(output, buffersRT[buf_output_idx], output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream));
|
||||
cudaStreamSynchronize(stream);
|
||||
checkCuda(cudaMemcpyAsync(buffersRT[buf_input_idx], data, batches*input_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream));
|
||||
contextRT->enqueue(batches, buffersRT, stream, nullptr);
|
||||
checkCuda(cudaMemcpyAsync(output, buffersRT[buf_output_idx], batches*output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream));
|
||||
checkCuda(cudaStreamSynchronize(stream));
|
||||
|
||||
dim = output_dim;
|
||||
dim.n = batches;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void NetworkRT::enqueue() {
|
||||
contextRT->enqueue(1, buffersRT, stream, nullptr);
|
||||
void NetworkRT::enqueue(int batchSize) {
|
||||
contextRT->enqueue(batchSize, buffersRT, stream, nullptr);
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Layer *l) {
|
||||
@@ -320,7 +328,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Conv2d *l) {
|
||||
lRT = (ILayer*) lRTconv;
|
||||
|
||||
Dims d = lRTconv->getOutput(0)->getDimensions();
|
||||
std::cout<<"DECONV: "<<d.d[0]<<" "<<d.d[1]<<" "<<d.d[2]<<" "<<d.d[3]<<"\n";
|
||||
//std::cout<<"DECONV: "<<d.d[0]<<" "<<d.d[1]<<" "<<d.d[2]<<" "<<d.d[3]<<"\n";
|
||||
}
|
||||
|
||||
checkNULL(lRT);
|
||||
@@ -527,7 +535,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Upsample *l) {
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) {
|
||||
std::cout<<"convert DEFORMABLE\n";
|
||||
//std::cout<<"convert DEFORMABLE\n";
|
||||
ILayer *preconv = convert_layer(input, l->preconv);
|
||||
checkNULL(preconv);
|
||||
|
||||
@@ -535,7 +543,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) {
|
||||
inputs[0] = input;
|
||||
inputs[1] = preconv->getOutput(0);
|
||||
|
||||
std::cout<<"New plugin DEFORMABLE\n";
|
||||
//std::cout<<"New plugin DEFORMABLE\n";
|
||||
IPlugin *plugin = new DeformableConvRT(l->chunk_dim, l->kernelH, l->kernelW, l->strideH, l->strideW, l->paddingH, l->paddingW,
|
||||
l->deformableGroup, l->input_dim.n, l->input_dim.c, l->input_dim.h, l->input_dim.w,
|
||||
l->output_dim.n, l->output_dim.c, l->output_dim.h, l->output_dim.w, l);
|
||||
@@ -562,7 +570,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) {
|
||||
Weights power{dtRT, power_b, l->outputs};
|
||||
Weights shift{dtRT, mean_b, l->outputs};
|
||||
Weights scale{dtRT, variance_b, l->outputs};
|
||||
std::cout<<lRT->getNbOutputs()<<std::endl;
|
||||
//std::cout<<lRT->getNbOutputs()<<std::endl;
|
||||
IScaleLayer *lRT2 = networkRT->addScale(*lRT->getOutput(0), ScaleMode::kCHANNEL,
|
||||
shift, scale, power);
|
||||
|
||||
@@ -622,7 +630,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
const char * buf = reinterpret_cast<const char*>(serialData);
|
||||
|
||||
std::string name(layerName);
|
||||
std::cout<<name<<std::endl;
|
||||
//std::cout<<name<<std::endl;
|
||||
|
||||
if(name.find("ActivationLeaky") == 0) {
|
||||
ActivationLeakyRT *a = new ActivationLeakyRT();
|
||||
|
||||
@@ -241,12 +241,13 @@ void dcnV2CudaForward(cublasStatus_t stat, cublasHandle_t handle,
|
||||
const int stride_h, const int stride_w,
|
||||
const int pad_h, const int pad_w,
|
||||
const int dilation_h, const int dilation_w,
|
||||
const int deformable_group,
|
||||
const int deformable_group, const int batch_id,
|
||||
const int in_n, const int in_c, const int in_h, const int in_w,
|
||||
const int out_n, const int out_c, const int out_h, const int out_w,
|
||||
const int chunk_dim, cudaStream_t stream)
|
||||
{
|
||||
// stat and handle have be moved out to preserve 2 - 6 milliseconds every 100.
|
||||
const int batch = batch_id;
|
||||
const int channels = in_c;
|
||||
const int height = in_h;
|
||||
const int width = in_w;
|
||||
@@ -265,13 +266,14 @@ void dcnV2CudaForward(cublasStatus_t stat, cublasHandle_t handle,
|
||||
stat = cublasSgemm(handle, CUBLAS_OP_T, CUBLAS_OP_N,
|
||||
n, m, k, &alpha,
|
||||
ones, k, bias, k,
|
||||
&beta, output, n);
|
||||
&beta, output + batch * out_c * out_h * out_w, n);
|
||||
if (stat != CUBLAS_STATUS_SUCCESS)
|
||||
FatalError("CUBLAS initialization failed\n");
|
||||
|
||||
modulatedDeformableIm2colCuda(stream,
|
||||
input, offset,
|
||||
mask,
|
||||
input + batch * channels * height * width,
|
||||
offset,// + b * 2 * int((float)chunk_dim / batch),
|
||||
mask,// + b * int((float)chunk_dim / batch),
|
||||
1, channels, height, width,
|
||||
height_out, width_out, deformable_group, columns);
|
||||
// modulatedDeformableIm2colCudaGeneralVersion(stream,
|
||||
@@ -290,7 +292,7 @@ void dcnV2CudaForward(cublasStatus_t stat, cublasHandle_t handle,
|
||||
stat = cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N,
|
||||
n, m, k, &alpha,
|
||||
columns, n, weight, k,
|
||||
&beta, output, n);
|
||||
&beta, output + batch * out_c * out_h * out_w, n);
|
||||
|
||||
if (stat != CUBLAS_STATUS_SUCCESS)
|
||||
FatalError("CUBLAS initialization failed\n");
|
||||
|
||||
Reference in New Issue
Block a user