Improved flexibility and output for regression/far_perf:

- fixed memory leaks and added asserts and errors for bad input data
    - restructured the CSV output to a line per test and renamed flag to -csv
    - added options -nopatches, -nostencils and -total options to reduce output
This commit is contained in:
barry 2019-06-17 09:19:38 -07:00
parent ff9a3b4fcb
commit 5fc51d87ca

View File

@ -34,8 +34,8 @@
#include <opensubdiv/far/primvarRefiner.h> #include <opensubdiv/far/primvarRefiner.h>
#include <opensubdiv/far/stencilTableFactory.h> #include <opensubdiv/far/stencilTableFactory.h>
#include <opensubdiv/far/patchTableFactory.h> #include <opensubdiv/far/patchTableFactory.h>
#include "../../regression/common/far_utils.h" #include "../../regression/common/far_utils.h"
// XXX: revisit the directory structure for examples/tests
#include "../../examples/common/stopwatch.h" #include "../../examples/common/stopwatch.h"
#include "init_shapes.h" #include "init_shapes.h"
@ -44,8 +44,33 @@
using namespace OpenSubdiv; using namespace OpenSubdiv;
struct Result { struct TestOptions {
TestOptions() :
refineLevel(2),
refineAdaptive(true),
createPatches(true),
createStencils(true),
endCapType(Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS) { }
int refineLevel;
bool refineAdaptive;
bool createPatches;
bool createStencils;
Far::PatchTableFactory::Options::EndCapType endCapType;
};
struct TestResult {
TestResult() :
level(-1),
timeTotal(0),
timeRefine(0),
timePatchFactory(0),
timeStencilFactory(0),
timeAppendStencil(0) { }
std::string name; std::string name;
int level;
double timeTotal; double timeTotal;
double timeRefine; double timeRefine;
double timePatchFactory; double timePatchFactory;
@ -54,74 +79,76 @@ struct Result {
}; };
template <typename REAL> template <typename REAL>
static Result static TestResult
doPerf(std::string const & name, RunPerfTest(Shape const & shape, TestOptions const & options) {
Shape const * shape,
int level,
bool adaptive,
Far::PatchTableFactory::Options::EndCapType endCapType)
{
typedef Far::StencilTableReal<REAL> FarStencilTable; typedef Far::StencilTableReal<REAL> FarStencilTable;
typedef Far::StencilTableFactoryReal<REAL> FarStencilTableFactory; typedef Far::StencilTableFactoryReal<REAL> FarStencilTableFactory;
Sdc::SchemeType sdcType = GetSdcType(*shape); Sdc::SchemeType sdcType = GetSdcType(shape);
Sdc::Options sdcOptions = GetSdcOptions(*shape); Sdc::Options sdcOptions = GetSdcOptions(shape);
Result result; TestResult result;
result.name = name; result.level = options.refineLevel;
Stopwatch s; Stopwatch s;
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Configure the patch table factory options // Configure the patch table factory options
Far::PatchTableFactory::Options poptions(level); Far::PatchTableFactory::Options poptions(options.refineLevel);
poptions.SetEndCapType(endCapType); poptions.SetEndCapType(options.endCapType);
poptions.SetPatchPrecision<REAL>(); poptions.SetPatchPrecision<REAL>();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Instantiate a FarTopologyRefiner from the descriptor and refine // Instantiate a FarTopologyRefiner from the descriptor and refine
s.Start();
Far::TopologyRefiner * refiner = Far::TopologyRefinerFactory<Shape>::Create( Far::TopologyRefiner * refiner = Far::TopologyRefinerFactory<Shape>::Create(
*shape, Far::TopologyRefinerFactory<Shape>::Options(sdcType, sdcOptions)); shape, Far::TopologyRefinerFactory<Shape>::Options(sdcType, sdcOptions));
{ assert(refiner);
if (adaptive) {
Far::TopologyRefiner::AdaptiveOptions options = s.Start();
poptions.GetRefineAdaptiveOptions(); if (options.refineAdaptive) {
refiner->RefineAdaptive(options); Far::TopologyRefiner::AdaptiveOptions rOptions =
} else { poptions.GetRefineAdaptiveOptions();
Far::TopologyRefiner::UniformOptions options(level); refiner->RefineAdaptive(rOptions);
refiner->RefineUniform(options); } else {
} Far::TopologyRefiner::UniformOptions rOptions(options.refineLevel);
refiner->RefineUniform(rOptions);
} }
s.Stop(); s.Stop();
result.timeRefine = s.GetElapsed(); result.timeRefine = s.GetElapsed();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Create patch table // Create patch table
s.Start();
Far::PatchTable const * patchTable = NULL; Far::PatchTable const * patchTable = NULL;
{ if (options.createPatches) {
s.Start();
patchTable = Far::PatchTableFactory::Create(*refiner, poptions); patchTable = Far::PatchTableFactory::Create(*refiner, poptions);
s.Stop();
result.timePatchFactory = s.GetElapsed();
} else {
result.timePatchFactory = 0;
} }
s.Stop();
result.timePatchFactory = s.GetElapsed();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Create stencil table // Create stencil table
s.Start();
FarStencilTable const * vertexStencils = NULL; FarStencilTable const * vertexStencils = NULL;
{ if (options.createStencils) {
s.Start();
typename FarStencilTableFactory::Options options; typename FarStencilTableFactory::Options options;
vertexStencils = FarStencilTableFactory::Create(*refiner, options); vertexStencils = FarStencilTableFactory::Create(*refiner, options);
s.Stop();
result.timeStencilFactory = s.GetElapsed();
} else {
result.timeStencilFactory = 0;
} }
s.Stop();
result.timeStencilFactory = s.GetElapsed();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// append local points to stencils // append local points to stencils
s.Start(); if (options.createPatches && options.createStencils) {
{ s.Start();
if (FarStencilTable const *vertexStencilsWithLocalPoints = if (FarStencilTable const *vertexStencilsWithLocalPoints =
FarStencilTableFactory::AppendLocalPointStencilTable( FarStencilTableFactory::AppendLocalPointStencilTable(
*refiner, vertexStencils, *refiner, vertexStencils,
@ -129,25 +156,128 @@ doPerf(std::string const & name,
delete vertexStencils; delete vertexStencils;
vertexStencils = vertexStencilsWithLocalPoints; vertexStencils = vertexStencilsWithLocalPoints;
} }
s.Stop();
result.timeAppendStencil = s.GetElapsed();
} else {
result.timeAppendStencil = 0;
} }
s.Stop();
result.timeAppendStencil = s.GetElapsed();
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
result.timeTotal = s.GetTotalElapsed(); result.timeTotal = s.GetTotalElapsed();
delete vertexStencils;
delete patchTable;
delete refiner;
return result; return result;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
struct PrintOptions {
PrintOptions() :
csvFormat(false),
refineTime(true),
patchTime(true),
stencilTime(true),
appendTime(true),
totalTime(true) { }
bool csvFormat;
bool refineTime;
bool patchTime;
bool stencilTime;
bool appendTime;
bool totalTime;
};
static void
PrintShape(ShapeDesc const & shapeDesc, PrintOptions const & ) {
static char const * g_schemeNames[3] = { "bilinear", "catmark", "loop" };
char const * shapeName = shapeDesc.name.c_str();
Scheme shapeScheme = shapeDesc.scheme;
printf("%s (%s):\n", shapeName, g_schemeNames[shapeScheme]);
}
static void
PrintResult(TestResult const & result, PrintOptions const & options) {
// If only printing the total, combine on same line as level:
if (!options.refineTime && !options.patchTime &&
!options.stencilTime && !options.appendTime) {
printf(" level %d: %f\n", result.level, result.timeTotal);
return;
}
printf(" level %d:\n", result.level);
if (options.refineTime) {
printf(" TopologyRefiner::Refine %f %5.2f%%\n",
result.timeRefine,
result.timeRefine/result.timeTotal*100);
}
if (options.patchTime) {
printf(" PatchTableFactory::Create %f %5.2f%%\n",
result.timePatchFactory,
result.timePatchFactory/result.timeTotal*100);
}
if (options.stencilTime) {
printf(" StencilTableFactory::Create %f %5.2f%%\n",
result.timeStencilFactory,
result.timeStencilFactory/result.timeTotal*100);
}
if (options.appendTime) {
printf(" StencilTableFactory::Append %f %5.2f%%\n",
result.timeAppendStencil,
result.timeAppendStencil/result.timeTotal*100);
}
if (options.totalTime) {
printf(" Total %f\n",
result.timeTotal);
}
}
static void
PrintHeaderCSV(PrintOptions const & options) {
// spreadsheet header row
printf("shape");
printf(",level");
if (options.refineTime) printf(",refine");
if (options.patchTime) printf(",patch");
if (options.stencilTime) printf(",stencilFactory");
if (options.appendTime) printf(",stencilAppend");
if (options.totalTime) printf(",total");
printf("\n");
}
static void
PrintResultCSV(TestResult const & result, PrintOptions const & options) {
// spreadsheet data row
printf("%s", result.name.c_str());
printf(",%d", result.level);
if (options.refineTime) printf(",%f", result.timeRefine);
if (options.patchTime) printf(",%f", result.timePatchFactory);
if (options.stencilTime) printf(",%f", result.timeStencilFactory);
if (options.appendTime) printf(",%f", result.timeAppendStencil);
if (options.totalTime) printf(",%f", result.timeTotal);
printf("\n");
}
//------------------------------------------------------------------------------
static int static int
parseIntArg(char const * argString, int dfltValue = 0) { parseIntArg(char const * argString, int dfltValue = 0) {
char *argEndptr; char *argEndptr;
int argValue = strtol(argString, &argEndptr, 10); int argValue = strtol(argString, &argEndptr, 10);
if (*argEndptr != 0) { if (*argEndptr != 0) {
printf("Warning: non-integer option parameter '%s' ignored\n", fprintf(stderr,
argString); "Warning: non-integer option parameter '%s' ignored\n",
argString);
argValue = dfltValue; argValue = dfltValue;
} }
return argValue; return argValue;
@ -155,30 +285,23 @@ parseIntArg(char const * argString, int dfltValue = 0) {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
bool adaptive = true; TestOptions testOptions;
int level = 8; PrintOptions printOptions;
std::vector<std::string> objFiles;
Scheme defaultScheme = kCatmark; Scheme defaultScheme = kCatmark;
Far::PatchTableFactory::Options::EndCapType endCapType = int minLevel = 1;
Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS; int maxLevel = 2;
bool runDouble = false; bool runDouble = false;
bool spreadsheet = false;
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
if (strstr(argv[i], ".obj")) { if (strstr(argv[i], ".obj")) {
std::ifstream ifs(argv[i]); objFiles.push_back(std::string(argv[i]));
if (ifs) {
std::stringstream ss;
ss << ifs.rdbuf();
ifs.close();
g_shapes.push_back(
ShapeDesc(argv[i], ss.str(), defaultScheme));
}
} else if (!strcmp(argv[i], "-a")) { } else if (!strcmp(argv[i], "-a")) {
adaptive = true; testOptions.refineAdaptive = true;
} else if (!strcmp(argv[i], "-u")) { } else if (!strcmp(argv[i], "-u")) {
adaptive = false; testOptions.refineAdaptive = false;
} else if (!strcmp(argv[i], "-l")) { } else if (!strcmp(argv[i], "-l")) {
if (++i < argc) level = parseIntArg(argv[i], 8); if (++i < argc) maxLevel = parseIntArg(argv[i], maxLevel);
} else if (!strcmp(argv[i], "-bilinear")) { } else if (!strcmp(argv[i], "-bilinear")) {
defaultScheme = kBilinear; defaultScheme = kBilinear;
} else if (!strcmp(argv[i], "-catmark")) { } else if (!strcmp(argv[i], "-catmark")) {
@ -188,22 +311,57 @@ int main(int argc, char **argv)
} else if (!strcmp(argv[i], "-e")) { } else if (!strcmp(argv[i], "-e")) {
char const * type = argv[++i]; char const * type = argv[++i];
if (!strcmp(type, "linear")) { if (!strcmp(type, "linear")) {
endCapType = testOptions.endCapType =
Far::PatchTableFactory::Options::ENDCAP_BILINEAR_BASIS; Far::PatchTableFactory::Options::ENDCAP_BILINEAR_BASIS;
} else if (!strcmp(type, "regular")) { } else if (!strcmp(type, "regular")) {
endCapType = testOptions.endCapType =
Far::PatchTableFactory::Options::ENDCAP_BSPLINE_BASIS; Far::PatchTableFactory::Options::ENDCAP_BSPLINE_BASIS;
} else if (!strcmp(type, "gregory")) { } else if (!strcmp(type, "gregory")) {
endCapType = testOptions.endCapType =
Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS; Far::PatchTableFactory::Options::ENDCAP_GREGORY_BASIS;
} else { } else {
printf("Unknown endcap type %s\n", type); fprintf(stderr, "Error: Unknown endcap type %s\n", type);
return 1; return 1;
} }
} else if (!strcmp(argv[i], "-double")) { } else if (!strcmp(argv[i], "-double")) {
runDouble = true; runDouble = true;
} else if (!strcmp(argv[i], "-spreadsheet")) { } else if (!strcmp(argv[i], "-nopatches")) {
spreadsheet = true; testOptions.createPatches = false;
printOptions.patchTime = false;
printOptions.appendTime = false;
} else if (!strcmp(argv[i], "-nostencils")) {
testOptions.createStencils = false;
printOptions.stencilTime = false;
printOptions.appendTime = false;
} else if (!strcmp(argv[i], "-total")) {
printOptions.refineTime = false;
printOptions.patchTime = false;
printOptions.stencilTime = false;
printOptions.appendTime = false;
} else if (!strcmp(argv[i], "-csv")) {
printOptions.csvFormat = true;
} else {
fprintf(stderr,
"Warning: unrecognized argument '%s' ignored\n", argv[i]);
}
}
assert(minLevel <= maxLevel);
if (!objFiles.empty()) {
for (size_t i = 0; i < objFiles.size(); ++i) {
char const * objFile = objFiles[i].c_str();
std::ifstream ifs(objFile);
if (ifs) {
std::stringstream ss;
ss << ifs.rdbuf();
ifs.close();
g_shapes.push_back(ShapeDesc(objFile, ss.str(), defaultScheme));
} else {
fprintf(stderr,
"Warning: cannot open shape file '%s'\n", objFile);
}
} }
} }
@ -211,67 +369,38 @@ int main(int argc, char **argv)
initShapes(); initShapes();
} }
std::vector< std::vector<Result> > resultsByLevel(level+1); // For each shape, run tests for all specified levels -- printing the
// results in the specified format:
for (int i = 0; i < (int)g_shapes.size(); ++i) { //
std::string const & name = g_shapes[i].name; if (printOptions.csvFormat) {
Shape const * shape = Shape::parseObj(g_shapes[i]); PrintHeaderCSV(printOptions);
for (int lv = 1; lv <= level; ++lv) {
Result result;
if (runDouble) {
result = doPerf<double>(name, shape, lv, adaptive, endCapType);
} else {
result = doPerf<float>(name, shape, lv, adaptive, endCapType);
}
printf("---- %s, level %d ----\n", result.name.c_str(), lv);
printf("TopologyRefiner::Refine %f %5.2f%%\n",
result.timeRefine,
result.timeRefine/result.timeTotal*100);
printf("StencilTableFactory::Create %f %5.2f%%\n",
result.timeStencilFactory,
result.timeStencilFactory/result.timeTotal*100);
printf("PatchTableFactory::Create %f %5.2f%%\n",
result.timePatchFactory,
result.timePatchFactory/result.timeTotal*100);
printf("StencilTableFactory::Append %f %5.2f%%\n",
result.timeAppendStencil,
result.timeAppendStencil/result.timeTotal*100);
printf("Total %f\n",
result.timeTotal);
if (spreadsheet) {
resultsByLevel[lv].push_back(result);
}
}
} }
if (spreadsheet) { for (size_t i = 0; i < g_shapes.size(); ++i) {
for (int lv=1; lv<(int)resultsByLevel.size(); ++lv) { ShapeDesc const & shapeDesc = g_shapes[i];
std::vector<Result> const & results = resultsByLevel[lv]; Shape const * shape = Shape::parseObj(shapeDesc);
if (lv == 1) {
// spreadsheet header row if (!printOptions.csvFormat) {
printf("level,"); PrintShape(shapeDesc, printOptions);
for (int s=0; s<(int)results.size(); ++s) {
Result const & result = results[s];
printf("%s total,", result.name.c_str());
printf("%s refine,", result.name.c_str());
printf("%s patchFactory,", result.name.c_str());
printf("%s stencilFactory,", result.name.c_str());
printf("%s stencilAppend,", result.name.c_str());
}
printf("\n");
}
// spreadsheet data row
printf("%d,", lv);
for (int s=0; s<(int)results.size(); ++s) {
Result const & result = results[s];
printf("%f,", result.timeTotal);
printf("%f,", result.timeRefine);
printf("%f,", result.timePatchFactory);
printf("%f,", result.timeStencilFactory);
printf("%f,", result.timeAppendStencil);
}
printf("\n");
} }
for (int levelIndex = minLevel; levelIndex <= maxLevel; ++levelIndex) {
testOptions.refineLevel = levelIndex;
TestResult result;
if (runDouble) {
result = RunPerfTest<double>(*shape, testOptions);
} else {
result = RunPerfTest<float>(*shape, testOptions);
}
result.name = shapeDesc.name;
if (printOptions.csvFormat) {
PrintResultCSV(result, printOptions);
} else {
PrintResult(result, printOptions);
}
}
delete shape;
} }
} }