def test_multicall(self): true_seq1, true_seq2 = list(range(10)), list(range(10, 20)) gpup = GPUParallel(n_gpu=2, progressbar=False) results = gpup(delayed(task_return_identity)(idx) for idx in true_seq1) self.assertEqual(true_seq1, sorted(results)) results = gpup(delayed(task_return_identity)(idx) for idx in true_seq2) self.assertEqual(true_seq2, sorted(results))
def test_batched_results_equal(self): true_seq = list(range(100)) gpup = GPUParallel(n_gpu=2, progressbar=False) non_batched_results = gpup( delayed(task_return_identity)(idx) for idx in true_seq) bgpup = BatchGPUParallel(task_fn=task_return_identity, batch_size=9, n_gpu=2, progressbar=False) batched_results = list(bgpup(true_seq)) self.assertEqual(len(batched_results), 12) batched_results_ravel = [ item for sublist in batched_results for item in sublist ] self.assertEqual(sorted(non_batched_results), sorted(batched_results_ravel))
def test_preserve_order(self): true_sequence = list(range(100)) gpup = GPUParallel(n_gpu=20, preserve_order=True, progressbar=False) results = gpup(delayed(task_wait_random_time)(idx) for idx in true_sequence) self.assertEqual(true_sequence, list(results))
def test_device_ids(self): true_device_ids = ['cuda:3', 'cuda:4'] gpup = GPUParallel(device_ids=true_device_ids, progressbar=False) results = gpup(delayed(task_return_device_id)() for _ in range(100)) self.assertEqual(set(true_device_ids), set(results))
def test_generator(self): true_seq = list(range(10)) gpup = GPUParallel(n_gpu=2, progressbar=False) results = gpup(delayed(task_return_identity)(idx) for idx in true_seq) self.assertTrue(isinstance(results, Generator)) self.assertEqual(true_seq, sorted(list(results)))
def test_debug_mode(self): true_seq = list(range(10)) gpup = GPUParallel(n_gpu=1, progressbar=False, debug=True) results = gpup(delayed(task_return_identity)(idx) for idx in true_seq) self.assertEqual(true_seq, sorted(results))
def test_results(self): true_seq = list(range(10)) results = GPUParallel(n_gpu=2, progressbar=False)(delayed(task_return_identity)(idx) for idx in true_seq) self.assertEqual(true_seq, sorted(results))
def test_init(self): true_set = {0, 1} results = GPUParallel(n_gpu=2, init_fn=test_init__init)(test_init__task for _ in range(10)) self.assertEqual(true_set, set(results))