()
| 34 | |
| 35 | @pytest.mark.require_ngpu(1) |
| 36 | def test_borrow(): |
| 37 | memstat = MemStat("xpux:0", "xpux:1") |
| 38 | |
| 39 | x_np = np.random.randint(2 ** 30, size=(1 * 1024 * 1024,), dtype="int32") |
| 40 | unit = x_np.size * 4 |
| 41 | x0 = mge.Tensor(x_np, device="xpux:0") |
| 42 | x1 = x0.to("xpux:1", _borrow=True) |
| 43 | y = -x1 |
| 44 | np.testing.assert_equal(-x_np, y.numpy()) |
| 45 | |
| 46 | mge._full_sync() |
| 47 | assert memstat.get_max("xpux:0") / unit < 2.1 |
| 48 | |
| 49 | |
| 50 | @pytest.mark.require_ngpu(1) |