Skip to content

Commit

Permalink
added benchamrk to test refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
mkstoyanov committed Mar 20, 2024
1 parent ef62603 commit 23c80e1
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
16 changes: 14 additions & 2 deletions SparseGrids/Benchmarks/benchCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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{
Expand Down Expand Up @@ -68,6 +70,11 @@ template<typename StringListIterator>
void readEntry(StringListIterator &iter, int &val){
val = std::stoi(*iter++);
}
//! \brief Convert a string to double and advance the iterator.
template<typename StringListIterator>
void readEntry(StringListIterator &iter, double &val){
val = std::stod(*iter++);
}
//! \brief Convert a string to TypeDepth and advance the iterator.
template<typename StringListIterator>
void readEntry(StringListIterator &iter, TypeDepth &val){
Expand All @@ -78,6 +85,11 @@ template<typename StringListIterator>
void readEntry(StringListIterator &iter, TypeOneDRule &val){
val = IO::getRuleString(*iter++);
}
//! \brief Convert a string to TypeRefinement and advance the iterator.
template<typename StringListIterator>
void readEntry(StringListIterator &iter, TypeRefinement &val){
val = IO::getTypeRefinementString(*iter++);
}
//! \brief Convert a string to TypeAcceleration and advance the iterator.
template<typename StringListIterator>
void readEntry(StringListIterator &iter, TypeAcceleration &val){
Expand Down
59 changes: 59 additions & 0 deletions SparseGrids/Benchmarks/benchRefine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef _TASMANIAN_BENCHMARK_REFINE_HPP
#define _TASMANIAN_BENCHMARK_REFINE_HPP

#include "benchCommon.hpp"

bool benchmark_refine(std::deque<std::string> &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<DryRun>(iteratons, test_lambda) << endl;

return true;
}

#endif
27 changes: 26 additions & 1 deletion SparseGrids/Benchmarks/bench_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "benchEvaluate.hpp"
#include "benchDifferentiate.hpp"
#include "benchInterpolationWeights.hpp"
#include "benchRefine.hpp"

void printHelp(BenchFuction test);

Expand Down Expand Up @@ -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!");
}
Expand All @@ -55,7 +59,7 @@ int main(int argc, const char** argv){
void printHelp(BenchFuction test){
if (test == bench_none){
cout << "\nusage: ./benchmark <function> <parameters>\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 <function> help\n";
}else if (test == bench_make){
cout << "\nusage: ./benchmark makegrid <grid> <dims> <depth> <type> <rule> <iters> <jumps> <aniso>\n\n";
Expand Down Expand Up @@ -124,6 +128,27 @@ void printHelp(BenchFuction test){
cout << "jumps : how many times to increase <depth> 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 <grid> <dims> <outs> <depth> <type> <rule> <order> <ref-type-depth> <min-growth> <surp-tolerance> <surp-criteria> <output> <iters> <acc> <gpu> <extra>\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;
}
1 change: 1 addition & 0 deletions SparseGrids/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion SparseGrids/tsgGridLocalPolynomial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,6 @@ Data2D<int> GridLocalPolynomial::buildUpdateMap(double tolerance, TypeRefinement
int nump = split.getJobNumPoints(j);
const int *pnts = split.getJobPoints(j);


std::vector<int> levels(nump);

int max_level = 0;
Expand Down

0 comments on commit 23c80e1

Please sign in to comment.