Skip to content

Commit

Permalink
rocm: Add new analysis to support new trace format
Browse files Browse the repository at this point in the history
As a new plugin was added to generate CTF traces with different event
types and format, these new analysis and trace were added to support
this new type. Each API function now has its own event type, and some
fields are now passed as context fields.

As this change uses the tracecompass.analysis.callstack and the rocm
plugin depends on it, the callstack plugin was added as a dependency
to the trace server.

[Added] New ROCm trace type to support new plugin
[Added] New ROCm CallStack that displays API and GPU activity

Signed-off-by: Arnaud Fiorini <[email protected]>
  • Loading branch information
arfio committed Apr 17, 2024
1 parent 9d144ca commit 78b087a
Show file tree
Hide file tree
Showing 14 changed files with 1,001 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.tracecompass.common.core,
org.eclipse.tracecompass.tmf.core,
org.eclipse.tracecompass.tmf.ctf.core,
org.eclipse.tracecompass.ctf.core,
org.eclipse.tracecompass.segmentstore.core,
org.eclipse.tracecompass.statesystem.core,
org.eclipse.tracecompass.analysis.timing.core,
org.eclipse.tracecompass.analysis.os.linux.core,
org.eclipse.tracecompass.analysis.profiling.core;bundle-version="2.4.0",
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.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
org.eclipse.tracecompass.tmf.ctf.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,
Expand All @@ -29,6 +33,4 @@ 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
org.apache.commons.lang3
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Bundle-Vendor = Eclipse Trace Compass Incubator
Bundle-Name = Trace Compass ROCm CTF Core Plug-in (Incubator)

trace.rocm.old = ROCm Trace (old)
trace.rocm = ROCm Trace
18 changes: 18 additions & 0 deletions analyses/org.eclipse.tracecompass.incubator.rocm.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
class="org.eclipse.tracecompass.incubator.rocm.core.trace.old.RocmTrace">
</tracetype>
</module>
<module
analysis_module="org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.RocmCallStackAnalysis"
automatic="true"
id="org.eclipse.tracecompass.incubator.rocm.core.analysis.atomic"
name="ROCm API Analysis">
<tracetype
applies="true"
class="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace">
</tracetype>
</module>
</extension>
<extension
point="org.eclipse.linuxtools.tmf.core.tracetype">
Expand All @@ -36,6 +46,14 @@
name="%trace.rocm.old"
trace_type="org.eclipse.tracecompass.incubator.rocm.core.trace.old.RocmTrace">
</type>
<type
category="org.eclipse.linuxtools.tmf.ctf.core.category.ctf"
event_type="org.eclipse.tracecompass.tmf.core.event.TmfEvent"
id="org.eclipse.tracecompass.incubator.rocm.core.trace.atomic"
isDirectory="true"
name="%trace.rocm"
trace_type="org.eclipse.tracecompass.incubator.rocm.core.trace.RocmTrace">
</type>
</extension>
<extension
point="org.eclipse.linuxtools.tmf.core.analysis">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2023 É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.Collection;
import java.util.Collections;
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.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;

/**
* This analysis is a callstack analysis which summarizes the execution of a
* ROCm GPU program.
*
* It separates the execution into two categories: the GPU queues 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
*/
@SuppressWarnings("restriction")
public class RocmCallStackAnalysis extends InstrumentedCallStackAnalysis {

private static final String EDGES = "EDGES"; //$NON-NLS-1$

@Override
protected @NonNull Collection<Integer> getEdgeQuarks() {
ITmfStateSystem ss = getStateSystem();
if (ss == null) {
return Collections.emptyList();
}
int edgeQuark = ss.optQuarkAbsolute(EDGES);
if (edgeQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
return Collections.emptyList();
}
return ss.getSubAttributes(edgeQuark, false);
}

@Override
protected @NonNull ITmfStateProvider createStateProvider() {
return new RocmCallStackStateProvider(Objects.requireNonNull(getTrace()), new RocmEventLayout());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*******************************************************************************
* Copyright (c) 2023 É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 org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.ApiEventHandler;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.IRocmEventHandler;
import org.eclipse.tracecompass.incubator.internal.rocm.core.analysis.handlers.OperationEventHandler;
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 creates callstacks and apply different event handlers.
* There are multiple types of events, each described in their respective
* handler.
*
* Attribute tree:
*
* <pre>
* |- OperationQueues
* | |- <Queue>
* | | |- <Depth> -> Each depth represents one operation that has been queued,
* | | | other depths are for other queued operations.
* |- Root
* | |- Processes
* | | |- <Thread>
* | | | |- <API> -> Each API is a callstack showing which API call is executed.
* | |- Queues
* | | | |- <ROCm Agent / GPU>
* | | | | |- <Queue> -> Each queue implemented as a callstack with corresponding
* | | | | | compute kernel activity.
* </pre>
*
* @author Arnaud Fiorini
*/
public class RocmCallStackStateProvider extends AbstractTmfStateProvider {

private static final String ID = "org.eclipse.tracecompass.incubator.rocm.core.stateprovider.atomic"; //$NON-NLS-1$
/** Name of the root attribute */
public static final String ROOT = "root"; //$NON-NLS-1$
/** Name of the sub-attribute where the name of the operation is stored */
public static final String NAME = "name"; //$NON-NLS-1$
/** 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$

private final RocmEventLayout fLayout;
private IRocmEventHandler fApiEventHandler;
private IRocmEventHandler fOperationEventHandler;

/**
* Constructor
*
* @param trace
* Trace to follow
* @param layout
* The layout of the events
*/
public RocmCallStackStateProvider(ITmfTrace trace, RocmEventLayout layout) {
super(trace, ID);
fLayout = layout;
fApiEventHandler = new ApiEventHandler();
fOperationEventHandler = new OperationEventHandler();
}

@Override
public int getVersion() {
return 0;
}

@Override
public @NonNull ITmfStateProvider getNewInstance() {
return new RocmCallStackStateProvider(getTrace(), fLayout);
}

@Override
protected void eventHandle(ITmfEvent event) {
ITmfStateSystemBuilder ssb = getStateSystemBuilder();
if (ssb == null) {
return;
}
if (event.getName().equals(fLayout.getHsaOperationBegin()) || event.getName().equals(fLayout.getHsaOperationEnd())) {
fOperationEventHandler.handleEvent(event, ssb, fLayout);
} else if (event.getName().equals(fLayout.getHipOperationBegin()) || event.getName().equals(fLayout.getHipOperationEnd())) {
fOperationEventHandler.handleEvent(event, ssb, fLayout);
} else if (event.getName().startsWith(fLayout.getHipPrefix()) || event.getName().startsWith(fLayout.getHsaPrefix())) {
fApiEventHandler.handleEvent(event, ssb, fLayout);
}
}
}
Loading

0 comments on commit 78b087a

Please sign in to comment.