37 AINFO <<
"GpuDownSample plugin init success.";
44 cudaError_t err = ::cudaSuccess;
45 unsigned int flags = cudaHostAllocMapped;
46 err = cudaHostAlloc(&h_point_cloud, cloud_ptr->size() *
sizeof(
base::PointF), flags);
47 if (err != ::cudaSuccess) {
48 AERROR <<
"cudaHostAlloc returns failed";
50 err = cudaHostGetDevicePointer(&d_point_cloud, h_point_cloud, 0);
51 if (err != ::cudaSuccess) {
52 AERROR <<
"cudaHostGetDevicePointer returns failed";
54 for (
int i = 0; i < cloud_ptr->size(); i++) {
55 h_point_cloud[i].
x = cloud_ptr->at(i).x;
56 h_point_cloud[i].
y = cloud_ptr->at(i).y;
57 h_point_cloud[i].
z = cloud_ptr->at(i).z;
58 h_point_cloud[i].
intensity = cloud_ptr->at(i).intensity;
62 int filtered_point_count = cloud_ptr->size();
66 downsample_voxel_size_x_,
67 downsample_voxel_size_y_,
68 downsample_voxel_size_z_,
69 downsample_use_centroid)) {
70 AERROR <<
"downSample is wrong!";
72 cudaDeviceSynchronize();
75 cloud_ptr->resize(filtered_point_count);
76 for (
int i = 0; i < filtered_point_count; i++) {
77 cloud_ptr->at(i).x = h_point_cloud[i].
x;
78 cloud_ptr->at(i).y = h_point_cloud[i].
y;
79 cloud_ptr->at(i).z = h_point_cloud[i].
z;
80 cloud_ptr->at(i).intensity = h_point_cloud[i].
intensity;
82 cudaFreeHost(h_point_cloud);
86void GpuDownSample::warmUpGPU() {
87 cudaError_t err = ::cudaSuccess;
88 err = cudaSetDevice(0);
89 if (err != ::cudaSuccess) {
94 if (err != ::cudaSuccess) {
99int GpuDownSample::getNumberOfAvailableThreads() {
101 cudaGetDeviceProperties(&prop, 0);
106 if (prop.major == 2) {
107 threads = prop.maxThreadsPerBlock / 2;
108 }
else if (prop.major > 2) {
109 threads = prop.maxThreadsPerBlock;
117bool GpuDownSample::downSample(
119 int& point_cloud_size,
123 bool use_centroid_downsample) {
124 cudaError_t
err = ::cudaSuccess;
125 err = cudaSetDevice(0);
126 if (err != ::cudaSuccess) {
129 gridParameters rgd_params;
130 hashElement* d_hashTable = NULL;
131 voxel* d_voxel = NULL;
135 int threads = getNumberOfAvailableThreads();
141 point_cloud, point_cloud_size, resolution_x, resolution_y, resolution_z, rgd_params);
142 if (err != ::cudaSuccess) {
146 err = cudaMalloc(
reinterpret_cast<void**
>(&d_hashTable), point_cloud_size *
sizeof(hashElement));
147 if (err != ::cudaSuccess) {
150 err = cudaMalloc(
reinterpret_cast<void**
>(&count),
sizeof(
int));
151 if (err != ::cudaSuccess) {
154 if (use_centroid_downsample) {
155 err = cudaMalloc(
reinterpret_cast<void**
>(&d_voxel), point_cloud_size *
sizeof(voxel));
156 if (err != ::cudaSuccess) {
161 threads, point_cloud, d_hashTable, point_cloud_size, rgd_params, count);
162 if (err != ::cudaSuccess) {
166 if (!use_centroid_downsample) {
167 err = cudaMalloc(
reinterpret_cast<void**
>(&d_markers), point_cloud_size *
sizeof(
bool));
168 if (err != ::cudaSuccess) {
180 use_centroid_downsample,
182 if (err != ::cudaSuccess) {
186 if (use_centroid_downsample) {
187 int* host_count =
new int[1];
188 err = cudaMemcpy(host_count, count,
sizeof(
int), cudaMemcpyDeviceToHost);
189 if (err != ::cudaSuccess) {
192 point_cloud_size = host_count[0];
194 h_markers =
reinterpret_cast<bool*
>(malloc(point_cloud_size *
sizeof(
bool)));
195 err = cudaMemcpy(h_markers, d_markers, point_cloud_size *
sizeof(
bool), cudaMemcpyDeviceToHost);
196 if (err != ::cudaSuccess) {
200 for (
size_t i = 0; i < point_cloud_size; i++) {
202 point_cloud[valid_size] = point_cloud[i];
206 point_cloud_size = valid_size;
209 if (!use_centroid_downsample) {
213 err = cudaFree(d_hashTable);
215 if (err != ::cudaSuccess) {
218 err = cudaFree(count);
220 if (err != ::cudaSuccess) {
223 if (use_centroid_downsample) {
224 err = cudaFree(d_voxel);
226 if (err != ::cudaSuccess) {
230 err = cudaFree(d_markers);
232 if (err != ::cudaSuccess) {
bool Init(const DownSampleInitOptions &options=DownSampleInitOptions()) override
Init of GpuDownSample object
bool Process(const DownSampleOptions &options, base::PointFCloudPtr &cloud_ptr) override
filter mark area objects
cudaError_t cudaCalculateGridParams(base::PointF *d_point_cloud, int number_of_points, float resolution_X, float resolution_Y, float resolution_Z, gridParameters &out_rgd_params)
cudaError_t cudaWarmUpGPU()
cudaError_t cudaCalculateGrid(int threads, base::PointF *d_point_cloud, hashElement *d_hashTable, int number_of_points, gridParameters rgd_params, int *count)
cudaError_t cudaDownSample(int threads, base::PointF *d_point_cloud, bool *d_markers, hashElement *d_hashTable, voxel *d_voxel, int number_of_points, gridParameters rgd_params, bool use_centroid_downsample, int *count)
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
std::shared_ptr< PointFCloud > PointFCloudPtr
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
optional double downsample_voxel_size_z
optional double downsample_voxel_size_x
optional bool downsample_use_centroid
optional double downsample_voxel_size_y