diff options
author | Josh Blum | 2012-04-15 17:32:38 -0700 |
---|---|---|
committer | Josh Blum | 2012-04-19 18:12:55 -0700 |
commit | 95e91b44d2ef3535129c0a402c51bc56cfd74d06 (patch) | |
tree | bfd183e0494cb1ea7b5cf87c9319dd7a5c061aaf /volk | |
parent | eccc86fbb8aa0392307bfdf1bd802e4394868334 (diff) | |
download | gnuradio-95e91b44d2ef3535129c0a402c51bc56cfd74d06.tar.gz gnuradio-95e91b44d2ef3535129c0a402c51bc56cfd74d06.tar.bz2 gnuradio-95e91b44d2ef3535129c0a402c51bc56cfd74d06.zip |
volk: created other templates for runtime + machines
Diffstat (limited to 'volk')
-rw-r--r-- | volk/gen/volk_arch_defs.py | 5 | ||||
-rw-r--r-- | volk/gen/volk_kernel_defs.py | 10 | ||||
-rw-r--r-- | volk/gen/volk_machine_defs.py | 3 | ||||
-rw-r--r-- | volk/gen/volk_tmpl_utils.py | 10 | ||||
-rw-r--r-- | volk/tmpl/volk.tmpl.c | 92 | ||||
-rw-r--r-- | volk/tmpl/volk.tmpl.h | 48 | ||||
-rw-r--r-- | volk/tmpl/volk_machine_xxx.tmpl.c | 88 | ||||
-rw-r--r-- | volk/tmpl/volk_machines.tmpl.c | 34 | ||||
-rw-r--r-- | volk/tmpl/volk_machines.tmpl.h | 51 | ||||
-rw-r--r-- | volk/tmpl/volk_typedefs.tmpl.h | 2 |
10 files changed, 336 insertions, 7 deletions
diff --git a/volk/gen/volk_arch_defs.py b/volk/gen/volk_arch_defs.py index 6869ef7a9..c6115d64e 100644 --- a/volk/gen/volk_arch_defs.py +++ b/volk/gen/volk_arch_defs.py @@ -18,6 +18,9 @@ archs = list() arch_dict = dict() +#TODO enable this when we are ready +create_unaligned_archs = False + class arch_class: def __init__(self, **kwargs): for key, cast, failval in ( @@ -44,7 +47,7 @@ def register_arch(**kwargs): arch = arch_class(**kwargs) archs.append(arch) arch_dict[arch.name] = arch - if arch.alignment > 1: + if arch.alignment > 1 and create_unaligned_archs: kwargs['name'] += '_u' kwargs['alignment'] = 1 register_arch(**kwargs) diff --git a/volk/gen/volk_kernel_defs.py b/volk/gen/volk_kernel_defs.py index f598ed3c0..a5c7cb710 100644 --- a/volk/gen/volk_kernel_defs.py +++ b/volk/gen/volk_kernel_defs.py @@ -154,8 +154,7 @@ for func in functions: ret = replace.sub("", ret); replace = re.compile("inline "); ret = replace.sub("", ret); - replace = re.compile("\)"); - arched_args = replace.sub(", const char* arch) {", args); + arched_args = args[args.find('(')+1:args.find(')')] remove = re.compile('\)|\(|{'); rargs = remove.sub("", args); @@ -198,8 +197,13 @@ for func in functions: class kernel_class: def __init__(self, index): self.name = functions[index] + self.pname = self.name.replace('volk_', 'p_') self.rettype = retlist[index] - self.arglist = my_argtypelist[index] + self.arglist_defs = my_argtypelist[index] + self.arglist_namedefs = arched_arglist[index] + self.arglist_names = my_arglist[index] + self.tagdeps = fcountlist[index] + self.taglist = taglist[index] def __repr__(self): return self.name diff --git a/volk/gen/volk_machine_defs.py b/volk/gen/volk_machine_defs.py index 1c879cd50..82734679c 100644 --- a/volk/gen/volk_machine_defs.py +++ b/volk/gen/volk_machine_defs.py @@ -32,6 +32,7 @@ class machine_class: if arch.alignment > 1 and arch_dict.has_key(arch_name): arch = arch_dict[arch_name] self.archs.append(arch) + self.alignment = max(map(lambda a: a.alignment, self.archs)) def __repr__(self): return self.name @@ -39,7 +40,7 @@ def register_machine(name, archs): for i, arch_name in enumerate(archs): if '|' in arch_name: #handle special arch names with the '|' for arch_sub in arch_name.split('|'): - register_machine(name, archs[:i] + [arch_sub] + archs[i+1:]) + register_machine(name+'_'+arch_sub, archs[:i] + [arch_sub] + archs[i+1:]) return machine = machine_class(name=name, archs=archs) machines.append(machine) diff --git a/volk/gen/volk_tmpl_utils.py b/volk/gen/volk_tmpl_utils.py index 804cc2f28..92b7fb1a4 100644 --- a/volk/gen/volk_tmpl_utils.py +++ b/volk/gen/volk_tmpl_utils.py @@ -37,6 +37,7 @@ def __escape_pre_processor(code): conly = fcn in ('include', 'define', 'ifdef', 'ifndef', 'endif', 'elif') both = fcn in ('if', 'else') istmpl = '$' in stuff + if 'defined' in stuff: istmpl = False if conly or (both and not istmpl): line = '%s\\#%s%s%s'%(p0, p1, fcn, stuff) out.append(line) @@ -45,7 +46,9 @@ def __escape_pre_processor(code): def __parse_tmpl(_tmpl, **kwargs): defs = { 'archs': volk_arch_defs.archs, + 'arch_dict': volk_arch_defs.arch_dict, 'machines': volk_machine_defs.machines, + 'machine_dict': volk_machine_defs.machine_dict, 'kernels': volk_kernel_defs.kernels, } defs.update(kwargs) @@ -58,4 +61,9 @@ def __parse_tmpl(_tmpl, **kwargs): return str(Template.Template(_tmpl, defs)) if __name__ == '__main__': - print __parse_tmpl(open(sys.argv[1]).read()) + input_file = sys.argv[1] + output_file = sys.argv[2] + which = sys.argv[3] + output = __parse_tmpl(open(input_file).read(), which=which) + if output_file: open(output_file, 'w').write(output) + else: print output diff --git a/volk/tmpl/volk.tmpl.c b/volk/tmpl/volk.tmpl.c new file mode 100644 index 000000000..161f49a43 --- /dev/null +++ b/volk/tmpl/volk.tmpl.c @@ -0,0 +1,92 @@ +/* + * Copyright 2011-2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include <volk/volk_common.h> +#include "volk_machines.h" +#include <volk/volk_typedefs.h> +#include <volk/volk_cpu.h> +#include "volk_rank_archs.h" +#include <volk/volk.h> +#include <stdio.h> +#include <string.h> + +struct volk_machine *get_machine(void) { + extern struct volk_machine *volk_machines[]; + extern unsigned int n_volk_machines; + static struct volk_machine *machine = NULL; + + if(machine != NULL) return machine; + else { + unsigned int max_score = 0; + unsigned int i; + for(i=0; i<n_volk_machines; i++) { + if(!(volk_machines[i]->caps & (~volk_get_lvarch()))) { + if(volk_machines[i]->caps > max_score) { + max_score = volk_machines[i]->caps; + machine = volk_machines[i]; + } + } + } + printf("Using Volk machine: %s\n", machine->name); + return machine; + } +} + +unsigned int volk_get_alignment(void) { + return get_machine()->alignment; +} + +#for $kern in $kernels + +void get_$(kern.name)($kern.arglist_defs) { + $kern.name = get_machine()->$(kern.name)_archs[volk_rank_archs( + get_machine()->$(kern.name)_indices, + get_machine()->$(kern.name)_arch_defs, + get_machine()->$(kern.name)_n_archs, + get_machine()->$(kern.name)_name, + volk_get_lvarch() + )]; + $(kern.name)($kern.arglist_names); +} + +$kern.pname $kern.name = &get_$(kern.name); + +void $(kern.name)_manual($kern.arglist_defs, const char* arch) { + const size_t index = get_index( + get_machine()->$(kern.name)_indices, + get_machine()->$(kern.name)_n_archs, + arch + ); + get_machine()->$(kern.name)_archs[index]( + $kern.arglist_names + ); +} + +struct volk_func_desc volk_32f_x2_add_32f_a_get_func_desc(void) { + struct volk_func_desc desc = { + get_machine()->$(kern.name)_indices, + get_machine()->$(kern.name)_arch_defs, + get_machine()->$(kern.name)_n_archs + }; + return desc; +} + +#end for diff --git a/volk/tmpl/volk.tmpl.h b/volk/tmpl/volk.tmpl.h new file mode 100644 index 000000000..161579e46 --- /dev/null +++ b/volk/tmpl/volk.tmpl.h @@ -0,0 +1,48 @@ +/* + * Copyright 2011-2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_VOLK_RUNTIME +#define INCLUDED_VOLK_RUNTIME + +#include <volk/volk_typedefs.h> +#include <volk/volk_config_fixed.h> +#include <volk/volk_common.h> +#include <volk/volk_complex.h> + +__VOLK_DECL_BEGIN + +struct volk_func_desc { + const char **indices; + const int *arch_defs; + const int n_archs; +}; + +VOLK_API unsigned int volk_get_alignment(void); + +#for $kern in $kernels +extern VOLK_API $kern.pname $kern.name; +extern VOLK_API void $(kern.name)_manual($kern.arglist_namedefs, const char* arch); +extern VOLK_API struct volk_func_desc $(kern.name)_get_func_desc(void); +#end for + +__VOLK_DECL_END + +#endif /*INCLUDED_VOLK_RUNTIME*/ diff --git a/volk/tmpl/volk_machine_xxx.tmpl.c b/volk/tmpl/volk_machine_xxx.tmpl.c new file mode 100644 index 000000000..57e652e4c --- /dev/null +++ b/volk/tmpl/volk_machine_xxx.tmpl.c @@ -0,0 +1,88 @@ +/* + * Copyright 2011-2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#set $this_machine = $machine_dict[$which] + +#for $arch in $this_machine.archs +#define LV_HAVE_$(arch.name.upper()) 1 +#end for + +#include <volk/volk_common.h> +#include "volk_machines.h" +#include <volk/volk_config_fixed.h> + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#for $kern in $kernels +#include <volk/$(kern.name).h> +#end for + +######################################################################## +#def make_arch_have_list($archs) +$(' | '.join(['(1 << LV_%s)'%a.name.upper() for a in $archs]))#slurp +#end def + +######################################################################## +#def make_tag_str_list($tags) +{$(', '.join(['"%s"'%a for a in $tags]))}#slurp +#end def + +######################################################################## +#def make_tag_have_list($deps) +{$(', '.join([' | '.join(['(1 << LV_%s)'%a.upper() for a in d]) for d in $deps]))}#slurp +#end def + +######################################################################## +#def make_tag_kern_list($name, $tags) +{$(', '.join(['%s_%s'%($name, a) for a in $tags]))}#slurp +#end def + +#ifdef LV_HAVE_ORC +struct volk_machine volk_machine_generic = { + $make_arch_have_list($this_machine.archs) | (1 << LV_ORC), + "$this_machine.name", + $this_machine.alignment, + #for $kern in $kernels + "$kern.name", + $make_tag_str_list($kern.taglist), + $make_tag_have_list($kern.tagdeps), + $make_tag_kern_list($kern.name, $kern.taglist), + $(len($kern.taglist)), + #end for +}; + +#else +struct volk_machine volk_machine_generic = { + $make_arch_have_list($this_machine.archs), + "$this_machine.name", + $this_machine.alignment, + #for $kern in $kernels + "$kern.name", + $make_tag_str_list($kern.taglist), + $make_tag_have_list($kern.tagdeps), + $make_tag_kern_list($kern.name, $kern.taglist), + $(len($kern.taglist)), + #end for +}; + +#endif diff --git a/volk/tmpl/volk_machines.tmpl.c b/volk/tmpl/volk_machines.tmpl.c new file mode 100644 index 000000000..57dd03c98 --- /dev/null +++ b/volk/tmpl/volk_machines.tmpl.c @@ -0,0 +1,34 @@ +/* + * Copyright 2011-2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include <volk/volk_common.h> +#include <volk/volk_typedefs.h> +#include "volk_machines.h" + +struct volk_machine *volk_machines[] = { +#for $machine in $machines +#ifdef LV_MACHINE_$(machine.name.upper()) +&volk_machine_$(machine.name), +#endif +#end for +}; + +unsigned int n_volk_machines = sizeof(volk_machines)/sizeof(*volk_machines); diff --git a/volk/tmpl/volk_machines.tmpl.h b/volk/tmpl/volk_machines.tmpl.h new file mode 100644 index 000000000..b30e600ed --- /dev/null +++ b/volk/tmpl/volk_machines.tmpl.h @@ -0,0 +1,51 @@ +/* + * Copyright 2011-2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_LIBVOLK_MACHINES_H +#define INCLUDED_LIBVOLK_MACHINES_H + +#include <volk/volk_common.h> +#include <volk/volk_typedefs.h> + +__VOLK_DECL_BEGIN + +struct volk_machine { + const unsigned int caps; //capabilities (i.e., archs compiled into this machine, in the volk_get_lvarch format) + const char *name; + const unsigned int alignment; //the maximum byte alignment required for functions in this library + #for $kern in $kernels + const char *$(kern.name)_name; + const char *$(kern.name)_indices[$(len($archs))]; + const int $(kern.name)_arch_defs[$(len($archs))]; + const $(kern.pname) $(kern.name)_archs[$(len($archs))]; + const int $(kern.name)_n_archs; + #end for +}; + +#for $machine in $machines +#ifdef LV_MACHINE_$(machine.name.upper()) +extern struct volk_machine volk_machine_$(machine.name); +#endif +#end for + +__VOLK_DECL_END + +#endif //INCLUDED_LIBVOLK_MACHINES_H diff --git a/volk/tmpl/volk_typedefs.tmpl.h b/volk/tmpl/volk_typedefs.tmpl.h index 947cb9ed5..2577df14e 100644 --- a/volk/tmpl/volk_typedefs.tmpl.h +++ b/volk/tmpl/volk_typedefs.tmpl.h @@ -26,7 +26,7 @@ #include <volk/volk_complex.h> #for $kern in $kernels -typedef $kern.rettype (*$(kern.name.replace('volk_', 'p_')))($kern.arglist); +typedef $kern.rettype (*$(kern.pname))($kern.arglist); #end for #endif /*INCLUDED_VOLK_TYPEDEFS*/ |