Return a host or device buffer with random data.
(size, target='host', dtype='uint8', ctx=None)
| 60 | |
| 61 | |
| 62 | def make_random_buffer(size, target='host', dtype='uint8', ctx=None): |
| 63 | """Return a host or device buffer with random data. |
| 64 | """ |
| 65 | dtype = np.dtype(dtype) |
| 66 | if target == 'host': |
| 67 | assert size >= 0 |
| 68 | buf = pa.allocate_buffer(size*dtype.itemsize) |
| 69 | arr = np.frombuffer(buf, dtype=dtype) |
| 70 | arr[:] = np.random.randint(low=0, high=255, size=size, |
| 71 | dtype=np.uint8) |
| 72 | return arr, buf |
| 73 | elif target == 'device': |
| 74 | arr, buf = make_random_buffer(size, target='host', dtype=dtype) |
| 75 | dbuf = ctx.new_buffer(size * dtype.itemsize) |
| 76 | dbuf.copy_from_host(buf, position=0, nbytes=buf.size) |
| 77 | return arr, dbuf |
| 78 | raise ValueError('invalid target value') |
| 79 | |
| 80 | |
| 81 | @pytest.mark.parametrize("c", range(len(context_choice_ids)), |
no test coverage detected