From ab6577373b1ffc02c3ef580849038098f057b439 Mon Sep 17 00:00:00 2001 From: Arnaud Fiorini Date: Fri, 8 Mar 2024 14:20:08 -0500 Subject: [PATCH] rocm: add rocm gpu trace for exatracer and ctf plugin Signed-off-by: Arnaud Fiorini --- Dockerfile | 4 +- .../META-INF/MANIFEST.MF | 3 +- .../core/analysis/GpuCallStackAnalysis.java | 2 +- .../gpu/core/handlers/ApiEventHandler.java | 4 +- .../gpu/core/trace/IGpuTraceEventLayout.java | 2 +- .../feature.xml | 19 +- .../META-INF/MANIFEST.MF | 5 +- .../plugin.xml | 68 +---- .../core/analysis/RocmCallStackAnalysis.java | 3 +- .../dependency/AbstractDependencyMaker.java | 73 ----- .../HipApiHipActivityDependencyMaker.java | 262 ------------------ .../analysis/dependency/package-info.java | 12 - .../analysis/handlers/ApiEventHandler.java | 4 +- .../handlers/old/AbstractGpuEventHandler.java | 133 --------- .../handlers/old/ApiEventHandler.java | 145 ---------- .../handlers/old/HipActivityEventHandler.java | 151 ---------- .../handlers/old/HostThreadIdentifier.java | 126 --------- .../handlers/old/HsaActivityEventHandler.java | 58 ---- .../handlers/old/HsaKernelEventHandler.java | 62 ----- .../handlers/old/RoctxEventHandler.java | 59 ---- .../analysis/handlers/old/package-info.java | 12 - .../analysis/old/RocmCallStackAnalysis.java | 81 ------ .../old/RocmCallStackStateProvider.java | 145 ---------- .../analysis/old/RocmMetadataAnalysis.java | 59 ---- .../old/RocmMetadataStateProvider.java | 104 ------- .../rocm/core/analysis/old/RocmStrings.java | 81 ------ .../trace/RocmApiCtfPluginEventLayout.java | 26 ++ .../ctfplugin/trace/RocmCtfPluginTrace.java | 166 +++++++++++ .../trace/RocmCtfPluginTraceEventLayout.java | 85 ++++++ .../old => ctfplugin/trace}/package-info.java | 5 +- .../exatracer/trace/RocmApiEventLayout.java | 20 ++ .../exatracer/trace/RocmExatracerTrace.java | 95 +++++++ .../trace/RocmExatracerTraceEventLayout.java | 86 ++++++ .../core/exatracer/trace}/package-info.java | 6 +- .../incubator/rocm/core/trace/GpuAspect.java | 10 - .../rocm/core/trace/RocmAspects.java | 157 +---------- .../rocm/core/trace/RocmCounterAspect.java | 114 -------- .../incubator/rocm/core/trace/RocmTrace.java | 99 +------ .../core/trace/RocmTraceSymbolProvider.java | 99 ------- .../trace/RocmTraceSymbolProviderFactory.java | 38 --- .../rocm/core/trace/old/RocmTrace.java | 232 ---------------- .../category.xml | 3 + .../META-INF/MANIFEST.MF | 2 +- .../pom.xml | 2 +- .../tracing.incubator.product | 1 + .../traceserver.product | 2 +- 46 files changed, 516 insertions(+), 2409 deletions(-) delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/AbstractDependencyMaker.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/HipApiHipActivityDependencyMaker.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/package-info.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/AbstractGpuEventHandler.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/ApiEventHandler.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HipActivityEventHandler.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HostThreadIdentifier.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaActivityEventHandler.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaKernelEventHandler.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/RoctxEventHandler.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/package-info.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackAnalysis.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackStateProvider.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataAnalysis.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataStateProvider.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmStrings.java create mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmApiCtfPluginEventLayout.java create mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTrace.java create mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTraceEventLayout.java rename analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/{trace/old => ctfplugin/trace}/package-info.java (72%) create mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmApiEventLayout.java create mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTrace.java create mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTraceEventLayout.java rename analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/{internal/rocm/core/analysis/old => rocm/core/exatracer/trace}/package-info.java (72%) delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmCounterAspect.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProvider.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProviderFactory.java delete mode 100644 analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/old/RocmTrace.java diff --git a/Dockerfile b/Dockerfile index 8fd3f1886..7779ae85b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ # SPDX-License-Identifier: EPL-2.0 ARG VARIANT=latest -FROM tracecompass:${VARIANT} as packager +FROM tracecompass-pss:${VARIANT} as packager ENV JAVA_MINIMAL="/opt/java-minimal" @@ -27,7 +27,7 @@ WORKDIR /app/ RUN mvn clean install -DskipTests -FROM alpine:3.16.0 +FROM alpine:3.18.0 ENV JAVA_HOME=/opt/java-minimal ENV PATH="$PATH:$JAVA_HOME/bin" diff --git a/analyses/org.eclipse.tracecompass.incubator.gpu.core/META-INF/MANIFEST.MF b/analyses/org.eclipse.tracecompass.incubator.gpu.core/META-INF/MANIFEST.MF index 5cdf08892..c52608e7d 100644 --- a/analyses/org.eclipse.tracecompass.incubator.gpu.core/META-INF/MANIFEST.MF +++ b/analyses/org.eclipse.tracecompass.incubator.gpu.core/META-INF/MANIFEST.MF @@ -15,8 +15,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.tracecompass.tmf.core, org.eclipse.tracecompass.segmentstore.core, org.eclipse.tracecompass.analysis.timing.core, - org.eclipse.tracecompass.analysis.profiling.core, - org.eclipse.tracecompass.analysis.callstack.core + org.eclipse.tracecompass.analysis.profiling.core Export-Package: org.eclipse.tracecompass.incubator.gpu.core.trace, org.eclipse.tracecompass.incubator.internal.gpu.core;x-friends:="org.eclipse.tracecompass.incubator.gpu.core.tests" Automatic-Module-Name: org.eclipse.tracecompass.incubator.gpu.core diff --git a/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/analysis/GpuCallStackAnalysis.java b/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/analysis/GpuCallStackAnalysis.java index 62c6d9001..8b61353da 100644 --- a/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/analysis/GpuCallStackAnalysis.java +++ b/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/analysis/GpuCallStackAnalysis.java @@ -43,7 +43,7 @@ public class GpuCallStackAnalysis extends InstrumentedCallStackAnalysis { /** Name of the sub-attribute where the correlation id is stored */ public static final String CORRELATION_ID = "correlation_id"; //$NON-NLS-1$ /** Name of the sub-attribute where the operations are stored */ - public static final String HIP_OPERATION_QUEUES = "hip_operation_queues"; //$NON-NLS-1$ + public static final String OPERATION_QUEUES = "operation_queues"; //$NON-NLS-1$ @Override protected Collection getEdgeQuarks() { diff --git a/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/handlers/ApiEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/handlers/ApiEventHandler.java index 79657f2cd..f7ab076cd 100644 --- a/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/handlers/ApiEventHandler.java +++ b/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/handlers/ApiEventHandler.java @@ -30,7 +30,7 @@ public class ApiEventHandler implements IGpuEventHandler { @Override public void handleEvent(ITmfEvent event, ITmfStateSystemBuilder ssb, IGpuTraceEventLayout layout, ITmfStateProvider stateProvider) { - Integer tid = event.getContent().getFieldValue(Integer.class, layout.fieldThreadId()); + Long tid = event.getContent().getFieldValue(Long.class, layout.fieldThreadId()); if (tid == null) { return; } @@ -41,7 +41,7 @@ public void handleEvent(ITmfEvent event, ITmfStateSystemBuilder ssb, IGpuTraceEv int apiQuark = ssb.getQuarkRelativeAndAdd(processQuark, apiLayout.getApiName()); int callStackQuark = ssb.getQuarkRelativeAndAdd(apiQuark, CallStackAnalysis.CALL_STACK); - if (apiLayout.isBeginEvent()) { + if (apiLayout.isBeginEvent(event)) { ssb.pushAttribute(event.getTimestamp().getValue(), apiLayout.getEventName(event), callStackQuark); } else { ssb.popAttribute(event.getTimestamp().getValue(), callStackQuark); diff --git a/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/trace/IGpuTraceEventLayout.java b/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/trace/IGpuTraceEventLayout.java index de04979ca..d8cd04fb9 100644 --- a/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/trace/IGpuTraceEventLayout.java +++ b/analyses/org.eclipse.tracecompass.incubator.gpu.core/src/org/eclipse/tracecompass/incubator/gpu/core/trace/IGpuTraceEventLayout.java @@ -83,7 +83,7 @@ public interface IApiEventLayout { * the event object * @return whether the event timestamp is the beginning */ - public abstract boolean isBeginEvent(); + public abstract boolean isBeginEvent(ITmfEvent event); /** * This function extracts the name of the event. diff --git a/analyses/org.eclipse.tracecompass.incubator.gpu/feature.xml b/analyses/org.eclipse.tracecompass.incubator.gpu/feature.xml index 4a581f08b..7d874b393 100644 --- a/analyses/org.eclipse.tracecompass.incubator.gpu/feature.xml +++ b/analyses/org.eclipse.tracecompass.incubator.gpu/feature.xml @@ -18,26 +18,13 @@ %license - - + id="org.eclipse.tracecompass.incubator.gpu.core" + version="0.0.0"/> + version="0.0.0"/> diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/META-INF/MANIFEST.MF b/analyses/org.eclipse.tracecompass.incubator.rocm.core/META-INF/MANIFEST.MF index a368319f4..359268478 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/META-INF/MANIFEST.MF +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/META-INF/MANIFEST.MF @@ -22,12 +22,11 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.tracecompass.analysis.counters.core;bundle-version="2.2.1", org.eclipse.tracecompass.incubator.analysis.core, org.eclipse.tracecompass.incubator.callstack.core, + org.eclipse.tracecompass.incubator.gpu.core, org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional Export-Package: org.eclipse.tracecompass.incubator.internal.rocm.core;x-friends:="org.eclipse.tracecompass.incubator.rocm.core.tests", - org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old, org.eclipse.tracecompass.incubator.rocm.core.analysis.dependency, - org.eclipse.tracecompass.incubator.rocm.core.trace, - org.eclipse.tracecompass.incubator.rocm.core.trace.old + org.eclipse.tracecompass.incubator.rocm.core.trace Automatic-Module-Name: org.eclipse.tracecompass.incubator.rocm.ctf.core Import-Package: com.google.common.annotations, com.google.common.base, diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/plugin.xml b/analyses/org.eclipse.tracecompass.incubator.rocm.core/plugin.xml index 17261e395..31d37daea 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/plugin.xml +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/plugin.xml @@ -1,79 +1,23 @@ - - - - - - - - - - - - - - - - + name="Exatracer Trace" + trace_type="org.eclipse.tracecompass.incubator.rocm.core.exatracer.trace.RocmExatracerTrace"> + name="RocmCtfPlugin Trace" + trace_type="org.eclipse.tracecompass.incubator.rocm.core.ctfplugin.trace.RocmCtfPluginTrace"> - - - - - - - - - - diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/RocmCallStackAnalysis.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/RocmCallStackAnalysis.java index 030e9d399..012fbcce3 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/RocmCallStackAnalysis.java +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/RocmCallStackAnalysis.java @@ -15,7 +15,7 @@ import java.util.Objects; import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.internal.provisional.analysis.profiling.core.instrumented.InstrumentedCallStackAnalysis; +import org.eclipse.tracecompass.analysis.profiling.core.instrumented.InstrumentedCallStackAnalysis; import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; @@ -29,7 +29,6 @@ * * @author Arnaud Fiorini */ -@SuppressWarnings("restriction") public class RocmCallStackAnalysis extends InstrumentedCallStackAnalysis { private static final String EDGES = "EDGES"; //$NON-NLS-1$ diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/AbstractDependencyMaker.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/AbstractDependencyMaker.java deleted file mode 100644 index 636cd8847..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/AbstractDependencyMaker.java +++ /dev/null @@ -1,73 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.dependency; - -import java.util.List; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread; -import org.eclipse.tracecompass.incubator.callstack.core.base.EdgeStateValue; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.incubator.rocm.core.analysis.dependency.IDependencyMaker; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; - -/** - * This dependency maker adds default methods for dependencies - * - * @author Arnaud Fiorini - */ -public abstract class AbstractDependencyMaker implements IDependencyMaker { - - /** - * DependencyMake constructor - */ - protected AbstractDependencyMaker() { - } - - /** - * Creates and adds an arrow to the state system - * - * @param ssb - * The state system to add the arrows - * @param startTime - * The start time of the arrow - * @param endTime - * The end time of the arrow - * @param id - * The id to identify the arrow - * @param src - * The source hostThread - * @param dest - * The destination hostThread - */ - public static void addArrow(ITmfStateSystemBuilder ssb, Long startTime, Long endTime, int id, - @NonNull HostThread src, @NonNull HostThread dest) { - int edgeQuark = getAvailableEdgeQuark(ssb, startTime); - Object edgeStateValue = new EdgeStateValue(id, src, dest); - ssb.modifyAttribute(startTime, edgeStateValue, edgeQuark); - ssb.modifyAttribute(endTime, (Object) null, edgeQuark); - } - - private static int getAvailableEdgeQuark(ITmfStateSystemBuilder ssb, long startTime) { - int edgeRoot = ssb.getQuarkAbsoluteAndAdd(RocmStrings.EDGES); - List<@NonNull Integer> subQuarks = ssb.getSubAttributes(edgeRoot, false); - - for (int quark : subQuarks) { - long start = ssb.getOngoingStartTime(quark); - Object value = ssb.queryOngoing(quark); - if (value == null && start <= startTime) { - return quark; - } - } - return ssb.getQuarkRelativeAndAdd(edgeRoot, Integer.toString(subQuarks.size())); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/HipApiHipActivityDependencyMaker.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/HipApiHipActivityDependencyMaker.java deleted file mode 100644 index 84a7d3e1e..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/HipApiHipActivityDependencyMaker.java +++ /dev/null @@ -1,262 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.dependency; - -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.PriorityQueue; -import java.util.Queue; - -import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread; -import org.eclipse.tracecompass.incubator.internal.rocm.core.Activator; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.AbstractGpuEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.ApiEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.HostThreadIdentifier; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.HostThreadIdentifier.KERNEL_CATEGORY; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.util.Pair; - -/** - * As the dependencies relies on specific information depending on the types of - * event that are available, one class is implemented for each use case. - * - * In this case this dependency maker works in the case where both the HIP API - * events and the HIP activity events are available. - * - * @author Arnaud Fiorini - */ -public class HipApiHipActivityDependencyMaker extends AbstractDependencyMaker { - - private final Map fApiEventCorrelationMap = new HashMap<>(); - private List fWaitEventPerThread = new LinkedList<>(); - private final Queue> fInFlightEvents = new PriorityQueue<>(new EventComparator()); - - /** - * This event comparator will sort pairs on API events and their - * corresponding activity event. This is useful to derive forward - * dependencies in the correct order. - * - * @author Arnaud Fiorini - */ - public static class EventComparator implements Comparator> { - @Override - public int compare(Pair pair1, Pair pair2) { - Long endTime1 = AbstractGpuEventHandler.getEndTime(pair1.getSecond()); - Long endTime2 = AbstractGpuEventHandler.getEndTime(pair2.getSecond()); - if (endTime1 == null || endTime2 == null) { - return -1; - } - return (int) (endTime1 - endTime2); - } - } - - @Override - public void processEvent(ITmfEvent event, ITmfStateSystemBuilder ssb) { - // Remove events that ended before this event - removeInFlightEvents(event); - // The eventName is the API function name where the event type name is - // the API name (HIP/HSA) - String eventName; - switch (event.getName()) { - case RocmStrings.HIP_API: - eventName = ApiEventHandler.getFunctionApiName(event); - // GPU Kernel dispatch - if (eventName.equals(RocmStrings.KERNEL_LAUNCH)) { - addGpuActivityDispatch(event, 7); - } - // Memory Copy dispatch - else if (eventName.equals("hipMemcpy")) { //$NON-NLS-1$ - addGpuActivityDispatch(event, 4); - } - // Wait Api Events - else if (eventName.equals(RocmStrings.HIP_DEVICE_SYNCHRONIZE)) { - addWaitDependencies(event, ssb); - } - break; - case RocmStrings.HIP_ACTIVITY: - eventName = event.getContent().getFieldValue(String.class, RocmStrings.NAME); - if (eventName != null && eventName.equals("KernelExecution")) { //$NON-NLS-1$ - addKernelDependency(event, ssb); - } else if (eventName != null && eventName.startsWith("Copy")) { //$NON-NLS-1$ - addMemoryDependency(event, ssb); - } - Long correlationId = event.getContent().getFieldValue(Long.class, RocmStrings.CORRELATION_ID); - fApiEventCorrelationMap.remove(correlationId); - break; - default: - } - } - - private void addGpuActivityDispatch(ITmfEvent event, int argPosition) { - Long correlationId = Long.parseLong(ApiEventHandler.getArg(event.getContent(), argPosition)); - fApiEventCorrelationMap.put(correlationId, event); - } - - private void addKernelDependency(ITmfEvent hipActivityEvent, ITmfStateSystemBuilder ssb) { - // Add Kernel Launch Dependency - Integer queueId = hipActivityEvent.getContent().getFieldValue(Integer.class, RocmStrings.QUEUE_ID); - Long correlationId = hipActivityEvent.getContent().getFieldValue(Long.class, RocmStrings.CORRELATION_ID); - Long gpuId = hipActivityEvent.getContent().getFieldValue(Long.class, RocmStrings.DEVICE_ID); - if (correlationId != null && queueId != null && gpuId != null) { - ITmfEvent hipEvent = fApiEventCorrelationMap.get(correlationId); - if (hipEvent == null) { - return; // no correlation - } - addInFlightEvent(hipEvent, hipActivityEvent, ssb); - Integer tid = hipEvent.getContent().getFieldValue(Integer.class, RocmStrings.TID); - if (tid == null) { - return; - } - int hipStreamId = Integer.parseInt(ApiEventHandler.getArg(hipEvent.getContent(), 4)); - HostThreadIdentifier srcHostThreadIdentifier = new HostThreadIdentifier(hipEvent, tid); - HostThreadIdentifier dstStreamHostThreadIdentifier = new HostThreadIdentifier(hipStreamId, KERNEL_CATEGORY.STREAM, gpuId.intValue()); - HostThreadIdentifier dstQueueHostThreadIdentifier = new HostThreadIdentifier(queueId.intValue(), KERNEL_CATEGORY.QUEUE, gpuId.intValue()); - // HostThreads - HostThread src = new HostThread(hipEvent.getTrace().getHostId(), srcHostThreadIdentifier.hashCode()); - HostThread destStream = new HostThread(hipEvent.getTrace().getHostId(), dstStreamHostThreadIdentifier.hashCode()); - HostThread destQueue = new HostThread(hipEvent.getTrace().getHostId(), dstQueueHostThreadIdentifier.hashCode()); - // Arrows - Long hipStreamEventEndTimestamp = AbstractGpuEventHandler.getEndTime(hipEvent); - if (hipStreamEventEndTimestamp != null) { - addArrow(ssb, hipStreamEventEndTimestamp - 1, hipActivityEvent.getTimestamp().getValue(), - Math.toIntExact(correlationId), src, destQueue); - addArrow(ssb, hipStreamEventEndTimestamp - 1, hipActivityEvent.getTimestamp().getValue(), - Math.toIntExact(correlationId), src, destStream); - } - } - } - - private void addMemoryDependency(ITmfEvent hipActivityEvent, ITmfStateSystemBuilder ssb) { - Long correlationId = hipActivityEvent.getContent().getFieldValue(Long.class, RocmStrings.CORRELATION_ID); - if (correlationId == null) { - return; - } - ITmfEvent hipEvent = fApiEventCorrelationMap.get(correlationId); - if (hipEvent == null) { - return; // no correlation - } - addInFlightEvent(hipEvent, hipActivityEvent, ssb); - Integer tid = hipEvent.getContent().getFieldValue(Integer.class, RocmStrings.TID); - if (tid == null) { - return; - } - HostThreadIdentifier srcHostThreadIdentifier = new HostThreadIdentifier(hipEvent, tid); - HostThreadIdentifier dstHostThreadIdentifier = new HostThreadIdentifier(); - // HostThreads - HostThread src = new HostThread(hipEvent.getTrace().getHostId(), srcHostThreadIdentifier.hashCode()); - HostThread dst = new HostThread(hipEvent.getTrace().getHostId(), dstHostThreadIdentifier.hashCode()); - // Arrow - addArrow(ssb, hipEvent.getTimestamp().getValue(), hipActivityEvent.getTimestamp().getValue(), - Math.toIntExact(correlationId), src, dst); - } - - private void addInFlightEvent(ITmfEvent hipApiEvent, ITmfEvent hipActivityEvent, ITmfStateSystemBuilder ssb) { - fInFlightEvents.add(new Pair<>(hipApiEvent, hipActivityEvent)); - - Long beginTs = hipApiEvent.getTimestamp().getValue(); - Long endTs = AbstractGpuEventHandler.getEndTime(hipApiEvent); - // Check all waiting events to see if we are already waiting for this - // operation. - Iterator waitEventIterator = fWaitEventPerThread.iterator(); - while (waitEventIterator.hasNext()) { - ITmfEvent waitEvent = waitEventIterator.next(); - Long dependencyBeginTs = waitEvent.getTimestamp().getValue(); - Long dependencyEndTs = AbstractGpuEventHandler.getEndTime(waitEvent); - if (beginTs > dependencyEndTs) { - // The wait event has finished without any other activity so - // there can be no wait dependency beyond this point. - waitEventIterator.remove(); - continue; - } - if (beginTs > dependencyBeginTs) { - // The wait event had already begun before the operation was - // queued. - // Therefore there is no dependency. - continue; - } - if (beginTs < dependencyBeginTs && endTs > dependencyBeginTs) { - // AFAIK, this case should not be possible. - Activator.getInstance().logError("If you see this message, the wait dependencies behavior should be changed."); //$NON-NLS-1$ - } - addWaitDependencies(waitEvent, ssb); - } - } - - private void addWaitDependencies(ITmfEvent hipWaitEvent, ITmfStateSystemBuilder ssb) { - String apiFunctionName = ApiEventHandler.getFunctionApiName(hipWaitEvent); - - Integer waitTid = hipWaitEvent.getContent().getFieldValue(Integer.class, RocmStrings.TID); - if (waitTid == null) { - return; - } - // Add the wait event for already queued operation that we cannot make - // dependencies for yet. - if (!fWaitEventPerThread.contains(hipWaitEvent)) { - fWaitEventPerThread.add(hipWaitEvent); - } - if (apiFunctionName.equals(RocmStrings.HIP_DEVICE_SYNCHRONIZE)) { - // Make arrows for current activity - // TODO register deviceId per thread - int waitingForDevice = 0; - for (Pair inFlightEventPair : fInFlightEvents) { - Integer deviceId = inFlightEventPair.getSecond().getContent().getFieldValue(Integer.class, RocmStrings.DEVICE_ID); - if (deviceId != null && deviceId == waitingForDevice) { - int hipStreamId = Integer.parseInt(ApiEventHandler.getArg(inFlightEventPair.getFirst().getContent(), 4)); - addWaitArrow(ssb, inFlightEventPair.getSecond(), hipWaitEvent, waitTid, waitingForDevice, hipStreamId); - } - } - } - } - - private static void addWaitArrow(ITmfStateSystemBuilder ssb, ITmfEvent deviceEvent, ITmfEvent waitEvent, int waitTid, int deviceId, int hipStreamId) { - Integer queueId = deviceEvent.getContent().getFieldValue(Integer.class, RocmStrings.QUEUE_ID); - if (queueId == null) { - return; - } - HostThreadIdentifier srcHostThreadIdentifier = new HostThreadIdentifier(waitEvent, waitTid); - HostThreadIdentifier dstStreamHostThreadIdentifier = new HostThreadIdentifier(hipStreamId, KERNEL_CATEGORY.STREAM, deviceId); - HostThreadIdentifier dstQueueHostThreadIdentifier = new HostThreadIdentifier(queueId, KERNEL_CATEGORY.QUEUE, deviceId); - // HostThreads - HostThread destThread = new HostThread(waitEvent.getTrace().getHostId(), srcHostThreadIdentifier.hashCode()); - HostThread srcStream = new HostThread(deviceEvent.getTrace().getHostId(), dstStreamHostThreadIdentifier.hashCode()); - HostThread srcQueue = new HostThread(deviceEvent.getTrace().getHostId(), dstQueueHostThreadIdentifier.hashCode()); - // Arrows - Long hipStreamEventEndTimestamp = AbstractGpuEventHandler.getEndTime(waitEvent) - 1; - Long correlationId = deviceEvent.getContent().getFieldValue(Long.class, RocmStrings.CORRELATION_ID); - if (correlationId != null) { - addArrow(ssb, AbstractGpuEventHandler.getEndTime(deviceEvent) - 1, hipStreamEventEndTimestamp, - Math.toIntExact(correlationId), srcStream, destThread); - addArrow(ssb, AbstractGpuEventHandler.getEndTime(deviceEvent) - 1, hipStreamEventEndTimestamp, - Math.toIntExact(correlationId), srcQueue, destThread); - } - } - - private void removeInFlightEvents(ITmfEvent event) { - Long currentTime = event.getTimestamp().getValue(); - Pair inFlightEvent = fInFlightEvents.peek(); - while (inFlightEvent != null && (currentTime >= AbstractGpuEventHandler.getEndTime(inFlightEvent.getSecond()))) { - fInFlightEvents.remove(); - inFlightEvent = fInFlightEvents.peek(); - } - } - - @Override - public Map getApiEventCorrelationMap() { - return fApiEventCorrelationMap; - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/package-info.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/package-info.java deleted file mode 100644 index e792dc674..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/dependency/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.dependency; diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/ApiEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/ApiEventHandler.java index 4d1fbaf81..f948d1a79 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/ApiEventHandler.java +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/ApiEventHandler.java @@ -14,7 +14,7 @@ import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis; import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmCallStackStateProvider; import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmEventLayout; -import org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace; +import org.eclipse.tracecompass.incubator.rocm.core.ctfplugin.trace.RocmCtfPluginTrace; import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; @@ -93,7 +93,7 @@ private static void addEventToOperationQueue(ITmfEvent event, ITmfStateSystemBui int operationsQuark = ssb.getQuarkAbsoluteAndAdd(RocmCallStackStateProvider.HIP_OPERATION_QUEUES); long ts = event.getTimestamp().getValue(); - if (layout.isMemcpyBegin(event.getName()) || (event.getName().equals(layout.hipLaunchKernelBegin()) && ((RocmTrace) event.getTrace()).isContainingKernelGpuActivity()) + if (layout.isMemcpyBegin(event.getName()) || (event.getName().equals(layout.hipLaunchKernelBegin()) && ((RocmCtfPluginTrace) event.getTrace()).isContainingKernelGpuActivity()) || event.getName().equals(layout.hipStreamSynchronizeBegin())) { int depth = 1; int subQuark = ssb.getQuarkRelativeAndAdd(operationsQuark, String.valueOf(depth)); diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/AbstractGpuEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/AbstractGpuEventHandler.java deleted file mode 100644 index e5e41776c..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/AbstractGpuEventHandler.java +++ /dev/null @@ -1,133 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmCallStackStateProvider; -import org.eclipse.tracecompass.internal.analysis.timing.core.Activator; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; - -/** - * The base class for all GPU events handler. - * - * These handlers are used by the RocmCallStackStateProvider but they are not - * responsible for dependency matching which is done by the DependencyMaker - * classes. - * - * @author Arnaud Fiorini - */ -public abstract class AbstractGpuEventHandler { - - private Set fHostIdDefined = new HashSet<>(); - /** - * The state provider that is calling to this event handler - */ - protected final RocmCallStackStateProvider fStateProvider; - - /** - * @param stateProvider - * The state provider that is using this event handler - */ - protected AbstractGpuEventHandler(RocmCallStackStateProvider stateProvider) { - fStateProvider = stateProvider; - } - - /** - * Handle a specific gpu event. - * - * @param ssb - * the state system to write to - * @param event - * the event - * @throws AttributeNotFoundException - * if the attribute is not yet create - */ - public abstract void handleEvent(ITmfStateSystemBuilder ssb, ITmfEvent event) throws AttributeNotFoundException; - - /** - * Add the host id (unique id per callstack to identify arrow source and - * target) to the state system - * - * @param ssb - * the state system to write to - * @param trace - * the trace being read - * @param hostThreadIdentifier - * the host thread identifier element that computes a unique id - * @param quark - * the quark of the call stack - */ - public void addHostIdToStateSystemIfNotDefined(ITmfStateSystemBuilder ssb, ITmfTrace trace, HostThreadIdentifier hostThreadIdentifier, int quark) { - if (fHostIdDefined.contains(hostThreadIdentifier.hashCode())) { - return; - } - int parentQuark = ssb.getParentAttributeQuark(quark); - this.fHostIdDefined.add(hostThreadIdentifier.hashCode()); - ssb.modifyAttribute(trace.getStartTime().toNanos(), hostThreadIdentifier.hashCode(), parentQuark); - } - - /** - * @param ssb - * The state system builder used - * @param callStackQuark - * the quark to push to - * @param eventName - * the gpu activity name (usually the compute kernel name) - * @param ts - * the begin timestamp - * @param endTs - * the end timestamp - */ - public void pushParallelActivityOnCallStack(ITmfStateSystemBuilder ssb, int callStackQuark, String eventName, Long ts, Long endTs) { - try { - int depth = 1; - int subQuark = ssb.getQuarkRelativeAndAdd(callStackQuark, String.valueOf(depth)); - if (ts < ssb.getStartTime()) { - // do nothing - return; - } - // While there is already activity on the quark - while (ssb.querySingleState(ts, subQuark).getValue() != null) { - depth += 1; - subQuark = ssb.getQuarkRelativeAndAdd(callStackQuark, String.valueOf(depth)); - } - // Register stack depth on call stack quark - ssb.modifyAttribute(ts, depth, callStackQuark); - fStateProvider.addFutureEvent(endTs, null, callStackQuark); - // Register event name in the call stack - ssb.modifyAttribute(ts, eventName, subQuark); - fStateProvider.addFutureEvent(endTs, null, subQuark); - } catch (StateSystemDisposedException e) { - Activator.getInstance().logError(e.getMessage()); - } - } - - /** - * @param event - * the event to get the end time of - * @return the end time - */ - public static Long getEndTime(ITmfEvent event) { - Long timestampEnd = event.getContent().getFieldValue(Long.class, "end"); //$NON-NLS-1$ - if (timestampEnd != null) { - return ((CtfTmfTrace) event.getTrace()).timestampCyclesToNanos(timestampEnd); - } - return 0l; - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/ApiEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/ApiEventHandler.java deleted file mode 100644 index 2aa80aba9..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/ApiEventHandler.java +++ /dev/null @@ -1,145 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; - -import java.util.Collection; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackStateProvider; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmCallStackStateProvider; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmMetadataStateProvider; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; -import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider.FutureEventType; -import org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider; -import org.eclipse.tracecompass.tmf.core.symbols.SymbolProviderManager; -import org.eclipse.tracecompass.tmf.core.symbols.SymbolProviderUtils; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; - -/** - * This event handler will handle any event that originates from a ROCm API. In - * ROCm there exists multiple APIs: HIP, HSA and KFD. - *
    - *
  • HIP: Heterogeneous-computing Interface for Portability
  • - *
  • HSA: Heterogeneous Software Architecture
  • - *
  • KFD: Kernel Fusion Driver
  • - *
- * - * @author Arnaud Fiorini - */ -public class ApiEventHandler extends AbstractGpuEventHandler { - - /** - * @param stateProvider - * The state provider that is using this event handler - */ - public ApiEventHandler(RocmCallStackStateProvider stateProvider) { - super(stateProvider); - } - - @Override - public void handleEvent(ITmfStateSystemBuilder ssb, ITmfEvent event) throws AttributeNotFoundException { - // Select the correct quark - int systemQuark = ssb.getQuarkAbsoluteAndAdd(CallStackStateProvider.PROCESSES, RocmStrings.SYSTEM); - Long threadId = event.getContent().getFieldValue(Long.class, RocmStrings.TID); - if (threadId == null) { - threadId = 0l; - } - int threadQuark = ssb.getQuarkRelativeAndAdd(systemQuark, RocmStrings.THREAD + threadId.toString()); - int apiQuark = ssb.getQuarkRelativeAndAdd(threadQuark, event.getName().toUpperCase()); - int callStackQuark = ssb.getQuarkRelativeAndAdd(apiQuark, InstrumentedCallStackAnalysis.CALL_STACK); - - // Retrieve event information - ITmfEventField content = event.getContent(); - Long timestamp = event.getTimestamp().toNanos(); - Integer functionID = RocmMetadataStateProvider.getFunctionId(event); - - // Push the api function name to the call stack quark - ssb.pushAttribute(timestamp, functionID, callStackQuark); - Long timestampEnd = content.getFieldValue(Long.class, RocmStrings.END); - - if (timestampEnd != null) { - fStateProvider.addFutureEvent(((CtfTmfTrace) event.getTrace()).timestampCyclesToNanos(timestampEnd), - timestampEnd, callStackQuark, FutureEventType.POP); - } - - // Get and add HostThreadIdentifier if necessary - Integer tid = content.getFieldValue(Integer.class, RocmStrings.TID); - if (tid == null) { - return; - } - HostThreadIdentifier hostThreadIdentifier = new HostThreadIdentifier(event, tid); - addHostIdToStateSystemIfNotDefined(ssb, event.getTrace(), hostThreadIdentifier, callStackQuark); - } - - /** - * A standard function to parse the args strings and get the correct - * positioned argument - * - * @param content - * The content of the event - * @param argPosition - * The position of the argument - * @return the string value of the argument when the API function was called - */ - public static String getArg(ITmfEventField content, int argPosition) { - String args = content.getFieldValue(String.class, RocmStrings.ARGS); - if (args == null) { - return StringUtils.EMPTY; - } - int currentIndex = 0; - int argIndex = -1; - int currentPosition = 0; - int depth = 0; // '(' increases depth, ')' decreases it - while (currentIndex < args.length() && currentPosition <= argPosition) { - if (args.charAt(currentIndex) == ',' && depth == 0) { - currentPosition += 1; - } - if (args.charAt(currentIndex) == '(' || args.charAt(currentIndex) == '{' || args.charAt(currentIndex) == '<') { - depth += 1; - } - if (args.charAt(currentIndex) == ')' || args.charAt(currentIndex) == '}' || args.charAt(currentIndex) == '>') { - depth -= 1; - } - if (currentPosition == argPosition && argIndex < 0) { - if (argPosition > 0) { // if there is a comma - argIndex = currentIndex + 1; // do not select it - } else { - argIndex = currentIndex; - } - } - currentIndex += 1; - } - if (currentPosition > argPosition) { - currentIndex -= 1; // move back before the comma - } - if (argIndex >= 0) { - return args.substring(argIndex, currentIndex).strip(); - } - return StringUtils.EMPTY; - } - - /** - * @param event - * The event - * @return the function name of the API call for this event - */ - public static String getFunctionApiName(ITmfEvent event) { - Collection<@NonNull ISymbolProvider> providers = SymbolProviderManager.getInstance().getSymbolProviders(event.getTrace()); - return SymbolProviderUtils.getSymbolText(providers, RocmMetadataStateProvider.getFunctionId(event)); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HipActivityEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HipActivityEventHandler.java deleted file mode 100644 index 83cc6ab31..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HipActivityEventHandler.java +++ /dev/null @@ -1,151 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; - -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackStateProvider; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.HostThreadIdentifier.KERNEL_CATEGORY; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmCallStackStateProvider; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.incubator.rocm.core.analysis.dependency.IDependencyMaker; -import org.eclipse.tracecompass.incubator.rocm.core.trace.GpuAspect; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; -import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider.FutureEventType; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; - -/** - * The HIP activity event handler It is possible to have different backends - * generate the GPU activity events. This event handler is for the GPU activity - * events generated by HIP. - * - * @author Arnaud Fiorini - */ -public class HipActivityEventHandler extends AbstractGpuEventHandler { - - /** - * @param stateProvider - * The state provider that is using this event handler - */ - public HipActivityEventHandler(RocmCallStackStateProvider stateProvider) { - super(stateProvider); - } - - @Override - public void handleEvent(ITmfStateSystemBuilder ssb, ITmfEvent event) throws AttributeNotFoundException { - // Can be memory tranfer event or kernel execution event - int callStackQuark = getCallStackQuark(ssb, event); - - ITmfEventField content = event.getContent(); - Long timestamp = event.getTimestamp().toNanos(); - String eventName = content.getFieldValue(String.class, RocmStrings.NAME); - - if (eventName != null && eventName.equals(RocmStrings.KERNEL_EXECUTION)) { - int hipStreamCallStackQuark = -1; - Long correlationId = content.getFieldValue(Long.class, RocmStrings.CORRELATION_ID); - int gpuId = getGpuId(event); - int hipStreamId = -1; - // Placeholder value in case we do not match any api event. - String kernelName = RocmStrings.KERNEL_EXECUTION; - IDependencyMaker dependencyMaker = fStateProvider.getDependencyMaker(); - if (dependencyMaker != null) { - Map apiEventCorrelationMap = dependencyMaker.getApiEventCorrelationMap(); - ITmfEvent apiEvent = apiEventCorrelationMap.get(correlationId); - if (apiEvent != null) { - hipStreamId = Integer.parseInt(ApiEventHandler.getArg(apiEvent.getContent(), 4)); - hipStreamCallStackQuark = getHipStreamCallStackQuark(ssb, apiEvent, gpuId); - kernelName = ApiEventHandler.getArg(apiEvent.getContent(), 6); - } - } - Integer queueId = content.getFieldValue(Integer.class, RocmStrings.QUEUE_ID); - if (queueId == null || correlationId == null) { - return; - } - Long timestampEnd = content.getFieldValue(Long.class, RocmStrings.END); - if (timestampEnd != null) { - pushParallelActivityOnCallStack(ssb, callStackQuark, kernelName, timestamp, - ((CtfTmfTrace) event.getTrace()).timestampCyclesToNanos(timestampEnd)); - if (hipStreamCallStackQuark > 0) { - pushParallelActivityOnCallStack(ssb, hipStreamCallStackQuark, kernelName, - timestamp, ((CtfTmfTrace) event.getTrace()).timestampCyclesToNanos(timestampEnd)); - } - } - - // Add Host Thread Identifier for dependency arrows - HostThreadIdentifier queueHostThreadIdentifier = new HostThreadIdentifier(queueId.intValue(), KERNEL_CATEGORY.QUEUE, gpuId); - addHostIdToStateSystemIfNotDefined(ssb, event.getTrace(), queueHostThreadIdentifier, callStackQuark); - if (hipStreamCallStackQuark > 0) { - HostThreadIdentifier streamHostThreadIdentifier = new HostThreadIdentifier(hipStreamId, KERNEL_CATEGORY.STREAM, gpuId); - addHostIdToStateSystemIfNotDefined(ssb, event.getTrace(), streamHostThreadIdentifier, hipStreamCallStackQuark); - } - } else { - if (eventName == null) { - ssb.modifyAttribute(timestamp, null, callStackQuark); - return; - } - Long timestampEnd = content.getFieldValue(Long.class, RocmStrings.END); - ssb.pushAttribute(timestamp, eventName, callStackQuark); - if (timestampEnd != null) { - fStateProvider.addFutureEvent(((CtfTmfTrace) event.getTrace()).timestampCyclesToNanos(timestampEnd), - timestampEnd, callStackQuark, FutureEventType.POP); - } - // Add CallStack Identifier (tid equivalent) for the memory quark - HostThreadIdentifier hostThreadIdentifier = new HostThreadIdentifier(); - addHostIdToStateSystemIfNotDefined(ssb, event.getTrace(), hostThreadIdentifier, callStackQuark); - } - } - - private static int getCallStackQuark(ITmfStateSystemBuilder ssb, ITmfEvent event) { - String eventName = event.getContent().getFieldValue(String.class, RocmStrings.NAME); - if (eventName == null) { - return -1; - } - if (eventName.equals(RocmStrings.KERNEL_EXECUTION)) { - Long queueId = event.getContent().getFieldValue(Long.class, RocmStrings.QUEUE_ID); - Long gpuId = event.getContent().getFieldValue(Long.class, RocmStrings.DEVICE_ID); - if (queueId == null || gpuId == null) { - return -1; - } - int gpuQuark = ssb.getQuarkAbsoluteAndAdd(CallStackStateProvider.PROCESSES, RocmStrings.GPU + gpuId.toString()); - int queuesQuark = ssb.getQuarkRelativeAndAdd(gpuQuark, RocmStrings.QUEUES); - int queueQuark = ssb.getQuarkRelativeAndAdd(queuesQuark, RocmStrings.QUEUE + Long.toString(queueId)); - return ssb.getQuarkRelativeAndAdd(queueQuark, InstrumentedCallStackAnalysis.CALL_STACK); - } - int copyQuark = ssb.getQuarkAbsoluteAndAdd(CallStackStateProvider.PROCESSES, RocmStrings.MEMORY); - int tempQuark1 = ssb.getQuarkRelativeAndAdd(copyQuark, StringUtils.EMPTY); - int tempQuark2 = ssb.getQuarkRelativeAndAdd(tempQuark1, RocmStrings.MEMORY_TRANSFERS); - return ssb.getQuarkRelativeAndAdd(tempQuark2, InstrumentedCallStackAnalysis.CALL_STACK); - } - - private static int getHipStreamCallStackQuark(ITmfStateSystemBuilder ssb, @NonNull ITmfEvent event, Integer gpuId) { - int gpuQuark = ssb.getQuarkAbsoluteAndAdd(CallStackStateProvider.PROCESSES, RocmStrings.GPU + gpuId.toString()); - int hipStreamsQuark = ssb.getQuarkRelativeAndAdd(gpuQuark, RocmStrings.STREAMS); - int hipStreamId = Integer.parseInt(ApiEventHandler.getArg(event.getContent(), 4)); - int hipStreamQuark = ssb.getQuarkRelativeAndAdd(hipStreamsQuark, RocmStrings.STREAM + Integer.toString(hipStreamId)); - return ssb.getQuarkRelativeAndAdd(hipStreamQuark, InstrumentedCallStackAnalysis.CALL_STACK); - } - - private static int getGpuId(ITmfEvent event) { - Integer gpuId = (Integer) TmfTraceUtils.resolveEventAspectOfClassForEvent(event.getTrace(), GpuAspect.class, event); - if (gpuId != null) { - return gpuId; - } - return -1; - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HostThreadIdentifier.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HostThreadIdentifier.java deleted file mode 100644 index eab8ae4c7..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HostThreadIdentifier.java +++ /dev/null @@ -1,126 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; - -import java.util.Objects; - -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.rocm.core.trace.old.RocmTrace; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; - -/** - * This class is used to identify the correct lane when defining dependencies. - * - * @author Arnaud Fiorini - */ -public class HostThreadIdentifier { - /** - * Each kernel is executed in a stream (logical separation) and a queue - * (hardware separation) We create for each activity two state intervals: - * one for the queue and one for the stream - * - * @author Arnaud Fiorini - */ - public enum KERNEL_CATEGORY { - /** - * Activity mapped to the hardware queue designated by the ROCm runtime. - */ - QUEUE, - /** - * Stream chosen by the user to execute its compute kernel. - */ - STREAM - } - - /** - * ROCm categories used to differentiate memory transfers and API calls - * - * @author Arnaud Fiorini - */ - public enum ROCM_CATEGORY { - /** - * API calls - */ - SYSTEM, - /** - * Memory transfers - */ - MEMORY - } - - private final int fApiId; // Api type, Queue id, Stream id - private final int fThreadId; // Tid, Queue type, Stream type - private final int fCategoryId; // System, Memory, GPU id - - private HostThreadIdentifier(int apiId, int threadId, int categoryId) { - fApiId = apiId; - fThreadId = threadId; - fCategoryId = categoryId; - } - - /** - * Constructor for Memory transfer events, as there is only one call stack - * for this, there is no parameters - * - */ - public HostThreadIdentifier() { - this(0, 0, ROCM_CATEGORY.MEMORY.ordinal()); - } - - /** - * Constructor for GPU events - * - * @param categoryId - * stream id or queue id - * @param category - * Either queues or streams - * @param gpuId - * the id of the GPU - */ - public HostThreadIdentifier(int categoryId, KERNEL_CATEGORY category, int gpuId) { - // There are other categories (system, memory), this will separate the - // GPU categories. - this(categoryId, category.ordinal(), gpuId + ROCM_CATEGORY.values().length); - } - - /** - * Constructor for API events - * - * @param event - * the event from which we create the HostThreadIdentifier - * @param tid - * the tid of this event - */ - public HostThreadIdentifier(ITmfEvent event, int tid) { - this(((RocmTrace) event.getTrace()).getApiId(event.getName()), tid, ROCM_CATEGORY.SYSTEM.ordinal()); - } - - @Override - public int hashCode() { - return Objects.hash(fApiId, fThreadId, fCategoryId); - } - - @Override - public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (other == null) { - return false; - } - if (this.getClass() != other.getClass()) { - return false; - } - HostThreadIdentifier that = (HostThreadIdentifier) other; - return (fApiId == that.fApiId) && (fThreadId == that.fThreadId) && (fCategoryId == that.fCategoryId); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaActivityEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaActivityEventHandler.java deleted file mode 100644 index d2f101483..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaActivityEventHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackStateProvider; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmCallStackStateProvider; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider.FutureEventType; - -/** - * The HSA activity event handler.
- * It is possible to have different backends generate the GPU activity events. - * This event handler is for the GPU activity events generated by HSA. - * - * @author Arnaud Fiorini - */ -public class HsaActivityEventHandler extends AbstractGpuEventHandler { - - /** - * @param stateProvider - * The state provider that is using this event handler - */ - public HsaActivityEventHandler(RocmCallStackStateProvider stateProvider) { - super(stateProvider); - } - - @Override - public void handleEvent(ITmfStateSystemBuilder ssb, ITmfEvent event) throws AttributeNotFoundException { - int copyQuark = ssb.getQuarkAbsoluteAndAdd(CallStackStateProvider.PROCESSES, RocmStrings.MEMORY); - int tempQuark1 = ssb.getQuarkRelativeAndAdd(copyQuark, StringUtils.EMPTY); - int tempQuark2 = ssb.getQuarkRelativeAndAdd(tempQuark1, RocmStrings.MEMORY_TRANSFERS); - int callStackQuark = ssb.getQuarkRelativeAndAdd(tempQuark2, InstrumentedCallStackAnalysis.CALL_STACK); - - Long timestamp = event.getTimestamp().toNanos(); - Long timestampEnd = AbstractGpuEventHandler.getEndTime(event); - ssb.pushAttribute(timestamp, RocmStrings.COPY, callStackQuark); - if (timestampEnd != null) { - fStateProvider.addFutureEvent(timestampEnd, null, callStackQuark, FutureEventType.POP); - } - // Add CallStack Identifier (tid equivalent) for the memory quark - HostThreadIdentifier hostThreadIdentifier = new HostThreadIdentifier(); - addHostIdToStateSystemIfNotDefined(ssb, event.getTrace(), hostThreadIdentifier, callStackQuark); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaKernelEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaKernelEventHandler.java deleted file mode 100644 index d9b09c570..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/HsaKernelEventHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; - -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackStateProvider; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.HostThreadIdentifier.KERNEL_CATEGORY; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmCallStackStateProvider; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; - -/** - * Handles compute kernel events generated with ROCProfiler that are not GPU - * activity events. - * - * @author Arnaud Fiorini - */ -public class HsaKernelEventHandler extends AbstractGpuEventHandler { - - /** - * @param stateProvider - * The state provider that is using this event handler - */ - public HsaKernelEventHandler(RocmCallStackStateProvider stateProvider) { - super(stateProvider); - } - - @Override - public void handleEvent(ITmfStateSystemBuilder ssb, ITmfEvent event) throws AttributeNotFoundException { - String kernelName = event.getContent().getFieldValue(String.class, RocmStrings.KERNEL_NAME); - Long queueId = event.getContent().getFieldValue(Long.class, RocmStrings.QUEUE_ID); - Long gpuId = event.getContent().getFieldValue(Long.class, RocmStrings.GPU_ID); - if (queueId == null || gpuId == null) { - return; - } - int gpuQuark = ssb.getQuarkAbsoluteAndAdd(CallStackStateProvider.PROCESSES, RocmStrings.GPU + gpuId.toString()); - int queuesQuark = ssb.getQuarkRelativeAndAdd(gpuQuark, RocmStrings.QUEUES); - int queueQuark = ssb.getQuarkRelativeAndAdd(queuesQuark, RocmStrings.QUEUE + Long.toString(queueId)); - int callStackQuark = ssb.getQuarkRelativeAndAdd(queueQuark, InstrumentedCallStackAnalysis.CALL_STACK); - Long timestamp = event.getTimestamp().toNanos(); - Long timestampEnd = event.getContent().getFieldValue(Long.class, "complete_time"); //$NON-NLS-1$ - if (timestampEnd != null) { - timestampEnd = ((CtfTmfTrace) event.getTrace()).timestampCyclesToNanos(timestampEnd); - pushParallelActivityOnCallStack(ssb, callStackQuark, kernelName, timestamp, timestampEnd); - } - // Add Host Thread Identifier for dependency arrows - HostThreadIdentifier queueHostThreadIdentifier = new HostThreadIdentifier(queueId.intValue(), KERNEL_CATEGORY.QUEUE, gpuId.intValue()); - addHostIdToStateSystemIfNotDefined(ssb, event.getTrace(), queueHostThreadIdentifier, callStackQuark); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/RoctxEventHandler.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/RoctxEventHandler.java deleted file mode 100644 index 9e45697cc..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/RoctxEventHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackStateProvider; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmCallStackStateProvider; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; - -/** - * This event handler is used for ROCtx events which are custom tracepoints - * defined by the user. - * - * @author Arnaud Fiorini - */ -public class RoctxEventHandler extends AbstractGpuEventHandler { - - /** - * @param stateProvider - * The state provider that is using this event handler - */ - public RoctxEventHandler(RocmCallStackStateProvider stateProvider) { - super(stateProvider); - } - - @Override - public void handleEvent(ITmfStateSystemBuilder ssb, ITmfEvent event) throws AttributeNotFoundException { - // Select the correct quark - int systemQuark = ssb.getQuarkAbsoluteAndAdd(CallStackStateProvider.PROCESSES, RocmStrings.SYSTEM); - Long threadId = event.getContent().getFieldValue(Long.class, RocmStrings.TID); - if (threadId == null) { - threadId = 0l; - } - int threadQuark = ssb.getQuarkRelativeAndAdd(systemQuark, RocmStrings.THREAD + threadId.toString()); - int apiQuark = ssb.getQuarkRelativeAndAdd(threadQuark, "RocTX"); //$NON-NLS-1$ - int callStackQuark = ssb.getQuarkRelativeAndAdd(apiQuark, InstrumentedCallStackAnalysis.CALL_STACK); - // Push message - Long timestamp = event.getTimestamp().getValue(); - String message = event.getContent().getFieldValue(String.class, RocmStrings.MESSAGE); - if (message == null || message.equals(StringUtils.EMPTY)) { - ssb.popAttribute(timestamp, callStackQuark); - return; - } - ssb.pushAttribute(timestamp, message, callStackQuark); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/package-info.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/package-info.java deleted file mode 100644 index 6b966bfe8..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/handlers/old/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old; diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackAnalysis.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackAnalysis.java deleted file mode 100644 index fcca1ec1e..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackAnalysis.java +++ /dev/null @@ -1,81 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackSeries; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackSeries.IThreadIdResolver; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackStateProvider; -import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.InstrumentedCallStackAnalysis; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; -import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; - -import com.google.common.collect.ImmutableList; - -/** - * This analysis is a callstack analysis which summarizes the execution of a - * ROCm GPU program. - * - * It separates the execution into 3 categories: the GPU, the memory transfers, - * and the system API calls. Furthermore, some dependencies were modeled using - * arrows to show the user how these abstract layers relate to each other. - * - * @author Arnaud Fiorini - */ -public class RocmCallStackAnalysis extends InstrumentedCallStackAnalysis { - /** - * Call stack analysis ID - */ - public static final @NonNull String ID = "org.eclipse.tracecompass.incubator.rocm.core.analysis.interval"; //$NON-NLS-1$ - - @Override - protected @NonNull ITmfStateProvider createStateProvider() { - return new RocmCallStackStateProvider(Objects.requireNonNull(getTrace())); - } - - @Override - protected @Nullable IThreadIdResolver getCallStackTidResolver() { - return new CallStackSeries.AttributeValueThreadResolver(2); - } - - @Override - protected @NonNull Collection<@NonNull Integer> getEdgeQuarks() { - ITmfStateSystem ss = getStateSystem(); - if (ss == null) { - return Collections.emptyList(); - } - int edgeQuark = ss.optQuarkAbsolute(RocmStrings.EDGES); - if (edgeQuark == ITmfStateSystem.INVALID_ATTRIBUTE) { - return Collections.emptyList(); - } - return ss.getSubAttributes(edgeQuark, false); - } - - /** - * Get the patterns for the GPUs, threads and categories - * - * @return The patterns for the different levels in the state system - */ - @Override - protected List getPatterns() { - return ImmutableList.of( - new String[] { CallStackStateProvider.PROCESSES, "*" }, //$NON-NLS-1$ - new String[] { "*" }, //$NON-NLS-1$ - new String[] { "*" }); //$NON-NLS-1$ - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackStateProvider.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackStateProvider.java deleted file mode 100644 index aac1c928d..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmCallStackStateProvider.java +++ /dev/null @@ -1,145 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old; - -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.common.core.NonNullUtils; -import org.eclipse.tracecompass.incubator.internal.rocm.core.Activator; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.dependency.HipApiHipActivityDependencyMaker; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.AbstractGpuEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.ApiEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.HipActivityEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.HsaActivityEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.HsaKernelEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.RoctxEventHandler; -import org.eclipse.tracecompass.incubator.rocm.core.analysis.dependency.IDependencyMaker; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; -import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; -import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents; - -import com.google.common.collect.ImmutableMap; - -/** - * This state provider creates callstacks and apply different event handlers. - * There are multiple types of events, each described in their respective - * handler. - * - * Attribute tree: - * - *
- * |- Processes
- * |  |- 
- * |  |  |- HIP Streams
- * |  |  |  |-  -> Each stream implemented as a callstack with corresponding
- * |  |  |  |              compute kernel activity.
- * |  |  |- Queues
- * |  |  |  |-  -> Each queue implemented as a callstack with corresponding
- * |  |  |  |             compute kernel activity.
- * |  |- Memory
- * |  |  |  |- Memory transfers -> Callstack with every memory transfer activity.
- * |  |- System
- * |  |  |- 
- * |  |  |  |-  -> Each API is a callstack showing which API call is executed.
- * 
- * - * @author Arnaud Fiorini - */ -public class RocmCallStackStateProvider extends AbstractTmfStateProvider { - - private static final String ID = "org.eclipse.tracecompass.incubator.rocm.core.stateprovider.interval"; //$NON-NLS-1$ - - private IDependencyMaker fDependencyMaker; - private Map fEventNames; - - /** - * @param trace - * trace to follow - */ - public RocmCallStackStateProvider(@NonNull ITmfTrace trace) { - super(trace, ID); - fDependencyMaker = getDependencyMaker((ITmfTraceWithPreDefinedEvents) trace); - fEventNames = buildEventNames(); - } - - private Map buildEventNames() { - ImmutableMap.Builder builder = ImmutableMap.builder(); - - builder.put(RocmStrings.HIP_API, new ApiEventHandler(this)); - builder.put(RocmStrings.HSA_API, new ApiEventHandler(this)); - builder.put(RocmStrings.HIP_ACTIVITY, new HipActivityEventHandler(this)); - builder.put(RocmStrings.ROCTX, new RoctxEventHandler(this)); - builder.put(RocmStrings.HSA_ACTIVITY, new HsaActivityEventHandler(this)); - if (fDependencyMaker == null) { // Disable HSA Activity in case we have - // hip activity events - builder.put(RocmStrings.KERNEL_EVENT, new HsaKernelEventHandler(this)); - } - - return builder.build(); - } - - private static IDependencyMaker getDependencyMaker(ITmfTraceWithPreDefinedEvents trace) { - IDependencyMaker dependencyMaker = null; - for (ITmfEventType eventType : (trace).getContainedEventTypes()) { - if (eventType.getName().equals(RocmStrings.HIP_ACTIVITY)) { - dependencyMaker = new HipApiHipActivityDependencyMaker(); - break; - } - } - return dependencyMaker; - } - - @Override - public int getVersion() { - return 1; - } - - @Override - public @NonNull ITmfStateProvider getNewInstance() { - return new RocmCallStackStateProvider(getTrace()); - } - - @Override - protected void eventHandle(@NonNull ITmfEvent event) { - String eventName = event.getName(); - ITmfStateSystemBuilder ssb = NonNullUtils.checkNotNull(getStateSystemBuilder()); - try { - AbstractGpuEventHandler handler = fEventNames.get(eventName); - if (handler != null) { - handler.handleEvent(ssb, event); - } - } catch (AttributeNotFoundException e) { - Activator.getInstance().logError("Exception while building the RocmCallStack state system", e); //$NON-NLS-1$ - } - if (fDependencyMaker != null) { - fDependencyMaker.processEvent(event, ssb); - } - } - - /** - * Accessor for the current dependency maker. - * - * The dependency maker is instantiated in the constructor depending the - * event types present in the rocm trace. - * - * @return dependency maker - */ - public IDependencyMaker getDependencyMaker() { - return fDependencyMaker; - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataAnalysis.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataAnalysis.java deleted file mode 100644 index a03bbcc43..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataAnalysis.java +++ /dev/null @@ -1,59 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old; - -import java.util.Objects; -import java.util.Set; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement; -import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement.PriorityLevel; -import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAnalysisEventRequirement; -import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; -import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; - -import com.google.common.collect.ImmutableSet; - -/** - * This analysis is used to store metadata of ROCm traces in the state system. - * For now it is only used to store mappings of function names and their - * corresponding cids. - * - * @author Arnaud Fiorini - */ -public class RocmMetadataAnalysis extends TmfStateSystemAnalysisModule { - - /** - * The ID of this analysis - */ - public static final String ID = "org.eclipse.tracecompass.incubator.rocm.core.analysis.functionname"; //$NON-NLS-1$ - - private Set<@NonNull TmfAbstractAnalysisRequirement> fAnalysisRequirements; - - @Override - protected @NonNull ITmfStateProvider createStateProvider() { - return new RocmMetadataStateProvider(Objects.requireNonNull(getTrace())); - } - - @Override - public Iterable<@NonNull TmfAbstractAnalysisRequirement> getAnalysisRequirements() { - Set<@NonNull TmfAbstractAnalysisRequirement> requirements = fAnalysisRequirements; - if (requirements == null) { - /* Initialize the requirements for the analysis */ - requirements = ImmutableSet.of(new TmfAnalysisEventRequirement( - ImmutableSet.of(RocmStrings.HIP_FUNCTION_NAME, RocmStrings.HSA_FUNCTION_NAME), - PriorityLevel.AT_LEAST_ONE)); - fAnalysisRequirements = requirements; - } - return requirements; - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataStateProvider.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataStateProvider.java deleted file mode 100644 index e89b4027f..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmMetadataStateProvider.java +++ /dev/null @@ -1,104 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.incubator.rocm.core.trace.old.RocmTrace; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider; -import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; - -/** - * This state provider stores each function name in the state system ordered - * with the function id. - * - * Attribute tree: - * - *
- * |- Function names -> begins at the start of the trace, each ns is a different function name.
- * 
- * - * @author Arnaud Fiorini - */ -public class RocmMetadataStateProvider extends AbstractTmfStateProvider { - - private static final String ID = "org.eclipse.tracecompass.incubator.rocm.core.stateprovider.functionname"; //$NON-NLS-1$ - - /** - * Attribute name for the function name map. - */ - public static final String FUNCTION_NAMES = "Function Names"; //$NON-NLS-1$ - - /** - * @param trace - * the trace to analyze - */ - public RocmMetadataStateProvider(@NonNull ITmfTrace trace) { - super(trace, ID); - } - - @Override - public int getVersion() { - return 1; - } - - @Override - public @NonNull ITmfStateProvider getNewInstance() { - return new RocmCallStackStateProvider(getTrace()); - } - - @Override - protected void eventHandle(@NonNull ITmfEvent event) { - if (event.getName().endsWith("function_name")) { //$NON-NLS-1$ - ITmfStateSystemBuilder ssb = getStateSystemBuilder(); - if (ssb == null) { - return; - } - int functionNameQuark = ssb.getQuarkAbsoluteAndAdd(FUNCTION_NAMES); - int apiQuark = ssb.getQuarkRelativeAndAdd(functionNameQuark, - ((Integer) ((RocmTrace) event.getTrace()).getApiId(event.getName().split("_")[0] + "_api")).toString()); //$NON-NLS-1$ //$NON-NLS-2$ - String functionName = event.getContent().getFieldValue(String.class, RocmStrings.NAME); - Integer cid = event.getContent().getFieldValue(Integer.class, RocmStrings.CORRELATION_ID); - if (functionName == null || cid == null) { - return; - } - ssb.modifyAttribute(ssb.getStartTime() + cid, functionName, apiQuark); - } - } - - /** - * Static function to get the function id from an api event cid. - * - * @param event - * An API event - * @return functionId - */ - public static int getFunctionId(@NonNull ITmfEvent event) { - int nApi = ((RocmTrace) event.getTrace()).getNApi(); - Integer cid = event.getContent().getFieldValue(Integer.class, RocmStrings.CID); - if (cid == null) { - cid = event.getContent().getFieldValue(Integer.class, RocmStrings.CORRELATION_ID); - } - if (cid == null) { - return -1; - } - int apiId; - if (event.getName().endsWith("function_name")) { //$NON-NLS-1$ - apiId = ((RocmTrace) event.getTrace()).getApiId(event.getName().split("_")[0] + "_api"); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - apiId = ((RocmTrace) event.getTrace()).getApiId(event.getName()); - } - return cid * nApi + apiId; - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmStrings.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmStrings.java deleted file mode 100644 index 16f540f1d..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/RocmStrings.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old; - -/** - * Strings used in the ROCm module - * - * @author Arnaud Fiorini - * @noimplement This interface is not intended to be implemented by clients. - */ -@SuppressWarnings({ "javadoc", "nls" }) -public interface RocmStrings { - /* Event types */ - String GPU_KERNEL = "compute_kernels_hsa"; - String HSA_API = "hsa_api"; - String HIP_API = "hip_api"; - String HCC_OPS = "hcc_ops"; - String ROCTX = "roctx"; - String ASYNC_COPY = "async_copy"; - String HIP_ACTIVITY = "hip_activity"; - String HSA_ACTIVITY = "hsa_activity"; - String KERNEL_EVENT = "kernel_event"; - String HIP_FUNCTION_NAME = "hip_function_name"; - String HSA_FUNCTION_NAME = "hsa_function_name"; - String METRIC_DOUBLE = "metric_double"; - String METRIC_INTEGER = "metric_uint64"; - String METRIC_NAME = "metric_name"; - String METRIC_NAME_END = "metric_name_end"; - - /* Field names */ - String NAME = "name"; - String ARGS = "args"; - String KERNEL_NAME = "kernel_name"; - String KERNEL_DISPATCH_ID = "kernel_dispatch_id"; - String GPU_ID = "gpu_id"; - String CORRELATION_ID = "correlation_id"; - String DEVICE_ID = "device_id"; - String QUEUE_ID = "queue_id"; - String QUEUE_INDEX = "queue_index"; - String STREAM_ID = "stream_id"; - /** Function call id, is used to identify the function name */ - String CID = "cid"; - String TID = "tid"; - String PID = "pid"; - String ID = "id"; - String END = "end"; - String MESSAGE = "message"; - String VALUE = "value"; - - /* State categories */ - String EDGES = "Edges"; - String GPU_ACTIVITY = "GPU Activity"; - String GPU = "GPU "; - String GAP_ANALYSIS = "Gap Analysis"; - String THREAD = "Thread "; - String SYSTEM = "System"; - String MEMORY = "Memory"; - String MEMORY_TRANSFERS = "Memory Transfers"; - String STREAMS = "HIP Streams"; - String STREAM = "Stream "; - String QUEUES = "Queues"; - String QUEUE = "Queue "; - String GPU_KERNELS = "GPU Kernels"; - - /* Event Names */ - String KERNEL_EXECUTION = "KernelExecution"; - String KERNEL_LAUNCH = "hipLaunchKernel"; - String HIP_DEVICE_SYNCHRONIZE = "hipDeviceSynchronize"; - String COPY = "Copy"; - - /* State values */ - String IDLE = "Idle"; -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmApiCtfPluginEventLayout.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmApiCtfPluginEventLayout.java new file mode 100644 index 000000000..cb0d63c55 --- /dev/null +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmApiCtfPluginEventLayout.java @@ -0,0 +1,26 @@ +package org.eclipse.tracecompass.incubator.rocm.core.ctfplugin.trace; + +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTraceEventLayout.IApiEventLayout; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; + +public abstract class RocmApiCtfPluginEventLayout implements IApiEventLayout { + + @Override + public boolean isBeginEvent(ITmfEvent event) { + return event.getName().endsWith("_begin") || event.getName().endsWith("Begin"); + } + + @Override + public String getEventName(ITmfEvent event) { + if (isBeginEvent(event)) { + if (event.getName().startsWith("hip")) { + return event.getName().substring(0, event.getName().length() - 5); + } + return event.getName().substring(0, event.getName().length() - 6); + } + if (event.getName().startsWith("hip")) { + return event.getName().substring(0, event.getName().length() - 3); + } + return event.getName().substring(0, event.getName().length() - 4); + } +} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTrace.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTrace.java new file mode 100644 index 000000000..574ec75ec --- /dev/null +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTrace.java @@ -0,0 +1,166 @@ +package org.eclipse.tracecompass.incubator.rocm.core.ctfplugin.trace; + +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTrace; +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTraceEventLayout; +import org.eclipse.tracecompass.incubator.internal.rocm.core.Activator; +import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmEventLayout; +import org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; +import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; +import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; +import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; +import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation; +import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo; +import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; + +public class RocmCtfPluginTrace extends RocmTrace implements IGpuTrace { + + private @Nullable Boolean fIsContainingKernelGpuActivity; + + private ImmutableList> fAspects = ImmutableList.of(TID_ASPECT, FUNCTION_NAME_ASPECT); + + private static final int MAX_OPERATIONS_UNTIL_OPERATION_END = 100; + private static final int CONFIDENCE = 100; + + @Override + public @NonNull IGpuTraceEventLayout getGpuTraceEventLayout() { + return RocmCtfPluginTraceEventLayout.getInstance(); + } + + @Override + public Iterable> getEventAspects() { + return fAspects; + } + + @Override + @org.eclipse.jdt.annotation.NonNullByDefault({}) + public void initTrace(final IResource resource, final String path, + final Class eventType) throws TmfTraceException { + super.initTrace(resource, path, eventType); + + ImmutableList.Builder> builder = new Builder<>(); + builder.addAll(super.getEventAspects()); + fAspects = builder.build(); + lookForKernelGpuActivityMetadata(); + } + + @Override + public @Nullable IStatus validate(final @Nullable IProject project, final @Nullable String path) { + IStatus status = super.validate(project, path); + if (status instanceof CtfTraceValidationStatus) { + Map environment = ((CtfTraceValidationStatus) status).getEnvironment(); + /* Make sure the domain is "kernel" in the trace's env vars */ + String domain = environment.get("tracer_name"); //$NON-NLS-1$ + boolean isRocprofilerVersionPresent = environment.get("rocprofiler_version") != null; //$NON-NLS-1$ + if (domain == null || !domain.equals("\"barectf\"")) { //$NON-NLS-1$ + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "This trace was not recognized as a ROCm trace. You can update your rocprofiler version or you can change manually the tracer name to \"rocprof\" in the metadata file to force the validation."); //$NON-NLS-1$ + } + if (isRocprofilerVersionPresent) { + return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); + } + } + return status; + } + + /** + * Look for metadata indicating if the trace contains kernel gpu activity + * events. Otherwise if it is requested, let the method + * isContainingKernelGpuActivity to calculate this boolean if the metadata + * is not present. + */ + private void lookForKernelGpuActivityMetadata() { + Map environment = this.getEnvironment(); + /* Make sure the domain is "kernel" in the trace's env vars */ + String rocprofilerArgs = environment.get("args"); //$NON-NLS-1$ + if (rocprofilerArgs == null) { + return; + } else if (rocprofilerArgs.contains("--sys-trace") || rocprofilerArgs.contains("--hsa-trace")) { //$NON-NLS-1$ //$NON-NLS-2$ + fIsContainingKernelGpuActivity = true; + } + fIsContainingKernelGpuActivity = false; + } + + /** + * Look for kernel GPU activity in the trace and tries to correlate it with + * API events. + * + * @return if the trace contains GPU kernel activity. + */ + public boolean isContainingKernelGpuActivity() { + if (fIsContainingKernelGpuActivity != null) { + return fIsContainingKernelGpuActivity; + } + ITmfContext context = seekEvent(new CtfLocation(new CtfLocationInfo(0L, 0L))); + ITmfEvent event = getNext(context); + Long hipLaunchKernelEventCorrelationId = -1L; + RocmEventLayout layout = new RocmEventLayout(); + Integer i = 0; + while (event != null && i < MAX_OPERATIONS_UNTIL_OPERATION_END) { + Long correlationId = event.getContent().getFieldValue(Long.class, layout.fieldCorrelationId()); + if (correlationId == null) { + event = getNext(context); + continue; + } + if (event.getName().equals(layout.hipLaunchKernelBegin())) { + if (hipLaunchKernelEventCorrelationId == -1) { + hipLaunchKernelEventCorrelationId = correlationId; + } + i += 1; + } + if (event.getName().equals(layout.getHipOperationBegin()) && correlationId.equals(hipLaunchKernelEventCorrelationId)) { + fIsContainingKernelGpuActivity = true; + return fIsContainingKernelGpuActivity; + } + event = getNext(context); + } + fIsContainingKernelGpuActivity = false; + return fIsContainingKernelGpuActivity; + } + + private static final ITmfEventAspect TID_ASPECT = new ITmfEventAspect<>() { + @Override + public String getName() { + return "Thread ID"; //$NON-NLS-1$ + } + + @Override + public String getHelpText() { + return ITmfEventAspect.EMPTY_STRING; + } + + @Override + public @Nullable Integer resolve(ITmfEvent event) { + return event.getContent().getFieldValue(Integer.class, RocmCtfPluginTraceEventLayout.getInstance().fieldThreadId()); + } + }; + + private static final ITmfEventAspect FUNCTION_NAME_ASPECT = new ITmfEventAspect<>() { + @Override + public String getName() { + return "Function name"; //$NON-NLS-1$ + } + + @Override + public String getHelpText() { + return ITmfEventAspect.EMPTY_STRING; + } + + @Override + public @Nullable String resolve(ITmfEvent event) { + return RocmCtfPluginTraceEventLayout.getInstance().getCorrespondingApiLayout(event).getEventName(event); + } + }; +} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTraceEventLayout.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTraceEventLayout.java new file mode 100644 index 000000000..cd389e339 --- /dev/null +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/RocmCtfPluginTraceEventLayout.java @@ -0,0 +1,85 @@ +package org.eclipse.tracecompass.incubator.rocm.core.ctfplugin.trace; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTraceEventLayout; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; + +public class RocmCtfPluginTraceEventLayout implements IGpuTraceEventLayout { + + private static @Nullable RocmCtfPluginTraceEventLayout INSTANCE; + private static List fApiLayouts = List.of(new HsaApiEventLayout(), new HipApiEventLayout()); + + /** + * The instance of this event layout + *

+ * This object is completely immutable, so no need to create additional + * instances via the constructor. + * + * @return the instance + */ + public static synchronized RocmCtfPluginTraceEventLayout getInstance() { + RocmCtfPluginTraceEventLayout instance = INSTANCE; + if (instance == null) { + instance = new RocmCtfPluginTraceEventLayout(); + INSTANCE = instance; + } + return instance; + } + + @Override + public @NonNull Collection getApiLayouts() { + return fApiLayouts; + } + + @Override + public @NonNull IApiEventLayout getCorrespondingApiLayout(ITmfEvent event) { + if (event.getName().startsWith("hsa")) { //$NON-NLS-1$ + return fApiLayouts.get(0); + } + return fApiLayouts.get(1); + } + + @Override + public boolean isMemcpyBegin(ITmfEvent event) { + return false; + } + + @Override + public boolean isLaunchBegin(ITmfEvent event) { + return false; + } + + @Override + public boolean isApiEvent(ITmfEvent event) { + String name = event.getName(); + return (name.startsWith("hsa") && !name.startsWith("hsa_op")) || (name.startsWith("hip") && !name.startsWith("hip_op")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public @NonNull String fieldThreadId() { + return "context._thread_id"; //$NON-NLS-1$ + } + + @Override + public @NonNull String fieldDuration() { + return ""; //$NON-NLS-1$ + } + + public static class HsaApiEventLayout extends RocmApiCtfPluginEventLayout { + @Override + public String getApiName() { + return "HSA"; //$NON-NLS-1$ + } + } + + public static class HipApiEventLayout extends RocmApiCtfPluginEventLayout { + @Override + public String getApiName() { + return "HIP"; //$NON-NLS-1$ + } + } +} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/old/package-info.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/package-info.java similarity index 72% rename from analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/old/package-info.java rename to analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/package-info.java index 76107c260..68c0b0a2a 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/old/package-info.java +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/ctfplugin/trace/package-info.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023 École Polytechnique de Montréal + * Copyright (c) 2024 École Polytechnique de Montréal * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License 2.0 which @@ -9,4 +9,5 @@ * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.tracecompass.incubator.rocm.core.trace.old; +@org.eclipse.jdt.annotation.NonNullByDefault +package org.eclipse.tracecompass.incubator.rocm.core.ctfplugin.trace; \ No newline at end of file diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmApiEventLayout.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmApiEventLayout.java new file mode 100644 index 000000000..d774cb6bb --- /dev/null +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmApiEventLayout.java @@ -0,0 +1,20 @@ +package org.eclipse.tracecompass.incubator.rocm.core.exatracer.trace; + +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTraceEventLayout.IApiEventLayout; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; + +public abstract class RocmApiEventLayout implements IApiEventLayout { + + @Override + public boolean isBeginEvent(ITmfEvent event) { + return event.getName().endsWith("_entry"); + } + + @Override + public String getEventName(ITmfEvent event) { + if (isBeginEvent(event)) { + return event.getName().substring(4, event.getName().length() - 6); + } + return event.getName().substring(4, event.getName().length() - 5); + } +} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTrace.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTrace.java new file mode 100644 index 000000000..b1cf9975a --- /dev/null +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTrace.java @@ -0,0 +1,95 @@ +package org.eclipse.tracecompass.incubator.rocm.core.exatracer.trace; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxPidAspect; +import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect; +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTrace; +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTraceEventLayout; +import org.eclipse.tracecompass.incubator.internal.rocm.core.Activator; +import org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; +import org.eclipse.tracecompass.tmf.core.event.aspect.TmfEventFieldAspect; +import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; +import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; + +public class RocmExatracerTrace extends RocmTrace implements IGpuTrace { + + private static final int CONFIDENCE = 100; + + public RocmExatracerTrace() { + super(); + } + + public static TmfEventFieldAspect fNameAspect = new TmfEventFieldAspect("Name", "name", ITmfEvent::getContent); //$NON-NLS-1$ //$NON-NLS-2$ + + public static LinuxPidAspect fVpidAspect = new LinuxPidAspect() { + + @Override + public @Nullable Integer resolve(ITmfEvent event) { + Long fieldValue = event.getContent().getFieldValue(Long.class, "context._vpid"); //$NON-NLS-1$ + if (fieldValue != null) { + return fieldValue.intValue(); + } + return null; + } + }; + public static LinuxTidAspect fVtidAspect = new LinuxTidAspect() { + @Override + public @Nullable Integer resolve(ITmfEvent event) { + Long fieldValue = event.getContent().getFieldValue(Long.class, "context._vtid"); //$NON-NLS-1$ + if (fieldValue != null) { + return fieldValue.intValue(); + } + fieldValue = event.getContent().getFieldValue(Long.class, RocmExatracerTraceEventLayout.getInstance().fieldThreadId()); //$NON-NLS-1$ + if (fieldValue != null) { + return fieldValue.intValue(); + } + return null; + } + }; + public static TmfEventFieldAspect fBackendAspect = new TmfEventFieldAspect("Backend", "context._backend", ITmfEvent::getContent); //$NON-NLS-1$ //$NON-NLS-2$ + + @Override + public IStatus validate(@Nullable IProject project, @Nullable String path) { + IStatus status = super.validate(project, path); + if (status instanceof CtfTraceValidationStatus) { + Map environment = ((CtfTraceValidationStatus) status).getEnvironment(); + /* Make sure the domain is "kernel" in the trace's env vars */ + String domain = environment.get("tracer_name"); //$NON-NLS-1$ + if (domain == null || !domain.equals("\"lttng-ust\"")) { //$NON-NLS-1$ + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "This trace was not recognized as a ROCm trace. You can update your rocprofiler version or you can change manually the tracer name to \"rocprof\" in the metadata file to force the validation."); //$NON-NLS-1$ + } + return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); + } + return status; + } + + @Override + public Iterable> getEventAspects() { + Iterable> oldAspects = super.getEventAspects(); + List> aspects = new ArrayList<>(); + for (ITmfEventAspect aspect : oldAspects) { + aspects.add(aspect); + } + aspects.add(fNameAspect); + aspects.add(fVpidAspect); + aspects.add(fVtidAspect); + aspects.add(fBackendAspect); + return aspects; + } + + @Override + public @NonNull IGpuTraceEventLayout getGpuTraceEventLayout() { + return RocmExatracerTraceEventLayout.getInstance(); + } +} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTraceEventLayout.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTraceEventLayout.java new file mode 100644 index 000000000..7de8c282e --- /dev/null +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/RocmExatracerTraceEventLayout.java @@ -0,0 +1,86 @@ +package org.eclipse.tracecompass.incubator.rocm.core.exatracer.trace; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.incubator.gpu.core.trace.IGpuTraceEventLayout; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; + +import com.google.common.collect.ImmutableList; + +public class RocmExatracerTraceEventLayout implements IGpuTraceEventLayout { + + private static @Nullable RocmExatracerTraceEventLayout INSTANCE; + private static List fApiLayouts = ImmutableList.of(new HsaApiEventLayout(), new HipApiEventLayout()); + + /** + * The instance of this event layout + *

+ * This object is completely immutable, so no need to create additional + * instances via the constructor. + * + * @return the instance + */ + public static synchronized RocmExatracerTraceEventLayout getInstance() { + RocmExatracerTraceEventLayout instance = INSTANCE; + if (instance == null) { + instance = new RocmExatracerTraceEventLayout(); + INSTANCE = instance; + } + return instance; + } + + @Override + public @NonNull Collection getApiLayouts() { + return fApiLayouts; + } + + @Override + public @NonNull IApiEventLayout getCorrespondingApiLayout(ITmfEvent event) { + if (event.getName().startsWith("hsa")) { //$NON-NLS-1$ + return fApiLayouts.get(0); + } + return fApiLayouts.get(1); + } + + @Override + public boolean isMemcpyBegin(ITmfEvent event) { + return false; + } + + @Override + public boolean isLaunchBegin(ITmfEvent event) { + return false; + } + + @Override + public boolean isApiEvent(ITmfEvent event) { + return event.getName().startsWith("hsa") || event.getName().startsWith("hip"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public @NonNull String fieldThreadId() { + return "lttng_thread_id"; //$NON-NLS-1$ + } + + @Override + public @NonNull String fieldDuration() { + return ""; //$NON-NLS-1$ + } + + public static class HsaApiEventLayout extends RocmApiEventLayout { + @Override + public String getApiName() { + return "HSA"; //$NON-NLS-1$ + } + } + + public static class HipApiEventLayout extends RocmApiEventLayout { + @Override + public String getApiName() { + return "HIP"; //$NON-NLS-1$ + } + } +} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/package-info.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/package-info.java similarity index 72% rename from analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/package-info.java rename to analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/package-info.java index fa9d33bf6..fd0f0dd78 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/internal/rocm/core/analysis/old/package-info.java +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/exatracer/trace/package-info.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023 École Polytechnique de Montréal + * Copyright (c) 2024 École Polytechnique de Montréal * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License 2.0 which @@ -8,4 +8,6 @@ * * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old; \ No newline at end of file + +@org.eclipse.jdt.annotation.NonNullByDefault +package org.eclipse.tracecompass.incubator.rocm.core.exatracer.trace; \ No newline at end of file diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/GpuAspect.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/GpuAspect.java index 3813c9a34..0a7e48eaf 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/GpuAspect.java +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/GpuAspect.java @@ -12,9 +12,7 @@ package org.eclipse.tracecompass.incubator.rocm.core.trace; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.event.aspect.TmfDeviceAspect; import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; @@ -55,14 +53,6 @@ public String getHelpText() { if (!(event instanceof CtfTmfEvent)) { return null; } - ITmfEventField content = event.getContent(); - if (content != null) { - Integer fieldValue = content.getFieldValue(Integer.class, RocmStrings.DEVICE_ID); - if (fieldValue == null) { - fieldValue = content.getFieldValue(Integer.class, RocmStrings.GPU_ID); - } - return fieldValue == null ? null : fieldValue.intValue(); - } return null; } diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmAspects.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmAspects.java index b015fec57..42f22a9e6 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmAspects.java +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmAspects.java @@ -14,8 +14,6 @@ import java.util.List; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.old.ApiEventHandler; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; @@ -41,167 +39,16 @@ public String getHelpText() { @Override public @Nullable Integer resolve(ITmfEvent event) { - return event.getContent().getFieldValue(Integer.class, RocmStrings.PID); + return event.getContent().getFieldValue(Integer.class, "context._pid"); } }; - private static final ITmfEventAspect TID_ASPECT = new ITmfEventAspect<>() { - @Override - public String getName() { - return Messages.getMessage(Messages.AspectName_TID); - } - - @Override - public String getHelpText() { - return ITmfEventAspect.EMPTY_STRING; - } - - @Override - public @Nullable Integer resolve(ITmfEvent event) { - return event.getContent().getFieldValue(Integer.class, RocmStrings.TID); - } - }; - - private static final ITmfEventAspect QUEUE_ID_ASPECT = new ITmfEventAspect<>() { - @Override - public String getName() { - return Messages.getMessage(Messages.AspectName_QueueID); - } - - @Override - public String getHelpText() { - return ITmfEventAspect.EMPTY_STRING; - } - - @Override - public @Nullable Integer resolve(ITmfEvent event) { - return event.getContent().getFieldValue(Integer.class, RocmStrings.QUEUE_ID); - } - }; - - private static final ITmfEventAspect STREAM_ID_ASPECT = new ITmfEventAspect<>() { - @Override - public String getName() { - return Messages.getMessage(Messages.AspectName_StreamID); - } - - @Override - public String getHelpText() { - return ITmfEventAspect.EMPTY_STRING; - } - - @Override - public @Nullable Integer resolve(ITmfEvent event) { - return event.getContent().getFieldValue(Integer.class, RocmStrings.STREAM_ID); - } - }; - - private static final ITmfEventAspect QUEUE_INDEX_ASPECT = new ITmfEventAspect<>() { - @Override - public String getName() { - return Messages.getMessage(Messages.AspectName_QueueIndex); - } - - @Override - public String getHelpText() { - return ITmfEventAspect.EMPTY_STRING; - } - @Override - public @Nullable Integer resolve(ITmfEvent event) { - return event.getContent().getFieldValue(Integer.class, RocmStrings.QUEUE_INDEX); - } - }; - - private static final ITmfEventAspect FUNCTION_NAME_ASPECT = new ITmfEventAspect<>() { - @Override - public String getName() { - return Messages.getMessage(Messages.AspectName_FunctionName); - } - - @Override - public String getHelpText() { - return ITmfEventAspect.EMPTY_STRING; - } - - @Override - public @Nullable String resolve(ITmfEvent event) { - if (event.getName().endsWith("_api")) { //$NON-NLS-1$ - return ApiEventHandler.getFunctionApiName(event); - } - String name = event.getContent().getFieldValue(String.class, RocmStrings.NAME); - if (name == null) { - name = event.getContent().getFieldValue(String.class, RocmStrings.KERNEL_NAME); - } - return name; - } - }; - - private static final List> ASPECTS = ImmutableList.of( - getPIDAspect(), - getTIDAspect(), - getQueueIDAspect(), - getStreamIDAspect(), - getQueueIndexAspect(), - getFunctionNameAspect()); + private static final List> ASPECTS = ImmutableList.of(PID_ASPECT); private RocmAspects() { } - /** - * Get the aspect for the event pid - * - * @return The process ID - */ - public static ITmfEventAspect getPIDAspect() { - return PID_ASPECT; - } - - /** - * Get the aspect for the event tid - * - * @return The thread ID - */ - public static ITmfEventAspect getTIDAspect() { - return TID_ASPECT; - } - - /** - * Get the aspect for the event HSA queue ID - * - * @return The queue ID - */ - public static ITmfEventAspect getQueueIDAspect() { - return QUEUE_ID_ASPECT; - } - - /** - * Get the aspect for the event HIP stream ID - * - * @return The stream ID - */ - public static ITmfEventAspect getStreamIDAspect() { - return STREAM_ID_ASPECT; - } - - /** - * Get the aspect for the event queue index - * - * @return The event index in its HSA queue - */ - public static ITmfEventAspect getQueueIndexAspect() { - return QUEUE_INDEX_ASPECT; - } - - /** - * Get the name of the function executed represented by the event - * - * @return The function name - */ - public static ITmfEventAspect getFunctionNameAspect() { - return FUNCTION_NAME_ASPECT; - } - /** * Get the list of all Rocm aspects * diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmCounterAspect.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmCounterAspect.java deleted file mode 100644 index 3fa730f5a..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmCounterAspect.java +++ /dev/null @@ -1,114 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.rocm.core.trace; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.analysis.counters.core.CounterAnalysis; -import org.eclipse.tracecompass.analysis.counters.core.aspects.CounterAspect; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; - -/** - * Counter aspects to make use of the Counter analysis - * - * @author Arnaud Fiorini - */ -public class RocmCounterAspect extends CounterAspect { - - private Integer fCounterId; - - /** - * Rocm Counter Aspect constructor - * - * @param fieldName - * The field of the performance counter - * @param label - * Label describing the performance counter - * @param class1 - * The Gpu group to which the counter is associated - * @param counterId - * the counter id which allows to retrieve the label after - * initialization - */ - public RocmCounterAspect(@NonNull String fieldName, @NonNull String label, Class<@NonNull GpuAspect> class1, Integer counterId) { - super(fieldName, label, class1); - fCounterId = counterId; - } - - /** - * Rocm Counter Aspect constructor - * - * @param fieldName - * The field of the performance counter - * @param label - * Label describing the performance counter - * @param counterId - * the counter id which allows to retrieve the label after - * initialization - */ - public RocmCounterAspect(@NonNull String fieldName, @NonNull String label, Integer counterId) { - super(fieldName, label); - fCounterId = counterId; - } - - @Override - public boolean isCumulative() { - return false; - } - - @Override - public @Nullable Number resolve(@NonNull ITmfEvent event) { - Integer counterId = event.getContent().getFieldValue(Integer.class, RocmStrings.ID); - if (fCounterId.equals(counterId)) { - if (event.getName().equals(RocmStrings.METRIC_DOUBLE)) { - return event.getContent().getFieldValue(Double.class, RocmStrings.VALUE); - } else if (event.getName().equals(RocmStrings.METRIC_INTEGER)) { - return event.getContent().getFieldValue(Long.class, RocmStrings.VALUE); - } - } - if (event.getName().equals(RocmStrings.HIP_ACTIVITY)) { - CounterAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(event.getTrace(), - CounterAnalysis.class, CounterAnalysis.ID); - if (module == null) { - return null; - } - ITmfStateSystem ss = module.getStateSystem(); - if (ss == null) { - return null; - } - try { - String gpuId = event.getContent().getFieldValue(String.class, RocmStrings.DEVICE_ID); - int groupQuark = ss.getQuarkAbsolute(CounterAnalysis.GROUPED_COUNTER_ASPECTS_ATTRIB); - int gpuGroupQuark = ss.getQuarkRelative(groupQuark, GpuAspect.INSTANCE.getName()); - int gpuQuark = ss.getQuarkRelative(gpuGroupQuark, gpuId); - int counterQuark = ss.getQuarkRelative(gpuQuark, this.getName()); - Long timestampEnd = event.getContent().getFieldValue(Long.class, RocmStrings.END); - if (timestampEnd != null) { - long valueBefore = ss.querySingleState(event.getTimestamp().getValue(), counterQuark).getValueLong(); - long valueAfter = ss.querySingleState(((CtfTmfTrace) event.getTrace()).timestampCyclesToNanos(timestampEnd), counterQuark).getValueLong(); - return valueAfter - valueBefore; - } - } catch (AttributeNotFoundException | StateSystemDisposedException e) { - // Either the analysis is not available or the state system has - // not been written yet. - return null; - } - } - return null; - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTrace.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTrace.java index b58cd6bcd..6eb43863d 100644 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTrace.java +++ b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTrace.java @@ -11,26 +11,14 @@ package org.eclipse.tracecompass.incubator.rocm.core.trace; import java.util.Collection; -import java.util.Map; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.internal.rocm.core.Activator; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmEventLayout; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects; import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; -import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; -import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; -import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation; -import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo; import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; @@ -50,22 +38,12 @@ public class RocmTrace extends CtfTmfTrace { TmfBaseAspects.getEventTypeAspect(), TmfBaseAspects.getContentsAspect(), TmfBaseAspects.getTraceNameAspect()); - private static final int CONFIDENCE = 100; - private static final int MAX_OPERATIONS_UNTIL_OPERATION_END = 100; /** Collection of aspects, default values */ private @NonNull Collection> fAspects = ImmutableSet.copyOf(ROCM_CTF_ASPECTS); - private @Nullable Boolean fIsContainingKernelGpuActivity; - - /** - * Constructor - */ - public RocmTrace() { - super(); - } @Override - public Iterable> getEventAspects() { + public @NonNull Iterable> getEventAspects() { return fAspects; } @@ -78,80 +56,5 @@ public void initTrace(final IResource resource, final String path, builder.add(GpuAspect.INSTANCE); builder.addAll(ROCM_CTF_ASPECTS); fAspects = builder.build(); - lookForKernelGpuActivityMetadata(); - } - - /** - * Look for metadata indicating if the trace contains kernel gpu activity - * events. Otherwise if it is requested, let the method - * isContainingKernelGpuActivity to calculate this boolean if the metadata - * is not present. - */ - private void lookForKernelGpuActivityMetadata() { - Map environment = this.getEnvironment(); - /* Make sure the domain is "kernel" in the trace's env vars */ - String rocprofilerArgs = environment.get("args"); //$NON-NLS-1$ - if (rocprofilerArgs == null) { - return; - } else if (rocprofilerArgs.contains("--sys-trace") || rocprofilerArgs.contains("--hsa-trace")) { //$NON-NLS-1$ //$NON-NLS-2$ - fIsContainingKernelGpuActivity = true; - } - fIsContainingKernelGpuActivity = false; - } - - @Override - public @Nullable IStatus validate(final @Nullable IProject project, final @Nullable String path) { - IStatus status = super.validate(project, path); - if (status instanceof CtfTraceValidationStatus) { - Map environment = ((CtfTraceValidationStatus) status).getEnvironment(); - /* Make sure the domain is "kernel" in the trace's env vars */ - String domain = environment.get("tracer_name"); //$NON-NLS-1$ - boolean isRocTracerVersionPresent = environment.get("roc_tracer_version") != null; //$NON-NLS-1$ - if (domain == null || !domain.equals("\"barectf\"")) { //$NON-NLS-1$ - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "This trace was not recognized as a ROCm trace. You can update your rocprofiler version or you can change manually the tracer name to \"rocprof\" in the metadata file to force the validation."); //$NON-NLS-1$ - } - if (isRocTracerVersionPresent) { - return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); - } - } - return status; - } - - /** - * Look for kernel GPU activity in the trace and tries to correlate it with - * API events. - * - * @return if the trace contains GPU kernel activity. - */ - public boolean isContainingKernelGpuActivity() { - if (fIsContainingKernelGpuActivity != null) { - return fIsContainingKernelGpuActivity; - } - ITmfContext context = seekEvent(new CtfLocation(new CtfLocationInfo(0L, 0L))); - ITmfEvent event = getNext(context); - Long hipLaunchKernelEventCorrelationId = -1L; - RocmEventLayout layout = new RocmEventLayout(); - Integer i = 0; - while (event != null && i < MAX_OPERATIONS_UNTIL_OPERATION_END) { - Long correlationId = event.getContent().getFieldValue(Long.class, layout.fieldCorrelationId()); - if (correlationId == null) { - event = getNext(context); - continue; - } - if (event.getName().equals(layout.hipLaunchKernelBegin())) { - if (hipLaunchKernelEventCorrelationId == -1) { - hipLaunchKernelEventCorrelationId = correlationId; - } - i += 1; - } - if (event.getName().equals(layout.getHipOperationBegin()) && correlationId.equals(hipLaunchKernelEventCorrelationId)) { - fIsContainingKernelGpuActivity = true; - return fIsContainingKernelGpuActivity; - } - event = getNext(context); - } - fIsContainingKernelGpuActivity = false; - return fIsContainingKernelGpuActivity; } } diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProvider.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProvider.java deleted file mode 100644 index ffee18c84..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProvider.java +++ /dev/null @@ -1,99 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.rocm.core.trace; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.internal.rocm.core.Activator; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmMetadataAnalysis; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmMetadataStateProvider; -import org.eclipse.tracecompass.incubator.rocm.core.trace.old.RocmTrace; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; -import org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider; -import org.eclipse.tracecompass.tmf.core.symbols.TmfResolvedSymbol; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; - -/** - * Symbol provider to resolve api function ids to their names - * - * @author Arnaud Fiorini - */ -public class RocmTraceSymbolProvider implements ISymbolProvider { - - private @NonNull ITmfTrace fTrace; - - /** - * Constructor - * - * @param trace - * The trace this provider is for - */ - public RocmTraceSymbolProvider(@NonNull ITmfTrace trace) { - fTrace = trace; - } - - @Override - public @NonNull ITmfTrace getTrace() { - return fTrace; - } - - @Override - public void loadConfiguration(@Nullable IProgressMonitor monitor) { - // No configuration - } - - @Override - public @Nullable TmfResolvedSymbol getSymbol(long address) { - RocmMetadataAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(getTrace(), - RocmMetadataAnalysis.class, RocmMetadataAnalysis.ID); - if (module == null) { - /* - * The analysis is not available for this trace, we won't be able to - * find the information. - */ - return null; - } - ITmfStateSystem ss = module.getStateSystem(); - if (ss == null || address == -1) { - return new TmfResolvedSymbol(address, StringUtils.EMPTY); - } - String functionName; - try { - RocmTrace trace = (RocmTrace) getTrace(); - int nApi = trace.getNApi(); - Integer apiId = (int) (address % nApi); - int cid = (int) ((address - apiId) / nApi); - int functionNameQuark = ss.getQuarkAbsolute(RocmMetadataStateProvider.FUNCTION_NAMES); - int apiQuark = ss.getQuarkRelative(functionNameQuark, apiId.toString()); - functionName = ss.querySingleState(ss.getStartTime() + cid, apiQuark).getValueString(); - if (functionName == null) { - functionName = StringUtils.EMPTY; - Activator.getInstance().logWarning("The function name with cid " + cid + //$NON-NLS-1$ - " and the apiId " + apiId + " was not found in the state system"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } catch (AttributeNotFoundException | StateSystemDisposedException e) { - Activator.getInstance().logError(e.getMessage()); - return new TmfResolvedSymbol(address, StringUtils.EMPTY); - } - return new TmfResolvedSymbol(address, functionName); - } - - @Override - public @Nullable TmfResolvedSymbol getSymbol(int pid, long timestamp, long address) { - return getSymbol(address); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProviderFactory.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProviderFactory.java deleted file mode 100644 index bc51e798a..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/RocmTraceSymbolProviderFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.rocm.core.trace; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmMetadataAnalysis; -import org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider; -import org.eclipse.tracecompass.tmf.core.symbols.ISymbolProviderFactory; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; - -/** - * Factory for the ROCm Symbol provider - * - * @author Arnaud Fiorini - */ -public class RocmTraceSymbolProviderFactory implements ISymbolProviderFactory { - - @Override - public @Nullable ISymbolProvider createProvider(@NonNull ITmfTrace trace) { - RocmMetadataAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, - RocmMetadataAnalysis.class, RocmMetadataAnalysis.ID); - if (module == null) { - return null; - } - return new RocmTraceSymbolProvider(trace); - } -} diff --git a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/old/RocmTrace.java b/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/old/RocmTrace.java deleted file mode 100644 index 5dcb425cc..000000000 --- a/analyses/org.eclipse.tracecompass.incubator.rocm.core/src/org/eclipse/tracecompass/incubator/rocm/core/trace/old/RocmTrace.java +++ /dev/null @@ -1,232 +0,0 @@ -/********************************************************************** - * Copyright (c) 2022 École Polytechnique de Montréal - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License 2.0 which - * accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - **********************************************************************/ - -package org.eclipse.tracecompass.incubator.rocm.core.trace.old; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.tracecompass.incubator.internal.rocm.core.Activator; -import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.old.RocmStrings; -import org.eclipse.tracecompass.incubator.rocm.core.trace.GpuAspect; -import org.eclipse.tracecompass.incubator.rocm.core.trace.RocmAspects; -import org.eclipse.tracecompass.incubator.rocm.core.trace.RocmCounterAspect; -import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; -import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; -import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; -import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects; -import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; -import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter; -import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; -import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext; -import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; -import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation; -import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; -import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.common.collect.ImmutableSet; - -/** - * Traces generated by the ROCm environment (ROC-tracer and/or ROC-profiler) - * that use the CTF format. These traces are identified using the tracer_name - * environment variable. - * - * @author Arnaud Fiorini - */ -public class RocmTrace extends CtfTmfTrace { - - private static final @NonNull Collection<@NonNull ITmfEventAspect> ROCM_CTF_ASPECTS = ImmutableList.of( - TmfBaseAspects.getTimestampAspect(), - TmfBaseAspects.getEventTypeAspect(), - TmfBaseAspects.getContentsAspect(), - TmfBaseAspects.getTraceNameAspect()); - - /** Collection of aspects, default values */ - private @NonNull Collection> fAspects = ImmutableSet.copyOf(ROCM_CTF_ASPECTS); - - private static final int CONFIDENCE = 100; - /** - * This is a reduction factor to avoid overflows. - */ - private static final int REDUCTION_FACTOR = 4096; - - private static final int VERSION = 1; - - /** Api type mapped to integer ids */ - private Map fApiMap; - - /** - * Constructor - */ - public RocmTrace() { - super(); - } - - @Override - public Iterable> getEventAspects() { - return fAspects; - } - - @Override - public void initTrace(final IResource resource, final String path, - final Class eventType) throws TmfTraceException { - super.initTrace(resource, path, eventType); - - initializeApiMap(); - - ImmutableList.Builder> builder = new Builder<>(); - builder.add(GpuAspect.INSTANCE); - builder.addAll(createRocmAspects(this)); - builder.addAll(ROCM_CTF_ASPECTS); - builder.addAll(createCounterAspects(this)); - fAspects = builder.build(); - } - - /** - * @param apiName - * the name of API (HIP, HSA) - * @return the api ID - */ - public int getApiId(String apiName) { - return fApiMap.getOrDefault(apiName, -1); - } - - /** - * @return the number of API defined in the trace - */ - public int getNApi() { - return fApiMap.size(); - } - - private void initializeApiMap() { - fApiMap = new HashMap<>(); - for (ITmfEventType eventType : getContainedEventTypes()) { - if (eventType.getName().endsWith("_api")) { //$NON-NLS-1$ - fApiMap.put(eventType.getName(), fApiMap.size()); - } - } - } - - private static Collection> createRocmAspects(ITmfTraceWithPreDefinedEvents trace) { - ImmutableList.Builder> builder = new Builder<>(); - - for (ITmfEventType eventType : trace.getContainedEventTypes()) { - if (eventType.getName().equals(RocmStrings.HSA_API)) { - builder.add(RocmAspects.getQueueIDAspect()); - builder.add(RocmAspects.getQueueIndexAspect()); - } - if (eventType.getName().equals(RocmStrings.HIP_API)) { - builder.add(RocmAspects.getStreamIDAspect()); - } - } - builder.add(RocmAspects.getPIDAspect()); - builder.add(RocmAspects.getTIDAspect()); - builder.add(RocmAspects.getFunctionNameAspect()); - return builder.build(); - } - - private Collection> createCounterAspects(ITmfTraceWithPreDefinedEvents trace) { - ImmutableSet.Builder> perfBuilder = new ImmutableSet.Builder<>(); - ITmfContext context = seekEvent(new CtfLocation(new CtfLocationInfo(0L, 0L))); - - // Get the number of events or an arbitrary number to check if there is - // any metric definition in the trace - Map environment = getEnvironment(); - int traceSize = 0; - if (environment != null) { - traceSize = Integer.parseInt(environment.get("nb_events")); //$NON-NLS-1$ - } - int nEventsToRead = Integer.min(traceSize, 10000); - - for (ITmfEventType eventType : trace.getContainedEventTypes()) { - if (eventType.getName().equals(RocmStrings.METRIC_NAME)) { - for (int i = 0; i < nEventsToRead; i++) { - ITmfEvent event = getNext(context); - if (event.getName().equals(RocmStrings.METRIC_NAME_END)) { - break; - } - if (event.getName().equals(RocmStrings.METRIC_NAME)) { - buildCounterAspectsFromEvent(perfBuilder, event); - } - } - break; - } - } - - return perfBuilder.build(); - } - - private static void buildCounterAspectsFromEvent(ImmutableSet.Builder> builder, ITmfEvent event) { - String fieldName = event.getContent().getFieldValue(String.class, RocmStrings.NAME); - if (fieldName != null) { - Integer id = event.getContent().getFieldValue(Integer.class, RocmStrings.ID); - builder.add(new RocmCounterAspect(fieldName, fieldName, GpuAspect.class, id)); - } - } - - @Override - public int size() { - Map environment = getEnvironment(); - if (environment != null) { - String size = environment.get("nb_events"); //$NON-NLS-1$ - if (size != null) { - return (int) (Long.parseLong(size) / REDUCTION_FACTOR); - } - } - return super.size(); - } - - @Override - public @Nullable IStatus validate(final @Nullable IProject project, final @Nullable String path) { - IStatus status = super.validate(project, path); - if (status instanceof CtfTraceValidationStatus) { - Map environment = ((CtfTraceValidationStatus) status).getEnvironment(); - /* Make sure the domain is "kernel" in the trace's env vars */ - String domain = environment.get("tracer_name"); //$NON-NLS-1$ - if (domain == null || !domain.equals("\"rocprof\"")) { //$NON-NLS-1$ - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "This trace was not recognized as a ROCm trace. You can update your rocprofiler version or you can change manually the tracer name to \"rocprof\" in the metadata file to force the validation."); //$NON-NLS-1$ - } - - int tracerMajor = Integer.parseInt(environment.get("plugin_major")); //$NON-NLS-1$ - int tracerMinor = Integer.parseInt(environment.get("plugin_minor")); //$NON-NLS-1$ - return checkVersion(tracerMajor, tracerMinor); - } - return status; - } - - private static IStatus checkVersion(int tracerMajor, int tracerMinor) { - if (tracerMajor < VERSION) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The tracer version is " + tracerMajor + "." + tracerMinor + " and this version of the ROCm plugin supports only tracer with versions > 3.0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } else if (tracerMajor > VERSION) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The ROCm plugin version needs to be updated to support this new version of rocprofiler."); //$NON-NLS-1$ - } - return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID); - } - - @Override - public TmfTraceContext createTraceContext(TmfTimeRange selection, TmfTimeRange windowRange, @Nullable IFile editorFile, @Nullable ITmfFilter filter) { - return new TmfTraceContext(selection, windowRange, editorFile, filter); - } -} diff --git a/common/org.eclipse.tracecompass.incubator.releng-site/category.xml b/common/org.eclipse.tracecompass.incubator.releng-site/category.xml index bc8179d9b..505a31ed5 100644 --- a/common/org.eclipse.tracecompass.incubator.releng-site/category.xml +++ b/common/org.eclipse.tracecompass.incubator.releng-site/category.xml @@ -69,6 +69,9 @@ + + + diff --git a/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/META-INF/MANIFEST.MF b/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/META-INF/MANIFEST.MF index 47b8bda98..8ee1cee14 100644 --- a/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/META-INF/MANIFEST.MF +++ b/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor -Bundle-Version: 0.8.0.qualifier +Bundle-Version: 0.9.0.qualifier Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.tracecompass.incubator.gpu.doc.user;singleton:=true Require-Bundle: org.eclipse.help diff --git a/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/pom.xml b/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/pom.xml index 5f5cb8aa6..34b8616d9 100644 --- a/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/pom.xml +++ b/doc/org.eclipse.tracecompass.incubator.gpu.doc.user/pom.xml @@ -16,7 +16,7 @@ org.eclipse.tracecompass.incubator.doc org.eclipse.tracecompass.incubator - 0.8.0-SNAPSHOT + 0.9.0-SNAPSHOT org.eclipse.tracecompass.incubator.gpu.doc.user diff --git a/rcp/org.eclipse.tracecompass.incubator.rcp.product/tracing.incubator.product b/rcp/org.eclipse.tracecompass.incubator.rcp.product/tracing.incubator.product index 6753343b4..571d42ba1 100644 --- a/rcp/org.eclipse.tracecompass.incubator.rcp.product/tracing.incubator.product +++ b/rcp/org.eclipse.tracecompass.incubator.rcp.product/tracing.incubator.product @@ -161,6 +161,7 @@ Java and all Java-based trademarks are trademarks of Oracle Corporation in the U + diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.product/traceserver.product b/trace-server/org.eclipse.tracecompass.incubator.trace.server.product/traceserver.product index ab1c881af..fe831436e 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.product/traceserver.product +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.product/traceserver.product @@ -176,7 +176,6 @@ Java and all Java-based trademarks are trademarks of Oracle Corporation in the U - @@ -190,6 +189,7 @@ Java and all Java-based trademarks are trademarks of Oracle Corporation in the U +