Skip to content

Commit

Permalink
Multiple major improvements.
Browse files Browse the repository at this point in the history
* Restructured enumerative solvers for less work.
* Added linear-time envelopes for Potts, TruncatedLinear, TruncatedQuadratic.
* Added deterministic mode (samples trees serially).
* Several minor bugfixes.
* Added GTest as a CMAKE dependency.
  • Loading branch information
dthuerck committed Jan 10, 2018
1 parent f73d2a6 commit 864b3c7
Show file tree
Hide file tree
Showing 76 changed files with 7,775 additions and 1,911 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.git
build
gtest
datasets
**/*.bin
.vscode
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ before_script:
- export CXX="g++-5"
- export CC="gcc-5"
- sudo apt-get install -qq libtbb-dev=4.4~20151115-0ubuntu3ppa1~trusty libtbb2=4.4~20151115-0ubuntu3ppa1~trusty libtbb2-dbg=4.4~20151115-0ubuntu3ppa1~trusty libgtest-dev
- cd /usr/src/gtest && sudo mkdir build && cd build && sudo cmake -DCMAKE_BUILD_TYPE=RELEASE .. && sudo make
- sudo mv libg* /usr/lib/
- cd $a
- mkdir build
- cd build
Expand Down
103 changes: 81 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)

set(CMAKE_C_COMPILER "gcc-5")
set(CMAKE_CXX_COMPILER "g++-5")
Expand All @@ -8,22 +8,31 @@ list(APPEND CMAKE_MODULE_PATH "$ENV{CMAKE_MODULE_PATH}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

project(mapMAP)
include(ExternalProject)

# selection what to build
option(BUILD_MEMSAVE "Use memory-saving mode. Might influence performance negatively." OFF)
option(BUILD_TEST "Build Google Tests for mapMAP modules." OFF)
option(BUILD_TEST "Build Google Tests for mapMAP modules." ON)
option(BUILD_DEMO "Build a demo, reading SHIMF datasets into mapMAP." ON)

set(TBB_INCLUDE_DIRS "/usr/include" CACHE PATH "Path to where the TBB include files (tbb/) reside")
set(TBB_LIBRARY "/usr/lib" CACHE PATH "Path to where the TBB library files (libtbb.so etc.) reside")

set(GTEST_ROOT "/usr/lib" CACHE PATH "Path to GoogleTest's root folder")
# default to Release build and C++11 mode
set(CMAKE_CXX_STANDARD 11)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif(NOT CMAKE_BUILD_TYPE)

# set optimization options for GCC on unixoid systems
# uses -march=native to make the compiler set __SSE4_2__, __AVX__ and
# __AVX2__ to fit the binary to the computer
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -march=native -O2 -flto -funroll-loops")
# __AVX2__ to fit to the computer (only in release mode)
set(CMAKE_CXX_FLAGS "-Wall -march=native")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -funroll-loops -mfpmath=sse")
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")

# augment build parameters for optional builds
if(BUILD_TEST)
Expand All @@ -47,7 +56,6 @@ include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/mapmap)
include_directories(SYSTEM
${GTEST_INCLUDE_DIR}
${TBB_INCLUDE_DIR})

set(header_dir "mapmap/header")
Expand All @@ -58,15 +66,13 @@ set(demo_dir "demo")
# base files
set(header_base
${header_dir}/color.h
${header_dir}/costs.h
${header_dir}/costs.h
${header_dir}/cost_bundle.h
${header_dir}/defines.h
${header_dir}/dynamic_programming.h
${header_dir}/graph.h
${header_dir}/instance_factory.h
${header_dir}/lock_free_tree_sampler.h
${header_dir}/mapmap.h
${header_dir}/multilevel.h
${header_dir}/optimistic_tree_sampler.h
${header_dir}/parallel_templates.h
${header_dir}/termination_criterion.h
${header_dir}/timer.h
Expand All @@ -78,14 +84,12 @@ set(header_base

set(impl_base
${impl_dir}/color.impl.h
${impl_dir}/costs.impl.h
${impl_dir}/dynamic_programming.impl.h
${impl_dir}/costs.impl.h
${impl_dir}/cost_bundle.impl.h
${impl_dir}/graph.impl.h
${impl_dir}/instance_factory.impl.h
${impl_dir}/lock_free_tree_sampler.impl.h
${impl_dir}/mapmap.impl.h
${impl_dir}/multilevel.impl.h
${impl_dir}/optimistic_tree_sampler.impl.h
${impl_dir}/parallel_templates.impl.h
${impl_dir}/timer.impl.h
${impl_dir}/tree.impl.h
Expand All @@ -95,19 +99,38 @@ set(impl_base

# cost instance files
set(header_cost_instances
${header_dir}/cost_instances/pairwise_antipotts.h
${header_dir}/cost_instances/pairwise_potts.h
${header_dir}/cost_instances/pairwise_table.h
${header_dir}/cost_instances/pairwise_truncated_linear.h
${header_dir}/cost_instances/pairwise_truncated_quadratic.h
${header_dir}/cost_instances/unary_table.h)

set(impl_cost_instances
${impl_dir}/cost_instances/pairwise_antipotts.impl.h
${impl_dir}/cost_instances/pairwise_potts.impl.h
${impl_dir}/cost_instances/pairwise_table.impl.h
${impl_dir}/cost_instances/pairwise_truncated_linear.h
${impl_dir}/cost_instances/pairwise_truncated_linear.impl.h
${impl_dir}/cost_instances/pairwise_truncated_quadratic.impl.h
${impl_dir}/cost_instances/unary_table.impl.h)

# optimizer
set(header_optimizer_instances
${header_dir}/optimizer_instances/envelope_instances/pairwise_potts_envelope.h
${header_dir}/optimizer_instances/envelope_instances/pairwise_truncated_linear_envelope.h
${header_dir}/optimizer_instances/envelope_instances/pairwise_truncated_quadratic_envelope.h
${header_dir}/optimizer_instances/dp_node.h
${header_dir}/optimizer_instances/dp_node_solver.h
${header_dir}/optimizer_instances/dp_node_solver_factory.h
${header_dir}/optimizer_instances/dynamic_programming.h
${header_dir}/optimizer_instances/envelope.h)

set(impl_optimizer_instances
${impl_dir}/optimizer_instances/envelope_instances/pairwise_potts_envelope.impl.h
${impl_dir}/optimizer_instances/envelope_instances/pairwise_truncated_linear_envelope.impl.h
${impl_dir}/optimizer_instances/envelope_instances/pairwise_truncated_quadratic_envelope.impl.h
${impl_dir}/optimizer_instances/dp_node_solver.impl.h
${impl_dir}/optimizer_instances/dp_node_solver_factory.impl.h
${impl_dir}/optimizer_instances/dynamic_programming.impl.h)

# multilevel instance files
set(header_multilevel_instances
${header_dir}/multilevel_instances/group_same_label.h)
Expand All @@ -128,6 +151,15 @@ set(impl_termination_instances
${impl_dir}/termination_instances/stop_when_flat.impl.h
${impl_dir}/termination_instances/stop_when_returns_diminish.impl.h)

# tree sampler instances
set(header_tree_sampler_instances
${header_dir}/tree_sampler_instances/lock_free_tree_sampler.h
${header_dir}/tree_sampler_instances/optimistic_tree_sampler.h)

set(impl_tree_sampler_instances
${impl_dir}/tree_sampler_instances/lock_free_tree_sampler.impl.h
${impl_dir}/tree_sampler_instances/optimistic_tree_sampler.impl.h)

# test files
set(header_test
${test_dir}/util_test.h)
Expand All @@ -139,28 +171,37 @@ set(src_test
${test_dir}/test_coloring.cc
${test_dir}/test_coordinate_set.cc
${test_dir}/test_dynamic_programming.cc
${test_dir}/test_envelope.cc
${test_dir}/test_graph.cc
${test_dir}/test_multilevel.cc
${test_dir}/test_spanning_tree.cc
${test_dir}/test_vector_math.cc)

set_source_files_properties(${header_base} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${header_cost_instances} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${header_optimizer_instances} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${header_multilevel_instances} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${header_termination_instances} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${tree_sampler_instances} PROPERTIES HEADER_FILE_ONLY TRUE)

source_group("Base" FILES
${header_base}
${impl_base})
source_group("Costs" FILES
${header_cost_instances}
${impl_cost_instances})
source_group("Optimizer" FILES
${header_optimizer_instances}
${impl_optimizer_instances})
source_group("Multilevel" FILES
${header_multilevel_instances}
${impl_multilevel_instances})
source_group("Termination" FILES
${header_termination_instances}
${impl_termination_instances})
source_group("TreeSampler" FILES
${header_tree_sampler_instances}
${impl_tree_sampler_instances})
source_group("Coloring" FILES
${header_coloring_instances}
${impl_coloring_instances})
Expand All @@ -169,14 +210,32 @@ source_group("Test" FILES
${impl_test}
${src_test})

# build gtest executable (and find Gtest, which is now necessary)
# build tests
if(BUILD_TEST)
find_package(GTest REQUIRED)

# CMake as dependency: download and build
externalproject_add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
PREFIX ${PROJECT_SOURCE_DIR}/gtest
CMAKE_ARGS -DBUILD_GTEST=ON -DBUILD_SHARED_LIBS=ON -Dgtest_build_tests=ON
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_TEST ON)

include_directories(SYSTEM
${PROJECT_SOURCE_DIR}/gtest/src/googletest/googletest/include)
link_directories(
${PROJECT_SOURCE_DIR}/gtest/src/googletest-build/googlemock/gtest)

add_executable(mapmap_test
${src_test})
target_link_libraries(mapmap_test
${TBB_LIBRARIES}
${GTEST_BOTH_LIBRARIES}
gtest
gtest_main
pthread)
endif(BUILD_TEST)

Expand All @@ -187,4 +246,4 @@ add_executable(mapmap_demo
${demo_dir}/mapmap_demo.cc)
target_link_libraries(mapmap_demo
${TBB_LIBRARIES})
endif(BUILD_DEMO)
endif(BUILD_DEMO)
52 changes: 45 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
mapMAP MRF MAP Solver [![Build Status](https://travis-ci.org/dthuerck/mapmap_cpu.svg?branch=master)](https://travis-ci.org/dthuerck/mapmap_cpu)
======

Change Log
------
Compared with the development version from our HPG paper (cf. below).

* v1.4 (1/10/2018):
- Deterministic solver path with user-provided seed.
- Several bugfixes and smaller improvements.
* v1.3 (10/18/2017):
- Envelope optimization for Potts, TruncatedLinear, TruncatedQuadratic.
- Ability to have individual cost functions per edge.
- Removed UNARY/PAIRWISE template parameters from solver, hiding these
internally.
- Improved multilevel performance, even in the case of individual costs.
- Added GTest for automatic built instead of a hard dependency.
* v1.2 (5/29/2017):
- Introduced a new, multicoloring-based tree selection algorithm -
lock-free.
* v1.1 (4/12/2017):
- Tuned the tree growing implementation for early termination and
- option for relaxing the maximality requirement.
* v1.0 (2/8/2017):
- Stable release.
- Logging callbacks for use as library.
- Clean, documented interface and documentation.
- Added a demo for correct usage.
* beta (12/6/2016):
- Initial release, mirrors functionality outlined in the paper.
- Automated vectorization (compile-time detection) for float/double.
- Supporting scalar/SSE2-4/AVX/AVX2.
- Added cost function instances.
- Added unit tests.

Overview
------

CPU-implementation of out massively-parallel, generic, MRF MAP solver named
*mapMAP* posing minimal assumptions to the input, allowing rapid solution
of a large class of MRF problems.
Expand All @@ -17,6 +52,8 @@ Currently, this code implements the following modules and features:
- [x] Templated SIMD width (1, 4, 8 for float; 1, 2, 4 for double)
- [x] Automatically setting SIMD width at compile time
- [x] Supports SSE4/AVX/AVX2, autodetected during build
- [x] Automatically using linear-time optimization for certain cost functions
- [x] Two algorithms for parallel tree sampling
- [x] Extensible interfaces for all components, providing user hooks
- [x] Cost functions (unary and pairwise)
- [x] Termination criteria
Expand All @@ -39,21 +76,20 @@ For the license and terms of usage, please see "License, Terms of usage & Refere
Prerequisites
------

* CMake building system (>= 2.8.0)
* CMake building system (>= 3.0.2)
* C++11 compatible compiler (e.g. gcc-5, MSVC 13, icc 17)
* GTest (see [Github](https://github.com/google/googletest)) for building/running the tests
* Intel TBB (>= 4.4, see [Webpage](https://www.threadingbuildingblocks.org/))

The code has been tested (and compiles without issues) on an Ubuntu 16.04
system with an AVX-compliant Intel i7-3930K CPU with 64 GB RAM and
using gcc/g++ 5.4.0, GTest 1.8.0 and Intel TBB (v2017u3). The latter is
using gcc/g++ 5.4.0 and Intel TBB (v2017u3). The latter is
licensed under the 3BSD-compatible Apache 2.0 licence (see
[ASF legal FAQ](http://www.apache.org/legal/resolved.html#category-a)).
Please make sure to use an C++11-comptabile compiler and activate the
necessary options.
If you are a Ubuntu user, please install the packages
`libtbb2 libtbb-dev libgtest-dev` and compile GTest's source in
`/usr/src/gtest` (see also Travis CI-script).
`libtbb2 libtbb-dev` (see also Travis CI-script). Google Test will automatically
be downloaded and built.

The provided FindTBB.cmake is taken from [justusc](https://github.com/justusc/FindTBB)
and licensed under the MIT license.
Expand Down Expand Up @@ -108,7 +144,8 @@ performance:
```
-std=c++11 -Wall -march=native -O2 -flto -mfpmath=sse -funroll-loops
```

As a good starting point, we recommend studying `mapmap_demo.cc` closely,
which is mostly self-explanatory.

Documentation
------
Expand Down Expand Up @@ -153,8 +190,9 @@ Contributors (including preceding project)
* Max von Buelow
* Patrick Seemann
* Nils Moehrle
* Nick Heppert

</a>Further material
Further material
------

Please see our project page at
Expand Down
Loading

0 comments on commit 864b3c7

Please sign in to comment.