dmlc--dgl
701b4fccc2
* initial update * more * more * multi-gpu example * cluster gcn, finalize homogeneous * more explanation * fix * bunch of fixes * fix * RGAT example and more fixes * shadow-gnn sampler and some changes in unit test * fix * wth * more fixes * remove shadow+node/edge dataloader tests for possible ux changes * lints * add legacy dataloading import just in case * fix * update pylint for f-strings * fix * lint * lint * lint again * cherry-picking commit fa9f494 * oops * fix * add sample_neighbors in dist_graph * fix * lint * fix * fix * fix * fix tutorial * fix * fix * fix * fix warning * remove debug * add get_foo_storage apis * lint
35 行
975 B
Python
35 行
975 B
Python
import dgl
|
|
import unittest
|
|
import backend as F
|
|
|
|
from dgl.dataloading import AsyncTransferer
|
|
|
|
@unittest.skipIf(F._default_context_str == 'cpu',
|
|
reason="CPU transfer not allowed")
|
|
def test_async_transferer_to_other():
|
|
cpu_ones = F.ones([100,75,25], dtype=F.int32, ctx=F.cpu())
|
|
tran = AsyncTransferer(F.ctx())
|
|
t = tran.async_copy(cpu_ones, F.ctx())
|
|
other_ones = t.wait()
|
|
|
|
assert F.context(other_ones) == F.ctx()
|
|
assert F.array_equal(F.copy_to(other_ones, ctx=F.cpu()), cpu_ones)
|
|
|
|
def test_async_transferer_from_other():
|
|
other_ones = F.ones([100,75,25], dtype=F.int32, ctx=F.ctx())
|
|
tran = AsyncTransferer(F.ctx())
|
|
|
|
try:
|
|
t = tran.async_copy(other_ones, F.cpu())
|
|
except ValueError:
|
|
# correctly threw an error
|
|
pass
|
|
else:
|
|
# should have thrown an error
|
|
assert False
|
|
|
|
if __name__ == '__main__':
|
|
test_async_transferer_to_other()
|
|
test_async_transferer_from_other()
|
|
|