Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add scope time logger w/ ACF_LOG_GPU_TIME option (hack benchmark) #16

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/build-xcode.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/bin/bash

TOOLCHAIN=xcode
CONFIG=MinSizeRel
CONFIG=Release

ARGS=(
--verbose
--toolchain ${TOOLCHAIN}
--config ${CONFIG}
--fwd HUNTER_CONFIGURATION_TYPES=${CONFIG}
ACF_USE_DRISHTI_CACHE=OFF
ACF_BUILD_TESTS=ON
--jobs 8
)

#build.py ${ARGS[@]} --install --reconfig ${*}
build.py ${ARGS[@]} --install ${*}
52 changes: 30 additions & 22 deletions src/lib/acf/ut/test-acf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ int gauze_main(int argc, char** argv)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#define ACF_TEST_DISPLAY_OUTPUT 0
#define ACF_TEST_WARM_UP_GPU 0 // for timing only

// clang-format off
#if defined(ACF_DO_GPU)
Expand All @@ -48,6 +47,10 @@ int gauze_main(int argc, char** argv)
// clang-format on
#include "io/cereal_pba.h"

#include "util/ScopeTimeLogger.h"

#define ACF_LOG_GPU_TIME 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Enable timer


// http://uscilab.github.io/cereal/serialization_archives.html
#include <cereal/archives/portable_binary.hpp>
#include <cereal/types/vector.hpp>
Expand Down Expand Up @@ -231,35 +234,32 @@ class ACFTest : public ::testing::Test
static const bool doGrayscale = false;
ogles_gpgpu::Size2d inputSize(image.cols, image.rows);

m_acf = std::make_shared<ogles_gpgpu::ACF>(nullptr, inputSize, sizes, ogles_gpgpu::ACF::kLUVM012345, doGrayscale, false);
m_acf = std::make_shared<ogles_gpgpu::ACF>(nullptr, inputSize, sizes, ogles_gpgpu::ACF::kM012345, doGrayscale, false);
m_acf->setRotation(0);
m_acf->setDoLuvTransfer(false);

cv::Mat input = image;
#if ACF_TEST_WARM_UP_GPU

#if ACF_LOG_GPU_TIME
// Warm up the GPU
for (int i = 0; i < 10; i++)
{
(*m_acf)({ input.cols, input.rows }, input.ptr(), true, 0, DFLT_TEXTURE_FORMAT);
}
m_acf->fill(Pgpu, Pcpu); // be sure to read and flush all commands
#endif

(*m_acf)({ input.cols, input.rows }, input.ptr(), true, 0, DFLT_TEXTURE_FORMAT);
m_acf->fill(Pgpu, Pcpu);

{
// This code block is a place holder for 7 channel ACF output, which conveniently fits in 2 textures
// for faster transfers on low performing Android devices. Currently there is no 7 channel ACF
// classifier/detector, so this is used as a place holder to illustrate the raw channel extraction
// and pyramid formatting until equivalent CPU formatting is in place.
auto acf7 = std::make_shared<ogles_gpgpu::ACF>(nullptr, inputSize, sizes, ogles_gpgpu::ACF::kM012345, doGrayscale, false);
(*acf7)({ input.cols, input.rows }, input.ptr(), true, 0, DFLT_TEXTURE_FORMAT);

acf::Detector::Pyramid Pgpu7;
acf7->fill(Pgpu7, Pcpu);

//cv::imshow("Pgpu7", draw(Pgpu7);
//cv::imshow("LM012345", acf7->getChannels());
//cv::imshow("LUVM012345", m_acf->getChannels());
//cv::waitKey(0);

#if ACF_LOG_GPU_TIME
util::ScopeTimeLogger logger = [&](double elapsed)
{
std::cout << "ACF::fill(): " << input.cols << " " << elapsed << std::endl;
};
#endif
// Fill in the pyramid:
(*m_acf)({ input.cols, input.rows }, input.ptr(), true, 0, DFLT_TEXTURE_FORMAT);
glFlush();
m_acf->fill(Pgpu, Pcpu);
}
}

Expand Down Expand Up @@ -450,7 +450,15 @@ TEST_F(ACFTest, ACFDetectionGPU10)

std::vector<double> scores;
std::vector<cv::Rect> objects;
(*m_detector)(Pgpu, objects);
{
#if ACF_LOG_GPU_TIME
util::ScopeTimeLogger logger = [](double elapsed)
{
std::cout << "acf::Detector::operator():" << elapsed << std::endl;
};
#endif
(*m_detector)(Pgpu, objects);
}

#if ACF_TEST_DISPLAY_OUTPUT
WaitKey waitKey;
Expand Down
63 changes: 63 additions & 0 deletions src/lib/util/ScopeTimeLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*! -*-c++-*-
@file timing.h
@author David Hirvonen
@brief Scope based timing macro.

\copyright Copyright 2014-2017 Elucideye, Inc. All rights reserved.
\license{This project is released under the 3 Clause BSD License.}

*/

#ifndef __util_core_ScopeTimeLogger_h__
#define __util_core_ScopeTimeLogger_h__

#include "util/acf_util.h"

#include <chrono>
#include <functional>

UTIL_NAMESPACE_BEGIN

class ScopeTimeLogger
{
using HighResolutionClock = std::chrono::high_resolution_clock;
using TimePoint = HighResolutionClock::time_point;

public:
template <class Callable>
ScopeTimeLogger(Callable&& logger)
: m_logger(std::forward<Callable>(logger))
{
m_tic = HighResolutionClock::now();
}

ScopeTimeLogger(ScopeTimeLogger&& other)
: m_logger(std::move(other.m_logger))
, m_tic(std::move(other.m_tic))
{
}

~ScopeTimeLogger()
{
auto now = HighResolutionClock::now();
m_logger(timeDifference(now, m_tic));
}

ScopeTimeLogger(const ScopeTimeLogger&) = delete;
void operator=(const ScopeTimeLogger&) = delete;

static double timeDifference(const TimePoint& a, const TimePoint& b)
{
return std::chrono::duration_cast<std::chrono::duration<double>>(a - b).count();
}

const TimePoint& getTime() const { return m_tic; }

protected:
std::function<void(double)> m_logger;
TimePoint m_tic;
};

UTIL_NAMESPACE_END

#endif // __util_core_ScopeTimeLogger_h__