diff --git a/profiling/simple-kernel-timer/kp_json_writer.cpp b/profiling/simple-kernel-timer/kp_json_writer.cpp index 9ea5e8940..b552218c0 100644 --- a/profiling/simple-kernel-timer/kp_json_writer.cpp +++ b/profiling/simple-kernel-timer/kp_json_writer.cpp @@ -54,19 +54,6 @@ inline void write_json(std::ostream& os, KernelPerformanceInfo const& kp, os << indent << '}'; } -int find_index(std::vector& kernels, - const char* kernelName) { - for (unsigned int i = 0; i < kernels.size(); i++) { - KernelPerformanceInfo* nextKernel = kernels[i]; - - if (strcmp(nextKernel->getName(), kernelName) == 0) { - return i; - } - } - - return -1; -} - int main(int argc, char* argv[]) { if (argc == 1) { fprintf(stderr, "Did you specify any data files on the command line!\n"); diff --git a/profiling/simple-kernel-timer/kp_kernel_info.h b/profiling/simple-kernel-timer/kp_kernel_info.h index 93b7871eb..a95f07b17 100644 --- a/profiling/simple-kernel-timer/kp_kernel_info.h +++ b/profiling/simple-kernel-timer/kp_kernel_info.h @@ -65,9 +65,6 @@ class KernelPerformanceInfo { : kType(kernelType) { kernelName = (char*)malloc(sizeof(char) * (kName.size() + 1)); strcpy(kernelName, kName.c_str()); - - callCount = 0; - time = 0; } ~KernelPerformanceInfo() { free(kernelName); } @@ -200,11 +197,10 @@ class KernelPerformanceInfo { fprintf(output, "%s\"time-per-call\" : %16.8f,\n", indentBuffer, (time / static_cast( std::max(static_cast(1), callCount)))); - fprintf( - output, "%s\"kernel-type\" : \"%s\"\n", indentBuffer, - (kType == PARALLEL_FOR) - ? "PARALLEL-FOR" - : (kType == PARALLEL_REDUCE) ? "PARALLEL-REDUCE" : "PARALLEL-SCAN"); + fprintf(output, "%s\"kernel-type\" : \"%s\"\n", indentBuffer, + (kType == PARALLEL_FOR) ? "PARALLEL-FOR" + : (kType == PARALLEL_REDUCE) ? "PARALLEL-REDUCE" + : "PARALLEL-SCAN"); fprintf(output, "%s}", indent); } @@ -218,13 +214,13 @@ class KernelPerformanceInfo { char* kernelName; // const char* regionName; - uint64_t callCount; - double time; - double timeSq; - double startTime; + uint64_t callCount = 0; + double time = 0; + double timeSq = 0; + double startTime = 0; KernelExecutionType kType; }; } // namespace KokkosTools::KernelTimer -#endif +#endif \ No newline at end of file diff --git a/profiling/simple-kernel-timer/kp_reader.cpp b/profiling/simple-kernel-timer/kp_reader.cpp index 094c0a8f1..45493445f 100644 --- a/profiling/simple-kernel-timer/kp_reader.cpp +++ b/profiling/simple-kernel-timer/kp_reader.cpp @@ -25,19 +25,6 @@ using namespace KokkosTools::KernelTimer; -int find_index(std::vector& kernels, - const char* kernelName) { - for (unsigned int i = 0; i < kernels.size(); i++) { - KernelPerformanceInfo* nextKernel = kernels[i]; - - if (strcmp(nextKernel->getName(), kernelName) == 0) { - return i; - } - } - - return -1; -} - int main(int argc, char* argv[]) { if (argc == 1) { fprintf(stderr, "Did you specify any data files on the command line!\n"); diff --git a/profiling/simple-kernel-timer/kp_shared.h b/profiling/simple-kernel-timer/kp_shared.h index f719f5b20..b8921d3ca 100644 --- a/profiling/simple-kernel-timer/kp_shared.h +++ b/profiling/simple-kernel-timer/kp_shared.h @@ -17,8 +17,11 @@ #ifndef _H_KOKKOSP_KERNEL_SHARED #define _H_KOKKOSP_KERNEL_SHARED +#include #include #include +#include + #include "kp_kernel_info.h" namespace KokkosTools::KernelTimer { @@ -39,6 +42,15 @@ inline bool compareKernelPerformanceInfo(KernelPerformanceInfo* left, return left->getTime() > right->getTime(); }; +inline int find_index(std::vector& kernels, + const char* kernelName) { + const auto it = + std::find_if(kernels.begin(), kernels.end(), [&](const auto& kernel) { + return strcmp(kernel->getName(), kernelName) == 0; + }); + return it == kernels.cend() ? -1 : std::distance(kernels.begin(), it); +} + } // namespace KokkosTools::KernelTimer #endif // _H_KOKKOSP_KERNEL_SHARED