|
5 | 5 | import pickle
|
6 | 6 | import re
|
7 | 7 |
|
| 8 | +import pytest |
8 | 9 | from cuda.core.experimental import Buffer, Device, DeviceMemoryResource, DeviceMemoryResourceOptions
|
9 |
| -from cuda.core.experimental._utils.cuda_utils import CUDAError |
| 10 | +from cuda.core.experimental._utils.cuda_utils import CUDAError, driver |
10 | 11 |
|
11 | 12 | CHILD_TIMEOUT_SEC = 20
|
12 | 13 | NBYTES = 64
|
@@ -141,3 +142,63 @@ def CHILD_ACTION(self, queue):
|
141 | 142 | def ASSERT(self, exc_type, exc_msg):
|
142 | 143 | assert exc_type is RuntimeError
|
143 | 144 | assert re.match(r"Memory resource [a-z0-9-]+ was not found", exc_msg)
|
| 145 | + |
| 146 | + |
| 147 | +def test_error_in_close_memory_resource(ipc_memory_resource): |
| 148 | + """Test that errors when closing a memory resource are raised.""" |
| 149 | + mr = ipc_memory_resource |
| 150 | + driver.cuMemPoolDestroy(mr.handle) |
| 151 | + with pytest.raises(CUDAError, match=".*CUDA_ERROR_INVALID_VALUE.*"): |
| 152 | + mr.close() |
| 153 | + |
| 154 | + |
| 155 | +@pytest.mark.skip("Errors are ignored") |
| 156 | +def test_error_in_close_buffer(ipc_memory_resource): |
| 157 | + """Test that errors when closing a memory buffer are raised.""" |
| 158 | + mr = ipc_memory_resource |
| 159 | + buffer = mr.allocate(NBYTES) |
| 160 | + driver.cuMemFree(buffer.handle) |
| 161 | + with pytest.raises(CUDAError, match=".*CUDA_ERROR_INVALID_VALUE.*"): |
| 162 | + buffer.close() |
| 163 | + |
| 164 | + |
| 165 | +@pytest.mark.skip("Errors are ignored") |
| 166 | +class TestErrorInCloseImportedMemoryResource(ChildErrorHarness): |
| 167 | + """Test that errors when closing an imported memory resource are raised.""" |
| 168 | + |
| 169 | + def PARENT_ACTION(self, queue): |
| 170 | + pass |
| 171 | + |
| 172 | + def CHILD_ACTION(self, queue): |
| 173 | + try: |
| 174 | + driver.cuMemPoolDestroy(self.mr.handle) |
| 175 | + except Exception: # noqa: S110 |
| 176 | + pass |
| 177 | + else: |
| 178 | + self.mr.close() |
| 179 | + |
| 180 | + def ASSERT(self, exc_type, exc_msg): |
| 181 | + assert exc_type is CUDAError |
| 182 | + assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg) |
| 183 | + |
| 184 | + |
| 185 | +@pytest.mark.skip("Errors are ignored") |
| 186 | +class TestErrorInCloseImportedBuffer(ChildErrorHarness): |
| 187 | + """Test that errors when closing an imported memory resource are raised.""" |
| 188 | + |
| 189 | + def PARENT_ACTION(self, queue): |
| 190 | + self.buffer = self.mr.allocate(NBYTES) |
| 191 | + queue.put(self.buffer) |
| 192 | + |
| 193 | + def CHILD_ACTION(self, queue): |
| 194 | + buffer = queue.get(timeout=CHILD_TIMEOUT_SEC) |
| 195 | + try: |
| 196 | + driver.cuMemFree(buffer.handle) |
| 197 | + except Exception: # noqa: S110 |
| 198 | + pass |
| 199 | + else: |
| 200 | + buffer.close() |
| 201 | + |
| 202 | + def ASSERT(self, exc_type, exc_msg): |
| 203 | + assert exc_type is CUDAError |
| 204 | + assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg) |
0 commit comments