Skip to content

Commit

Permalink
Remove macro definition from Makefile as suggested by @mhoemmen
Browse files Browse the repository at this point in the history
- check for __GXX_ABI_VERSION.
- create demangleName C-like function
- report this changes to simple-kernel-timer-json
  • Loading branch information
delpinux committed Jul 9, 2018
1 parent 79df648 commit ac39ee9
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*~
*.so
/src/tools/simple-kernel-timer/kp_reader
54 changes: 38 additions & 16 deletions src/tools/simple-kernel-timer-json/kp_kernel_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@
#include <sys/time.h>
#include <cstring>

#if defined(__GXX_ABI_VERSION)
#define HAVE_GCC_ABI_DEMANGLE
#endif

#if defined(HAVE_GCC_ABI_DEMANGLE)
#include <cxxabi.h>
#endif // HAVE_GCC_ABI_DEMANGLE

char* demangleName(char* kernelName)
{
#if defined(HAVE_GCC_ABI_DEMANGLE)
int status = -1;
char* demangledKernelName = abi::__cxa_demangle(kernelName, NULL, NULL, &status);
if (status==0) {
free(kernelName);
kernelName = demangledKernelName;
}
#endif // HAVE_GCC_ABI_DEMANGLE
return kernelName;
}

double seconds() {
struct timeval now;
Expand All @@ -25,7 +44,7 @@ class KernelPerformanceInfo {
public:
KernelPerformanceInfo(std::string kName, KernelExecutionType kernelType) :
kType(kernelType) {

kernelName = (char*) malloc(sizeof(char) * (kName.size() + 1));
regionName = "";
strcpy(kernelName, kName.c_str());
Expand Down Expand Up @@ -76,11 +95,11 @@ class KernelPerformanceInfo {
char* getName() {
return kernelName;
}

void addCallCount(const uint64_t newCalls) {
callCount += newCalls;
}

bool readFromFile(FILE* input) {
uint32_t recordLen = 0;
uint32_t actual_read = fread(&recordLen, sizeof(recordLen), 1, input);
Expand All @@ -93,58 +112,61 @@ class KernelPerformanceInfo {
uint32_t kernelNameLength;
copy((char*) &kernelNameLength, &entry[nextIndex], sizeof(kernelNameLength));
nextIndex += sizeof(kernelNameLength);

if(strlen(kernelName) > 0) {
free(kernelName);
}

kernelName = (char*) malloc( sizeof(char) * (kernelNameLength + 1));
copy(kernelName, &entry[nextIndex], kernelNameLength);
kernelName[kernelNameLength] = '\0';

kernelName = demangleName(kernelName);

nextIndex += kernelNameLength;

copy((char*) &callCount, &entry[nextIndex], sizeof(callCount));
nextIndex += sizeof(callCount);

copy((char*) &time, &entry[nextIndex], sizeof(time));
nextIndex += sizeof(time);

copy((char*) &timeSq, &entry[nextIndex], sizeof(timeSq));
nextIndex += sizeof(timeSq);

uint32_t kernelT = 0;
copy((char*) &kernelT, &entry[nextIndex], sizeof(kernelT));
nextIndex += sizeof(kernelT);

if(kernelT == 0) {
kType = PARALLEL_FOR;
} else if(kernelT == 1) {
kType = PARALLEL_REDUCE;
} else if(kernelT == 2) {
kType = PARALLEL_SCAN;
}

free(entry);
return true;
}

void writeToFile(FILE* output, char* indent) {
fprintf(output, "%s{\n", indent);

char* indentBuffer = (char*) malloc( sizeof(char) * 256 );
sprintf(indentBuffer, "%s ", indent);

fprintf(output, "%s\"kernel-name\" : \"%s\",\n", indentBuffer, kernelName);
fprintf(output, "%s\"region\" : \"%s\",\n", indentBuffer, regionName);
fprintf(output, "%s\"call-count\" : %lu,\n", indentBuffer, callCount);
fprintf(output, "%s\"total-time\" : %f,\n", indentBuffer, time);
fprintf(output, "%s\"time-per-call\" : %16.8f,\n", indentBuffer, (time /
fprintf(output, "%s\"time-per-call\" : %16.8f,\n", indentBuffer, (time /
static_cast<double>(std::max(
static_cast<uint64_t>(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}", indent);
}

Expand All @@ -154,7 +176,7 @@ class KernelPerformanceInfo {
dest[i] = src[i];
}
}

char* kernelName;
char* regionName;
uint64_t callCount;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/simple-kernel-timer-json/kp_kernel_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <algorithm>
#include <string>
#include <sys/time.h>
#include <cxxabi.h>

#include <unistd.h>
#include "kp_kernel_info.h"

Expand Down
2 changes: 0 additions & 2 deletions src/tools/simple-kernel-timer/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
CXX=g++
CXXFLAGS=-O3 -std=c++11 -g
SHARED_CXXFLAGS=-shared -fPIC
# comment the following line if abi::__cxa_demangle is not supported by your compiler
CXXFLAGS+= -DHAVE_GCC_ABI_DEMANGLE

all: kp_kernel_timer.so kp_reader

Expand Down
34 changes: 23 additions & 11 deletions src/tools/simple-kernel-timer/kp_kernel_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@
#include <stdio.h>
#include <sys/time.h>
#include <cstring>

#if defined(__GXX_ABI_VERSION)
#define HAVE_GCC_ABI_DEMANGLE
#endif

#if defined(HAVE_GCC_ABI_DEMANGLE)
#include <cxxabi.h>
#endif
#endif // HAVE_GCC_ABI_DEMANGLE

char* demangleName(char* kernelName)
{
#if defined(HAVE_GCC_ABI_DEMANGLE)
int status = -1;
char* demangledKernelName = abi::__cxa_demangle(kernelName, NULL, NULL, &status);
if (status==0) {
free(kernelName);
kernelName = demangledKernelName;
}
#endif // HAVE_GCC_ABI_DEMANGLE
return kernelName;
}

double seconds() {
struct timeval now;
gettimeofday(&now, NULL);
Expand Down Expand Up @@ -101,16 +120,9 @@ class KernelPerformanceInfo {
kernelName = (char*) malloc( sizeof(char) * (kernelNameLength + 1));
copy(kernelName, &entry[nextIndex], kernelNameLength);
kernelName[kernelNameLength] = '\0';
#if defined(HAVE_GCC_ABI_DEMANGLE)
{
int status = -1;
char* demangledKernelName = abi::__cxa_demangle(kernelName, NULL, NULL, &status);
if (status==0) {
free(kernelName);
kernelName = demangledKernelName;
}
}
#endif // HAVE_GCC_ABI_DEMANGLE

kernelName = demangleName(kernelName);

nextIndex += kernelNameLength;

copy((char*) &callCount, &entry[nextIndex], sizeof(callCount));
Expand Down
13 changes: 6 additions & 7 deletions src/tools/simple-kernel-timer/kp_kernel_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <algorithm>
#include <string>
#include <sys/time.h>
#include <cxxabi.h>

#include <unistd.h>
#include "kp_kernel_info.h"

Expand Down Expand Up @@ -80,13 +80,13 @@ extern "C" void kokkosp_init_library(const int loadSeq,
extern "C" void kokkosp_finalize_library() {
double finishTime = seconds();
double kernelTimes = 0;

char* hostname = (char*) malloc(sizeof(char) * 256);
gethostname(hostname, 256);

char* fileOutput = (char*) malloc(sizeof(char) * 256);
sprintf(fileOutput, "%s-%d.dat", hostname, (int) getpid());

free(hostname);
FILE* output_data = fopen(fileOutput, "wb");

Expand Down Expand Up @@ -214,8 +214,8 @@ extern "C" void kokkosp_finalize_library() {
if(NULL != outputDelimiter) {
free(outputDelimiter);
}*/


}

extern "C" void kokkosp_begin_parallel_for(const char* name, const uint32_t devID, uint64_t* kID) {
Expand Down Expand Up @@ -271,4 +271,3 @@ extern "C" void kokkosp_pop_profile_region() {
current_region_level--;
regions[current_region_level]->addFromTimer();
}

0 comments on commit ac39ee9

Please sign in to comment.