From 23c80e1d7839c510a804e0158820d8164fa355e7 Mon Sep 17 00:00:00 2001 From: Miroslav Stoyanov Date: Wed, 20 Mar 2024 14:23:13 -0400 Subject: [PATCH] added benchamrk to test refinement --- SparseGrids/Benchmarks/benchCommon.hpp | 16 ++++++- SparseGrids/Benchmarks/benchRefine.hpp | 59 ++++++++++++++++++++++++++ SparseGrids/Benchmarks/bench_main.cpp | 27 +++++++++++- SparseGrids/CMakeLists.txt | 1 + SparseGrids/tsgGridLocalPolynomial.cpp | 1 - 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 SparseGrids/Benchmarks/benchRefine.hpp diff --git a/SparseGrids/Benchmarks/benchCommon.hpp b/SparseGrids/Benchmarks/benchCommon.hpp index 557b9d1eb..49048a2a6 100644 --- a/SparseGrids/Benchmarks/benchCommon.hpp +++ b/SparseGrids/Benchmarks/benchCommon.hpp @@ -12,7 +12,8 @@ enum BenchFuction{ bench_evaluate, bench_evaluate_mixed, bench_differentiate, - bench_iweights + bench_iweights, + bench_refine }; BenchFuction getTest(std::string const &s){ @@ -22,7 +23,8 @@ BenchFuction getTest(std::string const &s){ {"differentiate", bench_differentiate}, {"loadneeded", bench_loadneeded}, {"makegrid", bench_make}, - {"iweights", bench_iweights} + {"iweights", bench_iweights}, + {"refine", bench_refine} }; try{ @@ -68,6 +70,11 @@ template void readEntry(StringListIterator &iter, int &val){ val = std::stoi(*iter++); } +//! \brief Convert a string to double and advance the iterator. +template +void readEntry(StringListIterator &iter, double &val){ + val = std::stod(*iter++); +} //! \brief Convert a string to TypeDepth and advance the iterator. template void readEntry(StringListIterator &iter, TypeDepth &val){ @@ -78,6 +85,11 @@ template void readEntry(StringListIterator &iter, TypeOneDRule &val){ val = IO::getRuleString(*iter++); } +//! \brief Convert a string to TypeRefinement and advance the iterator. +template +void readEntry(StringListIterator &iter, TypeRefinement &val){ + val = IO::getTypeRefinementString(*iter++); +} //! \brief Convert a string to TypeAcceleration and advance the iterator. template void readEntry(StringListIterator &iter, TypeAcceleration &val){ diff --git a/SparseGrids/Benchmarks/benchRefine.hpp b/SparseGrids/Benchmarks/benchRefine.hpp new file mode 100644 index 000000000..5c47cbcf2 --- /dev/null +++ b/SparseGrids/Benchmarks/benchRefine.hpp @@ -0,0 +1,59 @@ +#ifndef _TASMANIAN_BENCHMARK_REFINE_HPP +#define _TASMANIAN_BENCHMARK_REFINE_HPP + +#include "benchCommon.hpp" + +bool benchmark_refine(std::deque &args){ + if (args.size() < 15) return false; + + // report the test parameters to reference later + cout << "refine"; + for(auto &s : args) cout << " " << s; + + auto grid_family = getGridFamily(args); + if (grid_family == GridFamily::none) return false; + + int num_dimensions, num_outputs, num_depth, order, iteratons; + TypeDepth dtype; + TypeOneDRule rule; + TypeAcceleration acc; + int device; + + TypeDepth ref_aniso_type; + int aniso_min_growth; + double surp_tolerance; + TypeRefinement surp_criteria; + int output; + + auto riter = readEntries(args.begin(), num_dimensions, num_outputs, num_depth, dtype, rule, order, + ref_aniso_type, aniso_min_growth, surp_tolerance, surp_criteria, output, iteratons, acc, device); + + std::string flavor = checkFlavor(riter, args.end()); + + auto extra = extractWeightsLimits(grid_family, num_dimensions, dtype, riter, args.end()); + + auto make_grid = getLambdaMakeGrid(grid_family, num_dimensions, num_outputs, num_depth, dtype, rule, order, extra); + + auto grid = make_grid(); + cout << " (points: " << grid.getNumPoints() << ")\n"; + loadGenericModel(grid); + + grid.enableAcceleration(acc, device); + if (flavor != "auto") + grid.favorSparseAcceleration((flavor == "sparse")); + + auto test_lambda = [&](int)->void{ + if (aniso_min_growth < 1) { + grid.setSurplusRefinement(surp_tolerance, surp_criteria, output); + } else { + grid.setAnisotropicRefinement(ref_aniso_type, aniso_min_growth, output); + } + }; + + // make one dry-run + cout << setw(7) << testMethod(iteratons, test_lambda) << endl; + + return true; +} + +#endif diff --git a/SparseGrids/Benchmarks/bench_main.cpp b/SparseGrids/Benchmarks/bench_main.cpp index bf8e31ba1..489231063 100644 --- a/SparseGrids/Benchmarks/bench_main.cpp +++ b/SparseGrids/Benchmarks/bench_main.cpp @@ -3,6 +3,7 @@ #include "benchEvaluate.hpp" #include "benchDifferentiate.hpp" #include "benchInterpolationWeights.hpp" +#include "benchRefine.hpp" void printHelp(BenchFuction test); @@ -42,6 +43,9 @@ int main(int argc, const char** argv){ case bench_iweights: pass = benchmark_iweights(args); break; + case bench_refine: + pass = benchmark_refine(args); + break; default: throw std::runtime_error("bench_main.cpp: invalid test type in switch statement!"); } @@ -55,7 +59,7 @@ int main(int argc, const char** argv){ void printHelp(BenchFuction test){ if (test == bench_none){ cout << "\nusage: ./benchmark \n\n"; - cout << "functions: makegrid, loadneeded, evaluate(-mixed), differentiate, iweights\n"; + cout << "functions: makegrid, loadneeded, evaluate(-mixed), differentiate, iweights, refine\n"; cout << "\n see: ./benchmark help\n"; }else if (test == bench_make){ cout << "\nusage: ./benchmark makegrid \n\n"; @@ -124,6 +128,27 @@ void printHelp(BenchFuction test){ cout << "jumps : how many times to increase by 1\n"; cout << "aniso : (optional) list of anisotropic weights and level limits\n"; cout << " : anisotropic weights come first (if used by the grid), then level limits\n"; + }else if (test == bench_refine){ + cout << "\nusage: ./benchmark refine \n\n"; + cout << "grid : global, sequence, localp, wavelet, fourier\n"; + cout << "dims : number of dimensions\n"; + cout << "outs : number of outputs\n"; + cout << "depth : grid density\n"; + cout << "type : level, iptotal, etc.; ignored if not used by the grid\n"; + cout << "rule : rleja, clenshaw-curtis, etc.; ignored for wavelet and fourier grids\n"; + cout << "order : -1, 0, 1, 2; ignored if not used by the grid\n\n"; + + cout << "ref-type-depth : (anisotropic refinement) refinement type, e.g., iptotal, ipcurved\n"; + cout << "min-growth : (anisotropic refinement) minumum number of refinement points, use 0 to switch to surplus refinement\n"; + cout << "surp-tolerance : (surplus refinement) tolerance\n"; + cout << "surp-criteria : (surplus refinement) selection criteria, e.g., stable, fds\n"; + cout << "output : (all refinement) output to use in the refinement\n\n"; + + cout << "iters : number of times to repeat the function call\n"; + cout << "acc : acceleration type, e.g., gpu-cuda, cpu-blas, none, etc.\n"; + cout << "gpu : cuda device ID; ignored for cpu acceleration\n"; + cout << "extra : (optional) list of anisotropic weights and level limits\n"; + cout << " : anisotropic weights come first (if used by the grid), then level limits\n"; } cout << endl; } diff --git a/SparseGrids/CMakeLists.txt b/SparseGrids/CMakeLists.txt index fc55d951d..7bf2c6aaa 100644 --- a/SparseGrids/CMakeLists.txt +++ b/SparseGrids/CMakeLists.txt @@ -91,6 +91,7 @@ add_executable(Tasmanian_benchmarksgrid Benchmarks/benchCommon.hpp Benchmarks/benchLoadNeeded.hpp Benchmarks/benchDifferentiate.hpp Benchmarks/benchEvaluate.hpp + Benchmarks/benchRefine.hpp Benchmarks/bench_main.cpp) if (Tasmanian_ENABLE_CUDA) diff --git a/SparseGrids/tsgGridLocalPolynomial.cpp b/SparseGrids/tsgGridLocalPolynomial.cpp index 8e4afb36e..3d62a71ba 100644 --- a/SparseGrids/tsgGridLocalPolynomial.cpp +++ b/SparseGrids/tsgGridLocalPolynomial.cpp @@ -1273,7 +1273,6 @@ Data2D GridLocalPolynomial::buildUpdateMap(double tolerance, TypeRefinement int nump = split.getJobNumPoints(j); const int *pnts = split.getJobPoints(j); - std::vector levels(nump); int max_level = 0;