From 750304dab3f03ee3a28fc45e4b8b0273e0373224 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:53:22 -0700 Subject: [PATCH 001/107] Create test_sampler.cpp --- tests/sampler/test_sampler.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/sampler/test_sampler.cpp diff --git a/tests/sampler/test_sampler.cpp b/tests/sampler/test_sampler.cpp new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/sampler/test_sampler.cpp @@ -0,0 +1 @@ + From 9dde439c18c9bbf9a5be4fe49e189440fbfe572a Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:54:12 -0700 Subject: [PATCH 002/107] CMakeLists.txt: set up test for sampler --- tests/sampler/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/sampler/CMakeLists.txt diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt new file mode 100644 index 000000000..266ebcbad --- /dev/null +++ b/tests/sampler/CMakeLists.txt @@ -0,0 +1,8 @@ +kp_add_executable_and_test( + TARGET_NAME test_sampling + SOURCE_FILE test_sampler.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_SAMPLER_SKIP 50 + KOKKOS_TOOLS_GLOBALFENCES 1 +) From 64a9f1a912112ac14fe53bad4309ec464c6cb923 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:55:04 -0700 Subject: [PATCH 003/107] test_sampler.cpp: put in code for sampler test --- tests/sampler/test_sampler.cpp | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/sampler/test_sampler.cpp b/tests/sampler/test_sampler.cpp index 8b1378917..88c84fda7 100644 --- a/tests/sampler/test_sampler.cpp +++ b/tests/sampler/test_sampler.cpp @@ -1 +1,66 @@ +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "Kokkos_Core.hpp" + +struct Tester { + template + explicit Tester(const execution_space& space) { + //! Explicitly launch a kernel with a name, and run it 150 times with kernel + //! logger. Use a periodic sampling with skip rate 51. This should print + //! out 2 invocation, and there is a single matcher with a regular + //! expression to check this. + + for (int iter = 0; iter < 150; iter++) { + Kokkos::parallel_for("named kernel", + Kokkos::RangePolicy(space, 0, 1), + *this); + } + } + + KOKKOS_FUNCTION void operator()(const int) const {} +}; + +static const std::vector matchers{ + "(.*)KokkosP: sample 51 calling child-begin function...(.*)", + "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", + "(.*)KokkosP: sample 51 calling child-end function...(.*)", + "(.*)KokkosP: sample 51 calling child-end function.(.*)", + "(.*)KokkosP: sample 102 calling child-begin function...(.*)", + "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", + "(.*)KokkosP: sample 102 calling child-end function...(.*)", + "(.*)KokkosP: sample 102 calling child-end function.(.*)"}; + +/** + * @test This test checks that the tool effectively samples. + * + + */ +TEST(SamplerTest, ktoEnvVarDefault) { + //! Initialize @c Kokkos. + Kokkos::initialize(); + + //! Redirect output for later analysis. + std::cout.flush(); + std::ostringstream output; + std::streambuf* coutbuf = std::cout.rdbuf(output.rdbuf()); + + //! Run tests. @todo Replace this with Google Test. + Tester tester(Kokkos::DefaultExecutionSpace{}); + + //! Finalize @c Kokkos. + Kokkos::finalize(); + + //! Restore output buffer. + // std::cout.flush(); + std::cout.rdbuf(coutbuf); + std::cout << output.str() << std::endl; + + //! Analyze test output. + for (const auto& matcher : matchers) { + EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); + } // end TEST +} From 99d589daad468516efbf0144cfc69342bd9ece4e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:58:32 -0700 Subject: [PATCH 004/107] test_sampler.cpp: typo in comment (2 invocation --> 2 invocations) --- tests/sampler/test_sampler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_sampler.cpp b/tests/sampler/test_sampler.cpp index 88c84fda7..224500ef7 100644 --- a/tests/sampler/test_sampler.cpp +++ b/tests/sampler/test_sampler.cpp @@ -11,7 +11,7 @@ struct Tester { explicit Tester(const execution_space& space) { //! Explicitly launch a kernel with a name, and run it 150 times with kernel //! logger. Use a periodic sampling with skip rate 51. This should print - //! out 2 invocation, and there is a single matcher with a regular + //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. for (int iter = 0; iter < 150; iter++) { From d13efe8c0c73a1e07a94eea18fad238635acaaaf Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:00:21 -0700 Subject: [PATCH 005/107] CMakeLists.txt: support sampler test --- tests/CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 65ec02fe0..e6543edcb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,11 +5,14 @@ # Arguments: # TARGET_NAME : name of the test (required) # SOURCE_FILE : source file, defaults to .cpp (optional) -# KOKKOS_TOOLS_LIBS : the test environment will received the variable 'KOKKOS_TOOLS_LIBS' that is set as the path +# KOKKOS_TOOLS_LIBS : the test environment will receive the variable 'KOKKOS_TOOLS_LIBS' that is set as the path # to the target file of this argument (optional) -function(kp_add_executable_and_test) +# KOKKOS_TOOLS_SAMPLER_VERBOSE : the test environment will receive the variable 'KOKKOS_TOOLS_SAMPLER_VERBOSE' that is set as the value of 1 for printing the sample has been taken +# KOKKOS_TOOLS_GLOBALFENCES : test environment receives the variable 'KOKKOS_TOOLS_GLOBALFENCES' that is set as the value of 1 to turn the tool's auto-fencing on. +# KOKKOS_TOOLS_SAMPLER_SKIP : test environment receives the variable 'KOKKOS_TOOLS_SAMPLER_SKIP' that is set as the value of the number of Kokkos kernel invocations to skip before a tooling activity is invoked. - cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS" "" ${ARGN}) +function(kp_add_executable_and_test) + cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES;KOKKOS_TOOLS_SAMPLER_SKIP" "KOKKOS_TOOLS_LIBS" ${ARGN}) if(NOT DEFINED kaeat_args_TARGET_NAME) message(FATAL_ERROR "'TARGET_NAME' is a required argument.") @@ -38,13 +41,45 @@ function(kp_add_executable_and_test) ) if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS) + set(TOOL_LIBS_FILES) + foreach(TOOL_LIB ${kaeat_args_KOKKOS_TOOLS_LIBS}) + list(APPEND TOOL_LIBS_FILES "$") + endforeach() + string(REPLACE ";" "\;" TOOL_LIBS_FILES "${TOOL_LIBS_FILES}") + set_property( TEST ${kaeat_args_TARGET_NAME} - APPEND - PROPERTY - ENVIRONMENT "KOKKOS_TOOLS_LIBS=$" + APPEND PROPERTY ENVIRONMENT "KOKKOS_TOOLS_LIBS=${TOOL_LIBS_FILES}" ) endif() + + if(DEFINED kaeat_args_KOKKOS_TOOLS_SAMPLER_VERBOSE) + set_property( + TEST ${kaeat_args_TARGET_NAME} + APPEND + PROPERTY + ENVIRONMENT "KOKKOS_TOOLS_SAMPLER_VERBOSE=${kaeat_args_KOKKOS_TOOLS_SAMPLER_VERBOSE}" + ) + endif() + + if(DEFINED kaeat_args_KOKKOS_TOOLS_GLOBALFENCES) + set_property( + TEST ${kaeat_args_TARGET_NAME} + APPEND + PROPERTY + ENVIRONMENT "KOKKOS_TOOLS_GLOBALFENCES=${kaeat_args_KOKKOS_TOOLS_GLOBALFENCES}" + ) + endif() + + if (DEFINED kaeat_args_KOKKOS_TOOLS_SAMPLER_SKIP) + set_property( + TEST ${kaeat_args_TARGET_NAME} + APPEND + PROPERTY + ENVIRONMENT "KOKKOS_TOOLS_SAMPLER_SKIP=${kaeat_args_KOKKOS_TOOLS_SAMPLER_SKIP}" + ) + + endif() endfunction(kp_add_executable_and_test) @@ -59,3 +94,4 @@ target_sources( target_link_libraries(test_common PUBLIC GTest::gtest GTest::gmock Kokkos::kokkos) add_subdirectory(space-time-stack) +add_subdirectory(sampler) From d1673d46855076f963270fe3297c8ab3918e80c5 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:30:57 -0700 Subject: [PATCH 006/107] kp_sampler_skip.cpp: change printf to std::out for ctests --- common/kokkos-sampler/kp_sampler_skip.cpp | 57 ++++++++++++++++------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 81401ff31..c24ee6bc4 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -194,16 +194,20 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, static uint64_t invocationNum = 0; ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { - if (tool_verbosity > 0) { - printf("KokkosP: sample %llu calling child-begin function...\n", - (unsigned long long)(*kID)); - } + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function..." << std::endl; + } if (tool_globFence) { invoke_ktools_fence(0); } if (NULL != beginForCallee) { uint64_t nestedkID = 0; (*beginForCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " called child-begin function." << std::endl; + } infokIDSample.insert({*kID, nestedkID}); } } @@ -214,13 +218,18 @@ void kokkosp_end_parallel_for(const uint64_t kID) { if (!(infokIDSample.find(kID) == infokIDSample.end())) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { - printf("KokkosP: sample %llu calling child-end function...\n", - (unsigned long long)(kID)); + std::cout << "KokkosP: sample " << kID + << " calling child-end function..." << std::endl; } + if (tool_globFence) { invoke_ktools_fence(0); } (*endForCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " called child-end function." << std::endl; + } infokIDSample.erase(kID); } } @@ -233,8 +242,8 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { if (tool_verbosity > 0) { - printf("KokkosP: sample %llu calling child-begin function...\n", - (unsigned long long)(*kID)); + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function..." << std::endl; } if (NULL != beginScanCallee) { uint64_t nestedkID = 0; @@ -242,6 +251,10 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, invoke_ktools_fence(0); } (*beginScanCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " called child-begin function." << std::endl; + } infokIDSample.insert({*kID, nestedkID}); } } @@ -252,13 +265,17 @@ void kokkosp_end_parallel_scan(const uint64_t kID) { if (!(infokIDSample.find(kID) == infokIDSample.end())) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { - printf("KokkosP: sample %llu calling child-end function...\n", - (unsigned long long)(kID)); + std::cout << "KokkosP: sample " << kID + << " calling child-end function..." << std::endl; } if (tool_globFence) { invoke_ktools_fence(0); } (*endScanCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " called child-end function." << std::endl; + } infokIDSample.erase(kID); } } @@ -271,8 +288,8 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { if (tool_verbosity > 0) { - printf("KokkosP: sample %llu calling child-begin function...\n", - (unsigned long long)(*kID)); + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function..." << std::endl; } if (NULL != beginReduceCallee) { uint64_t nestedkID = 0; @@ -280,23 +297,31 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, invoke_ktools_fence(0); } (*beginReduceCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " called child-begin function." << std::endl; + } infokIDSample.insert({*kID, nestedkID}); } } } void kokkosp_end_parallel_reduce(const uint64_t kID) { - if (NULL != endScanCallee) { + if (NULL != endReduceCallee) { if (!(infokIDSample.find(kID) == infokIDSample.end())) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { - printf("KokkosP: sample %llu calling child-end function...\n", - (unsigned long long)(kID)); + std::cout << "KokkosP: sample " << kID + << " calling child-end function..." << std::endl; } if (tool_globFence) { invoke_ktools_fence(0); } - (*endScanCallee)(retrievedNestedkID); + (*endReduceCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " called child-end function." << std::endl; + } infokIDSample.erase(kID); } } From 51c209462b438fbc65f8d785173630bb9d4bb3a8 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:32:32 -0700 Subject: [PATCH 007/107] kp_sampler_skip.cpp: include iostream for std::cout --- common/kokkos-sampler/kp_sampler_skip.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index c24ee6bc4..ff4e08de4 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -6,6 +6,7 @@ #include #include "../../profiling/all/kp_core.hpp" #include "kp_config.hpp" +#include namespace KokkosTools { namespace Sampler { From e1aacb036f0ad6f95ff275934364df3cbd31ba21 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 20:11:51 -0400 Subject: [PATCH 008/107] Update kp_sampler_skip.cpp: \n instead of std::endl \n is faster for performance --- common/kokkos-sampler/kp_sampler_skip.cpp | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index ff4e08de4..f6d3295e2 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -197,7 +197,7 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, if ((invocationNum % kernelSampleSkip) == 0) { if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << *kID - << " calling child-begin function..." << std::endl; + << " calling child-begin function...\n"; } if (tool_globFence) { invoke_ktools_fence(0); @@ -207,7 +207,7 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, (*beginForCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << *kID - << " called child-begin function." << std::endl; + << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -220,7 +220,7 @@ void kokkosp_end_parallel_for(const uint64_t kID) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " calling child-end function..." << std::endl; + << " calling child-end function...\n"; } if (tool_globFence) { @@ -229,7 +229,7 @@ void kokkosp_end_parallel_for(const uint64_t kID) { (*endForCallee)(retrievedNestedkID); if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " called child-end function." << std::endl; + << " finished with child-end function.\n"; } infokIDSample.erase(kID); } @@ -244,7 +244,7 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, if ((invocationNum % kernelSampleSkip) == 0) { if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << *kID - << " calling child-begin function..." << std::endl; + << " calling child-begin function...\n"; } if (NULL != beginScanCallee) { uint64_t nestedkID = 0; @@ -254,7 +254,7 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, (*beginScanCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << *kID - << " called child-begin function." << std::endl; + << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -267,7 +267,7 @@ void kokkosp_end_parallel_scan(const uint64_t kID) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " calling child-end function..." << std::endl; + << " calling child-end function...\n"; } if (tool_globFence) { invoke_ktools_fence(0); @@ -275,7 +275,7 @@ void kokkosp_end_parallel_scan(const uint64_t kID) { (*endScanCallee)(retrievedNestedkID); if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " called child-end function." << std::endl; + << " finished with child-end function.\n"; } infokIDSample.erase(kID); } @@ -290,7 +290,7 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, if ((invocationNum % kernelSampleSkip) == 0) { if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << *kID - << " calling child-begin function..." << std::endl; + << " calling child-begin function...\n"; } if (NULL != beginReduceCallee) { uint64_t nestedkID = 0; @@ -300,7 +300,7 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, (*beginReduceCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << *kID - << " called child-begin function." << std::endl; + << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -313,7 +313,7 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " calling child-end function..." << std::endl; + << " calling child-end function...\n"; } if (tool_globFence) { invoke_ktools_fence(0); @@ -321,7 +321,7 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { (*endReduceCallee)(retrievedNestedkID); if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " called child-end function." << std::endl; + << " finished with child-end function.\n"; } infokIDSample.erase(kID); } From 0801d92229b41ccfdce61cba8248ebf520d2cfd2 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 18:14:16 -0700 Subject: [PATCH 009/107] kp_sampler_skip.cpp: apply clang format --- common/kokkos-sampler/kp_sampler_skip.cpp | 54 +++++++++++------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index f6d3295e2..60762c80c 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -195,10 +195,10 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, static uint64_t invocationNum = 0; ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " calling child-begin function...\n"; - } + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function...\n"; + } if (tool_globFence) { invoke_ktools_fence(0); } @@ -206,9 +206,9 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, uint64_t nestedkID = 0; (*beginForCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID + std::cout << "KokkosP: sample " << *kID << " finished with child-begin function.\n"; - } + } infokIDSample.insert({*kID, nestedkID}); } } @@ -219,18 +219,18 @@ void kokkosp_end_parallel_for(const uint64_t kID) { if (!(infokIDSample.find(kID) == infokIDSample.end())) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " calling child-end function...\n"; + std::cout << "KokkosP: sample " << kID + << " calling child-end function...\n"; } - + if (tool_globFence) { invoke_ktools_fence(0); } (*endForCallee)(retrievedNestedkID); if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID + std::cout << "KokkosP: sample " << kID << " finished with child-end function.\n"; - } + } infokIDSample.erase(kID); } } @@ -243,8 +243,8 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " calling child-begin function...\n"; + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function...\n"; } if (NULL != beginScanCallee) { uint64_t nestedkID = 0; @@ -253,9 +253,9 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, } (*beginScanCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID + std::cout << "KokkosP: sample " << *kID << " finished with child-begin function.\n"; - } + } infokIDSample.insert({*kID, nestedkID}); } } @@ -266,17 +266,17 @@ void kokkosp_end_parallel_scan(const uint64_t kID) { if (!(infokIDSample.find(kID) == infokIDSample.end())) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " calling child-end function...\n"; + std::cout << "KokkosP: sample " << kID + << " calling child-end function...\n"; } if (tool_globFence) { invoke_ktools_fence(0); } (*endScanCallee)(retrievedNestedkID); - if (tool_verbosity > 0) { + if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " finished with child-end function.\n"; - } + << " finished with child-end function.\n"; + } infokIDSample.erase(kID); } } @@ -289,8 +289,8 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " calling child-begin function...\n"; + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function...\n"; } if (NULL != beginReduceCallee) { uint64_t nestedkID = 0; @@ -298,8 +298,8 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, invoke_ktools_fence(0); } (*beginReduceCallee)(name, devID, &nestedkID); - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); @@ -313,15 +313,15 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " calling child-end function...\n"; + << " calling child-end function...\n"; } if (tool_globFence) { invoke_ktools_fence(0); } (*endReduceCallee)(retrievedNestedkID); - if (tool_verbosity > 0) { + if (tool_verbosity > 0) { std::cout << "KokkosP: sample " << kID - << " finished with child-end function.\n"; + << " finished with child-end function.\n"; } infokIDSample.erase(kID); } From c3713967db3c0860e18fc7b473a071ad39d92dcc Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 18:23:43 -0700 Subject: [PATCH 010/107] kp_sampler_skip.cpp: fix for std::out of tool-invoked fence verbose debug print --- common/kokkos-sampler/kp_sampler_skip.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 60762c80c..e77ba8d35 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,15 +51,12 @@ void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { tpi_funcs.fence(devID); if (tool_verbosity > 1) { - printf( - "KokkosP: Sampler utility sucessfully invoked " - " tool-induced fence on device %d\n", - getDeviceID(devID)); + std::cout << + "KokkosP: Sampler utility sucessfully invoked tool-induced fence on device " << getDeviceID(devID) << ".\n"; } } else { - printf( - "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked " - "Fence is NULL!\n"); + std::cout << + "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked Fence is NULL!\n"; exit(-1); } } From 83b50410f9698c69e3805b758569ebffe9041a5e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 18:23:43 -0700 Subject: [PATCH 011/107] kp_sampler_skip.cpp: apply clang format --- common/kokkos-sampler/kp_sampler_skip.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index e77ba8d35..db2545c60 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,12 +51,13 @@ void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { tpi_funcs.fence(devID); if (tool_verbosity > 1) { - std::cout << - "KokkosP: Sampler utility sucessfully invoked tool-induced fence on device " << getDeviceID(devID) << ".\n"; + std::cout << "KokkosP: Sampler utility sucessfully invoked tool-induced " + "fence on device " + << getDeviceID(devID) << ".\n"; } } else { - std::cout << - "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked Fence is NULL!\n"; + std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's " + "tool-invoked Fence is NULL!\n"; exit(-1); } } From 79f4b4259979e352c59d05d2a55024913637ec20 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:06:53 -0700 Subject: [PATCH 012/107] Rename test_sampler.cpp to test_parfor.cpp --- tests/sampler/{test_sampler.cpp => test_parfor.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/sampler/{test_sampler.cpp => test_parfor.cpp} (100%) diff --git a/tests/sampler/test_sampler.cpp b/tests/sampler/test_parfor.cpp similarity index 100% rename from tests/sampler/test_sampler.cpp rename to tests/sampler/test_parfor.cpp From b39e3dc0a770156a87a54ec560e16cd67576228d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:09:49 -0700 Subject: [PATCH 013/107] Update CMakeLists.txt: reduce and scan sampling tests --- tests/sampler/CMakeLists.txt | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 266ebcbad..376ae24c3 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,6 +1,24 @@ kp_add_executable_and_test( - TARGET_NAME test_sampling - SOURCE_FILE test_sampler.cpp + TARGET_NAME test_sampling_parfor + SOURCE_FILE test_parfor.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_SAMPLER_SKIP 50 + KOKKOS_TOOLS_GLOBALFENCES 1 +) + +kp_add_executable_and_test( + TARGET_NAME test_sampling_parscan + SOURCE_FILE test_parscan.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_SAMPLER_SKIP 50 + KOKKOS_TOOLS_GLOBALFENCES 1 +) + +kp_add_executable_and_test( + TARGET_NAME test_sampling_parreduce + SOURCE_FILE test_parreduce.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 50 From b802f47c7d0f0339ae19b8762eea02bbf184cd3d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:10:23 -0700 Subject: [PATCH 014/107] Create test_parreduce.cpp --- tests/sampler/test_parreduce.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/sampler/test_parreduce.cpp diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/sampler/test_parreduce.cpp @@ -0,0 +1 @@ + From a4741e80a41eeecfb6fb3f694788ed648e1e19d5 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:10:56 -0700 Subject: [PATCH 015/107] Create test_parscan.cpp --- tests/sampler/test_parscan.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/sampler/test_parscan.cpp diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/sampler/test_parscan.cpp @@ -0,0 +1 @@ + From acf4f210da1a1dfbef50577c54f191e50df6d7ef Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:36:09 -0700 Subject: [PATCH 016/107] Update test_parreduce.cpp: parallel_reduce function Test based on example shown at: https://kokkos.org/kokkos-core-wiki/API/core/parallel-dispatch/parallel_reduce.html --- tests/sampler/test_parreduce.cpp | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 8b1378917..05c203dcc 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -1 +1,70 @@ +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "Kokkos_Core.hpp" + +struct Tester { + template + explicit Tester(const execution_space& space) { + //! Explicitly launch a kernel with a name, and run it 150 times with kernel + //! logger. Use a periodic sampling with skip rate 51. This should print + //! out 2 invocations, and there is a single matcher with a regular + //! expression to check this. + const size_t N = 1024; + View x ("x", N); +for(int i = 0; i < N; i++) + { + x[i] = i; + } + for (int iter = 0; iter < 150; iter++) { + double sum = 0.0; + // KOKKOS_LAMBDA macro includes capture-by-value specifier [=]. + Kokkos::parallel_reduce("named kernel Reduction", N, KOKKOS_LAMBDA (const int i, double& update) { + update += x(i); }, sum); + } + } +}; + +static const std::vector matchers{ + "(.*)KokkosP: sample 51 calling child-begin function...(.*)", + "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", + "(.*)KokkosP: sample 51 calling child-end function...(.*)", + "(.*)KokkosP: sample 51 calling child-end function.(.*)", + "(.*)KokkosP: sample 102 calling child-begin function...(.*)", + "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", + "(.*)KokkosP: sample 102 calling child-end function...(.*)", + "(.*)KokkosP: sample 102 calling child-end function.(.*)"}; + +/** + * @test This test checks that the tool effectively samples. + * + + */ +TEST(SamplerTest, ktoEnvVarDefault) { + //! Initialize @c Kokkos. + Kokkos::initialize(); + + //! Redirect output for later analysis. + std::cout.flush(); + std::ostringstream output; + std::streambuf* coutbuf = std::cout.rdbuf(output.rdbuf()); + + //! Run tests. @todo Replace this with Google Test. + Tester tester(Kokkos::DefaultExecutionSpace{}); + + //! Finalize @c Kokkos. + Kokkos::finalize(); + + //! Restore output buffer. + // std::cout.flush(); + std::cout.rdbuf(coutbuf); + std::cout << output.str() << std::endl; + + //! Analyze test output. + for (const auto& matcher : matchers) { + EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); + } // end TEST +} From 83c3d8cb5d218a6142266e40917d15ed6b74287f Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:45:26 -0700 Subject: [PATCH 017/107] test_parscan.cpp: put in test for sampling parallel_scan Parallel scan sampling test based on example here: https://kokkos.org/kokkos-core-wiki/API/core/parallel-dispatch/parallel_scan.html --- tests/sampler/test_parscan.cpp | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 8b1378917..c99037395 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -1 +1,74 @@ +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "Kokkos_Core.hpp" + +struct Tester { + template + explicit Tester(const execution_space& space) { + //! Explicitly launch a kernel with a name, and run it 150 times with kernel + //! logger. Use a periodic sampling with skip rate 51. This should print + //! out 2 invocations, and there is a single matcher with a regular + //! expression to check this. + + int N = 100; + int64_t result; + Kokkos::View post("postfix_sum", N); + Kokkos::View pre("prefix_sum", N); + + for (int iter = 0; iter < 150; iter++) { + result = 0; + Kokkos::parallel_scan("Loop1", N, + KOKKOS_LAMBDA(int64_t i, int64_t& partial_sum, bool is_final) { + if(is_final) pre(i) = partial_sum; + partial_sum += i; + if(is_final) post(i) = partial_sum; + }, result); + } // end timestepping loop + } // end explicit Tester + +}; + +static const std::vector matchers { + "(.*)KokkosP: sample 51 calling child-begin function...(.*)", + "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", + "(.*)KokkosP: sample 51 calling child-end function...(.*)", + "(.*)KokkosP: sample 51 calling child-end function.(.*)", + "(.*)KokkosP: sample 102 calling child-begin function...(.*)", + "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", + "(.*)KokkosP: sample 102 calling child-end function...(.*)", + "(.*)KokkosP: sample 102 calling child-end function.(.*)"}; + +/** + * @test This test checks that the tool effectively samples. + * + + */ +TEST(SamplerTest, ktoEnvVarDefault) { + //! Initialize @c Kokkos. + Kokkos::initialize(); + + //! Redirect output for later analysis. + std::cout.flush(); + std::ostringstream output; + std::streambuf* coutbuf = std::cout.rdbuf(output.rdbuf()); + + //! Run tests. @todo Replace this with Google Test. + Tester tester(Kokkos::DefaultExecutionSpace{}); + + //! Finalize @c Kokkos. + Kokkos::finalize(); + + //! Restore output buffer. + // std::cout.flush(); + std::cout.rdbuf(coutbuf); + std::cout << output.str() << std::endl; + + //! Analyze test output. + for (const auto& matcher : matchers) { + EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); + } // end TEST +} From 3402f8fc15ee3b6b48843edb1bdd7ee664695e39 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:52:13 -0700 Subject: [PATCH 018/107] Update test_parreduce.cpp: fix x[i] to x(i) View index access of x does not use [] --- tests/sampler/test_parreduce.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 05c203dcc..1b1b498dd 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -15,10 +15,10 @@ struct Tester { //! expression to check this. const size_t N = 1024; View x ("x", N); -for(int i = 0; i < N; i++) + for(int i = 0; i < N; i++) { - x[i] = i; - } + x(i) = i; + } for (int iter = 0; iter < 150; iter++) { double sum = 0.0; // KOKKOS_LAMBDA macro includes capture-by-value specifier [=]. From 6dd9a635b2f21f32427d61008b17b2b01ab9ef32 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 20:02:15 -0700 Subject: [PATCH 019/107] Update test_parreduce.cpp: Kokkos:: for View --- tests/sampler/test_parreduce.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 1b1b498dd..ff7f80f78 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -14,7 +14,7 @@ struct Tester { //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. const size_t N = 1024; - View x ("x", N); + Kokkos::View x ("x", N); for(int i = 0; i < N; i++) { x(i) = i; @@ -22,7 +22,7 @@ struct Tester { for (int iter = 0; iter < 150; iter++) { double sum = 0.0; // KOKKOS_LAMBDA macro includes capture-by-value specifier [=]. - Kokkos::parallel_reduce("named kernel Reduction", N, KOKKOS_LAMBDA (const int i, double& update) { + Kokkos::parallel_reduce("named kernel reduction", N, KOKKOS_LAMBDA (const int i, double& update) { update += x(i); }, sum); } } From ca38a69abd131c8de5f30eeb278132ae31a5ebdb Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:12:25 -0400 Subject: [PATCH 020/107] test_parreduce.cpp: reduce lambda --- tests/sampler/test_parreduce.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index ff7f80f78..71f2d3f3d 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -13,21 +13,20 @@ struct Tester { //! logger. Use a periodic sampling with skip rate 51. This should print //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. - const size_t N = 1024; - Kokkos::View x ("x", N); - for(int i = 0; i < N; i++) - { - x(i) = i; - } - for (int iter = 0; iter < 150; iter++) { - double sum = 0.0; - // KOKKOS_LAMBDA macro includes capture-by-value specifier [=]. - Kokkos::parallel_reduce("named kernel reduction", N, KOKKOS_LAMBDA (const int i, double& update) { - update += x(i); }, sum); + + double sum; +for (int iter = 0; iter < 150; iter++) { + sum = 0; + Kokkos::parallel_reduce("named kernel", + Kokkos::RangePolicy(space, 0, 1), + *this, sum); } } + + KOKKOS_FUNCTION void operator()(const int) const {} }; + static const std::vector matchers{ "(.*)KokkosP: sample 51 calling child-begin function...(.*)", "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", From e381df3fe4019a40cda8e072151e1773d5387de9 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:14:47 -0400 Subject: [PATCH 021/107] Update test_parscan.cpp: operator for cuda/hip build --- tests/sampler/test_parscan.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index c99037395..7f14e65b1 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -30,6 +30,7 @@ struct Tester { } // end timestepping loop } // end explicit Tester +KOKKOS_FUNCTION void operator()(const int) const {} }; static const std::vector matchers { From 01cc359dc9b09f7898cf72e6b16fb55c70c3e80f Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:41:28 -0400 Subject: [PATCH 022/107] test_parscan.cpp: support scan test function --- tests/sampler/test_parscan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 7f14e65b1..f77baba46 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -30,7 +30,7 @@ struct Tester { } // end timestepping loop } // end explicit Tester -KOKKOS_FUNCTION void operator()(const int) const {} +KOKKOS_FUNCTION void operator()(const int i, const int psum, bool isFinal) const {} }; static const std::vector matchers { From 83910d9b26d5dbe133fedcb1dcb20d2fce8775e4 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:45:40 -0400 Subject: [PATCH 023/107] test_parreduce.cpp: reduction operator second argument second argument --- tests/sampler/test_parreduce.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 71f2d3f3d..e8e90da2a 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -23,7 +23,7 @@ for (int iter = 0; iter < 150; iter++) { } } - KOKKOS_FUNCTION void operator()(const int) const {} + KOKKOS_FUNCTION void operator()(const int, const int) const {} }; From 9b31f1e29d4c4f3c45b356e19321c77614a120c0 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:57:27 -0400 Subject: [PATCH 024/107] test_parscan.cpp: fix scan test operator --- tests/sampler/test_parscan.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index f77baba46..4d976b8d8 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -21,16 +21,16 @@ struct Tester { for (int iter = 0; iter < 150; iter++) { result = 0; - Kokkos::parallel_scan("Loop1", N, - KOKKOS_LAMBDA(int64_t i, int64_t& partial_sum, bool is_final) { - if(is_final) pre(i) = partial_sum; - partial_sum += i; - if(is_final) post(i) = partial_sum; - }, result); + Kokkos::parallel_scan("named kernel scan", + Kokkos::RangePolicy(space, 0, N), + *this, result); } // end timestepping loop } // end explicit Tester -KOKKOS_FUNCTION void operator()(const int i, const int psum, bool isFinal) const {} +KOKKOS_FUNCTION void operator()(const int i, const int& psum, bool isFinal) const {} + //if(isFinal) pre(i) = p_sum; + // p_sum += i; + // if(isFinal) post(i) = p_sum; }; static const std::vector matchers { From 05db2a6fa7eff604b6b256a88ac625e9eb9662bb Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 01:08:09 -0400 Subject: [PATCH 025/107] Update test_parscan.cpp: fix scan test to have to Views --- tests/sampler/test_parscan.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 4d976b8d8..a7b1a4bda 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -16,18 +16,18 @@ struct Tester { int N = 100; int64_t result; - Kokkos::View post("postfix_sum", N); - Kokkos::View pre("prefix_sum", N); + // Kokkos::View post("postfix_sum", N); + // Kokkos::View pre("prefix_sum", N); for (int iter = 0; iter < 150; iter++) { result = 0; Kokkos::parallel_scan("named kernel scan", - Kokkos::RangePolicy(space, 0, N), + Kokkos::RangePolicy(space, 0, 1), *this, result); } // end timestepping loop } // end explicit Tester -KOKKOS_FUNCTION void operator()(const int i, const int& psum, bool isFinal) const {} +KOKKOS_FUNCTION void operator()(const int, const int&, bool) const {} //if(isFinal) pre(i) = p_sum; // p_sum += i; // if(isFinal) post(i) = p_sum; From 039665f01c1c21e1658bd030fd20bcfa7f1ce6aa Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 02:07:57 -0400 Subject: [PATCH 026/107] test_parscan.cpp: policy to size --- tests/sampler/test_parscan.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index a7b1a4bda..3239842ac 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -14,15 +14,15 @@ struct Tester { //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. - int N = 100; + int N = 1024; int64_t result; // Kokkos::View post("postfix_sum", N); // Kokkos::View pre("prefix_sum", N); for (int iter = 0; iter < 150; iter++) { result = 0; - Kokkos::parallel_scan("named kernel scan", - Kokkos::RangePolicy(space, 0, 1), + Kokkos::parallel_scan("named kernel scan", N, + //Kokkos::RangePolicy(space, 0, N), *this, result); } // end timestepping loop } // end explicit Tester From c74c1b840ebf720ee2a04ea359502ba80cd6f373 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:22:59 -0700 Subject: [PATCH 027/107] Update kp_kernel_logger.cpp: fix typo for scan callback The typo was kokkospk_end_parallel_scan. This causes the third test for the sampler to fail. --- debugging/kernel-logger/kp_kernel_logger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/kernel-logger/kp_kernel_logger.cpp b/debugging/kernel-logger/kp_kernel_logger.cpp index bf7f585bb..dc5b13167 100644 --- a/debugging/kernel-logger/kp_kernel_logger.cpp +++ b/debugging/kernel-logger/kp_kernel_logger.cpp @@ -100,7 +100,7 @@ extern "C" void kokkosp_begin_parallel_scan(const char* name, printf(" %s\n", name); } -extern "C" void kokkospk_end_parallel_scan(const uint64_t kID) { +extern "C" void kokkosp_end_parallel_scan(const uint64_t kID) { printf("KokkosP: Execution of kernel %llu is completed.\n", (unsigned long long)(kID)); } From 489b5f3f61ce96771c677eca6a52c47d3a37cee2 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:35:06 -0700 Subject: [PATCH 028/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 3239842ac..4dc1fbc67 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -13,27 +13,28 @@ struct Tester { //! logger. Use a periodic sampling with skip rate 51. This should print //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. - + int N = 1024; int64_t result; // Kokkos::View post("postfix_sum", N); - // Kokkos::View pre("prefix_sum", N); + // Kokkos::View pre("prefix_sum", N); - for (int iter = 0; iter < 150; iter++) { + for (int iter = 0; iter < 150; iter++) { result = 0; - Kokkos::parallel_scan("named kernel scan", N, - //Kokkos::RangePolicy(space, 0, N), - *this, result); - } // end timestepping loop - } // end explicit Tester + Kokkos::parallel_scan( + "named kernel scan", N, + // Kokkos::RangePolicy(space, 0, N), + *this, result); + } // end timestepping loop + } // end explicit Tester -KOKKOS_FUNCTION void operator()(const int, const int&, bool) const {} - //if(isFinal) pre(i) = p_sum; - // p_sum += i; - // if(isFinal) post(i) = p_sum; + KOKKOS_FUNCTION void operator()(const int, const int&, bool) const {} + // if(isFinal) pre(i) = p_sum; + // p_sum += i; + // if(isFinal) post(i) = p_sum; }; -static const std::vector matchers { +static const std::vector matchers{ "(.*)KokkosP: sample 51 calling child-begin function...(.*)", "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", "(.*)KokkosP: sample 51 calling child-end function...(.*)", From ddc89dc09cd6299cc0790e9e260508f507d12f9d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:37:25 -0700 Subject: [PATCH 029/107] test_parreduce.cpp: apply clang format --- tests/sampler/test_parreduce.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index e8e90da2a..d73da7bac 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -15,18 +15,17 @@ struct Tester { //! expression to check this. double sum; -for (int iter = 0; iter < 150; iter++) { - sum = 0; + for (int iter = 0; iter < 150; iter++) { + sum = 0; Kokkos::parallel_reduce("named kernel", - Kokkos::RangePolicy(space, 0, 1), - *this, sum); + Kokkos::RangePolicy(space, 0, 1), + *this, sum); } } KOKKOS_FUNCTION void operator()(const int, const int) const {} }; - static const std::vector matchers{ "(.*)KokkosP: sample 51 calling child-begin function...(.*)", "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", From b905edd2f1cdd676f6209aee3c6389a2d49f6eb5 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:33:12 -0700 Subject: [PATCH 030/107] CMakeLists.txt: add_library -> kp_add_library --- common/kokkos-sampler/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/kokkos-sampler/CMakeLists.txt b/common/kokkos-sampler/CMakeLists.txt index 609ab5707..eb94dbd0f 100644 --- a/common/kokkos-sampler/CMakeLists.txt +++ b/common/kokkos-sampler/CMakeLists.txt @@ -1 +1 @@ -add_library(kp_kokkos_sampler ${KOKKOSTOOLS_LIBRARY_MODE} kp_sampler_skip.cpp) +kp_add_library(kp_kokkos_sampler ${KOKKOSTOOLS_LIBRARY_MODE} kp_sampler_skip.cpp) From 0e273716637a2f27d3e0677301d83a6f0328aa6b Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:39:57 -0700 Subject: [PATCH 031/107] Update test_parfor.cpp: put in finished with end in matchers --- tests/sampler/test_parfor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 224500ef7..f199cb978 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -28,11 +28,11 @@ static const std::vector matchers{ "(.*)KokkosP: sample 51 calling child-begin function...(.*)", "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", "(.*)KokkosP: sample 51 calling child-end function...(.*)", - "(.*)KokkosP: sample 51 calling child-end function.(.*)", + "(.*)KokkosP: sample 51 finished with child-end function.(.*)", "(.*)KokkosP: sample 102 calling child-begin function...(.*)", "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", "(.*)KokkosP: sample 102 calling child-end function...(.*)", - "(.*)KokkosP: sample 102 calling child-end function.(.*)"}; + "(.*)KokkosP: sample 102 finished with child-end function.(.*)"}; /** * @test This test checks that the tool effectively samples. From 19967bdae5d320d4f95821a34c7ec02fa5e62557 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:41:20 -0700 Subject: [PATCH 032/107] Update test_parscan.cpp: update matchers / comments removal --- tests/sampler/test_parscan.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 4dc1fbc67..f1792bdf6 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -16,33 +16,28 @@ struct Tester { int N = 1024; int64_t result; - // Kokkos::View post("postfix_sum", N); - // Kokkos::View pre("prefix_sum", N); for (int iter = 0; iter < 150; iter++) { result = 0; Kokkos::parallel_scan( "named kernel scan", N, - // Kokkos::RangePolicy(space, 0, N), *this, result); - } // end timestepping loop - } // end explicit Tester + } + } KOKKOS_FUNCTION void operator()(const int, const int&, bool) const {} - // if(isFinal) pre(i) = p_sum; - // p_sum += i; - // if(isFinal) post(i) = p_sum; + }; static const std::vector matchers{ "(.*)KokkosP: sample 51 calling child-begin function...(.*)", "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", "(.*)KokkosP: sample 51 calling child-end function...(.*)", - "(.*)KokkosP: sample 51 calling child-end function.(.*)", + "(.*)KokkosP: sample 51 finished with child-end function.(.*)", "(.*)KokkosP: sample 102 calling child-begin function...(.*)", "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", "(.*)KokkosP: sample 102 calling child-end function...(.*)", - "(.*)KokkosP: sample 102 calling child-end function.(.*)"}; + "(.*)KokkosP: sample 102 finished with child-end function.(.*)"}; /** * @test This test checks that the tool effectively samples. From 2943eb9fdb22b5c9632792223862541f1e9fafd8 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:42:34 -0700 Subject: [PATCH 033/107] test_parreduce.cpp: fix matchers --- tests/sampler/test_parreduce.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index d73da7bac..d6d37edaf 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -30,11 +30,11 @@ static const std::vector matchers{ "(.*)KokkosP: sample 51 calling child-begin function...(.*)", "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", "(.*)KokkosP: sample 51 calling child-end function...(.*)", - "(.*)KokkosP: sample 51 calling child-end function.(.*)", + "(.*)KokkosP: sample 51 finished with child-end function.(.*)", "(.*)KokkosP: sample 102 calling child-begin function...(.*)", "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", "(.*)KokkosP: sample 102 calling child-end function...(.*)", - "(.*)KokkosP: sample 102 calling child-end function.(.*)"}; + "(.*)KokkosP: sample 102 finished with child-end function.(.*)"}; /** * @test This test checks that the tool effectively samples. From 113b4dd0caa37b3e4405b4cf301ea0bd6c475ff9 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 09:56:43 -0700 Subject: [PATCH 034/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index f1792bdf6..c0e57bc6c 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -19,14 +19,11 @@ struct Tester { for (int iter = 0; iter < 150; iter++) { result = 0; - Kokkos::parallel_scan( - "named kernel scan", N, - *this, result); + Kokkos::parallel_scan("named kernel scan", N, *this, result); } } KOKKOS_FUNCTION void operator()(const int, const int&, bool) const {} - }; static const std::vector matchers{ From 5f5604d00d1ff5382fb6d1e89794e101a208659c Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:19:27 -0700 Subject: [PATCH 035/107] Update README.md: add sampler entry --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73f1a902a..409b9f391 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,14 @@ void foo() { The following provides an overview of the tools available in the set of Kokkos Tools. Click on each Kokkos Tools name to see more details about the tool via the Kokkos Tools Wiki. ### Utilities - + [**KernelFilter:**](https://github.com/kokkos/kokkos-tools/wiki/KernelFilter) A tool which is used in conjunction with analysis tools, to restrict them to a subset of the application. ++ [**KernelSampler:**](https://github.com/kokkos/kokkos-tools/wiki/KernelSampler) + + A tool which is used in conjunction with analysis tools, to restrict the tooling to samples of Kokkos kernel invocations. + ### Memory Analysis + [**MemoryHighWater:**](https://github.com/kokkos/kokkos-tools/wiki/MemoryHighWater) From b0a956e952b40a73985b68035d1d07225c6d5db8 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:06:34 -0700 Subject: [PATCH 036/107] test_parreduce.cpp: fix int ref in operator --- tests/sampler/test_parreduce.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index d6d37edaf..77912e12a 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -23,7 +23,7 @@ struct Tester { } } - KOKKOS_FUNCTION void operator()(const int, const int) const {} + KOKKOS_FUNCTION void operator()(const int, int&) const {} }; static const std::vector matchers{ From ae0cfa2e5410e335a8d2ab677e708d7e956be15f Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:07:24 -0700 Subject: [PATCH 037/107] test_parscan.cpp: int ref in operator --- tests/sampler/test_parscan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index c0e57bc6c..3c6d0405e 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -23,7 +23,7 @@ struct Tester { } } - KOKKOS_FUNCTION void operator()(const int, const int&, bool) const {} + KOKKOS_FUNCTION void operator()(const int, int&, bool) const {} }; static const std::vector matchers{ From 54009c2a09e4d2ac69375add577d6b8acfed41e3 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 12:22:27 -0700 Subject: [PATCH 038/107] test_parscan.cpp: long int in signature --- tests/sampler/test_parscan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 3c6d0405e..db389c1e7 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -23,7 +23,7 @@ struct Tester { } } - KOKKOS_FUNCTION void operator()(const int, int&, bool) const {} + KOKKOS_FUNCTION void operator()(const int, long int&, bool) const {} }; static const std::vector matchers{ From d0587bca062aaaebbf4413634fc71cfdfdcfcdf0 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 12:29:31 -0700 Subject: [PATCH 039/107] test_parreduce.cpp: long int in second argument to operator --- tests/sampler/test_parreduce.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 77912e12a..d09ec48f2 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -23,7 +23,7 @@ struct Tester { } } - KOKKOS_FUNCTION void operator()(const int, int&) const {} + KOKKOS_FUNCTION void operator()(const int, long int&) const {} }; static const std::vector matchers{ From 65b2ac536a5ee78c9bccf5c080fd0d10cf5069d7 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 15:49:26 -0400 Subject: [PATCH 040/107] Update test_parreduce.cpp: change sum to int type --- tests/sampler/test_parreduce.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index d09ec48f2..00da6b5da 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -14,7 +14,7 @@ struct Tester { //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. - double sum; + int sum; for (int iter = 0; iter < 150; iter++) { sum = 0; Kokkos::parallel_reduce("named kernel", From 538996680b110ed32b107c8a0f2258294866d2c5 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 16:08:02 -0400 Subject: [PATCH 041/107] Update test_parreduce.cpp: declare sum as long int --- tests/sampler/test_parreduce.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 00da6b5da..95eaa35b5 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -14,7 +14,7 @@ struct Tester { //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. - int sum; + long int sum; for (int iter = 0; iter < 150; iter++) { sum = 0; Kokkos::parallel_reduce("named kernel", From 9e1d806b4cf798bf8faf898ba639b9c9029e8ed7 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 08:15:42 -0700 Subject: [PATCH 042/107] Update README.md Co-authored-by: Daniel Arndt --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 409b9f391..1d54302ba 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The following provides an overview of the tools available in the set of Kokkos T + [**KernelSampler:**](https://github.com/kokkos/kokkos-tools/wiki/KernelSampler) - A tool which is used in conjunction with analysis tools, to restrict the tooling to samples of Kokkos kernel invocations. + A tool to be used in conjunction with analysis tools to restrict the tooling to samples of Kokkos kernel invocations. ### Memory Analysis + [**MemoryHighWater:**](https://github.com/kokkos/kokkos-tools/wiki/MemoryHighWater) From 6f6a305b8012f95538be5c3dcc9652dffc731930 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 09:56:48 -0700 Subject: [PATCH 043/107] Update test_parfor.cpp --- tests/sampler/test_parfor.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index f199cb978..5ce19c19d 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -25,14 +25,14 @@ struct Tester { }; static const std::vector matchers{ - "(.*)KokkosP: sample 51 calling child-begin function...(.*)", - "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", - "(.*)KokkosP: sample 51 calling child-end function...(.*)", - "(.*)KokkosP: sample 51 finished with child-end function.(.*)", - "(.*)KokkosP: sample 102 calling child-begin function...(.*)", - "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", - "(.*)KokkosP: sample 102 calling child-end function...(.*)", - "(.*)KokkosP: sample 102 finished with child-end function.(.*)"}; + "KokkosP: sample 51 calling child-begin function...", + "KokkosP: sample 51 finished with child-begin function.", + "KokkosP: sample 51 calling child-end function...", + "KokkosP: sample 51 finished with child-end function.", + "KokkosP: sample 102 calling child-begin function...", + "KokkosP: sample 102 finished with child-begin function.", + "KokkosP: sample 102 calling child-end function...", + "KokkosP: sample 102 finished with child-end function."}; /** * @test This test checks that the tool effectively samples. @@ -55,12 +55,12 @@ TEST(SamplerTest, ktoEnvVarDefault) { Kokkos::finalize(); //! Restore output buffer. - // std::cout.flush(); + std::cout.flush(); std::cout.rdbuf(coutbuf); std::cout << output.str() << std::endl; //! Analyze test output. for (const auto& matcher : matchers) { - EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); + EXPECT_THAT(output.str(), ::testing::HasSubstr(matcher)); } // end TEST } From 97da0444b9f6ff10cda8f00b73dea59ee18f34e2 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:50:21 -0700 Subject: [PATCH 044/107] test_parfor.cpp: put in fence test --- tests/sampler/test_parfor.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 5ce19c19d..340c05ebb 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -63,4 +63,8 @@ TEST(SamplerTest, ktoEnvVarDefault) { for (const auto& matcher : matchers) { EXPECT_THAT(output.str(), ::testing::HasSubstr(matcher)); } // end TEST + + EXPECT_THAT(output.str(), testing::Not(testing::HasSubstr( + "KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); } From 7cbecfe419f3cd4d88dbd9b88b6c9309483ad31f Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:17:35 -0700 Subject: [PATCH 045/107] Update test_parfor.cpp: put in checks for number of calls and Null Ptr fence --- tests/sampler/test_parfor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 340c05ebb..de3f4df87 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -64,7 +64,13 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), ::testing::HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), testing::Not(testing::HasSubstr( + EXPECT_THAT(output.str(), ::testing::Contains("calling child-begin function...").Times(2)); + EXPECT_THAT(output.str(), ::testing::Contains("finished with child-begin function.").Times(2)); + EXPECT_THAT(output.str(), ::testing::Contains("calling child-end function...").Times(2)); + EXPECT_THAT(output.str(), ::testing::Contains("finished with child-end function.").Times(2)); + + EXPECT_THAT(output.str(), ::testing::Not(::testing::HasSubstr( "KokkosP: FATAL: Kokkos Tools Programming " "Interface's tool-invoked Fence is NULL!"))); + } From 6afc419a5b947c848759d1c8bf0bd130cbe857d0 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:21:32 -0700 Subject: [PATCH 046/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index de3f4df87..6e206daa9 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -64,13 +64,18 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), ::testing::HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), ::testing::Contains("calling child-begin function...").Times(2)); - EXPECT_THAT(output.str(), ::testing::Contains("finished with child-begin function.").Times(2)); - EXPECT_THAT(output.str(), ::testing::Contains("calling child-end function...").Times(2)); - EXPECT_THAT(output.str(), ::testing::Contains("finished with child-end function.").Times(2)); + EXPECT_THAT(output.str(), + ::testing::Contains("calling child-begin function...").Times(2)); + EXPECT_THAT( + output.str(), + ::testing::Contains("finished with child-begin function.").Times(2)); + EXPECT_THAT(output.str(), + ::testing::Contains("calling child-end function...").Times(2)); + EXPECT_THAT( + output.str(), + ::testing::Contains("finished with child-end function.").Times(2)); EXPECT_THAT(output.str(), ::testing::Not(::testing::HasSubstr( "KokkosP: FATAL: Kokkos Tools Programming " "Interface's tool-invoked Fence is NULL!"))); - } From cb310a04e74e3ae3493ef730d41696d79bd3904b Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:45:07 -0700 Subject: [PATCH 047/107] fix test par for --- tests/sampler/test_parfor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 6e206daa9..71d7b3e50 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -75,7 +75,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { output.str(), ::testing::Contains("finished with child-end function.").Times(2)); - EXPECT_THAT(output.str(), ::testing::Not(::testing::HasSubstr( + EXPECT_THAT(output.str(), ::testing::Not( "KokkosP: FATAL: Kokkos Tools Programming " - "Interface's tool-invoked Fence is NULL!"))); + "Interface's tool-invoked Fence is NULL!")); } From 76241536be4426b2c2c03126a5f2bcb53f55516d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:47:27 -0700 Subject: [PATCH 048/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 71d7b3e50..fb240310f 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -75,7 +75,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { output.str(), ::testing::Contains("finished with child-end function.").Times(2)); - EXPECT_THAT(output.str(), ::testing::Not( - "KokkosP: FATAL: Kokkos Tools Programming " - "Interface's tool-invoked Fence is NULL!")); + EXPECT_THAT(output.str(), + ::testing::Not("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!")); } From 4b1ca10b1b56c51e142e84f5d8f51c4599fbabb1 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:40:35 -0700 Subject: [PATCH 049/107] kp_sampler_skip.cpp: fix sampler std::cout prints for test --- common/kokkos-sampler/kp_sampler_skip.cpp | 40 +++++++++-------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index db2545c60..386a88dc6 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,13 +51,11 @@ void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { tpi_funcs.fence(devID); if (tool_verbosity > 1) { - std::cout << "KokkosP: Sampler utility sucessfully invoked tool-induced " - "fence on device " + std::cout << "KokkosP: Sampler utility sucessfully invoked tool-induced fence on device " << getDeviceID(devID) << ".\n"; } } else { - std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's " - "tool-invoked Fence is NULL!\n"; + std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked Fence is NULL!\n"; exit(-1); } } @@ -66,9 +64,7 @@ void kokkosp_provide_tool_programming_interface( uint32_t num_funcs, Kokkos_Tools_ToolProgrammingInterface funcsFromTPI) { if (!num_funcs) { if (tool_verbosity > 0) - printf( - "KokkosP: Note: Number of functions in Tools Programming Interface " - "is 0!\n"); + std::cout << "KokkosP: Note: Number of functions in Tools Programming Interface is 0!\n"; } tpi_funcs = funcsFromTPI; } @@ -95,7 +91,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, "variable. Please use KOKKOS_TOOLS_LIBS\n"); profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); if (NULL == profileLibrary) { - printf("KokkosP: No library to call in %s\n", profileLibrary); + std::cout << "KokkosP: FATAL: No library to call in " << profileLibrary << "!\n"; exit(-1); } } @@ -112,12 +108,12 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, nextLibrary = strtok(NULL, ";"); if (NULL == nextLibrary) { - printf("KokkosP: No child library to call in %s\n", profileLibrary); + std::cout << "KokkosP: FATAL: No child library of sampler utility library to call in " << profileLibrary << "!\n"; exit(-1); } else { if (tool_verbosity > 0) { - printf("KokkosP: Next library to call: %s\n", nextLibrary); - printf("KokkosP: Loading child library ..\n"); + std::cout << "KokkosP: Next library to call: " << nextLibrary << "\n"; + std::cout << "KokkosP: Loading child library of sampler..\n"; } void* childLibrary = dlopen(nextLibrary, RTLD_NOW | RTLD_GLOBAL); @@ -152,19 +148,13 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } if (tool_verbosity > 0) { - printf("KokkosP: Function Status:\n"); - printf("KokkosP: begin-parallel-for: %s\n", - (beginForCallee == NULL) ? "no" : "yes"); - printf("KokkosP: begin-parallel-scan: %s\n", - (beginScanCallee == NULL) ? "no" : "yes"); - printf("KokkosP: begin-parallel-reduce: %s\n", - (beginReduceCallee == NULL) ? "no" : "yes"); - printf("KokkosP: end-parallel-for: %s\n", - (endForCallee == NULL) ? "no" : "yes"); - printf("KokkosP: end-parallel-scan: %s\n", - (endScanCallee == NULL) ? "no" : "yes"); - printf("KokkosP: end-parallel-reduce: %s\n", - (endReduceCallee == NULL) ? "no" : "yes"); + std::cout << "KokkosP: Function Status:\n"; + std::cout << "KokkosP: begin-parallel-for: " << ((beginForCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: begin-parallel-scan: " << ((beginScanCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: begin-parallel-reduce: " << ((beginReduceCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-for: " << ((endForCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-scan: " << ((endScanCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-reduce: " << ((endReduceCallee == NULL) ? "no" : "yes") << "\n"; } } } @@ -179,7 +169,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } if (tool_verbosity > 0) { - printf("KokkosP: Sampling rate set to: %s\n", tool_sample); + std::cout << "KokkosP: Sampling rate set to: " << tool_sample << "\n"; } } From 13ba3839aadcc1cabb1f2e3ed41292314cd2532f Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:43:26 -0700 Subject: [PATCH 050/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index fb240310f..8798a1639 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -65,15 +65,17 @@ TEST(SamplerTest, ktoEnvVarDefault) { } // end TEST EXPECT_THAT(output.str(), - ::testing::Contains("calling child-begin function...").Times(2)); - EXPECT_THAT( - output.str(), - ::testing::Contains("finished with child-begin function.").Times(2)); + ::testing::Contains("calling child-begin function...") + .::testing::Times(2)); EXPECT_THAT(output.str(), - ::testing::Contains("calling child-end function...").Times(2)); + ::testing::Contains("finished with child-begin function.") + .::testing::Times(2)); EXPECT_THAT( output.str(), - ::testing::Contains("finished with child-end function.").Times(2)); + ::testing::Contains("calling child-end function...").::testing::Times(2)); + EXPECT_THAT(output.str(), + ::testing::Contains("finished with child-end function.") + .::testing::Times(2)); EXPECT_THAT(output.str(), ::testing::Not("KokkosP: FATAL: Kokkos Tools Programming " From e18d2f589b53679375323e338d1c0e5d9c78cd20 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:46:49 -0700 Subject: [PATCH 051/107] test_parfor.cpp: fixing matcher string for number contains --- tests/sampler/test_parfor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 8798a1639..b842a1be2 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -66,16 +66,16 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), ::testing::Contains("calling child-begin function...") - .::testing::Times(2)); + .::testing::Times("2")); EXPECT_THAT(output.str(), ::testing::Contains("finished with child-begin function.") - .::testing::Times(2)); + .::testing::Times("2")); EXPECT_THAT( output.str(), - ::testing::Contains("calling child-end function...").::testing::Times(2)); + ::testing::Contains("calling child-end function...").::testing::Times("2")); EXPECT_THAT(output.str(), ::testing::Contains("finished with child-end function.") - .::testing::Times(2)); + .::testing::Times("2")); EXPECT_THAT(output.str(), ::testing::Not("KokkosP: FATAL: Kokkos Tools Programming " From 21ee9e25bcf638c332c4def22b73b1c27d82dabc Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:52:57 -0700 Subject: [PATCH 052/107] Update test_parfor.cpp: not substr --- tests/sampler/test_parfor.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index b842a1be2..bf068b95d 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -67,17 +67,22 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), ::testing::Contains("calling child-begin function...") .::testing::Times("2")); + EXPECT_THAT(output.str(), ::testing::Contains("finished with child-begin function.") .::testing::Times("2")); EXPECT_THAT( output.str(), ::testing::Contains("calling child-end function...").::testing::Times("2")); + EXPECT_THAT(output.str(), ::testing::Contains("finished with child-end function.") .::testing::Times("2")); EXPECT_THAT(output.str(), - ::testing::Not("KokkosP: FATAL: Kokkos Tools Programming " - "Interface's tool-invoked Fence is NULL!")); + ::testing::Not(::testing::HasSubstr("KokkosP: FATAL: No child library of sampler utility library to call"))); + + EXPECT_THAT(output.str(), + ::testing::Not(::testing::HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); } From 48b869dd8ed7516a40c3d4e874c9720594ec234e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:53:18 -0700 Subject: [PATCH 053/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index bf068b95d..35a8c0ec0 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -71,18 +71,19 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), ::testing::Contains("finished with child-begin function.") .::testing::Times("2")); - EXPECT_THAT( - output.str(), - ::testing::Contains("calling child-end function...").::testing::Times("2")); + EXPECT_THAT(output.str(), ::testing::Contains("calling child-end function...") + .::testing::Times("2")); EXPECT_THAT(output.str(), ::testing::Contains("finished with child-end function.") .::testing::Times("2")); - EXPECT_THAT(output.str(), - ::testing::Not(::testing::HasSubstr("KokkosP: FATAL: No child library of sampler utility library to call"))); + EXPECT_THAT( + output.str(), + ::testing::Not(::testing::HasSubstr("KokkosP: FATAL: No child library of " + "sampler utility library to call"))); - EXPECT_THAT(output.str(), - ::testing::Not(::testing::HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " - "Interface's tool-invoked Fence is NULL!"))); + EXPECT_THAT(output.str(), ::testing::Not(::testing::HasSubstr( + "KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); } From 756bd68b93ecd2836b148e2c142331a98f179c2a Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:55:50 -0700 Subject: [PATCH 054/107] kp_sampler_skip.cpp: apply clang format --- common/kokkos-sampler/kp_sampler_skip.cpp | 337 ---------------------- 1 file changed, 337 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 386a88dc6..e69de29bb 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -1,337 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "../../profiling/all/kp_core.hpp" -#include "kp_config.hpp" -#include - -namespace KokkosTools { -namespace Sampler { -static uint64_t uniqID = 0; -static uint64_t kernelSampleSkip = 101; -static int tool_verbosity = 0; -static int tool_globFence = 0; - -// a hash table mapping kID to nestedkID -static std::unordered_map infokIDSample; - -typedef void (*initFunction)(const int, const uint64_t, const uint32_t, void*); -typedef void (*finalizeFunction)(); -typedef void (*beginFunction)(const char*, const uint32_t, uint64_t*); -typedef void (*endFunction)(uint64_t); - -static initFunction initProfileLibrary = NULL; -static finalizeFunction finalizeProfileLibrary = NULL; -static beginFunction beginForCallee = NULL; -static beginFunction beginScanCallee = NULL; -static beginFunction beginReduceCallee = NULL; -static endFunction endForCallee = NULL; -static endFunction endScanCallee = NULL; -static endFunction endReduceCallee = NULL; - -void kokkosp_request_tool_settings(const uint32_t, - Kokkos_Tools_ToolSettings* settings) { - settings->requires_global_fencing = false; -} - -// set of functions from Kokkos ToolProgrammingInterface (includes fence) -Kokkos::Tools::Experimental::ToolProgrammingInterface tpi_funcs; - -uint32_t getDeviceID(uint32_t devid_in) { - int num_device_bits = 7; - int num_instance_bits = 17; - return (~((uint32_t(-1)) << num_device_bits)) & - (devid_in >> num_instance_bits); -} - -void invoke_ktools_fence(uint32_t devID) { - if (tpi_funcs.fence != nullptr) { - tpi_funcs.fence(devID); - if (tool_verbosity > 1) { - std::cout << "KokkosP: Sampler utility sucessfully invoked tool-induced fence on device " - << getDeviceID(devID) << ".\n"; - } - } else { - std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked Fence is NULL!\n"; - exit(-1); - } -} - -void kokkosp_provide_tool_programming_interface( - uint32_t num_funcs, Kokkos_Tools_ToolProgrammingInterface funcsFromTPI) { - if (!num_funcs) { - if (tool_verbosity > 0) - std::cout << "KokkosP: Note: Number of functions in Tools Programming Interface is 0!\n"; - } - tpi_funcs = funcsFromTPI; -} - -void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, - const uint32_t devInfoCount, void* deviceInfo) { - const char* tool_verbose_str = getenv("KOKKOS_TOOLS_SAMPLER_VERBOSE"); - const char* tool_globFence_str = getenv("KOKKOS_TOOLS_GLOBALFENCES"); - if (NULL != tool_verbose_str) { - tool_verbosity = atoi(tool_verbose_str); - } else { - tool_verbosity = 0; - } - if (NULL != tool_globFence_str) { - tool_globFence = atoi(tool_globFence_str); - } else { - tool_globFence = 0; - } - - char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); - if (NULL == profileLibrary) { - printf( - "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a depreciated " - "variable. Please use KOKKOS_TOOLS_LIBS\n"); - profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); - if (NULL == profileLibrary) { - std::cout << "KokkosP: FATAL: No library to call in " << profileLibrary << "!\n"; - exit(-1); - } - } - - char* envBuffer = (char*)malloc(sizeof(char) * (strlen(profileLibrary) + 1)); - strcpy(envBuffer, profileLibrary); - - char* nextLibrary = strtok(envBuffer, ";"); - - for (int i = 0; i < loadSeq; i++) { - nextLibrary = strtok(NULL, ";"); - } - - nextLibrary = strtok(NULL, ";"); - - if (NULL == nextLibrary) { - std::cout << "KokkosP: FATAL: No child library of sampler utility library to call in " << profileLibrary << "!\n"; - exit(-1); - } else { - if (tool_verbosity > 0) { - std::cout << "KokkosP: Next library to call: " << nextLibrary << "\n"; - std::cout << "KokkosP: Loading child library of sampler..\n"; - } - - void* childLibrary = dlopen(nextLibrary, RTLD_NOW | RTLD_GLOBAL); - - if (NULL == childLibrary) { - fprintf(stderr, "KokkosP: Error: Unable to load: %s (Error=%s)\n", - nextLibrary, dlerror()); - exit(-1); - } else { - beginForCallee = - (beginFunction)dlsym(childLibrary, "kokkosp_begin_parallel_for"); - beginScanCallee = - (beginFunction)dlsym(childLibrary, "kokkosp_begin_parallel_scan"); - beginReduceCallee = - (beginFunction)dlsym(childLibrary, "kokkosp_begin_parallel_reduce"); - - endScanCallee = - (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_scan"); - endForCallee = - (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_for"); - endReduceCallee = - (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_reduce"); - - initProfileLibrary = - (initFunction)dlsym(childLibrary, "kokkosp_init_library"); - finalizeProfileLibrary = - (finalizeFunction)dlsym(childLibrary, "kokkosp_finalize_library"); - - if (NULL != initProfileLibrary) { - (*initProfileLibrary)(loadSeq + 1, interfaceVer, devInfoCount, - deviceInfo); - } - - if (tool_verbosity > 0) { - std::cout << "KokkosP: Function Status:\n"; - std::cout << "KokkosP: begin-parallel-for: " << ((beginForCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: begin-parallel-scan: " << ((beginScanCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: begin-parallel-reduce: " << ((beginReduceCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: end-parallel-for: " << ((endForCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: end-parallel-scan: " << ((endScanCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: end-parallel-reduce: " << ((endReduceCallee == NULL) ? "no" : "yes") << "\n"; - } - } - } - - free(envBuffer); - - uniqID = 1; - - const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); - if (NULL != tool_sample) { - kernelSampleSkip = atoi(tool_sample) + 1; - } - - if (tool_verbosity > 0) { - std::cout << "KokkosP: Sampling rate set to: " << tool_sample << "\n"; - } -} - -void kokkosp_finalize_library() { - if (NULL != finalizeProfileLibrary) (*finalizeProfileLibrary)(); -} - -void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, - uint64_t* kID) { - *kID = uniqID++; - static uint64_t invocationNum = 0; - ++invocationNum; - if ((invocationNum % kernelSampleSkip) == 0) { - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " calling child-begin function...\n"; - } - if (tool_globFence) { - invoke_ktools_fence(0); - } - if (NULL != beginForCallee) { - uint64_t nestedkID = 0; - (*beginForCallee)(name, devID, &nestedkID); - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " finished with child-begin function.\n"; - } - infokIDSample.insert({*kID, nestedkID}); - } - } -} - -void kokkosp_end_parallel_for(const uint64_t kID) { - if (NULL != endForCallee) { - if (!(infokIDSample.find(kID) == infokIDSample.end())) { - uint64_t retrievedNestedkID = infokIDSample[kID]; - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " calling child-end function...\n"; - } - - if (tool_globFence) { - invoke_ktools_fence(0); - } - (*endForCallee)(retrievedNestedkID); - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " finished with child-end function.\n"; - } - infokIDSample.erase(kID); - } - } -} - -void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, - uint64_t* kID) { - *kID = uniqID++; - static uint64_t invocationNum = 0; - ++invocationNum; - if ((invocationNum % kernelSampleSkip) == 0) { - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " calling child-begin function...\n"; - } - if (NULL != beginScanCallee) { - uint64_t nestedkID = 0; - if (tool_globFence) { - invoke_ktools_fence(0); - } - (*beginScanCallee)(name, devID, &nestedkID); - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " finished with child-begin function.\n"; - } - infokIDSample.insert({*kID, nestedkID}); - } - } -} - -void kokkosp_end_parallel_scan(const uint64_t kID) { - if (NULL != endScanCallee) { - if (!(infokIDSample.find(kID) == infokIDSample.end())) { - uint64_t retrievedNestedkID = infokIDSample[kID]; - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " calling child-end function...\n"; - } - if (tool_globFence) { - invoke_ktools_fence(0); - } - (*endScanCallee)(retrievedNestedkID); - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " finished with child-end function.\n"; - } - infokIDSample.erase(kID); - } - } -} - -void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, - uint64_t* kID) { - *kID = uniqID++; - static uint64_t invocationNum = 0; - ++invocationNum; - if ((invocationNum % kernelSampleSkip) == 0) { - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " calling child-begin function...\n"; - } - if (NULL != beginReduceCallee) { - uint64_t nestedkID = 0; - if (tool_globFence) { - invoke_ktools_fence(0); - } - (*beginReduceCallee)(name, devID, &nestedkID); - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << *kID - << " finished with child-begin function.\n"; - } - infokIDSample.insert({*kID, nestedkID}); - } - } -} - -void kokkosp_end_parallel_reduce(const uint64_t kID) { - if (NULL != endReduceCallee) { - if (!(infokIDSample.find(kID) == infokIDSample.end())) { - uint64_t retrievedNestedkID = infokIDSample[kID]; - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " calling child-end function...\n"; - } - if (tool_globFence) { - invoke_ktools_fence(0); - } - (*endReduceCallee)(retrievedNestedkID); - if (tool_verbosity > 0) { - std::cout << "KokkosP: sample " << kID - << " finished with child-end function.\n"; - } - infokIDSample.erase(kID); - } - } -} - -} // namespace Sampler -} // end namespace KokkosTools - -extern "C" { - -namespace impl = KokkosTools::Sampler; -EXPOSE_TOOL_SETTINGS(impl::kokkosp_request_tool_settings) -EXPOSE_PROVIDE_TOOL_PROGRAMMING_INTERFACE( - impl::kokkosp_provide_tool_programming_interface) -EXPOSE_INIT(impl::kokkosp_init_library) -EXPOSE_FINALIZE(impl::kokkosp_finalize_library) -EXPOSE_BEGIN_PARALLEL_FOR(impl::kokkosp_begin_parallel_for) -EXPOSE_END_PARALLEL_FOR(impl::kokkosp_end_parallel_for) -EXPOSE_BEGIN_PARALLEL_SCAN(impl::kokkosp_begin_parallel_scan) -EXPOSE_END_PARALLEL_SCAN(impl::kokkosp_end_parallel_scan) -EXPOSE_BEGIN_PARALLEL_REDUCE(impl::kokkosp_begin_parallel_reduce) -EXPOSE_END_PARALLEL_REDUCE(impl::kokkosp_end_parallel_reduce) - -} // end extern "C" From 6e28d67bb44e7cdf7af493540c0c709694ed4f08 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:22:15 -0700 Subject: [PATCH 055/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 35a8c0ec0..3293111a4 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -6,6 +6,11 @@ #include "Kokkos_Core.hpp" +using ::testing::Contains; +using ::testing::HasSubstr; +using ::testing::Not; +using ::testing::Times; + struct Tester { template explicit Tester(const execution_space& space) { @@ -61,29 +66,25 @@ TEST(SamplerTest, ktoEnvVarDefault) { //! Analyze test output. for (const auto& matcher : matchers) { - EXPECT_THAT(output.str(), ::testing::HasSubstr(matcher)); + EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST EXPECT_THAT(output.str(), - ::testing::Contains("calling child-begin function...") - .::testing::Times("2")); + Contains.Times(AtMost(2), "calling child-begin function...")); + + EXPECT_THAT(output.str(), + Contains.Times(AtMost(2), "finished with child-begin function.")); EXPECT_THAT(output.str(), - ::testing::Contains("finished with child-begin function.") - .::testing::Times("2")); - EXPECT_THAT(output.str(), ::testing::Contains("calling child-end function...") - .::testing::Times("2")); + Contains.Times(AtMost(2), "calling child-end function...")); EXPECT_THAT(output.str(), - ::testing::Contains("finished with child-end function.") - .::testing::Times("2")); + Contains.Times(AtMost(2), "finished with child-end function.")); - EXPECT_THAT( - output.str(), - ::testing::Not(::testing::HasSubstr("KokkosP: FATAL: No child library of " + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); - EXPECT_THAT(output.str(), ::testing::Not(::testing::HasSubstr( - "KokkosP: FATAL: Kokkos Tools Programming " - "Interface's tool-invoked Fence is NULL!"))); + EXPECT_THAT(output.str(), + Not(HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); } From 57a66fcc6776e02e0e04c9795b535af3ba74fa3c Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:26:37 -0700 Subject: [PATCH 056/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 1 + tests/test_parfor.cpp | 0 2 files changed, 1 insertion(+) create mode 100644 tests/test_parfor.cpp diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 3293111a4..64ac8b883 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -10,6 +10,7 @@ using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; using ::testing::Times; +using ::testing::AtMost; struct Tester { template diff --git a/tests/test_parfor.cpp b/tests/test_parfor.cpp new file mode 100644 index 000000000..e69de29bb From a0a8483e6d70bdbbc2fd769754b0bd980e3b5419 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:31:45 -0700 Subject: [PATCH 057/107] Update test_parfor.cpp --- tests/sampler/test_parfor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 64ac8b883..e9fab33b5 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -71,16 +71,16 @@ TEST(SamplerTest, ktoEnvVarDefault) { } // end TEST EXPECT_THAT(output.str(), - Contains.Times(AtMost(2), "calling child-begin function...")); + Contains.::testing:::Times(AtMost(2), "calling child-begin function...")); EXPECT_THAT(output.str(), - Contains.Times(AtMost(2), "finished with child-begin function.")); + Contains.::testing::Times(AtMost(2), "finished with child-begin function.")); EXPECT_THAT(output.str(), - Contains.Times(AtMost(2), "calling child-end function...")); + Contains.::testing::Times(AtMost(2), "calling child-end function...")); EXPECT_THAT(output.str(), - Contains.Times(AtMost(2), "finished with child-end function.")); + Contains.::testing::Times(AtMost(2), "finished with child-end function.")); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 7f0a70d3374851c0e5afe9ca1011386e4dd0caa1 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:32:25 -0700 Subject: [PATCH 058/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index e9fab33b5..d3435f68a 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -6,11 +6,11 @@ #include "Kokkos_Core.hpp" +using ::testing::AtMost; using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; using ::testing::Times; -using ::testing::AtMost; struct Tester { template @@ -70,17 +70,19 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), - Contains.::testing:::Times(AtMost(2), "calling child-begin function...")); + EXPECT_THAT(output.str(), Contains.::testing:: + : Times(AtMost(2), "calling child-begin function...")); EXPECT_THAT(output.str(), - Contains.::testing::Times(AtMost(2), "finished with child-begin function.")); + Contains.::testing::Times(AtMost(2), + "finished with child-begin function.")); - EXPECT_THAT(output.str(), - Contains.::testing::Times(AtMost(2), "calling child-end function...")); + EXPECT_THAT(output.str(), Contains.::testing::Times( + AtMost(2), "calling child-end function...")); EXPECT_THAT(output.str(), - Contains.::testing::Times(AtMost(2), "finished with child-end function.")); + Contains.::testing::Times(AtMost(2), + "finished with child-end function.")); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 89ea724514406a1845388b0c78ed7a774883aa92 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:41:25 -0700 Subject: [PATCH 059/107] test_parfor.cpp: Times function --- tests/sampler/test_parfor.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index d3435f68a..ce75c09b7 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -70,18 +70,17 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), Contains.::testing:: - : Times(AtMost(2), "calling child-begin function...")); + EXPECT_THAT(output.str(), Contains.Times(AtMost(2), "calling child-begin function...")); EXPECT_THAT(output.str(), - Contains.::testing::Times(AtMost(2), + Contains.Times(AtMost(2), "finished with child-begin function.")); - EXPECT_THAT(output.str(), Contains.::testing::Times( + EXPECT_THAT(output.str(), Contains.Times( AtMost(2), "calling child-end function...")); EXPECT_THAT(output.str(), - Contains.::testing::Times(AtMost(2), + Contains.Times(AtMost(2), "finished with child-end function.")); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " From f4227bee793d2fdcf14041b242e5af15fe175dc1 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:47:27 -0700 Subject: [PATCH 060/107] delete file accidentally put in tests directory --- tests/test_parfor.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/test_parfor.cpp diff --git a/tests/test_parfor.cpp b/tests/test_parfor.cpp deleted file mode 100644 index e69de29bb..000000000 From 5b87797da51ef474f431370ffae252bd20cb4e82 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:50:38 -0700 Subject: [PATCH 061/107] Update test_parfor.cpp: remove AtMost --- tests/sampler/test_parfor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index ce75c09b7..7c59c0495 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -70,17 +70,17 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), Contains.Times(AtMost(2), "calling child-begin function...")); + EXPECT_THAT(output.str(), Contains.Times(2, "calling child-begin function...")); EXPECT_THAT(output.str(), - Contains.Times(AtMost(2), + Contains.Times(2, "finished with child-begin function.")); EXPECT_THAT(output.str(), Contains.Times( - AtMost(2), "calling child-end function...")); + 2, "calling child-end function...")); EXPECT_THAT(output.str(), - Contains.Times(AtMost(2), + Contains.Times(2, "finished with child-end function.")); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " From 9abf32ea1ad7915038451f086350d3c33e95f303 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:51:07 -0700 Subject: [PATCH 062/107] Update test_parfor.cpp: remove using AtMost --- tests/sampler/test_parfor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 7c59c0495..2aa0c11a2 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -6,7 +6,6 @@ #include "Kokkos_Core.hpp" -using ::testing::AtMost; using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; From d363a92ea721c9a6bb3399e6a86e515b4cd6149e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:05:11 -0700 Subject: [PATCH 063/107] kp_sampler_skip.cpp: put back in --- common/kokkos-sampler/kp_sampler_skip.cpp | 337 ++++++++++++++++++++++ 1 file changed, 337 insertions(+) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index e69de29bb..54ae2ba8e 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -0,0 +1,337 @@ +#include +#include +#include +#include +#include +#include +#include "../../profiling/all/kp_core.hpp" +#include "kp_config.hpp" +#include + +namespace KokkosTools { +namespace Sampler { +static uint64_t uniqID = 0; +static uint64_t kernelSampleSkip = 101; +static int tool_verbosity = 0; +static int tool_globFence = 0; + +// a hash table mapping kID to nestedkID +static std::unordered_map infokIDSample; + +typedef void (*initFunction)(const int, const uint64_t, const uint32_t, void*); +typedef void (*finalizeFunction)(); +typedef void (*beginFunction)(const char*, const uint32_t, uint64_t*); +typedef void (*endFunction)(uint64_t); + +static initFunction initProfileLibrary = NULL; +static finalizeFunction finalizeProfileLibrary = NULL; +static beginFunction beginForCallee = NULL; +static beginFunction beginScanCallee = NULL; +static beginFunction beginReduceCallee = NULL; +static endFunction endForCallee = NULL; +static endFunction endScanCallee = NULL; +static endFunction endReduceCallee = NULL; + +void kokkosp_request_tool_settings(const uint32_t, + Kokkos_Tools_ToolSettings* settings) { + settings->requires_global_fencing = false; +} + +// set of functions from Kokkos ToolProgrammingInterface (includes fence) +Kokkos::Tools::Experimental::ToolProgrammingInterface tpi_funcs; + +uint32_t getDeviceID(uint32_t devid_in) { + int num_device_bits = 7; + int num_instance_bits = 17; + return (~((uint32_t(-1)) << num_device_bits)) & + (devid_in >> num_instance_bits); +} + +void invoke_ktools_fence(uint32_t devID) { + if (tpi_funcs.fence != nullptr) { + tpi_funcs.fence(devID); + if (tool_verbosity > 1) { + std::cout << "KokkosP: Sampler utility sucessfully invoked tool-induced fence on device " + << getDeviceID(devID) << ".\n"; + } + } else { + std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked Fence is NULL!\n"; + exit(-1); + } +} + +void kokkosp_provide_tool_programming_interface( + uint32_t num_funcs, Kokkos_Tools_ToolProgrammingInterface funcsFromTPI) { + if (!num_funcs) { + if (tool_verbosity > 0) + std::cout << "KokkosP: Note: Number of functions in Tools Programming Interface is 0!\n"; + } + tpi_funcs = funcsFromTPI; +} + +void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, + const uint32_t devInfoCount, void* deviceInfo) { + const char* tool_verbose_str = getenv("KOKKOS_TOOLS_SAMPLER_VERBOSE"); + const char* tool_globFence_str = getenv("KOKKOS_TOOLS_GLOBALFENCES"); + if (NULL != tool_verbose_str) { + tool_verbosity = atoi(tool_verbose_str); + } else { + tool_verbosity = 0; + } + if (NULL != tool_globFence_str) { + tool_globFence = atoi(tool_globFence_str); + } else { + tool_globFence = 0; + } + + char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); + if (NULL == profileLibrary) { + printf( + "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a depreciated " + "variable. Please use KOKKOS_TOOLS_LIBS\n"); + profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); + if (NULL == profileLibrary) { + std::cout << "KokkosP: FATAL: No library to call in " << profileLibrary << "!\n"; + exit(-1); + } + } + + char* envBuffer = (char*)malloc(sizeof(char) * (strlen(profileLibrary) + 1)); + strcpy(envBuffer, profileLibrary); + + char* nextLibrary = strtok(envBuffer, ";"); + + for (int i = 0; i < loadSeq; i++) { + nextLibrary = strtok(NULL, ";"); + } + + nextLibrary = strtok(NULL, ";"); + + if (NULL == nextLibrary) { + std::cout << "KokkosP: FATAL: No child library of sampler utility library to call in " << profileLibrary << "!\n"; + exit(-1); + } else { + if (tool_verbosity > 0) { + std::cout << "KokkosP: Next library to call: " << nextLibrary << "\n"; + std::cout << "KokkosP: Loading child library of sampler..\n"; + } + + void* childLibrary = dlopen(nextLibrary, RTLD_NOW | RTLD_GLOBAL); + + if (NULL == childLibrary) { + fprintf(stderr, "KokkosP: Error: Unable to load: %s (Error=%s)\n", + nextLibrary, dlerror()); + exit(-1); + } else { + beginForCallee = + (beginFunction)dlsym(childLibrary, "kokkosp_begin_parallel_for"); + beginScanCallee = + (beginFunction)dlsym(childLibrary, "kokkosp_begin_parallel_scan"); + beginReduceCallee = + (beginFunction)dlsym(childLibrary, "kokkosp_begin_parallel_reduce"); + + endScanCallee = + (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_scan"); + endForCallee = + (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_for"); + endReduceCallee = + (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_reduce"); + + initProfileLibrary = + (initFunction)dlsym(childLibrary, "kokkosp_init_library"); + finalizeProfileLibrary = + (finalizeFunction)dlsym(childLibrary, "kokkosp_finalize_library"); + + if (NULL != initProfileLibrary) { + (*initProfileLibrary)(loadSeq + 1, interfaceVer, devInfoCount, + deviceInfo); + } + + if (tool_verbosity > 0) { + std::cout << "KokkosP: Function Status:\n"; + std::cout << "KokkosP: begin-parallel-for: " << ((beginForCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: begin-parallel-scan: " << ((beginScanCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: begin-parallel-reduce: " << ((beginReduceCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-for: " << ((endForCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-scan: " << ((endScanCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-reduce: " << ((endReduceCallee == NULL) ? "no" : "yes") << "\n"; + } + } + } + + free(envBuffer); + + uniqID = 1; + + const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); + if (NULL != tool_sample) { + kernelSampleSkip = atoi(tool_sample) + 1; + } + + if (tool_verbosity > 0) { + std::cout << "KokkosP: Sampling rate set to: " << tool_sample << "\n"; + } +} + +void kokkosp_finalize_library() { + if (NULL != finalizeProfileLibrary) (*finalizeProfileLibrary)(); +} + +void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, + uint64_t* kID) { + *kID = uniqID++; + static uint64_t invocationNum = 0; + ++invocationNum; + if ((invocationNum % kernelSampleSkip) == 0) { + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function...\n"; + } + if (tool_globFence) { + invoke_ktools_fence(0); + } + if (NULL != beginForCallee) { + uint64_t nestedkID = 0; + (*beginForCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " finished with child-begin function.\n"; + } + infokIDSample.insert({*kID, nestedkID}); + } + } +} + +void kokkosp_end_parallel_for(const uint64_t kID) { + if (NULL != endForCallee) { + if (!(infokIDSample.find(kID) == infokIDSample.end())) { + uint64_t retrievedNestedkID = infokIDSample[kID]; + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " calling child-end function...\n"; + } + + if (tool_globFence) { + invoke_ktools_fence(0); + } + (*endForCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " finished with child-end function.\n"; + } + infokIDSample.erase(kID); + } + } +} + +void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, + uint64_t* kID) { + *kID = uniqID++; + static uint64_t invocationNum = 0; + ++invocationNum; + if ((invocationNum % kernelSampleSkip) == 0) { + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function...\n"; + } + if (NULL != beginScanCallee) { + uint64_t nestedkID = 0; + if (tool_globFence) { + invoke_ktools_fence(0); + } + (*beginScanCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " finished with child-begin function.\n"; + } + infokIDSample.insert({*kID, nestedkID}); + } + } +} + +void kokkosp_end_parallel_scan(const uint64_t kID) { + if (NULL != endScanCallee) { + if (!(infokIDSample.find(kID) == infokIDSample.end())) { + uint64_t retrievedNestedkID = infokIDSample[kID]; + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " calling child-end function...\n"; + } + if (tool_globFence) { + invoke_ktools_fence(0); + } + (*endScanCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " finished with child-end function.\n"; + } + infokIDSample.erase(kID); + } + } +} + +void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, + uint64_t* kID) { + *kID = uniqID++; + static uint64_t invocationNum = 0; + ++invocationNum; + if ((invocationNum % kernelSampleSkip) == 0) { + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " calling child-begin function...\n"; + } + if (NULL != beginReduceCallee) { + uint64_t nestedkID = 0; + if (tool_globFence) { + invoke_ktools_fence(0); + } + (*beginReduceCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << *kID + << " finished with child-begin function.\n"; + } + infokIDSample.insert({*kID, nestedkID}); + } + } +} + +void kokkosp_end_parallel_reduce(const uint64_t kID) { + if (NULL != endReduceCallee) { + if (!(infokIDSample.find(kID) == infokIDSample.end())) { + uint64_t retrievedNestedkID = infokIDSample[kID]; + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " calling child-end function...\n"; + } + if (tool_globFence) { + invoke_ktools_fence(0); + } + (*endReduceCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " finished with child-end function.\n"; + } + infokIDSample.erase(kID); + } + } +} + +} // namespace Sampler +} // end namespace KokkosTools + +extern "C" { + +namespace impl = KokkosTools::Sampler; +EXPOSE_TOOL_SETTINGS(impl::kokkosp_request_tool_settings) +EXPOSE_PROVIDE_TOOL_PROGRAMMING_INTERFACE( + impl::kokkosp_provide_tool_programming_interface) +EXPOSE_INIT(impl::kokkosp_init_library) +EXPOSE_FINALIZE(impl::kokkosp_finalize_library) +EXPOSE_BEGIN_PARALLEL_FOR(impl::kokkosp_begin_parallel_for) +EXPOSE_END_PARALLEL_FOR(impl::kokkosp_end_parallel_for) +EXPOSE_BEGIN_PARALLEL_SCAN(impl::kokkosp_begin_parallel_scan) +EXPOSE_END_PARALLEL_SCAN(impl::kokkosp_end_parallel_scan) +EXPOSE_BEGIN_PARALLEL_REDUCE(impl::kokkosp_begin_parallel_reduce) +EXPOSE_END_PARALLEL_REDUCE(impl::kokkosp_end_parallel_reduce) + +} // end extern "C" From 23d0f8180e8bfbdd49ff3c7b340c4f33b206f2f7 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:24:01 -0700 Subject: [PATCH 064/107] Update test_parreduce.cpp --- tests/sampler/test_parreduce.cpp | 37 +++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 95eaa35b5..c0497c9e2 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -6,6 +6,8 @@ #include "Kokkos_Core.hpp" +using ::testing::HasSubstr; +using ::testing::Not; struct Tester { template explicit Tester(const execution_space& space) { @@ -17,7 +19,7 @@ struct Tester { long int sum; for (int iter = 0; iter < 150; iter++) { sum = 0; - Kokkos::parallel_reduce("named kernel", + Kokkos::parallel_reduce("named kernel reduce", Kokkos::RangePolicy(space, 0, 1), *this, sum); } @@ -27,20 +29,23 @@ struct Tester { }; static const std::vector matchers{ - "(.*)KokkosP: sample 51 calling child-begin function...(.*)", - "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", - "(.*)KokkosP: sample 51 calling child-end function...(.*)", - "(.*)KokkosP: sample 51 finished with child-end function.(.*)", - "(.*)KokkosP: sample 102 calling child-begin function...(.*)", - "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", - "(.*)KokkosP: sample 102 calling child-end function...(.*)", - "(.*)KokkosP: sample 102 finished with child-end function.(.*)"}; + "KokkosP: sample 51 calling child-begin function...", + "KokkosP: sample 51 finished with child-begin function.", + "KokkosP: sample 51 calling child-end function...", + "KokkosP: sample 51 finished with child-end function.", + "KokkosP: sample 102 calling child-begin function...", + "KokkosP: sample 102 finished with child-begin function.", + "KokkosP: sample 102 calling child-end function...", + "KokkosP: sample 102 finished with child-end function."}; + /** * @test This test checks that the tool effectively samples. * */ + + TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. Kokkos::initialize(); @@ -57,12 +62,20 @@ TEST(SamplerTest, ktoEnvVarDefault) { Kokkos::finalize(); //! Restore output buffer. - // std::cout.flush(); + std::cout.flush(); std::cout.rdbuf(coutbuf); std::cout << output.str() << std::endl; //! Analyze test output. for (const auto& matcher : matchers) { - EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); - } // end TEST + EXPECT_THAT(output.str(), HasSubstr(matcher)); + } + + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " + "sampler utility library to call"))); + + EXPECT_THAT(output.str(), + Not(HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); + } From ffbbb85267fdf026ed1395bd3a95e568b00f1b62 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:25:31 -0700 Subject: [PATCH 065/107] test_parfor.cpp: remove count for number of times --- tests/sampler/test_parfor.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 2aa0c11a2..fcfe70693 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -69,18 +69,6 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), Contains.Times(2, "calling child-begin function...")); - - EXPECT_THAT(output.str(), - Contains.Times(2, - "finished with child-begin function.")); - - EXPECT_THAT(output.str(), Contains.Times( - 2, "calling child-end function...")); - - EXPECT_THAT(output.str(), - Contains.Times(2, - "finished with child-end function.")); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 660c4ba0e2067501a9d9d0638684c6e15ae466e9 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:27:17 -0700 Subject: [PATCH 066/107] Update test_parscan.cpp --- tests/sampler/test_parscan.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index db389c1e7..ff53d7db1 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -6,6 +6,8 @@ #include "Kokkos_Core.hpp" +using ::testing::HasSubstr; +using ::testing::Not; struct Tester { template explicit Tester(const execution_space& space) { @@ -41,6 +43,7 @@ static const std::vector matchers{ * */ + TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. Kokkos::initialize(); @@ -57,12 +60,19 @@ TEST(SamplerTest, ktoEnvVarDefault) { Kokkos::finalize(); //! Restore output buffer. - // std::cout.flush(); + std::cout.flush(); std::cout.rdbuf(coutbuf); std::cout << output.str() << std::endl; //! Analyze test output. for (const auto& matcher : matchers) { - EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); + EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST + + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " + "sampler utility library to call"))); + + EXPECT_THAT(output.str(), + Not(HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); } From 17ed28552ab33c81b401613bbc3f9f58fded42fe Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:28:11 -0700 Subject: [PATCH 067/107] Update test_parfor.cpp: removing Contains --- tests/sampler/test_parfor.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index fcfe70693..7202b05b5 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -6,10 +6,8 @@ #include "Kokkos_Core.hpp" -using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; -using ::testing::Times; struct Tester { template From 7b8db70c4eedcd59160965ee22422e7df82984a7 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:32:21 -0700 Subject: [PATCH 068/107] kp_sampler_skip.cpp: apply clang format --- common/kokkos-sampler/kp_sampler_skip.cpp | 34 +++++++++++++++-------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 54ae2ba8e..78cbbff4b 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,11 +51,13 @@ void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { tpi_funcs.fence(devID); if (tool_verbosity > 1) { - std::cout << "KokkosP: Sampler utility sucessfully invoked tool-induced fence on device " + std::cout << "KokkosP: Sampler utility sucessfully invoked tool-induced " + "fence on device " << getDeviceID(devID) << ".\n"; } } else { - std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked Fence is NULL!\n"; + std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's " + "tool-invoked Fence is NULL!\n"; exit(-1); } } @@ -64,7 +66,8 @@ void kokkosp_provide_tool_programming_interface( uint32_t num_funcs, Kokkos_Tools_ToolProgrammingInterface funcsFromTPI) { if (!num_funcs) { if (tool_verbosity > 0) - std::cout << "KokkosP: Note: Number of functions in Tools Programming Interface is 0!\n"; + std::cout << "KokkosP: Note: Number of functions in Tools Programming " + "Interface is 0!\n"; } tpi_funcs = funcsFromTPI; } @@ -91,7 +94,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, "variable. Please use KOKKOS_TOOLS_LIBS\n"); profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); if (NULL == profileLibrary) { - std::cout << "KokkosP: FATAL: No library to call in " << profileLibrary << "!\n"; + std::cout << "KokkosP: FATAL: No library to call in " << profileLibrary + << "!\n"; exit(-1); } } @@ -108,7 +112,9 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, nextLibrary = strtok(NULL, ";"); if (NULL == nextLibrary) { - std::cout << "KokkosP: FATAL: No child library of sampler utility library to call in " << profileLibrary << "!\n"; + std::cout << "KokkosP: FATAL: No child library of sampler utility library " + "to call in " + << profileLibrary << "!\n"; exit(-1); } else { if (tool_verbosity > 0) { @@ -149,12 +155,18 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, if (tool_verbosity > 0) { std::cout << "KokkosP: Function Status:\n"; - std::cout << "KokkosP: begin-parallel-for: " << ((beginForCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: begin-parallel-scan: " << ((beginScanCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: begin-parallel-reduce: " << ((beginReduceCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: end-parallel-for: " << ((endForCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: end-parallel-scan: " << ((endScanCallee == NULL) ? "no" : "yes") << "\n"; - std::cout << "KokkosP: end-parallel-reduce: " << ((endReduceCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: begin-parallel-for: " + << ((beginForCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: begin-parallel-scan: " + << ((beginScanCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: begin-parallel-reduce: " + << ((beginReduceCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-for: " + << ((endForCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-scan: " + << ((endScanCallee == NULL) ? "no" : "yes") << "\n"; + std::cout << "KokkosP: end-parallel-reduce: " + << ((endReduceCallee == NULL) ? "no" : "yes") << "\n"; } } } From a1cb3fd5c4e825f13e30b1e2c2c77a989a245c3e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:33:29 -0700 Subject: [PATCH 069/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 7202b05b5..ad3a81f90 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -67,7 +67,6 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 388ca7b5af74336988266699a0b2c82a00e9de56 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:34:30 -0700 Subject: [PATCH 070/107] test_parreduce.cpp: apply clang format --- tests/sampler/test_parreduce.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index c0497c9e2..0d4419896 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -38,14 +38,12 @@ static const std::vector matchers{ "KokkosP: sample 102 calling child-end function...", "KokkosP: sample 102 finished with child-end function."}; - /** * @test This test checks that the tool effectively samples. * */ - TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. Kokkos::initialize(); @@ -77,5 +75,4 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " "Interface's tool-invoked Fence is NULL!"))); - } From 4dea6292776aca627f0daefd5c57be3536fad409 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:39:13 -0700 Subject: [PATCH 071/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index ff53d7db1..1913eb78a 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -29,14 +29,14 @@ struct Tester { }; static const std::vector matchers{ - "(.*)KokkosP: sample 51 calling child-begin function...(.*)", - "(.*)KokkosP: sample 51 finished with child-begin function.(.*)", - "(.*)KokkosP: sample 51 calling child-end function...(.*)", - "(.*)KokkosP: sample 51 finished with child-end function.(.*)", - "(.*)KokkosP: sample 102 calling child-begin function...(.*)", - "(.*)KokkosP: sample 102 finished with child-begin function.(.*)", - "(.*)KokkosP: sample 102 calling child-end function...(.*)", - "(.*)KokkosP: sample 102 finished with child-end function.(.*)"}; + "KokkosP: sample 51 calling child-begin function...", + "KokkosP: sample 51 finished with child-begin function.", + "KokkosP: sample 51 calling child-end function...", + "KokkosP: sample 51 finished with child-end function.", + "KokkosP: sample 102 calling child-begin function...", + "KokkosP: sample 102 finished with child-begin function.", + "KokkosP: sample 102 calling child-end function...", + "KokkosP: sample 102 finished with child-end function."}; /** * @test This test checks that the tool effectively samples. @@ -67,7 +67,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { //! Analyze test output. for (const auto& matcher : matchers) { EXPECT_THAT(output.str(), HasSubstr(matcher)); - } // end TEST + } EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From f97a3b457c0b897e3b3012fc5d655193677f8268 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:59:02 -0700 Subject: [PATCH 072/107] Update test_parfor.cpp: putting in times --- tests/sampler/test_parfor.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index ad3a81f90..f1a187e37 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -8,6 +8,8 @@ using ::testing::HasSubstr; using ::testing::Not; +using ::testing::Contains; +using ::testing::Times; struct Tester { template @@ -67,6 +69,12 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST + EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "calling child-begin function...")); + EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "finished with child-begin function.")); + + EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "calling child-end function...")); + EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "finished with child-end function.")); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 336e304331b558ac4f211523014c69af7a3af8ac Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:59:38 -0700 Subject: [PATCH 073/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index f1a187e37..8bdcac3a2 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -6,9 +6,9 @@ #include "Kokkos_Core.hpp" +using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; -using ::testing::Contains; using ::testing::Times; struct Tester { @@ -69,11 +69,19 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } // end TEST - EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "calling child-begin function...")); - EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "finished with child-begin function.")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "calling child-begin function...")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "finished with child-begin function.")); - EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "calling child-end function...")); - EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "finished with child-end function.")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "calling child-end function...")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "finished with child-end function.")); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 69c694afd341d33ab68cb106d88f362c67c70fcf Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:01:04 -0700 Subject: [PATCH 074/107] Update test_parreduce.cpp: put in times --- tests/sampler/test_parreduce.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 0d4419896..cdc0d146e 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -8,6 +8,9 @@ using ::testing::HasSubstr; using ::testing::Not; +using ::testing::Contains; +using ::testing::Times; + struct Tester { template explicit Tester(const execution_space& space) { @@ -69,6 +72,20 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "calling child-begin function...")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "finished with child-begin function.")); + + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "calling child-end function...")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "finished with child-end function.")); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 26573e520bc95909ca6d548e683e1a9cd6bf0fc6 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:03:16 -0700 Subject: [PATCH 075/107] test_parscan.cpp: put in times test --- tests/sampler/test_parscan.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 1913eb78a..3b1f69452 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -8,6 +8,9 @@ using ::testing::HasSubstr; using ::testing::Not; +using ::testing::Contains; +using ::testing::Times; + struct Tester { template explicit Tester(const execution_space& space) { @@ -69,6 +72,20 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "calling child-begin function...")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "finished with child-begin function.")); + + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "calling child-end function...")); + EXPECT_THAT(output.str(), + ::testing::Contains.Times(static_cast(2), + "finished with child-end function.")); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From c72fbb0ad3658a7e892165ab5ec7c93b9fbfffc6 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:04:25 -0700 Subject: [PATCH 076/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 3b1f69452..4e6e91a65 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -6,9 +6,9 @@ #include "Kokkos_Core.hpp" +using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; -using ::testing::Contains; using ::testing::Times; struct Tester { @@ -72,7 +72,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } - EXPECT_THAT(output.str(), + EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "calling child-begin function...")); EXPECT_THAT(output.str(), From 404f061015b309b74c8f2e7536e3e31b1cacad52 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:04:46 -0700 Subject: [PATCH 077/107] test_parreduce.cpp: apply clang format --- tests/sampler/test_parreduce.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index cdc0d146e..cedc294a2 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -6,9 +6,9 @@ #include "Kokkos_Core.hpp" +using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; -using ::testing::Contains; using ::testing::Times; struct Tester { @@ -72,7 +72,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } - EXPECT_THAT(output.str(), + EXPECT_THAT(output.str(), ::testing::Contains.Times(static_cast(2), "calling child-begin function...")); EXPECT_THAT(output.str(), From 5e5ecfe65a562ed5bfae99a8fe8ad4af851a290c Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:13:38 -0700 Subject: [PATCH 078/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 4e6e91a65..3480fe042 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -19,7 +19,7 @@ struct Tester { //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. - int N = 1024; + long int N = 1024; int64_t result; for (int iter = 0; iter < 150; iter++) { From b436b4be7d67812531229b3fbae12487cac31c3e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:33:17 -0700 Subject: [PATCH 079/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 3480fe042..e8b057071 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -6,10 +6,8 @@ #include "Kokkos_Core.hpp" -using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; -using ::testing::Times; struct Tester { template @@ -72,20 +70,6 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "calling child-begin function...")); - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "finished with child-begin function.")); - - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "calling child-end function...")); - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "finished with child-end function.")); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 5f60e7e7c1ad623d331b259dfa285736f508b038 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:35:42 -0700 Subject: [PATCH 080/107] test_parreduce.cpp: apply clang format --- tests/sampler/test_parreduce.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index cedc294a2..816451dde 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -6,10 +6,8 @@ #include "Kokkos_Core.hpp" -using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; -using ::testing::Times; struct Tester { template @@ -72,20 +70,6 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "calling child-begin function...")); - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "finished with child-begin function.")); - - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "calling child-end function...")); - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "finished with child-end function.")); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From c2871488542e8832a62eed9a8912194a820e62c9 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:35:54 -0700 Subject: [PATCH 081/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 8bdcac3a2..73a4a01d7 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -9,7 +9,6 @@ using ::testing::Contains; using ::testing::HasSubstr; using ::testing::Not; -using ::testing::Times; struct Tester { template @@ -67,21 +66,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { //! Analyze test output. for (const auto& matcher : matchers) { EXPECT_THAT(output.str(), HasSubstr(matcher)); - } // end TEST - - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "calling child-begin function...")); - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "finished with child-begin function.")); - - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "calling child-end function...")); - EXPECT_THAT(output.str(), - ::testing::Contains.Times(static_cast(2), - "finished with child-end function.")); + } EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From f3e54eb991cd09aec69ede6a788b566892e59812 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 19:36:30 -0700 Subject: [PATCH 082/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 73a4a01d7..54ed58515 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -68,6 +68,10 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 75 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 149 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From ac11f49f8ea585736d6993c0d2443f9c9965e9e3 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 19:38:36 -0700 Subject: [PATCH 083/107] test_parreduce.cpp: apply clang format --- tests/sampler/test_parreduce.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 816451dde..1308cde8b 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -70,6 +70,10 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 75 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 149 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 2c5fd43dfb92d7370f3dfa97d276f10f7e0e430a Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 5 Apr 2024 19:39:35 -0700 Subject: [PATCH 084/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index e8b057071..0580898e6 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -70,6 +70,10 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), HasSubstr(matcher)); } + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 75 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 149 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 262a6bbfe799c16bc21001a1e9446d8c3c0829cc Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 08:40:17 -0400 Subject: [PATCH 085/107] kp_sampler_skip.cpp: std::cout to std::cerr Co-authored-by: Daniel Arndt --- common/kokkos-sampler/kp_sampler_skip.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 78cbbff4b..0c34a5220 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -56,8 +56,9 @@ void invoke_ktools_fence(uint32_t devID) { << getDeviceID(devID) << ".\n"; } } else { - std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's " + std::cerr << "KokkosP: FATAL: Kokkos Tools Programming Interface's " "tool-invoked Fence is NULL!\n"; + std::abort(); exit(-1); } } From fd36878f21c9487cd4ce6ff6a3796f811c861a35 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 08:41:27 -0400 Subject: [PATCH 086/107] test_parscan.cpp: fix declaration for variable result Co-authored-by: Damien L-G --- tests/sampler/test_parscan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 0580898e6..082389a41 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -18,7 +18,7 @@ struct Tester { //! expression to check this. long int N = 1024; - int64_t result; + long int result; for (int iter = 0; iter < 150; iter++) { result = 0; From d146c28d2f8fadf694215f1efee316e2131e2b54 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:33:57 -0700 Subject: [PATCH 087/107] test_parfor.cpp: revisions of tests PR review --- tests/sampler/test_parfor.cpp | 45 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 54ed58515..6535d147c 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -13,12 +13,12 @@ using ::testing::Not; struct Tester { template explicit Tester(const execution_space& space) { - //! Explicitly launch a kernel with a name, and run it 150 times with kernel - //! logger. Use a periodic sampling with skip rate 51. This should print + //! Explicitly launch a kernel with a name, and run it 15 times with kernel + //! logger. Use a periodic sampling with skip rate 5. This should print //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. - for (int iter = 0; iter < 150; iter++) { + for (int iter = 0; iter < 15; iter++) { Kokkos::parallel_for("named kernel", Kokkos::RangePolicy(space, 0, 1), *this); @@ -29,14 +29,14 @@ struct Tester { }; static const std::vector matchers{ - "KokkosP: sample 51 calling child-begin function...", - "KokkosP: sample 51 finished with child-begin function.", - "KokkosP: sample 51 calling child-end function...", - "KokkosP: sample 51 finished with child-end function.", - "KokkosP: sample 102 calling child-begin function...", - "KokkosP: sample 102 finished with child-begin function.", - "KokkosP: sample 102 calling child-end function...", - "KokkosP: sample 102 finished with child-end function."}; + "KokkosP: sample 6 calling child-begin function...", + "KokkosP: sample 6 finished with child-begin function.", + "KokkosP: sample 6 calling child-end function...", + "KokkosP: sample 6 finished with child-end function.", + "KokkosP: sample 11 calling child-begin function...", + "KokkosP: sample 11 finished with child-begin function.", + "KokkosP: sample 11 calling child-end function...", + "KokkosP: sample 11 finished with child-end function."}; /** * @test This test checks that the tool effectively samples. @@ -69,8 +69,27 @@ TEST(SamplerTest, ktoEnvVarDefault) { } EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 75 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 149 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 2 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 3 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 4 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 5 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 7 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 8 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 9 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 10 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 12 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 13 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); + + int occurrences = 0; + while (std::string::size_type pos = 0; + (pos = s.find("calling child-begin function", pos)) != + std::string::npos) { + ++occurrences; + pos += target.length(); + } + EXPECT_EQ(occurrences, 2); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From 22ba2e4e86ed06ca9d1f2d9f507a83de326efdd8 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:37:26 -0700 Subject: [PATCH 088/107] test_parreduce.cpp: fix with new tests --- tests/sampler/test_parreduce.cpp | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 1308cde8b..dd3a8480a 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -45,6 +45,21 @@ static const std::vector matchers{ */ +static const std::vector matchers{ + "KokkosP: sample 6 calling child-begin function...", + "KokkosP: sample 6 finished with child-begin function.", + "KokkosP: sample 6 calling child-end function...", + "KokkosP: sample 6 finished with child-end function.", + "KokkosP: sample 11 calling child-begin function...", + "KokkosP: sample 11 finished with child-begin function.", + "KokkosP: sample 11 calling child-end function...", + "KokkosP: sample 11 finished with child-end function."}; + +/** + * @test This test checks that the tool effectively samples. + * + + */ TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. Kokkos::initialize(); @@ -71,8 +86,27 @@ TEST(SamplerTest, ktoEnvVarDefault) { } EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 75 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 149 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 2 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 3 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 4 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 5 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 7 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 8 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 9 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 10 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 12 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 13 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); + + int occurrences = 0; + while (std::string::size_type pos = 0; + (pos = s.find("calling child-begin function", pos)) != + std::string::npos) { + ++occurrences; + pos += target.length(); + } + EXPECT_EQ(occurrences, 2); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From d8a492e553d348399c63a32d6a3b15fe4470ed04 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:38:36 -0700 Subject: [PATCH 089/107] test_parscan.cpp: fix sampler scan --- tests/sampler/test_parscan.cpp | 46 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 082389a41..5e7097be0 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -12,15 +12,15 @@ using ::testing::Not; struct Tester { template explicit Tester(const execution_space& space) { - //! Explicitly launch a kernel with a name, and run it 150 times with kernel - //! logger. Use a periodic sampling with skip rate 51. This should print + //! Explicitly launch a kernel with a name, and run it 15 times with kernel + //! logger. Use a periodic sampling with skip rate 5. This should print //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. long int N = 1024; long int result; - for (int iter = 0; iter < 150; iter++) { + for (int iter = 0; iter < 15; iter++) { result = 0; Kokkos::parallel_scan("named kernel scan", N, *this, result); } @@ -30,21 +30,20 @@ struct Tester { }; static const std::vector matchers{ - "KokkosP: sample 51 calling child-begin function...", - "KokkosP: sample 51 finished with child-begin function.", - "KokkosP: sample 51 calling child-end function...", - "KokkosP: sample 51 finished with child-end function.", - "KokkosP: sample 102 calling child-begin function...", - "KokkosP: sample 102 finished with child-begin function.", - "KokkosP: sample 102 calling child-end function...", - "KokkosP: sample 102 finished with child-end function."}; + "KokkosP: sample 6 calling child-begin function...", + "KokkosP: sample 6 finished with child-begin function.", + "KokkosP: sample 6 calling child-end function...", + "KokkosP: sample 6 finished with child-end function.", + "KokkosP: sample 11 calling child-begin function...", + "KokkosP: sample 11 finished with child-begin function.", + "KokkosP: sample 11 calling child-end function...", + "KokkosP: sample 11 finished with child-end function."}; /** * @test This test checks that the tool effectively samples. * */ - TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. Kokkos::initialize(); @@ -71,8 +70,27 @@ TEST(SamplerTest, ktoEnvVarDefault) { } EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 75 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 149 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 2 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 3 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 4 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 5 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 7 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 8 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 9 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 10 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 12 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 13 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); + + int occurrences = 0; + while (std::string::size_type pos = 0; + (pos = s.find("calling child-begin function", pos)) != + std::string::npos) { + ++occurrences; + pos += target.length(); + } + EXPECT_EQ(occurrences, 2); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " "sampler utility library to call"))); From fc0c10cef68cf44bbdec978d34fdc81960c937b7 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:40:20 -0700 Subject: [PATCH 090/107] test_parreduce.cpp: fix with correct samples and comments --- tests/sampler/test_parreduce.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index dd3a8480a..e9ae45b47 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -12,13 +12,13 @@ using ::testing::Not; struct Tester { template explicit Tester(const execution_space& space) { - //! Explicitly launch a kernel with a name, and run it 150 times with kernel - //! logger. Use a periodic sampling with skip rate 51. This should print + //! Explicitly launch a kernel with a name, and run it 15 times with kernel + //! logger. Use a periodic sampling with skip rate 5. This should print //! out 2 invocations, and there is a single matcher with a regular //! expression to check this. long int sum; - for (int iter = 0; iter < 150; iter++) { + for (int iter = 0; iter < 15; iter++) { sum = 0; Kokkos::parallel_reduce("named kernel reduce", Kokkos::RangePolicy(space, 0, 1), @@ -30,14 +30,14 @@ struct Tester { }; static const std::vector matchers{ - "KokkosP: sample 51 calling child-begin function...", - "KokkosP: sample 51 finished with child-begin function.", - "KokkosP: sample 51 calling child-end function...", - "KokkosP: sample 51 finished with child-end function.", - "KokkosP: sample 102 calling child-begin function...", - "KokkosP: sample 102 finished with child-begin function.", - "KokkosP: sample 102 calling child-end function...", - "KokkosP: sample 102 finished with child-end function."}; + "KokkosP: sample 6 calling child-begin function...", + "KokkosP: sample 6 finished with child-begin function.", + "KokkosP: sample 6 calling child-end function...", + "KokkosP: sample 6 finished with child-end function.", + "KokkosP: sample 11 calling child-begin function...", + "KokkosP: sample 11 finished with child-begin function.", + "KokkosP: sample 11 calling child-end function...", + "KokkosP: sample 11 finished with child-end function."}; /** * @test This test checks that the tool effectively samples. From 71adb27ab92ccb894e1e977938edbbb8a7f35cfd Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:42:10 -0700 Subject: [PATCH 091/107] CMakeLists.txt: fix sampler skip rate --- tests/sampler/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 376ae24c3..955f639fe 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -3,7 +3,7 @@ kp_add_executable_and_test( SOURCE_FILE test_parfor.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 - KOKKOS_TOOLS_SAMPLER_SKIP 50 + KOKKOS_TOOLS_SAMPLER_SKIP 5 KOKKOS_TOOLS_GLOBALFENCES 1 ) @@ -12,7 +12,7 @@ kp_add_executable_and_test( SOURCE_FILE test_parscan.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 - KOKKOS_TOOLS_SAMPLER_SKIP 50 + KOKKOS_TOOLS_SAMPLER_SKIP 5 KOKKOS_TOOLS_GLOBALFENCES 1 ) @@ -21,6 +21,6 @@ kp_add_executable_and_test( SOURCE_FILE test_parreduce.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 - KOKKOS_TOOLS_SAMPLER_SKIP 50 + KOKKOS_TOOLS_SAMPLER_SKIP 5 KOKKOS_TOOLS_GLOBALFENCES 1 ) From aab0435a597cf7f390328860595cd006f47b3a83 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:47:57 -0700 Subject: [PATCH 092/107] test_parfor.cpp: add string header --- tests/sampler/test_parfor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 6535d147c..e46c25aba 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include From 3a230286a28e8d1ea9b08a3becb1e49a675b378d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:48:20 -0700 Subject: [PATCH 093/107] test_parreduce.cpp: add string header --- tests/sampler/test_parreduce.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index e9ae45b47..2d561df54 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -1,3 +1,4 @@ +#include #include #include #include From 877d863b13d560ee2828d355e5d53f023c9ed03d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:48:43 -0700 Subject: [PATCH 094/107] test_parscan.cpp: add string header --- tests/sampler/test_parscan.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 5e7097be0..8dffe97cb 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -1,3 +1,4 @@ +#include #include #include #include From 9fa94c500c26a64e3975542136ab3d3e62f8edfa Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:28:01 -0700 Subject: [PATCH 095/107] Update test_parfor.cpp: fix output --- tests/sampler/test_parfor.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index e46c25aba..65de39d16 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -42,8 +42,8 @@ static const std::vector matchers{ /** * @test This test checks that the tool effectively samples. * - */ + TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. Kokkos::initialize(); @@ -84,9 +84,10 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); int occurrences = 0; - while (std::string::size_type pos = 0; - (pos = s.find("calling child-begin function", pos)) != - std::string::npos) { + std::string::size_type pos = 0; + std::string samplerTestOutput(output.str()); + std::string target("calling child-begin function"); + while ((pos = samplerTestOutput.find(target, pos)) != std::string::npos) { ++occurrences; pos += target.length(); } From 88040dc7a38f22911a4678e2ef1f5d5188a00722 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:36:21 -0700 Subject: [PATCH 096/107] test_parreduce.cpp: fix test --- tests/sampler/test_parreduce.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 2d561df54..521da114c 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -100,13 +100,16 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); + int occurrences = 0; - while (std::string::size_type pos = 0; - (pos = s.find("calling child-begin function", pos)) != - std::string::npos) { + std::string::size_type pos = 0; + std::string samplerTestOutput(output.str()); + std::string target("calling child-begin function"); + while ((pos = samplerTestOutput.find(target, pos)) != std::string::npos) { ++occurrences; pos += target.length(); } + EXPECT_EQ(occurrences, 2); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " From 030734b6c96076290567e4381dfa26af5405d867 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:37:14 -0700 Subject: [PATCH 097/107] test_parscan.cpp: fix occurrences variable --- tests/sampler/test_parscan.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 8dffe97cb..9ac7cee7d 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -85,12 +85,14 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); int occurrences = 0; - while (std::string::size_type pos = 0; - (pos = s.find("calling child-begin function", pos)) != - std::string::npos) { + std::string::size_type pos = 0; + std::string samplerTestOutput(output.str()); + std::string target("calling child-begin function"); + while ((pos = samplerTestOutput.find(target, pos)) != std::string::npos) { ++occurrences; pos += target.length(); } + EXPECT_EQ(occurrences, 2); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: FATAL: No child library of " From 5c563ffff690669aa0796df7d04ba7cf1139195c Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:41:04 -0700 Subject: [PATCH 098/107] test_parfor.cpp: apply clang format --- tests/sampler/test_parfor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 65de39d16..866f29261 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -83,7 +83,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); - int occurrences = 0; + int occurrences = 0; std::string::size_type pos = 0; std::string samplerTestOutput(output.str()); std::string target("calling child-begin function"); From 9d644d760eaf75f09324f1c0a177f71baf554fbc Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:41:42 -0700 Subject: [PATCH 099/107] test_parreduce.cpp: apply clang format --- tests/sampler/test_parreduce.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index 521da114c..f27ec7040 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -100,8 +100,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); - - int occurrences = 0; + int occurrences = 0; std::string::size_type pos = 0; std::string samplerTestOutput(output.str()); std::string target("calling child-begin function"); From d8f29f441ce83c5fd92a05058fbfdc8a66179f10 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:42:19 -0700 Subject: [PATCH 100/107] test_parscan.cpp: apply clang format --- tests/sampler/test_parscan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index 9ac7cee7d..ba60318b1 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -84,7 +84,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); - int occurrences = 0; + int occurrences = 0; std::string::size_type pos = 0; std::string samplerTestOutput(output.str()); std::string target("calling child-begin function"); From 1f4e9c2f56b3947f6d9f828aa3b0ab4af4b335cf Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:45:00 -0700 Subject: [PATCH 101/107] test_parreduce.cpp: apply clang format --- tests/sampler/test_parreduce.cpp | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index f27ec7040..ffecb4ea1 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -39,27 +39,9 @@ static const std::vector matchers{ "KokkosP: sample 11 finished with child-begin function.", "KokkosP: sample 11 calling child-end function...", "KokkosP: sample 11 finished with child-end function."}; - -/** - * @test This test checks that the tool effectively samples. - * - - */ - -static const std::vector matchers{ - "KokkosP: sample 6 calling child-begin function...", - "KokkosP: sample 6 finished with child-begin function.", - "KokkosP: sample 6 calling child-end function...", - "KokkosP: sample 6 finished with child-end function.", - "KokkosP: sample 11 calling child-begin function...", - "KokkosP: sample 11 finished with child-begin function.", - "KokkosP: sample 11 calling child-end function...", - "KokkosP: sample 11 finished with child-end function."}; - -/** - * @test This test checks that the tool effectively samples. +/* + * @test This test checks that the sampling utility properly samples. * - */ TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. From efa80cb30ed5144da9bc1adeb67d0651c80e46b0 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:36:50 -0700 Subject: [PATCH 102/107] test_parfor.cpp: fix sampler number from 11 to 12 --- tests/sampler/test_parfor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 866f29261..2616614f4 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -34,10 +34,10 @@ static const std::vector matchers{ "KokkosP: sample 6 finished with child-begin function.", "KokkosP: sample 6 calling child-end function...", "KokkosP: sample 6 finished with child-end function.", - "KokkosP: sample 11 calling child-begin function...", - "KokkosP: sample 11 finished with child-begin function.", - "KokkosP: sample 11 calling child-end function...", - "KokkosP: sample 11 finished with child-end function."}; + "KokkosP: sample 12 calling child-begin function...", + "KokkosP: sample 12 finished with child-begin function.", + "KokkosP: sample 12 calling child-end function...", + "KokkosP: sample 12 finished with child-end function."}; /** * @test This test checks that the tool effectively samples. @@ -78,7 +78,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 8 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 9 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 10 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 12 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 11 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 13 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); From 08be2d776b7bc6d0947baff674e75d0a172bdd4e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:37:31 -0700 Subject: [PATCH 103/107] test_parreduce.cpp: sample number from 11 to 12 --- tests/sampler/test_parreduce.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp index ffecb4ea1..2c5a9abb2 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -35,10 +35,10 @@ static const std::vector matchers{ "KokkosP: sample 6 finished with child-begin function.", "KokkosP: sample 6 calling child-end function...", "KokkosP: sample 6 finished with child-end function.", - "KokkosP: sample 11 calling child-begin function...", - "KokkosP: sample 11 finished with child-begin function.", - "KokkosP: sample 11 calling child-end function...", - "KokkosP: sample 11 finished with child-end function."}; + "KokkosP: sample 12 calling child-begin function...", + "KokkosP: sample 12 finished with child-begin function.", + "KokkosP: sample 12 calling child-end function...", + "KokkosP: sample 12 finished with child-end function."}; /* * @test This test checks that the sampling utility properly samples. * @@ -77,7 +77,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 8 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 9 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 10 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 12 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 11 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 13 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); From 13d78dbfc2da73621e6cee097b76a5afa3a98619 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:40:50 -0700 Subject: [PATCH 104/107] test_parscan.cpp: change sample from 11 to 12 --- tests/sampler/test_parscan.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp index ba60318b1..03fa8ac17 100644 --- a/tests/sampler/test_parscan.cpp +++ b/tests/sampler/test_parscan.cpp @@ -35,10 +35,10 @@ static const std::vector matchers{ "KokkosP: sample 6 finished with child-begin function.", "KokkosP: sample 6 calling child-end function...", "KokkosP: sample 6 finished with child-end function.", - "KokkosP: sample 11 calling child-begin function...", - "KokkosP: sample 11 finished with child-begin function.", - "KokkosP: sample 11 calling child-end function...", - "KokkosP: sample 11 finished with child-end function."}; + "KokkosP: sample 12 calling child-begin function...", + "KokkosP: sample 12 finished with child-begin function.", + "KokkosP: sample 12 calling child-end function...", + "KokkosP: sample 12 finished with child-end function."}; /** * @test This test checks that the tool effectively samples. @@ -79,7 +79,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 8 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 9 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 10 calling"))); - EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 12 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 11 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 13 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 14 calling"))); EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); From 603ecc46bc5b93acee4365b3eaa2d26d1ac66583 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:06:38 -0700 Subject: [PATCH 105/107] kp_sampler_skip.cpp: revert cerr to cout --- common/kokkos-sampler/kp_sampler_skip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 0c34a5220..8df516e9e 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -56,7 +56,7 @@ void invoke_ktools_fence(uint32_t devID) { << getDeviceID(devID) << ".\n"; } } else { - std::cerr << "KokkosP: FATAL: Kokkos Tools Programming Interface's " + std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's " "tool-invoked Fence is NULL!\n"; std::abort(); exit(-1); From 8aaaae9ba4b5bab86772c3c031fbeb1c0e2d6e5c Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:17:26 -0700 Subject: [PATCH 106/107] CMakeLists.txt: make global fences 0 --- tests/sampler/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 955f639fe..54af252f2 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -4,7 +4,7 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 5 - KOKKOS_TOOLS_GLOBALFENCES 1 + KOKKOS_TOOLS_GLOBALFENCES 0 ) kp_add_executable_and_test( @@ -13,7 +13,7 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 5 - KOKKOS_TOOLS_GLOBALFENCES 1 + KOKKOS_TOOLS_GLOBALFENCES 0 ) kp_add_executable_and_test( @@ -22,5 +22,5 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 5 - KOKKOS_TOOLS_GLOBALFENCES 1 + KOKKOS_TOOLS_GLOBALFENCES 0 ) From 790752f283a2e75d3d4d02ff93d69ceeeb58f44b Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 11 Apr 2024 10:24:30 -0700 Subject: [PATCH 107/107] CMakeLists.txt: remove setting of global fence environment variable --- tests/sampler/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 54af252f2..a3e81add2 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -4,7 +4,6 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 5 - KOKKOS_TOOLS_GLOBALFENCES 0 ) kp_add_executable_and_test( @@ -13,7 +12,6 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 5 - KOKKOS_TOOLS_GLOBALFENCES 0 ) kp_add_executable_and_test( @@ -22,5 +20,4 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 5 - KOKKOS_TOOLS_GLOBALFENCES 0 )