MCPcopy Create free account
hub / github.com/apache/arrow / test_copy_from_device

Function test_copy_from_device

python/pyarrow/tests/test_cuda.py:458–504  ·  view source on GitHub ↗
(dest_ctx, size)

Source from the content-addressed store, hash-verified

456@pytest.mark.parametrize("dest_ctx", ['same', 'another'])
457@pytest.mark.parametrize("size", [0, 1, 1000])
458def test_copy_from_device(dest_ctx, size):
459 arr, buf = make_random_buffer(size=size, target='device')
460 lst = arr.tolist()
461 if dest_ctx == 'another':
462 dest_ctx = global_context1
463 if buf.context.device_number == dest_ctx.device_number:
464 pytest.skip("not a multi-GPU system")
465 else:
466 dest_ctx = buf.context
467 dbuf = dest_ctx.new_buffer(size)
468
469 def put(*args, **kwargs):
470 dbuf.copy_from_device(buf, *args, **kwargs)
471 rbuf = dbuf.copy_to_host()
472 return np.frombuffer(rbuf, dtype=np.uint8).tolist()
473 assert put() == lst
474 if size > 4:
475 assert put(position=size//4) == lst[:size//4]+lst[:-size//4]
476 assert put() == lst
477 assert put(position=1, nbytes=size//2) == \
478 lst[:1] + lst[:size//2] + lst[-(size-size//2-1):]
479
480 for (position, nbytes) in [
481 (size+2, -1), (-2, -1), (size+1, 0), (-3, 0),
482 ]:
483 with pytest.raises(ValueError,
484 match='position argument is out-of-range'):
485 put(position=position, nbytes=nbytes)
486
487 for (position, nbytes) in [
488 (0, size+1),
489 ]:
490 with pytest.raises(ValueError,
491 match=('requested more to copy than'
492 ' available from device buffer')):
493 put(position=position, nbytes=nbytes)
494
495 if size < 4:
496 return
497
498 for (position, nbytes) in [
499 (size//2, (size+1)//2+1)
500 ]:
501 with pytest.raises(ValueError,
502 match=('requested more to copy than'
503 ' available in device buffer')):
504 put(position=position, nbytes=nbytes)
505
506
507@pytest.mark.parametrize("size", [0, 1, 1000])

Callers

nothing calls this directly

Calls 2

putFunction · 0.85
make_random_bufferFunction · 0.70

Tested by

no test coverage detected