From 6bfca816cca2fbf3f47be526bb5e4c332ed8e01a Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 12 Oct 2023 18:20:47 -0700 Subject: [PATCH 01/87] kp_sampler_skip: putting in probabilistic sampling --- common/kokkos-sampler/kp_sampler_skip.cpp | 151 ++++++++++++++++------ 1 file changed, 115 insertions(+), 36 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index d56ed84ca..2e8c59d0f 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -6,11 +6,14 @@ #include #include "../../profiling/all/kp_core.hpp" #include "kp_config.hpp" +#include +#include namespace KokkosTools { namespace Sampler { static uint64_t uniqID = 0; -static uint64_t kernelSampleSkip = 101; +static uint64_t kernelSampleSkip = std::numeric_limits::max(); +static double tool_prob_num = 0.1; static int tool_verbosity = 0; static int tool_globFence = 0; @@ -33,7 +36,7 @@ static endFunction endReduceCallee = NULL; void kokkosp_request_tool_settings(const uint32_t, Kokkos_Tools_ToolSettings* settings) { - settings->requires_global_fencing = false; + settings->requires_global_fencing = 0; } // set of functions from Kokkos ToolProgrammingInterface (includes fence) @@ -182,6 +185,79 @@ 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); } + const char* tool_probability = getenv("KOKKOS_TOOLS_SAMPLER_PROB"); + + if (NULL != tool_probability) { + // read sampling probability as an float between 0 and 100, representing + // a percentage that data should be gathered. + // Connector reasons about probability as a double between 0.0 and 1.0. + tool_prob_num = atof(tool_probability); + if (tool_prob_num > 100.0) { + printf( + "KokkosP: The sampling probability value is set to be greater than " + "100.0. " + "Setting sampling probability to 100 percent; all of the " + "invocations of a Kokkos Kernel will be profiled.\n"); + tool_prob_num = 100.0; + } else if (tool_prob_num < 0.0) { + printf( + "KokkosP: The sampling probability value is set to be negative " + "number. Setting " + "sampling probability to 0 percent; none of the invocations of " + "a Kokkos Kernel will be profiled.\n"); + tool_prob_num = 0.0; + } + } + if ((tool_prob_num < 0.0) && + (kernelSampleSkip == std::numeric_limits::max())) { + if (tool_verbosity > 0) { + printf( + "KokkosP: Neither sampling utility's probability for sampling " + "nor sampling utility's skip rate were set. \n"); + } + tool_prob_num = 10.0; + if (tool_verbosity > 0) { + printf( + "KokkosP: Set the sampling utility's probability " + "for sampling to be %f percent. Sampler's skip rate " + "will not be used.\n", + tool_prob_num); + } + } + + if (tool_verbosity > 0) { + if (tool_verbosity > 1) { + printf("KokkosP: Sampling rate provided as input: %s\n", tool_sample); + printf("KokkosP: Sampling probability provided as input: %s\n", + tool_probability); + } + printf("KokkosP: Sampling rate set to: %llu\n", + (unsigned long long)(kernelSampleSkip)); + printf("KokkosP: Sampling probability set to %f\n", tool_prob_num); + printf( + "KokkosP: seeding Random Number Generator using clock for " + "probabilistic sampling.\n"); + } + srand(time(NULL)); + + if ((NULL != tool_probability) && (NULL != tool_sample)) { + printf( + "KokkosP: Note that both probability and skip rate are set. The Kokkos " + "Tools Sampler utility will invoke a Kokkos Tool child event you " + "specified " + "(e.g., the profiler or debugger tool connector you specified " + "in KOKKOS_TOOLS_LIBS) with only specified sampling probability " + "applied " + "and sampling skip rate set is ignored with no " + "predefined periodicity for sampling used.\n"); + + if (tool_verbosity > 0) { + printf( + "KokkosP: The skip rate in the sampler utility " + "is being set to 1.\n"); + } + kernelSampleSkip = 1; + } } void kokkosp_finalize_library() { @@ -194,17 +270,19 @@ 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_globFence) { - invoke_ktools_fence(0); - } - if (NULL != beginForCallee) { - uint64_t nestedkID = 0; - (*beginForCallee)(name, devID, &nestedkID); - infokIDSample.insert({*kID, nestedkID}); + if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.0)) { + if (tool_verbosity > 0) { + printf("KokkosP: sample %llu calling child-begin function...\n", + (unsigned long long)(*kID)); + } + if (tool_globFence) { + invoke_ktools_fence(0); + } + if (NULL != beginForCallee) { + uint64_t nestedkID = 0; + (*beginForCallee)(name, devID, &nestedkID); + infokIDSample.insert({*kID, nestedkID}); + } } } } @@ -221,7 +299,6 @@ void kokkosp_end_parallel_for(const uint64_t kID) { invoke_ktools_fence(0); } (*endForCallee)(retrievedNestedkID); - infokIDSample.erase(kID); } } } @@ -232,17 +309,19 @@ void kokkosp_begin_parallel_scan(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 (NULL != beginScanCallee) { - uint64_t nestedkID = 0; - if (tool_globFence) { - invoke_ktools_fence(0); + if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.0)) { + if (tool_verbosity > 0) { + printf("KokkosP: sample %llu calling child-begin function...\n", + (unsigned long long)(*kID)); + } + if (NULL != beginScanCallee) { + uint64_t nestedkID = 0; + if (tool_globFence) { + invoke_ktools_fence(0); + } + (*beginScanCallee)(name, devID, &nestedkID); + infokIDSample.insert({*kID, nestedkID}); } - (*beginScanCallee)(name, devID, &nestedkID); - infokIDSample.insert({*kID, nestedkID}); } } } @@ -259,7 +338,6 @@ void kokkosp_end_parallel_scan(const uint64_t kID) { invoke_ktools_fence(0); } (*endScanCallee)(retrievedNestedkID); - infokIDSample.erase(kID); } } } @@ -270,17 +348,19 @@ void kokkosp_begin_parallel_reduce(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 (NULL != beginReduceCallee) { - uint64_t nestedkID = 0; - if (tool_globFence) { - invoke_ktools_fence(0); + if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.0)) { + if (tool_verbosity > 0) { + printf("KokkosP: sample %llu calling child-begin function...\n", + (unsigned long long)(*kID)); + } + if (NULL != beginReduceCallee) { + uint64_t nestedkID = 0; + if (tool_globFence) { + invoke_ktools_fence(0); + } + (*beginReduceCallee)(name, devID, &nestedkID); + infokIDSample.insert({*kID, nestedkID}); } - (*beginReduceCallee)(name, devID, &nestedkID); - infokIDSample.insert({*kID, nestedkID}); } } } @@ -297,7 +377,6 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { invoke_ktools_fence(0); } (*endScanCallee)(retrievedNestedkID); - infokIDSample.erase(kID); } } } From fab829ae5c7dc4e459b9a7fecdcffd0510691bb0 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 12 Oct 2023 18:23:16 -0700 Subject: [PATCH 02/87] CMakeLists.txt in kokkos-sampler: fix add_library to 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 eeccd10d8fe5c6c6645cb6f6cdee4a34e8d81c56 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 12 Oct 2023 19:09:06 -0700 Subject: [PATCH 03/87] sampler's README.md: reflects sampler probability env var --- common/kokkos-sampler/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/kokkos-sampler/README.md b/common/kokkos-sampler/README.md index 3d0c6393a..779951884 100644 --- a/common/kokkos-sampler/README.md +++ b/common/kokkos-sampler/README.md @@ -1,4 +1,10 @@ -This is a sampler utility that is intended to complement other tools in the Kokkos Tools set. This utility allows for sampling (rather than collecting) of profiling or debugging data gathered from a particular tool of the Kokkos Tools set. The Kokkos Tools user provides a sampling rate via the environment variable KOKKOS_TOOLS_SAMPLER_SKIP. +This is a sampler utility that is intended to complement other tools in the Kokkos Tools set. This utility allows for sampling of profiling or debugging data collected from a particular tool of the Kokkos Tools set at each Kokkos kernel invocation. + +To use this utility, a Kokkos Tools user provides a sampling probability by setting the environment variable `KOKKOS_TOOLS_SAMPLER_PROB` to a positive real number between 0.0 and 100.0. +The user can alternatively set a sampling skip rate, i.e., the number of Kokkos kernel invocations to skip before the next sample is taken. +The user does so by setting the environment variable `KOKKOS_TOOLS_SAMPLER_SKIP` to a non-negative integer. + +If both sampling probability and sampling skip rate is set by the user, this sampling utility only uses the sampling probability for sampling, with the utility setting the sampling skip rate to 1. In order for the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool. This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. From d0a24ba7ec1997e7ae5a75d452e146e0682173d5 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 12 Oct 2023 19:30:05 -0700 Subject: [PATCH 04/87] kp_sampler_skip.cpp: tool_prob_num default to -1.0 not 0.1 --- 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 2e8c59d0f..c5a595fa9 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -13,7 +13,7 @@ namespace KokkosTools { namespace Sampler { static uint64_t uniqID = 0; static uint64_t kernelSampleSkip = std::numeric_limits::max(); -static double tool_prob_num = 0.1; +static double tool_prob_num = -1.0; static int tool_verbosity = 0; static int tool_globFence = 0; From 9df67482e01602691f1bae36e8a140ae1134c697 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:50:09 -0400 Subject: [PATCH 05/87] Update kp_sampler_skip.cpp: put erase back Erase got deleted (there on the develop branch) Took it out due to copy-paste --- common/kokkos-sampler/kp_sampler_skip.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index c5a595fa9..ec8cea41b 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -299,6 +299,7 @@ void kokkosp_end_parallel_for(const uint64_t kID) { invoke_ktools_fence(0); } (*endForCallee)(retrievedNestedkID); + infokIDSample.erase(kID); } } } @@ -338,6 +339,7 @@ void kokkosp_end_parallel_scan(const uint64_t kID) { invoke_ktools_fence(0); } (*endScanCallee)(retrievedNestedkID); + infokIDSample.erase(kID); } } } @@ -377,6 +379,7 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { invoke_ktools_fence(0); } (*endScanCallee)(retrievedNestedkID); + infokIDSample.erase(kID); } } } From b629300effd72137c77a9a13c9f9a8b4cce8f595 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:26:59 -0400 Subject: [PATCH 06/87] Update kp_sampler_skip.cpp: putting in seed User can input seed for RNG for probabilistic sampling --- common/kokkos-sampler/kp_sampler_skip.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index ec8cea41b..92d3900f7 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -16,6 +16,7 @@ static uint64_t kernelSampleSkip = std::numeric_limits::max(); static double tool_prob_num = -1.0; static int tool_verbosity = 0; static int tool_globFence = 0; +static unsigned int tool_seed = 1; // a hash table mapping kID to nestedkID static std::unordered_map infokIDSample; @@ -81,6 +82,8 @@ 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"); + const char* tool_seed_str = getenv("KOKKOS_TOOLS_SEED"); + if (NULL != tool_verbose_str) { tool_verbosity = atoi(tool_verbose_str); } else { @@ -91,6 +94,11 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } else { tool_globFence = 0; } + if (NULL != tool_seed_str) { + tool_seed = atoi(tool_seed_str); + } else { + tool_seed = 1; + } char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); if (NULL == profileLibrary) { @@ -234,11 +242,24 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, printf("KokkosP: Sampling rate set to: %llu\n", (unsigned long long)(kernelSampleSkip)); printf("KokkosP: Sampling probability set to %f\n", tool_prob_num); + } + + if(0 > tool_seed) { + srand(time(NULL)); + if(tool_verbosity > 0) { printf( "KokkosP: seeding Random Number Generator using clock for " "probabilistic sampling.\n"); + } } - srand(time(NULL)); + else { + srand(tool_seed); + if(tool_verbosity > 0) { + printf( + "KokkosP: seeding Random Number Generator using seed %u for " + "probabilistic sampling.\n", tool_seed); + } + } if ((NULL != tool_probability) && (NULL != tool_sample)) { printf( From df84895e464a264abc62f36bcc5b002e62c2de5f Mon Sep 17 00:00:00 2001 From: Vivek Kale Date: Mon, 23 Oct 2023 18:54:09 -0400 Subject: [PATCH 07/87] kp_sampler: set default seed to -1, tool fence verbosity --- common/kokkos-sampler/kp_sampler_skip.cpp | 37 +++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 92d3900f7..9661769ef 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -16,7 +16,7 @@ static uint64_t kernelSampleSkip = std::numeric_limits::max(); static double tool_prob_num = -1.0; static int tool_verbosity = 0; static int tool_globFence = 0; -static unsigned int tool_seed = 1; +static int tool_seed = -1; // a hash table mapping kID to nestedkID static std::unordered_map infokIDSample; @@ -51,11 +51,23 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { + if (tool_verbosity > 1) { + printf( + "KokkosP: Sampler utility finding" + " tool-induced fence function and invoking it.\n"); + } + if (tpi_funcs.fence != nullptr) { + if (tool_verbosity > 1) { + printf( + "KokkosP: Sampler utility found fence function. Attempting to invoke" + " tool-induced fence on device %d.\n", + getDeviceID(devID)); + } tpi_funcs.fence(devID); if (tool_verbosity > 1) { printf( - "KokkosP: Sampler utility sucessfully invoked " + "KokkosP: Sampler utility sucessfully invoked" " tool-induced fence on device %d\n", getDeviceID(devID)); } @@ -256,7 +268,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, srand(tool_seed); if(tool_verbosity > 0) { printf( - "KokkosP: seeding Random Number Generator using seed %u for " + "KokkosP: Seeding random number generator using seed %u for " "probabilistic sampling.\n", tool_seed); } } @@ -296,12 +308,16 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, printf("KokkosP: sample %llu calling child-begin function...\n", (unsigned long long)(*kID)); } - if (tool_globFence) { - invoke_ktools_fence(0); - } if (NULL != beginForCallee) { + if (tool_globFence) { + invoke_ktools_fence(0); + } uint64_t nestedkID = 0; (*beginForCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + printf("KokkosP: sample %llu finished with child-begin function.\n", + (unsigned long long)(*kID)); + } infokIDSample.insert({*kID, nestedkID}); } } @@ -342,6 +358,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) { + printf("KokkosP: sample %llu finished with child-begin function.\n", + (unsigned long long)(*kID)); + } infokIDSample.insert({*kID, nestedkID}); } } @@ -382,6 +402,10 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, invoke_ktools_fence(0); } (*beginReduceCallee)(name, devID, &nestedkID); + if (tool_verbosity > 0) { + printf("KokkosP: sample %llu finished with child-begin function.\n", + (unsigned long long)(*kID)); + } infokIDSample.insert({*kID, nestedkID}); } } @@ -399,6 +423,7 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { if (tool_globFence) { invoke_ktools_fence(0); } + (*endScanCallee)(retrievedNestedkID); infokIDSample.erase(kID); } From 624a14deae28d1357e527412b1cd04b56984e099 Mon Sep 17 00:00:00 2001 From: Vivek Kale Date: Mon, 23 Oct 2023 19:23:31 -0400 Subject: [PATCH 08/87] kp_sampler_skip.cpp: applied 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 9661769ef..1b940cbfd 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -52,13 +52,13 @@ uint32_t getDeviceID(uint32_t devid_in) { void invoke_ktools_fence(uint32_t devID) { if (tool_verbosity > 1) { - printf( - "KokkosP: Sampler utility finding" - " tool-induced fence function and invoking it.\n"); - } + printf( + "KokkosP: Sampler utility finding" + " tool-induced fence function and invoking it.\n"); + } if (tpi_funcs.fence != nullptr) { - if (tool_verbosity > 1) { + if (tool_verbosity > 1) { printf( "KokkosP: Sampler utility found fence function. Attempting to invoke" " tool-induced fence on device %d.\n", @@ -94,7 +94,7 @@ 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"); - const char* tool_seed_str = getenv("KOKKOS_TOOLS_SEED"); + const char* tool_seed_str = getenv("KOKKOS_TOOLS_SEED"); if (NULL != tool_verbose_str) { tool_verbosity = atoi(tool_verbose_str); @@ -255,23 +255,23 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, (unsigned long long)(kernelSampleSkip)); printf("KokkosP: Sampling probability set to %f\n", tool_prob_num); } - - if(0 > tool_seed) { + + if (0 > tool_seed) { srand(time(NULL)); - if(tool_verbosity > 0) { - printf( - "KokkosP: seeding Random Number Generator using clock for " - "probabilistic sampling.\n"); + if (tool_verbosity > 0) { + printf( + "KokkosP: seeding Random Number Generator using clock for " + "probabilistic sampling.\n"); } - } - else { + } else { srand(tool_seed); - if(tool_verbosity > 0) { - printf( - "KokkosP: Seeding random number generator using seed %u for " - "probabilistic sampling.\n", tool_seed); + if (tool_verbosity > 0) { + printf( + "KokkosP: Seeding random number generator using seed %u for " + "probabilistic sampling.\n", + tool_seed); } - } + } if ((NULL != tool_probability) && (NULL != tool_sample)) { printf( @@ -309,14 +309,14 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, (unsigned long long)(*kID)); } if (NULL != beginForCallee) { - if (tool_globFence) { - invoke_ktools_fence(0); - } + if (tool_globFence) { + invoke_ktools_fence(0); + } uint64_t nestedkID = 0; (*beginForCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { - printf("KokkosP: sample %llu finished with child-begin function.\n", - (unsigned long long)(*kID)); + printf("KokkosP: sample %llu finished with child-begin function.\n", + (unsigned long long)(*kID)); } infokIDSample.insert({*kID, nestedkID}); } @@ -359,8 +359,8 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, } (*beginScanCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { - printf("KokkosP: sample %llu finished with child-begin function.\n", - (unsigned long long)(*kID)); + printf("KokkosP: sample %llu finished with child-begin function.\n", + (unsigned long long)(*kID)); } infokIDSample.insert({*kID, nestedkID}); } @@ -404,7 +404,7 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, (*beginReduceCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { printf("KokkosP: sample %llu finished with child-begin function.\n", - (unsigned long long)(*kID)); + (unsigned long long)(*kID)); } infokIDSample.insert({*kID, nestedkID}); } From bd237ac68398cd64e6eb1e83771ceabc980fb2f0 Mon Sep 17 00:00:00 2001 From: Vivek Kale Date: Tue, 24 Oct 2023 19:50:26 -0400 Subject: [PATCH 09/87] Sampler: reduce text in prints; revise README --- common/kokkos-sampler/kp_sampler_skip.cpp | 69 +++++++++++------------ 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 1b940cbfd..afa20b735 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,23 +51,17 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { - if (tool_verbosity > 1) { - printf( - "KokkosP: Sampler utility finding" - " tool-induced fence function and invoking it.\n"); - } - if (tpi_funcs.fence != nullptr) { if (tool_verbosity > 1) { printf( - "KokkosP: Sampler utility found fence function. Attempting to invoke" + "KokkosP: Sampler attempting to invoke" " tool-induced fence on device %d.\n", getDeviceID(devID)); } tpi_funcs.fence(devID); if (tool_verbosity > 1) { printf( - "KokkosP: Sampler utility sucessfully invoked" + "KokkosP: Sampler sucessfully invoked" " tool-induced fence on device %d\n", getDeviceID(devID)); } @@ -208,7 +202,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const char* tool_probability = getenv("KOKKOS_TOOLS_SAMPLER_PROB"); if (NULL != tool_probability) { - // read sampling probability as an float between 0 and 100, representing + // read sampling probability as a float between 0 and 100, representing // a percentage that data should be gathered. // Connector reasons about probability as a double between 0.0 and 1.0. tool_prob_num = atof(tool_probability); @@ -216,15 +210,17 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, printf( "KokkosP: The sampling probability value is set to be greater than " "100.0. " - "Setting sampling probability to 100 percent; all of the " - "invocations of a Kokkos Kernel will be profiled.\n"); + "The probability for the sampler will be set to 100 percent; all of " + "the " + "invocations of a Kokkos kernel will be profiled.\n"); tool_prob_num = 100.0; } else if (tool_prob_num < 0.0) { printf( - "KokkosP: The sampling probability value is set to be negative " - "number. Setting " - "sampling probability to 0 percent; none of the invocations of " - "a Kokkos Kernel will be profiled.\n"); + "KokkosP: The sampling probability value is set to be a negative " + "number. The " + "sampler's probability will be set to 0 percent; none of the " + "invocations of " + "a Kokkos kernel will be profiled.\n"); tool_prob_num = 0.0; } } @@ -232,14 +228,15 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, (kernelSampleSkip == std::numeric_limits::max())) { if (tool_verbosity > 0) { printf( - "KokkosP: Neither sampling utility's probability for sampling " - "nor sampling utility's skip rate were set. \n"); + "KokkosP: Neither the probability " + "nor the skip rate for sampling were set...\n"); } tool_prob_num = 10.0; if (tool_verbosity > 0) { printf( - "KokkosP: Set the sampling utility's probability " - "for sampling to be %f percent. Sampler's skip rate " + "KokkosP: The probability " + "for the sampler is set to the default of %f percent. The skip rate " + "for sampler" "will not be used.\n", tool_prob_num); } @@ -247,47 +244,45 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, if (tool_verbosity > 0) { if (tool_verbosity > 1) { - printf("KokkosP: Sampling rate provided as input: %s\n", tool_sample); - printf("KokkosP: Sampling probability provided as input: %s\n", + printf("KokkosP: Sampling skip rate provided as input is: %s\n", + tool_sample); + printf("KokkosP: Sampling probability provided as input is: %s\n", tool_probability); } - printf("KokkosP: Sampling rate set to: %llu\n", + printf("KokkosP: Sampling skip rate is set to: %llu\n", (unsigned long long)(kernelSampleSkip)); - printf("KokkosP: Sampling probability set to %f\n", tool_prob_num); + printf("KokkosP: Sampling probability is set to %f\n", tool_prob_num); } if (0 > tool_seed) { srand(time(NULL)); if (tool_verbosity > 0) { printf( - "KokkosP: seeding Random Number Generator using clock for " - "probabilistic sampling.\n"); + "KokkosP: Seeding random number generator using clock for " + "random sampling.\n"); } } else { srand(tool_seed); if (tool_verbosity > 0) { printf( "KokkosP: Seeding random number generator using seed %u for " - "probabilistic sampling.\n", + "random sampling.\n", tool_seed); } } if ((NULL != tool_probability) && (NULL != tool_sample)) { printf( - "KokkosP: Note that both probability and skip rate are set. The Kokkos " - "Tools Sampler utility will invoke a Kokkos Tool child event you " - "specified " - "(e.g., the profiler or debugger tool connector you specified " - "in KOKKOS_TOOLS_LIBS) with only specified sampling probability " - "applied " - "and sampling skip rate set is ignored with no " - "predefined periodicity for sampling used.\n"); + "KokkosP: You set both the probability and skip rate for the sampler. " + "Only random sampling " + "will be done, using the probabability you set; " + "The skip rate you set will be ignored.\n"); - if (tool_verbosity > 0) { + if (tool_verbosity > 1) { printf( - "KokkosP: The skip rate in the sampler utility " - "is being set to 1.\n"); + "KokkosP: Note: The skip rate will be set to 1. Sampling will not be " + "based " + " on a pre-defined periodicity.\n"); } kernelSampleSkip = 1; } From 27ea88dc23723162ce9c70e76ad2d1bcf6ee335e Mon Sep 17 00:00:00 2001 From: Vivek Kale Date: Tue, 24 Oct 2023 19:52:53 -0400 Subject: [PATCH 10/87] fix readme indent --- common/kokkos-sampler/README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/common/kokkos-sampler/README.md b/common/kokkos-sampler/README.md index 779951884..2b21d7598 100644 --- a/common/kokkos-sampler/README.md +++ b/common/kokkos-sampler/README.md @@ -1,10 +1,7 @@ This is a sampler utility that is intended to complement other tools in the Kokkos Tools set. This utility allows for sampling of profiling or debugging data collected from a particular tool of the Kokkos Tools set at each Kokkos kernel invocation. -To use this utility, a Kokkos Tools user provides a sampling probability by setting the environment variable `KOKKOS_TOOLS_SAMPLER_PROB` to a positive real number between 0.0 and 100.0. -The user can alternatively set a sampling skip rate, i.e., the number of Kokkos kernel invocations to skip before the next sample is taken. -The user does so by setting the environment variable `KOKKOS_TOOLS_SAMPLER_SKIP` to a non-negative integer. +To use this utility, a Kokkos Tools user provides a sampling probability by setting the environment variable `KOKKOS_TOOLS_SAMPLER_PROB` to a positive real number between 0.0 and 100.0. The user can alternatively set a sampling skip rate, i.e., the number of Kokkos kernel invocations to skip before the next sample is taken. The user does so by setting the environment variable `KOKKOS_TOOLS_SAMPLER_SKIP` to a non-negative integer. -If both sampling probability and sampling skip rate is set by the user, this sampling utility only uses the sampling probability for sampling, with the utility setting the sampling skip rate to 1. +If both sampling probability and sampling skip rate are set by the user, this sampling utility only uses the sampling probability for sampling; the utility sets the sampling skip rate to 1, incorporating no pre-defined periodicity in sampling. If neither sampling probability nor the sampling skip rate are set by the user, then purely random sampling is againdone, with the sampler's probability being 10.0 percent. The sampler is periodic only if the sampling probability is not set by the user _and_ the sampling skip rate is set by the user. -In order for the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool. -This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. +For the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool.This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. From ad08a5ea9bbed05ba92cc3f04166d271028ef78d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:15:29 -0700 Subject: [PATCH 11/87] kp_sampler: fix name of seed environment varable and else condition for seed for user input + README --- common/kokkos-sampler/README.md | 2 ++ common/kokkos-sampler/kp_sampler_skip.cpp | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/kokkos-sampler/README.md b/common/kokkos-sampler/README.md index 2b21d7598..c8455ddeb 100644 --- a/common/kokkos-sampler/README.md +++ b/common/kokkos-sampler/README.md @@ -3,5 +3,7 @@ This is a sampler utility that is intended to complement other tools in the Kokk To use this utility, a Kokkos Tools user provides a sampling probability by setting the environment variable `KOKKOS_TOOLS_SAMPLER_PROB` to a positive real number between 0.0 and 100.0. The user can alternatively set a sampling skip rate, i.e., the number of Kokkos kernel invocations to skip before the next sample is taken. The user does so by setting the environment variable `KOKKOS_TOOLS_SAMPLER_SKIP` to a non-negative integer. If both sampling probability and sampling skip rate are set by the user, this sampling utility only uses the sampling probability for sampling; the utility sets the sampling skip rate to 1, incorporating no pre-defined periodicity in sampling. If neither sampling probability nor the sampling skip rate are set by the user, then purely random sampling is againdone, with the sampler's probability being 10.0 percent. The sampler is periodic only if the sampling probability is not set by the user _and_ the sampling skip rate is set by the user. +For the randomized sampling, the user can ensure reproducibility by setting `KOKKOS_TOOLS_RANDOM_SEED` to any integer. If this environment variable is not set, the seed is based on +the C time function. For the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool.This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index afa20b735..5956fac0b 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -88,7 +88,7 @@ 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"); - const char* tool_seed_str = getenv("KOKKOS_TOOLS_SEED"); + const char* tool_seed_str = getenv("KOKKOS_TOOLS_RANDOM_SEED"); if (NULL != tool_verbose_str) { tool_verbosity = atoi(tool_verbose_str); @@ -102,8 +102,6 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } if (NULL != tool_seed_str) { tool_seed = atoi(tool_seed_str); - } else { - tool_seed = 1; } char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); From 5c1a2729d097096a05eeafac3980cf51dc6ccdc7 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 23 Jan 2024 14:49:57 -0800 Subject: [PATCH 12/87] Update kp_sampler_skip.cpp: fix msg Kokkos_tools_libs --- 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 5956fac0b..0d19d7dab 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -107,7 +107,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); if (NULL == profileLibrary) { printf( - "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a depreciated " + "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a deprecated " "variable. Please use KOKKOS_TOOLS_LIBS\n"); profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); if (NULL == profileLibrary) { From a6dd9dc6928d533ca5bcb78224f000f1e1bbe3e8 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:03:17 -0800 Subject: [PATCH 13/87] intitialized pointer --- common/kokkos-sampler/kp_sampler_skip.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 0d19d7dab..280fb421c 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,8 +51,10 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { - if (tpi_funcs.fence != nullptr) { - if (tool_verbosity > 1) { + + (void)(*(tpi_funcs.fence)); + if (tpi_funcs.fence != nullptr ) { + if (tool_verbosity > 1) { printf( "KokkosP: Sampler attempting to invoke" " tool-induced fence on device %d.\n", @@ -69,7 +71,8 @@ void invoke_ktools_fence(uint32_t devID) { printf( "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked " "Fence is NULL!\n"); - exit(-1); + // exit(-1); + tpi_funcs.fence(devID); } } From 52e334982a9eb0a0e2a1f4b7e51d60894be1a05b Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:27:38 -0800 Subject: [PATCH 14/87] kp_sampler_skip.cpp: revert fix of initialize pointer --- common/kokkos-sampler/kp_sampler_skip.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 280fb421c..f0b1ca004 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,10 +51,8 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { - - (void)(*(tpi_funcs.fence)); - if (tpi_funcs.fence != nullptr ) { - if (tool_verbosity > 1) { + if (tpi_funcs.fence != nullptr) { + if (tool_verbosity > 1) { printf( "KokkosP: Sampler attempting to invoke" " tool-induced fence on device %d.\n", @@ -71,8 +69,6 @@ void invoke_ktools_fence(uint32_t devID) { printf( "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked " "Fence is NULL!\n"); - // exit(-1); - tpi_funcs.fence(devID); } } From dae1f2c6fea94d9ab4d895865b48959c10b7d2bc Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:37:30 -0800 Subject: [PATCH 15/87] Update kp_sampler_skip.cpp: fix func pointer - tools --- common/kokkos-sampler/kp_sampler_skip.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index f0b1ca004..e5e33eb15 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,21 +51,22 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { - if (tpi_funcs.fence != nullptr) { + if ((*tpi_funcs.fence) != nullptr)) { if (tool_verbosity > 1) { printf( "KokkosP: Sampler attempting to invoke" " tool-induced fence on device %d.\n", getDeviceID(devID)); } - tpi_funcs.fence(devID); + (*tpi_funcs.fence)(devID); if (tool_verbosity > 1) { printf( "KokkosP: Sampler sucessfully invoked" " tool-induced fence on device %d\n", getDeviceID(devID)); } - } else { + } + else { printf( "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked " "Fence is NULL!\n"); From 68c109313e8d2a87649faeef9eed04bcad4d0df6 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:35:33 -0500 Subject: [PATCH 16/87] kp_sampler_skip.cpp: provide_tpi parameter changed --- common/kokkos-sampler/kp_sampler_skip.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index e5e33eb15..d4aa4c073 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,14 +51,14 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { - if ((*tpi_funcs.fence) != nullptr)) { + if (tpi_funcs.fence != nullptr)) { if (tool_verbosity > 1) { printf( "KokkosP: Sampler attempting to invoke" " tool-induced fence on device %d.\n", getDeviceID(devID)); } - (*tpi_funcs.fence)(devID); + (*(tpi_funcs.fence))(devID); if (tool_verbosity > 1) { printf( "KokkosP: Sampler sucessfully invoked" @@ -74,14 +74,14 @@ void invoke_ktools_fence(uint32_t devID) { } void kokkosp_provide_tool_programming_interface( - uint32_t num_funcs, Kokkos_Tools_ToolProgrammingInterface* funcsFromTPI) { + 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"); } - tpi_funcs = *funcsFromTPI; + tpi_funcs = funcsFromTPI; } void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, From 8c56daf38372aa3db27da29212823cb76830a187 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:40:32 -0500 Subject: [PATCH 17/87] kp_core.hpp: provide_tpi takes struct --- profiling/all/kp_core.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiling/all/kp_core.hpp b/profiling/all/kp_core.hpp index c63db1863..77193e901 100644 --- a/profiling/all/kp_core.hpp +++ b/profiling/all/kp_core.hpp @@ -55,7 +55,7 @@ using Kokkos::Tools::SpaceHandle; #define EXPOSE_PROVIDE_TOOL_PROGRAMMING_INTERFACE(FUNC_NAME) \ __attribute__((weak)) void kokkosp_provide_tool_programming_interface( \ const uint32_t num_actions, \ - Kokkos_Tools_ToolProgrammingInterface* ptpi) { \ + Kokkos_Tools_ToolProgrammingInterface ptpi) { \ FUNC_NAME(num_actions, ptpi); \ } From a2b8577a29a77a5b43f56f74febd95bb33afd852 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:46:05 -0500 Subject: [PATCH 18/87] Update kp_sampler_skip.cpp: fix paren in invoke_ktools_fence --- 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 d4aa4c073..a5bbca591 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,7 +51,7 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { - if (tpi_funcs.fence != nullptr)) { + if (tpi_funcs.fence != nullptr) { if (tool_verbosity > 1) { printf( "KokkosP: Sampler attempting to invoke" From 43bd1a2b6923a06c4a38381176ae5c20ee4d3a10 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 15 Feb 2024 18:10:58 -0800 Subject: [PATCH 19/87] kp_sampler_skip.cpp: applied clang-format-8 --- common/kokkos-sampler/kp_sampler_skip.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index a5bbca591..6f53d0a65 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -51,7 +51,7 @@ uint32_t getDeviceID(uint32_t devid_in) { } void invoke_ktools_fence(uint32_t devID) { - if (tpi_funcs.fence != nullptr) { + if (tpi_funcs.fence != nullptr) { if (tool_verbosity > 1) { printf( "KokkosP: Sampler attempting to invoke" @@ -65,8 +65,7 @@ void invoke_ktools_fence(uint32_t devID) { " tool-induced fence on device %d\n", getDeviceID(devID)); } - } - else { + } else { printf( "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked " "Fence is NULL!\n"); From 8021f36880ad9f24fa37cfcc7d51ebe2cde111a4 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 15 Feb 2024 18:25:27 -0800 Subject: [PATCH 20/87] kp_core.hpp: applied clang-format-8 --- profiling/all/kp_core.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiling/all/kp_core.hpp b/profiling/all/kp_core.hpp index 77193e901..cc51bc3d9 100644 --- a/profiling/all/kp_core.hpp +++ b/profiling/all/kp_core.hpp @@ -55,7 +55,7 @@ using Kokkos::Tools::SpaceHandle; #define EXPOSE_PROVIDE_TOOL_PROGRAMMING_INTERFACE(FUNC_NAME) \ __attribute__((weak)) void kokkosp_provide_tool_programming_interface( \ const uint32_t num_actions, \ - Kokkos_Tools_ToolProgrammingInterface ptpi) { \ + Kokkos_Tools_ToolProgrammingInterface ptpi) { \ FUNC_NAME(num_actions, ptpi); \ } From 5b66f9060504f0f11bc6a30165ac473ebce47df3 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 29 Feb 2024 09:24:45 -0800 Subject: [PATCH 21/87] Create test_randomized_sampling.cpp --- tests/sampler/test_randomized_sampling.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/sampler/test_randomized_sampling.cpp diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/sampler/test_randomized_sampling.cpp @@ -0,0 +1 @@ + From d89291e79d1e351c1ae0cd8a53327060d439e637 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 29 Feb 2024 09:26:17 -0800 Subject: [PATCH 22/87] Create CMakeLists.txt --- tests/sampler/CMakeLists.txt | 5 +++++ 1 file changed, 5 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..b02a7511d --- /dev/null +++ b/tests/sampler/CMakeLists.txt @@ -0,0 +1,5 @@ +kp_add_executable_and_test( + TARGET_NAME test_sampler_randomizedsampling + SOURCE_FILE test_randomized_sampling.cpp + KOKKOS_TOOLS_LIBS kp_sampler +) From e1f7c223d8e5011e3273fcfe62e25bafdf959db6 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 29 Feb 2024 09:39:03 -0800 Subject: [PATCH 23/87] Update test_randomized_sampling.cpp --- tests/sampler/test_randomized_sampling.cpp | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 8b1378917..c55412ee2 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -1 +1,69 @@ +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Kokkos_Core.hpp" + +#define NUMITERS 1000 +struct Tester { + struct TagNamed {}; + struct TagUnnamed {}; + + template + explicit Tester(const execution_space& space) { + //! Explicitly launch a kernel with a name and no tag, and run it NUM_ITERS times + //! Use a random sampling of 1 percent and use a random seed of 2. + //! With NUMITERS 1000, this should print out 10 invocations. + //! In the test, we match the invocations output from all three runs against each other, and ensure that each shows 10 invocations. + + for (int trial = 0; trial < 3; trial++) + { + for (int iter = 0; iter < NUMITERS; iter++) { + Kokkos::parallel_for("named kernel", + Kokkos::RangePolicy(space, 0, 1), + *this); + } + } + + KOKKOS_FUNCTION void operator()(const int) const {} + + template + KOKKOS_FUNCTION void operator()(const TagType, const int) const {} +}; + +static const std::vector matchers{ + }; + +/** + * @test This test checks that the tool effectively samples randomly. + * + + */ +TEST(SamplerTest, randomized) { + //! 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 d020036af5b8486a66f22619f1d6d02bcce12179 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 29 Feb 2024 11:40:34 -0800 Subject: [PATCH 24/87] test_randomized_sampling.cpp: fix matcher text for 4 samples --- tests/sampler/test_randomized_sampling.cpp | 107 ++++++++++----------- 1 file changed, 49 insertions(+), 58 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index c55412ee2..d4352b742 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -6,64 +6,55 @@ #include "Kokkos_Core.hpp" -#define NUMITERS 1000 struct Tester { - struct TagNamed {}; - struct TagUnnamed {}; - template explicit Tester(const execution_space& space) { - //! Explicitly launch a kernel with a name and no tag, and run it NUM_ITERS times - //! Use a random sampling of 1 percent and use a random seed of 2. - //! With NUMITERS 1000, this should print out 10 invocations. - //! In the test, we match the invocations output from all three runs against each other, and ensure that each shows 10 invocations. - - for (int trial = 0; trial < 3; trial++) - { - for (int iter = 0; iter < NUMITERS; iter++) { - Kokkos::parallel_for("named kernel", - Kokkos::RangePolicy(space, 0, 1), - *this); - } - } - - KOKKOS_FUNCTION void operator()(const int) const {} - - template - KOKKOS_FUNCTION void operator()(const TagType, const int) const {} -}; - -static const std::vector matchers{ - }; - -/** - * @test This test checks that the tool effectively samples randomly. - * - - */ -TEST(SamplerTest, randomized) { - //! 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 - -} + //! Explicitly launch a kernel with a name, and run it 4 times with kernel + //! logger. Use a periodic sampling with skip rate 2. This should print out + //! 1 invocation In the test, we match the invocations output from the + //! second invocation and make sure the first + // and third are not printed out, and the second and fourth are sequenced + // correctly in the print. + + for (int iter = 0; iter < 4; iter++) { + Kokkos::parallel_for("named kernel", + Kokkos::RangePolicy(space, 0, 1), + *this); + } + + KOKKOS_FUNCTION void operator()(const int) const {} + }; + + static const std::vector matchers{ + "[0-9,a-z]+ KokkosP: sample 2 [0-9]+ KokkosP: sample 4 [0-9,a-z]+"}; + + /** + * @test This test checks that the tool effectively samples randomly. + * + + */ + TEST(SamplerTest, randomized) { + //! 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 d2b0a6950e1017db646b9441982bc4f8a1cf3e0d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:32:06 -0800 Subject: [PATCH 25/87] Update CMakeLists.txt: add sampler subdirectory --- tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 65ec02fe0..d9d20d2ba 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -59,3 +59,4 @@ target_sources( target_link_libraries(test_common PUBLIC GTest::gtest GTest::gmock Kokkos::kokkos) add_subdirectory(space-time-stack) +add_subdirectory(sampler) From cc9118d900b8b9dfb90bafce9272e5e9ce3285cb Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:34:19 -0800 Subject: [PATCH 26/87] Update CMakeLists.txt: fix to be kp_kokkos_sampler --- tests/sampler/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index b02a7511d..525152260 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,5 +1,5 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp - KOKKOS_TOOLS_LIBS kp_sampler + KOKKOS_TOOLS_LIBS kp_kokkos_sampler ) From fc3cc11160b8e5462ff49ace4e67db22734db3ab Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:35:52 -0800 Subject: [PATCH 27/87] Update test_randomized_sampling.cpp: fix to test with RE2 --- tests/sampler/test_randomized_sampling.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index d4352b742..ff7db307f 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -16,7 +16,7 @@ struct Tester { // and third are not printed out, and the second and fourth are sequenced // correctly in the print. - for (int iter = 0; iter < 4; iter++) { + for (int iter = 0; iter < 150; iter++) { Kokkos::parallel_for("named kernel", Kokkos::RangePolicy(space, 0, 1), *this); @@ -26,7 +26,8 @@ struct Tester { }; static const std::vector matchers{ - "[0-9,a-z]+ KokkosP: sample 2 [0-9]+ KokkosP: sample 4 [0-9,a-z]+"}; + "> (.*)\| KokkosP: sample 101 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 101 finished with child-begin function.\nKokkosP: sample 101 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" }; +"}; /** * @test This test checks that the tool effectively samples randomly. From 7f519ef58b4dba809e393fe61a19e12b3bd9f2f2 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:36:18 -0800 Subject: [PATCH 28/87] Update test_randomized_sampling.cpp: vector include --- tests/sampler/test_randomized_sampling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index ff7db307f..62dea521a 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -1,6 +1,6 @@ #include #include - +#include #include "gmock/gmock.h" #include "gtest/gtest.h" From 0df7f5c679629d1a5255c68246ed35d3d4d2f7bc Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:40:02 -0800 Subject: [PATCH 29/87] Update test_randomized_sampling.cpp: curly fix --- tests/sampler/test_randomized_sampling.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 62dea521a..ac21da819 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -26,8 +26,9 @@ struct Tester { }; static const std::vector matchers{ - "> (.*)\| KokkosP: sample 101 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 101 finished with child-begin function.\nKokkosP: sample 101 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" }; -"}; + "> (.*)\| KokkosP: sample 101 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 101 finished with child-begin function.\nKokkosP: sample 101 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" +" +}; /** * @test This test checks that the tool effectively samples randomly. From 9ee76007bdb0c75b0384d206fe12cd8211318941 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:41:39 -0800 Subject: [PATCH 30/87] Update test_randomized_sampling.cpp: RE2 quotation fix --- tests/sampler/test_randomized_sampling.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index ac21da819..6f989916b 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -26,8 +26,7 @@ struct Tester { }; static const std::vector matchers{ - "> (.*)\| KokkosP: sample 101 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 101 finished with child-begin function.\nKokkosP: sample 101 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" -" + "> (.*)\| KokkosP: sample 101 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 101 finished with child-begin function.\nKokkosP: sample 101 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" }; /** From 4c241a202eb9ca8fc75eedd769ce9c738cc6829d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:42:15 -0500 Subject: [PATCH 31/87] CMakeLists.txt: put in test for kernel logger --- tests/sampler/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 525152260..c0d880f48 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,5 +1,5 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp - KOKKOS_TOOLS_LIBS kp_kokkos_sampler + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger ) From e6e65459df571bd415a95e7c3f7785c1da875199 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:44:50 -0500 Subject: [PATCH 32/87] test_randomized_sampling.cpp: sample number to be 100 --- tests/sampler/test_randomized_sampling.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 6f989916b..29245fb54 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -9,8 +9,8 @@ struct Tester { template explicit Tester(const execution_space& space) { - //! Explicitly launch a kernel with a name, and run it 4 times with kernel - //! logger. Use a periodic sampling with skip rate 2. This should print out + //! Explicitly launch a kernel with a name, and run it 150 times with kernel + //! logger. Use a periodic sampling with skip rate 101. This should print out //! 1 invocation In the test, we match the invocations output from the //! second invocation and make sure the first // and third are not printed out, and the second and fourth are sequenced @@ -26,7 +26,7 @@ struct Tester { }; static const std::vector matchers{ - "> (.*)\| KokkosP: sample 101 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 101 finished with child-begin function.\nKokkosP: sample 101 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" + "> (.*)\| KokkosP: sample 100 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 100 finished with child-begin function.\nKokkosP: sample 100 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" }; /** From 377ffa8cabd3f3ebc4bdb65d5fbcf69a0caa50a6 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:57:55 -0500 Subject: [PATCH 33/87] test_randomized_sampling.cpp: fix comment on test --- tests/sampler/test_randomized_sampling.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 29245fb54..10de16bf0 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -11,10 +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 101. This should print out - //! 1 invocation In the test, we match the invocations output from the - //! second invocation and make sure the first - // and third are not printed out, and the second and fourth are sequenced - // correctly in the print. + //! 1 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", From 74f9196f4ebc3b40213db4291083b2bc8a17fe42 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:11:01 -0500 Subject: [PATCH 34/87] test_randomized_sampling.cpp: env var default --- tests/sampler/test_randomized_sampling.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 10de16bf0..83cf69349 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -27,11 +27,11 @@ struct Tester { }; /** - * @test This test checks that the tool effectively samples randomly. + * @test This test checks that the tool effectively samples. * */ - TEST(SamplerTest, randomized) { + TEST(SamplerTest, ktoEnvVarDefault) { //! Initialize @c Kokkos. Kokkos::initialize(); From e337319f55daed6b390eec57ec15b06459aa56b1 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:39:28 -0700 Subject: [PATCH 35/87] Update CMakeLists.txt: fix sampler --- tests/sampler/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index c0d880f48..7a6bcd47e 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,5 +1,7 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp - KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_LIBS kp_kokkos_sampler + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_SAMPLER_SKIP 101 ) From d74eae77e05673b5ac1d6fcc741ba7447019971e Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:40:36 -0700 Subject: [PATCH 36/87] Update CMakeLists.txt: put add'l env variables --- tests/sampler/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 7a6bcd47e..7a8f5432b 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -2,6 +2,6 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler - KOKKOS_TOOLS_SAMPLER_VERBOSE 2 - KOKKOS_TOOLS_SAMPLER_SKIP 101 + KOKKOS_TOOLS_SAMPLER_VERBOSE 1 + KOKKOS_TOOLS_GLOBALFENCES 1 ) From 6049952bb3b7d0296ff6bda5ef562e309e5335e0 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:12:39 -0700 Subject: [PATCH 37/87] test_randomized_sampling.cpp: apply clang format --- tests/sampler/test_randomized_sampling.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 83cf69349..3e8deb225 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -10,8 +10,9 @@ 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 101. This should print out - //! 1 invocation, and there is a single matcher with a regular expression to check this. + //! logger. Use a periodic sampling with skip rate 101. This should print + //! out 1 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", @@ -23,8 +24,13 @@ struct Tester { }; static const std::vector matchers{ - "> (.*)\| KokkosP: sample 100 calling child-begin function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| KokkosP: sample 100 finished with child-begin function.\nKokkosP: sample 100 calling child-end function...\nKokkosP: Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\|" -}; + "> (.*)\| KokkosP: sample 100 calling child-begin function...\nKokkosP: " + "Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: " + "Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| " + "KokkosP: sample 100 finished with child-begin function.\nKokkosP: " + "sample 100 calling child-end function...\nKokkosP: Sampler attempting " + "to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully " + "invoked tool-induced fence on device 0\n > (.*)\|"}; /** * @test This test checks that the tool effectively samples. From 0c9ce3f2c48ed2bd03d2c4e3782fb8782be6d741 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:29:27 -0700 Subject: [PATCH 38/87] CMakeLists.txt: put in sampler verbose --- tests/CMakeLists.txt | 25 ++++++++++++++++++++-- tests/sampler/CMakeLists.txt | 1 - tests/sampler/test_randomized_sampling.cpp | 12 ++++------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d9d20d2ba..a5c40dcb1 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) +# 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. + function(kp_add_executable_and_test) - cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS" "" ${ARGN}) + cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES" "" ${ARGN}) if(NOT DEFINED kaeat_args_TARGET_NAME) message(FATAL_ERROR "'TARGET_NAME' is a required argument.") @@ -45,6 +48,24 @@ function(kp_add_executable_and_test) ENVIRONMENT "KOKKOS_TOOLS_LIBS=$" ) endif() + + if(DEFINED kaeat_args_KOKKOS_TOOLS_SAMPLER_VERBOSE) + set_property( + TEST ${kaeat_args_TARGET_NAME} + APPEND + PROPERTY + ENVIRONMENT "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=$" + ) + endif() endfunction(kp_add_executable_and_test) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 7a8f5432b..f16a2795f 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -3,5 +3,4 @@ kp_add_executable_and_test( SOURCE_FILE test_randomized_sampling.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler KOKKOS_TOOLS_SAMPLER_VERBOSE 1 - KOKKOS_TOOLS_GLOBALFENCES 1 ) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 3e8deb225..3e557c6dc 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -23,14 +23,10 @@ struct Tester { KOKKOS_FUNCTION void operator()(const int) const {} }; - static const std::vector matchers{ - "> (.*)\| KokkosP: sample 100 calling child-begin function...\nKokkosP: " - "Sampler attempting to invoke tool-induced fence on device 0.\nKokkosP: " - "Sampler sucessfully invoked tool-induced fence on device 0\n > (.*)\| " - "KokkosP: sample 100 finished with child-begin function.\nKokkosP: " - "sample 100 calling child-end function...\nKokkosP: Sampler attempting " - "to invoke tool-induced fence on device 0.\nKokkosP: Sampler sucessfully " - "invoked tool-induced fence on device 0\n > (.*)\|"}; + static const std::vector matchers { + "(.*) KokkosP: sample 100 calling child-begin function... (.*)" + "\nKokkosP: sample 100 calling child-end function ... (.*)" + }; /** * @test This test checks that the tool effectively samples. From 64c6a588b8f8a72531f2dc9d0c9605ccf055cae1 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:31:23 -0700 Subject: [PATCH 39/87] test_randomized_sampling: apply clang format --- tests/sampler/test_randomized_sampling.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 3e557c6dc..946b6d681 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -23,10 +23,9 @@ struct Tester { KOKKOS_FUNCTION void operator()(const int) const {} }; - static const std::vector matchers { - "(.*) KokkosP: sample 100 calling child-begin function... (.*)" - "\nKokkosP: sample 100 calling child-end function ... (.*)" - }; + static const std::vector matchers{ + "(.*) KokkosP: sample 100 calling child-begin function... (.*)" + "\nKokkosP: sample 100 calling child-end function ... (.*)"}; /** * @test This test checks that the tool effectively samples. From 486ba9e70959e033e8cfec8847d80821827effd2 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:45:47 -0700 Subject: [PATCH 40/87] test_randomized_sampling.cpp: fixing setting environment variable in Ctest --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a5c40dcb1..fe9e6900d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -54,7 +54,7 @@ function(kp_add_executable_and_test) TEST ${kaeat_args_TARGET_NAME} APPEND PROPERTY - ENVIRONMENT "KOKKOS_TOOLS_SAMPLER_VERBOSE=$" + ENVIRONMENT "KOKKOS_TOOLS_SAMPLER_VERBOSE=${kaeat_args_KOKKOS_TOOLS_SAMPLER_VERBOSE}" ) endif() @@ -63,7 +63,7 @@ function(kp_add_executable_and_test) TEST ${kaeat_args_TARGET_NAME} APPEND PROPERTY - ENVIRONMENT "KOKKOS_TOOLS_GLOBALFENCES=$" + ENVIRONMENT "KOKKOS_TOOLS_GLOBALFENCES=${kaeat_args_KOKKOS_TOOLS_GLOBALFENCES}" ) endif() From d509a6e6676d79c3ff562604d580184fe0cf96bd Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:57:10 -0700 Subject: [PATCH 41/87] test_randomized_sampling.cpp: apply clang-format --- tests/sampler/test_randomized_sampling.cpp | 59 +++++++++++----------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 946b6d681..98949d0b7 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -19,41 +19,42 @@ struct Tester { Kokkos::RangePolicy(space, 0, 1), *this); } + } - KOKKOS_FUNCTION void operator()(const int) const {} - }; + KOKKOS_FUNCTION void operator()(const int) const {} +}; - static const std::vector matchers{ - "(.*) KokkosP: sample 100 calling child-begin function... (.*)" - "\nKokkosP: sample 100 calling child-end function ... (.*)"}; +static const std::vector matchers{ + "(.*) KokkosP: sample 100 calling child-begin function... (.*)" + "\nKokkosP: sample 100 calling child-end function ... (.*)"}; - /** - * @test This test checks that the tool effectively samples. - * +/** + * @test This test checks that the tool effectively samples. + * - */ - TEST(SamplerTest, ktoEnvVarDefault) { - //! Initialize @c Kokkos. - Kokkos::initialize(); + */ +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()); + //! 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{}); + //! Run tests. @todo Replace this with Google Test. + Tester tester(Kokkos::DefaultExecutionSpace{}); - //! Finalize @c Kokkos. - Kokkos::finalize(); + //! Finalize @c Kokkos. + Kokkos::finalize(); - //! Restore output buffer. - std::cout.flush(); - std::cout.rdbuf(coutbuf); - std::cout << output.str() << std::endl; + //! 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 - } + //! Analyze test output. + for (const auto& matcher : matchers) { + EXPECT_THAT(output.str(), ::testing::ContainsRegex(matcher)); + } // end TEST +} From 2c84bcca5ec31b2b619b98e9aae7da9957700f1c Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:21:12 -0700 Subject: [PATCH 42/87] fix test randomized sampling --- tests/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fe9e6900d..fe255da87 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,8 +11,7 @@ # 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. function(kp_add_executable_and_test) - - cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES" "" ${ARGN}) + cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS;KOKKOS_TOOLS_LIBS2;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES" "" ${ARGN}) if(NOT DEFINED kaeat_args_TARGET_NAME) message(FATAL_ERROR "'TARGET_NAME' is a required argument.") @@ -40,12 +39,12 @@ function(kp_add_executable_and_test) COMMAND $ ) - if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS) + if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS AND DEFINED kaeat_args_KOKKOS_TOOLS_LIBS2) set_property( TEST ${kaeat_args_TARGET_NAME} APPEND PROPERTY - ENVIRONMENT "KOKKOS_TOOLS_LIBS=$" + ENVIRONMENT "KOKKOS_TOOLS_LIBS=$;$" ) endif() From 3cb33b4d9ad3257664c69b85529dd05377a0d134 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:34:20 -0700 Subject: [PATCH 43/87] CMakeLists.txt: fix enviornment var for KOKKOS_TOOLS_LIBS2 --- tests/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fe255da87..e25e8823b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,13 +39,22 @@ function(kp_add_executable_and_test) COMMAND $ ) - if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS AND DEFINED kaeat_args_KOKKOS_TOOLS_LIBS2) + if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS) + if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS2) set_property( TEST ${kaeat_args_TARGET_NAME} APPEND PROPERTY ENVIRONMENT "KOKKOS_TOOLS_LIBS=$;$" ) + else() + set_property( + TEST + APPEND + PROPERTY + ENVIRONMENT "KOKKOS_TOOLS_LIBS=$;" + ) + endif() if(DEFINED kaeat_args_KOKKOS_TOOLS_SAMPLER_VERBOSE) From e4c4f6bc2f67220a0919c5be75745b5936a16b28 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:36:03 -0700 Subject: [PATCH 44/87] CMakeLists.txt: add global fences environment variable --- tests/sampler/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index f16a2795f..b0db4be06 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -2,5 +2,7 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler + KOKKOS_TOOLS_LIBS2 kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 1 + KOKKOS_TOOLS_GLOBALFENCES 1 ) From fa331665eed335ad9ea5d6f548daf75eba20b307 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:39:43 -0700 Subject: [PATCH 45/87] CMakeLists.txt: fix nesting of if's in ctest --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e25e8823b..6588715a7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -54,7 +54,7 @@ function(kp_add_executable_and_test) PROPERTY ENVIRONMENT "KOKKOS_TOOLS_LIBS=$;" ) - + endif() endif() if(DEFINED kaeat_args_KOKKOS_TOOLS_SAMPLER_VERBOSE) From 3c1fb93364dac4f29338fc313929a3f183373fd8 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:52:43 -0700 Subject: [PATCH 46/87] Update CMakeLists.txt: kaeat_args --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6588715a7..70e5bcc8c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -49,7 +49,7 @@ function(kp_add_executable_and_test) ) else() set_property( - TEST + TEST ${kaeat_args_TARGET_NAME} APPEND PROPERTY ENVIRONMENT "KOKKOS_TOOLS_LIBS=$;" From 375ebba3e67fc7dfbc8f3c70ce7872aea6c015dd Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:02:39 -0700 Subject: [PATCH 47/87] Update CMakeLists.txt: kp_kernel_logger fix --- tests/sampler/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index b0db4be06..c00e67322 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,7 +1,7 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp - KOKKOS_TOOLS_LIBS kp_kokkos_sampler + KOKKOS_TOOLS_LIBS kp_kokkos_sampler;kp_kernel_logger KOKKOS_TOOLS_LIBS2 kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 1 KOKKOS_TOOLS_GLOBALFENCES 1 From c19c0184654b0e12d5f375a05235fa627f81d4d9 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:30:30 -0700 Subject: [PATCH 48/87] Update CMakeLists.txt: fix target file 2 --- tests/sampler/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index c00e67322..b0db4be06 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,7 +1,7 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp - KOKKOS_TOOLS_LIBS kp_kokkos_sampler;kp_kernel_logger + KOKKOS_TOOLS_LIBS kp_kokkos_sampler KOKKOS_TOOLS_LIBS2 kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 1 KOKKOS_TOOLS_GLOBALFENCES 1 From 8317118a66e41b54c95c2cc5d3971056ed4b3ce6 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 20 Mar 2024 08:50:08 -0700 Subject: [PATCH 49/87] add cmake --- tests/CMakeLists.txt | 12 +++++++++++- tests/sampler/CMakeLists.txt | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6588715a7..a508225f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,7 +45,7 @@ function(kp_add_executable_and_test) TEST ${kaeat_args_TARGET_NAME} APPEND PROPERTY - ENVIRONMENT "KOKKOS_TOOLS_LIBS=$;$" + ENVIRONMENT "KOKKOS_TOOLS_LIBS=$\;$" ) else() set_property( @@ -74,6 +74,16 @@ function(kp_add_executable_and_test) 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) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index b0db4be06..537c2dd20 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -4,5 +4,6 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler KOKKOS_TOOLS_LIBS2 kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 1 + KOKKOS_TOOLS_SAMPLER_SKIP 101 KOKKOS_TOOLS_GLOBALFENCES 1 ) From 9517af586b59c9b8ecc191ad649ee7a1d41b4aba Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Wed, 20 Mar 2024 09:06:28 -0700 Subject: [PATCH 50/87] random sampling --- common/kokkos-sampler/kp_sampler_skip.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 6f53d0a65..00c2471df 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -88,7 +88,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const char* tool_verbose_str = getenv("KOKKOS_TOOLS_SAMPLER_VERBOSE"); const char* tool_globFence_str = getenv("KOKKOS_TOOLS_GLOBALFENCES"); const char* tool_seed_str = getenv("KOKKOS_TOOLS_RANDOM_SEED"); - + printf("tool_verbose_str: %s\n", tool_verbose_str); if (NULL != tool_verbose_str) { tool_verbosity = atoi(tool_verbose_str); } else { @@ -191,7 +191,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); if (NULL != tool_sample) { kernelSampleSkip = atoi(tool_sample) + 1; - } + } else + kernelSampleSkip = 101; if (tool_verbosity > 0) { printf("KokkosP: Sampling rate set to: %s\n", tool_sample); From a03955ef059904c7af759c92ebd1b112e78bc698 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:58:18 -0700 Subject: [PATCH 51/87] test_randomized_sampling.cpp: fix matcher --- tests/sampler/test_randomized_sampling.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 98949d0b7..000883f17 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -25,8 +25,7 @@ struct Tester { }; static const std::vector matchers{ - "(.*) KokkosP: sample 100 calling child-begin function... (.*)" - "\nKokkosP: sample 100 calling child-end function ... (.*)"}; + "(.*) KokkosP: Execution of kernel 101 is completed (.*)"}; /** * @test This test checks that the tool effectively samples. From a4285d33181ef1d7c7010828a40d537e0152e3ca Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 21 Mar 2024 19:02:00 -0700 Subject: [PATCH 52/87] Update CMakeLists.txt: fix sampler skip variable --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 01bf9ccf5..334197492 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,7 +11,7 @@ # 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. function(kp_add_executable_and_test) - cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS;KOKKOS_TOOLS_LIBS2;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES" "" ${ARGN}) + cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS;KOKKOS_TOOLS_LIBS2;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES;KOKKOS_TOOLS_SAMPLER_SKIP" "" ${ARGN}) if(NOT DEFINED kaeat_args_TARGET_NAME) message(FATAL_ERROR "'TARGET_NAME' is a required argument.") From 090245bd32ce719061e3bc21b46800f6e39116b8 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:40:51 -0400 Subject: [PATCH 53/87] Update CMakeLists.txt: env var --- tests/sampler/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 537c2dd20..0df9a156b 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -4,6 +4,7 @@ kp_add_executable_and_test( KOKKOS_TOOLS_LIBS kp_kokkos_sampler KOKKOS_TOOLS_LIBS2 kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 1 - KOKKOS_TOOLS_SAMPLER_SKIP 101 + KOKKOS_TOOLS_SAMPLER_SKIP 100 + KOKKOS_TOOLS_SAMPLER_PROB 100.0 KOKKOS_TOOLS_GLOBALFENCES 1 ) From 371ae929970176fb39b02a6f4725fc645264121f Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:22:10 -0400 Subject: [PATCH 54/87] Update kp_sampler_skip.cpp: remove else kernelSampleSkip --- common/kokkos-sampler/kp_sampler_skip.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 00c2471df..b6a4a4976 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -191,8 +191,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); if (NULL != tool_sample) { kernelSampleSkip = atoi(tool_sample) + 1; - } else - kernelSampleSkip = 101; + } if (tool_verbosity > 0) { printf("KokkosP: Sampling rate set to: %s\n", tool_sample); From 27e112bae86cba76a1ab1cdd2a86cc6933af0d19 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:07:04 -0400 Subject: [PATCH 55/87] Update kp_sampler_skip.cpp: period in sampler fence printf --- 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 b6a4a4976..a522deecc 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -62,7 +62,7 @@ void invoke_ktools_fence(uint32_t devID) { if (tool_verbosity > 1) { printf( "KokkosP: Sampler sucessfully invoked" - " tool-induced fence on device %d\n", + " tool-induced fence on device %d.\n", getDeviceID(devID)); } } else { From ceb1e2d711e034a44dfd004d6b6b7f13143fc8b9 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:20:29 -0400 Subject: [PATCH 56/87] kp_sampler_skip.cpp: removed tool verbose str print --- common/kokkos-sampler/kp_sampler_skip.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index a522deecc..61ba7e1bd 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -88,7 +88,6 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const char* tool_verbose_str = getenv("KOKKOS_TOOLS_SAMPLER_VERBOSE"); const char* tool_globFence_str = getenv("KOKKOS_TOOLS_GLOBALFENCES"); const char* tool_seed_str = getenv("KOKKOS_TOOLS_RANDOM_SEED"); - printf("tool_verbose_str: %s\n", tool_verbose_str); if (NULL != tool_verbose_str) { tool_verbosity = atoi(tool_verbose_str); } else { From 44f1eb7c631cff171e3017c217dab6d39b255686 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:31:49 -0400 Subject: [PATCH 57/87] test_randomized_sampling.cpp: take out flushes --- tests/sampler/test_randomized_sampling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 000883f17..994b0c57b 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -48,7 +48,7 @@ TEST(SamplerTest, ktoEnvVarDefault) { Kokkos::finalize(); //! Restore output buffer. - std::cout.flush(); + // std::cout.flush(); std::cout.rdbuf(coutbuf); std::cout << output.str() << std::endl; From 19cbc2c305209fd9ef4d7ac4d812d8fc4f091006 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 25 Mar 2024 13:54:07 -0400 Subject: [PATCH 58/87] Convert kp_kernel_logger to std::cout --- debugging/kernel-logger/kp_kernel_logger.cpp | 83 +++++++++----------- 1 file changed, 35 insertions(+), 48 deletions(-) diff --git a/debugging/kernel-logger/kp_kernel_logger.cpp b/debugging/kernel-logger/kp_kernel_logger.cpp index bf7f585bb..e67891690 100644 --- a/debugging/kernel-logger/kp_kernel_logger.cpp +++ b/debugging/kernel-logger/kp_kernel_logger.cpp @@ -20,6 +20,7 @@ #include #include #include +#include std::vector regions; static uint64_t uniqID; @@ -28,10 +29,10 @@ struct SpaceHandle { }; void kokkosp_print_region_stack_indent(const int level) { - printf("KokkosP: "); + std::cout << "KokkosP: "; for (int i = 0; i < level; i++) { - printf(" "); + std::cout << " "; } } @@ -40,7 +41,7 @@ int kokkosp_print_region_stack() { for (auto regItr = regions.begin(); regItr != regions.end(); regItr++) { kokkosp_print_region_stack_indent(level); - printf("%s\n", (*regItr).c_str()); + std::cout << *regItr << '\n'; level++; } @@ -52,15 +53,13 @@ extern "C" void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const uint32_t /*devInfoCount*/, void* /*deviceInfo*/) { - printf( - "KokkosP: Kernel Logger Library Initialized (sequence is %d, version: " - "%llu)\n", - loadSeq, (unsigned long long)(interfaceVer)); + std::cout << "KokkosP: Kernel Logger Library Initialized (sequence is " + << loadSeq << ", version: " << interfaceVer << ")\n"; uniqID = 0; } extern "C" void kokkosp_finalize_library() { - printf("KokkosP: Kokkos library finalization called.\n"); + std::cout << "KokkosP: Kokkos library finalization called.\n"; } extern "C" void kokkosp_begin_parallel_for(const char* name, @@ -68,20 +67,17 @@ extern "C" void kokkosp_begin_parallel_for(const char* name, uint64_t* kID) { *kID = uniqID++; - printf( - "KokkosP: Executing parallel-for kernel on device %d with unique " - "execution identifier %llu\n", - devID, (unsigned long long)(*kID)); + std::cout << "KokkosP: Executing parallel-for kernel on device " << devID + << " with unique execution identifier " << *kID << '\n'; int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - - printf(" %s\n", name); + std::cout << " " << name << '\n'; } extern "C" void kokkosp_end_parallel_for(const uint64_t kID) { - printf("KokkosP: Execution of kernel %llu is completed.\n", - (unsigned long long)(kID)); + std::abort(); + std::cout << "KokkosP: Execution of kernel " << kID << " is completed.\n"; } extern "C" void kokkosp_begin_parallel_scan(const char* name, @@ -89,20 +85,17 @@ extern "C" void kokkosp_begin_parallel_scan(const char* name, uint64_t* kID) { *kID = uniqID++; - printf( - "KokkosP: Executing parallel-scan kernel on device %d with unique " - "execution identifier %llu\n", - devID, (unsigned long long)(*kID)); + std::cout << "KokkosP: Executing parallel-scan kernel on device " << devID + << " with unique execution identifier " << *kID << '\n'; int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - printf(" %s\n", name); + std::cout << " " << name << '\n'; } extern "C" void kokkospk_end_parallel_scan(const uint64_t kID) { - printf("KokkosP: Execution of kernel %llu is completed.\n", - (unsigned long long)(kID)); + std::cout << "KokkosP: Execution of kernel " << kID << " is completed.\n"; } extern "C" void kokkosp_begin_parallel_reduce(const char* name, @@ -110,20 +103,17 @@ extern "C" void kokkosp_begin_parallel_reduce(const char* name, uint64_t* kID) { *kID = uniqID++; - printf( - "KokkosP: Executing parallel-reduce kernel on device %d with unique " - "execution identifier %llu\n", - devID, (unsigned long long)(*kID)); + std::cout << "KokkosP: Executing parallel-reduce kernel on device " << devID + << " with unique execution identifier " << *kID << '\n'; int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - printf(" %s\n", name); + std::cout << " " << name << '\n'; } extern "C" void kokkosp_end_parallel_reduce(const uint64_t kID) { - printf("KokkosP: Execution of kernel %llu is completed.\n", - (unsigned long long)(kID)); + std::cout << "KokkosP: Execution of kernel " << kID << " is completed.\n"; } extern "C" void kokkosp_begin_fence(const char* name, const uint32_t devID, @@ -139,15 +129,13 @@ extern "C" void kokkosp_begin_fence(const char* name, const uint32_t devID, } else { *kID = uniqID++; - printf( - "KokkosP: Executing fence on device %d with unique execution " - "identifier %llu\n", - devID, (unsigned long long)(*kID)); + std::cout << "KokkosP: Executing fence on device " << devID + << " with unique execution identifier " << kID << '\n'; int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - printf(" %s\n", name); + std::cout << " " << name << '\n'; } } @@ -156,13 +144,12 @@ extern "C" void kokkosp_end_fence(const uint64_t kID) { // dealing with the application's fence, which we filtered out in the callback // for fences if (kID != std::numeric_limits::max()) { - printf("KokkosP: Execution of fence %llu is completed.\n", - (unsigned long long)(kID)); + std::cout << "KokkosP: Execution of fence %llu is completed.\n"; } } extern "C" void kokkosp_push_profile_region(char* regionName) { - printf("KokkosP: Entering profiling region: %s\n", regionName); + std::cout << "KokkosP: Entering profiling region: " << regionName << '\n'; std::string regionNameStr(regionName); regions.push_back(regionNameStr); @@ -170,21 +157,22 @@ extern "C" void kokkosp_push_profile_region(char* regionName) { extern "C" void kokkosp_pop_profile_region() { if (regions.size() > 0) { - printf("KokkosP: Exiting profiling region: %s\n", regions.back().c_str()); + std::cout << "KokkosP: Exiting profiling region: " << regions.back() + << '\n'; regions.pop_back(); } } extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char* name, void* ptr, uint64_t size) { - printf("KokkosP: Allocate<%s> name: %s pointer: %p size: %llu\n", handle.name, - name, ptr, (unsigned long long)(size)); + std::cout << "KokkosP: Allocate<" << handle.name << "> name: " << name + << " pointer: " << ptr << " size: " << size << '\n'; } extern "C" void kokkosp_deallocate_data(SpaceHandle handle, const char* name, void* ptr, uint64_t size) { - printf("KokkosP: Deallocate<%s> name: %s pointer: %p size: %llu\n", - handle.name, name, ptr, (unsigned long long)(size)); + std::cout << "KokkosP: Deallocate<" << handle.name << "> name: " << name + << " pointer: " << ptr << " size: " << size << '\n'; } extern "C" void kokkosp_begin_deep_copy(SpaceHandle dst_handle, @@ -193,9 +181,8 @@ extern "C" void kokkosp_begin_deep_copy(SpaceHandle dst_handle, SpaceHandle src_handle, const char* src_name, const void* src_ptr, uint64_t size) { - printf( - "KokkosP: DeepCopy<%s,%s> DST(name: %s pointer: %p) SRC(name: %s pointer " - "%p) Size: %llu\n", - dst_handle.name, src_handle.name, dst_name, dst_ptr, src_name, src_ptr, - (unsigned long long)(size)); + std::cout << "KokkosP: DeepCopy<" << dst_handle.name << ',' << src_handle.name + << "> DST(name: " << dst_name << " pointer: " << dst_ptr + << ") SRC(name: " << src_name << " pointer " << src_ptr + << ") Size: " << size << '\n'; } From c309f0e38d08ff885c92e4fe883cec775642766d Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 26 Mar 2024 10:01:26 -0400 Subject: [PATCH 59/87] Working --- common/kokkos-sampler/kp_sampler_skip.cpp | 92 ++++++++------------ debugging/kernel-logger/kp_kernel_logger.cpp | 1 - tests/sampler/CMakeLists.txt | 4 +- tests/sampler/test_randomized_sampling.cpp | 7 +- 4 files changed, 42 insertions(+), 62 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 61ba7e1bd..f56238ad9 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -8,6 +8,7 @@ #include "kp_config.hpp" #include #include +#include namespace KokkosTools { namespace Sampler { @@ -187,14 +188,23 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, uniqID = 1; - const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); - if (NULL != tool_sample) { - kernelSampleSkip = atoi(tool_sample) + 1; + if (0 > tool_seed) { + srand(time(NULL)); + if (tool_verbosity > 0) { + printf( + "KokkosP: Seeding random number generator using clock for " + "random sampling.\n"); + } + } else { + srand(tool_seed); + if (tool_verbosity > 0) { + printf( + "KokkosP: Seeding random number generator using seed %u for " + "random sampling.\n", + tool_seed); + } } - if (tool_verbosity > 0) { - printf("KokkosP: Sampling rate set to: %s\n", tool_sample); - } const char* tool_probability = getenv("KOKKOS_TOOLS_SAMPLER_PROB"); if (NULL != tool_probability) { @@ -219,15 +229,30 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, "a Kokkos kernel will be profiled.\n"); tool_prob_num = 0.0; } + if (tool_verbosity > 0) { + printf("KokkosP: Probability for the sampler set to: %f\n", tool_prob_num); + } + kernelSampleSkip = 1; + return; } - if ((tool_prob_num < 0.0) && - (kernelSampleSkip == std::numeric_limits::max())) { + + const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); + if (NULL != tool_sample) { + tool_prob_num = 100.0; + kernelSampleSkip = atoi(tool_sample) + 1; + if (tool_verbosity > 0) { + printf("KokkosP: Sampling rate set to: %s\n", tool_sample); + } + return; + } + if (tool_verbosity > 0) { printf( "KokkosP: Neither the probability " "nor the skip rate for sampling were set...\n"); } tool_prob_num = 10.0; + kernelSampleSkip = 1; if (tool_verbosity > 0) { printf( "KokkosP: The probability " @@ -236,52 +261,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, "will not be used.\n", tool_prob_num); } - } - - if (tool_verbosity > 0) { - if (tool_verbosity > 1) { - printf("KokkosP: Sampling skip rate provided as input is: %s\n", - tool_sample); - printf("KokkosP: Sampling probability provided as input is: %s\n", - tool_probability); - } - printf("KokkosP: Sampling skip rate is set to: %llu\n", - (unsigned long long)(kernelSampleSkip)); - printf("KokkosP: Sampling probability is set to %f\n", tool_prob_num); - } - - if (0 > tool_seed) { - srand(time(NULL)); - if (tool_verbosity > 0) { - printf( - "KokkosP: Seeding random number generator using clock for " - "random sampling.\n"); - } - } else { - srand(tool_seed); - if (tool_verbosity > 0) { - printf( - "KokkosP: Seeding random number generator using seed %u for " - "random sampling.\n", - tool_seed); - } - } - - if ((NULL != tool_probability) && (NULL != tool_sample)) { - printf( - "KokkosP: You set both the probability and skip rate for the sampler. " - "Only random sampling " - "will be done, using the probabability you set; " - "The skip rate you set will be ignored.\n"); - - if (tool_verbosity > 1) { - printf( - "KokkosP: Note: The skip rate will be set to 1. Sampling will not be " - "based " - " on a pre-defined periodicity.\n"); - } kernelSampleSkip = 1; - } } void kokkosp_finalize_library() { @@ -294,7 +274,7 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, static uint64_t invocationNum = 0; ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { - if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.0)) { + if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.0)) { if (tool_verbosity > 0) { printf("KokkosP: sample %llu calling child-begin function...\n", (unsigned long long)(*kID)); @@ -316,8 +296,8 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, } void kokkosp_end_parallel_for(const uint64_t kID) { - if (NULL != endForCallee) { - if (!(infokIDSample.find(kID) == infokIDSample.end())) { +if (NULL != endForCallee) { + if (!(infokIDSample.find(kID) == infokIDSample.end())) { uint64_t retrievedNestedkID = infokIDSample[kID]; if (tool_verbosity > 0) { printf("KokkosP: sample %llu calling child-end function...\n", diff --git a/debugging/kernel-logger/kp_kernel_logger.cpp b/debugging/kernel-logger/kp_kernel_logger.cpp index e67891690..90d0bf69a 100644 --- a/debugging/kernel-logger/kp_kernel_logger.cpp +++ b/debugging/kernel-logger/kp_kernel_logger.cpp @@ -76,7 +76,6 @@ extern "C" void kokkosp_begin_parallel_for(const char* name, } extern "C" void kokkosp_end_parallel_for(const uint64_t kID) { - std::abort(); std::cout << "KokkosP: Execution of kernel " << kID << " is completed.\n"; } diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 0df9a156b..842fe6fe2 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -3,8 +3,8 @@ kp_add_executable_and_test( SOURCE_FILE test_randomized_sampling.cpp KOKKOS_TOOLS_LIBS kp_kokkos_sampler KOKKOS_TOOLS_LIBS2 kp_kernel_logger - KOKKOS_TOOLS_SAMPLER_VERBOSE 1 - KOKKOS_TOOLS_SAMPLER_SKIP 100 + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_SAMPLER_SKIP 50 KOKKOS_TOOLS_SAMPLER_PROB 100.0 KOKKOS_TOOLS_GLOBALFENCES 1 ) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 994b0c57b..5fcd2371d 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -10,8 +10,8 @@ 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 101. This should print - //! out 1 invocation, and there is a single matcher with a regular + //! 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++) { @@ -25,7 +25,8 @@ struct Tester { }; static const std::vector matchers{ - "(.*) KokkosP: Execution of kernel 101 is completed (.*)"}; + "(.*)KokkosP: Execution of kernel 0 is completed(.*)", + "(.*)KokkosP: Execution of kernel 1 is completed(.*)"}; /** * @test This test checks that the tool effectively samples. From 8cab46a2e46db5d7c8e2fb85460b6bb3dee83064 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 26 Mar 2024 10:36:38 -0400 Subject: [PATCH 60/87] Almost working --- tests/CMakeLists.txt | 54 +++++++++++++++++------------------- tests/sampler/CMakeLists.txt | 4 +-- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 334197492..2c38e064f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,7 +11,7 @@ # 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. function(kp_add_executable_and_test) - cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_LIBS;KOKKOS_TOOLS_LIBS2;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES;KOKKOS_TOOLS_SAMPLER_SKIP" "" ${ARGN}) + 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.") @@ -34,54 +34,50 @@ function(kp_add_executable_and_test) kokkostools test_common ) + MESSAGE(STATUS "TARGET_NAME: ${kaeat_args_TARGET_NAME}, KOKKOS_TOOLS_LIBS: ${kaeat_args_KOKKOS_TOOLS_LIBS}") + add_test( NAME ${kaeat_args_TARGET_NAME} COMMAND $ ) if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS) - if(DEFINED kaeat_args_KOKKOS_TOOLS_LIBS2) + set(TOOL_LIBS_FILES) + foreach(TOOL_LIB ${kaeat_args_KOKKOS_TOOLS_LIBS}) + set(TOOL_LIBS_FILES "${TOOL_LIBS_FILES}\;$") + endforeach() + set_property( TEST ${kaeat_args_TARGET_NAME} - APPEND - PROPERTY - ENVIRONMENT "KOKKOS_TOOLS_LIBS=$\;$" + APPEND PROPERTY ENVIRONMENT "KOKKOS_TOOLS_LIBS=${TOOL_LIBS_FILES}" ) - else() - set_property( - TEST ${kaeat_args_TARGET_NAME} - APPEND - PROPERTY - ENVIRONMENT "KOKKOS_TOOLS_LIBS=$;" - ) - endif() 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}" - ) + 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}" + 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}" - ) + set_property( + TEST ${kaeat_args_TARGET_NAME} + APPEND + PROPERTY + ENVIRONMENT "KOKKOS_TOOLS_SAMPLER_SKIP=${kaeat_args_KOKKOS_TOOLS_SAMPLER_SKIP}" + ) endif() diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 842fe6fe2..a756af4ff 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,10 +1,8 @@ kp_add_executable_and_test( TARGET_NAME test_sampler_randomizedsampling SOURCE_FILE test_randomized_sampling.cpp - KOKKOS_TOOLS_LIBS kp_kokkos_sampler - KOKKOS_TOOLS_LIBS2 kp_kernel_logger + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger KOKKOS_TOOLS_SAMPLER_VERBOSE 2 KOKKOS_TOOLS_SAMPLER_SKIP 50 - KOKKOS_TOOLS_SAMPLER_PROB 100.0 KOKKOS_TOOLS_GLOBALFENCES 1 ) From 83d17fb2a0c98bab3bb9d531fabb9ab35b5773c8 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 26 Mar 2024 10:42:47 -0400 Subject: [PATCH 61/87] Still working --- tests/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2c38e064f..7dfd75f69 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,8 +34,6 @@ function(kp_add_executable_and_test) kokkostools test_common ) - MESSAGE(STATUS "TARGET_NAME: ${kaeat_args_TARGET_NAME}, KOKKOS_TOOLS_LIBS: ${kaeat_args_KOKKOS_TOOLS_LIBS}") - add_test( NAME ${kaeat_args_TARGET_NAME} COMMAND $ @@ -44,8 +42,9 @@ 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}) - set(TOOL_LIBS_FILES "${TOOL_LIBS_FILES}\;$") + list(APPEND TOOL_LIBS_FILES "$") endforeach() + string(REPLACE ";" "\;" TOOL_LIBS_FILES "${TOOL_LIBS_FILES}") set_property( TEST ${kaeat_args_TARGET_NAME} From e683d6f0d904aee8058080efc928beb358ef4fe7 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 26 Mar 2024 11:14:27 -0400 Subject: [PATCH 62/87] Use cout in sampler --- common/kokkos-sampler/kp_sampler_skip.cpp | 122 ++++++++++----------- tests/sampler/test_randomized_sampling.cpp | 10 +- 2 files changed, 63 insertions(+), 69 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index f56238ad9..456131fde 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -54,22 +54,22 @@ uint32_t getDeviceID(uint32_t devid_in) { void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { if (tool_verbosity > 1) { - printf( + std::cout << "KokkosP: Sampler attempting to invoke" - " tool-induced fence on device %d.\n", - getDeviceID(devID)); + " tool-induced fence on device " << + getDeviceID(devID) << '\n'; } (*(tpi_funcs.fence))(devID); if (tool_verbosity > 1) { - printf( + std::cout << "KokkosP: Sampler sucessfully invoked" - " tool-induced fence on device %d.\n", - getDeviceID(devID)); + " tool-induced fence on device " << + getDeviceID(devID) << '\n'; } } else { - printf( + std::cout << "KokkosP: FATAL: Kokkos Tools Programming Interface's tool-invoked " - "Fence is NULL!\n"); + "Fence is NULL!\n"; } } @@ -77,9 +77,9 @@ void kokkosp_provide_tool_programming_interface( uint32_t num_funcs, Kokkos_Tools_ToolProgrammingInterface funcsFromTPI) { if (!num_funcs) { if (tool_verbosity > 0) - printf( + std::cout << "KokkosP: Note: Number of functions in Tools Programming Interface " - "is 0!\n"); + "is 0!\n"; } tpi_funcs = funcsFromTPI; } @@ -105,12 +105,12 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); if (NULL == profileLibrary) { - printf( + std::cout << "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a deprecated " - "variable. Please use KOKKOS_TOOLS_LIBS\n"); + "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: No library to call in " << profileLibrary << '\n'; exit(-1); } } @@ -127,19 +127,18 @@ 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: No child 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 ..\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()); + std::cerr << "KokkosP: Error: Unable to load: " << nextLibrary << " (Error=" << dlerror() << ")\n"; exit(-1); } else { beginForCallee = @@ -167,19 +166,19 @@ 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'; } } } @@ -191,17 +190,16 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, if (0 > tool_seed) { srand(time(NULL)); if (tool_verbosity > 0) { - printf( + std::cout << "KokkosP: Seeding random number generator using clock for " - "random sampling.\n"); + "random sampling.\n"; } } else { srand(tool_seed); if (tool_verbosity > 0) { - printf( - "KokkosP: Seeding random number generator using seed %u for " - "random sampling.\n", - tool_seed); + std::cout << + "KokkosP: Seeding random number generator using seed " << tool_seed << " for " + "random sampling.\n"; } } @@ -213,24 +211,24 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, // Connector reasons about probability as a double between 0.0 and 1.0. tool_prob_num = atof(tool_probability); if (tool_prob_num > 100.0) { - printf( + std::cout << "KokkosP: The sampling probability value is set to be greater than " "100.0. " "The probability for the sampler will be set to 100 percent; all of " "the " - "invocations of a Kokkos kernel will be profiled.\n"); + "invocations of a Kokkos kernel will be profiled.\n"; tool_prob_num = 100.0; } else if (tool_prob_num < 0.0) { - printf( + std::cout << "KokkosP: The sampling probability value is set to be a negative " "number. The " "sampler's probability will be set to 0 percent; none of the " "invocations of " - "a Kokkos kernel will be profiled.\n"); + "a Kokkos kernel will be profiled.\n"; tool_prob_num = 0.0; } if (tool_verbosity > 0) { - printf("KokkosP: Probability for the sampler set to: %f\n", tool_prob_num); + std::cout << "KokkosP: Probability for the sampler set to: " << tool_prob_num << '\n'; } kernelSampleSkip = 1; return; @@ -241,25 +239,24 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, tool_prob_num = 100.0; kernelSampleSkip = atoi(tool_sample) + 1; if (tool_verbosity > 0) { - printf("KokkosP: Sampling rate set to: %s\n", tool_sample); + std::cout << "KokkosP: Sampling rate set to: " << tool_sample << '\n'; } return; } if (tool_verbosity > 0) { - printf( + std::cout << "KokkosP: Neither the probability " - "nor the skip rate for sampling were set...\n"); + "nor the skip rate for sampling were set...\n"; } tool_prob_num = 10.0; kernelSampleSkip = 1; if (tool_verbosity > 0) { - printf( + std::cout << "KokkosP: The probability " - "for the sampler is set to the default of %f percent. The skip rate " + "for the sampler is set to the default of " < 0) { - printf("KokkosP: sample %llu calling child-begin function...\n", - (unsigned long long)(*kID)); + std::cout << "KokkosP: sample " << *kID << " calling child-begin function...\n"; } if (NULL != beginForCallee) { if (tool_globFence) { @@ -286,8 +282,7 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, uint64_t nestedkID = 0; (*beginForCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { - printf("KokkosP: sample %llu finished with child-begin function.\n", - (unsigned long long)(*kID)); + std::cout << "KokkosP: sample " << *kID << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -300,8 +295,7 @@ if (NULL != endForCallee) { 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...\n"; } if (tool_globFence) { invoke_ktools_fence(0); @@ -320,8 +314,7 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, if ((invocationNum % kernelSampleSkip) == 0) { if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.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...\n"; } if (NULL != beginScanCallee) { uint64_t nestedkID = 0; @@ -330,8 +323,7 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, } (*beginScanCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { - printf("KokkosP: sample %llu finished with child-begin function.\n", - (unsigned long long)(*kID)); + std::cout << "KokkosP: sample " << *kID << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -344,8 +336,7 @@ 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...\n"; } if (tool_globFence) { invoke_ktools_fence(0); @@ -364,8 +355,7 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, if ((invocationNum % kernelSampleSkip) == 0) { if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.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...\n"; } if (NULL != beginReduceCallee) { uint64_t nestedkID = 0; @@ -374,8 +364,7 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, } (*beginReduceCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { - printf("KokkosP: sample %llu finished with child-begin function.\n", - (unsigned long long)(*kID)); + std::cout << "KokkosP: sample " << *kID << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -388,8 +377,7 @@ void kokkosp_end_parallel_reduce(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...\n"; } if (tool_globFence) { invoke_ktools_fence(0); diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 5fcd2371d..500c9834b 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.cpp @@ -25,8 +25,14 @@ struct Tester { }; static const std::vector matchers{ - "(.*)KokkosP: Execution of kernel 0 is completed(.*)", - "(.*)KokkosP: Execution of kernel 1 is completed(.*)"}; +"(.*)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. From c93d11c98c7793b9ed74bf97b8190944e5795807 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 26 Mar 2024 11:15:25 -0400 Subject: [PATCH 63/87] Revert changes to kp_kernel_logger.cpp --- debugging/kernel-logger/kp_kernel_logger.cpp | 82 ++++++++++++-------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/debugging/kernel-logger/kp_kernel_logger.cpp b/debugging/kernel-logger/kp_kernel_logger.cpp index 90d0bf69a..bf7f585bb 100644 --- a/debugging/kernel-logger/kp_kernel_logger.cpp +++ b/debugging/kernel-logger/kp_kernel_logger.cpp @@ -20,7 +20,6 @@ #include #include #include -#include std::vector regions; static uint64_t uniqID; @@ -29,10 +28,10 @@ struct SpaceHandle { }; void kokkosp_print_region_stack_indent(const int level) { - std::cout << "KokkosP: "; + printf("KokkosP: "); for (int i = 0; i < level; i++) { - std::cout << " "; + printf(" "); } } @@ -41,7 +40,7 @@ int kokkosp_print_region_stack() { for (auto regItr = regions.begin(); regItr != regions.end(); regItr++) { kokkosp_print_region_stack_indent(level); - std::cout << *regItr << '\n'; + printf("%s\n", (*regItr).c_str()); level++; } @@ -53,13 +52,15 @@ extern "C" void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const uint32_t /*devInfoCount*/, void* /*deviceInfo*/) { - std::cout << "KokkosP: Kernel Logger Library Initialized (sequence is " - << loadSeq << ", version: " << interfaceVer << ")\n"; + printf( + "KokkosP: Kernel Logger Library Initialized (sequence is %d, version: " + "%llu)\n", + loadSeq, (unsigned long long)(interfaceVer)); uniqID = 0; } extern "C" void kokkosp_finalize_library() { - std::cout << "KokkosP: Kokkos library finalization called.\n"; + printf("KokkosP: Kokkos library finalization called.\n"); } extern "C" void kokkosp_begin_parallel_for(const char* name, @@ -67,16 +68,20 @@ extern "C" void kokkosp_begin_parallel_for(const char* name, uint64_t* kID) { *kID = uniqID++; - std::cout << "KokkosP: Executing parallel-for kernel on device " << devID - << " with unique execution identifier " << *kID << '\n'; + printf( + "KokkosP: Executing parallel-for kernel on device %d with unique " + "execution identifier %llu\n", + devID, (unsigned long long)(*kID)); int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - std::cout << " " << name << '\n'; + + printf(" %s\n", name); } extern "C" void kokkosp_end_parallel_for(const uint64_t kID) { - std::cout << "KokkosP: Execution of kernel " << kID << " is completed.\n"; + printf("KokkosP: Execution of kernel %llu is completed.\n", + (unsigned long long)(kID)); } extern "C" void kokkosp_begin_parallel_scan(const char* name, @@ -84,17 +89,20 @@ extern "C" void kokkosp_begin_parallel_scan(const char* name, uint64_t* kID) { *kID = uniqID++; - std::cout << "KokkosP: Executing parallel-scan kernel on device " << devID - << " with unique execution identifier " << *kID << '\n'; + printf( + "KokkosP: Executing parallel-scan kernel on device %d with unique " + "execution identifier %llu\n", + devID, (unsigned long long)(*kID)); int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - std::cout << " " << name << '\n'; + printf(" %s\n", name); } extern "C" void kokkospk_end_parallel_scan(const uint64_t kID) { - std::cout << "KokkosP: Execution of kernel " << kID << " is completed.\n"; + printf("KokkosP: Execution of kernel %llu is completed.\n", + (unsigned long long)(kID)); } extern "C" void kokkosp_begin_parallel_reduce(const char* name, @@ -102,17 +110,20 @@ extern "C" void kokkosp_begin_parallel_reduce(const char* name, uint64_t* kID) { *kID = uniqID++; - std::cout << "KokkosP: Executing parallel-reduce kernel on device " << devID - << " with unique execution identifier " << *kID << '\n'; + printf( + "KokkosP: Executing parallel-reduce kernel on device %d with unique " + "execution identifier %llu\n", + devID, (unsigned long long)(*kID)); int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - std::cout << " " << name << '\n'; + printf(" %s\n", name); } extern "C" void kokkosp_end_parallel_reduce(const uint64_t kID) { - std::cout << "KokkosP: Execution of kernel " << kID << " is completed.\n"; + printf("KokkosP: Execution of kernel %llu is completed.\n", + (unsigned long long)(kID)); } extern "C" void kokkosp_begin_fence(const char* name, const uint32_t devID, @@ -128,13 +139,15 @@ extern "C" void kokkosp_begin_fence(const char* name, const uint32_t devID, } else { *kID = uniqID++; - std::cout << "KokkosP: Executing fence on device " << devID - << " with unique execution identifier " << kID << '\n'; + printf( + "KokkosP: Executing fence on device %d with unique execution " + "identifier %llu\n", + devID, (unsigned long long)(*kID)); int level = kokkosp_print_region_stack(); kokkosp_print_region_stack_indent(level); - std::cout << " " << name << '\n'; + printf(" %s\n", name); } } @@ -143,12 +156,13 @@ extern "C" void kokkosp_end_fence(const uint64_t kID) { // dealing with the application's fence, which we filtered out in the callback // for fences if (kID != std::numeric_limits::max()) { - std::cout << "KokkosP: Execution of fence %llu is completed.\n"; + printf("KokkosP: Execution of fence %llu is completed.\n", + (unsigned long long)(kID)); } } extern "C" void kokkosp_push_profile_region(char* regionName) { - std::cout << "KokkosP: Entering profiling region: " << regionName << '\n'; + printf("KokkosP: Entering profiling region: %s\n", regionName); std::string regionNameStr(regionName); regions.push_back(regionNameStr); @@ -156,22 +170,21 @@ extern "C" void kokkosp_push_profile_region(char* regionName) { extern "C" void kokkosp_pop_profile_region() { if (regions.size() > 0) { - std::cout << "KokkosP: Exiting profiling region: " << regions.back() - << '\n'; + printf("KokkosP: Exiting profiling region: %s\n", regions.back().c_str()); regions.pop_back(); } } extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char* name, void* ptr, uint64_t size) { - std::cout << "KokkosP: Allocate<" << handle.name << "> name: " << name - << " pointer: " << ptr << " size: " << size << '\n'; + printf("KokkosP: Allocate<%s> name: %s pointer: %p size: %llu\n", handle.name, + name, ptr, (unsigned long long)(size)); } extern "C" void kokkosp_deallocate_data(SpaceHandle handle, const char* name, void* ptr, uint64_t size) { - std::cout << "KokkosP: Deallocate<" << handle.name << "> name: " << name - << " pointer: " << ptr << " size: " << size << '\n'; + printf("KokkosP: Deallocate<%s> name: %s pointer: %p size: %llu\n", + handle.name, name, ptr, (unsigned long long)(size)); } extern "C" void kokkosp_begin_deep_copy(SpaceHandle dst_handle, @@ -180,8 +193,9 @@ extern "C" void kokkosp_begin_deep_copy(SpaceHandle dst_handle, SpaceHandle src_handle, const char* src_name, const void* src_ptr, uint64_t size) { - std::cout << "KokkosP: DeepCopy<" << dst_handle.name << ',' << src_handle.name - << "> DST(name: " << dst_name << " pointer: " << dst_ptr - << ") SRC(name: " << src_name << " pointer " << src_ptr - << ") Size: " << size << '\n'; + printf( + "KokkosP: DeepCopy<%s,%s> DST(name: %s pointer: %p) SRC(name: %s pointer " + "%p) Size: %llu\n", + dst_handle.name, src_handle.name, dst_name, dst_ptr, src_name, src_ptr, + (unsigned long long)(size)); } From 9d98e9e48f2c9cada61dad1dfb83480fbe25cf55 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:03:53 -0700 Subject: [PATCH 64/87] kp_sampler_skip.cpp: apply clang format --- common/kokkos-sampler/kp_sampler_skip.cpp | 169 ++++++++++++---------- 1 file changed, 90 insertions(+), 79 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 456131fde..14af45863 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -54,22 +54,20 @@ uint32_t getDeviceID(uint32_t devid_in) { void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { if (tool_verbosity > 1) { - std::cout << - "KokkosP: Sampler attempting to invoke" - " tool-induced fence on device " << - getDeviceID(devID) << '\n'; + std::cout << "KokkosP: Sampler attempting to invoke" + " tool-induced fence on device " + << getDeviceID(devID) << '\n'; } (*(tpi_funcs.fence))(devID); if (tool_verbosity > 1) { - std::cout << - "KokkosP: Sampler sucessfully invoked" - " tool-induced fence on device " << - getDeviceID(devID) << '\n'; + std::cout << "KokkosP: Sampler 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"; } } @@ -77,9 +75,9 @@ 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; } @@ -105,9 +103,9 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); if (NULL == profileLibrary) { - std::cout << - "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a deprecated " - "variable. Please use KOKKOS_TOOLS_LIBS\n"; + std::cout + << "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a deprecated " + "variable. Please use KOKKOS_TOOLS_LIBS\n"; profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); if (NULL == profileLibrary) { std::cout << "KokkosP: No library to call in " << profileLibrary << '\n'; @@ -127,7 +125,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, nextLibrary = strtok(NULL, ";"); if (NULL == nextLibrary) { - std::cout << "KokkosP: No child library to call in " << profileLibrary << '\n'; + std::cout << "KokkosP: No child library to call in " << profileLibrary + << '\n'; exit(-1); } else { if (tool_verbosity > 0) { @@ -138,7 +137,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, void* childLibrary = dlopen(nextLibrary, RTLD_NOW | RTLD_GLOBAL); if (NULL == childLibrary) { - std::cerr << "KokkosP: Error: Unable to load: " << nextLibrary << " (Error=" << dlerror() << ")\n"; + std::cerr << "KokkosP: Error: Unable to load: " << nextLibrary + << " (Error=" << dlerror() << ")\n"; exit(-1); } else { beginForCallee = @@ -167,18 +167,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'; } } } @@ -190,16 +190,16 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, if (0 > tool_seed) { srand(time(NULL)); if (tool_verbosity > 0) { - std::cout << - "KokkosP: Seeding random number generator using clock for " - "random sampling.\n"; + std::cout << "KokkosP: Seeding random number generator using clock for " + "random sampling.\n"; } } else { srand(tool_seed); if (tool_verbosity > 0) { - std::cout << - "KokkosP: Seeding random number generator using seed " << tool_seed << " for " - "random sampling.\n"; + std::cout << "KokkosP: Seeding random number generator using seed " + << tool_seed + << " for " + "random sampling.\n"; } } @@ -211,32 +211,34 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, // Connector reasons about probability as a double between 0.0 and 1.0. tool_prob_num = atof(tool_probability); if (tool_prob_num > 100.0) { - std::cout << - "KokkosP: The sampling probability value is set to be greater than " - "100.0. " - "The probability for the sampler will be set to 100 percent; all of " - "the " - "invocations of a Kokkos kernel will be profiled.\n"; + std::cout << "KokkosP: The sampling probability value is set to be " + "greater than " + "100.0. " + "The probability for the sampler will be set to 100 " + "percent; all of " + "the " + "invocations of a Kokkos kernel will be profiled.\n"; tool_prob_num = 100.0; } else if (tool_prob_num < 0.0) { - std::cout << - "KokkosP: The sampling probability value is set to be a negative " - "number. The " - "sampler's probability will be set to 0 percent; none of the " - "invocations of " - "a Kokkos kernel will be profiled.\n"; + std::cout + << "KokkosP: The sampling probability value is set to be a negative " + "number. The " + "sampler's probability will be set to 0 percent; none of the " + "invocations of " + "a Kokkos kernel will be profiled.\n"; tool_prob_num = 0.0; } if (tool_verbosity > 0) { - std::cout << "KokkosP: Probability for the sampler set to: " << tool_prob_num << '\n'; - } + std::cout << "KokkosP: Probability for the sampler set to: " + << tool_prob_num << '\n'; + } kernelSampleSkip = 1; return; } const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); if (NULL != tool_sample) { - tool_prob_num = 100.0; + tool_prob_num = 100.0; kernelSampleSkip = atoi(tool_sample) + 1; if (tool_verbosity > 0) { std::cout << "KokkosP: Sampling rate set to: " << tool_sample << '\n'; @@ -244,21 +246,21 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, return; } - if (tool_verbosity > 0) { - std::cout << - "KokkosP: Neither the probability " - "nor the skip rate for sampling were set...\n"; - } - tool_prob_num = 10.0; - kernelSampleSkip = 1; - if (tool_verbosity > 0) { - std::cout << - "KokkosP: The probability " - "for the sampler is set to the default of " < 0) { + std::cout << "KokkosP: Neither the probability " + "nor the skip rate for sampling were set...\n"; + } + tool_prob_num = 10.0; + kernelSampleSkip = 1; + if (tool_verbosity > 0) { + std::cout << "KokkosP: The probability " + "for the sampler is set to the default of " + << tool_prob_num + << " percent. The skip rate " + "for sampler" + "will not be used.\n"; + } + kernelSampleSkip = 1; } void kokkosp_finalize_library() { @@ -271,9 +273,10 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, static uint64_t invocationNum = 0; ++invocationNum; if ((invocationNum % kernelSampleSkip) == 0) { - if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.0)) { + if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.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 != beginForCallee) { if (tool_globFence) { @@ -282,7 +285,8 @@ 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 << " finished with child-begin function.\n"; + std::cout << "KokkosP: sample " << *kID + << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -291,11 +295,12 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, } void kokkosp_end_parallel_for(const uint64_t kID) { -if (NULL != endForCallee) { - if (!(infokIDSample.find(kID) == infokIDSample.end())) { + 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"; + std::cout << "KokkosP: sample " << kID + << " calling child-end function...\n"; } if (tool_globFence) { invoke_ktools_fence(0); @@ -314,7 +319,8 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID, if ((invocationNum % kernelSampleSkip) == 0) { if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.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; @@ -323,7 +329,8 @@ 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 << " finished with child-begin function.\n"; + std::cout << "KokkosP: sample " << *kID + << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -336,7 +343,8 @@ 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); @@ -355,7 +363,8 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, if ((invocationNum % kernelSampleSkip) == 0) { if ((rand() / (1.0 * RAND_MAX)) < (tool_prob_num / 100.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; @@ -364,7 +373,8 @@ 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 << " finished with child-begin function.\n"; + std::cout << "KokkosP: sample " << *kID + << " finished with child-begin function.\n"; } infokIDSample.insert({*kID, nestedkID}); } @@ -377,7 +387,8 @@ void kokkosp_end_parallel_reduce(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); From 828597d4e78503fed987627dda01ee79b7d8287b Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:08:52 -0700 Subject: [PATCH 65/87] test_randomized_sampling.cpp: apply clang format --- tests/sampler/test_randomized_sampling.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_randomized_sampling.cpp index 500c9834b..88c84fda7 100644 --- a/tests/sampler/test_randomized_sampling.cpp +++ b/tests/sampler/test_randomized_sampling.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 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.(.*)"}; + "(.*)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. From 7f0cd8a98c379b9258f2552d1f97e22c353271ef Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 26 Mar 2024 12:21:34 -0400 Subject: [PATCH 66/87] More indentation --- common/kokkos-sampler/kp_sampler_skip.cpp | 54 +++++++++-------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 14af45863..ba99f4707 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -54,20 +54,19 @@ uint32_t getDeviceID(uint32_t devid_in) { void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { if (tool_verbosity > 1) { - std::cout << "KokkosP: Sampler attempting to invoke" - " tool-induced fence on device " + std::cout << "KokkosP: Sampler attempting to invoke tool-induced fence " + "on device " << getDeviceID(devID) << '\n'; } (*(tpi_funcs.fence))(devID); if (tool_verbosity > 1) { - std::cout << "KokkosP: Sampler sucessfully invoked" - " tool-induced fence on device " + std::cout << "KokkosP: Sampler 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"; } } @@ -76,8 +75,7 @@ void kokkosp_provide_tool_programming_interface( if (!num_funcs) { if (tool_verbosity > 0) std::cout << "KokkosP: Note: Number of functions in Tools Programming " - "Interface " - "is 0!\n"; + "Interface is 0!\n"; } tpi_funcs = funcsFromTPI; } @@ -103,9 +101,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); if (NULL == profileLibrary) { - std::cout - << "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a deprecated " - "variable. Please use KOKKOS_TOOLS_LIBS\n"; + std::cout << "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a " + "deprecated variable. Please use KOKKOS_TOOLS_LIBS\n"; profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); if (NULL == profileLibrary) { std::cout << "KokkosP: No library to call in " << profileLibrary << '\n'; @@ -197,9 +194,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, srand(tool_seed); if (tool_verbosity > 0) { std::cout << "KokkosP: Seeding random number generator using seed " - << tool_seed - << " for " - "random sampling.\n"; + << tool_seed << " for random sampling.\n"; } } @@ -212,20 +207,15 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, tool_prob_num = atof(tool_probability); if (tool_prob_num > 100.0) { std::cout << "KokkosP: The sampling probability value is set to be " - "greater than " - "100.0. " - "The probability for the sampler will be set to 100 " - "percent; all of " - "the " - "invocations of a Kokkos kernel will be profiled.\n"; + "greater than 100.0. The probability for the sampler will " + "be set to 100 percent; all of the invocations of a Kokkos " + "kernel will be profiled.\n"; tool_prob_num = 100.0; } else if (tool_prob_num < 0.0) { std::cout << "KokkosP: The sampling probability value is set to be a negative " - "number. The " - "sampler's probability will be set to 0 percent; none of the " - "invocations of " - "a Kokkos kernel will be profiled.\n"; + "number. The sampler's probability will be set to 0 percent; none " + "of the invocations of a Kokkos kernel will be profiled.\n"; tool_prob_num = 0.0; } if (tool_verbosity > 0) { @@ -247,18 +237,16 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } if (tool_verbosity > 0) { - std::cout << "KokkosP: Neither the probability " - "nor the skip rate for sampling were set...\n"; + std::cout << "KokkosP: Neither the probability nor the skip rate for " + "sampling were set...\n"; } tool_prob_num = 10.0; kernelSampleSkip = 1; if (tool_verbosity > 0) { - std::cout << "KokkosP: The probability " - "for the sampler is set to the default of " - << tool_prob_num - << " percent. The skip rate " - "for sampler" - "will not be used.\n"; + std::cout + << "KokkosP: The probability for the sampler is set to the default of " + << tool_prob_num + << " percent. The skip rate for sampler will not be used.\n"; } kernelSampleSkip = 1; } From 2a376ca29abb695d69b58d0ff9d75fc2785cac89 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 1 Apr 2024 20:21:14 -0700 Subject: [PATCH 67/87] kp_sampler_skip.cpp: fix reduce callee null check --- common/kokkos-sampler/kp_sampler_skip.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index ba99f4707..2769d383b 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -371,7 +371,7 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID, } 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) { @@ -382,7 +382,7 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { invoke_ktools_fence(0); } - (*endScanCallee)(retrievedNestedkID); + (*endReduceCallee)(retrievedNestedkID); infokIDSample.erase(kID); } } From ce93309cd132c0e1d106fd7f2de15cb6547093dd Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:20:13 -0700 Subject: [PATCH 68/87] kp_kernel_logger.cpp: scan typo fix --- 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 0d8e79a28e2719df7a948514c12ba33f3df75328 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:21:18 -0700 Subject: [PATCH 69/87] Rename test_randomized_sampling.cpp to test_parfor.cpp --- tests/sampler/{test_randomized_sampling.cpp => test_parfor.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/sampler/{test_randomized_sampling.cpp => test_parfor.cpp} (100%) diff --git a/tests/sampler/test_randomized_sampling.cpp b/tests/sampler/test_parfor.cpp similarity index 100% rename from tests/sampler/test_randomized_sampling.cpp rename to tests/sampler/test_parfor.cpp From c16004ad2b5ee361c98d6a99ca54fb7344120e2d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:22:18 -0700 Subject: [PATCH 70/87] Update CMakeLists.txt: fix sampling --- tests/sampler/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index a756af4ff..9c60982ac 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,6 +1,6 @@ kp_add_executable_and_test( - TARGET_NAME test_sampler_randomizedsampling - SOURCE_FILE test_randomized_sampling.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 From 3178c8bde3740b02d3612bca120f8fe77d6e3d27 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:19:06 -0400 Subject: [PATCH 71/87] Prob smplr (#16) * CMakeLists.txt: add_library to kp_add_library Sampler's CMakeLists.txt: add_library to kp_add_library * kp_core.hpp: remove pointer from ptpi * kp_sampler_skip.cpp: pass by value kokkosp_p_t_p_i kp_sampler_skip.cpp: last parameter should be passed by value rather than pointer in kokkosp_p_t_p_i * kp_sampler_skip.cpp: remove dereference assignment for ptpi callback * kp_core.hpp: apply clang-format * Create test_sampler.cpp * CMakeLists.txt: set up test for sampler * test_sampler.cpp: put in code for sampler test * test_sampler.cpp: typo in comment (2 invocation --> 2 invocations) * CMakeLists.txt: support sampler test * kp_sampler_skip.cpp: change printf to std::out for ctests * kp_sampler_skip.cpp: include iostream for std::cout * Update kp_sampler_skip.cpp: \n instead of std::endl \n is faster for performance * kp_sampler_skip.cpp: apply clang format * kp_sampler_skip.cpp: fix for std::out of tool-invoked fence verbose debug print * kp_sampler_skip.cpp: apply clang format * Rename test_sampler.cpp to test_parfor.cpp * Update CMakeLists.txt: reduce and scan sampling tests * Create test_parreduce.cpp * Create test_parscan.cpp * 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 * 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 * Update test_parreduce.cpp: fix x[i] to x(i) View index access of x does not use [] * Update test_parreduce.cpp: Kokkos:: for View * test_parreduce.cpp: reduce lambda * Update test_parscan.cpp: operator for cuda/hip build * test_parscan.cpp: support scan test function * test_parreduce.cpp: reduction operator second argument second argument * test_parscan.cpp: fix scan test operator * Update test_parscan.cpp: fix scan test to have to Views * test_parscan.cpp: policy to size * 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. * test_parscan.cpp: apply clang format * test_parreduce.cpp: apply clang format * CMakeLists.txt: add_library -> kp_add_library * kp_sampler_skip.cpp: put in prob samplr * CMakeLists.txt: sampling prob test * Create test_parfor_prob.cpp * Create test_parreduce_prob.cpp * Create test_parscan_prob.cpp * test_parfor_prob.cpp: edit matchers for prob sampling * test_parreduce_prob.cpp: fix matchers * Update test_parscan_prob.cpp: fix parscan test matchers * Update test_parscan_prob.cpp: fix test comments * test_parfor_prob.cpp: fix comments * Update test_parreduce_prob.cpp: fix comments * test_parfor.cpp: update matcher * Update test_parscan.cpp: fix matchers * test_parreduce.cpp: matchers fix * Update kp_sampler_skip.cpp: add cout for end_parallel_xxx * Update test_parfor.cpp: put in finished with end in matchers * Update test_parscan.cpp: update matchers / comments removal * test_parreduce.cpp: fix matchers * Update kp_sampler_skip.cpp: fix elipses * test_parscan.cpp: apply clang format * CMakeLists.txt: skip rate is 0 * test_parscan.cpp: apply clang format * test_parfor_prob.cpp: apply clang format * Update README.md: add sampler entry * test_parreduce_prob.cpp: apply clang format * kp_sampler_skip.cpp: apply clang format * README.md: sampler README for probability * test_parreduce.cpp: fix int ref in operator * test_parscan.cpp: int ref in operator * test_parscan.cpp: long int in signature * test_parreduce.cpp: long int in second argument to operator * Update test_parreduce.cpp: change sum to int type * Update test_parreduce.cpp: declare sum as long int * Update kp_kernel_logger.cpp: kokkospk_end_parallel_scan --> kokkosp_end_parallel_scan * Update README.md Co-authored-by: Daniel Arndt * Update test_parfor.cpp * test_parfor.cpp: put in fence test * Update test_parfor.cpp: put in checks for number of calls and Null Ptr fence * test_parfor.cpp: apply clang format * fix test par for * test_parfor.cpp: apply clang format * kp_sampler_skip.cpp: fix sampler std::cout prints for test * test_parfor.cpp: apply clang format * test_parfor.cpp: fixing matcher string for number contains * Update test_parfor.cpp: not substr * test_parfor.cpp: apply clang format * kp_sampler_skip.cpp: apply clang format * test_parfor.cpp: apply clang format * test_parfor.cpp: apply clang format * Update test_parfor.cpp * test_parfor.cpp: apply clang format * test_parfor.cpp: Times function * delete file accidentally put in tests directory * Update test_parfor.cpp: remove AtMost * Update test_parfor.cpp: remove using AtMost * kp_sampler_skip.cpp: put back in * Update test_parreduce.cpp * test_parfor.cpp: remove count for number of times * Update test_parscan.cpp * Update test_parfor.cpp: removing Contains * kp_sampler_skip.cpp: apply clang format * test_parfor.cpp: apply clang format * test_parreduce.cpp: apply clang format * test_parscan.cpp: apply clang format * Update test_parfor.cpp: putting in times * test_parfor.cpp: apply clang format * Update test_parreduce.cpp: put in times * test_parscan.cpp: put in times test * test_parscan.cpp: apply clang format * test_parreduce.cpp: apply clang format * test_parscan.cpp: apply clang format * test_parscan.cpp: apply clang format * test_parreduce.cpp: apply clang format * test_parfor.cpp: apply clang format * test_parfor.cpp: apply clang format * test_parreduce.cpp: apply clang format * test_parscan.cpp: apply clang format * kp_sampler_skip.cpp: std::cout to std::cerr Co-authored-by: Daniel Arndt * test_parscan.cpp: fix declaration for variable result Co-authored-by: Damien L-G * test_parfor.cpp: revisions of tests PR review * test_parreduce.cpp: fix with new tests * test_parscan.cpp: fix sampler scan * test_parreduce.cpp: fix with correct samples and comments * CMakeLists.txt: fix sampler skip rate * test_parfor.cpp: add string header * test_parreduce.cpp: add string header * test_parscan.cpp: add string header * Update test_parfor.cpp: fix output * test_parreduce.cpp: fix test * test_parscan.cpp: fix occurrences variable * test_parfor.cpp: apply clang format * test_parreduce.cpp: apply clang format * test_parscan.cpp: apply clang format * test_parreduce.cpp: apply clang format * test_parfor.cpp: fix sampler number from 11 to 12 * test_parreduce.cpp: sample number from 11 to 12 * test_parscan.cpp: change sample from 11 to 12 * kp_sampler_skip.cpp: revert cerr to cout * CMakeLists.txt: make global fences 0 * CMakeLists.txt: remove setting of global fence environment variable * Put in tests for sampler (#248) * CMakeLists.txt: tests for prob sampling Without fence and with fence * parreduce.hpp: file for parallel reduce * Update parreduce.hpp: putting once pragma for header * parfor.hpp: header file for parfor * parfor.hpp: put in code for Kokkos parallel for test * Create parscan.hpp: parscan code file * parscan.hpp: put in code for scan * test_parreduce.cpp: deleting parreduce header * test_parscan.cpp: using header for parscan * test_parfor.cpp: parfor header * test_parfor_prob.cpp: header * test_parreduce_prob.cpp: putting in parreduce hpp * test_parscan_prob.cpp: fix includes * test_parreduce_prob.cpp: HasSubStr to HasSubstr * new MatchersProb based on random seed two from CI build test OpenMP * matchersProb.hpp: update * test_par*_prob.cpp: apply clang format * test_parfor.cpp: apply clang format * matchersProb.hpp: fix to matchers - apply clang format * matchersProb.hpp: fix to matchers semicolon apply clang format * matchersProb.hpp: fix to matchers semicolon apply clang format --------- Co-authored-by: Christian Trott Co-authored-by: Damien L-G Co-authored-by: Daniel Arndt Co-authored-by: Damien L-G --- README.md | 5 +- common/kokkos-sampler/README.md | 9 +-- common/kokkos-sampler/kp_sampler_skip.cpp | 15 ++++- matchersProb.hpp | 0 tests/CMakeLists.txt | 23 ++++++- tests/sampler/CMakeLists.txt | 81 ++++++++++++++++++++++- tests/sampler/matchersProb.hpp | 42 ++++++++++++ tests/sampler/matchersSkip.hpp | 11 +++ tests/sampler/parfor.hpp | 19 ++++++ tests/sampler/parreduce.hpp | 21 ++++++ tests/sampler/parscan.hpp | 21 ++++++ tests/sampler/test_parfor.cpp | 76 ++++++++++++--------- tests/sampler/test_parfor_prob.cpp | 72 ++++++++++++++++++++ tests/sampler/test_parreduce.cpp | 76 +++++++++++++++++++++ tests/sampler/test_parreduce_prob.cpp | 72 ++++++++++++++++++++ tests/sampler/test_parscan.cpp | 77 +++++++++++++++++++++ tests/sampler/test_parscan_prob.cpp | 72 ++++++++++++++++++++ 17 files changed, 652 insertions(+), 40 deletions(-) create mode 100644 matchersProb.hpp create mode 100644 tests/sampler/matchersProb.hpp create mode 100644 tests/sampler/matchersSkip.hpp create mode 100644 tests/sampler/parfor.hpp create mode 100644 tests/sampler/parreduce.hpp create mode 100644 tests/sampler/parscan.hpp create mode 100644 tests/sampler/test_parfor_prob.cpp create mode 100644 tests/sampler/test_parreduce.cpp create mode 100644 tests/sampler/test_parreduce_prob.cpp create mode 100644 tests/sampler/test_parscan.cpp create mode 100644 tests/sampler/test_parscan_prob.cpp diff --git a/README.md b/README.md index 73f1a902a..1d54302ba 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 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) diff --git a/common/kokkos-sampler/README.md b/common/kokkos-sampler/README.md index c8455ddeb..f150a80c2 100644 --- a/common/kokkos-sampler/README.md +++ b/common/kokkos-sampler/README.md @@ -1,9 +1,10 @@ This is a sampler utility that is intended to complement other tools in the Kokkos Tools set. This utility allows for sampling of profiling or debugging data collected from a particular tool of the Kokkos Tools set at each Kokkos kernel invocation. + To use this utility, a Kokkos Tools user provides a sampling probability by setting the environment variable `KOKKOS_TOOLS_SAMPLER_PROB` to a positive real number between 0.0 and 100.0. The user can alternatively set a sampling skip rate, i.e., the number of Kokkos kernel invocations to skip before the next sample is taken. The user does so by setting the environment variable `KOKKOS_TOOLS_SAMPLER_SKIP` to a non-negative integer. -If both sampling probability and sampling skip rate are set by the user, this sampling utility only uses the sampling probability for sampling; the utility sets the sampling skip rate to 1, incorporating no pre-defined periodicity in sampling. If neither sampling probability nor the sampling skip rate are set by the user, then purely random sampling is againdone, with the sampler's probability being 10.0 percent. The sampler is periodic only if the sampling probability is not set by the user _and_ the sampling skip rate is set by the user. -For the randomized sampling, the user can ensure reproducibility by setting `KOKKOS_TOOLS_RANDOM_SEED` to any integer. If this environment variable is not set, the seed is based on -the C time function. +If both sampling probability and sampling skip rate are set by the user, this sampling utility only uses the sampling probability for sampling; the utility sets the sampling skip rate to 1, incorporating no pre-defined periodicity in sampling. If neither sampling probability nor the sampling skip rate are set by the user, then purely random sampling is done, with the sampler's probability being 10.0 percent. The sampler is periodic only if the sampling probability is not set by the user and the sampling skip rate is set by the user. + +For the randomized sampling, the user can ensure reproducibility across multiple runs of a Kokkos application by setting `KOKKOS_TOOLS_RANDOM_SEED` to an integer value before all of the runs. If this environment variable is not set, the seed is based on the C time function. -For the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool.This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. +For the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool. This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 2769d383b..1a701c3ba 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -1,3 +1,4 @@ + #include #include #include @@ -248,6 +249,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, << tool_prob_num << " percent. The skip rate for sampler will not be used.\n"; } + kernelSampleSkip = 1; } @@ -294,6 +296,10 @@ void kokkosp_end_parallel_for(const uint64_t kID) { invoke_ktools_fence(0); } (*endForCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " finished with child-end function.\n"; + } infokIDSample.erase(kID); } } @@ -338,6 +344,10 @@ void kokkosp_end_parallel_scan(const uint64_t kID) { invoke_ktools_fence(0); } (*endScanCallee)(retrievedNestedkID); + if (tool_verbosity > 0) { + std::cout << "KokkosP: sample " << kID + << " finished with child-end function.\n"; + } infokIDSample.erase(kID); } } @@ -381,8 +391,11 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) { 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); } } diff --git a/matchersProb.hpp b/matchersProb.hpp new file mode 100644 index 000000000..e69de29bb diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7dfd75f69..6d2d1f5a5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,8 +10,11 @@ # 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. + 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}) + cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;KOKKOS_TOOLS_SAMPLER_VERBOSE;KOKKOS_TOOLS_GLOBALFENCES;KOKKOS_TOOLS_SAMPLER_SKIP;KOKKOS_TOOLS_SAMPLER_PROB;KOKKOS_TOOLS_RANDOM_SEED" "KOKKOS_TOOLS_LIBS" ${ARGN}) + if(NOT DEFINED kaeat_args_TARGET_NAME) message(FATAL_ERROR "'TARGET_NAME' is a required argument.") @@ -77,6 +80,24 @@ function(kp_add_executable_and_test) PROPERTY ENVIRONMENT "KOKKOS_TOOLS_SAMPLER_SKIP=${kaeat_args_KOKKOS_TOOLS_SAMPLER_SKIP}" ) + endif() + + if (DEFINED kaeat_args_KOKKOS_TOOLS_SAMPLER_PROB) + set_property( + TEST ${kaeat_args_TARGET_NAME} + APPEND + PROPERTY + ENVIRONMENT "KOKKOS_TOOLS_SAMPLER_PROB=${kaeat_args_KOKKOS_TOOLS_SAMPLER_PROB}" + ) + endif() + + if (DEFINED kaeat_args_KOKKOS_TOOLS_RANDOM_SEED) + set_property( + TEST ${kaeat_args_TARGET_NAME} + APPEND + PROPERTY + ENVIRONMENT "KOKKOS_TOOLS_RANDOM_SEED=${kaeat_args_KOKKOS_TOOLS_RANDOM_SEED}" + ) endif() diff --git a/tests/sampler/CMakeLists.txt b/tests/sampler/CMakeLists.txt index 9c60982ac..e9093b43f 100644 --- a/tests/sampler/CMakeLists.txt +++ b/tests/sampler/CMakeLists.txt @@ -1,8 +1,87 @@ + +## tests for skip rate 5, no fencing selected + kp_add_executable_and_test( 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_SAMPLER_SKIP 5 +) + +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 5 +) + +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 5 +) + +## tests for probability of 51.6% (with skip rate 0), no fencing selected + +kp_add_executable_and_test( + TARGET_NAME test_sampling_prob_parfor + SOURCE_FILE test_parfor_prob.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_RANDOM_SEED 2 + KOKKOS_TOOLS_SAMPLER_PROB 51.6 +) + +kp_add_executable_and_test( + TARGET_NAME test_sampling_prob_parscan + SOURCE_FILE test_parscan_prob.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_RANDOM_SEED 2 + KOKKOS_TOOLS_SAMPLER_PROB 51.6 +) + +kp_add_executable_and_test( + TARGET_NAME test_sampling_prob_parreduce + SOURCE_FILE test_parreduce_prob.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_RANDOM_SEED 2 + KOKKOS_TOOLS_SAMPLER_PROB 51.6 +) + +## tests for probability of 51.6% (with skip rate 0), with fences + +kp_add_executable_and_test( + TARGET_NAME test_sampling_prob_parfor_fence + SOURCE_FILE test_parfor_prob.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_RANDOM_SEED 2 + KOKKOS_TOOLS_SAMPLER_PROB 51.6 + KOKKOS_TOOLS_GLOBALFENCES 1 +) + +kp_add_executable_and_test( + TARGET_NAME test_sampling_prob_parscan_fence + SOURCE_FILE test_parscan_prob.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_RANDOM_SEED 2 + KOKKOS_TOOLS_SAMPLER_PROB 51.6 + KOKKOS_TOOLS_GLOBALFENCES 1 +) + +kp_add_executable_and_test( + TARGET_NAME test_sampling_prob_parreduce_fence + SOURCE_FILE test_parreduce_prob.cpp + KOKKOS_TOOLS_LIBS kp_kokkos_sampler kp_kernel_logger + KOKKOS_TOOLS_SAMPLER_VERBOSE 2 + KOKKOS_TOOLS_RANDOM_SEED 2 + KOKKOS_TOOLS_SAMPLER_PROB 51.6 KOKKOS_TOOLS_GLOBALFENCES 1 ) diff --git a/tests/sampler/matchersProb.hpp b/tests/sampler/matchersProb.hpp new file mode 100644 index 000000000..a6fb98f94 --- /dev/null +++ b/tests/sampler/matchersProb.hpp @@ -0,0 +1,42 @@ +#pragma once + +static const std::vector matchers{ + "KokkosP: sample 3 calling child-begin function...", + "KokkosP: sample 3 finished with child-begin function.", + "KokkosP: sample 3 calling child-end function...", + "KokkosP: sample 3 finished with child-end function.", + + "KokkosP: sample 4 calling child-begin function...", + "KokkosP: sample 4 finished with child-begin function.", + "KokkosP: sample 4 calling child-end function...", + "KokkosP: sample 4 finished with child-end function.", + + "KokkosP: sample 5 calling child-begin function...", + "KokkosP: sample 5 finished with child-begin function.", + "KokkosP: sample 5 calling child-end function...", + "KokkosP: sample 5 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 8 calling child-begin function...", + "KokkosP: sample 8 finished with child-begin function.", + "KokkosP: sample 8 calling child-end function...", + "KokkosP: sample 8 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.", + + "KokkosP: sample 13 calling child-begin function...", + "KokkosP: sample 13 finished with child-begin function.", + "KokkosP: sample 13 calling child-end function...", + "KokkosP: sample 13 finished with child-end function.", + + "KokkosP: sample 14 calling child-begin function...", + "KokkosP: sample 14 finished with child-begin function.", + "KokkosP: sample 14 calling child-end function...", + "KokkosP: sample 14 finished with child-end function."}; diff --git a/tests/sampler/matchersSkip.hpp b/tests/sampler/matchersSkip.hpp new file mode 100644 index 000000000..8a3f6887d --- /dev/null +++ b/tests/sampler/matchersSkip.hpp @@ -0,0 +1,11 @@ +#pragma once + +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 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."}; diff --git a/tests/sampler/parfor.hpp b/tests/sampler/parfor.hpp new file mode 100644 index 000000000..0f1649456 --- /dev/null +++ b/tests/sampler/parfor.hpp @@ -0,0 +1,19 @@ +#pragma once + +struct Tester { + template + explicit Tester(const execution_space& space) { + //! 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 < 15; iter++) { + Kokkos::parallel_for("named kernel", + Kokkos::RangePolicy(space, 0, 1), + *this); + } + } + + KOKKOS_FUNCTION void operator()(const int) const {} +}; diff --git a/tests/sampler/parreduce.hpp b/tests/sampler/parreduce.hpp new file mode 100644 index 000000000..2bc43a154 --- /dev/null +++ b/tests/sampler/parreduce.hpp @@ -0,0 +1,21 @@ +#pragma once + +struct Tester { + template + explicit Tester(const execution_space& space) { + //! 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 < 15; iter++) { + sum = 0; + Kokkos::parallel_reduce("named kernel reduce", + Kokkos::RangePolicy(space, 0, 1), + *this, sum); + } + } + + KOKKOS_FUNCTION void operator()(const int, long int&) const {} +}; diff --git a/tests/sampler/parscan.hpp b/tests/sampler/parscan.hpp new file mode 100644 index 000000000..082191edf --- /dev/null +++ b/tests/sampler/parscan.hpp @@ -0,0 +1,21 @@ +#pragma once + +struct Tester { + template + explicit Tester(const execution_space& space) { + //! 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 < 15; iter++) { + result = 0; + Kokkos::parallel_scan("named kernel scan", N, *this, result); + } + } + + KOKKOS_FUNCTION void operator()(const int, long int&, bool) const {} +}; diff --git a/tests/sampler/test_parfor.cpp b/tests/sampler/test_parfor.cpp index 88c84fda7..c30139600 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -1,3 +1,5 @@ + +#include #include #include #include @@ -6,40 +8,19 @@ #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 {} -}; +using ::testing::Contains; +using ::testing::HasSubstr; +using ::testing::Not; -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.(.*)"}; +#include "parfor.hpp" +#include "matchersSkip.hpp" /** * @test This test checks that the tool effectively samples. * - */ -TEST(SamplerTest, ktoEnvVarDefault) { + +TEST(SamplerSkipTest, parfor) { //! Initialize @c Kokkos. Kokkos::initialize(); @@ -55,12 +36,43 @@ 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: sample 1 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 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"))); + + int occurrences = 0; + 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 " + "sampler utility library to call"))); + + EXPECT_THAT(output.str(), + Not(HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); +} \ No newline at end of file diff --git a/tests/sampler/test_parfor_prob.cpp b/tests/sampler/test_parfor_prob.cpp new file mode 100644 index 000000000..7c43f3492 --- /dev/null +++ b/tests/sampler/test_parfor_prob.cpp @@ -0,0 +1,72 @@ + +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Kokkos_Core.hpp" + +using ::testing::Contains; +using ::testing::HasSubstr; +using ::testing::Not; + +#include "parfor.hpp" +#include "matchersProb.hpp" + +/** + * @test This test checks that the tool effectively samples. + * + */ + +TEST(SamplerProbTest, parfor) { + //! 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(), HasSubstr(matcher)); + } + + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 2 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 7 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 11 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); + + int occurrences = 0; + 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, 8); + + 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!"))); +} diff --git a/tests/sampler/test_parreduce.cpp b/tests/sampler/test_parreduce.cpp new file mode 100644 index 000000000..5d4dd7375 --- /dev/null +++ b/tests/sampler/test_parreduce.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Kokkos_Core.hpp" + +using ::testing::HasSubstr; +using ::testing::Not; + +#include "parreduce.hpp" +#include "matchersSkip.hpp" + +/* + * @test This test checks that the sampling utility properly samples. + * + */ +TEST(SamplerSkipTest, parfor) { + //! 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(), HasSubstr(matcher)); + } + + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 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 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"))); + + int occurrences = 0; + 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 " + "sampler utility library to call"))); + + EXPECT_THAT(output.str(), + Not(HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); +} diff --git a/tests/sampler/test_parreduce_prob.cpp b/tests/sampler/test_parreduce_prob.cpp new file mode 100644 index 000000000..0a0130d5d --- /dev/null +++ b/tests/sampler/test_parreduce_prob.cpp @@ -0,0 +1,72 @@ + +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Kokkos_Core.hpp" + +using ::testing::Contains; +using ::testing::HasSubstr; +using ::testing::Not; + +#include "parreduce.hpp" +#include "matchersProb.hpp" + +/** + * @test This test checks that the tool effectively samples. + * + */ + +TEST(SamplerProbTest, parreduce) { + //! 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(), HasSubstr(matcher)); + } + + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 2 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 7 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 11 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); + + int occurrences = 0; + 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, 8); + + 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!"))); +} diff --git a/tests/sampler/test_parscan.cpp b/tests/sampler/test_parscan.cpp new file mode 100644 index 000000000..d1d83b498 --- /dev/null +++ b/tests/sampler/test_parscan.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Kokkos_Core.hpp" + +using ::testing::HasSubstr; +using ::testing::Not; + +#include "parscan.hpp" +#include "matchersSkip.hpp" + +/** + * @test This test checks that the tool effectively samples. + * + + */ +TEST(SamplerSkipTest, parscan) { + //! 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(), HasSubstr(matcher)); + } + + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 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 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"))); + + int occurrences = 0; + 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 " + "sampler utility library to call"))); + + EXPECT_THAT(output.str(), + Not(HasSubstr("KokkosP: FATAL: Kokkos Tools Programming " + "Interface's tool-invoked Fence is NULL!"))); +} diff --git a/tests/sampler/test_parscan_prob.cpp b/tests/sampler/test_parscan_prob.cpp new file mode 100644 index 000000000..26e274f2c --- /dev/null +++ b/tests/sampler/test_parscan_prob.cpp @@ -0,0 +1,72 @@ + +#include +#include +#include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Kokkos_Core.hpp" + +using ::testing::Contains; +using ::testing::HasSubstr; +using ::testing::Not; + +#include "parscan.hpp" +#include "matchersProb.hpp" + +/** + * @test This test checks that the tool effectively samples. + * + */ + +TEST(SamplerProbTest, parscan) { + //! 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(), HasSubstr(matcher)); + } + + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 1 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 2 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 7 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 11 calling"))); + EXPECT_THAT(output.str(), Not(HasSubstr("KokkosP: sample 15 calling"))); + + int occurrences = 0; + 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, 8); + + 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 ca54d3534ec30f5f0b2b9c1e95711bedf6b75fbf Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:36:52 -0700 Subject: [PATCH 72/87] test_par*.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 aad12871c..98da58edb 100644 --- a/tests/sampler/test_parfor.cpp +++ b/tests/sampler/test_parfor.cpp @@ -20,7 +20,6 @@ using ::testing::Not; */ TEST(SamplerSkipTest, parfor) { - //! Initialize @c Kokkos. Kokkos::initialize(); From 75f9057523772dd0a67a0916f3a11a9aaeddac09 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:41:59 -0700 Subject: [PATCH 73/87] test_parreduce.cpp: change test tag; apply clang format --- 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 9acd5e6b3..fc9fdff3e 100644 --- a/tests/sampler/test_parreduce.cpp +++ b/tests/sampler/test_parreduce.cpp @@ -18,7 +18,7 @@ using ::testing::Not; * */ -TEST(SamplerSkipTest, parfor) { +TEST(SamplerSkipTest, parreduce) { //! Initialize @c Kokkos. Kokkos::initialize(); From 6f9cd82999aa25ff8acc4d219c0559ec8cb217df Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 2 May 2024 10:39:33 -0700 Subject: [PATCH 74/87] Delete matchersProb.hpp --- matchersProb.hpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 matchersProb.hpp diff --git a/matchersProb.hpp b/matchersProb.hpp deleted file mode 100644 index e69de29bb..000000000 From 39db70df7ea50b90a11a925932941146b216e3a2 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 2 May 2024 10:54:47 -0700 Subject: [PATCH 75/87] kp_sampler_skip.cpp: make function pointer correct --- common/kokkos-sampler/kp_sampler_skip.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index ff3cc291b..ce0cb4a9d 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -58,7 +58,7 @@ void invoke_ktools_fence(uint32_t devID) { "on device " << getDeviceID(devID) << '\n'; } - (*(tpi_funcs.fence))(devID); + (tpi_funcs.fence)(devID); if (tool_verbosity > 1) { std::cout << "KokkosP: Sampler sucessfully invoked tool-induced fence on " "device " @@ -418,4 +418,4 @@ 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" \ No newline at end of file +} // end extern "C" From 8d28cf630ebb620a2e68cc4bec117870623263dd Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 2 May 2024 11:01:38 -0700 Subject: [PATCH 76/87] kp_sampler_skip.cpp: invoke kokkos tools fence --- common/kokkos-sampler/kp_sampler_skip.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index ce0cb4a9d..e456195c9 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -53,20 +53,17 @@ uint32_t getDeviceID(uint32_t devid_in) { void invoke_ktools_fence(uint32_t devID) { if (tpi_funcs.fence != nullptr) { + tpi_funcs.fence(devID); if (tool_verbosity > 1) { - std::cout << "KokkosP: Sampler attempting to invoke tool-induced fence " - "on device " - << getDeviceID(devID) << '\n'; - } - (tpi_funcs.fence)(devID); - if (tool_verbosity > 1) { - std::cout << "KokkosP: Sampler 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::abort(); + exit(-1); } } From e28dccd68b08c1668b79b1508602ab8bf61f5bd2 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 11:16:21 -0700 Subject: [PATCH 77/87] kp_sampler_skip.cpp: Remove small changes not relating to this PR Fixing inconsistencies of diff with develop that shouldn't be there. These changes do not belong to this PR. They changes comprise primarily of minor changes with printed output. These unintended changes that I have taken out don't change any core logic or control flow in the program. --- common/kokkos-sampler/kp_sampler_skip.cpp | 33 ++++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index e456195c9..21e10bf94 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -38,7 +38,7 @@ static endFunction endReduceCallee = NULL; void kokkosp_request_tool_settings(const uint32_t, Kokkos_Tools_ToolSettings* settings) { - settings->requires_global_fencing = 0; + settings->requires_global_fencing = false; } // set of functions from Kokkos ToolProgrammingInterface (includes fence) @@ -102,7 +102,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, "deprecated variable. Please use KOKKOS_TOOLS_LIBS\n"; profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); if (NULL == profileLibrary) { - std::cout << "KokkosP: No library to call in " << profileLibrary << '\n'; + std::cout << "KokkosP: FATAL: No library to call in " << profileLibrary << "!\n"; exit(-1); } } @@ -119,20 +119,20 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, nextLibrary = strtok(NULL, ";"); if (NULL == nextLibrary) { - std::cout << "KokkosP: No child library to call in " << profileLibrary - << '\n'; + std::cout << "KokkosP: FATAL: No child 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 ..\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); if (NULL == childLibrary) { - std::cerr << "KokkosP: Error: Unable to load: " << nextLibrary - << " (Error=" << dlerror() << ")\n"; + fprintf(stderr, "KokkosP: Error: Unable to load: %s (Error=%s)\n", + nextLibrary, dlerror()); exit(-1); } else { beginForCallee = @@ -162,17 +162,17 @@ 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'; + << ((beginForCallee == NULL) ? "no" : "yes") << "\n"; std::cout << "KokkosP: begin-parallel-scan: " - << ((beginScanCallee == NULL) ? "no" : "yes") << '\n'; + << ((beginScanCallee == NULL) ? "no" : "yes") << "\n"; std::cout << "KokkosP: begin-parallel-reduce: " - << ((beginReduceCallee == NULL) ? "no" : "yes") << '\n'; + << ((beginReduceCallee == NULL) ? "no" : "yes") << "\n"; std::cout << "KokkosP: end-parallel-for: " - << ((endForCallee == NULL) ? "no" : "yes") << '\n'; + << ((endForCallee == NULL) ? "no" : "yes") << "\n"; std::cout << "KokkosP: end-parallel-scan: " - << ((endScanCallee == NULL) ? "no" : "yes") << '\n'; + << ((endScanCallee == NULL) ? "no" : "yes") << "\n"; std::cout << "KokkosP: end-parallel-reduce: " - << ((endReduceCallee == NULL) ? "no" : "yes") << '\n'; + << ((endReduceCallee == NULL) ? "no" : "yes") << "\n"; } } } @@ -228,7 +228,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, tool_prob_num = 100.0; kernelSampleSkip = atoi(tool_sample) + 1; if (tool_verbosity > 0) { - std::cout << "KokkosP: Sampling rate set to: " << tool_sample << '\n'; + std::cout << "KokkosP: Sampling rate set to: " << tool_sample << "\n"; } return; } @@ -264,10 +264,10 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, std::cout << "KokkosP: sample " << *kID << " calling child-begin function...\n"; } - if (NULL != beginForCallee) { if (tool_globFence) { invoke_ktools_fence(0); } + if (NULL != beginForCallee) { uint64_t nestedkID = 0; (*beginForCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { @@ -288,6 +288,7 @@ void kokkosp_end_parallel_for(const uint64_t kID) { std::cout << "KokkosP: sample " << kID << " calling child-end function...\n"; } + if (tool_globFence) { invoke_ktools_fence(0); } From 367ca7719dfd63944d9d699205f968d3a4df42fb Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 11:20:06 -0700 Subject: [PATCH 78/87] kp_sampler_skip.cpp: apply clang format --- common/kokkos-sampler/kp_sampler_skip.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 21e10bf94..59e9d8fad 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -102,7 +102,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, "deprecated 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); } } @@ -119,8 +120,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, nextLibrary = strtok(NULL, ";"); if (NULL == nextLibrary) { - std::cout << "KokkosP: FATAL: No child library to call in " << profileLibrary - << "!\n"; + std::cout << "KokkosP: FATAL: No child library to call in " + << profileLibrary << "!\n"; exit(-1); } else { if (tool_verbosity > 0) { @@ -264,10 +265,10 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, std::cout << "KokkosP: sample " << *kID << " calling child-begin function...\n"; } - if (tool_globFence) { - invoke_ktools_fence(0); - } - if (NULL != beginForCallee) { + if (tool_globFence) { + invoke_ktools_fence(0); + } + if (NULL != beginForCallee) { uint64_t nestedkID = 0; (*beginForCallee)(name, devID, &nestedkID); if (tool_verbosity > 0) { @@ -288,7 +289,7 @@ void kokkosp_end_parallel_for(const uint64_t kID) { std::cout << "KokkosP: sample " << kID << " calling child-end function...\n"; } - + if (tool_globFence) { invoke_ktools_fence(0); } From af97417dce81784ae323747cb39edbaf97cfd072 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 11:37:57 -0700 Subject: [PATCH 79/87] README.md: eliminate unintended changes in text to make diff more readable/auditable --- common/kokkos-sampler/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/kokkos-sampler/README.md b/common/kokkos-sampler/README.md index f150a80c2..7ab95fc6a 100644 --- a/common/kokkos-sampler/README.md +++ b/common/kokkos-sampler/README.md @@ -1,10 +1,11 @@ -This is a sampler utility that is intended to complement other tools in the Kokkos Tools set. This utility allows for sampling of profiling or debugging data collected from a particular tool of the Kokkos Tools set at each Kokkos kernel invocation. - +This is a sampler utility that is intended to complement other tools in the Kokkos Tools set. This utility allows for sampling (rather than collecting) of profiling or debugging data gathered from a particular tool of the Kokkos Tools set. To use this utility, a Kokkos Tools user provides a sampling probability by setting the environment variable `KOKKOS_TOOLS_SAMPLER_PROB` to a positive real number between 0.0 and 100.0. The user can alternatively set a sampling skip rate, i.e., the number of Kokkos kernel invocations to skip before the next sample is taken. The user does so by setting the environment variable `KOKKOS_TOOLS_SAMPLER_SKIP` to a non-negative integer. -If both sampling probability and sampling skip rate are set by the user, this sampling utility only uses the sampling probability for sampling; the utility sets the sampling skip rate to 1, incorporating no pre-defined periodicity in sampling. If neither sampling probability nor the sampling skip rate are set by the user, then purely random sampling is done, with the sampler's probability being 10.0 percent. The sampler is periodic only if the sampling probability is not set by the user and the sampling skip rate is set by the user. +If both sampling probability and sampling skip rate are set by the user, this sampling utility only uses the sampling probability for sampling; the utility sets the sampling skip rate to 1, incorporating no pre-defined periodicity in sampling. If neither sampling probability nor the sampling skip rate are set by the user, then randomized sampling is done, with the sampler's probability being 10.0 percent. The sampler is periodic only if the sampling probability is not set by the user and the sampling skip rate is set by the user. + +For randomized sampling, the user can ensure reproducibility of this tool's output across multiple runs of a Kokkos application by setting `KOKKOS_TOOLS_RANDOM_SEED` to an integer value before all of the runs. If this environment variable is not set, the seed is based on the C time function. -For the randomized sampling, the user can ensure reproducibility across multiple runs of a Kokkos application by setting `KOKKOS_TOOLS_RANDOM_SEED` to an integer value before all of the runs. If this environment variable is not set, the seed is based on the C time function. +In order for the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool. +This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. -For the state of the sampled profiling and logging data in memory to be captured at the time of the utility's callback invocation, it might be important to enforce fences. However, this also means that there are more synchronization points compared with running the program without the tool. This fencing behavior can be controlled by setting the environment variable `KOKKOS_TOOLS_GLOBALFENCES`. A non-zero value implies global fences on invocation of the tool. The default is not to introduce extra fences. From 4c48eb0daf7d47e789b732873e86494867fe54cb Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 11:40:37 -0700 Subject: [PATCH 80/87] CMakeLists.txt for test tools: comment in sampler prob environment variable should refer to that variable and not sampler skip --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2931a70bc..e433b92aa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,7 +11,7 @@ # 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_RANDOM_SEED : test environment receives the variable 'KOKKOS_TOOLS_RANDOM_SEED' that is set as the value for a seed of the random number generator (used for testing repeatability). # 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. -# KOKKOS_TOOLS_SAMPLER_PROB : test environment receives the variable 'KOKKOS_TOOLS_SAMPLER_SKIP' that is set as the probability that a Kokkos kernel invocation has a tooling activity invoked for it. +# KOKKOS_TOOLS_SAMPLER_PROB : test environment receives the variable 'KOKKOS_TOOLS_SAMPLER_PROB' that is set as the probability that a Kokkos kernel invocation has a tooling activity invoked for it. function(kp_add_executable_and_test) From bb538bb9a9edb2161e305bd99259e7f9396b6d5d Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 11:47:19 -0700 Subject: [PATCH 81/87] kp_sampler_skip.cpp: apply clang format --- common/kokkos-sampler/kp_sampler_skip.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 59e9d8fad..081442209 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -199,9 +199,9 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, const char* tool_probability = getenv("KOKKOS_TOOLS_SAMPLER_PROB"); if (NULL != tool_probability) { - // read sampling probability as a float between 0 and 100, representing + // Read sampling probability as a float between 0 and 100, representing // a percentage that data should be gathered. - // Connector reasons about probability as a double between 0.0 and 1.0. + // Utility reasons about probability as a double between 0.0 and 1.0. tool_prob_num = atof(tool_probability); if (tool_prob_num > 100.0) { std::cout << "KokkosP: The sampling probability value is set to be " @@ -218,7 +218,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } if (tool_verbosity > 0) { std::cout << "KokkosP: Probability for the sampler set to: " - << tool_prob_num << '\n'; + << tool_prob_num << "\n"; } kernelSampleSkip = 1; return; From b03c2c4bf498d014310ce2d4254c897de254fe90 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 15:20:12 -0700 Subject: [PATCH 82/87] kp_sampler_skip.cpp: make probability sampling the priority (as before) Fix from a previous suggestion from contributed commit - it may have been misunderstood that probability sampling is the priority here (I should have caught this). Co-authored-by: Christian Trott --- 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 081442209..0f985f742 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -225,7 +225,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); - if (NULL != tool_sample) { + if (NULL != tool_sample && tool_prob_num == -1.0) { tool_prob_num = 100.0; kernelSampleSkip = atoi(tool_sample) + 1; if (tool_verbosity > 0) { From d571b94c3b160132807614c630881286e66e8b7f Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 16:09:56 -0700 Subject: [PATCH 83/87] kp_sampler_skip.cpp: fix conditional as per review request I put comments to make clear the desired behavior. Note that the conditional shouldn't be needed. --- common/kokkos-sampler/kp_sampler_skip.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 0f985f742..17b07fab3 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -225,7 +225,10 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); - if (NULL != tool_sample && tool_prob_num == -1.0) { + if ((NULL != tool_sample) && (tool_prob_num == -1.0)) { + // If the user touched the sample skip rate variable + // and the tool probability is set to -1 (no probability sampling + // desired), then use only sampler skip rate. tool_prob_num = 100.0; kernelSampleSkip = atoi(tool_sample) + 1; if (tool_verbosity > 0) { @@ -233,7 +236,11 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } return; } - + + // If the tool probability is set to -1 (no probability sampling + // desired) and the user also didn't set + // skip rate, then use a default with a probability sampling of 10%. + if (tool_verbosity > 0) { std::cout << "KokkosP: Neither the probability nor the skip rate for " "sampling were set...\n"; @@ -245,10 +252,10 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, << "KokkosP: The probability for the sampler is set to the default of " << tool_prob_num << " percent. The skip rate for sampler will not be used.\n"; - } + } + +} // end kokkosp_init_library - kernelSampleSkip = 1; -} void kokkosp_finalize_library() { if (NULL != finalizeProfileLibrary) (*finalizeProfileLibrary)(); From a426547bf641887ef5c9d68c61fecb5d318f23c1 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Fri, 3 May 2024 16:11:59 -0700 Subject: [PATCH 84/87] kp_sampler_skip.cpp: putting back in conditional as requested --- common/kokkos-sampler/kp_sampler_skip.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 17b07fab3..a4843f292 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -237,10 +237,12 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, return; } + if (tool_prob_num == -1.0) + { // If the tool probability is set to -1 (no probability sampling // desired) and the user also didn't set // skip rate, then use a default with a probability sampling of 10%. - + if (tool_verbosity > 0) { std::cout << "KokkosP: Neither the probability nor the skip rate for " "sampling were set...\n"; @@ -253,7 +255,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, << tool_prob_num << " percent. The skip rate for sampler will not be used.\n"; } - + } } // end kokkosp_init_library From 199988338be3a7fda4d700363d9ae58900bea3cb Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Mon, 6 May 2024 08:57:32 -0700 Subject: [PATCH 85/87] kp_sampler_skip.cpp: apply clang-format --- common/kokkos-sampler/kp_sampler_skip.cpp | 42 +++++++++++------------ 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index a4843f292..9c4f8fb21 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -228,7 +228,7 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, if ((NULL != tool_sample) && (tool_prob_num == -1.0)) { // If the user touched the sample skip rate variable // and the tool probability is set to -1 (no probability sampling - // desired), then use only sampler skip rate. + // desired), then use only sampler skip rate. tool_prob_num = 100.0; kernelSampleSkip = atoi(tool_sample) + 1; if (tool_verbosity > 0) { @@ -236,28 +236,26 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, } return; } - - if (tool_prob_num == -1.0) - { - // If the tool probability is set to -1 (no probability sampling - // desired) and the user also didn't set - // skip rate, then use a default with a probability sampling of 10%. - - if (tool_verbosity > 0) { - std::cout << "KokkosP: Neither the probability nor the skip rate for " - "sampling were set...\n"; - } - tool_prob_num = 10.0; - kernelSampleSkip = 1; - if (tool_verbosity > 0) { - std::cout - << "KokkosP: The probability for the sampler is set to the default of " - << tool_prob_num - << " percent. The skip rate for sampler will not be used.\n"; - } - } -} // end kokkosp_init_library + if (tool_prob_num == -1.0) { + // If the tool probability is set to -1 (no probability sampling + // desired) and the user also didn't set + // skip rate, then use a default with a probability sampling of 10%. + + if (tool_verbosity > 0) { + std::cout << "KokkosP: Neither the probability nor the skip rate for " + "sampling were set...\n"; + } + tool_prob_num = 10.0; + kernelSampleSkip = 1; + if (tool_verbosity > 0) { + std::cout << "KokkosP: The probability for the sampler is set to the " + "default of " + << tool_prob_num + << " percent. The skip rate for sampler will not be used.\n"; + } + } +} // end kokkosp_init_library void kokkosp_finalize_library() { if (NULL != finalizeProfileLibrary) (*finalizeProfileLibrary)(); From 4cdf85d633f1a8dbe613e6e63a4a7a4a80065579 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 23 May 2024 10:18:36 -0700 Subject: [PATCH 86/87] kp_sampler_skip.cpp: take out returns from input processing --- common/kokkos-sampler/kp_sampler_skip.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index 9c4f8fb21..d2a335120 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -221,7 +221,6 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, << tool_prob_num << "\n"; } kernelSampleSkip = 1; - return; } const char* tool_sample = getenv("KOKKOS_TOOLS_SAMPLER_SKIP"); @@ -234,7 +233,6 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, if (tool_verbosity > 0) { std::cout << "KokkosP: Sampling rate set to: " << tool_sample << "\n"; } - return; } if (tool_prob_num == -1.0) { From 679ba482fae16bb814fe3d70c54ac68f95f5d3ac Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Thu, 23 May 2024 12:16:09 -0600 Subject: [PATCH 87/87] Fix clang-format --- common/kokkos-sampler/kp_sampler_skip.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/common/kokkos-sampler/kp_sampler_skip.cpp b/common/kokkos-sampler/kp_sampler_skip.cpp index cfdba5145..7c10ffcea 100644 --- a/common/kokkos-sampler/kp_sampler_skip.cpp +++ b/common/kokkos-sampler/kp_sampler_skip.cpp @@ -19,7 +19,6 @@ static int tool_verbosity = 0; static int tool_globFence = 0; static int tool_seed = -1; - // a hash table mapping kID to nestedkID static std::unordered_map infokIDSample;