Skip to content

Commit

Permalink
Merge pull request flann-lib#1 from BaltashovIlia/master
Browse files Browse the repository at this point in the history
CUDA, testing, and other fixes
  • Loading branch information
tkircher authored Jun 6, 2021
2 parents c50f296 + 6f3f392 commit 8706330
Show file tree
Hide file tree
Showing 19 changed files with 366 additions and 236 deletions.
16 changes: 1 addition & 15 deletions cmake/flann_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,4 @@ macro(flann_add_pyunit file)
# add dependency to 'test' target
add_dependencies(pyunit_${_testname} flann)
add_dependencies(test pyunit_${_testname})
endmacro(flann_add_pyunit)



macro(flann_download_test_data _name _md5)
string(REPLACE "/" "_" _dataset_name dataset_${_name})

add_custom_target(${_dataset_name}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin/download_checkmd5.py https://www.cs.ubc.ca/research/flann/uploads/FLANN/datasets/${_name} ${TEST_OUTPUT_PATH}/${_name} ${_md5}
VERBATIM)

# Also make sure that downloads are done before we run any tests
add_dependencies(tests ${_dataset_name})

endmacro(flann_download_test_data)
endmacro(flann_add_pyunit)
2 changes: 1 addition & 1 deletion src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endif()
set_property(TARGET flann_cpp_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC FLANN_USE_CUDA)

if (BUILD_CUDA_LIB)
SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-DFLANN_USE_CUDA")
SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-DFLANN_USE_CUDA;-Xcudafe \"--diag_suppress=partial_override\" ;-gencode=arch=compute_52,code=\"sm_52,compute_52\";-gencode=arch=compute_61,code=\"sm_61,compute_61\"")
if(CMAKE_COMPILER_IS_GNUCC)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xcompiler;-fPIC;" )
if (NVCC_COMPILER_BINDIR)
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/flann/algorithms/hierarchical_clustering_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
for(size_t i=0; i<childs.size(); i++){
childs[i]->~Node();
pivot = NULL;
pivot_index = -1;
pivot_index = SIZE_MAX;
}
};

Expand Down
164 changes: 93 additions & 71 deletions src/cpp/flann/algorithms/kdtree_cuda_3d_index.cu

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cpp/flann/algorithms/kdtree_cuda_3d_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class KDTreeCuda3dIndex : public NNIndex<Distance>
* params = parameters passed to the kdtree algorithm
*/
KDTreeCuda3dIndex(const Matrix<ElementType>& inputData, const IndexParams& params = KDTreeCuda3dIndexParams(),
Distance d = Distance() ) : BaseClass(params,d), dataset_(inputData), leaf_count_(0), visited_leafs(0), node_count_(0), current_node_count_(0)
Distance d = Distance() ) : BaseClass(params,d), visited_leafs(0), dataset_(inputData), leaf_count_(0), node_count_(0), current_node_count_(0)
{
size_ = dataset_.rows;
dim_ = dataset_.cols;
Expand Down
309 changes: 220 additions & 89 deletions src/cpp/flann/algorithms/kdtree_cuda_builder.h

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/cpp/flann/algorithms/nn_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class NNIndex : public IndexBase
* @param params
* @return
*/
int knnSearch(const Matrix<ElementType>& queries,
virtual int knnSearch(const Matrix<ElementType>& queries,
Matrix<int>& indices,
Matrix<DistanceType>& dists,
size_t knn,
Expand All @@ -388,7 +388,7 @@ class NNIndex : public IndexBase
* @param[in] knn Number of nearest neighbors to return
* @param[in] params Search parameters
*/
int knnSearch(const Matrix<ElementType>& queries,
virtual int knnSearch(const Matrix<ElementType>& queries,
std::vector< std::vector<size_t> >& indices,
std::vector<std::vector<DistanceType> >& dists,
size_t knn,
Expand Down Expand Up @@ -459,7 +459,7 @@ class NNIndex : public IndexBase
* @param params
* @return
*/
int knnSearch(const Matrix<ElementType>& queries,
virtual int knnSearch(const Matrix<ElementType>& queries,
std::vector< std::vector<int> >& indices,
std::vector<std::vector<DistanceType> >& dists,
size_t knn,
Expand All @@ -484,7 +484,7 @@ class NNIndex : public IndexBase
* @param[in] params Search parameters
* @return Number of neighbors found
*/
int radiusSearch(const Matrix<ElementType>& queries,
virtual int radiusSearch(const Matrix<ElementType>& queries,
Matrix<size_t>& indices,
Matrix<DistanceType>& dists,
float radius,
Expand Down Expand Up @@ -567,7 +567,7 @@ class NNIndex : public IndexBase
* @param params
* @return
*/
int radiusSearch(const Matrix<ElementType>& queries,
virtual int radiusSearch(const Matrix<ElementType>& queries,
Matrix<int>& indices,
Matrix<DistanceType>& dists,
float radius,
Expand All @@ -594,7 +594,7 @@ class NNIndex : public IndexBase
* @param[in] params Search parameters
* @return Number of neighbors found
*/
int radiusSearch(const Matrix<ElementType>& queries,
virtual int radiusSearch(const Matrix<ElementType>& queries,
std::vector< std::vector<size_t> >& indices,
std::vector<std::vector<DistanceType> >& dists,
float radius,
Expand Down Expand Up @@ -673,7 +673,7 @@ class NNIndex : public IndexBase
* @param params
* @return
*/
int radiusSearch(const Matrix<ElementType>& queries,
virtual int radiusSearch(const Matrix<ElementType>& queries,
std::vector< std::vector<int> >& indices,
std::vector<std::vector<DistanceType> >& dists,
float radius,
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/flann/util/result_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class KNNSimpleResultSet : public ResultSet<DistanceType>
capacity_(capacity_)
{
// reserving capacity to prevent memory re-allocations
dist_index_.resize(capacity_, DistIndex(std::numeric_limits<DistanceType>::max(),-1));
dist_index_.resize(capacity_, DistIndex(std::numeric_limits<DistanceType>::max(),std::numeric_limits<size_t>::max()));
clear();
}

Expand Down Expand Up @@ -210,7 +210,7 @@ class KNNResultSet : public ResultSet<DistanceType>
KNNResultSet(int capacity) : capacity_(capacity)
{
// reserving capacity to prevent memory re-allocations
dist_index_.resize(capacity_, DistIndex(std::numeric_limits<DistanceType>::max(),-1));
dist_index_.resize(capacity_, DistIndex(std::numeric_limits<DistanceType>::max(),std::numeric_limits<size_t>::max()));
clear();
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/flann/util/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ class LoadArchive : public InputArchive<LoadArchive>
// If not v1.0 format hack...
if (buffer_blocks_ != NULL) {
// Read the last '0' in the file
size_t zero = -1;
size_t zero = 1;
if (fread(&zero, sizeof(zero), 1, stream_) != 1) {
throw FLANNException("Invalid index file, cannot read from disk (end)");
}
Expand Down
23 changes: 7 additions & 16 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ add_dependencies(test tests)

set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH})

if (PYTHON_EXECUTABLE)
flann_download_test_data(sift10K.h5 0964a910946d2dd5fe28337507a8abc3)
flann_download_test_data(sift10K_byte.h5 f835e0148df4618a81f67febfda2b4d0)
flann_download_test_data(sift100K.h5 ae2b08f93f3d9f89f5d68566b0406102)
flann_download_test_data(sift100K_byte.h5 b772255fd2044e9d2a5a0183953e4705)
flann_download_test_data(cloud.h5 dfc77bad391a3ae739a9874f4a5dc0d7)
flann_download_test_data(brief100K.h5 e1e781c0955917bc2f0a27b6344c2342)
endif()

if (GTEST_FOUND AND HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIR})

Expand Down Expand Up @@ -56,7 +47,7 @@ if (GTEST_FOUND AND HDF5_FOUND)
endif()

if (GTEST_FOUND AND HDF5_FOUND AND BUILD_CUDA_LIB)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xcompiler;-fPIC;-arch=sm_13" )
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xcompiler;-fPIC;-Xcudafe \"--diag_suppress=partial_override\" ;-gencode=arch=compute_52,code=\"sm_52,compute_52\";-gencode=arch=compute_61,code=\"sm_61,compute_61\"" )
if (NVCC_COMPILER_BINDIR)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};--compiler-bindir=${NVCC_COMPILER_BINDIR}")
endif()
Expand All @@ -75,9 +66,9 @@ if (BUILD_PYTHON_BINDINGS)
endif()

#---------- ruby spec ----------------
if (BUILD_C_BINDINGS)
add_custom_target(flann_ruby_spec
COMMAND bundle exec rake spec
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/ruby)
add_dependencies(test flann_ruby_spec)
endif()
#if (BUILD_C_BINDINGS)
# add_custom_target(flann_ruby_spec
# COMMAND bundle exec rake spec
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/ruby)
# add_dependencies(test flann_ruby_spec)
#endif()
6 changes: 3 additions & 3 deletions test/flann_autotuned_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Autotuned_SIFT100K : public FLANNTestFixture {
indices = flann::Matrix<size_t>(new size_t[1000*5], 1000, 5);
printf("Reading test data...");
fflush(stdout);
flann::load_from_file(data, "sift100K.h5","dataset");
flann::load_from_file(query,"sift100K.h5","query");
flann::load_from_file(match,"sift100K.h5","match");
flann::load_from_file(data, "../datasets/sift100K.h5","dataset");
flann::load_from_file(query,"../datasets/sift100K.h5","query");
flann::load_from_file(match,"../datasets/sift100K.h5","match");
printf("done\n");
}

Expand Down
6 changes: 3 additions & 3 deletions test/flann_cuda_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ protected:
{
printf("Reading test data...");
fflush(stdout);
flann::load_from_file(data, "cloud.h5","dataset");
flann::load_from_file(query,"cloud.h5","query");
flann::load_from_file(match,"cloud.h5","indices");
flann::load_from_file(data, "../datasets/cloud.h5","dataset");
flann::load_from_file(query,"../datasets/cloud.h5","query");
flann::load_from_file(match,"../datasets/cloud.h5","match");

dists = flann::Matrix<float>(new float[query.rows*5], query.rows, 5);
indices = flann::Matrix<int>(new int[query.rows*5], query.rows, 5);
Expand Down
4 changes: 2 additions & 2 deletions test/flann_hierarchical_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class HierarchicalIndex_Brief100K : public FLANNTestFixture
k_nn_ = 3;
printf("Reading test data...");
fflush(stdout);
flann::load_from_file(data, "brief100K.h5", "dataset");
flann::load_from_file(query, "brief100K.h5", "query");
flann::load_from_file(data, "../datasets/brief100K.h5", "dataset");
flann::load_from_file(query, "../datasets/brief100K.h5", "query");
printf("done\n");

flann::Index<Distance> index(data, flann::LinearIndexParams());
Expand Down
4 changes: 2 additions & 2 deletions test/flann_kdtree_single_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace flann;

class KDTreeSingle :public DatasetTestFixture<float, float> {
protected:
KDTreeSingle() : DatasetTestFixture("cloud.h5") {}
KDTreeSingle() : DatasetTestFixture("../datasets/cloud.h5") {}
};

TEST_F(KDTreeSingle, TestSearch)
Expand All @@ -29,7 +29,7 @@ TEST_F(KDTreeSingle, TestSearch2)
TEST_F(KDTreeSingle, TestSearchPadded)
{
flann::Matrix<float> data_padded;
flann::load_from_file(data_padded, "cloud.h5", "dataset_padded");
flann::load_from_file(data_padded, "../datasets/cloud.h5", "dataset_padded");
flann::Matrix<float> data2(data_padded.ptr(), data_padded.rows, 3, data_padded.cols*sizeof(float));

TestSearch<L2_Simple<float> >(data2, flann::KDTreeSingleIndexParams(12, false),
Expand Down
8 changes: 4 additions & 4 deletions test/flann_kdtree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace flann;
*/
class KDTree_SIFT10K : public DatasetTestFixture<float, float> {
protected:
KDTree_SIFT10K() : DatasetTestFixture("sift10K.h5") {}
KDTree_SIFT10K() : DatasetTestFixture("../datasets/sift10K.h5") {}
};

TEST_F(KDTree_SIFT10K, TestSearch)
Expand Down Expand Up @@ -72,7 +72,7 @@ TEST_F(KDTree_SIFT10K, TestCopy2)
*/
class KDTree_SIFT100K : public DatasetTestFixture<float, float> {
protected:
KDTree_SIFT100K() : DatasetTestFixture("sift100K.h5") {}
KDTree_SIFT100K() : DatasetTestFixture("../datasets/sift100K.h5") {}
};


Expand Down Expand Up @@ -110,7 +110,7 @@ TEST_F(KDTree_SIFT100K, TestRemove)
*/
class KDTree_SIFT10K_byte : public DatasetTestFixture<unsigned char, float> {
protected:
KDTree_SIFT10K_byte() : DatasetTestFixture("sift10K_byte.h5") {}
KDTree_SIFT10K_byte() : DatasetTestFixture("../datasets/sift10K_byte.h5") {}
};


Expand All @@ -123,7 +123,7 @@ TEST_F(KDTree_SIFT10K_byte, TestSearch)

class KDTree_SIFT100K_byte : public DatasetTestFixture<unsigned char, float> {
protected:
KDTree_SIFT100K_byte() : DatasetTestFixture("sift100K_byte.h5") {}
KDTree_SIFT100K_byte() : DatasetTestFixture("../datasets/sift100K_byte.h5") {}
};


Expand Down
8 changes: 4 additions & 4 deletions test/flann_kmeans_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace flann;
*/
class KMeans_SIFT10K : public DatasetTestFixture<float, float> {
protected:
KMeans_SIFT10K() : DatasetTestFixture("sift10K.h5") {}
KMeans_SIFT10K() : DatasetTestFixture("../datasets/sift10K.h5") {}
};


Expand Down Expand Up @@ -77,7 +77,7 @@ TEST_F(KMeans_SIFT10K, TestCopy2)
*/
class KMeans_SIFT100K : public DatasetTestFixture<float, float> {
protected:
KMeans_SIFT100K() : DatasetTestFixture("sift100K.h5") {}
KMeans_SIFT100K() : DatasetTestFixture("../datasets/sift100K.h5") {}
};


Expand Down Expand Up @@ -120,7 +120,7 @@ TEST_F(KMeans_SIFT100K, TestSave)
*/
class KMeans_SIFT10K_byte : public DatasetTestFixture<unsigned char, float> {
protected:
KMeans_SIFT10K_byte() : DatasetTestFixture("sift10K_byte.h5") {}
KMeans_SIFT10K_byte() : DatasetTestFixture("../datasets/sift10K_byte.h5") {}
};

TEST_F(KMeans_SIFT10K_byte, TestSearch)
Expand All @@ -133,7 +133,7 @@ TEST_F(KMeans_SIFT10K_byte, TestSearch)

class KMeans_SIFT100K_byte : public DatasetTestFixture<unsigned char, float> {
protected:
KMeans_SIFT100K_byte() : DatasetTestFixture("sift100K_byte.h5") {}
KMeans_SIFT100K_byte() : DatasetTestFixture("../datasets/sift100K_byte.h5") {}
};

TEST_F(KMeans_SIFT100K_byte, TestSearch)
Expand Down
8 changes: 4 additions & 4 deletions test/flann_linear_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace flann;
*/
class Linear_SIFT10K : public DatasetTestFixture<float, float> {
protected:
Linear_SIFT10K() : DatasetTestFixture("sift10K.h5") {}
Linear_SIFT10K() : DatasetTestFixture("../datasets/sift10K.h5") {}
};


Expand Down Expand Up @@ -61,7 +61,7 @@ TEST_F(Linear_SIFT10K, TestCopy2)
*/
class Linear_SIFT100K : public DatasetTestFixture<float, float> {
protected:
Linear_SIFT100K() : DatasetTestFixture("sift100K.h5") {}
Linear_SIFT100K() : DatasetTestFixture("../datasets/sift100K.h5") {}
};


Expand All @@ -77,7 +77,7 @@ TEST_F(Linear_SIFT100K, TestSearch)
*/
class Linear_SIFT10K_byte : public DatasetTestFixture<unsigned char, float> {
protected:
Linear_SIFT10K_byte() : DatasetTestFixture("sift10K_byte.h5") {}
Linear_SIFT10K_byte() : DatasetTestFixture("../datasets/sift10K_byte.h5") {}
};


Expand All @@ -93,7 +93,7 @@ TEST_F(Linear_SIFT10K_byte, Linear)

class Linear_SIFT100K_byte : public DatasetTestFixture<unsigned char, float> {
protected:
Linear_SIFT100K_byte() : DatasetTestFixture("sift100K_byte.h5") {}
Linear_SIFT100K_byte() : DatasetTestFixture("../datasets/sift100K_byte.h5") {}
};


Expand Down
6 changes: 3 additions & 3 deletions test/flann_lsh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class LshIndex_Brief100K : public FLANNTestFixture
k_nn_ = 3;
printf("Reading test data...");
fflush(stdout);
flann::load_from_file(data, "brief100K.h5", "dataset");
flann::load_from_file(query, "brief100K.h5", "query");
flann::load_from_file(data, "../datasets/brief100K.h5", "dataset");
flann::load_from_file(query, "../datasets/brief100K.h5", "query");

dists = flann::Matrix<DistanceType>(new DistanceType[query.rows * k_nn_], query.rows, k_nn_);
indices = flann::Matrix<size_t>(new size_t[query.rows * k_nn_], query.rows, k_nn_);

printf("done\n");

// The matches are bogus so we compute them the hard way
// flann::load_from_file(match,"brief100K.h5","indices");
// flann::load_from_file(match,"../datasets/brief100K.h5","indices");

flann::Index<Distance> index(data, flann::LinearIndexParams());
index.buildIndex();
Expand Down
14 changes: 7 additions & 7 deletions test/flann_multithreaded_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class FlannTest : public FLANNTestFixture {

printf("Reading test data...");
fflush(stdout);
flann::load_from_file(data_, "cloud.h5","dataset");
flann::load_from_file(query_,"cloud.h5","query");
flann::load_from_file(match_,"cloud.h5","match");
flann::load_from_file(data_, "../datasets/cloud.h5","dataset");
flann::load_from_file(query_,"../datasets/cloud.h5","query");
flann::load_from_file(match_,"../datasets/cloud.h5","match");

dists_ = flann::Matrix<float>(new float[query_.rows*knn_], query_.rows, knn_);
indices_ = flann::Matrix<size_t>(new size_t[query_.rows*knn_], query_.rows, knn_);
Expand Down Expand Up @@ -155,8 +155,8 @@ class FlannCompareKnnTest : public FLANNTestFixture {

printf("Reading test data...");
fflush(stdout);
flann::load_from_file(data_, "cloud.h5","dataset");
flann::load_from_file(query_,"cloud.h5","query");
flann::load_from_file(data_, "../datasets/cloud.h5","dataset");
flann::load_from_file(query_,"../datasets/cloud.h5","query");

dists_single_ = flann::Matrix<float>(new float[query_.rows*knn_], query_.rows, knn_);
indices_single_ = flann::Matrix<size_t>(new size_t[query_.rows*knn_], query_.rows, knn_);
Expand Down Expand Up @@ -229,8 +229,8 @@ class FlannCompareRadiusTest : public FLANNTestFixture {

printf("Reading test data...");
fflush(stdout);
flann::load_from_file(data_, "cloud.h5","dataset");
flann::load_from_file(query_,"cloud.h5","query");
flann::load_from_file(data_, "../datasets/cloud.h5","dataset");
flann::load_from_file(query_,"../datasets/cloud.h5","query");

int reserve_size = data_.rows / 1000;

Expand Down

0 comments on commit 8706330

Please sign in to comment.