Make sure that cvcuda.clear_cache clears the cache for all threads.
()
| 240 | |
| 241 | |
| 242 | def test_parallel_clear_cache(): |
| 243 | """Make sure that cvcuda.clear_cache clears the cache for all threads.""" |
| 244 | |
| 245 | def clear_cache(): |
| 246 | done_event.wait() # wait for the main thread to be ready |
| 247 | cvcuda.clear_cache() |
| 248 | clear_event.set() # notify that the cache has been cleared |
| 249 | |
| 250 | # Ensure that the cache limit was not altered by another test |
| 251 | cvcuda.set_cache_limit_inbytes(torch.cuda.mem_get_info()[1] // 2) |
| 252 | cvcuda.clear_cache() |
| 253 | |
| 254 | done_event = threading.Event() |
| 255 | clear_event = threading.Event() |
| 256 | clear_thread = threading.Thread(target=clear_cache, daemon=True) |
| 257 | clear_thread.start() |
| 258 | |
| 259 | h, w = 16, 32 |
| 260 | cvcuda.Tensor((h, w), np.uint8) |
| 261 | size_inbytes = cvcuda.current_cache_size_inbytes() |
| 262 | assert cvcuda.cache_size() == 1 |
| 263 | assert size_inbytes > 0 |
| 264 | |
| 265 | done_event.set() |
| 266 | clear_event.wait() |
| 267 | |
| 268 | assert cvcuda.cache_size() == cvcuda.current_cache_size_inbytes() == 0 |
| 269 | cvcuda.Tensor((h, w), np.uint8) |
| 270 | assert cvcuda.cache_size() == 1 |
| 271 | assert cvcuda.current_cache_size_inbytes() == size_inbytes |