def func_nplp(): np = nplp.begin_computation_stack() a = np.arange(8) b = a.reshape((2, 4), order='F') knl = np.end_computation_stack([a, b]) evt, (out_a, out_b) = knl(queue) return out_a.get(), out_b.get()
def func_nplp(): np = nplp.begin_computation_stack() a = np.ones(10) b = np.arange(10) c = 2 * a + 3 * b knl = np.end_computation_stack([a, c]) evt, (out_a, out_c) = knl(queue) return out_a.get(), out_c.get()
def func_nplp(): np = nplp.begin_computation_stack() A = np.arange(9).reshape((3, 3)) # noqa: N806 x = np.arange(3) y = np.sum(A * x, axis=1) knl = np.end_computation_stack([A, x, y]) evt, (out_A, out_x, out_y) = knl(queue) return out_A.get(), out_x.get(), out_y.get()
def func_nplp(A_in, B_in): np = nplp.begin_computation_stack() A = np.argument((n, n)) B = np.argument((n, n)) A1 = A.reshape((n, n, 1)) B1 = B.reshape((1, n, n)) C1 = A1 * B1 C = np.sum(C1, axis=1) knl = np.end_computation_stack((C, )) evt, (out_c, ) = knl(queue, **{A.name: A_in, B.name: B_in}) return out_c.get()
def func_nplp(x_in): np = nplp.begin_computation_stack() x = np.argument((1000, 2)) x_new = np.argument((1000, 2)) midpoint = np.sum(x, axis=0) / x.shape[0] is_left = x[:, 0] < midpoint[0] is_lower = x[:, 1] < midpoint[1] is_ll = is_lower * is_left is_ul = (1 - is_lower) * is_left is_lr = is_lower * (1 - is_left) is_ur = (1 - is_lower) * (1 - is_left) num_ll = np.sum(is_ll) num_ul = np.sum(is_ul) num_lr = np.sum(is_lr) idx_ll = np.cumsum(is_ll) * (is_ll) idx_ul = (np.cumsum(is_ul) + num_ll) * (is_ul) idx_lr = (np.cumsum(is_lr) + num_ll + num_ul) * (is_lr) idx_ur = (np.cumsum(is_ur) + num_ll + num_ul + num_lr) * (is_ur) indices = idx_ll + idx_ul + idx_lr + idx_ur - 1 x_new[indices, :] = x knl = np.end_computation_stack([ midpoint, is_lower, is_left, num_ll, num_ul, num_lr, indices, x_new ]) knl = lp.set_options(knl, return_dict=True) knl, out_dict = knl(queue, **{x.name: x_in}) return out_dict[x_new.name].get()
import loopy as lp import numloopy as nplp np = nplp.begin_computation_stack() a = np.arange(8) b = a.reshape((2, 4), order='F') knl = np.end_computation_stack([a, b]) print(lp.generate_code_v2(knl).device_code())