Hello,
I used opencv to implement data transfer with openacc,but I got error when I compiled the code file.Please take a look at the information below:
#include <opencv2/opencv.hpp>
#include<queue>
#include <vector>
#include<random>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include<openacc.h>
using namespace std;
using namespace cv;
int main(){
cv::Mat srcImg=cv::imread("/home/usera/images/blue-mountains.jpg");
Mat grayScale(srcImg.rows, srcImg.cols, CV_8UC1, Scalar::all(0));
Mat duplicate(srcImg.rows,srcImg.cols, CV_8UC1,Scalar::all(255) );
if(!srcImg.data){
cout<<"The file is not loaded or does not exist"<<endl;
return -1;
}
for(int i = 0; i < srcImg.rows; i++) {
for(int j = 0; j < srcImg.cols; j++) {
double gray = 0.21 * srcImg.at<cv::Vec3b>(i,j)[0] +
0.72 * srcImg.at<cv::Vec3b>(i,j)[1] +
0.07 * srcImg.at<cv::Vec3b>(i,j)[2];
grayScale.at<uchar>(i,j) = (uchar) gray;
}
}
cout<<"Matrix grayScale :"<<grayScale.rows<<" "<<grayScale.cols<<endl;
int vrows=srcImg.rows;
int vcols=srcImg.cols;
cout<<"Step"<<grayScale.step<<endl;
int b[3][5];
#pragma acc parallel loop copy(b[:3][:5])
for(int i=0;i<3;i++){
#pragma acc loop
for(int j=0;j<5;j++){
b[i][j]=i+j;
}
}
cout<<"b[N-1][M-2] :"<<b[1][1]<<endl;
cout<<"b[N][M] :"<<b[2][4]<<endl;
auto *startaddress=grayScale.data;
cout<<(int)*(startaddress+1)<<endl;
cout<<(int)*(startaddress+2)<<endl;
#pragma acc parallel loop collapse(2)
for(int i=0;i<vrows;i++){
//#pragma acc loop
for(int j=0;j<vcols;j++){
duplicate.at<uchar>(i,j)=10;//grayScale.at<uchar>(i,j);
}
}
cout<<"duplicate"<<": "<<(int)grayScale.at<uchar>(23,45)<<endl;
cout<<"duplicate"<<": "<<(int)duplicate.at<uchar>(23,45)<<endl;
}
The result shows:
Matrix grayScale :810 1440
Step1440
b[N-1][M-2] :2
b[N][M] :6
194
195
duplicate lives at 0x7ffff78db5c0 size 96 partially present
Present table dump for device[1]: NVIDIA Tesla GPU 0, compute capability 8.6, threadid=1
host:0x7ffff78db610 device:0x7f1ba56fa000 size:8 presentcount:1+0 line:129 name:(null)
allocated block device:0x7f1ba56fa000 size:512 thread:1
FATAL ERROR: variable in data clause is partially present on the device: name=duplicate
I have one doubt that if there is not enough space for the gang or vectors requested by the object duplicate
Could anyone provide any hints or suggestions?
Thanks in advance.