-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernel logger upgrades for better output and better code comparisons #276
base: develop
Are you sure you want to change the base?
Changes from all commits
aecdb82
8358c9f
62a39a1
21d6359
5f15867
520f74f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,75 @@ | |
#include <vector> | ||
#include <string> | ||
#include <limits> | ||
#include <climits> | ||
#include <cstring> | ||
#include "impl/Kokkos_Profiling_Interface.hpp" | ||
|
||
std::vector<std::string> regions; | ||
static uint64_t uniqID; | ||
struct SpaceHandle { | ||
char name[64]; | ||
}; | ||
|
||
// Get a useful label from the deviceId | ||
// NOTE: Relevant code is in: | ||
// kokkos/core/src/impl/Kokkos_Profiling_Interface.hpp | ||
std::string deviceIdToString(const uint32_t deviceId) { | ||
using namespace Kokkos::Tools::Experimental; | ||
std::string device_label("("); | ||
ExecutionSpaceIdentifier eid = identifier_from_devid(deviceId); | ||
if (eid.type == DeviceType::Serial) | ||
device_label += "Serial"; | ||
else if (eid.type == DeviceType::OpenMP) | ||
device_label += "OpenMP"; | ||
else if (eid.type == DeviceType::Cuda) | ||
device_label += "Cuda"; | ||
else if (eid.type == DeviceType::HIP) | ||
device_label += "HIP"; | ||
else if (eid.type == DeviceType::OpenMPTarget) | ||
device_label += "OpenMPTarget"; | ||
else if (eid.type == DeviceType::HPX) | ||
device_label += "HPX"; | ||
else if (eid.type == DeviceType::Threads) | ||
device_label += "Threads"; | ||
else if (eid.type == DeviceType::SYCL) | ||
device_label += "SYCL"; | ||
else if (eid.type == DeviceType::OpenACC) | ||
device_label += "OpenACC"; | ||
else if (eid.type == DeviceType::Unknown) | ||
device_label += "Unknown"; | ||
else | ||
device_label += "Unknown to KokkosTools"; | ||
Comment on lines
+39
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't be opposed to pushing this part (or even the whole function) to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concur. I also have to maintain this function in Trilinos, so I would love to put it in Kokkos_Profiling_Interface.hpp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If @crtrott doesn't object, I'll open a Kokkos PR with that. |
||
|
||
if (eid.instance_id == | ||
int_for_synchronization_reason( | ||
SpecialSynchronizationCases::GlobalDeviceSynchronization)) | ||
device_label += " All Instances)"; | ||
else if (eid.instance_id == | ||
int_for_synchronization_reason( | ||
SpecialSynchronizationCases::DeepCopyResourceSynchronization)) | ||
device_label += " DeepCopyResource)"; | ||
else | ||
device_label += " Instance " + std::to_string(eid.instance_id) + ")"; | ||
|
||
return device_label; | ||
} | ||
|
||
bool suppressCounts() { | ||
static bool value = [](){ | ||
const char* varVal = std::getenv("KOKKOS_TOOLS_LOGGER_SUPPRESS_COUNTS"); | ||
csiefer2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (varVal) { | ||
std::string v = std::string(varVal); | ||
// default to false | ||
if (v == "1" || v == "ON" || v == "on" || v == "TRUE" || v == "true" || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the time, it seems that this repo wants either 0 or 1 for the value of an environment variable. Then use I think it is important that all environment variables follow consistent conventions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @romintomasetti This is a Tpetra-ism to allow it to take anything reasonable as an option. If @vlkale or @crtrott doesn't like it that's fine, but we've found the flexibility to be useful in Trilinos |
||
v == "YES" || v == "yes") | ||
return true; | ||
} | ||
return false; | ||
}(); | ||
return value; | ||
} | ||
|
||
void kokkosp_print_region_stack_indent(const int level) { | ||
printf("KokkosP: "); | ||
|
||
|
@@ -66,12 +127,14 @@ extern "C" void kokkosp_finalize_library() { | |
extern "C" void kokkosp_begin_parallel_for(const char* name, | ||
const uint32_t devID, | ||
uint64_t* kID) { | ||
*kID = uniqID++; | ||
*kID = uniqID++; | ||
int output = *kID; | ||
if (suppressCounts()) output = 0; | ||
|
||
printf( | ||
"KokkosP: Executing parallel-for kernel on device %d with unique " | ||
"KokkosP: Executing parallel-for kernel on device %s with unique " | ||
"execution identifier %llu\n", | ||
devID, (unsigned long long)(*kID)); | ||
deviceIdToString(devID).c_str(), (unsigned long long)(output)); | ||
|
||
int level = kokkosp_print_region_stack(); | ||
kokkosp_print_region_stack_indent(level); | ||
|
@@ -80,19 +143,26 @@ extern "C" void kokkosp_begin_parallel_for(const char* name, | |
} | ||
|
||
extern "C" void kokkosp_end_parallel_for(const uint64_t kID) { | ||
int output = kID; | ||
if (suppressCounts()) output = 0; | ||
printf("KokkosP: Execution of kernel %llu is completed.\n", | ||
(unsigned long long)(kID)); | ||
(unsigned long long)output); | ||
} | ||
|
||
extern "C" void kokkosp_begin_parallel_scan(const char* name, | ||
const uint32_t devID, | ||
uint64_t* kID) { | ||
*kID = uniqID++; | ||
*kID = uniqID++; | ||
int output = *kID; | ||
if (suppressCounts()) output = 0; | ||
|
||
printf( | ||
"KokkosP: Executing parallel-scan kernel on device %d with unique " | ||
"KokkosP: Executing parallel-scan kernel on device %s with unique " | ||
"execution identifier %llu\n", | ||
devID, (unsigned long long)(*kID)); | ||
printf( | ||
"KokkosP: Executing parallel-scan kernel on device %d (%s) with unique " | ||
"execution identifier %llu\n", | ||
devID, deviceIdToString(devID).c_str(), (unsigned long long)(output)); | ||
|
||
int level = kokkosp_print_region_stack(); | ||
kokkosp_print_region_stack_indent(level); | ||
|
@@ -101,19 +171,23 @@ extern "C" void kokkosp_begin_parallel_scan(const char* name, | |
} | ||
|
||
extern "C" void kokkosp_end_parallel_scan(const uint64_t kID) { | ||
int output = kID; | ||
if (suppressCounts()) output = 0; | ||
printf("KokkosP: Execution of kernel %llu is completed.\n", | ||
(unsigned long long)(kID)); | ||
(unsigned long long)(output)); | ||
} | ||
|
||
extern "C" void kokkosp_begin_parallel_reduce(const char* name, | ||
const uint32_t devID, | ||
uint64_t* kID) { | ||
*kID = uniqID++; | ||
*kID = uniqID++; | ||
int output = *kID; | ||
if (suppressCounts()) output = 0; | ||
|
||
printf( | ||
"KokkosP: Executing parallel-reduce kernel on device %d with unique " | ||
"KokkosP: Executing parallel-reduce kernel on device %s with unique " | ||
"execution identifier %llu\n", | ||
devID, (unsigned long long)(*kID)); | ||
deviceIdToString(devID).c_str(), (unsigned long long)(output)); | ||
|
||
int level = kokkosp_print_region_stack(); | ||
kokkosp_print_region_stack_indent(level); | ||
|
@@ -122,8 +196,11 @@ extern "C" void kokkosp_begin_parallel_reduce(const char* name, | |
} | ||
|
||
extern "C" void kokkosp_end_parallel_reduce(const uint64_t kID) { | ||
int output = kID; | ||
if (suppressCounts()) output = 0; | ||
|
||
printf("KokkosP: Execution of kernel %llu is completed.\n", | ||
(unsigned long long)(kID)); | ||
(unsigned long long)(output)); | ||
} | ||
|
||
extern "C" void kokkosp_begin_fence(const char* name, const uint32_t devID, | ||
|
@@ -139,10 +216,13 @@ extern "C" void kokkosp_begin_fence(const char* name, const uint32_t devID, | |
} else { | ||
*kID = uniqID++; | ||
|
||
int output = *kID; | ||
if (suppressCounts()) output = 0; | ||
|
||
printf( | ||
"KokkosP: Executing fence on device %d with unique execution " | ||
"KokkosP: Executing fence on device %s with unique execution " | ||
"identifier %llu\n", | ||
devID, (unsigned long long)(*kID)); | ||
deviceIdToString(devID).c_str(), (unsigned long long)(output)); | ||
|
||
int level = kokkosp_print_region_stack(); | ||
kokkosp_print_region_stack_indent(level); | ||
|
@@ -156,8 +236,11 @@ 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<uint64_t>::max()) { | ||
int output = kID; | ||
if (suppressCounts()) output = 0; | ||
|
||
printf("KokkosP: Execution of fence %llu is completed.\n", | ||
(unsigned long long)(kID)); | ||
(unsigned long long)(output)); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a switch case.