-
Notifications
You must be signed in to change notification settings - Fork 22
Add CUPTI Python API #479
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
Merged
Merged
Add CUPTI Python API #479
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
62dbe07
Add CUPTI Cython API
pentschev ffa74e8
Minor constness improvement
pentschev 9395746
Add tests
pentschev 6d644cd
Merge remote-tracking branch 'upstream/branch-25.10' into cupti-python
pentschev afb0582
Remove types from docstring
pentschev 0378f20
Raise error on init
pentschev 1aac972
Fix linting
pentschev 2b843c1
Add cupti to conda recipe
pentschev 19582a7
Fix punctuation
pentschev 0270c36
Remove return types from pyx file
pentschev 0cefd9b
Rename to bool_t
pentschev f4054b8
Merge remote-tracking branch 'origin/cupti-python' into cupti-python
pentschev deb328e
Add psutil C++ test dependency
pentschev c0a248c
Revert "Add psutil C++ test dependency"
pentschev 7a52d67
Add CUPTI memory monitor to bulk_mpi_shuffle example
pentschev 2545638
Add standalone CUPTI example
pentschev d8c01a7
Merge remote-tracking branch 'upstream/branch-25.10' into cupti-python
pentschev 7f84d74
Fix linting
pentschev 189de6f
Remove unnecessary comments
pentschev 001c63b
Fix linting (again)
pentschev f03eb18
Merge remote-tracking branch 'upstream/branch-25.10' into cupti-python
pentschev e890c99
Remove cupti module import from init
pentschev 05b5f29
Remove return type annotations from Cython
pentschev 1f06542
Merge remote-tracking branch 'upstream/branch-25.10' into cupti-python
pentschev 8c9200b
Remove unused typing import
pentschev 558c82c
Centralize tests skip when CUPTI is unavailable
pentschev 7d513c2
Add CuPy import back
pentschev 8daa0b3
Remove overzealous exception
pentschev 1c8d201
Test cleanup
pentschev 704c639
Revert "Centralize tests skip when CUPTI is unavailable"
pentschev 801ca13
Improve formatting
pentschev e987763
Merge remote-tracking branch 'origin/cupti-python' into cupti-python
pentschev ff5a5e4
Remove unnecessary CUPTI check
pentschev fd77925
Fix linting
pentschev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from libc.stddef cimport size_t | ||
| from libcpp cimport bool as cpp_bool | ||
pentschev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from libcpp.memory cimport unique_ptr | ||
| from libcpp.string cimport string | ||
| from libcpp.unordered_map cimport unordered_map | ||
| from libcpp.vector cimport vector | ||
|
|
||
|
|
||
| cdef extern from "<chrono>" namespace "std::chrono" nogil: | ||
| cdef cppclass milliseconds: | ||
| milliseconds(long long) except + | ||
|
|
||
| cdef extern from "<cupti.h>" nogil: | ||
| ctypedef enum CUpti_CallbackId: | ||
| pass | ||
|
|
||
|
|
||
| cdef extern from "<rapidsmpf/cupti.hpp>" nogil: | ||
| cdef struct cpp_MemoryDataPoint "rapidsmpf::MemoryDataPoint": | ||
| double timestamp | ||
| size_t free_memory | ||
| size_t total_memory | ||
| size_t used_memory | ||
|
|
||
| cdef cppclass cpp_CuptiMonitor "rapidsmpf::CuptiMonitor": | ||
| cpp_CuptiMonitor( | ||
| cpp_bool enable_periodic_sampling, | ||
| milliseconds sampling_interval_ms | ||
| ) except + | ||
| void start_monitoring() except + | ||
| void stop_monitoring() except + | ||
| cpp_bool is_monitoring() except + | ||
| void capture_memory_sample() except + | ||
| const vector[cpp_MemoryDataPoint]& get_memory_samples() except + | ||
| void clear_samples() except + | ||
| size_t get_sample_count() except + | ||
| void write_csv(const string& filename) except + | ||
| void set_debug_output(cpp_bool enabled, size_t threshold_mb) except + | ||
| unordered_map[CUpti_CallbackId, size_t] get_callback_counters() except + | ||
| void clear_callback_counters() except + | ||
| size_t get_total_callback_count() except + | ||
| string get_callback_summary() except + | ||
|
|
||
|
|
||
| cdef class MemoryDataPoint: | ||
| cdef cpp_MemoryDataPoint _data | ||
|
|
||
| @staticmethod | ||
| cdef MemoryDataPoint from_cpp(cpp_MemoryDataPoint data) | ||
|
|
||
|
|
||
| cdef class CuptiMonitor: | ||
| cdef unique_ptr[cpp_CuptiMonitor] _handle | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| class MemoryDataPoint: | ||
| @property | ||
| def timestamp(self) -> float: ... | ||
| @property | ||
| def free_memory(self) -> int: ... | ||
| @property | ||
| def total_memory(self) -> int: ... | ||
| @property | ||
| def used_memory(self) -> int: ... | ||
| def __repr__(self) -> str: ... | ||
|
|
||
| class CuptiMonitor: | ||
| def __init__( | ||
| self, enable_periodic_sampling: bool = False, sampling_interval_ms: int = 100 | ||
pentschev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) -> None: ... | ||
| def start_monitoring(self) -> None: ... | ||
| def stop_monitoring(self) -> None: ... | ||
| def is_monitoring(self) -> bool: ... | ||
| def capture_memory_sample(self) -> None: ... | ||
| def get_memory_samples(self) -> list[MemoryDataPoint]: ... | ||
| def clear_samples(self) -> None: ... | ||
| def get_sample_count(self) -> int: ... | ||
| def write_csv(self, filename: str) -> None: ... | ||
| def set_debug_output(self, enabled: bool, threshold_mb: int = 10) -> None: ... | ||
pentschev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def get_callback_counters(self) -> dict[int, int]: ... | ||
| def clear_callback_counters(self) -> None: ... | ||
| def get_total_callback_count(self) -> int: ... | ||
| def get_callback_summary(self) -> str: ... | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically have only compilers in build and all CUDA libraries (e.g.
libcublas-dev,cuda-cupti-dev, etc.) in host. (Because the compiler depends oncuda-cudart-dev, it ends up in both build and host.) One way to think about it is that if you were cross-compiling, you'd need your toolchain like the compiler executables in build but all the libraries you're building against go in host. For this reason I suspect we should only needcuda-cupti-devin host, and that if it isn't working that way, we have some kind of build system bug that needs to be identified and addressed.For now, I don't want to block further work, but let's flag this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following a discussion offline, instead of adding comments we started #510 to track this, given this PR is only an extension of changes already added in #445 , where
cuda-cupti-devis part ofbuildsection of librapidsmpf's conda recipe.