flann-lib / flann

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

Segmentation fault when I buildIndex() #362

Open xmy7216 opened 6 years ago

xmy7216 commented 6 years ago

I want to match binary features using Hamming distance. My binary features have 64*64 dimentionality. So I choose the HierarchicalClusteringIndexParams to build the index. In order to reduce the mem, I use unsigned long to storage 64bits binary features.

flann::Matrix<unsigned long> dataset(featureArr, nnindexLen, 64);
flann::Index< flann::Hamming<unsigned long> > > nnindex( dataset, flann::HierarchicalClusteringIndexParams(32, FLANN_CENTERS_KMEANSPP, 4, 100));
nnindex->buildIndex();

when nnindex->buildIndex(), I get the Segmentation fault. Why? The gdb backtrace is as follow:

#0  0x00007ffff44403b1 in _int_malloc () at /lib64/libc.so.6
#1  0x00007ffff444310c in malloc () at /lib64/libc.so.6
#2  0x00007ffff4cfd1bd in operator new(unsigned long) () at /lib64/libstdc++.so.6
#3  0x00007ffff4cfd2b9 in operator new[](unsigned long) () at /lib64/libstdc++.so.6
#4  0x0000000000406944 in flann::KMeansppCenterChooser<flann::Hamming<unsigned long> >::operator()(int, int*, int, int*, int&) (this=0x655d10, k=32, indices=0x657eb8, indices_length=211, centers=0x36589a0, centers_length=@0x7fffff7ff21c: 16843009) at /usr/local/include/flann/algorithms/center_chooser.h:169
#5  0x000000000040f154 in flann::HierarchicalClusteringIndex<flann::Hamming<unsigned long> >::computeClustering(flann::HierarchicalClusteringIndex<flann::Hamming<unsigned long> >::Node*, int*, int) (this=this@entry=0x655aa0, node=0x363afd8, indices=indices@entry=0x657eb8, indices_length=indices_length@entry=211)
    at /usr/local/include/flann/algorithms/hierarchical_clustering_index.h:487

Isn't the Hamming distance supporting the datatype unsigned long?

Thank you very much for your answer. @mariusmuja

sunsided commented 6 years ago

I had a similar problem just now. The error would only appear in CMake Release-like builds. For me, the operation failed in Hamming::operator() at the popcnt64 instruction. Building the binary with gcc's -march=native option resolved the issue for me.