2020-02-04 09:26:14 -08:00
|
|
|
/* Copyright (c) 2008-present Advanced Micro Devices, Inc.
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE. */
|
2014-07-04 16:17:05 -04:00
|
|
|
|
|
|
|
|
#include "device/gpu/gpudefs.hpp"
|
|
|
|
|
#include "device/gpu/gpucounters.hpp"
|
|
|
|
|
#include "device/gpu/gpuvirtual.hpp"
|
2015-08-25 13:22:29 -04:00
|
|
|
#include "query/PerformanceQueryObject.h"
|
2014-07-04 16:17:05 -04:00
|
|
|
|
|
|
|
|
namespace gpu {
|
|
|
|
|
|
|
|
|
|
CalCounterReference::~CalCounterReference() {
|
2017-04-13 13:56:38 -04:00
|
|
|
// 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
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
if (0 != counter_) {
|
|
|
|
|
gpu().cs()->destroyQuery(gslCounter());
|
|
|
|
|
}
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -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
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
PerfCounter::~PerfCounter() {
|
|
|
|
|
if (calRef_ == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
// Release the counter reference object
|
|
|
|
|
calRef_->release();
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
bool PerfCounter::create(CalCounterReference* calRef) {
|
|
|
|
|
assert(&gpu() == &calRef->gpu());
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
calRef_ = calRef;
|
|
|
|
|
counter_ = calRef->gslCounter();
|
|
|
|
|
index_ = calRef->retain() - 2;
|
|
|
|
|
calRef->growResultArray(index_);
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
// Initialize the counter
|
|
|
|
|
gslCounter()->getAsPerformanceQueryObject()->setCounterState(
|
|
|
|
|
info()->blockIndex_, info()->counterIndex_, info()->eventIndex_);
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
return true;
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -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: {
|
2017-04-13 13:56:38 -04:00
|
|
|
// Return the GPU block index
|
|
|
|
|
return info()->blockIndex_;
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
case CL_PERFCOUNTER_GPU_COUNTER_INDEX: {
|
2017-04-13 13:56:38 -04:00
|
|
|
// Return the GPU counter index
|
|
|
|
|
return info()->counterIndex_;
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
case CL_PERFCOUNTER_GPU_EVENT_INDEX: {
|
2017-04-13 13:56:38 -04:00
|
|
|
// Return the GPU event index
|
|
|
|
|
return info()->eventIndex_;
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
case CL_PERFCOUNTER_DATA: {
|
2017-04-13 13:56:38 -04:00
|
|
|
gslCounter()->GetResult(gpu().cs(), reinterpret_cast<uint64*>(calRef_->results()));
|
|
|
|
|
return calRef_->results()[index_];
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
default:
|
2017-04-13 13:56:38 -04:00
|
|
|
LogError("Wrong PerfCounter::getInfo parameter");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
} // namespace gpu
|