Bring the HSA_EVT callbacks back to the roctracer
Change-Id: I26080b264d7989880ba7e9f00502cc680b2256d7
Этот коммит содержится в:
@@ -18,68 +18,52 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE. */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "inc/roctracer.h"
|
||||
#include "inc/roctracer_hsa.h"
|
||||
#include <rocprofiler/rocprofiler.h>
|
||||
|
||||
#define PUBLIC_API __attribute__((visibility("default")))
|
||||
#define CONSTRUCTOR_API __attribute__((constructor))
|
||||
#define DESTRUCTOR_API __attribute__((destructor))
|
||||
|
||||
namespace {
|
||||
// Check returned HSA API status
|
||||
void check_status(roctracer_status_t status) {
|
||||
inline void CHECK(roctracer_status_t status) {
|
||||
if (status != ROCTRACER_STATUS_SUCCESS) {
|
||||
const char* error_string = roctracer_error_string();
|
||||
fprintf(stderr, "ERROR: %s\n", error_string);
|
||||
fprintf(stderr, "ERROR: %s\n", roctracer_error_string());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
// codeobj callback
|
||||
void codeobj_callback(uint32_t domain, uint32_t cid, const void* data, void* arg) {
|
||||
void CodeObjectCallback(uint32_t domain, uint32_t cid, const void* data, void* arg) {
|
||||
const hsa_evt_data_t* evt_data = reinterpret_cast<const hsa_evt_data_t*>(data);
|
||||
const char* uri = evt_data->codeobj.uri;
|
||||
printf(
|
||||
"codeobj_callback domain(%u) cid(%u): load_base(0x%lx) load_size(0x%lx) load_delta(0x%lx) "
|
||||
"uri(\"%s\")\n",
|
||||
domain, cid, evt_data->codeobj.load_base, evt_data->codeobj.load_size,
|
||||
evt_data->codeobj.load_delta, uri);
|
||||
free((void*)uri);
|
||||
fflush(stdout);
|
||||
fprintf(stdout,
|
||||
"codeobj_callback domain(%u) cid(%u): load_base(0x%lx) load_size(0x%lx) "
|
||||
"load_delta(0x%lx) uri(\"%s\") unload(%d)\n",
|
||||
domain, cid, evt_data->codeobj.load_base, evt_data->codeobj.load_size,
|
||||
evt_data->codeobj.load_delta, evt_data->codeobj.uri, evt_data->codeobj.unload);
|
||||
}
|
||||
|
||||
void initialize() {
|
||||
roctracer_status_t status = roctracer_enable_op_callback(
|
||||
ACTIVITY_DOMAIN_HSA_EVT, HSA_EVT_ID_CODEOBJ, codeobj_callback, NULL);
|
||||
check_status(status);
|
||||
} // namespace
|
||||
|
||||
#include <hsa/hsa_api_trace.h>
|
||||
|
||||
extern "C" {
|
||||
// The HSA_AMD_TOOL_PRIORITY variable must be a constant value type initialized by the loader
|
||||
// itself, not by code during _init. 'extern const' seems to do that although that is not a
|
||||
// guarantee.
|
||||
ROCTRACER_EXPORT extern const uint32_t HSA_AMD_TOOL_PRIORITY = 1050;
|
||||
|
||||
// HSA-runtime tool on-load method
|
||||
ROCTRACER_EXPORT bool OnLoad(HsaApiTable* table, uint64_t runtime_version,
|
||||
uint64_t failed_tool_count, const char* const* failed_tool_names) {
|
||||
CHECK(roctracer_enable_op_callback(ACTIVITY_DOMAIN_HSA_EVT, HSA_EVT_ID_CODEOBJ,
|
||||
CodeObjectCallback, nullptr));
|
||||
return true;
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
roctracer_status_t status = roctracer_disable_domain_callback(ACTIVITY_DOMAIN_HSA_EVT);
|
||||
check_status(status);
|
||||
ROCTRACER_EXPORT void OnUnload() {
|
||||
CHECK(roctracer_disable_domain_callback(ACTIVITY_DOMAIN_HSA_EVT));
|
||||
}
|
||||
|
||||
// Tool constructor
|
||||
extern "C" PUBLIC_API void OnLoadToolProp(rocprofiler_settings_t* settings) {
|
||||
// Enable HSA events intercepting
|
||||
settings->hsa_intercepting = 1;
|
||||
// Initialize profiling
|
||||
initialize();
|
||||
}
|
||||
|
||||
// Tool destructor
|
||||
extern "C" PUBLIC_API void OnUnloadTool() {
|
||||
// Final resources cleanup
|
||||
cleanup();
|
||||
}
|
||||
|
||||
extern "C" CONSTRUCTOR_API void constructor() {
|
||||
printf("constructor\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
extern "C" DESTRUCTOR_API void destructor() { OnUnloadTool(); }
|
||||
} // extern "C"
|
||||
Ссылка в новой задаче
Block a user