Как получить правильную глобальную переменную с timeit jupyter? - PullRequest
0 голосов
/ 09 ноября 2018

Первая ячейка у меня такая:

from numba import cuda
@cuda.jit
def thread_counter_safe(global_counter):
    cuda.atomic.add(global_counter, 0, 1)  # Safely add 1 to offset 0 in global_counter array

В следующей ячейке у меня есть это:

global_counter = cuda.to_device(np.array([0], dtype=np.int32))
thread_counter_safe[64, 64](global_counter)
print('Should be %d:' % (64*64), global_counter.copy_to_host())

global_counter = cuda.to_device(np.array([0], dtype=np.int32))
%timeit thread_counter_safe[64, 64](global_counter)
print('Should be %d:' % (64*64), global_counter.copy_to_host())

Вывод этой второй ячейки выглядит примерно так:

Should be 4096: [4096]
10000 loops, best of 3: 118 µs per loop
Should be 4096: [168390656]

Время Jupyter Notebook содержит global_counter через его итерационный тест. Как заставить его вернуть global_counter правильно?

...