I have done some programs with thrust, specially remove_if
function with no problem.
However instead of simple types I would like to use arrays of pre-defined classes. (For example opencv’s cv::KeyPoint
) However my code is not building.
This is not my final code or how I want to do it in the end (in the end I want to process in the device not the host) but is very basic yet still failing.
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
//#include <thrust/copy.h>
#include <thrust/remove.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/cudaarithm.hpp>
#include <iostream>
struct is_zero
{
__host__ __device__
bool operator()(const cv::KeyPoint x)
{
return x.response == 0.0;
}
};
int main(void){
cv::KeyPoint h_data[5];
h_data[0]= cv::KeyPoint(cv::Point2f(3,4),0.3);
h_data[1]= cv::KeyPoint(cv::Point2f(2,6),0.3);
h_data[2]= cv::KeyPoint(cv::Point2f(1,1),0.3);
h_data[3]= cv::KeyPoint(cv::Point2f(2,8),0.3);
h_data[4]= cv::KeyPoint(cv::Point2f(2,6),0.3);
h_data[0].response=0.3;
h_data[1].response=0.0;
h_data[2].response=0.5;
h_data[3].response=0.0;
h_data[4].response=0.6;
cv::KeyPoint *new_data_end = thrust::remove_if(h_data, h_data + 5, is_zero()); //this does not work
}
When I try to build this I get
/usr/local/cuda/include/thrust/system/cuda/detail/par.h(141): warning: calling a __host__ function("cv::Point_<float> ::Point_") from a __host__ __device__ function("cv::KeyPoint::KeyPoint") is not allowed
/usr/local/cuda/include/thrust/system/cuda/detail/par.h(141): warning: calling a __host__ function("cv::Point_<float> ::Point_") from a __host__ __device__ function("cv::KeyPoint::KeyPoint [subobject]") is not allowed
/usr/local/cuda/include/thrust/system/cuda/detail/par.h(141): warning: calling a __host__ function("cv::Point_<float> ::operator =") from a __host__ __device__ function("cv::KeyPoint::operator =") is not allowed
What am I doing wrong and what is the correct way to do this.
(take into account that in the end I would like to do this not for an array in host memory but for one in device memory)