Remove AutodiffCodegen autodiff benchmarks
Change-Id: If1eaad31710cc91d40323ea6cae7cabe6fa64b1f
diff --git a/internal/ceres/autodiff_benchmarks/CMakeLists.txt b/internal/ceres/autodiff_benchmarks/CMakeLists.txt
index 454e04b..06b3cf6 100644
--- a/internal/ceres/autodiff_benchmarks/CMakeLists.txt
+++ b/internal/ceres/autodiff_benchmarks/CMakeLists.txt
@@ -1,8 +1,4 @@
# TODO: Add support for other compilers
-if(CODE_GENERATION)
- list(APPEND CERES_BENCHMARK_FLAGS "-DWITH_CODE_GENERATION")
-endif()
-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND CERES_BENCHMARK_FLAGS "-mllvm" "-inline-threshold=1000000")
endif()
@@ -16,23 +12,3 @@
add_executable(autodiff_benchmarks_fast_math autodiff_benchmarks.cc)
add_dependencies_to_benchmark(autodiff_benchmarks_fast_math)
target_compile_options(autodiff_benchmarks_fast_math PRIVATE ${CERES_BENCHMARK_FAST_MATH_FLAGS})
-
-if(CODE_GENERATION)
- macro (generate_benchmark_functor FUNCTOR_NAME FUNCTOR_FILE)
- ceres_generate_cost_function_implementation_for_functor(
- NAME ${FUNCTOR_NAME}
- INPUT_FILE ${FUNCTOR_FILE}
- OUTPUT_DIRECTORY benchmarks
- NAMESPACE ceres
- )
- endmacro()
- include(CeresCodeGeneration)
-
- generate_benchmark_functor(SnavelyReprojectionError snavely_reprojection_error.h)
- generate_benchmark_functor(Linear1CostFunction linear_cost_functions.h)
- generate_benchmark_functor(Linear10CostFunction linear_cost_functions.h)
- generate_benchmark_functor(Brdf brdf_cost_function.h)
-
- target_link_libraries(autodiff_benchmarks PUBLIC SnavelyReprojectionError Linear1CostFunction Linear10CostFunction Brdf)
- target_link_libraries(autodiff_benchmarks_fast_math PUBLIC SnavelyReprojectionError Linear1CostFunction Linear10CostFunction Brdf)
-endif()
diff --git a/internal/ceres/autodiff_benchmarks/autodiff_benchmarks.cc b/internal/ceres/autodiff_benchmarks/autodiff_benchmarks.cc
index 38b3632..cf2d558 100644
--- a/internal/ceres/autodiff_benchmarks/autodiff_benchmarks.cc
+++ b/internal/ceres/autodiff_benchmarks/autodiff_benchmarks.cc
@@ -101,25 +101,6 @@
BENCHMARK_TEMPLATE(BM_ConstantAnalytic, 60);
BENCHMARK_TEMPLATE(BM_ConstantAutodiff, 60);
-#ifdef WITH_CODE_GENERATION
-static void BM_Linear1CodeGen(benchmark::State& state) {
- double parameter_block1[] = {1.};
- double* parameters[] = {parameter_block1};
-
- double jacobian1[1];
- double residuals[1];
- double* jacobians[] = {jacobian1};
-
- std::unique_ptr<ceres::CostFunction> cost_function(new Linear1CostFunction());
-
- for (auto _ : state) {
- cost_function->Evaluate(
- parameters, residuals, state.range(0) ? jacobians : nullptr);
- }
-}
-BENCHMARK(BM_Linear1CodeGen)->Arg(0)->Arg(1);
-#endif
-
static void BM_Linear1AutoDiff(benchmark::State& state) {
using FunctorType =
ceres::internal::CostFunctionToFunctor<Linear1CostFunction>;
@@ -141,26 +122,6 @@
}
BENCHMARK(BM_Linear1AutoDiff)->Arg(0)->Arg(1);
-#ifdef WITH_CODE_GENERATION
-static void BM_Linear10CodeGen(benchmark::State& state) {
- double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
- double* parameters[] = {parameter_block1};
-
- double jacobian1[10 * 10];
- double residuals[10];
- double* jacobians[] = {jacobian1};
-
- std::unique_ptr<ceres::CostFunction> cost_function(
- new Linear10CostFunction());
-
- for (auto _ : state) {
- cost_function->Evaluate(
- parameters, residuals, state.range(0) ? jacobians : nullptr);
- }
-}
-BENCHMARK(BM_Linear10CodeGen)->Arg(0)->Arg(1);
-#endif
-
static void BM_Linear10AutoDiff(benchmark::State& state) {
using FunctorType =
ceres::internal::CostFunctionToFunctor<Linear10CostFunction>;
@@ -221,31 +182,6 @@
}
BENCHMARK(BM_Rat43AutoDiff)->Arg(0)->Arg(1);
-#ifdef WITH_CODE_GENERATION
-static void BM_SnavelyReprojectionCodeGen(benchmark::State& state) {
- double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
- double parameter_block2[] = {1., 2., 3.};
- double* parameters[] = {parameter_block1, parameter_block2};
-
- double jacobian1[2 * 9];
- double jacobian2[2 * 3];
- double residuals[2];
- double* jacobians[] = {jacobian1, jacobian2};
-
- const double x = 0.2;
- const double y = 0.3;
-
- std::unique_ptr<ceres::CostFunction> cost_function(
- new SnavelyReprojectionError(x, y));
-
- for (auto _ : state) {
- cost_function->Evaluate(
- parameters, residuals, state.range(0) ? jacobians : nullptr);
- }
-}
-BENCHMARK(BM_SnavelyReprojectionCodeGen)->Arg(0)->Arg(1);
-#endif
-
static void BM_SnavelyReprojectionAutoDiff(benchmark::State& state) {
using FunctorType =
ceres::internal::CostFunctionToFunctor<SnavelyReprojectionError>;
@@ -367,44 +303,6 @@
BENCHMARK(BM_RelativePoseAutoDiff)->Arg(0)->Arg(1);
-#ifdef WITH_CODE_GENERATION
-static void BM_BrdfCodeGen(benchmark::State& state) {
- using FunctorType = ceres::internal::CostFunctionToFunctor<Brdf>;
-
- double material[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
- auto c = Eigen::Vector3d(0.1, 0.2, 0.3);
- auto n = Eigen::Vector3d(-0.1, 0.5, 0.2).normalized();
- auto v = Eigen::Vector3d(0.5, -0.2, 0.9).normalized();
- auto l = Eigen::Vector3d(-0.3, 0.4, -0.3).normalized();
- auto x = Eigen::Vector3d(0.5, 0.7, -0.1).normalized();
- auto y = Eigen::Vector3d(0.2, -0.2, -0.2).normalized();
-
- double* parameters[7] = {
- material, c.data(), n.data(), v.data(), l.data(), x.data(), y.data()};
-
- double jacobian[(10 + 6 * 3) * 3];
- double residuals[3];
- double* jacobians[7] = {
- jacobian + 0,
- jacobian + 10 * 3,
- jacobian + 13 * 3,
- jacobian + 16 * 3,
- jacobian + 19 * 3,
- jacobian + 22 * 3,
- jacobian + 25 * 3,
- };
-
- std::unique_ptr<ceres::CostFunction> cost_function(new Brdf());
-
- for (auto _ : state) {
- cost_function->Evaluate(
- parameters, residuals, state.range(0) ? jacobians : nullptr);
- }
-}
-
-BENCHMARK(BM_BrdfCodeGen)->Arg(0)->Arg(1);
-#endif
-
static void BM_BrdfAutoDiff(benchmark::State& state) {
using FunctorType = ceres::internal::CostFunctionToFunctor<Brdf>;
diff --git a/internal/ceres/autodiff_benchmarks/brdf_cost_function.h b/internal/ceres/autodiff_benchmarks/brdf_cost_function.h
index de69cdd..4134181 100644
--- a/internal/ceres/autodiff_benchmarks/brdf_cost_function.h
+++ b/internal/ceres/autodiff_benchmarks/brdf_cost_function.h
@@ -35,7 +35,6 @@
#include <Eigen/Core>
#include <cmath>
-#include "ceres/codegen/codegen_cost_function.h"
namespace ceres {
// The brdf is based on:
@@ -44,7 +43,7 @@
//
// The implementation is based on:
// https://github.com/wdas/brdf/blob/master/src/brdfs/disney.brdf
-struct Brdf : public ceres::CodegenCostFunction<3, 10, 3, 3, 3, 3, 3, 3> {
+struct Brdf {
public:
Brdf() {}
@@ -57,7 +56,6 @@
const T* const x_ptr,
const T* const y_ptr,
T* residual) const {
- using ceres::Ternary;
using Vec3 = Eigen::Matrix<T, 3, 1>;
T metallic = material[0];
@@ -121,8 +119,8 @@
const T aspct = Aspect(anisotropic);
const T ax_temp = Square(roughness) / aspct;
const T ay_temp = Square(roughness) * aspct;
- const T ax = Ternary(ax_temp < eps, eps, ax_temp);
- const T ay = Ternary(ay_temp < eps, eps, ay_temp);
+ const T ax = (ax_temp < eps ? eps : ax_temp);
+ const T ay = (ay_temp < eps ? eps : ay_temp);
const T ds = GTR2Aniso(n_dot_h, h_dot_x, h_dot_y, ax, ay);
const T fh = SchlickFresnel(l_dot_h);
const Vec3 fs = Lerp(c_spec0, Vec3(T(1), T(1), T(1)), fh);
@@ -180,13 +178,13 @@
T GTR1(const T& n_dot_h, const T& a) const {
T result = T(0);
- CERES_IF(a >= T(1)) { result = T(1 / M_PI); }
- CERES_ELSE {
+ if (a >= T(1)) {
+ result = T(1 / M_PI);
+ } else {
const T a2 = a * a;
const T t = T(1) + (a2 - T(1)) * n_dot_h * n_dot_h;
result = (a2 - T(1)) / (T(M_PI) * T(log(a2) * t));
}
- CERES_ENDIF;
return result;
}
@@ -217,16 +215,6 @@
inline T Square(const T& x) const {
return x * x;
}
-
-#ifdef WITH_CODE_GENERATION
-#include "benchmarks/brdf.h"
-#else
- virtual bool Evaluate(double const* const* parameters,
- double* residuals,
- double** jacobians) const {
- return false;
- }
-#endif
};
} // namespace ceres
diff --git a/internal/ceres/autodiff_benchmarks/linear_cost_functions.h b/internal/ceres/autodiff_benchmarks/linear_cost_functions.h
index e009ee2..4ead04a 100644
--- a/internal/ceres/autodiff_benchmarks/linear_cost_functions.h
+++ b/internal/ceres/autodiff_benchmarks/linear_cost_functions.h
@@ -32,29 +32,19 @@
#ifndef CERES_INTERNAL_AUTODIFF_BENCHMARKS_LINEAR_COST_FUNCTIONS_H_
#define CERES_INTERNAL_AUTODIFF_BENCHMARKS_LINEAR_COST_FUNCTIONS_H_
-#include "ceres/codegen/codegen_cost_function.h"
#include "ceres/rotation.h"
namespace ceres {
-struct Linear1CostFunction : public ceres::CodegenCostFunction<1, 1> {
+struct Linear1CostFunction {
template <typename T>
bool operator()(const T* const x, T* residuals) const {
residuals[0] = x[0] + T(10);
return true;
}
-#ifdef WITH_CODE_GENERATION
-#include "benchmarks/linear1costfunction.h"
-#else
- virtual bool Evaluate(double const* const* parameters,
- double* residuals,
- double** jacobians) const {
- return false;
- }
-#endif
};
-struct Linear10CostFunction : public ceres::CodegenCostFunction<10, 10> {
+struct Linear10CostFunction {
template <typename T>
bool operator()(const T* const x, T* residuals) const {
for (int i = 0; i < 10; ++i) {
@@ -62,15 +52,6 @@
}
return true;
}
-#ifdef WITH_CODE_GENERATION
-#include "benchmarks/linear10costfunction.h"
-#else
- virtual bool Evaluate(double const* const* parameters,
- double* residuals,
- double** jacobians) const {
- return false;
- }
-#endif
};
} // namespace ceres
diff --git a/internal/ceres/autodiff_benchmarks/snavely_reprojection_error.h b/internal/ceres/autodiff_benchmarks/snavely_reprojection_error.h
index aa86fd7..b1b5081 100644
--- a/internal/ceres/autodiff_benchmarks/snavely_reprojection_error.h
+++ b/internal/ceres/autodiff_benchmarks/snavely_reprojection_error.h
@@ -32,12 +32,11 @@
#ifndef CERES_INTERNAL_AUTODIFF_BENCHMARK_SNAVELY_REPROJECTION_ERROR_H_
#define CERES_INTERNAL_AUTODIFF_BENCHMARK_SNAVELY_REPROJECTION_ERROR_H_
-#include "ceres/codegen/codegen_cost_function.h"
#include "ceres/rotation.h"
namespace ceres {
-struct SnavelyReprojectionError : public ceres::CodegenCostFunction<2, 9, 3> {
+struct SnavelyReprojectionError {
SnavelyReprojectionError(double observed_x, double observed_y)
: observed_x(observed_x), observed_y(observed_y) {}
@@ -81,15 +80,6 @@
return true;
}
-#ifdef WITH_CODE_GENERATION
-#include "benchmarks/snavelyreprojectionerror.h"
-#else
- virtual bool Evaluate(double const* const* parameters,
- double* residuals,
- double** jacobians) const {
- return false;
- }
-#endif
double observed_x;
double observed_y;
};