Skip to content

Commit 149de05

Browse files
authored
Merge pull request #81 from andrew-hardin/feature/remove-boost-from-core
Remove boost from core popsift library
2 parents bf3556f + 249bbca commit 149de05

File tree

9 files changed

+105
-49
lines changed

9 files changed

+105
-49
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ oxford
4545
# Temporary files
4646
.DS_Store
4747

48+
# Downloaded archives for tests.
49+
*.tgz

CMakeLists.txt

+3-15
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@ option(PopSift_USE_POSITION_INDEPENDENT_CODE "Generate position independent code
1414
option(PopSift_USE_GRID_FILTER "Switch off grid filtering to massively reduce compile time while debugging other things." ON)
1515
option(PopSift_USE_NORMF "The __normf function computes Euclidian distance on large arrays. Fast but stability is uncertain." OFF)
1616
option(PopSift_USE_TEST_CMD "Add testing step for functional verification" OFF)
17-
option(PopSift_BOOST_USE_STATIC_LIBS "Link with static Boost libraries" OFF)
1817
option(PopSift_NVCC_WARNINGS "Switch on several additional warning for CUDA nvcc" OFF)
1918
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
2019

2120

22-
if(PopSift_BOOST_USE_STATIC_LIBS)
23-
set(Boost_USE_STATIC_LIBS ON)
24-
endif()
25-
2621
if(PopSift_USE_POSITION_INDEPENDENT_CODE)
2722
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2823
endif()
@@ -52,16 +47,6 @@ set(CMAKE_CUDA_STANDARD_REQUIRED ON)
5247
include(GNUInstallDirs)
5348

5449

55-
#################
56-
# BOOST
57-
#################
58-
find_package(Boost 1.53.0 REQUIRED COMPONENTS system thread)
59-
if(WIN32)
60-
add_definitions("-DBOOST_ALL_NO_LIB")
61-
link_directories(Boost_LIBRARRY_DIR_DEBUG)
62-
link_directories(Boost_LIBRARRY_DIR_RELEASE)
63-
endif(WIN32)
64-
6550
if(BUILD_SHARED_LIBS)
6651
message(STATUS "BUILD_SHARED_LIBS ON")
6752
# Need to declare CUDA_USE_STATIC_CUDA_RUNTIME as an option to ensure that it is not overwritten in FindCUDA.
@@ -77,6 +62,9 @@ else()
7762
set(CUDA_USE_STATIC_CUDA_RUNTIME ON)
7863
endif()
7964

65+
# Require threads because of std::thread.
66+
find_package(Threads REQUIRED)
67+
8068
###################
8169
# CUDA
8270
###################

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# PopSift
2+
# PopSift
33

44
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3728/badge)](https://bestpractices.coreinfrastructure.org/projects/3728) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/8b0f7a68bc0d4df2ac89c6e732917caa)](https://app.codacy.com/manual/alicevision/popsift?utm_source=github.com&utm_medium=referral&utm_content=alicevision/popsift&utm_campaign=Badge_Grade_Settings)
55

@@ -15,12 +15,12 @@ PopSift compiles and works with NVidia cards of compute capability >= 3.0 (inclu
1515

1616
PopSift depends on:
1717

18-
* Boost >= 1.55 (required components {atomic, chrono, date-time, system, thread}-dev)
19-
2018
* CUDA >= 7.0
2119

2220
Optionally, for the provided applications:
2321

22+
* Boost >= 1.55 (required components {atomic, chrono, date-time, system, thread}-dev)
23+
2424
* DevIL (libdevil-dev) can be used to load a broader range of image formats, otherwise only pgm is supported.
2525

2626
## Build
@@ -41,7 +41,7 @@ Some build options are available:
4141
* `BUILD_SHARED_LIBS` (default: `ON`) controls the type of library to build (`ON` for shared libraries, `OFF` for static)
4242

4343

44-
### Continuous integration:
44+
### Continuous integration:
4545
- [![Build Status](https://travis-ci.org/alicevision/popsift.svg?branch=master)](https://travis-ci.org/alicevision/popsift) master branch.
4646
- [![Build Status](https://travis-ci.org/alicevision/popsift.svg?branch=develop)](https://travis-ci.org/alicevision/popsift) develop branch.
4747
- [![Build status](https://ci.appveyor.com/api/projects/status/rsm5269hs288c2ji/branch/develop?svg=true)](https://ci.appveyor.com/project/AliceVision/popsift/branch/develop)
@@ -57,12 +57,12 @@ Calling `popsift-demo` without parameters shows the options.
5757

5858
### Using PopSift as third party
5959

60-
To integrate PopSift into other software, link with `libpopsift`.
61-
If your are using CMake for building your project you can easily add PopSift to your project.
60+
To integrate PopSift into other software, link with `libpopsift`.
61+
If your are using CMake for building your project you can easily add PopSift to your project.
6262
Once you have built and installed PopSift in a directory (say, `<prefix>`), in your `CMakeLists.txt` file just add the dependency
6363

6464
```cmake
65-
# Find the package from the PopSiftConfig.cmake
65+
# Find the package from the PopSiftConfig.cmake
6666
# in <prefix>/lib/cmake/PopSift/. Under the namespace PopSift::
6767
# it exposes the target popsift that allows you to compile
6868
# and link with the library
@@ -86,23 +86,23 @@ cmake .. -DPopSift_DIR=<prefix>/lib/cmake/PopSift/
8686

8787
The caller must create a `popart::Config` struct (documented in `src/sift/sift_conf.h`) to control the behaviour of the PopSift, and instantiate an object of class `PopSift` (found in `src/sift/popsift.h`).
8888

89-
After this, images can be enqueued for SIFT extraction using (`enqueue()`).
89+
After this, images can be enqueued for SIFT extraction using (`enqueue()`).
9090
A valid input is a single plane of grayscale values located in host memory.
9191
They can passed as a pointer to unsigned char, with a value range from 0 to 255, or as a pointer to float, with a value range from 0.0f to 1.0f.
9292

93-
Only host memory limits the number of images that can be enqueued.
93+
Only host memory limits the number of images that can be enqueued.
9494
The `enqueue` function returns a pointer to a `SiftJob` immediately and performs the feature extraction asynchronously.
9595
The memory of the image passed to enqueue remains the caller's responsibility. Calling `SiftJob::get` on the returned job blocks until features are extracted, and returns them.
9696

97-
Features offer iterators that iterate over objects of type `Feature`.
98-
Both classes are documented in `sift_extremum.h`.
97+
Features offer iterators that iterate over objects of type `Feature`.
98+
Both classes are documented in `sift_extremum.h`.
9999
Each feature represents a feature point in the coordinate system of the input image, providing X and Y coordinates and scale (sigma), as well as several alternative descriptors for the feature point (according to Lowe, 15% of the feature points should be expected to have 2 or more descriptors).
100100

101101
In an alternate, deprecated, blocking API, `init()` must be called to pass image width and height to PopSift, followed by a call to `executed()` that takes image data and returns the extracted features. `execute()` is synchronous and blocking.
102102

103-
As far as we know, no implementation that is faster than PopSift at the time of PopSift's release comes under a license that allows commercial use and sticks close to the original paper at the same time as well.
104-
PopSift can be configured at runtime to use constants that affect it behaviours.
105-
In particular, users can choose to generate results very similar to VLFeat or results that are closer (but not as close) to the SIFT implementation of the OpenCV extras.
103+
As far as we know, no implementation that is faster than PopSift at the time of PopSift's release comes under a license that allows commercial use and sticks close to the original paper at the same time as well.
104+
PopSift can be configured at runtime to use constants that affect it behaviours.
105+
In particular, users can choose to generate results very similar to VLFeat or results that are closer (but not as close) to the SIFT implementation of the OpenCV extras.
106106
We acknowledge that there is at least one SIFT implementation that is vastly faster, but it makes considerable sacrifices in terms of accuracy and compatibility.
107107

108108

@@ -131,7 +131,7 @@ If you use PopSift for your publication, please cite us as:
131131
acmid = {3208136},
132132
publisher = {ACM},
133133
address = {New York, NY, USA},
134-
}
134+
}
135135
```
136136

137137

cmake/Config.cmake.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
#
3737
################################################################################
3838

39-
4039
@PACKAGE_INIT@
4140

41+
include(CMakeFindDependencyMacro)
42+
find_dependency(Threads REQUIRED)
43+
4244
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
4345
check_required_components("@PROJECT_NAME@")

src/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ set(popsift_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
4545

4646
# BUILD_INTERFACE allows to include the directory with source only when target is
4747
# built in the building tree (ie, not from an install location)
48-
target_include_directories(popsift
48+
target_include_directories(popsift
4949
PUBLIC
5050
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
5151
$<BUILD_INTERFACE:${popsift_generated_dir}>
5252
$<BUILD_INTERFACE:${popsift_generated_dir}/popsift>
5353
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/>
54-
${Boost_INCLUDE_DIRS}
5554
${CUDA_INCLUDE_DIRS})
5655

5756

@@ -60,7 +59,8 @@ set_target_properties(popsift PROPERTIES DEBUG_POSTFIX "d")
6059

6160
# cannot use PRIVATE here as there is a bug in FindCUDA and CUDA_ADD_LIBRARY
6261
# https://gitlab.kitware.com/cmake/cmake/issues/16097
63-
target_link_libraries(popsift ${Boost_LIBRARIES} ${CUDA_CUDADEVRT_LIBRARY} ${CUDA_CUBLAS_LIBRARIES})
62+
target_link_libraries(popsift ${CUDA_CUDADEVRT_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} Threads::Threads)
63+
6464

6565

6666
# EXPORTING THE LIBRARY

src/application/CMakeLists.txt

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(PopsiftDemo LANGUAGES CXX)
33

4+
OPTION(PopSift_BOOST_USE_STATIC_LIBS "Link examples with static Boost libraries" OFF)
5+
46
if(TARGET popsift)
57
# when compiled in the repository the target is already defined
68
add_library(PopSift::popsift ALIAS popsift)
@@ -15,9 +17,13 @@ endif()
1517

1618
find_package(DevIL COMPONENTS IL ILU) # yields IL_FOUND, IL_LIBRARIES, IL_INCLUDE_DIR
1719

18-
set(Boost_INCLUDE_DIRS "")
19-
set(Boost_LIBRARIES "")
20-
find_package(Boost 1.53.0 REQUIRED COMPONENTS filesystem program_options)
20+
if(PopSift_BOOST_USE_STATIC_LIBS)
21+
set(Boost_USE_STATIC_LIBS ON)
22+
endif()
23+
find_package(Boost 1.53.0 REQUIRED COMPONENTS filesystem program_options system)
24+
if(WIN32)
25+
add_definitions("-DBOOST_ALL_NO_LIB")
26+
endif(WIN32)
2127

2228
set(PD_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
2329
set(PD_LINK_LIBS ${Boost_LIBRARIES} ${CUDA_CUDADEVRT_LIBRARY})

src/popsift/common/sync_queue.h

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#pragma once
2+
3+
#include <condition_variable>
4+
#include <mutex>
5+
#include <queue>
6+
7+
namespace popsift {
8+
9+
/**
10+
* @brief A thread safe wrapper around std::queue (replaces boost::sync_queue).
11+
* @tparam T the value type that's stored in the queue.
12+
*/
13+
template<typename T>
14+
class SyncQueue {
15+
public:
16+
SyncQueue() = default;
17+
18+
/**
19+
* @brief Push an item onto the queue and signal it's available.
20+
* @param[in] value the item to add to the queue.
21+
*/
22+
void push(const T& value) {
23+
std::unique_lock<std::mutex> lock(mtx_);
24+
items_.push(value);
25+
lock.unlock();
26+
signal_.notify_one();
27+
}
28+
29+
/**
30+
* @brief Check if the queue is empty - thread safety via mutex.
31+
* @return True if the queue is empty.
32+
*/
33+
bool empty() {
34+
std::unique_lock<std::mutex> lock(mtx_);
35+
return items_.empty();
36+
}
37+
38+
/**
39+
* @brief Pull an item off the queue, or, wait until one arrives. Blocking.
40+
* @return The front item that was popped off the queue.
41+
*/
42+
T pull() {
43+
std::unique_lock<std::mutex> lock(mtx_);
44+
signal_.wait(lock, [this] { return !items_.empty(); });
45+
auto ans = items_.front();
46+
items_.pop();
47+
return ans;
48+
}
49+
50+
private:
51+
std::mutex mtx_;
52+
std::queue<T> items_;
53+
std::condition_variable signal_;
54+
};
55+
56+
} // namespace popsift

src/popsift/popsift.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
#include <cmath>
9+
#include <cstring>
810
#include <fstream>
911

1012
#include "popsift.h"
@@ -30,11 +32,11 @@ PopSift::PopSift( const popsift::Config& config, popsift::Config::ProcessingMode
3032

3133
configure( config, true );
3234

33-
_pipe._thread_stage1.reset( new boost::thread( &PopSift::uploadImages, this ));
35+
_pipe._thread_stage1.reset( new std::thread( &PopSift::uploadImages, this ));
3436
if( mode == popsift::Config::ExtractingMode )
35-
_pipe._thread_stage2.reset( new boost::thread( &PopSift::extractDownloadLoop, this ));
37+
_pipe._thread_stage2.reset( new std::thread( &PopSift::extractDownloadLoop, this ));
3638
else
37-
_pipe._thread_stage2.reset( new boost::thread( &PopSift::matchPrepareLoop, this ));
39+
_pipe._thread_stage2.reset( new std::thread( &PopSift::matchPrepareLoop, this ));
3840
}
3941

4042
PopSift::PopSift( ImageMode imode )
@@ -51,8 +53,8 @@ PopSift::PopSift( ImageMode imode )
5153
_pipe._unused.push( new popsift::ImageFloat );
5254
}
5355

54-
_pipe._thread_stage1.reset( new boost::thread( &PopSift::uploadImages, this ));
55-
_pipe._thread_stage2.reset( new boost::thread( &PopSift::extractDownloadLoop, this ));
56+
_pipe._thread_stage1.reset( new std::thread( &PopSift::uploadImages, this ));
57+
_pipe._thread_stage2.reset( new std::thread( &PopSift::extractDownloadLoop, this ));
5658
}
5759

5860
PopSift::~PopSift()

src/popsift/popsift.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include <stack>
1313
#include <queue>
1414
#include <future>
15-
#include <boost/thread/thread.hpp>
16-
#include <boost/thread/sync_queue.hpp>
15+
#include <thread>
1716

17+
#include "common/sync_queue.h"
1818
#include "sift_conf.h"
1919
#include "sift_extremum.h"
2020
#include "sift_config.h"
@@ -75,11 +75,11 @@ class PopSift
7575
{
7676
struct Pipe
7777
{
78-
std::unique_ptr<boost::thread> _thread_stage1;
79-
std::unique_ptr<boost::thread> _thread_stage2;
80-
boost::sync_queue<SiftJob*> _queue_stage1;
81-
boost::sync_queue<SiftJob*> _queue_stage2;
82-
boost::sync_queue<popsift::ImageBase*> _unused;
78+
std::unique_ptr<std::thread> _thread_stage1;
79+
std::unique_ptr<std::thread> _thread_stage2;
80+
popsift::SyncQueue<SiftJob*> _queue_stage1;
81+
popsift::SyncQueue<SiftJob*> _queue_stage2;
82+
popsift::SyncQueue<popsift::ImageBase*> _unused;
8383

8484
popsift::Pyramid* _pyramid{nullptr};
8585

0 commit comments

Comments
 (0)