Unable to use convertTo function in opencv gpumat when the gpumat created with cudamallocmanaged

asked 2019-07-12 07:20:05 -0500

vishnu021988 gravatar image

updated 2019-07-15 01:54:14 -0500

I created two gpumat using unified memory concept(CudaMallocManaged) of CUDA. When i try call convertTo function it got crashed, with below error,

what(): OpenCV(3.4.2) /home/visionteam/revampedtarastack/source/build/opencv-3.4.2/modules/cudev/include/opencv2/cudev/grid/detail/transform.hpp:321: error: (-217:Gpu API call) an illegal memory access was encountered in function 'call'

I tried in ubuntu18.04 with cuda 10:

Mat input = imread("sample.jpg",0);

uint8_t* h_a;

uint8_t* h_b;

cudaMallocManaged(&h_a, sizeof(uint8_t)*1280*720);

cudaMallocManaged(&h_b, sizeof(float)*1280*720);

cv::Mat left1(input.cols,input.rows,CV_8UC1,h_a);

h_a = (uint8_t*)input.data;

cv::cuda::GpuMat floatGPU(input.rows,input.cols,CV_32FC1,h_b);

cv::cuda::GpuMat leftGPU(input.rows,input.cols,CV_8UC1,h_a);

floatGPU.convertTo(leftGPU,CV_8U);

'

Expected: conversion to be success. Actual: what(): OpenCV(3.4.2) /home/visionteam/revampedtarastack/source/build/opencv-3.4.2/modules/cudev/include/opencv2/cudev/grid/detail/transform.hpp:321: error: (-217:Gpu API call) an illegal memory access was encountered in function 'call'

Edited:

I added another sample code, that too does not produce desired result, please find the sample code below, #include<iostream>

#include<cstdio>

#include<opencv2/core/core.hpp>

#include "opencv2/cudastereo.hpp"

#include "opencv2/cudaarithm.hpp"

#include<opencv2/highgui/highgui.hpp>

#include<cuda_runtime.h>

#include <sys/time.h>

#include <math.h>


using namespace cv;

int main(void)
{
  int rows = 480;
  int cols = 1280;
  float* h_a, *h_b, *h_c;


//Allocate memory for device pointers

cudaMallocManaged(&h_a, sizeof(float)*rows*cols);

cudaMallocManaged(&h_b, sizeof(float)*rows*cols);

cudaMallocManaged(&h_c, sizeof(float)*rows*cols);


//Mats (declaring them using pointers)

Mat hmat_a(Size(cols, rows), CV_32F, h_a);

hmat_a = imread("/home/vishnu/Desktop/color.png", 0);

Mat hmat_b(Size(cols, rows), CV_32F, h_b);

hmat_b = imread("/home/vishnu/Desktop/color.png", 0);

Mat hmat_c(Size(cols, rows), CV_32F, h_c);


//Gpu Mats (declaring with the same pointers!)

cuda::GpuMat dmat_a(Size(cols, rows), CV_32F, h_a);

cuda::GpuMat dmat_b(Size(cols, rows), CV_32F, h_b);

cuda::GpuMat dmat_c(Size(cols, rows), CV_32F, h_c);


cuda::multiply(dmat_a, dmat_b, dmat_c);


std::cout << hmat_c << endl;


 return 0;
}
edit retag flag offensive close merge delete