Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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)1280720);

cudaMallocManaged(&h_b, sizeof(float)1280720);

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'

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

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 1010:

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

imread("sample.jpg",0); uint8_t* h_a;

uint8_t* h_a;

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

uint8_t* h_b;

cudaMallocManaged(&h_b, sizeof(float)*1280*720); cv::Mat left1(input.cols,input.rows,CV_8UC1,h_a);

cudaMallocManaged(&h_a, sizeof(uint8_t)1280720);

cudaMallocManaged(&h_b, sizeof(float)1280720);

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

h_a = (uint8_t*)input.data;

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

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

leftGPU(input.rows,input.cols,CV_8UC1,h_a);

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

floatGPU.convertTo(leftGPU,CV_8U);

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'

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

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'

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

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;
}