Merge pull request #24840 from fengyuentau:ocl_innerproduct

dnn (opencl): integrate bias handling in the inner product opencl kernel
This commit is contained in:
Alexander Smorkalov 2024-01-12 15:10:16 +03:00 committed by GitHub
commit 97c418ab86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 15 deletions

View File

@ -455,13 +455,6 @@ public:
ret = false; ret = false;
break; break;
} }
if (!use_half && bias && (outerSize > 1))
{
UMat biasOnesMat = UMat::ones(outerSize, 1, umat_blobs[0].type());
UMat& biases = umat_blobs[1];
cv::gemm(biasOnesMat, biases, 1, dstMat, 1, dstMat, 0);
}
} }
if (ret) return true; if (ret) return true;

View File

@ -97,15 +97,19 @@ bool OCL4DNNInnerProduct<Dtype>::Forward(const UMat& bottom,
max_image_size); max_image_size);
} }
if (use_half_ && bias_term_) if (bias_term_) {
{ if (use_half_) {
UMat biasOneMat = UMat::ones(M_, 1, CV_32F); UMat biasOneMat = UMat::ones(M_, 1, CV_32F);
UMat newbias, tmpTop; UMat newbias, tmpTop;
convertFp16(bias, newbias); convertFp16(bias, newbias);
convertFp16(top, tmpTop); convertFp16(top, tmpTop);
cv::gemm(biasOneMat, newbias, 1, tmpTop, 1, tmpTop, 0); cv::gemm(biasOneMat, newbias, 1, tmpTop, 1, tmpTop, 0);
convertFp16(tmpTop, top); convertFp16(tmpTop, top);
} else {
UMat biasOnesMat = UMat::ones(M_, 1, CV_32F);
cv::gemm(biasOnesMat, bias, 1, top, 1, top, 0);
}
} }
return ret; return ret;