Skip to content

fix: set_kernel_name returns None for unexpected activity kinds - #23

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/cupti-utils-set-kernel-name-returns-none-for
Open

fix: set_kernel_name returns None for unexpected activity kinds#23
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/cupti-utils-set-kernel-name-returns-none-for

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in src/sol_execbench/core/bench/cupti_utils.py: set_kernel_name returns None for unexpected activity kinds.

Changes

  • src/sol_execbench/core/bench/cupti_utils.py: set_kernel_name returns None for unexpected activity kinds.

Details

--- a/src/sol_execbench/core/bench/cupti_utils.py
+++ b/src/sol_execbench/core/bench/cupti_utils.py
@@ -1,9 +1,11 @@
-    @staticmethod
-    def set_kernel_name(activity):
-        if activity.kind == cupti.ActivityKind.CONCURRENT_KERNEL:
-            return _demangle(activity.name)
-        if activity.kind == cupti.ActivityKind.MEMCPY:
-            return "MEMCPY"
-        if activity.kind == cupti.ActivityKind.MEMSET:
-            return "MEMSET"
-        return None
+    @staticmethod
+    def set_kernel_name(activity):
+        if activity.kind == cupti.ActivityKind.CONCURRENT_KERNEL:
+            return _demangle(activity.name)
+        if activity.kind == cupti.ActivityKind.MEMCPY:
+            return "MEMCPY"
+        if activity.kind == cupti.ActivityKind.MEMSET:
+            return "MEMSET"
+        # Activities such as RUNTIME or DRIVER may not provide a name. Fall
+        # back to a stable string so callers always receive a `str`.
+        return getattr(activity, "name", None) or str(activity.kind)

Tests

  • tests/core/bench/test_cupti_utils.py
--- /dev/null
+++ b/tests/core/bench/test_cupti_utils.py
@@ -0,0 +1,28 @@
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+
+"""Tests for CUPTI activity normalization helpers."""
+
+import types
+import pytest
+
+from sol_execbench.core.bench.cupti_utils import CuptiKernelInfo
+
+
+def test_kernel_string_for_activity_without_name():
+    """Unexpected activity kinds without a name must still produce a string identity."""
+    activity = types.SimpleNamespace(
+        kind="RUNTIME",
+        name=None,
+        start=0.0,
+        end=1.0,
+        correlation_id=0,
+        bytes=0,
+        copy_kind=0,
+        value=0,
+    )
+    info = CuptiKernelInfo.from_activity(activity)
+    assert isinstance(info.name, str)
+    assert info.kernel_string() == "RUNTIME_0_0_0_RUNTIME"
+
+
+def test_kernel_string_for_activity_with_unexpected_name():
+    """An unexpected kind that does provide a name should use it."""
+    activity = types.SimpleNamespace(
+        kind="DRIVER",
+        name="myDriverCall",
+        start=0.0,
+        end=1.0,
+        correlation_id=0,
+        bytes=0,
+        copy_kind=0,
+        value=0,
+    )
+    info = CuptiKernelInfo.from_activity(activity)
+    assert info.name == "myDriverCall"
+    assert info.kernel_string() == "myDriverCall_0_0_0_DRIVER"

Contributor guidelines

Per this repo's CONTRIBUTING.md:

  • All commits are signed off (Signed-off-by trailer, DCO).

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
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.

1 participant