MCPcopy Create free account
hub / github.com/NVIDIA/DALI / test_pool_context_sync

Method test_pool_context_sync

dali/test/python/test_pool.py:279–308  ·  view source on GitHub ↗
(self, start_method)

Source from the content-addressed store, hash-verified

277
278 @params(*start_methods)
279 def test_pool_context_sync(self, start_method):
280 callbacks = [simple_callback, another_callback]
281 groups = [MockGroup.from_callback(cb, prefetch_queue_depth=3) for cb in callbacks]
282 with create_pool(
283 groups, keep_alive_queue_size=1, num_workers=4, start_method=start_method
284 ) as pool:
285 capture_processes(pool)
286 for i in range(4):
287 work_batch = TaskArgs.make_sample(SampleRange(0, 10 * (i + 1), 0, 0))
288 pool.schedule_batch(context_i=0, work_batch=work_batch)
289 pool.schedule_batch(context_i=1, work_batch=work_batch)
290 assert_scheduled_num(pool.contexts[0], 4)
291 assert_scheduled_num(pool.contexts[1], 4)
292 # pool after a reset should discard all previously scheduled tasks
293 # (and sync workers to avoid race on writing to results buffer)
294 pool.reset()
295 tasks = [(SampleInfo(1000 + j, j, 0, 1),) for j in range(5)]
296 work_batch = TaskArgs.make_sample(SampleRange(1000, 1005, 0, 1))
297 pool.schedule_batch(context_i=0, work_batch=work_batch)
298 pool.schedule_batch(context_i=1, work_batch=work_batch)
299 assert_scheduled_num(pool.contexts[0], 1)
300 assert_scheduled_num(pool.contexts[1], 1)
301 batch_0 = pool.receive_batch(context_i=0)
302 batch_1 = pool.receive_batch(context_i=1)
303 assert len(batch_0) == len(tasks)
304 assert len(batch_1) == len(tasks)
305 for task, sample in zip(tasks, batch_0):
306 np.testing.assert_array_equal(answer(-1, *task)[1:], sample[1:])
307 for task, sample in zip(tasks, batch_1):
308 np.testing.assert_array_equal(answer(-1, *task)[1:] + 100, sample[1:])
309
310 @params(1, 4)
311 def test_multiple_stateful_sources_single_worker(self, num_workers):

Callers

nothing calls this directly

Calls 11

capture_processesFunction · 0.90
SampleRangeClass · 0.90
SampleInfoClass · 0.90
create_poolFunction · 0.85
assert_scheduled_numFunction · 0.85
answerFunction · 0.85
from_callbackMethod · 0.80
make_sampleMethod · 0.80
receive_batchMethod · 0.80
schedule_batchMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected