Basically add tests to cover concerns raised in #11
Testing of asyncio safety will require adding test-time dependency on pytest-asyncio. The test file may be as follows:
importdpctlimportdpctl.memoryasdpmemimportrandomimportasyncioasyncdef_task1():
q=dpctl.SyclQueue("opencl:gpu")
abc=b"abcdefghijklmnopqrstuvwxyz"m=dpmem.MemoryUSMShared(len(abc))
withdpctl.device_context(q) aslq:
for_inrange(12):
cd=dpctl.get_current_queue().sycl_deviceassertcd.backend==q.sycl_device.backendm.copy_from_host(abc)
awaitasyncio.sleep(0.1*random.random())
asyncdef_task2():
q=dpctl.SyclQueue("level_zero:gpu")
m=dpmem.MemoryUSMShared(10)
host_data=b"\x00"*10withdpctl.device_context(q) aslq:
for_inrange(12):
cd=dpctl.get_current_queue().sycl_deviceassertcd.backend==q.sycl_device.backendm.copy_from_host(host_data)
awaitasyncio.sleep(0.1*random.random())
asyncdeftest_asyncio_safety():
j1=asyncio.create_task(_task1())
j2=asyncio.create_task(_task2())
awaitj1awaitj2print("done")
if__name__=='__main__':
asyncio.run(test_asyncio_safety())The test for multi-processing may look as follows, but to turn it into a test, assertions must be added:
importdpctlimportdpctl.memoryasdpmemimportmultiprocessingasmpdefcompute_works(i):
d=dpctl.SyclDevice("cpu")
sd=d.create_sub_devices(partition=(4, 4, 4))
ctx=dpctl.SyclContext(sd)
q=dpctl.SyclQueue(ctx, sd[i], property="in_order")
mem=dpmem.MemoryUSMShared(32, queue=q)
host= (b" ") *32mem.copy_from_host(host)
print((i, "->", mem.copy_to_host()))
print("", flush=True)
# dpctl.set_global_queue(q)defrt_warnings(i):
cq=dpctl.get_current_queue()
withdpctl.device_context("cpu") asq:
print(
"Hello from {}, using {} with {} EUs".format(
i, q.sycl_device.name, q.sycl_device.max_compute_units
)
)
dpctl.set_global_queue(q)
returniif__name__=="__main__":
withmp.Pool(3) asp:
p.map(rt_warnings, [0, 1, 2])
print("Execution of rt_warnings finished")
print("--"*30)
withmp.Pool(3) asp:
p.map(compute_works, [0, 1, 2])
print("Execution of compute_works finished")
Basically add tests to cover concerns raised in #11
Testing of asyncio safety will require adding test-time dependency on
pytest-asyncio. The test file may be as follows:The test for multi-processing may look as follows, but to turn it into a test, assertions must be added: