You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

#include "CUDA_DataChange.cuh"
__global__ void ucharToFloat_stream(const unsigned char *input, float *output, int size)
{
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < size)
{
output[tid] = static_cast<float>(input[tid]);
}
}
__global__ void floatToUchar_stream(const float *input, unsigned char *output, int size)
{
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < size)
{
output[tid] = static_cast<unsigned char>(input[tid]);
}
}
void Cuda_ucharToFloat_stream(const unsigned char *input, float *output, int size, cudaStream_t stream)
{
int blockSize = 1024;
int numBlocks = (size + blockSize - 1) / blockSize;
ucharToFloat_stream<<<numBlocks, blockSize, 0, stream>>>(input, output, size);
}
void Cuda_FloatTouchar_stream(const float *input, unsigned char *output, int size, cudaStream_t stream)
{
int blockSize = 1024;
int numBlocks = (size + blockSize - 1) / blockSize;
floatToUchar_stream<<<numBlocks, blockSize, 0, stream>>>(input, output, size);
}