From e84a66c6a456badc2e26eac523545e71627e8fe5 Mon Sep 17 00:00:00 2001 From: Brian Manh Hien Han Date: Tue, 17 Sep 2024 14:25:45 -0700 Subject: [PATCH 1/2] Add caliper annotations to quest_candidates_example --- .../examples/quest_candidates_example.cpp | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/axom/quest/examples/quest_candidates_example.cpp b/src/axom/quest/examples/quest_candidates_example.cpp index 328fad64d3..9a7c33b452 100644 --- a/src/axom/quest/examples/quest_candidates_example.cpp +++ b/src/axom/quest/examples/quest_candidates_example.cpp @@ -116,6 +116,7 @@ struct Input int resolution {0}; bool verboseOutput {false}; RuntimePolicy policy {RuntimePolicy::seq}; + std::string annotationMode {"none"}; void parse(int argc, char** argv, axom::CLI::App& app); bool isVerbose() const { return verboseOutput; } @@ -175,6 +176,15 @@ void Input::parse(int argc, char** argv, axom::CLI::App& app) ->capture_default_str() ->check(axom::CLI::IsMember {Input::s_validMethods}); +#ifdef AXOM_USE_CALIPER + app.add_option("--caliper", annotationMode) + ->description( + "caliper annotation mode. Valid options include 'none' and 'report'. " + "Use 'help' to see full list.") + ->capture_default_str() + ->check(axom::utilities::ValidCaliperMode); +#endif + app.get_formatter()->column_width(40); app.parse(argc, argv); // Could throw an exception @@ -252,6 +262,8 @@ template HexMesh loadBlueprintHexMesh(const std::string& mesh_path, bool verboseOutput = false) { + AXOM_ANNOTATE_SCOPE("load Blueprint hexahedron mesh"); + using HexArray = axom::Array; using BBoxArray = axom::Array; constexpr bool on_device = axom::execution_space::onDevice(); @@ -434,6 +446,7 @@ template axom::Array findCandidatesBVH(const HexMesh& insertMesh, const HexMesh& queryMesh) { + AXOM_ANNOTATE_BEGIN("initializing BVH"); axom::utilities::Timer timer; timer.start(); @@ -463,8 +476,10 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, timer.stop(); SLIC_INFO(axom::fmt::format("0: Initializing BVH took {:4.3} seconds.", timer.elapsedTimeInSec())); + AXOM_ANNOTATE_END("initializing BVH"); // Search for candidate bounding boxes of hexes to query; + AXOM_ANNOTATE_BEGIN("query candidates"); timer.start(); IndexArray offsets_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); IndexArray counts_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); @@ -482,6 +497,9 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, SLIC_INFO(axom::fmt::format( "1: Querying candidate bounding boxes took {:4.3} seconds.", timer.elapsedTimeInSec())); + AXOM_ANNOTATE_END("query candidates"); + + AXOM_ANNOTATE_BEGIN("write candidate pairs"); timer.start(); // Initialize candidate pairs on device. @@ -512,9 +530,12 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, SLIC_INFO(axom::fmt::format( "2: Initializing candidate pairs (on device) took {:4.3} seconds.", timer.elapsedTimeInSec())); - timer.start(); + AXOM_ANNOTATE_END("write candidate pairs"); // copy pairs back to host and into return array + AXOM_ANNOTATE_BEGIN("copy pairs to host"); + timer.start(); + IndexArray candidates_h[2] = { on_device ? IndexArray(firstPair_d, host_allocator) : IndexArray(), on_device ? IndexArray(secondPair_d, host_allocator) : IndexArray()}; @@ -544,6 +565,7 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, queryMesh.numHexes(), 1.0 * insertMesh.numHexes() * queryMesh.numHexes(), candidatePairs.size())); + AXOM_ANNOTATE_END("copy pairs to host"); return candidatePairs; } // end of findCandidatesBVH for Blueprint Meshes @@ -553,6 +575,7 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, const HexMesh& queryMesh, int resolution) { + AXOM_ANNOTATE_BEGIN("initializing implicit grid"); axom::utilities::Timer timer; timer.start(); @@ -596,7 +619,9 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, SLIC_INFO( axom::fmt::format("0: Initializing Implicit Grid took {:4.3} seconds.", timer.elapsedTimeInSec())); + AXOM_ANNOTATE_END("initializing implicit grid"); + AXOM_ANNOTATE_BEGIN("query candidates"); timer.start(); IndexArray offsets_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); IndexArray counts_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); @@ -641,6 +666,9 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, SLIC_INFO(axom::fmt::format( "1: Querying candidate bounding boxes took {:4.3} seconds.", timer.elapsedTimeInSec())); + AXOM_ANNOTATE_END("query candidates"); + + AXOM_ANNOTATE_BEGIN("write candidate pairs"); timer.start(); // Generate offsets from the counts @@ -692,8 +720,10 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, SLIC_INFO(axom::fmt::format( "2: Initializing candidate pairs (on device) took {:4.3} seconds.", timer.elapsedTimeInSec())); + AXOM_ANNOTATE_END("write candidate pairs"); // copy results back to host and into return vector + AXOM_ANNOTATE_BEGIN("copy pairs to host"); timer.start(); IndexArray candidates_h[2] = { @@ -726,6 +756,7 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, queryMesh.numHexes(), 1.0 * insertMesh.numHexes() * queryMesh.numHexes(), candidatePairs.size())); + AXOM_ANNOTATE_END("copy pairs to host"); return candidatePairs; } @@ -749,6 +780,11 @@ int main(int argc, char** argv) } } + axom::utilities::raii::AnnotationsWrapper annotation_raii_wrapper( + params.annotationMode); + AXOM_ANNOTATE_SCOPE("quest candidates example"); + + AXOM_ANNOTATE_BEGIN("load Blueprint meshes"); axom::utilities::Timer timer(true); // Update the logging level based on verbosity flag @@ -823,7 +859,9 @@ int main(int argc, char** argv) SLIC_INFO(axom::fmt::format("Reading in Blueprint files took {:4.3} seconds.", timer.elapsedTimeInSec())); + AXOM_ANNOTATE_END("load Blueprint meshes"); + AXOM_ANNOTATE_BEGIN("find candidates"); // Check for candidates; results are returned as an array of index pairs axom::Array candidatePairs; timer.start(); @@ -922,6 +960,7 @@ int main(int argc, char** argv) << std::endl; } } + AXOM_ANNOTATE_END("find candidates"); return 0; } From 6a17af445d498f641b7b276bc08f310d7ff48c71 Mon Sep 17 00:00:00 2001 From: Brian Manh Hien Han Date: Mon, 23 Sep 2024 13:06:54 -0700 Subject: [PATCH 2/2] Return candidate pairs as std::vector instead of axom::Array for speedup, remove Timer usage --- .../examples/quest_candidates_example.cpp | 84 +++++-------------- 1 file changed, 19 insertions(+), 65 deletions(-) diff --git a/src/axom/quest/examples/quest_candidates_example.cpp b/src/axom/quest/examples/quest_candidates_example.cpp index 9a7c33b452..4da5867493 100644 --- a/src/axom/quest/examples/quest_candidates_example.cpp +++ b/src/axom/quest/examples/quest_candidates_example.cpp @@ -428,12 +428,7 @@ HexMesh loadBlueprintHexMesh(const std::string& mesh_path, // Write out to vtk for test viewing SLIC_INFO("Writing out Blueprint mesh to test.vtk for debugging..."); - axom::utilities::Timer timer(true); axom::mint::write_vtk(mesh, "test.vtk"); - timer.stop(); - SLIC_INFO(axom::fmt::format( - "Writing out Blueprint mesh to test.vtk took {:4.3} seconds.", - timer.elapsedTimeInSec())); delete mesh; mesh = nullptr; @@ -443,12 +438,10 @@ HexMesh loadBlueprintHexMesh(const std::string& mesh_path, } // end of loadBlueprintHexMesh template -axom::Array findCandidatesBVH(const HexMesh& insertMesh, +std::vector findCandidatesBVH(const HexMesh& insertMesh, const HexMesh& queryMesh) { AXOM_ANNOTATE_BEGIN("initializing BVH"); - axom::utilities::Timer timer; - timer.start(); SLIC_INFO("Running BVH candidates algorithm in execution Space: " << axom::execution_space::name()); @@ -456,7 +449,7 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, using IndexArray = axom::Array; constexpr bool on_device = axom::execution_space::onDevice(); - axom::Array candidatePairs; + std::vector candidatePairs; // Get ids of necessary allocators const int host_allocator = @@ -473,14 +466,11 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, axom::spin::BVH<3, ExecSpace, double> bvh; bvh.setAllocatorID(kernel_allocator); bvh.initialize(insert_bbox_v, insert_bbox_v.size()); - timer.stop(); - SLIC_INFO(axom::fmt::format("0: Initializing BVH took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("0: Initialized BVH.")); AXOM_ANNOTATE_END("initializing BVH"); // Search for candidate bounding boxes of hexes to query; AXOM_ANNOTATE_BEGIN("query candidates"); - timer.start(); IndexArray offsets_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); IndexArray counts_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); IndexArray candidates_d(0, 0, kernel_allocator); @@ -493,14 +483,10 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, query_bbox_v.size(), query_bbox_v); - timer.stop(); - SLIC_INFO(axom::fmt::format( - "1: Querying candidate bounding boxes took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("1: Queried candidate bounding boxes.")); AXOM_ANNOTATE_END("query candidates"); AXOM_ANNOTATE_BEGIN("write candidate pairs"); - timer.start(); // Initialize candidate pairs on device. auto candidates_v = candidates_d.view(); @@ -526,15 +512,11 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, } }); - timer.stop(); - SLIC_INFO(axom::fmt::format( - "2: Initializing candidate pairs (on device) took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("2: Initialized candidate pairs (on device).")); AXOM_ANNOTATE_END("write candidate pairs"); // copy pairs back to host and into return array AXOM_ANNOTATE_BEGIN("copy pairs to host"); - timer.start(); IndexArray candidates_h[2] = { on_device ? IndexArray(firstPair_d, host_allocator) : IndexArray(), @@ -543,16 +525,14 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, auto candidate1_h_v = on_device ? candidates_h[0].view() : firstPair_d.view(); auto candidate2_h_v = on_device ? candidates_h[1].view() : secondPair_d.view(); - for(int idx = 0; idx < candidates_v.size(); ++idx) + candidatePairs.reserve(candidates_v.size()); + for(axom::IndexType idx = 0; idx < candidates_v.size(); ++idx) { candidatePairs.emplace_back( std::make_pair(candidate1_h_v[idx], candidate2_h_v[idx])); } - timer.stop(); - SLIC_INFO( - axom::fmt::format("3: Moving candidate pairs to host took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("3: Moved candidate pairs to host.")); SLIC_INFO(axom::fmt::format(axom::utilities::locale(), R"(Stats for query @@ -571,15 +551,13 @@ axom::Array findCandidatesBVH(const HexMesh& insertMesh, } // end of findCandidatesBVH for Blueprint Meshes template -axom::Array findCandidatesImplicit(const HexMesh& insertMesh, +std::vector findCandidatesImplicit(const HexMesh& insertMesh, const HexMesh& queryMesh, int resolution) { AXOM_ANNOTATE_BEGIN("initializing implicit grid"); - axom::utilities::Timer timer; - timer.start(); - axom::Array candidatePairs; + std::vector candidatePairs; SLIC_INFO("Running Implicit Grid candidates algorithm in execution Space: " << axom::execution_space::name()); @@ -615,14 +593,10 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, insertMesh.numHexes(), kernel_allocator); gridIndex.insert(insertMesh.numHexes(), insert_bbox_v.data()); - timer.stop(); - SLIC_INFO( - axom::fmt::format("0: Initializing Implicit Grid took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("0: Initialized Implicit Grid.")); AXOM_ANNOTATE_END("initializing implicit grid"); AXOM_ANNOTATE_BEGIN("query candidates"); - timer.start(); IndexArray offsets_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); IndexArray counts_d(query_bbox_v.size(), query_bbox_v.size(), kernel_allocator); @@ -662,14 +636,10 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, totalCandidatePairs += count; }); - timer.stop(); - SLIC_INFO(axom::fmt::format( - "1: Querying candidate bounding boxes took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("1: Queried candidate bounding boxes.")); AXOM_ANNOTATE_END("query candidates"); AXOM_ANNOTATE_BEGIN("write candidate pairs"); - timer.start(); // Generate offsets from the counts // (Note: exclusive scan for offsets in candidate array @@ -715,16 +685,11 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, grid_device.visitCandidates(query_bbox_v[icell], fillCandidates); }); - timer.stop(); - - SLIC_INFO(axom::fmt::format( - "2: Initializing candidate pairs (on device) took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("2: Initialized candidate pairs (on device).")); AXOM_ANNOTATE_END("write candidate pairs"); // copy results back to host and into return vector AXOM_ANNOTATE_BEGIN("copy pairs to host"); - timer.start(); IndexArray candidates_h[2] = { on_device ? IndexArray(firstPair_d, host_allocator) : IndexArray(), @@ -733,17 +698,14 @@ axom::Array findCandidatesImplicit(const HexMesh& insertMesh, auto candidate1_h_v = on_device ? candidates_h[0].view() : firstPair_d.view(); auto candidate2_h_v = on_device ? candidates_h[1].view() : secondPair_d.view(); - for(int idx = 0; idx < totalCandidatePairs; ++idx) + candidatePairs.reserve(totalCandidatePairs.get()); + for(axom::IndexType idx = 0; idx < totalCandidatePairs.get(); ++idx) { candidatePairs.emplace_back( std::make_pair(candidate1_h_v[idx], candidate2_h_v[idx])); } - timer.stop(); - - SLIC_INFO( - axom::fmt::format("3: Moving candidate pairs to host took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("3: Moved candidate pairs to host.")); SLIC_INFO(axom::fmt::format(axom::utilities::locale(), R"(Stats for query @@ -785,7 +747,6 @@ int main(int argc, char** argv) AXOM_ANNOTATE_SCOPE("quest candidates example"); AXOM_ANNOTATE_BEGIN("load Blueprint meshes"); - axom::utilities::Timer timer(true); // Update the logging level based on verbosity flag axom::slic::setLoggingMsgLevel(params.isVerbose() ? axom::slic::message::Debug @@ -855,16 +816,12 @@ int main(int argc, char** argv) break; } - timer.stop(); - - SLIC_INFO(axom::fmt::format("Reading in Blueprint files took {:4.3} seconds.", - timer.elapsedTimeInSec())); + SLIC_INFO(axom::fmt::format("Finished reading in Blueprint files.")); AXOM_ANNOTATE_END("load Blueprint meshes"); AXOM_ANNOTATE_BEGIN("find candidates"); // Check for candidates; results are returned as an array of index pairs - axom::Array candidatePairs; - timer.start(); + std::vector candidatePairs; if(params.method == "bvh") { @@ -923,10 +880,7 @@ int main(int argc, char** argv) break; } } - timer.stop(); - SLIC_INFO(axom::fmt::format("Computing candidates took {:4.3} seconds.", - timer.elapsedTimeInSec())); SLIC_INFO(axom::fmt::format(axom::utilities::locale(), "Mesh had {:L} candidates pairs", candidatePairs.size())); @@ -954,7 +908,7 @@ int main(int argc, char** argv) std::ofstream outf("candidates.txt"); outf << candidatePairs.size() << " candidate pairs:" << std::endl; - for(int i = 0; i < candidatePairs.size(); ++i) + for(unsigned long i = 0; i < candidatePairs.size(); ++i) { outf << candidatePairs[i].first << " " << candidatePairs[i].second << std::endl;