standalone/sampling mode
Change-Id: I24c358bfebacb5678fb3d31f2f94ae867a1c9ac9
[ROCm/rocprofiler commit: b481bfe5de]
This commit is contained in:
@@ -22,97 +22,25 @@ THE SOFTWARE.
|
||||
|
||||
#include <hsa.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "ctrl/run_kernel.h"
|
||||
#include "ctrl/test_aql.h"
|
||||
#include "ctrl/test_hsa.h"
|
||||
#include "inc/rocprofiler.h"
|
||||
#include "dummy_kernel/dummy_kernel.h"
|
||||
#include "simple_convolution/simple_convolution.h"
|
||||
#include "util/test_assert.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
bool ret_val = false;
|
||||
// HSA status
|
||||
hsa_status_t status = HSA_STATUS_ERROR;
|
||||
// Profiling context
|
||||
rocprofiler_t* context = NULL;
|
||||
// Profiling properties
|
||||
rocprofiler_properties_t properties;
|
||||
// Number of context invocation
|
||||
uint32_t invocation = 0;
|
||||
|
||||
#if 0
|
||||
// Profiling info objects
|
||||
const unsigned info_count = 1;
|
||||
rocprofiler_info_t info[info_count];
|
||||
// PMC events
|
||||
memset(info, 0, sizeof(info));
|
||||
info[0].type = ROCPROFILER_TYPE_METRIC;
|
||||
info[0].name = "SQ_WAVES";
|
||||
#else
|
||||
// Profiling info objects
|
||||
const unsigned info_count = 3;
|
||||
rocprofiler_info_t info[info_count];
|
||||
// PMC events
|
||||
memset(info, 0, sizeof(info));
|
||||
info[0].type = ROCPROFILER_TYPE_METRIC;
|
||||
info[0].name = "SQ_WAVES";
|
||||
info[1].type = ROCPROFILER_TYPE_METRIC;
|
||||
info[1].name = "SQ_ITEMS";
|
||||
// Tracing parameters
|
||||
const unsigned parameter_count = 2;
|
||||
rocprofiler_parameter_t parameters[parameter_count];
|
||||
info[2].name = "THREAD_TRACE";
|
||||
info[2].type = ROCPROFILER_TYPE_TRACE;
|
||||
info[2].parameters = parameters;
|
||||
info[2].parameter_count = parameter_count;
|
||||
parameters[0].parameter_name = HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_MASK;
|
||||
parameters[0].value = 0;
|
||||
parameters[1].parameter_name = HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_TOKEN_MASK;
|
||||
parameters[1].value = 0;
|
||||
#endif
|
||||
|
||||
// Creating profiling context
|
||||
properties = {};
|
||||
properties.queue_depth = 128;
|
||||
status = rocprofiler_open(TestHsa::HsaAgentId(), info, info_count, &context,
|
||||
ROCPROFILER_MODE_STANDALONE | ROCPROFILER_MODE_OWNQUEUE, &properties);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
|
||||
TestHsa::SetQueue(properties.queue);
|
||||
|
||||
// Adding dispatch observer
|
||||
status = rocprofiler_dispatch_observer(rocprofiler_dispatch_callback, context);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
|
||||
// Querying the number of context invocation
|
||||
status = rocprofiler_invocation(context, &invocation);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
|
||||
// Dispatching profiled kernel n-times to collect all counter groups data
|
||||
unsigned n = 0;
|
||||
while (1) {
|
||||
std::cout << "> " << n << "/" << invocation << std::endl;
|
||||
#if 0
|
||||
status = rocprofiler_start(context);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
ret_val = RunKernel<SimpleConvolution, TestAql>(argc, argv);
|
||||
status = rocprofiler_stop(context);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
#else
|
||||
ret_val = RunKernel<SimpleConvolution, TestAql>(argc, argv);
|
||||
#endif
|
||||
status = rocprofiler_sample(context);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
|
||||
for (rocprofiler_info_t* p = info; p < info + info_count; ++p) {
|
||||
std::cout << (p - info) << ": " << p->name;
|
||||
void print_features(rocprofiler_feature_t* feature, uint32_t feature_count) {
|
||||
for (rocprofiler_feature_t* p = feature; p < feature + feature_count; ++p) {
|
||||
std::cout << (p - feature) << ": " << p->name;
|
||||
switch (p->data.kind) {
|
||||
case ROCPROFILER_DATA_KIND_INT64:
|
||||
std::cout << std::dec << " result64 (" << p->data.result64 << ")" << std::endl;
|
||||
std::cout << std::dec << " result64 (" << p->data.result_int64 << ")" << std::endl;
|
||||
break;
|
||||
case ROCPROFILER_BYTES: {
|
||||
case ROCPROFILER_DATA_KIND_BYTES: {
|
||||
const char* ptr = reinterpret_cast<const char*>(p->data.result_bytes.ptr);
|
||||
uint64_t size = 0;
|
||||
for (unsigned i = 0; i < p->data.result_bytes.instance_count; ++i) {
|
||||
@@ -130,15 +58,119 @@ int main(int argc, char** argv) {
|
||||
TEST_ASSERT(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++n;
|
||||
if (n < invocation) {
|
||||
status = rocprofiler_next(context);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
void read_features(uint32_t n, rocprofiler_t* context, rocprofiler_feature_t* feature, const unsigned feature_count) {
|
||||
std::cout << "read features" << std::endl;
|
||||
hsa_status_t status = rocprofiler_read(context, n);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
std::cout << "read issue" << std::endl;
|
||||
status = rocprofiler_get_data(context, n);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
status = rocprofiler_get_metrics(context);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
print_features(feature, feature_count);
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool ret_val = false;
|
||||
// HSA status
|
||||
hsa_status_t status = HSA_STATUS_ERROR;
|
||||
// Profiling context
|
||||
rocprofiler_t* context = NULL;
|
||||
// Profiling properties
|
||||
rocprofiler_properties_t properties;
|
||||
|
||||
// Profiling feature objects
|
||||
const unsigned feature_count = 9;
|
||||
rocprofiler_feature_t feature[feature_count];
|
||||
// PMC events
|
||||
memset(feature, 0, sizeof(feature));
|
||||
feature[0].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[0].name = "GRBM_COUNT";
|
||||
feature[1].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[1].name = "GRBM_GUI_ACTIVE";
|
||||
feature[2].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[2].name = "GPUBusy";
|
||||
feature[3].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[3].name = "SQ_WAVES";
|
||||
feature[4].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[4].name = "SQ_INSTS_VALU";
|
||||
feature[5].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[5].name = "VALUInsts";
|
||||
feature[6].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[6].name = "TCC_HIT_sum";
|
||||
feature[7].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[7].name = "TCC_MISS_sum";
|
||||
feature[8].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
feature[8].name = "WRITE_SIZE";
|
||||
// feature[8].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
// feature[8].name = "TCC_EA_WRREQ_sum";
|
||||
// feature[9].kind = ROCPROFILER_FEATURE_KIND_METRIC;
|
||||
// feature[9].name = "TCC_EA_WRREQ_64B_sum";
|
||||
#if 0
|
||||
// Tracing parameters
|
||||
const unsigned parameter_count = 2;
|
||||
rocprofiler_parameter_t parameters[parameter_count];
|
||||
feature[2].name = "THREAD_TRACE";
|
||||
feature[2].kind = ROCPROFILER_FEATURE_KIND_TRACE;
|
||||
feature[2].parameters = parameters;
|
||||
feature[2].parameter_count = parameter_count;
|
||||
parameters[0].parameter_name = HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_MASK;
|
||||
parameters[0].value = 0;
|
||||
parameters[1].parameter_name = HSA_VEN_AMD_AQLPROFILE_PARAMETER_NAME_TOKEN_MASK;
|
||||
parameters[1].value = 0;
|
||||
#endif
|
||||
|
||||
// Instantiate HSA resources
|
||||
HsaRsrcFactory::Create();
|
||||
|
||||
// Getting GPU device info
|
||||
const AgentInfo* agent_info = NULL;
|
||||
if (HsaRsrcFactory::Instance().GetGpuAgentInfo(0, &agent_info) == false) abort();
|
||||
|
||||
// Creating the queues pool
|
||||
const unsigned queue_count = 16;
|
||||
hsa_queue_t* queue[queue_count];
|
||||
for (unsigned queue_ind = 0; queue_ind < queue_count; ++queue_ind) {
|
||||
if (HsaRsrcFactory::Instance().CreateQueue(agent_info, 128, &queue[queue_ind]) == false) abort();
|
||||
}
|
||||
hsa_queue_t* prof_queue = queue[0];
|
||||
|
||||
// Creating profiling context
|
||||
properties = {};
|
||||
properties.queue = prof_queue;
|
||||
status = rocprofiler_open(agent_info->dev_id, feature, feature_count, &context,
|
||||
ROCPROFILER_MODE_STANDALONE, &properties);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
|
||||
// Test initialization
|
||||
TestHsa::SetQueue(prof_queue);
|
||||
TestHsa::HsaInstantiate(0);
|
||||
|
||||
// Dispatching profiled kernel n-times to collect all counter groups data
|
||||
const unsigned group_n = 0;
|
||||
status = rocprofiler_start(context, group_n);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
std::cout << "start" << std::endl;
|
||||
|
||||
for (unsigned ind = 0; ind < 3; ++ind) {
|
||||
#if 1
|
||||
const unsigned queue_ind = ind % queue_count;
|
||||
TestHsa::SetQueue(queue[queue_ind]);
|
||||
// ret_val = RunKernel<DummyKernel, TestAql>();
|
||||
ret_val = RunKernel<SimpleConvolution, TestAql>();
|
||||
std::cout << "run kernel, queue " << queue_ind << std::endl;
|
||||
#else
|
||||
sleep(3);
|
||||
#endif
|
||||
read_features(group_n, context, feature, feature_count);
|
||||
}
|
||||
|
||||
// Stop counters
|
||||
status = rocprofiler_stop(context, group_n);
|
||||
TEST_STATUS(status == HSA_STATUS_SUCCESS);
|
||||
std::cout << "stop" << std::endl;
|
||||
|
||||
// Finishing cleanup
|
||||
// Deleting profiling context will delete all allocated resources
|
||||
|
||||
Reference in New Issue
Block a user