错误:不允许从 __global__ 函数调用 __host__ 函数

Sup*_*ole 1 cuda

我已经为特征点的密集采样编写了 cuda 函数,但出现错误。下面给出了我的 cuda 代码。我正在使用 cuda 7.5 工具包。

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/opencv.hpp>


using namespace cv::gpu;
using namespace cv;
using namespace std;

__global__ void densefun(std::vector<int>* d_counters,std::vector<Point2f>* d_points,int d_x_max,int d_y_max,int width, int min_distance)
{
  int i = blockDim.x * blockIdx.x + threadIdx.x;
  Point2f point = (*d_points)[i];
  int x = cvFloor(point.x);
  int y = cvFloor(point.y);
  //if(x >= d_x_max || y >= d_y_max)
      //continue;
  x /= min_distance;
  y /= min_distance;
  (*d_counters)[y*width+x]++;
}


void dense(std::vector<int>& counters,std::vector<Point2f>& points,int x_max,int y_max,int width)
{
  std::vector<int>* d_counters;
  std::vector<Point2f>* d_points;
  int min_distance=5; 
  cudaMalloc(&d_counters,counters.size());
  cudaMalloc(&d_points,points.size());
  cudaMemcpy(d_points, &points, points.size(), cudaMemcpyHostToDevice);
  densefun<<<1,points.size()>>>(d_counters,d_points,x_max,y_max,width,min_distance);
  cudaMemcpy(&counters, d_counters, counters.size(), cudaMemcpyDeviceToHost);
  cudaFree(d_counters);
  cudaFree(d_points);
}
Run Code Online (Sandbox Code Playgroud)

输出:

/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(28):错误:不允许从全局函数(“densefun”)调用宿主函数(“cv::Point_ ::Point_”)

/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(28): 错误:从全局 函数调用宿主函数("std::vector , std::allocator > > ::operator []") ("densefun") 是不允许的

/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(29)(第7栏):错误:不允许从全局函数(“densefun”)调用宿主函数(“cvFloor”)

/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(30)(第7栏):错误:不允许从全局函数(“densefun”)调用宿主函数(“cvFloor”)

/home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/denseCuda.cu(35): 错误:从全局 函数("densefun")调用宿主函数("std::vector > ::operator [] ") 是不允许

在“/tmp/tmpxft_00000c85_00000000-7_denseCuda.cpp1.ii”的编译中检测到5个错误。testVideo_generated_denseCuda.cu.o.cmake:260 处的 CMake 错误(消息):生成文件时
出错 /home/supriya/Desktop/5Dec/CalculateFV_merged_gpu_old/build/CMakeFiles/testVideo.dir//./testVideo_generated_denseCuda.cu.o

CMakeFiles/testVideo.dir/build.make:392: 目标 'CMakeFiles/testVideo.dir/./testVideo_generated_denseCuda.cu.o' 的配方失败 make[2]: * [CMakeFiles/testVideo.dir/./testVideo_generated_denseCuda.cu. o] 错误 1 ​​CMakeFiles/Makefile2:130: 目标 'CMakeFiles/testVideo.dir/all' 的配方失败 make[1]: * [CMakeFiles/testVideo.dir/all] 错误 2 Makefile:76: 目标 'all' 的配方制作失败:*** [全部] 错误 2