Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

154 lines
5.7 KiB
C++

//===- OmptProfiler.cpp - OMPT impl of GenericProfilerTy --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Implementation of OmptProfilerTy
//
//===----------------------------------------------------------------------===//
#include "OmptProfiler.h"
#include "OpenMP/OMPT/Interface.h"
#include "PluginInterface.h"
#include "Shared/Debug.h"
using namespace llvm::omp::target;
void ompt::OmptProfilerTy::handleInit(plugin::GenericDeviceTy *Device,
plugin::GenericPluginTy *Plugin) {
auto DeviceId = Device->getDeviceId();
auto DevicePtr = reinterpret_cast<ompt_device_t *>(Device);
ompt::setDeviceId(DevicePtr, Plugin->getUserId(DeviceId));
if (ompt::Initialized) {
bool ExpectedStatus = false;
if (OmptInitialized.compare_exchange_strong(ExpectedStatus, true))
performOmptCallback(device_initialize, Plugin->getUserId(DeviceId),
/*type=*/Device->getComputeUnitKind().c_str(),
/*device=*/DevicePtr,
/*lookup=*/ompt::lookupDeviceTracingFn,
/*documentation=*/nullptr);
}
}
void ompt::OmptProfilerTy::handleDeinit(
plugin::GenericDeviceTy *Device, target::plugin::GenericPluginTy *Plugin) {
auto DeviceId = Device->getDeviceId();
if (ompt::Initialized) {
bool ExpectedStatus = true;
if (OmptInitialized.compare_exchange_strong(ExpectedStatus, false))
performOmptCallback(device_finalize, Plugin->getUserId(DeviceId));
}
ompt::removeDeviceId(reinterpret_cast<ompt_device_t *>(Device));
}
void ompt::OmptProfilerTy::handleLoadBinary(plugin::GenericDeviceTy *Device,
plugin::GenericPluginTy *Plugin,
const StringRef InputTgtImage) {
if (!ompt::Initialized)
return;
auto DeviceId = Device->getDeviceId();
size_t Bytes = InputTgtImage.size();
performOmptCallback(
device_load, Plugin->getUserId(DeviceId),
/*FileName=*/nullptr, /*FileOffset=*/0, /*VmaInFile=*/nullptr,
/*ImgSize=*/Bytes,
/*HostAddr=*/const_cast<unsigned char *>(InputTgtImage.bytes_begin()),
/*DeviceAddr=*/nullptr, /* FIXME: ModuleId */ 0);
}
void ompt::OmptProfilerTy::handleDataAlloc(uint64_t StartNanos,
uint64_t EndNanos, void *HostPtr,
uint64_t Size, void *Data) {
ompt::setOmptTimestamp(StartNanos, EndNanos);
}
void ompt::OmptProfilerTy::handleDataDelete(uint64_t StartNanos,
uint64_t EndNanos, void *TgtPtr,
void *Data) {
ompt::setOmptTimestamp(StartNanos, EndNanos);
}
void ompt::OmptProfilerTy::handlePreKernelLaunch(
plugin::GenericDeviceTy *Device, uint32_t NumBlocks[3],
__tgt_async_info *AI) {
if (!ompt::isTracedDevice(getDeviceId(Device)))
return;
if (AI->ProfilerData == nullptr)
return;
auto ProfilerSpecificData =
reinterpret_cast<ompt::OmptEventInfoTy *>(AI->ProfilerData);
assert(ProfilerSpecificData && "Invalid ProfilerSpecificData");
// Set number of granted teams for OMPT
setOmptGrantedNumTeams(NumBlocks[0]);
ProfilerSpecificData->NumTeams = NumBlocks[0];
}
void ompt::OmptProfilerTy::handleKernelCompletion(uint64_t StartNanos,
uint64_t EndNanos,
void *Data) {
if (!isProfilingEnabled())
return;
/// Empty data means no tracing in OMPT
/// offload/include/OpenMP/OMPT/Interface.h line 492
if (!Data)
return;
ODBG(ODT_Tool) << "OMPT-Async: Time kernel for asynchronous execution: Start "
<< StartNanos << " End " << EndNanos;
auto OmptEventInfo = reinterpret_cast<ompt::OmptEventInfoTy *>(Data);
assert(OmptEventInfo && "Invalid OmptEventInfo");
assert(OmptEventInfo->TraceRecord && "Invalid TraceRecord");
ompt::RegionInterface.stopTargetSubmitTraceAsync(OmptEventInfo->TraceRecord,
OmptEventInfo->NumTeams,
StartNanos, EndNanos);
// Done processing, our responsibility to free the memory
freeProfilerDataEntry(OmptEventInfo);
}
void ompt::OmptProfilerTy::handleDataTransfer(uint64_t StartNanos,
uint64_t EndNanos, void *Data) {
if (!isProfilingEnabled())
return;
/// Empty data means no tracing in OMPT
/// offload/include/OpenMP/OMPT/Interface.h line 492
if (!Data)
return;
ODBG(ODT_Tool) << "OMPT-Async: Time data for asynchronous execution: Start "
<< StartNanos << " End " << EndNanos;
auto OmptEventInfo = reinterpret_cast<ompt::OmptEventInfoTy *>(Data);
assert(OmptEventInfo && "Invalid OmptEventInfo");
assert(OmptEventInfo->TraceRecord && "Invalid TraceRecord");
ompt::RegionInterface.stopTargetDataMovementTraceAsync(
OmptEventInfo->TraceRecord, StartNanos, EndNanos);
// Done processing, our responsibility to free the memory
freeProfilerDataEntry(OmptEventInfo);
}
bool ompt::OmptProfilerTy::isProfilingEnabled() { return ompt::TracingActive; }
void ompt::OmptProfilerTy::setTimeConversionFactorsImpl(double Slope,
double Offset) {
ODBG(ODT_Tool) << "Using Time Slope: " << Slope << " and Offset: " << Offset;
setOmptHostToDeviceRate(Slope, Offset);
}