mirror of https://gitlab.com/ita1024/waf.git
extras: add halide code generation tool
This commit is contained in:
parent
49a8bb15b2
commit
3e378c45bf
|
@ -0,0 +1,122 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Halide code generation tool
|
||||
|
||||
__author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
|
||||
__copyright__ = "Jérôme Carretero, 2014"
|
||||
|
||||
"""
|
||||
|
||||
Tool to run `Halide <http://halide-lang.org>`_ code generators.
|
||||
|
||||
Usage::
|
||||
|
||||
bld(
|
||||
name='pipeline',
|
||||
# ^ Reference this in use="..." for things using the generated code
|
||||
features='halide',
|
||||
halide_env="HL_TRACE=1 HL_TARGET=host-opencl-gpu_debug",
|
||||
# ^ Environment passed to the generator,
|
||||
# can be a dict, k/v list, or string.
|
||||
args=[],
|
||||
# ^ Command-line arguments to the generator (optional),
|
||||
# eg. to give parameters to the scheduling
|
||||
source='pipeline_gen',
|
||||
# ^ Name of the source executable
|
||||
)
|
||||
|
||||
|
||||
Known issues:
|
||||
|
||||
- Currently only handles .o+.h generation
|
||||
|
||||
- Currently the generator must name its generated files
|
||||
like himself ('source' not 'name').
|
||||
eg. halide_x.cpp -> halide_x.{o,h}
|
||||
|
||||
- Currently only supports Linux (no ".exe")
|
||||
|
||||
- Doesn't rerun on input modification when input is part of a build
|
||||
chain, and has been modified externally.
|
||||
|
||||
"""
|
||||
|
||||
from waflib import Node, Task, Utils, Options, TaskGen, Errors
|
||||
|
||||
class run_halide_gen(Task.Task):
|
||||
color = 'CYAN'
|
||||
vars = ['HALIDE_ENV', 'HALIDE_ARGS']
|
||||
run_str = "${SRC[0].abspath()} ${HALIDE_ARGS}"
|
||||
def __str__(self):
|
||||
stuff = "halide"
|
||||
stuff += ("[%s]" % (",".join(
|
||||
('%s=%s' % (k,v)) for k, v in sorted(self.env.env.items()))))
|
||||
return Task.Task.__str__(self).replace(self.__class__.__name__,
|
||||
stuff)
|
||||
|
||||
@TaskGen.feature('halide')
|
||||
@TaskGen.before_method('process_source')
|
||||
def halide(self):
|
||||
Utils.def_attrs(self,
|
||||
args=[],
|
||||
halide_env={},
|
||||
)
|
||||
|
||||
bld = self.bld
|
||||
|
||||
env = self.halide_env
|
||||
try:
|
||||
if isinstance(env, str):
|
||||
env = dict(x.split('=') for x in env.split())
|
||||
elif isinstance(env, list):
|
||||
env = dict(x.split('=') for x in env)
|
||||
assert isinstance(env, dict)
|
||||
except Exception as e:
|
||||
if not isinstance(e, ValueError) \
|
||||
and not isinstance(e, AssertionError):
|
||||
raise
|
||||
raise Errors.WafError(
|
||||
"halide_env must be under the form" \
|
||||
" {'HL_x':'a', 'HL_y':'b'}" \
|
||||
" or ['HL_x=y', 'HL_y=b']" \
|
||||
" or 'HL_x=y HL_y=b'")
|
||||
|
||||
src = self.to_nodes(self.source)
|
||||
assert len(src) == 1, "Only one source expected"
|
||||
src = src[0]
|
||||
|
||||
args = Utils.to_list(self.args)
|
||||
|
||||
tgt = [src.change_ext('.o'), src.change_ext('.h')]
|
||||
task = self.create_task('run_halide_gen', src, tgt)
|
||||
task.env.append_unique('HALIDE_ARGS', args)
|
||||
oldenv = task.env.env
|
||||
if task.env.env == []:
|
||||
task.env.env = {}
|
||||
task.env.env.update(env)
|
||||
task.env.HALIDE_ENV = " ".join(("%s=%s" % (k,v)) for (k,v) in sorted(env.items()))
|
||||
task.env.HALIDE_ARGS = args
|
||||
|
||||
try:
|
||||
self.compiled_tasks.append(task)
|
||||
except AttributeError:
|
||||
self.compiled_tasks = [task]
|
||||
self.source = []
|
||||
|
||||
def configure(conf):
|
||||
if Options.options.halide_root is None:
|
||||
conf.check_cfg(package='Halide', args='--cflags --libs')
|
||||
else:
|
||||
halide_root = Options.options.halide_root
|
||||
conf.env.INCLUDES_HALIDE = [ os.path.join(halide_root, "include") ]
|
||||
conf.env.LIBPATH_HALIDE = [ os.path.join(halide_root, "lib") ]
|
||||
conf.env.LIB_HALIDE = ["Halide"]
|
||||
|
||||
# You might want to add this, while upstream doesn't fix it
|
||||
#conf.env.LIB_HALIDE += ['ncurses', 'dl', 'pthread']
|
||||
|
||||
def options(opt):
|
||||
opt.add_option('--halide-root',
|
||||
help="path to Halide include and lib files",
|
||||
)
|
||||
|
Loading…
Reference in New Issue