This source file includes following definitions.
- blockId
- blockSize
- threadLineId
- blockFill
- blockYota
- blockCopy
- blockTransfrom
- blockTransfrom
#pragma once
#ifndef __OPENCV_CUDEV_BLOCK_BLOCK_HPP__
#define __OPENCV_CUDEV_BLOCK_BLOCK_HPP__
#include "../common.hpp"
namespace cv { namespace cudev {
struct Block
{
__device__ __forceinline__ static uint blockId()
{
return (blockIdx.z * gridDim.y + blockIdx.y) * gridDim.x + blockIdx.x;
}
__device__ __forceinline__ static uint blockSize()
{
return blockDim.x * blockDim.y * blockDim.z;
}
__device__ __forceinline__ static uint threadLineId()
{
return (threadIdx.z * blockDim.y + threadIdx.y) * blockDim.x + threadIdx.x;
}
};
template <class It, typename T>
__device__ __forceinline__ static void blockFill(It beg, It end, const T& value)
{
uint STRIDE = Block::blockSize();
It t = beg + Block::threadLineId();
for(; t < end; t += STRIDE)
*t = value;
}
template <class OutIt, typename T>
__device__ __forceinline__ static void blockYota(OutIt beg, OutIt end, T value)
{
uint STRIDE = Block::blockSize();
uint tid = Block::threadLineId();
value += tid;
for(OutIt t = beg + tid; t < end; t += STRIDE, value += STRIDE)
*t = value;
}
template <class InIt, class OutIt>
__device__ __forceinline__ static void blockCopy(InIt beg, InIt end, OutIt out)
{
uint STRIDE = Block::blockSize();
InIt t = beg + Block::threadLineId();
OutIt o = out + (t - beg);
for(; t < end; t += STRIDE, o += STRIDE)
*o = *t;
}
template <class InIt, class OutIt, class UnOp>
__device__ __forceinline__ static void blockTransfrom(InIt beg, InIt end, OutIt out, const UnOp& op)
{
uint STRIDE = Block::blockSize();
InIt t = beg + Block::threadLineId();
OutIt o = out + (t - beg);
for(; t < end; t += STRIDE, o += STRIDE)
*o = op(*t);
}
template <class InIt1, class InIt2, class OutIt, class BinOp>
__device__ __forceinline__ static void blockTransfrom(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, const BinOp& op)
{
uint STRIDE = Block::blockSize();
InIt1 t1 = beg1 + Block::threadLineId();
InIt2 t2 = beg2 + Block::threadLineId();
OutIt o = out + (t1 - beg1);
for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, o += STRIDE)
*o = op(*t1, *t2);
}
}}
#endif