flann-lib / flann

Fast Library for Approximate Nearest Neighbors
http://people.cs.ubc.ca/~mariusm/flann
Other
2.21k stars 646 forks source link

flann_cuda_tests are failing #501

Open bialasjaroslaw opened 1 year ago

bialasjaroslaw commented 1 year ago

I was able to compile flann with CUDA support (I have just adjusted supported architectures to allow more than just sm_13), however tests are showing that something is not right:

[ RUN ] Flann_3D.TestRadiusSearch Reading test data...done Building kd-tree index...done (0.009155 seconds) Radius search, r=0.02...done (0.000262 seconds) verifying results.../home/jbialas/flann/src/flann-1.9.2/test/flann_cuda_test.cu:471: Failure Value of: std::find( indices[i].begin(), indices[i].end(), j )!=indices[i].end() Actual: false Expected: true

Other tests for CUDA are also failing

[ RUN ] Flann_3D_Random_Cloud.Test4NN creating random point cloud (10000 points)...done Building linear index...done (1e-06 seconds) Searching KNN...done (0.376761 seconds) Building kd-tree index...done (0.002738 seconds) Searching KNN...done (8.1e-05 seconds) /home/jbialas/flann/src/flann-1.9.2/test/flann_cuda_test.cu:273: Failure Expected: (precision) >= (0.99), actual: 0.2515 vs 0.99 Precision: 0.2515

I am using GCC 11.3.0 with CUDA 11.8. I will be happy to provide more information or add some contribution to this project if it will make it better.

sl1pkn07 commented 1 year ago

works for me

9/14 Testing: test_flann_cuda_test
9/14 Test: test_flann_cuda_test
Command: "/tmp/makepkg/sl1-flann-git/src/flann/test/flann_cuda_test" "--gtest_print_time"
Directory: /tmp/makepkg/sl1-flann-git/src/flann/test
"test_flann_cuda_test" start time: Dec 04 19:59 CET
Output:
----------------------------------------------------------
[==========] Running 8 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 3 tests from Flann_3D
[ RUN      ] Flann_3D.KDTreeSingleTest
Reading test data...done
Building kd-tree index...done (0.025287 seconds)
Searching KNN...done (0.093774 seconds)
Precision: 0.99932
[       OK ] Flann_3D.KDTreeSingleTest (124 ms)
[ RUN      ] Flann_3D.KDTreeCudaTest
Reading test data...done
Building kd-tree index...done (0.195708 seconds)
Searching KNN...done (0.001429 seconds)
Precision: 0.999533
[       OK ] Flann_3D.KDTreeCudaTest (223 ms)
[ RUN      ] Flann_3D.TestRadiusSearch
Reading test data...done
Building kd-tree index...done (0.010752 seconds)
Radius search, r=0.02...done (0.003288 seconds)
verifying results...done (25.3627 seconds)
Radius search, r=0.01done (0.004685 seconds)
verifying results...done (18.3533 seconds)
[       OK ] Flann_3D.TestRadiusSearch (43779 ms)
[----------] 3 tests from Flann_3D (44127 ms total)

[----------] 5 tests from Flann_3D_Random_Cloud
[ RUN      ] Flann_3D_Random_Cloud.Test1NN
creating random point cloud (10000 points)...done
Building linear index...done (2e-06 seconds)
Searching KNN...done (0.671411 seconds)
Building kd-tree index...done (0.014269 seconds)
Searching KNN...done (0.000618 seconds)
Precision: 1
[       OK ] Flann_3D_Random_Cloud.Test1NN (687 ms)
[ RUN      ] Flann_3D_Random_Cloud.Test4NN
creating random point cloud (10000 points)...done
Building linear index...done (2e-06 seconds)
Searching KNN...done (0.671176 seconds)
Building kd-tree index...done (0.002894 seconds)
Searching KNN...done (0.001042 seconds)
Precision: 1
[       OK ] Flann_3D_Random_Cloud.Test4NN (676 ms)
[ RUN      ] Flann_3D_Random_Cloud.Test4NNGpuBuffers
creating random point cloud (10000 points)...done
Building linear index...done (1e-06 seconds)
Searching KNN...done (0.671012 seconds)
Building kd-tree index...done (0.002529 seconds)
Searching KNN...done (0.000515 seconds)
Precision: 1
[       OK ] Flann_3D_Random_Cloud.Test4NNGpuBuffers (676 ms)
[ RUN      ] Flann_3D_Random_Cloud.TestRadiusSearchVector
creating random point cloud (10000 points)...done
Building linear index...done (2e-06 seconds)
Searching KNN...done (0.670912 seconds)
Building kd-tree index...done (0.003093 seconds)
Radius search, r=0.1done (0.007789 seconds)verifying results...done (1.67853 seconds)
Radius search, r=0.05done (0.002025 seconds)verifying results...done (0.727867 seconds)
[       OK ] Flann_3D_Random_Cloud.TestRadiusSearchVector (3094 ms)
[ RUN      ] Flann_3D_Random_Cloud.TestRadiusSearchMatrix
creating random point cloud (10000 points)...done
Building linear index...done (1e-06 seconds)
Searching KNN...done (0.670765 seconds)
Building kd-tree index...done (0.003136 seconds)
counting neighbors...done (0.000331 seconds)Radius search, r=0.05done (0.001059 seconds)verifying results...done (1.14978 seconds)
[       OK ] Flann_3D_Random_Cloud.TestRadiusSearchMatrix (1827 ms)
[----------] 5 tests from Flann_3D_Random_Cloud (6963 ms total)

[----------] Global test environment tear-down
[==========] 8 tests from 2 test suites ran. (51090 ms total)
[  PASSED  ] 8 tests.
<end of output>
Test time =  51.13 sec
----------------------------------------------------------
Test Passed.
"test_flann_cuda_test" end time: Dec 04 20:00 CET
"test_flann_cuda_test" time elapsed: 00:00:51
----------------------------------------------------------
Chang-Che-Kuei commented 1 year ago

Hello, I have trouble building flann with CUDA on Windows. I build flann 1.9.1 from source with CUDA 11.1. I encounter the error when importing the file kdtree_cuda_3d_index.h and the error is identifier "FLANN_INDEX_KDTREE_CUDA" is undefined . I have tested the CPU kd-tree and it works well. It seems to me that the error comes from FLANN_USE_CUDA which is never defined, so make the following defines.h codes inactive :

#ifdef FLANN_USE_CUDA  
   FLANN_INDEX_KDTREE_CUDA  = 7,

The snapshot of my cmake-gui (I don't need hdf5 and gtest). I use VS19 to compile flann in Debug and Release modes. image

Are there any suspicious operation errors during the building?

Chang-Che-Kuei commented 1 year ago

I found I have to add #define FLANN_USE_CUDA at the top of my main.cu file. Although I don't know why flann headers are able to read my definition in main.cu, it just works.

sl1pkn07 commented 1 year ago

uf help you. in my linux

┌─┤[$]|[sl1pkn07]|[sL1pKn07]|[/usr/include/flann]|
└───╼  grep -R CUDA
defines.h:#ifdef FLANN_USE_CUDA
defines.h:    FLANN_INDEX_KDTREE_CUDA   = 7,
util/cuda/result_set.h:#ifndef FLANN_UTIL_CUDA_RESULTSET_H
util/cuda/result_set.h:#define FLANN_UTIL_CUDA_RESULTSET_H
util/cuda/heap.h:#ifndef FLANN_UTIL_CUDA_HEAP_H
util/cuda/heap.h:#define FLANN_UTIL_CUDA_HEAP_H
util/cutil_math.h:    (float3, float4 etc.) since these are not provided as standard by CUDA.
util/cutil_math.h:#ifndef __CUDACC__
util/cutil_math.h:// host implementations of CUDA functions
algorithms/kdtree_cuda_3d_index.h:#ifndef FLANN_KDTREE_CUDA_3D_INDEX_H_
algorithms/kdtree_cuda_3d_index.h:#define FLANN_KDTREE_CUDA_3D_INDEX_H_
algorithms/kdtree_cuda_3d_index.h:        (*this)["algorithm"] = FLANN_INDEX_KDTREE_CUDA;
algorithms/all_indices.h:#ifdef FLANN_USE_CUDA
algorithms/all_indices.h:#ifdef FLANN_USE_CUDA
algorithms/all_indices.h:       case FLANN_INDEX_KDTREE_CUDA:
algorithms/kdtree_cuda_builder.h:#ifndef FLANN_CUDA_KD_TREE_BUILDER_H_
algorithms/kdtree_cuda_builder.h:#define FLANN_CUDA_KD_TREE_BUILDER_H_