From 14d391b30bfe5b30cc83a730c7624633e433aee5 Mon Sep 17 00:00:00 2001 From: Vivek Kale <11766050+vlkale@users.noreply.github.com> Date: Thu, 17 Aug 2023 18:04:42 -0700 Subject: [PATCH] Allow deprecated kp_kernel_filter Fix kp_kernel_filter to allow KOKKOS_TOOLS_LIBS environment variable --- common/kernel-filter/kp_kernel_filter.cpp | 24 ++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/common/kernel-filter/kp_kernel_filter.cpp b/common/kernel-filter/kp_kernel_filter.cpp index 30efeb36a..7b39aec8a 100644 --- a/common/kernel-filter/kp_kernel_filter.cpp +++ b/common/kernel-filter/kp_kernel_filter.cpp @@ -116,7 +116,6 @@ extern "C" void kokkosp_init_library(const int loadSeq, std::regex nextRegEx(lineBuffer, std::regex::optimize); kernelNames.push_back(nextRegEx); } - free(lineBuffer); } @@ -124,9 +123,21 @@ extern "C" void kokkosp_init_library(const int loadSeq, printf("KokkosP: Kernel Filtering is %s\n", (filterKernels ? "enabled" : "disabled")); + + if (filterKernels) { + char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS"); + // check deprecated environment variable. + if (NULL == profileLibrary) { + printf( + "Checking KOKKOS_PROFILE_LIBRARY. WARNING: This is a deprecated " + "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); + exit(-1); + } - if (filterKernels) { - char* profileLibrary = getenv("KOKKOS_PROFILE_LIBRARY"); char* envBuffer = (char*)malloc(sizeof(char) * (strlen(profileLibrary) + 1)); strcpy(envBuffer, profileLibrary); @@ -136,7 +147,7 @@ extern "C" void kokkosp_init_library(const int loadSeq, for (int i = 0; i < loadSeq; i++) { nextLibrary = strtok(NULL, ";"); } - + nextLibrary = strtok(NULL, ";"); if (NULL == nextLibrary) { @@ -157,19 +168,18 @@ extern "C" void kokkosp_init_library(const int loadSeq, (beginFunction)dlsym(childLibrary, "kokkosp_begin_parallel_scan"); beginReduceCallee = (beginFunction)dlsym( childLibrary, "kokkosp_begin_parallel_reduce"); - + endScanCallee = (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_scan"); endForCallee = (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_for"); endReduceCallee = (endFunction)dlsym(childLibrary, "kokkosp_end_parallel_reduce"); - initProfileLibrary = (initFunction)dlsym(childLibrary, "kokkosp_init_library"); finalizeProfileLibrary = (finalizeFunction)dlsym(childLibrary, "kokkosp_finalize_library"); - + if (NULL != initProfileLibrary) { (*initProfileLibrary)(loadSeq + 1, interfaceVer, devInfoCount, deviceInfo);