Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class for documented Nvtx Ranges #12035

Draft
wants to merge 8 commits into
base: branch-25.04
Choose a base branch
from

Conversation

zpuller
Copy link
Collaborator

@zpuller zpuller commented Jan 27, 2025

This PR adds a scala class which can wrap NvtxRange and add a docstring to a given range. It then provides functionality to take all such ranges and auto generate a readme containing the doc strings.

All existing ranges will need to be migrated to the new class, but I'm planning to do that in a series of smaller migration PRs. This PR migrates a couple ranges over for example purposes.

Signed-off-by: Zach Puller <zpuller@nvidia.com>
Signed-off-by: Zach Puller <zpuller@nvidia.com>
Signed-off-by: Zach Puller <zpuller@nvidia.com>
Signed-off-by: Zach Puller <zpuller@nvidia.com>
Signed-off-by: Zach Puller <zpuller@nvidia.com>
@zpuller zpuller requested a review from a team as a code owner January 27, 2025 19:16
@@ -1,7 +1,7 @@
---
layout: page
title: Compute Sanitizer
nav_order: 7
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are adding in a new page in the developer docs. Additionally, I noticed that there were two existing pages with the same nav_order, which I am also fixing, so the end result is all the back pages get moved back by 2.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a separate concern worth its own PR

Signed-off-by: Zach Puller <zpuller@nvidia.com>
Signed-off-by: Zach Puller <zpuller@nvidia.com>
Signed-off-by: Zach Puller <zpuller@nvidia.com>
@@ -1,7 +1,7 @@
---
layout: page
title: Compute Sanitizer
nav_order: 7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a separate concern worth its own PR

object NvtxId {
val registeredRanges = new ListBuffer[NvtxId]()

private def register(nvtxId: NvtxId): Unit = registeredRanges += nvtxId
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make it a Map and detect collisions

}
}

class NvtxRangeWithDoc(val id: NvtxId, color: NvtxColor) extends AutoCloseable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
class NvtxRangeWithDoc(val id: NvtxId, color: NvtxColor) extends AutoCloseable {
case class NvtxRangeWithDoc(val id: NvtxId, color: NvtxColor) extends AutoCloseable {

color: NvtxColor,
f: => A): A = {
val start = System.nanoTime()
withResource(new NvtxRangeWithDoc(range, color)) { _ =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you make it a case class or add a companion with factory apply manually

Suggested change
withResource(new NvtxRangeWithDoc(range, color)) { _ =>
withResource(NvtxRangeWithDoc(range, color)) { _ =>

}
}

class NvtxRangeWithDoc(val id: NvtxId, color: NvtxColor) extends AutoCloseable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please change the API? The AutoClosable was me trying to do an RAII like API, but that is not a great API for java/scala. I know this will require changes to the CUDF code to open up the API, but can we please add some static push and pop methods in NvtxRange that take the name and the color bits but do check if nvtx is enabled.

Then we can have each of the NvtxIds, might want to rename them, have an apply method so we get the following code instead.

Nntx.ACQUIRE_GPU(semWaitTimeNs) {
  f()
}
Nvtx.RELEASE_GPU {
  ...
}

You might have guessed from this that I would like the color to be a part of the NvtxId as well. I think it is better if we are consistent in the color for a given range and that we have it documented.

@zpuller zpuller changed the base branch from branch-25.02 to branch-25.04 February 13, 2025 17:34
@zpuller zpuller marked this pull request as draft February 13, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants