Create and optionally initialize an nvshmem-accessible DNDArray.
(sess, shape, dtype, init_data_fn=None, zero_out=True)
| 47 | |
| 48 | |
| 49 | def create_nvshmem_array(sess, shape, dtype, init_data_fn=None, zero_out=True): |
| 50 | """Create and optionally initialize an nvshmem-accessible DNDArray.""" |
| 51 | nvshmem_empty = sess.get_global_func("runtime.disco.nvshmem.empty") |
| 52 | arr = nvshmem_empty(ShapeTuple(shape), dtype, None) |
| 53 | |
| 54 | if init_data_fn: |
| 55 | for i in range(NUM_WORKERS): |
| 56 | arr.debug_copy_from(i, init_data_fn(i, shape, dtype)) |
| 57 | elif zero_out: |
| 58 | zero_data = np.zeros(shape, dtype=dtype) |
| 59 | for i in range(NUM_WORKERS): |
| 60 | arr.debug_copy_from(i, zero_data) |
| 61 | |
| 62 | return arr |
| 63 | |
| 64 | |
| 65 | @pytest.mark.gpu |
no test coverage detected
searching dependent graphs…