Fixed broken timing script and fixed logic for building/excluding examples and timing scripts

release/4.3a0
Richard Roberts 2014-06-21 16:26:48 -07:00
parent 946cc5338a
commit 873283c522
5 changed files with 40 additions and 182 deletions

View File

@ -363,7 +363,7 @@ message(STATUS "================ Configuration Options ======================"
message(STATUS "Build flags ")
print_config_flag(${GTSAM_BUILD_TESTS} "Build Tests ")
print_config_flag(${GTSAM_BUILD_EXAMPLES_ALWAYS} "Build examples with 'make all' ")
print_config_flag(${GTSAM_BUILD_TIMING} "Build Timing scripts ")
print_config_flag(${GTSAM_BUILD_TIMING_ALWAYS} "Build timing scripts with 'make all'")
if (DOXYGEN_FOUND)
print_config_flag(${GTSAM_BUILD_DOCS} "Build Docs ")
endif()

View File

@ -52,7 +52,7 @@ endmacro()
# an empty string "" if nothing needs to be excluded.
# linkLibraries: The list of libraries to link to.
macro(gtsamAddExamplesGlob globPatterns excludedFiles linkLibraries)
gtsamAddExesGlob_impl("${globPatterns}" "${excludedFiles}" "${linkLibraries}" "examples" "${GTSAM_BUILD_EXAMPLES_ALWAYS}")
gtsamAddExesGlob_impl("${globPatterns}" "${excludedFiles}" "${linkLibraries}" "examples" ${GTSAM_BUILD_EXAMPLES_ALWAYS})
endmacro()
@ -77,7 +77,7 @@ endmacro()
# an empty string "" if nothing needs to be excluded.
# linkLibraries: The list of libraries to link to.
macro(gtsamAddTimingGlob globPatterns excludedFiles linkLibraries)
gtsamAddExesGlob_impl("${globPatterns}" "${excludedFiles}" "${linkLibraries}" "timing" "FALSE")
gtsamAddExesGlob_impl("${globPatterns}" "${excludedFiles}" "${linkLibraries}" "timing" ${GTSAM_BUILD_TIMING_ALWAYS})
endmacro()
@ -88,7 +88,7 @@ enable_testing()
option(GTSAM_BUILD_TESTS "Enable/Disable building of tests" ON)
option(GTSAM_BUILD_EXAMPLES_ALWAYS "Build examples with 'make all' (build with 'make examples' if not)" ON)
option(GTSAM_BUILD_TIMING "Enable/Disable building of timing scripts" OFF) # These do not currently work
option(GTSAM_BUILD_TIMING_ALWAYS "Build timing scripts with 'make all' (build with 'make timing' if not" OFF)
# Add option for combining unit tests
if(MSVC OR XCODE_VERSION)
@ -107,9 +107,7 @@ endif()
add_custom_target(examples)
# Add timing target
if(GTSAM_BUILD_TIMING)
add_custom_target(timing)
endif()
add_custom_target(timing)
# Include obsolete macros - will be removed in the near future
include(GtsamTestingObsolete)
@ -258,10 +256,12 @@ macro(gtsamAddExesGlob_impl globPatterns excludedFiles linkLibraries groupName b
# Add TOPSRCDIR
set_property(SOURCE ${script_src} APPEND PROPERTY COMPILE_DEFINITIONS "TOPSRCDIR=\"${PROJECT_SOURCE_DIR}\"")
if(NOT buildWithAll)
# Exclude from all or not - note weird variable assignment because we're in a macro
set(buildWithAll_on ${buildWithAll})
if(NOT buildWithAll_on)
# Exclude from 'make all' and 'make install'
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL ON)
set_target_properties("${script_name}" PROPERTIES EXCLUDE_FROM_ALL ON)
endif()
# Configure target folder (for MSVC and Xcode)

View File

@ -1,6 +1,3 @@
list(APPEND to_exclude
timeFactorOverhead.cpp
timeSLAMlike.cpp)
gtsamAddTimingGlob("*.cpp" "${to_exclude}" "gtsam")
gtsamAddTimingGlob("*.cpp" "" "gtsam")
target_link_libraries(timeGaussianFactorGraph CppUnitLite)

View File

@ -16,30 +16,29 @@
* @date Aug 20, 2010
*/
#include <gtsam/base/timing.h>
#include <gtsam/linear/GaussianBayesNet.h>
#include <gtsam/linear/GaussianFactorGraph.h>
#include <gtsam/linear/NoiseModel.h>
#include <gtsam/inference/EliminationTree-inl.h>
#include <gtsam/linear/VectorValues.h>
#include <boost/random.hpp>
#include <boost/timer.hpp>
#include <vector>
using namespace gtsam;
using namespace std;
typedef EliminationTree<GaussianFactor> GaussianEliminationTree;
static boost::variate_generator<boost::mt19937, boost::uniform_real<> > rg(boost::mt19937(), boost::uniform_real<>(0.0, 1.0));
int main(int argc, char *argv[]) {
Index key = 0;
Key key = 0;
size_t vardim = 2;
size_t blockdim = 1;
size_t nBlocks = 2000;
size_t nBlocks = 4000;
size_t nTrials = 10;
size_t nTrials = 20;
double blockbuild, blocksolve, combbuild, combsolve;
@ -54,8 +53,7 @@ int main(int argc, char *argv[]) {
// Build GFG's
cout << "Building blockwise Gaussian factor graphs... ";
cout.flush();
boost::timer timer;
timer.restart();
gttic_(blockbuild);
vector<GaussianFactorGraph> blockGfgs;
blockGfgs.reserve(nTrials);
for(size_t trial=0; trial<nTrials; ++trial) {
@ -70,22 +68,26 @@ int main(int argc, char *argv[]) {
Vector b(blockdim);
for(size_t j=0; j<blockdim; ++j)
b(j) = rg();
blockGfgs[trial].push_back(JacobianFactor::shared_ptr(new JacobianFactor(key, A, b, noise)));
blockGfgs[trial].push_back(boost::make_shared<JacobianFactor>(key, A, b, noise));
}
}
blockbuild = timer.elapsed();
gttoc_(blockbuild);
tictoc_getNode(blockbuildNode, blockbuild);
blockbuild = blockbuildNode->secs();
cout << blockbuild << " s" << endl;
// Solve GFG's
cout << "Solving blockwise Gaussian factor graphs... ";
cout.flush();
timer.restart();
gttic_(blocksolve);
for(size_t trial=0; trial<nTrials; ++trial) {
// cout << "Trial " << trial << endl;
GaussianBayesNet::shared_ptr gbn(GaussianEliminationTree::Create(blockGfgs[trial])->eliminate(&EliminateQR));
VectorValues soln(optimize(*gbn));
GaussianBayesNet::shared_ptr gbn = blockGfgs[trial].eliminateSequential();
VectorValues soln = gbn->optimize();
}
blocksolve = timer.elapsed();
gttoc_(blocksolve);
tictoc_getNode(blocksolveNode, blocksolve);
blocksolve = blocksolveNode->secs();
cout << blocksolve << " s" << endl;
}
@ -97,8 +99,7 @@ int main(int argc, char *argv[]) {
// Build GFG's
cout << "Building combined-factor Gaussian factor graphs... ";
cout.flush();
boost::timer timer;
timer.restart();
gttic_(combbuild);
vector<GaussianFactorGraph> combGfgs;
for(size_t trial=0; trial<nTrials; ++trial) {
combGfgs.push_back(GaussianFactorGraph());
@ -115,21 +116,25 @@ int main(int argc, char *argv[]) {
for(size_t j=0; j<blockdim; ++j)
bcomb(blockdim*i+j) = rg();
}
combGfgs[trial].push_back(JacobianFactor::shared_ptr(new JacobianFactor(key, Acomb, bcomb,
noiseModel::Isotropic::Sigma(blockdim*nBlocks, 1.0))));
combGfgs[trial].push_back(boost::make_shared<JacobianFactor>(key, Acomb, bcomb,
noiseModel::Isotropic::Sigma(blockdim*nBlocks, 1.0)));
}
combbuild = timer.elapsed();
gttoc(combbuild);
tictoc_getNode(combbuildNode, combbuild);
combbuild = combbuildNode->secs();
cout << combbuild << " s" << endl;
// Solve GFG's
cout << "Solving combined-factor Gaussian factor graphs... ";
cout.flush();
timer.restart();
gttic_(combsolve);
for(size_t trial=0; trial<nTrials; ++trial) {
GaussianBayesNet::shared_ptr gbn(GaussianEliminationTree::Create(combGfgs[trial])->eliminate(&EliminateQR));
VectorValues soln(optimize(*gbn));
GaussianBayesNet::shared_ptr gbn = combGfgs[trial].eliminateSequential();
VectorValues soln = gbn->optimize();
}
combsolve = timer.elapsed();
gttoc_(combsolve);
tictoc_getNode(combsolveNode, combsolve);
combsolve = combsolveNode->secs();
cout << combsolve << " s" << endl;
}

View File

@ -1,144 +0,0 @@
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
/**
* @file timeSLAMlike.cpp
* @brief Times solving of random SLAM-like graphs
* @author Richard Roberts
* @date Aug 30, 2010
*/
#include <gtsam/linear/GaussianFactorGraph.h>
#include <gtsam/linear/NoiseModel.h>
#include <boost/random.hpp>
#include <boost/timer.hpp>
#include <boost/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <vector>
using namespace gtsam;
using namespace std;
using namespace boost::lambda;
typedef EliminationTree<JacobianFactor> GaussianEliminationTree;
static boost::variate_generator<boost::mt19937, boost::uniform_real<> > rg(boost::mt19937(), boost::uniform_real<>(0.0, 1.0));
bool _pair_compare(const pair<Index, Matrix>& a1, const pair<Index, Matrix>& a2) { return a1.first < a2.first; }
int main(int argc, char *argv[]) {
size_t vardim = 3;
size_t blockdim = 3;
int nVars = 500;
size_t blocksPerVar = 5;
size_t varsPerBlock = 2;
size_t varSpread = 10;
size_t nTrials = 10;
double blockbuild, blocksolve;
cout << "\n" << nVars << " variables of dimension " << vardim << ", " <<
blocksPerVar << " blocks for each variable, blocks of dimension " << blockdim << " measure " << varsPerBlock << " variables\n";
cout << nTrials << " trials\n";
boost::variate_generator<boost::mt19937, boost::uniform_int<> > ri(boost::mt19937(), boost::uniform_int<>(-varSpread, varSpread));
/////////////////////////////////////////////////////////////////////////////
// Timing test with blockwise Gaussian factor graphs
{
// Build GFG's
cout << "Building SLAM-like Gaussian factor graphs... ";
cout.flush();
boost::timer timer;
timer.restart();
vector<GaussianFactorGraph> blockGfgs;
blockGfgs.reserve(nTrials);
for(size_t trial=0; trial<nTrials; ++trial) {
blockGfgs.push_back(GaussianFactorGraph());
SharedDiagonal noise = noiseModel::Isotropic::Sigma(blockdim, 1.0);
for(int c=0; c<nVars; ++c) {
for(size_t d=0; d<blocksPerVar; ++d) {
vector<pair<Index, Matrix> > terms; terms.reserve(varsPerBlock);
if(c == 0 && d == 0)
// If it's the first factor, just make a prior
terms.push_back(make_pair(0, eye(vardim)));
else if(c != 0) {
// Generate a random Gaussian factor
for(size_t h=0; h<varsPerBlock; ++h) {
int var;
// If it's the first factor for this variable, make it "odometry"
if(d == 0 && h == 0)
var = c-1;
else if(d == 0 && h == 1)
var = c;
else
// Choose random variable ids
do
var = c + ri();
while(var < 0 || var > nVars-1 || find_if(terms.begin(), terms.end(),
boost::bind(&pair<Index, Matrix>::first, boost::lambda::_1) == Index(var)) != terms.end());
Matrix A(blockdim, vardim);
for(size_t j=0; j<blockdim; ++j)
for(size_t k=0; k<vardim; ++k)
A(j,k) = rg();
terms.push_back(make_pair(Index(var), A));
}
}
Vector b(blockdim);
sort(terms.begin(), terms.end(), &_pair_compare);
for(size_t j=0; j<blockdim; ++j)
b(j) = rg();
if(!terms.empty())
blockGfgs[trial].push_back(JacobianFactor::shared_ptr(new JacobianFactor(terms, b, noise)));
}
}
// if(trial == 0)
// blockGfgs.front().print("GFG: ");
}
blockbuild = timer.elapsed();
cout << blockbuild << " s" << endl;
// Solve GFG's
cout << "Solving SLAM-like Gaussian factor graphs... ";
cout.flush();
timer.restart();
for(size_t trial=0; trial<nTrials; ++trial) {
// cout << "Trial " << trial << endl;
VectorValues soln(*GaussianMultifrontalSolver(blockGfgs[trial]).optimize());
}
blocksolve = timer.elapsed();
cout << blocksolve << " s" << endl;
}
/////////////////////////////////////////////////////////////////////////////
// Print per-graph times
cout << "\nPer-factor-graph times for building and solving\n";
cout << " total " << (1000.0*(blockbuild+blocksolve)/double(nTrials)) <<
" build " << (1000.0*blockbuild/double(nTrials)) <<
" solve " << (1000.0*blocksolve/double(nTrials)) << " ms/graph\n";
cout << endl;
return 0;
}
/**
* @file timeSLAMlike.cpp
* @brief
* @author Richard Roberts
* @date Aug 30, 2010
*/