Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
224f18b0
Commit
224f18b0
authored
Aug 27, 2013
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bitwise operation optimization
parent
eb449968
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
29 deletions
+92
-29
bitwise_mat.cu
modules/cudaarithm/src/cuda/bitwise_mat.cu
+92
-29
No files found.
modules/cudaarithm/src/cuda/bitwise_mat.cu
View file @
224f18b0
...
@@ -58,21 +58,6 @@ void bitMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& m
...
@@ -58,21 +58,6 @@ void bitMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& m
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// bitwise_not
/// bitwise_not
namespace
{
template <typename T>
void bitMatNot(const GpuMat& src, GpuMat& dst, const GpuMat& mask, Stream& stream)
{
GlobPtrSz<T> vsrc = globPtr((T*) src.data, src.step, src.rows, src.cols * src.channels());
GlobPtrSz<T> vdst = globPtr((T*) dst.data, dst.step, src.rows, src.cols * src.channels());
if (mask.data)
gridTransformUnary(vsrc, vdst, bit_not<T>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
else
gridTransformUnary(vsrc, vdst, bit_not<T>(), stream);
}
}
void cv::cuda::bitwise_not(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
void cv::cuda::bitwise_not(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
{
{
GpuMat src = _src.getGpuMat();
GpuMat src = _src.getGpuMat();
...
@@ -86,17 +71,59 @@ void cv::cuda::bitwise_not(InputArray _src, OutputArray _dst, InputArray _mask,
...
@@ -86,17 +71,59 @@ void cv::cuda::bitwise_not(InputArray _src, OutputArray _dst, InputArray _mask,
_dst.create(src.size(), src.type());
_dst.create(src.size(), src.type());
GpuMat dst = _dst.getGpuMat();
GpuMat dst = _dst.getGpuMat();
if (depth == CV_32F || depth == CV_32S)
if (mask.empty())
{
bitMatNot<uint>(src, dst, mask, stream);
}
else if (depth == CV_16S || depth == CV_16U)
{
{
bitMatNot<ushort>(src, dst, mask, stream);
const int bcols = (int) (src.cols * src.elemSize());
if ((bcols & 3) == 0)
{
const int vcols = bcols >> 2;
GlobPtrSz<uint> vsrc = globPtr((uint*) src.data, src.step, src.rows, vcols);
GlobPtrSz<uint> vdst = globPtr((uint*) dst.data, dst.step, src.rows, vcols);
gridTransformUnary(vsrc, vdst, bit_not<uint>(), stream);
}
else if ((bcols & 1) == 0)
{
const int vcols = bcols >> 1;
GlobPtrSz<ushort> vsrc = globPtr((ushort*) src.data, src.step, src.rows, vcols);
GlobPtrSz<ushort> vdst = globPtr((ushort*) dst.data, dst.step, src.rows, vcols);
gridTransformUnary(vsrc, vdst, bit_not<ushort>(), stream);
}
else
{
GlobPtrSz<uchar> vsrc = globPtr((uchar*) src.data, src.step, src.rows, bcols);
GlobPtrSz<uchar> vdst = globPtr((uchar*) dst.data, dst.step, src.rows, bcols);
gridTransformUnary(vsrc, vdst, bit_not<uchar>(), stream);
}
}
}
else
else
{
{
bitMatNot<uchar>(src, dst, mask, stream);
if (depth == CV_32F || depth == CV_32S)
{
GlobPtrSz<uint> vsrc = globPtr((uint*) src.data, src.step, src.rows, src.cols * src.channels());
GlobPtrSz<uint> vdst = globPtr((uint*) dst.data, dst.step, src.rows, src.cols * src.channels());
gridTransformUnary(vsrc, vdst, bit_not<uint>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
}
else if (depth == CV_16S || depth == CV_16U)
{
GlobPtrSz<ushort> vsrc = globPtr((ushort*) src.data, src.step, src.rows, src.cols * src.channels());
GlobPtrSz<ushort> vdst = globPtr((ushort*) dst.data, dst.step, src.rows, src.cols * src.channels());
gridTransformUnary(vsrc, vdst, bit_not<ushort>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
}
else
{
GlobPtrSz<uchar> vsrc = globPtr((uchar*) src.data, src.step, src.rows, src.cols * src.channels());
GlobPtrSz<uchar> vdst = globPtr((uchar*) dst.data, dst.step, src.rows, src.cols * src.channels());
gridTransformUnary(vsrc, vdst, bit_not<uchar>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
}
}
}
}
}
...
@@ -146,17 +173,53 @@ void bitMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& m
...
@@ -146,17 +173,53 @@ void bitMat(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& m
CV_DbgAssert( depth <= CV_32F );
CV_DbgAssert( depth <= CV_32F );
CV_DbgAssert( op >= 0 && op < 3 );
CV_DbgAssert( op >= 0 && op < 3 );
if (depth == CV_32F || depth == CV_32S)
if (mask.empty())
{
funcs32[op](src1, src2, dst, mask, stream);
}
else if (depth == CV_16S || depth == CV_16U)
{
{
funcs16[op](src1, src2, dst, mask, stream);
const int bcols = (int) (src1.cols * src1.elemSize());
if ((bcols & 3) == 0)
{
const int vcols = bcols >> 2;
GpuMat vsrc1(src1.rows, vcols, CV_32SC1, src1.data, src1.step);
GpuMat vsrc2(src1.rows, vcols, CV_32SC1, src2.data, src2.step);
GpuMat vdst(src1.rows, vcols, CV_32SC1, dst.data, dst.step);
funcs32[op](vsrc1, vsrc2, vdst, GpuMat(), stream);
}
else if ((bcols & 1) == 0)
{
const int vcols = bcols >> 1;
GpuMat vsrc1(src1.rows, vcols, CV_16UC1, src1.data, src1.step);
GpuMat vsrc2(src1.rows, vcols, CV_16UC1, src2.data, src2.step);
GpuMat vdst(src1.rows, vcols, CV_16UC1, dst.data, dst.step);
funcs16[op](vsrc1, vsrc2, vdst, GpuMat(), stream);
}
else
{
GpuMat vsrc1(src1.rows, bcols, CV_8UC1, src1.data, src1.step);
GpuMat vsrc2(src1.rows, bcols, CV_8UC1, src2.data, src2.step);
GpuMat vdst(src1.rows, bcols, CV_8UC1, dst.data, dst.step);
funcs8[op](vsrc1, vsrc2, vdst, GpuMat(), stream);
}
}
}
else
else
{
{
funcs8[op](src1, src2, dst, mask, stream);
if (depth == CV_32F || depth == CV_32S)
{
funcs32[op](src1, src2, dst, mask, stream);
}
else if (depth == CV_16S || depth == CV_16U)
{
funcs16[op](src1, src2, dst, mask, stream);
}
else
{
funcs8[op](src1, src2, dst, mask, stream);
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment