OpenCL: Remove PERF_COUNT framework

It was rarely used, but added a lot of code and an unconditional
dependency on openclwrapper.h.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2019-02-09 10:58:15 +01:00
parent ec8f02c0de
commit d42413dd17
7 changed files with 33 additions and 213 deletions

View File

@ -70,7 +70,9 @@
#include "mutableiterator.h" // for MutableIterator
#include "normalis.h" // for kBlnBaselineOffset, kBlnXHeight
#include "ocrclass.h" // for ETEXT_DESC
#include "openclwrapper.h" // for PERF_COUNT_END, PERF_COUNT_START, PERF...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif
#include "osdetect.h" // for OSResults, OSBestResult, OrientationId...
#include "pageres.h" // for PAGE_RES_IT, WERD_RES, PAGE_RES, CR_DE...
#include "paragraphs.h" // for DetectParagraphs
@ -360,7 +362,6 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
const GenericVector<STRING>* vars_vec,
const GenericVector<STRING>* vars_values,
bool set_only_non_debug_params, FileReader reader) {
PERF_COUNT_START("TessBaseAPI::Init")
// Default language is "eng".
if (language == nullptr) language = "eng";
STRING datapath = data_size == 0 ? data : language;
@ -376,12 +377,10 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
delete tesseract_;
tesseract_ = nullptr;
}
// PERF_COUNT_SUB("delete tesseract_")
#ifdef USE_OPENCL
OpenclDevice od;
od.InitEnv();
#endif
PERF_COUNT_SUB("OD::InitEnv()")
bool reset_classifier = true;
if (tesseract_ == nullptr) {
reset_classifier = false;
@ -400,7 +399,6 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
}
}
PERF_COUNT_SUB("update tesseract_")
// Update datapath and language requested for the last valid initialization.
if (datapath_ == nullptr)
datapath_ = new STRING(datapath);
@ -417,14 +415,11 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
last_oem_requested_ = oem;
#ifndef DISABLED_LEGACY_ENGINE
// PERF_COUNT_SUB("update last_oem_requested_")
// For same language and datapath, just reset the adaptive classifier.
if (reset_classifier) {
tesseract_->ResetAdaptiveClassifier();
PERF_COUNT_SUB("tesseract_->ResetAdaptiveClassifier()")
}
#endif // ndef DISABLED_LEGACY_ENGINE
PERF_COUNT_END
return 0;
}
@ -1106,7 +1101,6 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
const char* retry_config,
int timeout_millisec,
TessResultRenderer* renderer) {
PERF_COUNT_START("ProcessPages")
bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
if (stdInput) {
#ifdef WIN32
@ -1199,14 +1193,12 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
if (!r || (renderer && !renderer->EndDocument())) {
return false;
}
PERF_COUNT_END
return true;
}
bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
const char* retry_config, int timeout_millisec,
TessResultRenderer* renderer) {
PERF_COUNT_START("ProcessPage")
SetInputName(filename);
SetImage(pix);
bool failed = false;
@ -1264,7 +1256,6 @@ bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
failed = !renderer->AddImage(this);
}
PERF_COUNT_END
return !failed;
}

View File

@ -28,7 +28,9 @@
#include "baseapi.h"
#include "basedir.h"
#include "dict.h"
#include "openclwrapper.h" // for PERF_COUNT_START, ...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif
#include "osdetect.h"
#include "renderer.h"
#include "simddetect.h"
@ -582,8 +584,6 @@ int main(int argc, char** argv) {
if (image == nullptr && !list_langs && !print_parameters)
return EXIT_SUCCESS;
PERF_COUNT_START("Tesseract:main")
// Call GlobalDawgCache here to create the global DawgCache object before
// the TessBaseAPI object. This fixes the order of destructor calls:
// first TessBaseAPI must be destructed, DawgCache must be the last object.
@ -721,7 +721,5 @@ int main(int argc, char** argv) {
}
}
PERF_COUNT_END
return EXIT_SUCCESS;
}

View File

@ -25,8 +25,11 @@
#include <cstring>
#include "otsuthr.h"
#include "tprintf.h" // for tprintf
#include "openclwrapper.h" // for PERF_COUNT_START, ...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif
namespace tesseract {
@ -263,7 +266,6 @@ Pix* ImageThresholder::GetPixRectGrey() {
// Otsu thresholds the rectangle, taking the rectangle from *this.
void ImageThresholder::OtsuThresholdRectToPix(Pix* src_pix,
Pix** out_pix) const {
PERF_COUNT_START("OtsuThresholdRectToPix")
int* thresholds;
int* hi_values;
@ -286,8 +288,6 @@ void ImageThresholder::OtsuThresholdRectToPix(Pix* src_pix,
#endif
delete [] thresholds;
delete [] hi_values;
PERF_COUNT_END
}
/// Threshold the rectangle, taking everything except the src_pix
@ -299,7 +299,6 @@ void ImageThresholder::ThresholdRectToPix(Pix* src_pix,
const int* thresholds,
const int* hi_values,
Pix** pix) const {
PERF_COUNT_START("ThresholdRectToPix")
*pix = pixCreate(rect_width_, rect_height_, 1);
uint32_t* pixdata = pixGetData(*pix);
int wpl = pixGetWpl(*pix);
@ -325,8 +324,6 @@ void ImageThresholder::ThresholdRectToPix(Pix* src_pix,
SET_DATA_BIT(pixline, x);
}
}
PERF_COUNT_END
}
} // namespace tesseract.

View File

@ -22,7 +22,9 @@
#include <cstring>
#include "allheaders.h"
#include "helpers.h"
#include "openclwrapper.h" // for PERF_COUNT_START, ...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif
namespace tesseract {
@ -40,7 +42,6 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
int num_channels = pixGetDepth(src_pix) / 8;
// Of all channels with no good hi_value, keep the best so we can always
// produce at least one answer.
PERF_COUNT_START("OtsuThreshold")
int best_hi_value = 1;
int best_hi_index = 0;
bool any_good_hivalue = false;
@ -139,7 +140,6 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
// Use the best of the ones that were not good enough.
(*hi_values)[best_hi_index] = best_hi_value;
}
PERF_COUNT_END
return num_channels;
}
@ -150,7 +150,6 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
void HistogramRect(Pix* src_pix, int channel,
int left, int top, int width, int height,
int* histogram) {
PERF_COUNT_START("HistogramRect")
int num_channels = pixGetDepth(src_pix) / 8;
channel = ClipToRange(channel, 0, num_channels - 1);
int bottom = top + height;
@ -164,7 +163,6 @@ void HistogramRect(Pix* src_pix, int channel,
++histogram[pixel];
}
}
PERF_COUNT_END
}
// Computes the Otsu threshold(s) for the given histogram.

View File

@ -14,6 +14,7 @@
#include <unistd.h>
#endif
#include <cfloat>
#include <ctime> // for clock_gettime
#include "oclkernels.h"
#include "openclwrapper.h"
@ -22,6 +23,22 @@
#include "otsuthr.h"
#include "thresholder.h"
// platform preprocessor commands
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || \
defined(__CYGWIN__) || defined(__MINGW32__)
#define ON_WINDOWS 1
#define ON_APPLE 0
#elif defined(__linux__)
#define ON_WINDOWS 0
#define ON_APPLE 0
#elif defined(__APPLE__)
#define ON_WINDOWS 0
#define ON_APPLE 1
#else
#define ON_WINDOWS 0
#define ON_APPLE 0
#endif
#if ON_APPLE
#include <mach/mach_time.h>
#endif
@ -712,19 +729,15 @@ int OpenclDevice::initMorphCLAllocations(l_int32 wpl, l_int32 h, Pix* pixs) {
}
int OpenclDevice::InitEnv() {
// PERF_COUNT_START("OD::InitEnv")
// tprintf("[OD] OpenclDevice::InitEnv()\n");
#ifdef SAL_WIN32
while (1) {
if (1 == LoadOpencl()) break;
}
PERF_COUNT_SUB("LoadOpencl")
#endif
// sets up environment, compiles programs
InitOpenclRunEnv_DeviceSelection(0);
// PERF_COUNT_SUB("called InitOpenclRunEnv_DS")
// PERF_COUNT_END
return 1;
}
@ -755,11 +768,9 @@ int OpenclDevice::RegistOpenclKernel() {
}
int OpenclDevice::InitOpenclRunEnv_DeviceSelection(int argc) {
// PERF_COUNT_START("InitOpenclRunEnv_DS")
if (!isInited) {
// after programs compiled, selects best device
ds_device bestDevice_DS = getDeviceSelection();
// PERF_COUNT_SUB("called getDeviceSelection()")
cl_device_id bestDevice = bestDevice_DS.oclDeviceID;
// overwrite global static GPUEnv with new device
if (selectedDeviceIsOpenCL()) {
@ -768,16 +779,13 @@ int OpenclDevice::InitOpenclRunEnv_DeviceSelection(int argc) {
populateGPUEnvFromDevice(&gpuEnv, bestDevice);
gpuEnv.mnFileCount = 0; // argc;
gpuEnv.mnKernelCount = 0UL;
// PERF_COUNT_SUB("populate gpuEnv")
CompileKernelFile(&gpuEnv, "");
// PERF_COUNT_SUB("CompileKernelFile")
} else {
// tprintf("[DS] InitOpenclRunEnv_DS::Skipping populateGPUEnvFromDevice()
// b/c native cpu selected\n");
}
isInited = 1;
}
// PERF_COUNT_END
return 0;
}
@ -941,7 +949,6 @@ int OpenclDevice::GeneratBinFromKernelSource(cl_program program,
}
int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
// PERF_COUNT_START("CompileKernelFile")
cl_int clStatus = 0;
const char* source;
size_t source_size[1];
@ -962,14 +969,12 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
binaryExisted = 0;
binaryExisted = BinaryGenerated(
filename, &fd); // don't check for binary during microbenchmark
// PERF_COUNT_SUB("BinaryGenerated")
if (binaryExisted == 1) {
clStatus = clGetContextInfo(gpuInfo->mpContext, CL_CONTEXT_NUM_DEVICES,
sizeof(numDevices), &numDevices, nullptr);
CHECK_OPENCL(clStatus, "clGetContextInfo");
std::vector<cl_device_id> mpArryDevsID(numDevices);
// PERF_COUNT_SUB("get numDevices")
bool b_error = fseek(fd, 0, SEEK_END) < 0;
long pos = ftell(fd);
b_error |= (pos <= 0);
@ -986,29 +991,24 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
b_error |= fread(&binary[0], 1, length, fd) != length;
fclose(fd);
// PERF_COUNT_SUB("read file")
fd = nullptr;
// grab the handles to all of the devices in the context.
clStatus = clGetContextInfo(gpuInfo->mpContext, CL_CONTEXT_DEVICES,
sizeof(cl_device_id) * numDevices,
&mpArryDevsID[0], nullptr);
CHECK_OPENCL(clStatus, "clGetContextInfo");
// PERF_COUNT_SUB("get devices")
// fprintf(stderr, "[OD] Create kernel from binary\n");
const uint8_t* c_binary = &binary[0];
gpuInfo->mpArryPrograms[idx] = clCreateProgramWithBinary(
gpuInfo->mpContext, numDevices, &mpArryDevsID[0], &length, &c_binary,
&binary_status, &clStatus);
CHECK_OPENCL(clStatus, "clCreateProgramWithBinary");
// PERF_COUNT_SUB("clCreateProgramWithBinary")
// PERF_COUNT_SUB("binaryExisted")
} else {
// create a CL program using the kernel source
// fprintf(stderr, "[OD] Create kernel from source\n");
gpuInfo->mpArryPrograms[idx] = clCreateProgramWithSource(
gpuInfo->mpContext, 1, &source, source_size, &clStatus);
CHECK_OPENCL(clStatus, "clCreateProgramWithSource");
// PERF_COUNT_SUB("!binaryExisted")
}
if (gpuInfo->mpArryPrograms[idx] == (cl_program) nullptr) {
@ -1018,19 +1018,15 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
// char options[512];
// create a cl program executable for all the devices specified
// tprintf("[OD] BuildProgram.\n");
PERF_COUNT_START("OD::CompileKernel::clBuildProgram")
if (!gpuInfo->mnIsUserCreated) {
clStatus =
clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, gpuInfo->mpArryDevsID,
buildOption, nullptr, nullptr);
// PERF_COUNT_SUB("clBuildProgram notUserCreated")
} else {
clStatus =
clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &(gpuInfo->mpDevID),
buildOption, nullptr, nullptr);
// PERF_COUNT_SUB("clBuildProgram isUserCreated")
}
PERF_COUNT_END
if (clStatus != CL_SUCCESS) {
tprintf("BuildProgram error!\n");
size_t length;
@ -1068,26 +1064,21 @@ int OpenclDevice::CompileKernelFile(GPUEnv* gpuInfo, const char* buildOption) {
fclose(fd1);
}
// PERF_COUNT_SUB("build error log")
return 0;
}
strcpy(gpuInfo->mArryKnelSrcFile[idx], filename);
// PERF_COUNT_SUB("strcpy")
if (binaryExisted == 0) {
GeneratBinFromKernelSource(gpuInfo->mpArryPrograms[idx], filename);
PERF_COUNT_SUB("GenerateBinFromKernelSource")
}
gpuInfo->mnFileCount += 1;
// PERF_COUNT_END
return 1;
}
l_uint32* OpenclDevice::pixReadFromTiffKernel(l_uint32* tiffdata, l_int32 w,
l_int32 h, l_int32 wpl,
l_uint32* line) {
PERF_COUNT_START("pixReadFromTiffKernel")
cl_int clStatus;
KernelEnv rEnv;
size_t globalThreads[2];
@ -1130,7 +1121,6 @@ l_uint32* OpenclDevice::pixReadFromTiffKernel(l_uint32* tiffdata, l_int32 w,
CHECK_OPENCL(clStatus, "clSetKernelArg");
// Kernel enqueue
PERF_COUNT_SUB("before")
clStatus =
clEnqueueNDRangeKernel(rEnv.mpkCmdQueue, rEnv.mpkKernel, 2, nullptr,
globalThreads, localThreads, 0, nullptr, nullptr);
@ -1145,8 +1135,6 @@ l_uint32* OpenclDevice::pixReadFromTiffKernel(l_uint32* tiffdata, l_int32 w,
// Sync
clFinish(rEnv.mpkCmdQueue);
PERF_COUNT_SUB("kernel & map")
PERF_COUNT_END
return pResult;
}
@ -1627,7 +1615,6 @@ int OpenclDevice::HistogramRectOCL(void* imageData,
int top, // always 0
int width, int height, int kHistogramSize,
int* histogramAllChannels) {
PERF_COUNT_START("HistogramRectOCL")
cl_int clStatus;
int retVal = 0;
KernelEnv histKern;
@ -1742,7 +1729,6 @@ int OpenclDevice::HistogramRectOCL(void* imageData,
CHECK_OPENCL(clStatus, "clSetKernelArg histogramBuffer");
/* launch histogram */
PERF_COUNT_SUB("before")
clStatus = clEnqueueNDRangeKernel(histKern.mpkCmdQueue, histKern.mpkKernel, 1,
nullptr, global_work_size, local_work_size,
0, nullptr, nullptr);
@ -1763,7 +1749,6 @@ int OpenclDevice::HistogramRectOCL(void* imageData,
if (clStatus != 0) {
retVal = -1;
}
PERF_COUNT_SUB("redKernel")
/* map results back from gpu */
ptr = clEnqueueMapBuffer(histRedKern.mpkCmdQueue, histogramBuffer, CL_TRUE,
@ -1779,8 +1764,6 @@ int OpenclDevice::HistogramRectOCL(void* imageData,
clReleaseMemObject(histogramBuffer);
clReleaseMemObject(imageBuffer);
PERF_COUNT_SUB("after")
PERF_COUNT_END
return retVal;
}
@ -1794,7 +1777,6 @@ int OpenclDevice::ThresholdRectToPixOCL(unsigned char* imageData,
int* thresholds, int* hi_values,
Pix** pix, int height, int width,
int top, int left) {
PERF_COUNT_START("ThresholdRectToPixOCL")
int retVal = 0;
/* create pix result buffer */
*pix = pixCreate(width, height, 1);
@ -1874,13 +1856,11 @@ int OpenclDevice::ThresholdRectToPixOCL(unsigned char* imageData,
CHECK_OPENCL(clStatus, "clSetKernelArg pixThBuffer");
/* launch kernel & wait */
PERF_COUNT_SUB("before")
clStatus = clEnqueueNDRangeKernel(rEnv.mpkCmdQueue, rEnv.mpkKernel, 1,
nullptr, global_work_size, local_work_size,
0, nullptr, nullptr);
CHECK_OPENCL(clStatus, "clEnqueueNDRangeKernel kernel_ThresholdRectToPix");
clFinish(rEnv.mpkCmdQueue);
PERF_COUNT_SUB("kernel")
if (clStatus != 0) {
tprintf("Setting return value to -1\n");
retVal = -1;
@ -1897,8 +1877,6 @@ int OpenclDevice::ThresholdRectToPixOCL(unsigned char* imageData,
clReleaseMemObject(thresholdsBuffer);
clReleaseMemObject(hiValuesBuffer);
PERF_COUNT_SUB("after")
PERF_COUNT_END
return retVal;
}
@ -2499,16 +2477,13 @@ static ds_status evaluateScoreForDevice(ds_device* device, void* inputData) {
// initial call to select device
ds_device OpenclDevice::getDeviceSelection() {
if (!deviceIsSelected) {
PERF_COUNT_START("getDeviceSelection")
// check if opencl is available at runtime
if (1 == LoadOpencl()) {
// opencl is available
// PERF_COUNT_SUB("LoadOpencl")
// setup devices
ds_status status;
ds_profile* profile;
status = initDSProfile(&profile, "v0.1");
PERF_COUNT_SUB("initDSProfile")
// try reading scores from file
const char* fileName = "tesseract_opencl_profile_devices.dat";
status = readProfileFromFile(profile, deserializeScore, fileName);
@ -2520,16 +2495,13 @@ ds_device OpenclDevice::getDeviceSelection() {
// create input data
TessScoreEvaluationInputData input;
populateTessScoreEvaluationInputData(&input);
// PERF_COUNT_SUB("populateTessScoreEvaluationInputData")
// perform evaluations
unsigned int numUpdates;
status = profileDevices(profile, DS_EVALUATE_ALL,
evaluateScoreForDevice, &input, &numUpdates);
PERF_COUNT_SUB("profileDevices")
// write scores to file
if (status == DS_SUCCESS) {
status = writeProfileToFile(profile, serializeScore, fileName);
PERF_COUNT_SUB("writeProfileToFile")
if (status == DS_SUCCESS) {
tprintf("[DS] Scores written to file (%s).\n", fileName);
} else {
@ -2544,7 +2516,6 @@ ds_device OpenclDevice::getDeviceSelection() {
"file.\n");
}
} else {
PERF_COUNT_SUB("readProfileFromFile")
tprintf("[DS] Profile read from file (%s).\n", fileName);
}
@ -2614,10 +2585,7 @@ ds_device OpenclDevice::getDeviceSelection() {
selectedDevice.oclDriverVersion = nullptr;
}
deviceIsSelected = true;
PERF_COUNT_SUB("select from Profile")
PERF_COUNT_END
}
// PERF_COUNT_END
return selectedDevice;
}

View File

@ -18,136 +18,6 @@
// including CL/cl.h doesn't occur until USE_OPENCL defined below
// platform preprocessor commands
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || \
defined(__CYGWIN__) || defined(__MINGW32__)
#define ON_WINDOWS 1
#define ON_LINUX 0
#define ON_APPLE 0
#define ON_OTHER 0
#define IF_WINDOWS(X) X
#define IF_LINUX(X)
#define IF_APPLE(X)
#define IF_OTHER(X)
#define NOT_WINDOWS(X)
#elif defined(__linux__)
#define ON_WINDOWS 0
#define ON_LINUX 1
#define ON_APPLE 0
#define ON_OTHER 0
#define IF_WINDOWS(X)
#define IF_LINUX(X) X
#define IF_APPLE(X)
#define IF_OTHER(X)
#define NOT_WINDOWS(X) X
#elif defined(__APPLE__)
#define ON_WINDOWS 0
#define ON_LINUX 0
#define ON_APPLE 1
#define ON_OTHER 0
#define IF_WINDOWS(X)
#define IF_LINUX(X)
#define IF_APPLE(X) X
#define IF_OTHER(X)
#define NOT_WINDOWS(X) X
#else
#define ON_WINDOWS 0
#define ON_LINUX 0
#define ON_APPLE 0
#define ON_OTHER 1
#define IF_WINDOWS(X)
#define IF_LINUX(X)
#define IF_APPLE(X)
#define IF_OTHER(X) X
#define NOT_WINDOWS(X) X
#endif
#if ON_LINUX
#include <ctime>
#endif
/************************************************************************************
* enable/disable reporting of performance
* PERF_REPORT_LEVEL
* 0 - no reporting
* 1 - no reporting
* 2 - report total function call time for functions we're tracking
* 3 - optionally report breakdown of function calls (kernel launch, kernel
*time, data copies)
************************************************************************************/
#define PERF_COUNT_VERBOSE 1
#define PERF_COUNT_REPORT_STR "[%36s], %24s, %11.6f\n"
#if ON_WINDOWS
#if PERF_COUNT_VERBOSE >= 2
#define PERF_COUNT_START(FUNCT_NAME) \
char* funct_name = FUNCT_NAME; \
double elapsed_time_sec; \
LARGE_INTEGER freq, time_funct_start, time_funct_end, time_sub_start, \
time_sub_end; \
QueryPerformanceFrequency(&freq); \
QueryPerformanceCounter(&time_funct_start); \
time_sub_start = time_funct_start; \
time_sub_end = time_funct_start;
#define PERF_COUNT_END \
QueryPerformanceCounter(&time_funct_end); \
elapsed_time_sec = (time_funct_end.QuadPart - time_funct_start.QuadPart) / \
(double)(freq.QuadPart); \
tprintf(PERF_COUNT_REPORT_STR, funct_name, "total", elapsed_time_sec);
#else
#define PERF_COUNT_START(FUNCT_NAME)
#define PERF_COUNT_END
#endif
#if PERF_COUNT_VERBOSE >= 3
#define PERF_COUNT_SUB(SUB) \
QueryPerformanceCounter(&time_sub_end); \
elapsed_time_sec = (time_sub_end.QuadPart - time_sub_start.QuadPart) / \
(double)(freq.QuadPart); \
tprintf(PERF_COUNT_REPORT_STR, funct_name, SUB, elapsed_time_sec); \
time_sub_start = time_sub_end;
#else
#define PERF_COUNT_SUB(SUB)
#endif
// not on windows
#else
#if PERF_COUNT_VERBOSE >= 2
#define PERF_COUNT_START(FUNCT_NAME) \
char* funct_name = FUNCT_NAME; \
double elapsed_time_sec; \
timespec time_funct_start, time_funct_end, time_sub_start, time_sub_end; \
clock_gettime(CLOCK_MONOTONIC, &time_funct_start); \
time_sub_start = time_funct_start; \
time_sub_end = time_funct_start;
#define PERF_COUNT_END \
clock_gettime(CLOCK_MONOTONIC, &time_funct_end); \
elapsed_time_sec = \
(time_funct_end.tv_sec - time_funct_start.tv_sec) * 1.0 + \
(time_funct_end.tv_nsec - time_funct_start.tv_nsec) / 1000000000.0; \
tprintf(PERF_COUNT_REPORT_STR, funct_name, "total", elapsed_time_sec);
#else
#define PERF_COUNT_START(FUNCT_NAME)
#define PERF_COUNT_END
#endif
#if PERF_COUNT_VERBOSE >= 3
#define PERF_COUNT_SUB(SUB) \
clock_gettime(CLOCK_MONOTONIC, &time_sub_end); \
elapsed_time_sec = \
(time_sub_end.tv_sec - time_sub_start.tv_sec) * 1.0 + \
(time_sub_end.tv_nsec - time_sub_start.tv_nsec) / 1000000000.0; \
tprintf(PERF_COUNT_REPORT_STR, funct_name, SUB, elapsed_time_sec); \
time_sub_start = time_sub_end;
#else
#define PERF_COUNT_SUB(SUB)
#endif
#endif
/**************************************************************************
* enable/disable use of OpenCL
**************************************************************************/

View File

@ -27,7 +27,9 @@
#include "tabvector.h"
#include "blobbox.h"
#include "edgblob.h"
#include "openclwrapper.h" // for PERF_COUNT_START, ...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif
#include "allheaders.h"
@ -243,7 +245,6 @@ void LineFinder::FindAndRemoveLines(int resolution, bool debug, Pix* pix,
Pix** pix_music_mask,
TabVector_LIST* v_lines,
TabVector_LIST* h_lines) {
PERF_COUNT_START("FindAndRemoveLines")
if (pix == nullptr || vertical_x == nullptr || vertical_y == nullptr) {
tprintf("Error in parameters for LineFinder::FindAndRemoveLines\n");
return;
@ -308,7 +309,6 @@ void LineFinder::FindAndRemoveLines(int resolution, bool debug, Pix* pix,
"vhlinefinding.pdf");
pixaDestroy(&pixa_display);
}
PERF_COUNT_END
}
// Converts the Boxa array to a list of C_BLOB, getting rid of severely
@ -583,7 +583,6 @@ void LineFinder::GetLineMasks(int resolution, Pix* src_pix,
}
int closing_brick = max_line_width / 3;
PERF_COUNT_START("GetLineMasksMorph")
// only use opencl if compiled w/ OpenCL and selected device is opencl
#ifdef USE_OPENCL
if (OpenclDevice::selectedDeviceIsOpenCL()) {
@ -625,7 +624,6 @@ void LineFinder::GetLineMasks(int resolution, Pix* src_pix,
#ifdef USE_OPENCL
}
#endif
PERF_COUNT_END
// Lines are sufficiently rare, that it is worth checking for a zero image.
l_int32 v_empty = 0;