def test_looplevel(): x, y = hl.Var('x'), hl.Var('y') target = hl.get_jit_target_from_environment() buffer_input = hl.Buffer(hl.UInt(8), [4, 4]) buffer_input.fill(123) func_input = hl.Func("func_input") func_input[x, y] = x + y simple_compute_at = hl.LoopLevel() simple = simplestub.generate(target, buffer_input, func_input, 3.5, compute_level=simple_compute_at) computed_output = hl.Func('computed_output') computed_output[x, y] = simple[x, y] + 3 simple_compute_at.set(hl.LoopLevel(computed_output, x)) _realize_and_check(computed_output, 3)
def test_simplestub(): x, y = hl.Var(), hl.Var() target = hl.get_jit_target_from_environment() b_in = hl.Buffer(hl.UInt(8), [2, 2]) b_in.fill(123) f_in = hl.Func("f") f_in[x, y] = x + y # ----------- Inputs by-position f = simplestub.generate(target, b_in, f_in, 3.5) _realize_and_check(f) # ----------- Inputs by-name f = simplestub.generate(target, buffer_input=b_in, func_input=f_in, float_arg=3.5) _realize_and_check(f) # ----------- Inputs w/ mixed by-position and by-name f = simplestub.generate(target, b_in, f_in, float_arg=3.5) _realize_and_check(f) f = simplestub.generate(target, b_in, float_arg=3.5, func_input=f_in) _realize_and_check(f) # ----------- Above set again, w/ GeneratorParam mixed in k = 42 f = simplestub.generate(target, b_in, f_in, 3.5, offset=k) _realize_and_check(f, k) f = simplestub.generate(target, offset=k, buffer_input=b_in, func_input=f_in, float_arg=3.5) _realize_and_check(f, k) f = simplestub.generate(target, b_in, f_in, offset=k, float_arg=3.5) _realize_and_check(f, k) f = simplestub.generate(target, b_in, float_arg=3.5, offset=k, func_input=f_in) _realize_and_check(f, k) # ----------- Test various failure modes try: # too many positional args f = simplestub.generate(target, b_in, f_in, 3.5, 4) except RuntimeError as e: assert 'Expected at most 3 positional args, but saw 4.' in str(e) else: assert False, 'Did not see expected exception!' try: # Inputs that can't be converted to what the receiver needs (positional) f = simplestub.generate(target, 3.141592, "happy") except RuntimeError as e: assert 'Unable to cast Python instance' in str(e) else: assert False, 'Did not see expected exception!' try: # Inputs that can't be converted to what the receiver needs (named) f = simplestub.generate(target, b_in, f_in, float_arg="bogus") except RuntimeError as e: assert 'Unable to cast Python instance' in str(e) else: assert False, 'Did not see expected exception!' try: # Missing required inputs f = simplestub.generate(target, b_in, f_in) except RuntimeError as e: assert "Generator Input named 'float_arg' was not specified." in str(e) else: assert False, 'Did not see expected exception!' try: # Input specified by both pos and kwarg f = simplestub.generate(target, b_in, f_in, 3.5, float_arg=4.5) except RuntimeError as e: assert "Generator Input named 'float_arg' was specified by both position and keyword." in str( e) else: assert False, 'Did not see expected exception!' try: # Bad input name f = simplestub.generate(target, b_in, float_arg=3.5, offset=k, funk_input=f_in) except RuntimeError as e: assert "Generator Input named 'func_input' was not specified." in str( e) else: assert False, 'Did not see expected exception!' try: # Bad gp name f = simplestub.generate(target, b_in, float_arg=3.5, offset=k, func_input=f_in, nonexistent_generator_param="wat") except RuntimeError as e: assert "Generator simplestub has no GeneratorParam named: nonexistent_generator_param" in str( e) else: assert False, 'Did not see expected exception!'
def test_simplestub(): x, y = hl.Var(), hl.Var() target = hl.get_jit_target_from_environment() b_in = hl.Buffer(hl.UInt(8), [2, 2]) b_in.fill(123) f_in = hl.Func("f") f_in[x, y] = x + y # ----------- Inputs by-position f = simplestub.generate(target, b_in, f_in, 3.5) _realize_and_check(f) # ----------- Inputs by-name f = simplestub.generate(target, buffer_input=b_in, func_input=f_in, float_arg=3.5) _realize_and_check(f) # ----------- Inputs w/ mixed by-position and by-name f = simplestub.generate(target, b_in, f_in, float_arg=3.5) _realize_and_check(f) f = simplestub.generate(target, b_in, float_arg=3.5, func_input=f_in) _realize_and_check(f) # ----------- Above set again, w/ GeneratorParam mixed in k = 42 f = simplestub.generate(target, b_in, f_in, 3.5, offset=k) _realize_and_check(f, k) f = simplestub.generate(target, offset=k, buffer_input=b_in, func_input=f_in, float_arg=3.5) _realize_and_check(f, k) f = simplestub.generate(target, b_in, f_in, offset=k, float_arg=3.5) _realize_and_check(f, k) f = simplestub.generate(target, b_in, float_arg=3.5, offset=k, func_input=f_in) _realize_and_check(f, k) # ----------- Test various failure modes try: # too many positional args f = simplestub.generate(target, b_in, f_in, 3.5, 4) except RuntimeError as e: assert 'Expected at most 3 positional args, but saw 4.' in str(e) else: assert False, 'Did not see expected exception!' try: # Inputs that can't be converted to what the receiver needs (positional) f = simplestub.generate(target, 3.141592, "happy") except RuntimeError as e: assert 'Unable to cast Python instance' in str(e) else: assert False, 'Did not see expected exception!' try: # Inputs that can't be converted to what the receiver needs (named) f = simplestub.generate(target, b_in, f_in, float_arg="bogus") except RuntimeError as e: assert 'Unable to cast Python instance' in str(e) else: assert False, 'Did not see expected exception!' try: # Missing required inputs f = simplestub.generate(target, b_in, f_in) except RuntimeError as e: assert "Generator Input named 'float_arg' was not specified." in str(e) else: assert False, 'Did not see expected exception!' try: # Input specified by both pos and kwarg f = simplestub.generate(target, b_in, f_in, 3.5, float_arg=4.5) except RuntimeError as e: assert "Generator Input named 'float_arg' was specified by both position and keyword." in str(e) else: assert False, 'Did not see expected exception!' try: # Bad input name f = simplestub.generate(target, b_in, float_arg=3.5, offset=k, funk_input=f_in) except RuntimeError as e: assert "Generator Input named 'func_input' was not specified." in str(e) else: assert False, 'Did not see expected exception!' try: # Bad gp name f = simplestub.generate(target, b_in, float_arg=3.5, offset=k, func_input=f_in, nonexistent_generator_param="wat") except RuntimeError as e: assert "Generator has no GeneratorParam named: nonexistent_generator_param" in str(e) else: assert False, 'Did not see expected exception!'