Skip to content

Commit

Permalink
Allow deprecated kp_kernel_filter
Browse files Browse the repository at this point in the history
Fix kp_kernel_filter to allow KOKKOS_TOOLS_LIBS environment variable
  • Loading branch information
vlkale authored Aug 18, 2023
1 parent 62f2918 commit 14d391b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions common/kernel-filter/kp_kernel_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,28 @@ extern "C" void kokkosp_init_library(const int loadSeq,
std::regex nextRegEx(lineBuffer, std::regex::optimize);
kernelNames.push_back(nextRegEx);
}

free(lineBuffer);
}

filterKernels = (kernelNames.size() > 0);

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);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 14d391b

Please sign in to comment.