def update_B(A, B, x): hcl.print(0, "print1\n") hcl.assert_(x < 2, "assert error 1") hcl.print(0, "print2\n") hcl.assert_(x < 1, "assert error 2") hcl.print(x, "print3\n") B[x] = A[x] + 1
def add(a, b, c): d = hcl.compute(a.shape, lambda *x: a[x] + b[x]) hcl.assert_(False) hcl.print(0, "print1") hcl.update(c, lambda *x: d[x] + 1) hcl.assert_(False) hcl.print(0, "print2")
def add(a, b, c): d = hcl.compute(a.shape, lambda *x: a[x] + b[x], "d") hcl.assert_(True, "assert error 1") hcl.print(0, "print1\n") hcl.update(c, lambda *x: d[x] + 1, "u") hcl.assert_(False, "assert error 2") hcl.print(0, "print2")
def mul(A, B, x): temp = hcl.scalar(0) with hcl.for_(0, x) as i: hcl.assert_(x < 5, "assert in for") temp[0] += add(A, B, x) hcl.print(0, "in for\n") hcl.return_(temp[0])
def loop_body(x): with hcl.if_(A[x]> M[0]): with hcl.if_(A[x]> M[1]): hcl.assert_(x == 2, "assert error in if--value of x: %d", x) M[0] = M[1] M[1] = A[x] with hcl.else_(): M[0] = A[x]
def update_B(A, x): with hcl.if_(A[x] < 5): hcl.print(0, "print1\n") hcl.assert_(A[x] < 4, "assert message 1") hcl.print(0, "print2\n") hcl.return_(-1) hcl.assert_(A[x] >= 5, "assert message 2") hcl.print(0, "not in if\n") hcl.return_(A[x] + 1)
def update_B(A, x): with hcl.for_(0, 10) as i: hcl.assert_(i < 20) hcl.print(0, "in for loop\n") with hcl.if_(A[x] == i): hcl.assert_(A[x] > 10, "assert in if") hcl.print(0, "this should not be printed") hcl.return_(1) hcl.return_(A[x])
def kernel(matrix_1, matrix_2): return_matrix = hcl.compute((m,k), lambda x, y: matrix_1[x,y] + matrix_2[x,y], "return_matrix") with hcl.if_(matrix_2[0,0] == 0): hcl.assert_(matrix_2[1,1] == 0, "assert message in if statement") #result is true hcl.print(0, "in the if statement\n") #should be printed hcl.assert_(matrix_1[0,0] != 0, "customized assert message 1") #result is false hcl.print(0, "this shouldn't be printed") return return_matrix
def update_B(A, x): with hcl.if_(A[x] > 5): hcl.print(0, "print if 1\n") hcl.assert_(A[x] <= 5, "assert in if") hcl.print(0, "print if 2\n") hcl.return_(-1) with hcl.else_(): hcl.print(0, "print else 1\n") hcl.assert_(A[x] <= 5, "assert in else") hcl.print(0, "print else 2\n") hcl.return_(A[x] + 1)
def kernel(matrix_1, matrix_2): return_matrix = hcl.compute((m,k), lambda x, y: matrix_1[x,y] + matrix_2[x,y], "return_matrix") with hcl.for_(0, 7, name="for_loop") as f: hcl.assert_(matrix_2[f,2] == 0, "assert message in the first for loop") #assert true hcl.print(0, "in the first for loop\n") #should be printed with hcl.for_(0, 7, name="for_loop") as f: hcl.assert_(matrix_2[f,2] != 0, "assert message in the second for loop") #assert false hcl.print(0, "in the second for loop\n") #should not be printed hcl.print(0, "this should not be printed\n") #should not be printed return return_matrix
def kernel(matrix_1, matrix_2): return_matrix = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y], "return_matrix") with hcl.if_(matrix_2[0, 0] == 0): matrix_A = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y], "matrix_A") with hcl.else_(): matrix_B = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y] + 2, "matrix_B") hcl.assert_(matrix_1[0, 0] != 0, "customized assert message 1") #result is false matrix_C = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y], "matrix_C") hcl.print(0, "this shouldn't be printed") return return_matrix
def kernel(matrix_1, matrix_2): first_matrix = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y], "first_matrix") return_matrix = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y] + 7, "return_matrix") ax = hcl.scalar(0) with hcl.while_(ax.v < 3): matrix_A = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y] + 7, "matrix_A") with hcl.for_(0, 2, name="for_loop_in") as h: matrix_B = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y] + 8, "matrix_B") with hcl.if_(matrix_1[0, 2] >= 0): matrix_C = hcl.compute((m, k), lambda x, y : matrix_1[x, x] + matrix_2[x, x] + 9, "matrix_C") hcl.assert_(matrix_1[0, 0]> 0, "assert message in the if statement %d", matrix_C[0, 0]) matrix_D = hcl.compute((m, k), lambda x, y : matrix_1[x, x] + matrix_2[x, x] + 9, "matrix_D") hcl.print(0, "in if statement\n") hcl.assert_(matrix_1[0, 0]> 1, "assert message for loop") matrix_F = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y] + 8, "matrix_F") hcl.print(0, "in for loop\n") hcl.assert_(matrix_1[0, 0]> 2, "assert error, matrix_A[1, 1]: %d matrix_A[2, 1]: %d matrix_A[3, 1]: %d", [matrix_A[1, 1], matrix_A[2, 1], matrix_A[3, 1]]) hcl.print(0, "in the while loop\n") ax.v = ax.v + 1 hcl.assert_(matrix_1[0, 0]> 3, "assert message end") matrix_E = hcl.compute((m, k), lambda x, y : matrix_1[x, y] + matrix_2[x, y] + 10, "matrix_E") hcl.print(0, "this should not be printed\n") return return_matrix
def update_B(A, x): with hcl.if_(A[x] > 5): with hcl.if_(A[x] > 7): hcl.print(0, "in if 1\n") hcl.assert_(A[x] == 1, "assert in if") hcl.print(0, "in if 2\n") hcl.return_(-2) hcl.return_(-1) with hcl.else_(): with hcl.if_(A[x] > 3): hcl.print(0, "in else 1\n") hcl.assert_(A[x] == 4, "assert in else") hcl.print(2, "in else 2\n") hcl.return_(-3) hcl.return_(A[x] + 1)
def kernel(matrix_1, matrix_2): return_matrix = hcl.compute( (m, k), lambda x, y: matrix_1[x, y] + matrix_2[x, y], "return_matrix") matrix_A = hcl.compute( (m, k), lambda x, y: matrix_1[x, y] + matrix_2[x, y] + 7, "matrix_A") matrix_B = hcl.compute( (m, k), lambda x, y: matrix_1[x, y] + matrix_2[x, y] + 8, "matrix_B") with hcl.for_(0, 7, name="for_loop") as f: with hcl.if_(matrix_1[0, f] == 0): hcl.assert_( matrix_2[f, 2] == 0, "assert message in the first for loop") #assert true hcl.print(0, "in the first for loop and if statement\n" ) #should be printed 7 times hcl.print(0, "in the first for loop, outside if statement\n" ) #should be printed 7 times with hcl.for_(0, 7, name="for_loop") as f: with hcl.if_(matrix_1[0, f] == 0): hcl.assert_( matrix_2[f, 2] != 0, "assert message in the second for loop") #assert false hcl.print(0, "in the second for loop and if statement\n" ) #should not be printed hcl.print(0, "in the second for loop, outside if statement\n" ) #should not be printed hcl.print(0, "this should not be printed\n") #should not be printed matrix_C = hcl.compute( (m, k), lambda x, y: matrix_1[x, y] + matrix_2[x, y] + 9, "matrix_C") matrix_D = hcl.compute( (m, k), lambda x, y: matrix_1[x, y] + matrix_2[x, y] + 10, "matrix_D") return return_matrix
def add(a, b, c): with hcl.for_(0, 10) as i: a[i] = 0 hcl.assert_(i < 10, "assert error 1") d = hcl.compute(a.shape, lambda *x: a[x] + b[x]) hcl.assert_(a[0] == 0, "assert error 2") hcl.update(c, lambda *x: d[x] + 1) hcl.assert_(a[0] == 0, "assert error 3")
def kernel(matrix_1, matrix_2): first_matrix = hcl.compute((m,k), lambda x, y: matrix_1[x,y] + matrix_2[x,y], "first_matrix") return_matrix = hcl.compute((m,k), lambda x, y: matrix_1[x,y] + matrix_2[x,y] + 7, "return_matrix") hcl.assert_(matrix_1[0,0] == 0, "assert %d message % d", [matrix_1[0,0], matrix_2[0,0]]) #assert is true hcl.assert_(matrix_1[0,0] == 10, "assert %d message % d number 2", [matrix_1[0,0], matrix_2[0,0]]) #assert is false matrix_C = hcl.compute((m,k), lambda x, y: matrix_1[x,y] + matrix_2[x,y] + 9, "matrix_C") matrix_D = hcl.compute((m,k), lambda x, y: matrix_1[x,y] + matrix_2[x,y] + 10, "matrix_D") hcl.assert_(matrix_1[0,0] == 0, "assert %d message % d number 3", [matrix_1[0,0], matrix_2[0,0]]) #assert is true hcl.print(0, "this should not be printed\n") #should not be printed return return_matrix
def add(A, B, x): hcl.assert_(x < 3, "assert in add") hcl.print(0, "in add\n") hcl.return_(A[x] + B[x])
def func(A): hcl.assert_(A[0] > 0, "")
def kernel(A): hcl.assert_(5 == 6) return hcl.compute(A.shape, lambda x: A[x])
def add(a, b, c): hcl.update(c, lambda *x: a[x] + b[x]) hcl.assert_(False) hcl.print(0, "print add")
def update_B(A, x): hcl.print(0, "print1\n") hcl.assert_(A[x] != 7) hcl.print(0, "print2\n") hcl.return_(A[x] + 1)