Skip to content
Snippets Groups Projects
Select Git revision
  • d58227b9ab0c81d6c19d4108df2887ca8c21d35d
  • master default
  • update-cudawrappers
  • migrate-cmake
4 results

PerformanceCounter.cc

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PerformanceCounter.cc 4.55 KiB
    #include "Common/Config.h"
    
    #include "Common/OpenCL_Support.h"
    #include "Common/PerformanceCounter.h"
    
    #include <iomanip>
    #include <iostream>
    
    
    unsigned PerformanceCounter::nrCounters;
    
    
    PerformanceCounter::PerformanceCounter(const std::string &name, bool profiling)
    :
    #if defined MEASURE_POWER
      totalJoules(0),
    #endif
      totalNrOperations(0),
      totalNrBytesRead(0),
      totalNrBytesWritten(0),
      totalTime(0),
      totalEvents(0),
      name(name),
      profiling(profiling)
    {
    //#pragma omp atomic
      counterNumber = nrCounters ++;
    }
    
    
    PerformanceCounter::~PerformanceCounter() noexcept(false)
    {
      if (totalTime > 0)
    #pragma omp critical (cout)
      {
        std::cout << std::setw(12) << name
    	      << std::setprecision(3)
    	      << ": " << totalTime / totalEvents * 1e3 << " ms";
    
        if (totalNrOperations != 0)
          std::cout << ", " << totalNrOperations / totalTime * 1e-12 << " TFLOPS";
    
        if (totalNrBytesRead != 0 || totalNrBytesWritten != 0)
          std::cout << ", " << totalNrBytesRead / totalTime * 1e-9 << '+'
    		<< totalNrBytesWritten / totalTime * 1e-9 << '='
    		<< (totalNrBytesRead + totalNrBytesWritten) / totalTime * 1e-9 << " GB/s (R+W)";
    
    #if defined MEASURE_POWER
        if (totalNrOperations > 0)
          std::cout << ", " << totalJoules / totalTime << " W"
    		", " << totalNrOperations / totalJoules * 1e-9 << " GFLOPS/W";
    #endif
    
        std::cout << std::endl;
      }
    }
    
    
    void PerformanceCounter::eventCompleteCallBack(cl_event ev, cl_int /*status*/, void *counter)
    {
    #if 0
      try {
        clRetainEvent(ev); // otherwise event.~Event() will destroy object
        cl::Event event(ev);
    
        cl_ulong queued = event.getProfilingInfo<CL_PROFILING_COMMAND_QUEUED>();
        cl_ulong submitted = event.getProfilingInfo<CL_PROFILING_COMMAND_SUBMIT>();
        cl_ulong start = event.getProfilingInfo<CL_PROFILING_COMMAND_START>();
        cl_ulong stop = event.getProfilingInfo<CL_PROFILING_COMMAND_END>();
        double seconds = (stop - start) / 1e9;