Files
rocm-systems/rocclr/runtime/device/gpu/gpucounters.cpp
T

82 rader
1.9 KiB
C++
Normal vy Historik

2014-07-04 16:17:05 -04:00
//
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
//
#include "device/gpu/gpudefs.hpp"
#include "device/gpu/gpucounters.hpp"
#include "device/gpu/gpuvirtual.hpp"
#include "query/PerformanceQueryObject.h"
2014-07-04 16:17:05 -04:00
namespace gpu {
CalCounterReference::~CalCounterReference() {
// The counter object is always associated with a particular queue,
// so we have to lock just this queue
amd::ScopedLock lock(gpu_.execution());
2014-07-04 16:17:05 -04:00
if (0 != counter_) {
gpu().cs()->destroyQuery(gslCounter());
}
2014-07-04 16:17:05 -04:00
}
bool CalCounterReference::growResultArray(uint index) {
if (results_ != NULL) {
delete[] results_;
}
results_ = new uint64_t[index + 1];
if (results_ == NULL) {
return false;
}
return true;
2014-07-04 16:17:05 -04:00
}
PerfCounter::~PerfCounter() {
if (calRef_ == NULL) {
return;
}
2014-07-04 16:17:05 -04:00
// Release the counter reference object
calRef_->release();
2014-07-04 16:17:05 -04:00
}
bool PerfCounter::create(CalCounterReference* calRef) {
assert(&gpu() == &calRef->gpu());
2014-07-04 16:17:05 -04:00
calRef_ = calRef;
counter_ = calRef->gslCounter();
index_ = calRef->retain() - 2;
calRef->growResultArray(index_);
2014-07-04 16:17:05 -04:00
// Initialize the counter
gslCounter()->getAsPerformanceQueryObject()->setCounterState(
info()->blockIndex_, info()->counterIndex_, info()->eventIndex_);
2014-07-04 16:17:05 -04:00
return true;
2014-07-04 16:17:05 -04:00
}
uint64_t PerfCounter::getInfo(uint64_t infoType) const {
switch (infoType) {
2014-07-04 16:17:05 -04:00
case CL_PERFCOUNTER_GPU_BLOCK_INDEX: {
// Return the GPU block index
return info()->blockIndex_;
2014-07-04 16:17:05 -04:00
}
case CL_PERFCOUNTER_GPU_COUNTER_INDEX: {
// Return the GPU counter index
return info()->counterIndex_;
2014-07-04 16:17:05 -04:00
}
case CL_PERFCOUNTER_GPU_EVENT_INDEX: {
// Return the GPU event index
return info()->eventIndex_;
2014-07-04 16:17:05 -04:00
}
case CL_PERFCOUNTER_DATA: {
gslCounter()->GetResult(gpu().cs(), reinterpret_cast<uint64*>(calRef_->results()));
return calRef_->results()[index_];
2014-07-04 16:17:05 -04:00
}
default:
LogError("Wrong PerfCounter::getInfo parameter");
}
return 0;
2014-07-04 16:17:05 -04:00
}
} // namespace gpu