optimized gpumat::setTo()

pull/13383/head
Andrey Morozov 15 years ago
parent 12dc52c2e7
commit 290c967b8f
  1. 56
      modules/gpu/src/cuda/matrix_operations.cu

@ -77,6 +77,58 @@ namespace mat_operators
////////////////////////////////// SetTo ////////////////////////////////// ////////////////////////////////// SetTo //////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
template <typename T>
class shift_and_sizeof;
template <>
class shift_and_sizeof<char>
{
public:
enum { shift = 0 };
};
template <>
class shift_and_sizeof<unsigned char>
{
public:
enum { shift = 0 };
};
template <>
class shift_and_sizeof<short>
{
public:
enum { shift = 1 };
};
template <>
class shift_and_sizeof<unsigned short>
{
public:
enum { shift = 1 };
};
template <>
class shift_and_sizeof<int>
{
public:
enum { shift = 2 };
};
template <>
class shift_and_sizeof<float>
{
public:
enum { shift = 2 };
};
template <>
class shift_and_sizeof<double>
{
public:
enum { shift = 3 };
};
template<typename T> template<typename T>
__global__ void kernel_set_to_without_mask(T * mat, int cols, int rows, int step, int channels) __global__ void kernel_set_to_without_mask(T * mat, int cols, int rows, int step, int channels)
{ {
@ -85,7 +137,7 @@ namespace mat_operators
if ((x < cols * channels ) && (y < rows)) if ((x < cols * channels ) && (y < rows))
{ {
size_t idx = y * (step / sizeof(T)) + x; size_t idx = y * ( step >> shift_and_sizeof<T>::shift ) + x;
mat[idx] = scalar_d[ x % channels ]; mat[idx] = scalar_d[ x % channels ];
} }
} }
@ -99,7 +151,7 @@ namespace mat_operators
if ((x < cols * channels ) && (y < rows)) if ((x < cols * channels ) && (y < rows))
if (mask[y * step_mask + x / channels] != 0) if (mask[y * step_mask + x / channels] != 0)
{ {
size_t idx = y * (step / sizeof(T)) + x; size_t idx = y * ( step >> shift_and_sizeof<T>::shift ) + x;
mat[idx] = scalar_d[ x % channels ]; mat[idx] = scalar_d[ x % channels ];
} }
} }

Loading…
Cancel
Save