CUDA version of cvMatToOpInput (#1212)

This commit is contained in:
joker3212
2019-05-06 23:56:19 -04:00
committed by Gines
parent 99fb8c5921
commit db41591327
+35 -1
View File
@@ -87,7 +87,41 @@ namespace op
// CUDA version (if #Gpus > n)
else
{
error("Not implemented yet.", __LINE__, __FUNCTION__, __FILE__);
// (Re)Allocate temporary memory
const unsigned int inputImageSize = 3 * cvInputData.rows * cvInputData.cols;
const unsigned int outputImageSize = 3 * netInputSizes[i].x * netInputSizes[i].y;
if (pInputMaxSize < inputImageSize)
{
pInputMaxSize = inputImageSize;
// Free temporary memory
cudaFree(pInputImageCuda);
cudaFree(pInputImageReorderedCuda);
// Re-allocate memory
cudaMalloc((void**)&pInputImageCuda, sizeof(unsigned char) * inputImageSize);
cudaMalloc((void**)&pInputImageReorderedCuda, sizeof(float) * inputImageSize);
}
if (pOutputMaxSize < outputImageSize)
{
pOutputMaxSize = outputImageSize;
// Free temporary memory
cudaFree(pOutputImageCuda);
// Re-allocate memory
cudaMalloc((void**)&pOutputImageCuda, sizeof(float) * outputImageSize);
}
// Copy image to GPU
cudaMemcpy(
pInputImageCuda, cvInputData.data, sizeof(unsigned char) * inputImageSize,
cudaMemcpyHostToDevice);
// Resize image on GPU
reorderAndCast(pInputImageReorderedCuda, pInputImageCuda, cvInputData.cols, cvInputData.rows, 3);
resizeAndMergeRGBGPU(
pOutputImageCuda, pInputImageReorderedCuda, cvInputData.cols, cvInputData.rows,
netInputSizes[i].x, netInputSizes[i].y, (float)scaleInputToNetInputs[i]);
// Copy back to CPU
inputNetData[i].reset({1, 3, netInputSizes.at(i).y, netInputSizes.at(i).x});
cudaMemcpy(
inputNetData[i].getPtr(), pOutputImageCuda, sizeof(float) * outputImageSize,
cudaMemcpyDeviceToHost);
}
}
return inputNetData;