diff --git a/Python/benchmarking.py b/Python/benchmarking.py index ec9e4db6ffbfaf7b23008649dd5d8f0e9e49ffc8..6796be74d3eca61d5d95a9420a689d765a9c9cae 100644 --- a/Python/benchmarking.py +++ b/Python/benchmarking.py @@ -25,7 +25,7 @@ def count(paths, path_table, off): data = np.load("table/table-half_31_120722.npz", allow_pickle=True) -table = data['table'].item() +_table = data['table'].item() twzr = data['wfm'].item() static_sig = data['static_sig'] target = data['target'] @@ -33,19 +33,22 @@ t_idx = np.nonzero(target)[0] nt = twzr.omega.size _table_cp = {} - -for key in table: - _table_cp[key] = cp.array(table[key]) +# _sig = np.copy(static_sig) +for key in _table: + _table_cp[key] = cp.array(_table[key]) n_repeat = 500 -total_t = np.zeros((nt+1, 2)) -gpu_t = np.zeros((nt+1, 2)) -cpu_t = np.zeros((nt+1, 2)) +times = { + 'total_t': np.zeros((nt + 1, 2)), + 'gpu_t': np.zeros((nt + 1, 2)), + 'cpu_t': np.zeros((nt + 1, 2)) +} filling_ratio = np.zeros((nt+1, 2)) n_move = np.zeros((nt+1, 2)) for i in range(nt+1): - _sig = cp.array(static_sig) + # _sig = cp.array(static_sig) + _sig = np.copy(static_sig) f_prob = i/nt t_t = np.zeros(n_repeat) g_t = np.zeros(n_repeat) @@ -54,11 +57,12 @@ for i in range(nt+1): nm = np.zeros(n_repeat) print(i, f_prob) for j in range(n_repeat): - filled = np.random.rand(nt) - tr = filled < f_prob - fa = filled >= f_prob - filled[tr] = 1 - filled[fa] = 0 + # filled = np.random.rand(nt) + # tr = filled < f_prob + # fa = filled >= f_prob + # filled[tr] = 1 + # filled[fa] = 0 + filled = np.random.binomial(1, f_prob, nt) f_idx = np.nonzero(filled)[0] b = benchmark( test, @@ -75,21 +79,18 @@ for i in range(nt+1): n_move[i,0] = np.mean(nm) n_move[i,1] = np.var(nm) - gpu_t[i,0] = np.mean(g_t) - gpu_t[i,1] = np.var(g_t) - cpu_t[i,0] = np.mean(c_t) - cpu_t[i,1] = np.var(c_t) - total_t[i,0] = np.mean(t_t) - total_t[i,1] = np.var(t_t) + times['gpu_t'][i,0] = np.mean(g_t) + times['gpu_t'][i,1] = np.var(g_t) + times['cpu_t'][i,0] = np.mean(c_t) + times['cpu_t'][i,1] = np.var(c_t) + times['total_t'][i,0] = np.mean(t_t) + times['total_t'][i,1] = np.var(t_t) filling_ratio[i,0] = np.mean(ratio) filling_ratio[i,1] = np.var(ratio) -times = {} -times['gpu_t'] = gpu_t -times['cpu_t'] = cpu_t -times['total_t'] = total_t + np.savez( - f"data/120722_benchmark_{nt}-half_wfm-and-transfer.npz", + f"data/120822_{nt}-half_wfm-and-transfer_CPU.npz", wfm=twzr, target=target, filling_ratio=filling_ratio,