mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
Adds a Ceres Context structure.
A Ceres Context holds common global state that can be re-used within Ceres. The Context current contains a thread pool if compiling with C++11 threading support. Threads are expensive to create and destroy so it is good to maintain across multiple Ceres solves. Tested by compiling with and without TBB support and ran unit tests. Ran bazel as well. Change-Id: I82f598dfae642aa0e81a6039dc174608a5e8dbfb
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// Ceres Solver - A fast non-linear least squares minimizer
|
||||
// Copyright 2018 Google Inc. All rights reserved.
|
||||
// http://ceres-solver.org/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: vitus@google.com (Michael Vitus)
|
||||
|
||||
#ifndef CERES_PUBLIC_CONTEXT_H_
|
||||
#define CERES_PUBLIC_CONTEXT_H_
|
||||
|
||||
#include "ceres/internal/macros.h"
|
||||
|
||||
namespace ceres {
|
||||
|
||||
// A global context for processing data in Ceres. This provides a mechanism to
|
||||
// allow Ceres to reuse items that are expensive to create between multiple
|
||||
// calls; for example, thread pools. The same Context can be used on multiple
|
||||
// Problems, either serially or in parallel. When using it with multiple
|
||||
// Problems at the same time, they may end up contending for resources
|
||||
// (e.g. threads) managed by the Context.
|
||||
class Context {
|
||||
public:
|
||||
Context() {}
|
||||
virtual ~Context() {}
|
||||
|
||||
// Creates a context object and the caller takes ownership.
|
||||
static Context* Create();
|
||||
|
||||
private:
|
||||
CERES_DISALLOW_COPY_AND_ASSIGN(Context);
|
||||
};
|
||||
|
||||
} // namespace ceres
|
||||
|
||||
#endif // CERES_PUBLIC_CONTEXT_H_
|
||||
@@ -33,10 +33,10 @@
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "ceres/internal/disable_warnings.h"
|
||||
#include "ceres/internal/port.h"
|
||||
#include "ceres/internal/scoped_ptr.h"
|
||||
#include "ceres/types.h"
|
||||
#include "ceres/internal/disable_warnings.h"
|
||||
|
||||
namespace ceres {
|
||||
|
||||
|
||||
+12
-4
@@ -39,13 +39,13 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "glog/logging.h"
|
||||
#include "ceres/context.h"
|
||||
#include "ceres/internal/disable_warnings.h"
|
||||
#include "ceres/internal/macros.h"
|
||||
#include "ceres/internal/port.h"
|
||||
#include "ceres/internal/scoped_ptr.h"
|
||||
#include "ceres/types.h"
|
||||
#include "ceres/internal/disable_warnings.h"
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
namespace ceres {
|
||||
|
||||
@@ -126,7 +126,8 @@ class CERES_EXPORT Problem {
|
||||
loss_function_ownership(TAKE_OWNERSHIP),
|
||||
local_parameterization_ownership(TAKE_OWNERSHIP),
|
||||
enable_fast_removal(false),
|
||||
disable_all_safety_checks(false) {}
|
||||
disable_all_safety_checks(false),
|
||||
context(NULL) {}
|
||||
|
||||
// These flags control whether the Problem object owns the cost
|
||||
// functions, loss functions, and parameterizations passed into
|
||||
@@ -165,6 +166,13 @@ class CERES_EXPORT Problem {
|
||||
// WARNING: Do not set this to true, unless you are absolutely sure of what
|
||||
// you are doing.
|
||||
bool disable_all_safety_checks;
|
||||
|
||||
// A Ceres global context to use for solving this problem. This may help to
|
||||
// reduce computation time as Ceres can reuse expensive objects to create.
|
||||
// The context object can be NULL, in which case Ceres may create one.
|
||||
//
|
||||
// Ceres does NOT take ownership of the pointer.
|
||||
Context* context;
|
||||
};
|
||||
|
||||
// The default constructor is equivalent to the
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ceres/crs_matrix.h"
|
||||
#include "ceres/internal/disable_warnings.h"
|
||||
#include "ceres/internal/macros.h"
|
||||
#include "ceres/internal/port.h"
|
||||
#include "ceres/iteration_callback.h"
|
||||
#include "ceres/ordered_groups.h"
|
||||
#include "ceres/types.h"
|
||||
#include "ceres/internal/disable_warnings.h"
|
||||
|
||||
namespace ceres {
|
||||
|
||||
@@ -1059,9 +1059,8 @@ class CERES_EXPORT Solver {
|
||||
};
|
||||
|
||||
// Helper function which avoids going through the interface.
|
||||
CERES_EXPORT void Solve(const Solver::Options& options,
|
||||
Problem* problem,
|
||||
Solver::Summary* summary);
|
||||
CERES_EXPORT void Solve(const Solver::Options& options, Problem* problem,
|
||||
Solver::Summary* summary);
|
||||
|
||||
} // namespace ceres
|
||||
|
||||
|
||||
Reference in New Issue
Block a user