| 280 | |
| 281 | |
| 282 | def test_foreign_buffer(): |
| 283 | ctx = global_context |
| 284 | dtype = np.dtype(np.uint8) |
| 285 | size = 10 |
| 286 | hbuf = cuda.new_host_buffer(size * dtype.itemsize) |
| 287 | |
| 288 | # test host buffer memory reference counting |
| 289 | rc = sys.getrefcount(hbuf) |
| 290 | fbuf = ctx.foreign_buffer(hbuf.address, hbuf.size, hbuf) |
| 291 | assert sys.getrefcount(hbuf) == rc + 1 |
| 292 | del fbuf |
| 293 | assert sys.getrefcount(hbuf) == rc |
| 294 | |
| 295 | # test postponed deallocation of host buffer memory |
| 296 | fbuf = ctx.foreign_buffer(hbuf.address, hbuf.size, hbuf) |
| 297 | del hbuf |
| 298 | fbuf.copy_to_host() |
| 299 | |
| 300 | |
| 301 | @pytest.mark.parametrize("size", [0, 1, 1000]) |