def verify_program(program): states = walk_program(program) for p_idx, loop_vars in states: r_call_abstract_with_scope = program[p_idx] current_node = (p_idx, loop_vars) scope = r_call_abstract_with_scope.scope.copy() children = find_children(program, p_idx, loop_vars) for p_idx_child, child_vars in children: child_parents = find_parents(program, p_idx_child, child_vars) assert current_node in child_parents parents = find_parents(program, p_idx, loop_vars) for p_idx_parent, parent_vars in parents: parent_children = find_children(program, p_idx_parent, parent_vars) assert current_node in parent_children
def test_qr(): A = dummy_matrix(num_dims=2) V = dummy_matrix(num_dims=2) T = dummy_matrix(num_dims=2) R = dummy_matrix(num_dims=2) S = dummy_matrix(num_dims=4) t = time.time() program = lpcompile(QR)(A, V, T, R, S, 16, 0) #states = walk_program(program) #idx = np.random.choice(len(states), len(states) - 1, replace=False)[0] #states = states[idx:idx+1] states = [(8, {'j': 1, 'level': 0, 'k': 6, 'i': 1})] print(states) times = [] print("number of states", len(states)) actual = time.time() for p_idx, loop_vars in states: r_call_abstract_with_scope = program[p_idx] current_node = (p_idx, loop_vars) scope = r_call_abstract_with_scope.scope.copy() children = find_children(program, p_idx, loop_vars) for p_idx_child, child_vars in children: child_parents = find_parents(program, p_idx_child, child_vars) assert current_node in child_parents e = time.time() times.append(e - actual) print("mean find children and parents", np.mean(times)) print("full time ", e - t) print("std time find children and parents", np.std(times))
def test_bdfac(): A = dummy_matrix(num_dims=2) V = dummy_matrix(num_dims=3) T = dummy_matrix(num_dims=3) R = dummy_matrix(num_dims=4) S = dummy_matrix(num_dims=4) VR = dummy_matrix(num_dims=3) TR = dummy_matrix(num_dims=3) L = dummy_matrix(num_dims=4) SR = dummy_matrix(num_dims=4) program = lpcompile(BDFAC)(A, V, T, R, S, VR, TR, SR, L, 256, 0) t = time.time() print(find_children(program, 15, {'j': 2, 'k': 2, 'i': 1, 'level': 1})) e = time.time() print(e - t)
T_sharded = BigMatrix("tsqr_test_T", shape=(num_tree_levels*shard_size*b_fac, X_sharded.shape[0]), shard_sizes=(shard_size*b_fac, shard_size), write_header=False, safe=False) I = BigMatrix("I", shape=(N, N), shard_sizes=( shard_size, shard_size), write_header=True, safe=False) Vs = BigMatrix("Vs", shape=(num_tree_levels, N, N), shard_sizes=( 1, shard_size, shard_size), write_header=True, safe=False) Ts = BigMatrix("Ts", shape=(num_tree_levels, N, N), shard_sizes=( 1, shard_size, shard_size), write_header=True, safe=False) Rs = BigMatrix("Rs", shape=(num_tree_levels, N, N), shard_sizes=( 1, shard_size, shard_size), write_header=True, safe=False) Ss = BigMatrix("Ss", shape=(N, N, N, num_tree_levels*shard_size), shard_sizes=(shard_size, shard_size, shard_size, shard_size), write_header=True, parent_fn=parent_fn, safe=False) #tsqr = frontend.lpcompile(TSQR_BinTree) N_blocks = X_sharded.num_blocks(0) program_compiled_linear = compiler.lpcompile(SimpleTestLinear)(Vs, Ts) program_compiled_nonlinear = compiler.lpcompile( SimpleTestNonLinear)(Vs, Ts, 100) program_compiled_QR = compiler.lpcompile(QR)(I, Vs, Ts, Rs, Ss, 16, 0) start = timer() #print("children linear", compiler.find_children(program_compiled_linear[0], program_compiled_linear, level=0, j=4, i=3)) #print("children nonlinear", compiler.find_children(program_compiled_nonlinear[0], program_compiled_nonlinear, level=1, k=8, i=0)) #print("children qr", compiler.find_children(program_compiled_QR[1], program_compiled_QR, i=0, j=0, level=0)) print("children", compiler.find_children( program_compiled_QR[9], program_compiled_QR, k=2, j=3, i=1)) print("parents", compiler.find_parents( program_compiled_QR[6], program_compiled_QR, i=2, j=3)) #print("parents", compiler.find_parents(program_compiled_QR[2], program_compiled_QR, i=0, j=0, level=2)) end = timer() print(end - start)