1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
import os
import shutil
import tempfile
import halide as hl
def main():
x = hl.Var("x")
f = hl.Func("f")
f[x] = 100 * x
args = []
tmpdir = tempfile.mkdtemp()
try:
p = os.path.join(tmpdir, "f.bc")
f.compile_to_bitcode(p, args, "f")
assert os.path.isfile(p)
p = os.path.join(tmpdir, "f.cpp")
f.compile_to_c(p, args, "f")
assert os.path.isfile(p)
p = os.path.join(tmpdir, "f.o")
f.compile_to_object(p, args, "f")
assert os.path.isfile(p)
p = os.path.join(tmpdir, "f.h")
f.compile_to_header(p, args, "f")
assert os.path.isfile(p)
p = os.path.join(tmpdir, "f.s")
f.compile_to_assembly(p, args, "f")
assert os.path.isfile(p)
p = os.path.join(tmpdir, "f.txt")
f.compile_to_lowered_stmt(p, args)
assert os.path.isfile(p)
f.compile_to_file(os.path.join(tmpdir, "f_all"), args)
assert os.path.isfile(os.path.join(tmpdir, "f_all.h"))
if hl.get_target_from_environment().os == hl.TargetOS.Windows:
assert os.path.isfile(os.path.join(tmpdir, "f_all.obj"))
else:
assert os.path.isfile(os.path.join(tmpdir, "f_all.o"))
p = os.path.join(tmpdir, "f.stmt.html")
f.compile_to({hl.OutputFileType.stmt_html: p}, args, "f")
assert os.path.isfile(p)
finally:
shutil.rmtree(tmpdir, ignore_errors=True)
if __name__ == "__main__":
main()
|