-
Notifications
You must be signed in to change notification settings - Fork 242
Add __repr__ to core API classes and consolidate object protocol tests #1538
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
@@ -613,6 +613,9 @@ cdef class Kernel: | |
| def __hash__(self) -> int: | ||
| return hash(as_intptr(self._h_kernel)) | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f"Kernel(handle={as_intptr(self._h_kernel):#x})" | ||
|
|
||
|
|
||
| CodeTypeT = bytes | bytearray | str | ||
|
|
||
|
|
@@ -864,3 +867,8 @@ cdef class ObjectCode: | |
| # Trigger lazy load to get the handle | ||
| self._lazy_load_module() | ||
| return hash(as_intptr(self._h_library)) | ||
|
|
||
| def __repr__(self) -> str: | ||
| # Trigger lazy load to get the handle | ||
| self._lazy_load_module() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm ... this could trigger "interesting" error scenarios. Is the lazy loading really needed? How was the handle generated (if it exists)? Didn't that trigger the import already? If the handle does not exist, maybe we should just show
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My 2c: trigger lazy execution on |
||
| return f"ObjectCode(handle={as_intptr(self._h_library):#x}, code_type='{self._code_type}')" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
@@ -221,6 +221,9 @@ cdef class Stream: | |
| return NotImplemented | ||
| return as_intptr(self._h_stream) == as_intptr((<Stream>other)._h_stream) | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f"Stream(handle={as_intptr(self._h_stream):#x})" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because streams are tied to a specific context, does it make sense to capture the context here as well? Similar question for other types tied to a specific context. |
||
|
|
||
| @property | ||
| def handle(self) -> cuda.bindings.driver.CUstream: | ||
| """Return the underlying ``CUstream`` object. | ||
|
|
||
This file was deleted.
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.
Given we have a stream associated to the Buffer that we ultimately deallocate with, it may be nice to include that in the repr?