Skip to content

Commit

Permalink
Resolve warning: AttributeError: '_Reduce' object has no attribute 'b…
Browse files Browse the repository at this point in the history
…uild_result'

```
=========================================================================== warnings summary ===========================================================================
tests/test_reduce.py::test_reduce_non_contiguous
  /home/coder/cccl/python/devenv/lib/python3.12/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning: Exception ignored in: <function _Reduce.__del__ at 0x7bf123139080>

  Traceback (most recent call last):
    File "/home/coder/cccl/python/cuda_parallel/cuda/parallel/experimental/algorithms/reduce.py", line 132, in __del__
      bindings.cccl_device_reduce_cleanup(ctypes.byref(self.build_result))
                                                       ^^^^^^^^^^^^^^^^^
  AttributeError: '_Reduce' object has no attribute 'build_result'

    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================= 1 passed, 93 deselected, 1 warning in 0.44s ==============================================================
```
  • Loading branch information
rwgk committed Jan 6, 2025
1 parent eddc6cc commit bcf0de8
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __init__(
op: Callable,
h_init: np.ndarray,
):
# Referenced from __del__:
self.build_result = None

d_in_cccl = cccl.to_cccl_iter(d_in)
self._ctor_d_in_cccl_type_enum_name = cccl.type_enum_as_name(
d_in_cccl.value_type.type.value
Expand Down Expand Up @@ -128,6 +131,8 @@ def __call__(self, temp_storage, d_in, d_out, num_items: int, h_init: np.ndarray
return temp_storage_bytes.value

def __del__(self):
if self.build_result is None:
return
bindings = get_bindings()
bindings.cccl_device_reduce_cleanup(ctypes.byref(self.build_result))

Expand Down

0 comments on commit bcf0de8

Please sign in to comment.