看我CUDA大法:
__global__ static void greyKernel(unsigned char *in, unsigned char *out)
{
const unsigned long offset = (blockIdx.x * THREAD_N + threadIdx.x);
unsigned char b = in[offset * 3];
unsigned char g = in[offset * 3 + 1];
unsigned char r = in[offset * 3 + 2];
unsigned char t = (unsigned char)(0.299f * r + 0.587f * g + 0.114f * b);
out[offset * 3] = out[offset * 3 + 1] = out[offset * 3 + 2] = t;
}
1280×800,0.41毫秒,GT200的240个流处理器真不是吃素的。
__global__ static void greyKernel(unsigned char *in, unsigned char *out)
{
const unsigned long offset = (blockIdx.x * THREAD_N + threadIdx.x);
unsigned char b = in[offset * 3];
unsigned char g = in[offset * 3 + 1];
unsigned char r = in[offset * 3 + 2];
unsigned char t = (unsigned char)(0.299f * r + 0.587f * g + 0.114f * b);
out[offset * 3] = out[offset * 3 + 1] = out[offset * 3 + 2] = t;
}
1280×800,0.41毫秒,GT200的240个流处理器真不是吃素的。