Skip to content

Commit

Permalink
All hail clang
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Siefert <[email protected]>
  • Loading branch information
csiefer2 committed Oct 16, 2024
1 parent 8358c9f commit 62a39a1
Showing 1 changed file with 66 additions and 65 deletions.
131 changes: 66 additions & 65 deletions debugging/kernel-logger/kp_kernel_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,61 +29,71 @@ 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
// 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";

if(eid.instance_id == int_for_synchronization_reason(SpecialSynchronizationCases::GlobalDeviceSynchronization))
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";

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))
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=false;
static bool initialized=false;
if(initialized)
static bool value = false;
static bool initialized = false;

if (initialized)
return value;
else {
const char* varVal = std::getenv("KOKKOS_PROFILE_SUPPRESS_COUNTS");
if(varVal) {
if (varVal) {
std::string v = std::string(varVal);
// default to false
if (v=="1" || v=="ON" || v=="on" || v=="TRUE" || v=="true" || v=="YES" || v=="yes")
value=true;
if (v == "1" || v == "ON" || v == "on" || v == "TRUE" || v == "true" ||
v == "YES" || v == "yes")
value = true;
else
value=false;
value = false;
}
initialized=true;
initialized = true;
return value;
}
}

}

void kokkosp_print_region_stack_indent(const int level) {
printf("KokkosP: ");
Expand Down Expand Up @@ -124,12 +134,10 @@ 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++;
int output=*kID;
if(suppressCounts())
output=0;


*kID = uniqID++;
int output = *kID;
if (suppressCounts()) output = 0;

printf(
"KokkosP: Executing parallel-for kernel on device %s with unique "
"execution identifier %llu\n",
Expand All @@ -142,21 +150,19 @@ 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;
int output = kID;
if (suppressCounts()) output = 0;
printf("KokkosP: Execution of kernel %llu is completed.\n",
(unsigned long long)output);
}

extern "C" void kokkosp_begin_parallel_scan(const char* name,
const uint32_t devID,
uint64_t* kID) {
*kID = uniqID++;
int output=*kID;
if(suppressCounts())
output=0;

*kID = uniqID++;
int output = *kID;
if (suppressCounts()) output = 0;

printf(
"KokkosP: Executing parallel-scan kernel on device %s with unique "
"execution identifier %llu\n",
Expand All @@ -169,20 +175,18 @@ 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;
int output = kID;
if (suppressCounts()) output = 0;
printf("KokkosP: Execution of kernel %llu is completed.\n",
(unsigned long long)(output));
}

extern "C" void kokkosp_begin_parallel_reduce(const char* name,
const uint32_t devID,
uint64_t* kID) {
*kID = uniqID++;
int output=*kID;
if(suppressCounts())
output=0;
*kID = uniqID++;
int output = *kID;
if (suppressCounts()) output = 0;

printf(
"KokkosP: Executing parallel-reduce kernel on device %s with unique "
Expand All @@ -196,9 +200,8 @@ 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;
int output = kID;
if (suppressCounts()) output = 0;

printf("KokkosP: Execution of kernel %llu is completed.\n",
(unsigned long long)(output));
Expand All @@ -217,10 +220,9 @@ extern "C" void kokkosp_begin_fence(const char* name, const uint32_t devID,
} else {
*kID = uniqID++;

int output=*kID;
if(suppressCounts())
output=0;

int output = *kID;
if (suppressCounts()) output = 0;

printf(
"KokkosP: Executing fence on device %s with unique execution "
"identifier %llu\n",
Expand All @@ -238,10 +240,9 @@ 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;

int output = kID;
if (suppressCounts()) output = 0;

printf("KokkosP: Execution of fence %llu is completed.\n",
(unsigned long long)(output));
}
Expand Down

0 comments on commit 62a39a1

Please sign in to comment.