This source file includes following definitions.
- copy
- copy
- copy
- copy
- copy_tuple
- copy_tuple
#pragma once
#ifndef __OPENCV_CUDEV_GRID_COPY_DETAIL_HPP__
#define __OPENCV_CUDEV_GRID_COPY_DETAIL_HPP__
#include "../../common.hpp"
#include "../../util/tuple.hpp"
#include "../../util/saturate_cast.hpp"
#include "../../ptr2d/glob.hpp"
#include "../../ptr2d/traits.hpp"
namespace cv { namespace cudev {
namespace grid_copy_detail
{
template <class SrcPtr, typename DstType, class MaskPtr>
__global__ void copy(const SrcPtr src, GlobPtr<DstType> dst, const MaskPtr mask, const int rows, const int cols)
{
const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y;
if (x >= cols || y >= rows || !mask(y, x))
return;
dst(y, x) = saturate_cast<DstType>(src(y, x));
}
template <class Policy, class SrcPtr, typename DstType, class MaskPtr>
__host__ void copy(const SrcPtr& src, const GlobPtr<DstType>& dst, const MaskPtr& mask, int rows, int cols, cudaStream_t stream)
{
const dim3 block(Policy::block_size_x, Policy::block_size_y);
const dim3 grid(divUp(cols, block.x), divUp(rows, block.y));
copy<<<grid, block, 0, stream>>>(src, dst, mask, rows, cols);
CV_CUDEV_SAFE_CALL( cudaGetLastError() );
if (stream == 0)
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
}
template <int count> struct Unroll
{
template <class SrcPtrTuple, class DstPtrTuple>
__device__ static void copy(const SrcPtrTuple& src, DstPtrTuple& dst, const int y, const int x)
{
typedef typename tuple_element<count - 1, DstPtrTuple>::type dst_ptr_type;
typedef typename PtrTraits<dst_ptr_type>::value_type dst_type;
get<count - 1>(dst)(y, x) = saturate_cast<dst_type>(get<count - 1>(src)(y, x));
Unroll<count - 1>::copy(src, dst, y, x);
}
};
template <> struct Unroll<0>
{
template <class SrcPtrTuple, class DstPtrTuple>
__device__ __forceinline__ static void copy(const SrcPtrTuple&, DstPtrTuple&, const int, const int)
{
}
};
template <class SrcPtrTuple, class DstPtrTuple, class MaskPtr>
__global__ void copy_tuple(const SrcPtrTuple src, DstPtrTuple dst, const MaskPtr mask, const int rows, const int cols)
{
const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y;
if (x >= cols || y >= rows || !mask(y, x))
return;
Unroll<tuple_size<SrcPtrTuple>::value>::copy(src, dst, y, x);
}
template <class Policy, class SrcPtrTuple, class DstPtrTuple, class MaskPtr>
__host__ void copy_tuple(const SrcPtrTuple& src, const DstPtrTuple& dst, const MaskPtr& mask, int rows, int cols, cudaStream_t stream)
{
const dim3 block(Policy::block_size_x, Policy::block_size_y);
const dim3 grid(divUp(cols, block.x), divUp(rows, block.y));
copy_tuple<<<grid, block, 0, stream>>>(src, dst, mask, rows, cols);
CV_CUDEV_SAFE_CALL( cudaGetLastError() );
if (stream == 0)
CV_CUDEV_SAFE_CALL( cudaDeviceSynchronize() );
}
}
}}
#endif