Skip to content

Commit

Permalink
rocm: Update to the ROCm plugin to support the latest traces
Browse files Browse the repository at this point in the history
The traces read by this plugin were generated before using a babeltrace
plugin from a sqlite file. Since then, a library was written by Yoann
Heitz to generate traces directly from ROC-profiler. This patch updates
the ROCm plugin in Trace Compass to handle those traces. It also adds a
number of features to derive dependency relations between memory
tranfers, synchronisation calls and compute kernel executions.

Signed-off-by: Arnaud Fiorini <fiorini.arnaud@gmail.com>
Change-Id: I2c2db97c0fdaaf342695e9d0a2e6fcfcf066e78a
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/196164
Reviewed-by: Marco Miller <marco.miller@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
arfio authored and MatthewKhouzam committed Nov 11, 2022
1 parent a577af8 commit 90d2eac
Show file tree
Hide file tree
Showing 31 changed files with 2,416 additions and 401 deletions.
Expand Up @@ -21,6 +21,13 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.tracecompass.tmf.ctf.core
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,
org.eclipse.tracecompass.incubator.rocm.core.analysis.dependency,
org.eclipse.tracecompass.incubator.rocm.core.trace
Automatic-Module-Name: org.eclipse.tracecompass.incubator.rocm.ctf.core
Import-Package: com.google.common.collect
Import-Package: com.google.common.annotations,
com.google.common.base,
com.google.common.collect,
com.google.common.hash,
org.apache.commons.lang3,
org.eclipse.tracecompass.analysis.counters.core,
org.eclipse.tracecompass.analysis.counters.core.aspects
48 changes: 41 additions & 7 deletions analyses/org.eclipse.tracecompass.incubator.rocm.core/plugin.xml
@@ -1,6 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.linuxtools.tmf.core.analysis">
<module
analysis_module="org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmMetadataAnalysis"
automatic="true"
id="org.eclipse.tracecompass.incubator.rocm.core.analysis.functionname"
name="ROCm Function Name Analysis">
<tracetype
applies="true"
class="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace">
</tracetype>
</module>
</extension>
<extension
point="org.eclipse.linuxtools.tmf.core.analysis">
<module
analysis_module="org.eclipse.tracecompass.analysis.counters.core.CounterAnalysis"
automatic="true"
icon="icons/runtime.gif"
id="org.eclipse.tracecompass.analysis.counters.core.counteranalysis"
name="Counters">
<tracetype
class="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace">
</tracetype>
</module>
</extension>
<extension
point="org.eclipse.linuxtools.tmf.core.tracetype">
<type
Expand All @@ -9,20 +35,28 @@
id="org.eclipse.tracecompass.incubator.rocm.core.trace"
isDirectory="true"
name="%trace.rocm"
trace_type="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmCtfTrace">
trace_type="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace">
</type>
</extension>
<extension
point="org.eclipse.linuxtools.tmf.core.analysis">
<extension
point="org.eclipse.linuxtools.tmf.core.analysis">
<module
analysis_module="org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmCtfCallStackAnalysis"
analysis_module="org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmCallStackAnalysis"
automatic="true"
id="org.eclipse.tracecompass.incubator.rocm.core.analysis.callstack"
id="org.eclipse.tracecompass.incubator.rocm.core.analysis.interval"
name="ROCm API Analysis">
<tracetype
applies="true"
class="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmCtfTrace">
class="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace">
</tracetype>
</module>
</extension>
</plugin>
<extension
point="org.eclipse.tracecompass.tmf.core.symbolProvider">
<providerFactory
class="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTraceSymbolProviderFactory"
id="org.eclipse.tracecompass.incubator.rocm.core.trace.providerfactory"
priority="56">
</providerFactory>
</extension>
</plugin>
@@ -1,51 +1,51 @@
/*******************************************************************************
* Copyright (c) 2020 École Polytechnique de Montréal
/**********************************************************************
* 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;
**********************************************************************/

package org.eclipse.tracecompass.incubator.internal.rocm.core.analysis;

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.incubator.callstack.core.instrumented.statesystem.CallStackSeries.IThreadIdResolver;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;

import com.google.common.collect.ImmutableList;

/**
* ROCm API call stack analysis which displays the main view of the different APIs and GPU kernels
* 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 RocmCtfCallStackAnalysis extends InstrumentedCallStackAnalysis {
public class RocmCallStackAnalysis extends InstrumentedCallStackAnalysis {
/**
* Call stack analysis ID
*/
public static final @NonNull String ID = "org.eclipse.tracecompass.incubator.rocm.core.analysis.callstack"; //$NON-NLS-1$

@Override
protected ITmfStateProvider createStateProvider() {
return new RocmCtfCallStackStateProvider(Objects.requireNonNull(getTrace()));
}
public static final @NonNull String ID = "org.eclipse.tracecompass.incubator.rocm.core.analysis.interval"; //$NON-NLS-1$

@Override
public Iterable<TmfAbstractAnalysisRequirement> getAnalysisRequirements() {
return Collections.emptyList();
protected @NonNull ITmfStateProvider createStateProvider() {
return new RocmCallStackStateProvider(Objects.requireNonNull(getTrace()));
}

@Override
Expand Down
@@ -0,0 +1,145 @@
/**********************************************************************
* 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;

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.AbstractGpuEventHandler;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.ApiEventHandler;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.HipActivityEventHandler;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.HsaActivityEventHandler;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.HsaKernelEventHandler;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.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:
*
* <pre>
* |- Processes
* | |- <GPU>
* | | |- HIP Streams
* | | | |- <Stream> -> Each stream implemented as a callstack with corresponding
* | | | | compute kernel activity.
* | | |- Queues
* | | | |- <Queue> -> Each queue implemented as a callstack with corresponding
* | | | | compute kernel activity.
* | |- Memory
* | | | |- Memory transfers -> Callstack with every memory transfer activity.
* | |- System
* | | |- <Thread>
* | | | |- <API> -> Each API is a callstack showing which API call is executed.
* </pre>
*
* @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<String, AbstractGpuEventHandler> fEventNames;

/**
* @param trace
* trace to follow
*/
public RocmCallStackStateProvider(@NonNull ITmfTrace trace) {
super(trace, ID);
fDependencyMaker = getDependencyMaker((ITmfTraceWithPreDefinedEvents) trace);
fEventNames = buildEventNames();
}

private Map<String, AbstractGpuEventHandler> buildEventNames() {
ImmutableMap.Builder<String, AbstractGpuEventHandler> 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;
}
}

0 comments on commit 90d2eac

Please sign in to comment.