(size)
| 391 | |
| 392 | @pytest.mark.parametrize("size", [0, 1, 1000]) |
| 393 | def test_copy_to_host(size): |
| 394 | arr, dbuf = make_random_buffer(size, target='device') |
| 395 | |
| 396 | buf = dbuf.copy_to_host() |
| 397 | assert buf.is_cpu |
| 398 | np.testing.assert_equal(arr, np.frombuffer(buf, dtype=np.uint8)) |
| 399 | |
| 400 | buf = dbuf.copy_to_host(position=size//4) |
| 401 | assert buf.is_cpu |
| 402 | np.testing.assert_equal(arr[size//4:], np.frombuffer(buf, dtype=np.uint8)) |
| 403 | |
| 404 | buf = dbuf.copy_to_host(position=size//4, nbytes=size//8) |
| 405 | assert buf.is_cpu |
| 406 | np.testing.assert_equal(arr[size//4:size//4+size//8], |
| 407 | np.frombuffer(buf, dtype=np.uint8)) |
| 408 | |
| 409 | buf = dbuf.copy_to_host(position=size//4, nbytes=0) |
| 410 | assert buf.is_cpu |
| 411 | assert buf.size == 0 |
| 412 | |
| 413 | for (position, nbytes) in [ |
| 414 | (size+2, -1), (-2, -1), (size+1, 0), (-3, 0), |
| 415 | ]: |
| 416 | with pytest.raises(ValueError, |
| 417 | match='position argument is out-of-range'): |
| 418 | dbuf.copy_to_host(position=position, nbytes=nbytes) |
| 419 | |
| 420 | for (position, nbytes) in [ |
| 421 | (0, size+1), (size//2, (size+1)//2+1), (size, 1) |
| 422 | ]: |
| 423 | with pytest.raises(ValueError, |
| 424 | match=('requested more to copy than' |
| 425 | ' available from device buffer')): |
| 426 | dbuf.copy_to_host(position=position, nbytes=nbytes) |
| 427 | |
| 428 | buf = pa.allocate_buffer(size//4) |
| 429 | dbuf.copy_to_host(buf=buf) |
| 430 | np.testing.assert_equal(arr[:size//4], np.frombuffer(buf, dtype=np.uint8)) |
| 431 | |
| 432 | if size < 12: |
| 433 | return |
| 434 | |
| 435 | dbuf.copy_to_host(buf=buf, position=12) |
| 436 | np.testing.assert_equal(arr[12:12+size//4], |
| 437 | np.frombuffer(buf, dtype=np.uint8)) |
| 438 | |
| 439 | dbuf.copy_to_host(buf=buf, nbytes=12) |
| 440 | np.testing.assert_equal(arr[:12], np.frombuffer(buf, dtype=np.uint8)[:12]) |
| 441 | |
| 442 | dbuf.copy_to_host(buf=buf, nbytes=12, position=6) |
| 443 | np.testing.assert_equal(arr[6:6+12], |
| 444 | np.frombuffer(buf, dtype=np.uint8)[:12]) |
| 445 | |
| 446 | for (position, nbytes) in [ |
| 447 | (0, size+10), (10, size-5), |
| 448 | (0, size//2), (size//4, size//4+1) |
| 449 | ]: |
| 450 | with pytest.raises(ValueError, |
nothing calls this directly
no test coverage detected