Skip to content

Commit

Permalink
[FEATURE] Use counter to control count process
Browse files Browse the repository at this point in the history
We implement startProfiling, stopProfiling and printValues for counter
class. Now the count process can be like:

----create counter----
counter counter();
counter.setxxx();
----start profiling----
counter.startProfiling();

====Running Kernel====

----stop profiling----
counter.stopProfiling();

Signed-off-by: YushuoEdge <[email protected]>
  • Loading branch information
YushuoEdge committed Mar 30, 2022
1 parent 62a8343 commit 174c9e4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
8 changes: 5 additions & 3 deletions src/amanda/profiler/counter/autorange_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ bool setupProfiling(std::vector<uint8_t>& configImage,
return true;
}

void startProfiling(counterControler* controler)
void counter::startProfiling()
{
CUpti_ProfilerRange profilerRange = CUPTI_AutoRange;
counterControler* controler = this->getControler();

DRIVER_API_CALL(cuInit(0));
validateProfilerEnvironment(controler->deviceNum);
Expand Down Expand Up @@ -236,7 +237,7 @@ void startProfiling(counterControler* controler)
}
}

void stopProfiling()
void counter::stopProfiling()
{
CUpti_Profiler_DisableProfiling_Params disableProfilingParams = {CUpti_Profiler_DisableProfiling_Params_STRUCT_SIZE};
CUpti_Profiler_UnsetConfig_Params unsetConfigParams = {CUpti_Profiler_UnsetConfig_Params_STRUCT_SIZE};
Expand All @@ -251,8 +252,9 @@ void stopProfiling()
DRIVER_API_CALL(cuCtxDestroy(cuContext));
}

void printValues(counterControler *controler)
void counter::printValues()
{
counterControler* controler = this->getControler();
/* Evaluation of metrics collected in counterDataImage, this can also be done offline*/
NV::Metric::Eval::PrintMetricValues(controler->chipName, controler->counterDataImage, controler->metricNames);
}
17 changes: 9 additions & 8 deletions src/amanda/profiler/counter/autorange_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void cleanUp(int *h_A, int *h_B, int *h_C, int *h_D, int *d_A, int *d_B,
if (h_D)
free(h_D);}

bool runTest(counterControler *controler)
bool runTest(int deviceNum, std::vector<std::string> metricNames)
{

int N = 1024*1024*1024/4/3;
Expand Down Expand Up @@ -74,18 +74,22 @@ bool runTest(counterControler *controler)
cudaMemcpy(d_A, h_A, size, cudaMemcpyHostToDevice);
cudaMemcpy(d_B, h_B, size, cudaMemcpyHostToDevice);

// create a counter and set the parameters
counter counter(0);
counter.setCountParams(deviceNum, metricNames);

// start profiling...
startProfiling(controler);
counter.startProfiling();
std::cout << "start profiling ..." << std::endl;

callVecAdd(d_A, d_B, d_C, N);
callVecSub(d_A, d_B, d_D, N);


// stop profiling
stopProfiling();
counter.stopProfiling();
std::cout << "stop profiling ..." << std::endl;
printValues(controler);
counter.printValues();


// Copy result from device memory to host memory
Expand Down Expand Up @@ -137,10 +141,7 @@ int main(int argc, char* argv[])
metricNames.push_back(METRIC_NAME);
}

counterControler controler;
controler.deviceNum = deviceNum;
controler.metricNames = metricNames;
if(!runTest(&controler))
if(!runTest(deviceNum, metricNames))
{
std::cout << "Failed to run sample" << std::endl;
exit(-1);
Expand Down
4 changes: 4 additions & 0 deletions src/amanda/profiler/counter/counter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "counter.h"

counterControler* counter::getControler() {
return &this->controler;
}

counter::counter() {
this->filePath = "metrics_record.txt";
this->kindFlag = 0;
Expand Down
19 changes: 7 additions & 12 deletions src/amanda/profiler/counter/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
typedef struct counterControler
{
// Parameters needed to be set before profiling
int deviceNum;
int deviceNum = 0;
std::vector<std::string> metricNames;

// Profiling values
Expand Down Expand Up @@ -41,11 +41,11 @@ class counter {

counterControler controler;
Counter::count_Mode countMode;
void setMetrics(unsigned long flag);
counterControler* getControler();

public:
std::vector<Counter::countData_t> countData;
void setMetrics(unsigned long flag);

counter();
counter(std::string);
counter(unsigned long kindFlag);
Expand All @@ -63,12 +63,7 @@ class counter {
void setCountParams(int deviceNum, std::vector<std::string> metricsNames);

void clearData();
// void startProfiling();
// void stopProfiling();
// void printValues();
};

void startProfiling(counterControler *controler);
void stopProfiling();

void printValues(counterControler *controler);
void startProfiling();
void stopProfiling();
void printValues();
};

0 comments on commit 174c9e4

Please sign in to comment.