Hi!I have been trying to accelerate my program which uses OpenCV and PCL libraries.And the code is as follows:
#include <iostream>
#include <string>
using namespace std;
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "/usr/include/pcl-1.7/pcl/io/pcd_io.h"
#include "/usr/include/pcl-1.7/pcl/point_types.h"
#include <openacc.h>
typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud<PointT> PointCloud;
const double camera_factor = 1000;
const double camera_cx = 325.5;
const double camera_cy = 253.5;
const double camera_fx = 518.0;
const double camera_fy = 519.0;
int main( int argc, char** argv )
{
cv::Mat rgb, depth;
rgb = cv::imread( "./data/rgb.png" );
depth = cv::imread( "./data/depth.png", -1 );
PointCloud::Ptr cloud ( new PointCloud );
#pragma acc enter data copyin(rgb,depth)
#pragma acc loop
for (int m = 0; m < depth.rows; m++)
for (int n=0; n < depth.cols; n++)
{
ushort d = depth.ptr<ushort>(m)[n];
if (d == 0)
continue;
PointT p;
p.z = double(d) / camera_factor;
p.x = (n - camera_cx) * p.z / camera_fx;
p.y = (m - camera_cy) * p.z / camera_fy;
p.b = rgb.ptr<uchar>(m)[n*3];
p.g = rgb.ptr<uchar>(m)[n*3+1];
p.r = rgb.ptr<uchar>(m)[n*3+2];
cloud->points.push_back( p );
}
cloud->height = 1;
cloud->width = cloud->points.size();
cloud->is_dense = false;
pcl::io::savePCDFile( "./data/pointcloud.pcd", *cloud );
cloud->points.clear();
return 0;
}
When I add “#pragma acc loop” and compile it,it shows that:
PGCC-S-1000-Call in OpenACC region to procedure '_ZSt20__throw_length_errorPKc' which has no acc routine information (generatePointCloud.cpp: 1340)
std::vector<pcl::PointXYZRGBA, Eigen::aligned_allocator_indirection<pcl::PointXYZRGBA>>::_M_check_len(unsigned long, const char *) const:
5, include "core.hpp"
49, include "types_c.h"
58, include "float.h"
1896, include "core.hpp"
58, include "cstddef"
23, include "core.hpp"
63, include "vector"
64, include "stl_vector.h"
1340, Generating implicit acc routine seq
1342, Accelerator restriction: call to '_ZSt20__throw_length_errorPKc' with no acc routine information
69, include "vector.tcc"
PGCC/x86 Linux 15.10-0: compilation completed with severe errors
[/b]
When I replace the directive with"#pragma acc parallel loop",it shows:
1, include "iostream"
39, include "ostream"
38, include "ios"
42, include "ios_base.h"
41, include "locale_classes.h"
40, include "string"
41, include "allocator.h"
46, include "c++allocator.h"
33, include "new_allocator.h"
33, include "new"
118, Generating implicit acc routine seq
PGCC-S-0155-Procedures called in a compute region must have acc routine information: __assert_fail (generatePointCloud.cpp: 653)
PGCC-S-0155-Accelerator region ignored; see -Minfo messages (generatePointCloud.cpp: 28)
main:
28, Accelerator region ignored
31, Accelerator restriction: size of the GPU copy of rgbdata,depthdata is unknown
653, Accelerator restriction: call to '__assert_fail' with no acc routine information
PGCC/x86 Linux 15.10-0: compilation completed with severe errors
[/b]
Then I add the following directive to copy rgbdata and depthdata to GPU.
#pragma acc enter data copyin(rgb,depth,camera_factor,camera_fx,camera_fy)
#pragma acc loop
but it still shows:
PGCC-S-1000-Call in OpenACC region to procedure '_ZSt20__throw_length_errorPKc' which has no acc routine information (generatePointCloud.cpp: 1340)
std::vector<pcl::PointXYZRGBA, Eigen::aligned_allocator_indirection<pcl::PointXYZRGBA>>::_M_check_len(unsigned long, const char *) const:
5, include "core.hpp"
49, include "types_c.h"
58, include "float.h"
1896, include "core.hpp"
58, include "cstddef"
23, include "core.hpp"
63, include "vector"
64, include "stl_vector.h"
1340, Generating implicit acc routine seq
1342, Accelerator restriction: call to '_ZSt20__throw_length_errorPKc' with no acc routine information
69, include "vector.tcc"
PGCC/x86 Linux 15.10-0: compilation completed with severe errors
[/b]
Because my program has to use the libraries OpenCV and PCL,I don’t know if the problem resulted from the libraries?I have been struggling with this problem for a long time,hope you can help me,thanks![/quote]