예제 #1
0
class Fctr_list(Functor) :
    """get functor list according criterias"""
    def __init__(self, tool_box_name) :
        Functor.__init__(self, tool_box_name,'check')
        self.logger = Mylogging("nt2.fctor_lists.Fctr_list")
        st = self.check_tbox()  
        if not st :
            self.logger.error(
                "\ntoolbox %s does not exists\n" % self.get_tb_name() +
                "in path: %s\n" % self.get_tb_abs_path()
                )

    def get_functors_rel_path(self) :
        a = os.path.join(self.get_tb_abs_path(),self.get_tb_name()+'.hpp')
        s = read(a)
        r = []
        for l in s :
            m= re.search('\#include <(.*)>',l)
            if m :
                r.append(m.groups()[0])
        return r

    def get_functors_abs_path(self) :
        s = self.get_functors_rel_path()
        a = self.get_path_to_nt2()
        r = []
        for l in s :
            r.append(os.path.join(a,l))
        return r
    
    def get_functors_names(self) :
        s = self.get_functors_rel_path()
        r = []
        for l in s :
            r.append(l.split('/')[-1])
        return r

    def get_functors_datas(self) :
        pathes = self.get_functors_abs_path()
        dr = {}
        for p in pathes :
            d= {}
            lp = p.split('/')
            lp[-2]= 'function'
            name = lp[-1][:-4]
            s = read('/'.join(lp))
            r = []
            for l in s :
                m= re.search('([0-9]+)\) *$',l)
                if m : r.append(int(m.groups()[0]))
            d["arity"]=r
            dr[name]=d    
        return dr   
예제 #2
0
 def __init__(self, tool_box_name) :
     Functor.__init__(self, tool_box_name,'check')
     self.logger = Mylogging("nt2.fctor_lists.Fctr_list")
     st = self.check_tbox()  
     if not st :
         self.logger.error(
             "\ntoolbox %s does not exists\n" % self.get_tb_name() +
             "in path: %s\n" % self.get_tb_abs_path()
             )
예제 #3
0
 def __init__(self, tool_box_name,
              mode = 'modify',
              style='usr',
              actions = None) :
     self.logger = Mylogging("nt2.fctor.Functor")
     Toolbox.__init__(self, tool_box_name, mode=mode, style=style)
     if not self.get_tb_status() and mode !='check' :
         self.logger.error(
             "\ntoolbox %s has invalid status\n" % self.get_tb_name() +
             "aborting"
             )
         raise SystemExit
     self.__fct_actions = Functor.Fct_actions if actions is None else actions
     self.ext='.hpp'
예제 #4
0
 def __init__(self,
              year = None,
              banner_cpght = None,
              banner_template_begin = None,
              banner_template_end   = None,
              comment = '//') :
     self.logger = Mylogging("nt2.banner.Banner")
     self.__banner_begin = Banner.Std_begin if (banner_template_begin is None) else banner_template_begin
     self.__banner_end   = Banner.Std_end   if (banner_template_end   is None) else banner_template_end
     self.__banner_cpght = Banner.Std_cpght if (banner_cpght          is None) else banner_cpght 
     self.__year = year
     self.__comment=comment
     self.set_year()
     self.cpght = sub_list('^//',self.__comment,self.__banner_cpght)
     self.__banner_begin = sub_list('^//',self.__comment,self.__banner_begin)
     self.__banner_end = sub_list('^//',self.__comment,self.__banner_end)
     self.__banner_cpght = sub_list('<year>',self.__year,self.__banner_cpght)
     self.__banner_cpght = sub_list('^//',self.__comment,self.__banner_cpght)
     self.__banner_begin = sub_list('@',self.__comment[0],self.__banner_begin)
     self.__banner_end = sub_list('@',self.__comment[0],self.__banner_end)
     self.__banner_cpght = sub_list('@',self.__comment[0],self.__banner_cpght)
예제 #5
0
class Banner :
    """create nt2 banner

       you can set a banner_template_begin and a banner_template_end as string lists
       but defaults are provided

       you can also define or add to the default list banner_cprth (copyrights)
    """
    Std_begin = [
        "//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
        ]
    Std_end = [
        "//@",
        "//@          Distributed under the Boost Software License, Version 1.0",
        "//@                 See accompanying file LICENSE.txt or copy at",
        "//@                     http://www.boost.org/LICENSE_1_0.txt",
        "//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
        ]
    Std_cpght = [
        "//@   Copyright 2003 and onward LASMEA UMR 6602 CNRS/U.B.P Clermont-Ferrand",  
        "//@   Copyright 2009 and onward LRI    UMR 8623 CNRS/Univ Paris Sud XI",
        ]
    def __init__(self,
                 year = None,
                 banner_cpght = None,
                 banner_template_begin = None,
                 banner_template_end   = None,
                 comment = '//') :
        self.logger = Mylogging("nt2.banner.Banner")
        self.__banner_begin = Banner.Std_begin if (banner_template_begin is None) else banner_template_begin
        self.__banner_end   = Banner.Std_end   if (banner_template_end   is None) else banner_template_end
        self.__banner_cpght = Banner.Std_cpght if (banner_cpght          is None) else banner_cpght 
        self.__year = year
        self.__comment=comment
        self.set_year()
        self.cpght = sub_list('^//',self.__comment,self.__banner_cpght)
        self.__banner_begin = sub_list('^//',self.__comment,self.__banner_begin)
        self.__banner_end = sub_list('^//',self.__comment,self.__banner_end)
        self.__banner_cpght = sub_list('<year>',self.__year,self.__banner_cpght)
        self.__banner_cpght = sub_list('^//',self.__comment,self.__banner_cpght)
        self.__banner_begin = sub_list('@',self.__comment[0],self.__banner_begin)
        self.__banner_end = sub_list('@',self.__comment[0],self.__banner_end)
        self.__banner_cpght = sub_list('@',self.__comment[0],self.__banner_cpght)

    def add_cpght(self, cpght) :
        if type(cpght) is str :
            self.__banner_cpght.append(cpght)
        elif type(cpght) is list :
            self.__banner_cpght.extend(cpght)
        self.__banner_cpght = sub_list('<year>',self.__year,self.__banner_cpght)
        self.__banner_cpght = sub_list('^//',self.__comment,self.__banner_cpght)
        self.__banner_cpght = sub_list('@',self.__comment[0],self.__banner_cpght)
                  
    def __str__(self) :
        return "\n".join(self.__call__())
    
    def set_year(self) :
        if self.__year is None :
            self.__year = time.localtime().tm_year
        if type(self.__year) is not str :
            self.__year = str(self.__year)
        if len(self.__year)==1 :
            self.__year = '0'+self.__year
        if len(self.__year)==2 :
            self.__year = "20"+self.__year
        try :
            self.__year = str(int(self.__year))
        except :
            saved_year =self.__year
            self.logger.warning(
                "\nin setyear\n"+
                ("year has been given the incorrect value: %s" % self.__year)
                )
            self.__year = str(time.localtime().tm_year)
            self.logger.warning(
                "\nin Banner.setyear\n "+
                "year has been given the incorrect value: %s" % saved_year +
                "\nyear is turned to %s " % self.__year
                )
        self.__banner_cpght = sub_list('<year>',self.__year,self.__banner_cpght)

    def get_banner(self) :
        """ return the complete banner """
        return self.__banner_begin + self.__banner_cpght + self.__banner_end
    def __call__(self) :
        """ return the complete banner """
        return self.__banner_begin + self.__banner_cpght + self.__banner_end
    def get_banner_begin(self) :
        """ return the high part of the banner """
        return self.__banner_begin
    def get_banner_end(self) :
        """ return the low part of the banner """
        return self.__banner_end
    def get_banner_cprght(self) :
        """ return the copyright part of the banner """
        return self.__banner_cpght
    def get_year(self) :
        """ return the current end year of the copyright"""
        return self.__year
예제 #6
0
            #### match for token
            pattern = re.compile(token)
            i = find_index(pattern)
            if i != 0 :
                text.insert(i,line2add)
            return (True,text)

    def __rmv_line(self,text, line2rmv) :
        if line2rmv in text :
            text.remove(line2rmv)
            return (True,text)
        else :
            return (False,text)

    def read_functor(self,fct_name,type) :
        fct_name_path = os.path.join(self.get_tb_abs_path(),'function',type,fct_name+'.hpp')
        r = read(fct_name_path)
        return r

    def write_functor(self,fct_name,type,s,check) :
        fct_name_path = os.path.join(self.get_tb_abs_path(),'function',type,fct_name+'.hpp')
        r = write(fct_name_path,s,check)

if __name__ == "__main__":
    Mylogging.set_level('ERROR')
    tb = Functor("pipo3")
    tb.add_functor("zorro",fct_arity=2)
#    tb.add_functor("zzo",fct_arity=2)
    print "done"
#    tb.rmv_functor("zorro")
예제 #7
0
            l.extend(r)
        return l

    def create_txt(self,s,tb_name) :
        r = []
        for l in s :
            m= re.search('\#include <nt2/toolbox/'+tb_name+'/include/(.*)>',l)
            if m :
                fct_name =m.groups()[0][:-4]
                r.append(fct_name)
        return r    

    def get_simd_propers(self,arch,modes,fcts) :
        for tb_name in self.tb_list :
            for k in modes.keys()[1:] :
                for name in fcts :
                    src = os.path.join(self.absolute_path_to_mode(),tb_name,"function/simd",arch,k,name+'.hpp')
                    if  exist(src) and (os.path.getsize(src) > 1536) :
                        print "in toobox %s in mode %s functor %s has a proper implementation " % (tb_name, k, name)
            
       
if __name__ == "__main__":
    Mylogging.set_level('CRITICAL')
    f = Findintr()#["arithmetic"])
#    l = f.get_list()
#    show(f.get_list())
    show(f.get_simd_propers("sse",Sse.Variants,f.get_list()))
#    show(f.get_includes())
#    show(f.get_unexpected())

예제 #8
0
        return self.__banner_begin + self.__banner_cpght + self.__banner_end
    def get_banner_begin(self) :
        """ return the high part of the banner """
        return self.__banner_begin
    def get_banner_end(self) :
        """ return the low part of the banner """
        return self.__banner_end
    def get_banner_cprght(self) :
        """ return the copyright part of the banner """
        return self.__banner_cpght
    def get_year(self) :
        """ return the current end year of the copyright"""
        return self.__year

if __name__ == "__main__":
    Mylogging.set_level('INFO')
    print Mylogging.get_level()
    banner = Banner()
    print banner
    banner = Banner(20)
    print banner
    banner = Banner('2013')
    print banner
    banner = Banner('z')
    print banner
    banner.add_cpght("//*   Copyright 1907-<year> ZORGLUB THE GREAT      ") 
    print banner
    banner = Banner('z',comment='##')
    print banner
    banner.add_cpght("//*      Copyright 1907-<year> ZORGLUB THE GREAT      ") 
    print banner
예제 #9
0
    def __init__(self, tool_box_name,
                 mode = 'create',
                 p2nt2 = None,
                 style = 'usr') :

        """creation or recovery of a toolbox
         <tool_box_name> is the name of the toolbox

         <mode> is the opening mode. Proper modes are create(default) or modify

             create : creates a new toolbox tree under .../nt2/toolbox/
                  with the given <tool_box_name> provided that a 
                  directory of this name not existed previously (default)
             update : add all missing directories or files to an existing
                      toolbox without modifying any existing files or
                      directories
             modify : creates a new toolbox tree or allow access to an
                  existing one to add or suppress functors extensions

          <p2nt2> is the path to nt2. The path defaults to the computation 
                  furnished by the Nt2 class
          <style> determines if the functors defined in the toolbox functors
                  will reside in the namespace nt2 ('sys') or in the namespace
                  <tool_box_name> ('usr'). It is only needed when mode is  
                  'create' and is 'usr' by default. The other modes recover
                  the creation parameter from existing data: in the present
                  implementation, once created the toolbox mode cannot be
                  modified.
        """

        Mode = [ 'create', 'update', 'check', 'modify']
        Style = ['usr','sys']
        Nt2.__init__(self,'toolbox')
        self.__status = True
        self.logger = Mylogging("nt2.toolbox.Toolbox")
        if p2nt2 is None : p2nt2 = self.get_path2nt2()
        self.__tb_name     = tool_box_name
        self.__tb_pathfnt2 = os.path.join(self.get_pathfnt2(),self.__tb_name)
        self.__tb          = os.path.join(self.get_path2nt2(),self.__tb_pathfnt2)
        self.__tb_path2mode= os.path.join(self.get_path2nt2(),self.get_pathfnt2())
        self.__tb_style = style if style == "sys" else "usr"
        if os.path.exists(self.get_tb_abs_path()) : self.read_style()    
        self.__test_status = True
        self.__mode = mode
        self.__tb_tree = Toolbox.Tb_tree
        self.__tb_files= Toolbox.Tb_files
        Tb_files.__init__(self,self.__tb_name,self.__tb_path2mode,
                          self.__tb_tree,
                          self.__tb_files,
                          style)
        if mode in Mode :
            self.logger.info(
                ("\nopening toolbox %s with mode: "% self.__tb_name) +
                mode+"\nin directory\n" +
                self.__tb
                )
            action = getattr(self,mode+'_tbox')
            action()
        else:
            self.logger.error(
                "\nopening with unknown mode: "+mode+"\n"+
                " raising SystemExit\n"
                )
            raise SystemExit
예제 #10
0
            d1 = re.match("(^.*/)nt2/",d).groups()
        except :
            nt2_env_logger.error(
                     "\n Environment chain 'NT2_DIR' is not defined\n"+
                     "and your current path does not contain /nt2/\n"+
                     "sorry aborting\n"+
                     nt2_dir.__doc__
                     )
            raise SystemExit
        if len(d1)!=0 : d = d1[0]
        nt2_env_logger.warning(
                     "\n Environment chain 'NT2_DIR' is not defined\n "+
                     ("defaulting to %s\n"%d)+
                     nt2_dir.__doc__
                     )
    return os.path.expanduser(os.path.join(d,"nt2/include/"))

def nt2_py_dir() :
    return os.path.dirname(os.path.realpath(__file__))

        
if __name__ == "__main__":
    Mylogging.set_level('INFO')
    print "nt2_dir %s" % nt2_dir()
    print "------------"
    print "sys.path[0] %s" % sys.path[0]
    print "------------"
    print "os.getcwd() %s" % os.getcwd()
    print "------------"

예제 #11
0
class Functor(Toolbox) :
    """adding/removing functors to a toolbox"""
    Fct_actions = {
        "" : {
            'add'   : {
                "file" : "../../include/functions/$fct_name$.hpp",
                "tmpl" : "gbl_include.tpl",
                "cmmt" : "//",
                "head" : 'full',
                },
             'mdy'   : {
                "file" : "$root_name$.hpp",
                "l2ad" : "#include <$self.tb_pathfnt2$/include/$fct_name$.hpp>",
                "tokn" : "//<\include>",
                },
            },
        "bench/scalar"       : {
            'add'   : {
                "file" : "$fct_name$.cpp",
                "tmpl" : "mk_cppbench.tpl",
                "cmmt" : "//",
                "head" : 'banner+inner',
                "parm" : "nt2::uint32_t",
                },
            'mdy'   : {
                "file" : "CMakeLists.txt",
                "l2ad" : "  $fct_name$.cpp",
                "tokn" : "SET\( SOURCES",
                },
            },
        "bench/simd"       : {
            'add'   : {
                "file" : "$fct_name$.cpp",
                "tmpl" : "mk_cppbench.tpl",
                "cmmt" : "//",
                "head" : 'banner+inner',
                "parm" : "nt2::simd::native<float,nt2::tag::sse_>",
                },
            'mdy'   : {
                "file" : "CMakeLists.txt",
                "l2ad" : "  $fct_name$.cpp",
                "tokn" : "SET\( SOURCES",
                },
            },
        "doc/source"             : {
            "add"   : {
                "file" : "$fct_name$.rst",
                "tmpl" : "mk_doc.tpl",
                "cmmt" : "  ",
                "head" : 'inner'
                },
            }, 
        "include"                : {
            "add"   : {
                "file" : "$fct_name$.hpp",
                "tmpl" : "mk_include.tpl",
                "cmmt" : "//",
                "head" : "full"
                }
            },
        "function"               : {
            "add"   : {
                "file" : "$fct_name$.hpp",
                "tmpl" : "mk_define.tpl",
                "cmmt" : "//",
                "head" : "full"
                }
            },                  
        "function/scalar"        : {
            "add"   : {
                "file" : "$fct_name$.hpp",
                "tmpl" : "mk_scalar.tpl",
                "cmmt" : "//",
                "head" : "full"
                }
            },
        "function/simd/common"   : {
            "add"   : {
                "file" : "$fct_name$.hpp",
                "tmpl" : "mk_common.tpl",
                "cmmt" : "//",
                "head" : "full"
                }
            },   
        "function/simd/vmx"      : {
            "hie"   : {
                "file" : "$fct_name$.hpp",
                "hier" : Vmx(),
                "cmmt" : "//",
                "head" : "full"
                }
            },
        "function/simd/sse"      : {
            "hie"   : {
                "file" : "$fct_name$.hpp",
                "hier" : Sse(),
                "cmmt" : "//",
                "head" : "full"
                }
            },
        "unit/scalar"       : {
            'add'   : {
                "file" : "$fct_name$.cpp",
                "tmpl" : "mk_cppunit.tpl",
                "cmmt" : "//",
                "head" : 'banner+inner'
                },
            'mdy'   : {
                "file" : "CMakeLists.txt",
                "l2ad" : "  $fct_name$.cpp",
                "tokn" : "SET\( SOURCES",
                },
            },
        "unit/simd"       : {
            'add'   : {
                "file" : "$fct_name$.cpp",
                "tmpl" : "mk_cppunit_simd.tpl",
                "cmmt" : "//",
                "head" : 'banner+inner'
                },
            'mdy'   : {
                "file" : "CMakeLists.txt",
                "l2ad" : "  $fct_name$.cpp",
                "tokn" : "SET\( SOURCES",
                },
            },
        }
    def __init__(self, tool_box_name,
                 mode = 'modify',
                 style='usr',
                 actions = None) :
        self.logger = Mylogging("nt2.fctor.Functor")
        Toolbox.__init__(self, tool_box_name, mode=mode, style=style)
        if not self.get_tb_status() and mode !='check' :
            self.logger.error(
                "\ntoolbox %s has invalid status\n" % self.get_tb_name() +
                "aborting"
                )
            raise SystemExit
        self.__fct_actions = Functor.Fct_actions if actions is None else actions
        self.ext='.hpp'
        
    def get_fct_actions(self) : return self.__fct_actions
        
    def add_functor(self,fct_name,fct_arity=1) :
        "adding a new functor"
        self.read_style()
        def strlist(tpl,n=1,sep = ", ") :
            s = tpl % (n*(0,))
            tpl =sep+tpl
            for i in range(1,fct_arity) :
                s += tpl % (n*(i,))
            return s
        if self.get_tb_style()[0] != 's' :
            tb_taggedname =  self.get_tb_name()+'::'+fct_name
        else :
            tb_taggedname = fct_name
        subs_dict = {
            "\$self.tb_name\$"              : self.get_tb_name(),
            "\$self.tb_nameupper\$"         : self.get_tb_name().upper(),
            "\$self.name\$"                 : fct_name,
            "\$self.arity\$"                : str(fct_arity),
            "\$self.class_list\$"           : strlist("class A%d"),
            "\$self.const_type_list\$"      : strlist("A0",0), 
            "\$self.const_class_list\$"     : strlist("class A0",0), 
            "\$self.type_list\$"            : strlist("A%d"),
            "\$self.parm_list\$"            : strlist("a%d"),
            "\$self.parm_list_j\$"          : strlist("a%d[j]"),
            "\$self.const_type_T_list\$"    : strlist("T",0),
            "\$self.const_type_n_t_list\$"  : strlist("n_t",0), 
            "\$self.gl_list\$"              : strlist("//    n_t a%d = load<n_t>(&data[0],%d);",2,"\n"),
            "\$self.call_list\$"            : strlist("const A%d& a%d",2),
            "\$self.const_type_call_list\$" : strlist("const A0& a%d",1),
            "\$self.tb_namespace\$"         : self.get_tb_namespace(),
            "\$self.tb_taggedname\$"        : tb_taggedname,
            "\$parms_type_and_ranges\$"     : strlist("(($parm$, -10, 10))",0,"\n//"+(17+len(fct_name))*' '),
            }
        for acts, datas in self.get_fct_actions().items() :
            action_names = self.get_fct_actions()[acts]
            for action_name, action_data in action_names.items() :
                action = getattr(Functor,action_name,None)
                action(self,fct_name,acts,subs_dict,action_data,check=True)

    def rmv_functor(self,fct_name) :
        "removing an existing functor"
        for acts, datas in self.get_fct_actions().items() :
            action_names = self.get_fct_actions()[acts]
            for action_name, action_data in action_names.items() :
                action_name = action_name[::-1]
                action = getattr(Functor,action_name,None)
                action(self,fct_name,acts,{},action_data,check=True)


    def add(self,fct_name,acts,subs_dict,action_data,check=True) :
        """add a file"""
        do_it = True
        fname = action_data["file"].replace('$fct_name$',fct_name)
        fct_name_path = os.path.abspath(os.path.join(self.get_tb_abs_path(),acts,fname))
        if acts != "" :
            rel_path = os.path.join(self.get_tb_pathfnt2(),acts)
        else :
            rel_path = 'nt2/include/functions'
            do_it = self.get_tb_style()[0]=='s'
        if do_it :
            tplname = '../tpl/'+action_data["tmpl"]
            # print  "action_data[tmpl] %s" % action_data["tmpl"]
            tpl_name_path = os.path.join(nt2_py_dir(),tplname)
            if "parm" in action_data.keys() :
                s = subs_dict["\$parms_type_and_ranges\$"]
                subs_dict["\$parms_type_and_ranges\$"] =  re.sub('\$parm\$', action_data["parm"], s)
            subs_dict["\$acts\$"] = acts
            inner_text = self.__treat(read(tpl_name_path),subs_dict)
            if "parm" in action_data.keys() :
                subs_dict["\$parms_type_and_ranges\$"] = s
            comment = action_data["cmmt"]
            flag    = action_data["head"]
            h = Headers(rel_path,fct_name,inner=inner_text,comment=comment)
            # print "fct_name_path %s" % fct_name_path
            h.write_header2(fct_name_path,flag=flag,check=check)
         
    def dda(self,fct_name,acts,subs_dict,action_data,check=True) :
        """remove a file: reverse of add"""
        fname = action_data["file"].replace('$fct_name$',fct_name)
        fct_name_path = os.path.abspath(os.path.join(self.get_tb_abs_path(),acts,fname))
        os.remove(fct_name_path)  

    def mdy(self,fct_name,acts,subs_dict,action_data,check=True) :
        """modify a file, inserting a line"""
        fname = action_data["file"].replace('$root_name$',self.get_tb_name())
        file2modify = os.path.join(self.get_tb_abs_path(),acts,fname)
        
        text = read(file2modify)
        subs_dict["\$self.tb_pathfnt2\$"]=self.get_tb_pathfnt2()
        subs_dict["\$fct_name\$"]=fct_name
        line2add = self.__treat(action_data["l2ad"], subs_dict) 
        token = action_data["tokn"]
        test, text = self.__add_line(text, line2add, token)
        if test :
            self.logger.info(
                "\nmodifying \n%s\nfor definition of functor %s\n" % (file2modify,fct_name)
                )
            write(file2modify,text,False)
        else :
            self.logger.warning(
                "\nFile %s was already included\n" % fct_name +
                "in file\n%s\n" %  file2modify
                )

    def ydm(self,fct_name,acts,subs_dict,action_data,check=True) :
        """modify a file (reverse of mdy): deleting a line"""
        fname = action_data["file"].replace('$root_name$',self.get_tb_name())
        file2modify = os.path.join(self.get_tb_abs_path(),acts,fname)
        text = read(file2modify)
        subs_dict["\$self.tb_pathfnt2\$"]=self.get_tb_pathfnt2()
        subs_dict["\$fct_name\$"]=fct_name
        line2rmv = self.__treat(action_data["l2ad"], subs_dict) 
        test, text = self.__rmv_line(text, line2rmv)
        if test :
            self.logger.info(
                "\nmodifying \n%s\nfor definition of functor %s\n" % (file2modify,fct_name)
                )
            write(file2modify,text,False)
        else :
            self.logger.warning(
                "\nFile %s was not present in file\n%s\n" %  (fct_name,file2modify)
                )



                
    def hie(self,fct_name,acts,subs_dict,action_data,check=True) :
        """create an include hierarchy for simd"""
        fname = action_data["file"].replace('$fct_name$',fct_name)
        path = os.path.join(self.get_tb_abs_path(),acts) 
        hierarchy = action_data["hier"]
        cmmt = action_data["cmmt"]
        head = action_data["head"]
        relpath = os.path.join(self.get_tb_pathfnt2(),acts)
        relpathm1 = '/'.join(relpath.split('/')[:-1])
        for base, prev in hierarchy.Variants.items() :
            file = os.path.join(path,base,fct_name+'.hpp')
            inner_text = ["#include <" + os.path.join(relpathm1, prev,fct_name + '.hpp>')]
            rpath = os.path.join(relpath,base)
            h = Headers(rpath,fct_name, inner=inner_text)
            h.write_header2(file,flag='full',check=check)
             
    def eih(self,fct_name,acts,subs_dict,action_data,check=True) :
        """delete an include hierarchy for simd(reverse of hie)"""
        path = os.path.join(self.get_tb_abs_path(),acts) 
        hierarchy = action_data["hier"]
        for base, prev in hierarchy.Variants.items() :
            file = os.path.join(path,base,fct_name+'.hpp')
            os.remove(file)
            
    def __treat(self,s, subs_dict) :
        """__treat substitutes all $self.<id>$ chains in the
           string s with the value of the variable self.<id> if it
           exist else leaves it as is"""
        if type(s) is str :
            for k,v in subs_dict.items() :
                s = re.sub(k,str(v),s)
            return s        
        elif type(s) is list :
            self.tb_name = self.get_tb_name()
            l= [] 
            for ss in s :
                l.append(self.__treat(ss, subs_dict))
            del self.tb_name
            return l
        
    def __add_line(self,text, line2add, token) :
        pattern = re.compile(line2add)
        def find_index(p) :
            for i,l in enumerate(text) :
                if p.match(l) : return i+1
            return 0
        if find_index(pattern) :
          return (False,text)
        else :
            #### match for token
            pattern = re.compile(token)
            i = find_index(pattern)
            if i != 0 :
                text.insert(i,line2add)
            return (True,text)

    def __rmv_line(self,text, line2rmv) :
        if line2rmv in text :
            text.remove(line2rmv)
            return (True,text)
        else :
            return (False,text)

    def read_functor(self,fct_name,type) :
        fct_name_path = os.path.join(self.get_tb_abs_path(),'function',type,fct_name+'.hpp')
        r = read(fct_name_path)
        return r

    def write_functor(self,fct_name,type,s,check) :
        fct_name_path = os.path.join(self.get_tb_abs_path(),'function',type,fct_name+'.hpp')
        r = write(fct_name_path,s,check)
예제 #12
0
class Toolbox(Nt2,Tb_files) :
    Tb_tree = [
        "",
        "include",
        "src",   
        "doc",
        "doc/source",
        "unit",
        "unit/scalar",
        "unit/simd",
        "bench",
        "bench/scalar",
        "bench/simd",
        "function",
        "function/scalar",
        "function/simd",
        "function/simd/common",
        "function/simd/vmx", 
        "function/simd/vmx/common",
        "function/simd/vmx/altivec",
        "function/simd/vmx/spu",
        "function/simd/sse",
        "function/simd/sse/common",
        "function/simd/sse/sse2",
        "function/simd/sse/sse3",
        "function/simd/sse/ssse3",
        "function/simd/sse/sse4_1",
        "function/simd/sse/sse4_2",
        "function/simd/sse/avx",
        "function/simd/sse/sse4a",
        "function/simd/sse/xop",
        "function/simd/sse/fma4",
        ]
    Tb_files =                 {
        "" : {
            "py_data"      : "py_data.py", 
            "base"         : "$root_name$",  
            "root"         : "$root_name$",
            "root_include" : "include.hpp",
            },
        "bench" :            {
            "inner"        : "CMakeLists.txt"
            },
        "bench/scalar" : {
            "scalar"       : "CMakeLists.txt"
            },
        "bench/simd" :   {  
            "simd"         : "CMakeLists.txt",
            },
        "unit" :                 {
            "inner"        : "CMakeLists.txt"
            },
        "unit/scalar" :      {
            "scalar"       : "CMakeLists.txt"
            },
        "unit/simd" :        {  
            "simd"         : "CMakeLists.txt",
            },
         }
    def __init__(self, tool_box_name,
                 mode = 'create',
                 p2nt2 = None,
                 style = 'usr') :

        """creation or recovery of a toolbox
         <tool_box_name> is the name of the toolbox

         <mode> is the opening mode. Proper modes are create(default) or modify

             create : creates a new toolbox tree under .../nt2/toolbox/
                  with the given <tool_box_name> provided that a 
                  directory of this name not existed previously (default)
             update : add all missing directories or files to an existing
                      toolbox without modifying any existing files or
                      directories
             modify : creates a new toolbox tree or allow access to an
                  existing one to add or suppress functors extensions

          <p2nt2> is the path to nt2. The path defaults to the computation 
                  furnished by the Nt2 class
          <style> determines if the functors defined in the toolbox functors
                  will reside in the namespace nt2 ('sys') or in the namespace
                  <tool_box_name> ('usr'). It is only needed when mode is  
                  'create' and is 'usr' by default. The other modes recover
                  the creation parameter from existing data: in the present
                  implementation, once created the toolbox mode cannot be
                  modified.
        """

        Mode = [ 'create', 'update', 'check', 'modify']
        Style = ['usr','sys']
        Nt2.__init__(self,'toolbox')
        self.__status = True
        self.logger = Mylogging("nt2.toolbox.Toolbox")
        if p2nt2 is None : p2nt2 = self.get_path2nt2()
        self.__tb_name     = tool_box_name
        self.__tb_pathfnt2 = os.path.join(self.get_pathfnt2(),self.__tb_name)
        self.__tb          = os.path.join(self.get_path2nt2(),self.__tb_pathfnt2)
        self.__tb_path2mode= os.path.join(self.get_path2nt2(),self.get_pathfnt2())
        self.__tb_style = style if style == "sys" else "usr"
        if os.path.exists(self.get_tb_abs_path()) : self.read_style()    
        self.__test_status = True
        self.__mode = mode
        self.__tb_tree = Toolbox.Tb_tree
        self.__tb_files= Toolbox.Tb_files
        Tb_files.__init__(self,self.__tb_name,self.__tb_path2mode,
                          self.__tb_tree,
                          self.__tb_files,
                          style)
        if mode in Mode :
            self.logger.info(
                ("\nopening toolbox %s with mode: "% self.__tb_name) +
                mode+"\nin directory\n" +
                self.__tb
                )
            action = getattr(self,mode+'_tbox')
            action()
        else:
            self.logger.error(
                "\nopening with unknown mode: "+mode+"\n"+
                " raising SystemExit\n"
                )
            raise SystemExit

    def get_tb_name(self) : return self.__tb_name
    def get_tb_pathfnt2(self) : return self.__tb_pathfnt2
    def get_tb_abs_path(self) : return self.__tb 
    def get_tb_path2mode(self) : return self.__tb_path2mode
#    def get_status(self) : return self.__status
    def get_tb_style (self) : return self.__tb_style
    def get_tb_namespace(self) :
        return "functors" if (self.__tb_style == "sys") else self.__tb_name 
    def get_tb_mode(self) : return self.__mode
    def get_tb_status(self) : return self.__status
    def get_tb_tree(self) : return self.__tb_tree
    def get_tb_files(self) : return self.__tb_files
    def exist_tb(self) : return os.path.exists(self.get_tb_abs_path())
    def create_tbox(self):
        """ create a toolbox tree and global files only if it does not exist"""
        if os.path.exists(self.get_tb_abs_path()) :
            self.__status = False
            self.logger.error(
                "\ntoolbox %s already exists\n" % self.get_tb_name() +
                "in path: %s\n" % self.get_tb_abs_path() +
                "please use another toolbox name\n" +
                "or delete the old one using remove_tbox "
                "before creating the new one\n"
                )
            raise SystemExit
        else:
            self.create_tb_tree()
            self.create_tb_files()
        return self.__status

    def update_tbox(self):
        """ add missing directory and files to a toolbox
            without modifying any existing ones
        """
        self.read_style()    
        self.update_tb_tree()
        self.update_tb_files()
        return self.__status

    def check_tbox(self):
        """ check the toolbox integrity
        """
        self.__status = self.check_tb_tree() and self.check_tb_files()
        if self.__status : self.read_style()
        return self.__status
   
    def rm_tbox(self):
        """ remove a toolbox tree and global files"""
        if os.path.exists(self.get_tb_abs_path()) :
            path = self.get_tb_abs_path()
            os.remove( path+'.hpp')
            shutil.rmtree(path,True)
            
        
    def modify_tbox(self):
        if not os.path.exists(self.get_tb_abs_path()) :
            self.logger.warning(
                "\ntoolbox %s does not exists\n" % self.get_tb_name() +
                "in path: %s\n" % self.get_tb_abs_path() +
                "\nIt will be created using 'usr' style"
                )
            self.__tb_style = 'usr'
            self.create_tbox()
        self.read_style()    
        return self.__status
    
    def read_style(self) :
        dirname = self.get_tb_abs_path()
        filename = os.path.join(dirname,'py_data.py')
        if exist(filename) :
            sys.path.insert(0,dirname)
            from py_data import datas
            s = datas['style']
            sys.path.pop(0)
            self.__tb_style = s
            return s

        dirname = self.get_tb_path2mode()
        filename = os.path.join(dirname,self.get_tb_name()+'.hpp')
        if exist(filename) :
            s = read(filename)
            pattern = re.compile("^// This toolbox is of (.*) type")
            for l in s :
                d1 = re.match(pattern,l)
                if d1 :
                    self.__tb_style = d1.groups()
                    return d1
            
      
        self.logger.warning(
            "\nno file allowing to determine the style of " % self.get_tb_name() +
            "longer exists.\nAssuming an usr toolbox.\n" 
            )
        self.__tb_style = 'usr'
        return 'usr'
예제 #13
0
        return sub_list(pattern,rep,s)
        
    def write_Cmake_txt(self,s) :
        print "writing CMakeLists.txt"
        p = os.path.join(self.get_bench_path(),'CMakeLists.txt')
        write(p,s,False)
        #show(s)
        return s
    
 
    def remove_simd_dir(self):
        p = os.path.join(self.get_def_path(),'simd')
        print p


if __name__ == "__main__" :
    Mylogging.set_level('DEBUG')
    length = len(sys.argv)
    if length == 2 :
        old = Sup_simd(sys.argv[1])
##        old.remove_simd_dir()
##        old.modify_Cmake_benches_txt()
##        old.modify_functors_defs() 
    else :
        print __doc__

sys.path.pop(0)
           
       

예제 #14
0
    def get_tb_name(self):
        return self.__tb_name

    def get_list_cpps(self):
        return self.__list_cpps

    def get_unit_simd_path(self):
        return self.__unit_simd_path

    def ok(self, f):
        return os.path.getsize(f) < 1024

    def replace(self):
        for f in self.get_list_cpps():
            full_f = os.path.join(self.get_unit_simd_path(), f)
            if self.ok(full_f):
                s = Rep_units_simd.Simd_unit
                s = sub_list("\$name\$", f[:-4], s)
                s = sub_list("\$tb_name\$", self.get_tb_name(), s)
                show(s)
                write(full_f, s, False)


if __name__ == "__main__":
    Mylogging.set_level("CRITICAL")
    i = Rep_units_simd("predicates")
    #    show(i.get_list_cpps())
    i.replace()
sys.path.pop(0)
예제 #15
0
 def __init__(self, root_name, root_abs_path, rel_tree) :
     self.logger = Mylogging("nt2.tb_tree.Tb_tree")
     self.__root_name = root_name
     self.__mk_rel_tree(rel_tree)
     self.__root_abs_path = root_abs_path
예제 #16
0
class Tb_tree :
    """ creation and deletion of (empty) toolbox trees.
    <root_name>     is the name of the root directory
    <root_abs_path> is the path to the root directory
                    not including it
    <rel_tree>      is the list of path from the root (not
                    including it to be created or deleted)

    
    """
    def __init__(self, root_name, root_abs_path, rel_tree) :
        self.logger = Mylogging("nt2.tb_tree.Tb_tree")
        self.__root_name = root_name
        self.__mk_rel_tree(rel_tree)
        self.__root_abs_path = root_abs_path

    def __mk_rel_tree      (self,tree) :
        self.__rel_tree = []
        for l in  tree :
            self.__rel_tree.append(os.path.join( self.__root_name,l))
        self.__rel_tree.sort()    
    
    def get_root_name    (self) : return self.__root_name
    def get_rel_tree     (self) : return self.__rel_tree
    def get_root_abs_path(self) : return self.__root_abs_path
        
    def show_tb_tree(self) :
        for l in  self.get_abs_tree() :
           print l

    def get_abs_tree(self) :
        r = []
        for l in  self.get_rel_tree() :
           r.append(os.path.join(self.get_root_abs_path(),l))
        return r
           
    def create_tb_tree(self) :
        for l in  self.get_abs_tree() :
           if not exist(l) :
               self.logger.info("\ncreating : \n%s" % l)
               mkdir(l)
           else :
               self.logger.warning("\ndirectory : \n%s\nalready exists" % l)

    def update_tb_tree(self) :
        for l in  self.get_abs_tree() :
           if not exist(l) :
               self.logger.info("\ncreating : \n%s" % l)
               mkdir(l)

    def list_tb_tree(self) : return self.get_abs_tree()


    def check_tb_tree(self) :
        for l in  self.get_abs_tree() :
            r = exist(l)
            if not r :
                self.logger.info("\ndirectory %s\ndoes not exist\n" % l)
                return False
        return True       

    def remove_tb_tree(self) :
        r = self.get_abs_tree()
        r.reverse()
        for l in r :
            try :
                os.rmdir(l)
                self.logger.info("\ndirectory : \n%s\nhas been removed" % l)
            except (OsError) :
                self.logger.warning("\ndirectory : \n%s\nis not empty, so not removed" % l)

    def get_tb_tree_lack(self) :
        """return the list of non existing directories required for
        defined tree. Returns an empty list if the tree is full.
        """
        r = []
        for l in  self.get_abs_tree() :
            if not exist(l) :
                r.append(l)
        return r
예제 #17
0
        "function/simd/common",
        "function/simd/vmx", 
        "function/simd/vmx/common",
        "function/simd/vmx/altivec",
        "function/simd/vmx/spu",
        "function/simd/sse",
        "function/simd/sse/common",
        "function/simd/sse/sse2",
        "function/simd/sse/sse3",
        "function/simd/sse/ssse3",
        "function/simd/sse/sse4_1",
        "function/simd/sse/sse4_2",
        "function/simd/sse/avx",
        "function/simd/sse/sse4a",
        "function/simd/sse/xop",
        "function/simd/sse/fma4",
        ]
    from list_utils import show
    Mylogging.set_level('ALWAYS')
    name = "pipo"
    path = "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox"
    tb = Tb_tree(name,path,a_tree)
    print "get_root_name()      %s   "%tb.get_root_name()        
    print "get_rel_tree()       %s   "%tb.get_rel_tree()    
    print "get_root_abs_path()  %s   "%tb.get_root_abs_path()             
##    tb.show_tb_tree()
##    tb.create_tb_tree()
##    tb.remove_tb_tree()
##    show(tb.get_tree_lack())
    show(tb.get_rel_tree())
예제 #18
0
 def __init__(self, root_name, root_abs_path, rel_tree, files, style='usr') :
     self.logger = Mylogging("nt2.tb_files.Tb_files")
     self.__tb_style = style
     self.__tb_files = files
     self.__root_abs_path = root_abs_path
     Tb_tree.__init__(self,root_name, root_abs_path, rel_tree)
예제 #19
0
class Tb_files(Tb_tree) :
    """ creation and deletion of unique files in toolbox trees.
    <root_name>     is the name of the root directory
    <root_abs_path> is the path to the root directory
                    not including it
    <rel_tree>      is the list of path from the root (not
                    including it to be created or deleted)

    
    """
    def __init__(self, root_name, root_abs_path, rel_tree, files, style='usr') :
        self.logger = Mylogging("nt2.tb_files.Tb_files")
        self.__tb_style = style
        self.__tb_files = files
        self.__root_abs_path = root_abs_path
        Tb_tree.__init__(self,root_name, root_abs_path, rel_tree)

    def get_tb_files(self) : return self.__tb_files

    def __mk_tb_files(self,check=False) :
        """ calling this method suppose that create_tree
        was invoked earlier
        """
        n = self.get_root_name()+'/'
        for a,r in  zip(self.get_abs_tree(),self.get_rel_tree()) :
            if not exist(a) :
               self.logger.info("\ncreating : \n%s" % a)
               mkdir(a)
            key = string.replace(r,n,"",1)
            if key in self.get_tb_files() :
                for action_name, name in self.get_tb_files()[key].items() :
                    if name == "$root_name$" : name = self.get_root_name()
                    action = getattr(Tb_files,"mk_"+action_name,None)
                    if callable(action) : 
                        value = action(self,check,a,r,name,key)
                        if (check == "check_only") and not value : return False
#NO UPDATE#        if self.__tb_style == 'sys' : self.update_CMake(check)
        return True
    
    def create_tb_files(self) :
        self.__mk_tb_files(check=False)
      
    def update_tb_files(self) :
        self.__mk_tb_files(check=True)

    def check_tb_files(self) :
        return self.__mk_tb_files(check='check_only')

    def update_CMake(self,check) :
        lp = self.__root_abs_path.split('/')
        p = os.path.join('/'.join(lp[:-4]),'CMakeLists.txt')
        s= read(p)
        pattern = "ADD_SUBDIRECTORY\(\${PROJECT_BINARY_DIR}/include/nt2/toolbox/"+self.get_tb_name()+'\)'
        for l in s :
            m = re.match(pattern, l)
            if m : return
        s.append(string.replace(pattern,'\\',''))    
        write(p,s,False)

    def mk_root(self,check,a,r,name,key) :
        """the created file will contain the include list of functors
        immediately available from the toolbox.
        """
        fname = os.path.join(a,name+'.hpp')
        if check == 'check_only' :
            r = exist(fname)
            if not r : self.logger.info("\nroot file %s does not exist" % fname)
            return r
        self.logger.info(
            "\ncreating include template for %s\n" % self.get_root_name()
            )
        rp = os.path.join('nt2/toolbox/',r)
        h = Headers(rp,self.get_root_name())
        h.write_header2(fname,check=check)
        return True

    def mk_py_data(self,check,a,r,name,key) :
        """this file contains python infos for pursuing the toolbox
           completion with functors
        """
        fname = os.path.join(a,name)
        if check == 'check_only' :
            r = exist(fname)
            if not r : self.logger.info("\npy_data file %s does not exist" % fname)
            return r 
        self.logger.info(
            "\ncreating toolbox py datas for %s\n" % self.get_root_name()
            )
        inner_text = [
            "datas = {",
            "'style' : '%s'" % self.__tb_style,
            "}"
            ]
        rp = os.path.join('nt2/toolbox/',r)
        h = Headers(rp, self.get_root_name(),inner=inner_text, ext='.py')
        h.write_header2(fname,flag='inner',check=check)
        return True
        
    def mk_root_include(self,check,a,r,name,key) :
        """the created file  include.hpp contains the BASE_<tb>... MACROS
        under toolbox/<tb>.
        """
        fname = os.path.join(a,'include.hpp')
        if check == 'check_only' : 
            r = exist(fname)
            if not r : self.logger.info("\nroot include file %s does not exist" % fname)
            return r
        self.logger.info(
            "\ncreating toolbox include template for %s\n" % self.get_root_name()
            )
        inner_text = [
            "#include <nt2/sdk/details/preprocessor.hpp>",
            "",
            "#define NT2_$tb_nameupper$_BASE() nt2/toolbox/$tb_name$/function/scalar/",
            "#define NT2_$tb_nameupper$_RELATIVE() nt2/toolbox/$tb_name$/function/",
            "",
            "#if defined(NT2_SIMD_DETECTED)",
            "#define NT2_$tb_nameupper$_INCLUDE(F) NT2_SIMD_RELATIVE_INCLUDE(NT2_$tb_nameupper$_RELATIVE, F)",
            "#else",
            "#define NT2_$tb_nameupper$_INCLUDE(F) NT2_PP_INCLUDE(NT2_$tb_nameupper$_BASE, F)",
            "#endif",
            ""
            ]
        inn=[]
        for l in inner_text :
            z=re.sub('\$tb_nameupper\$',self.get_root_name().upper(),l)
            z=re.sub('\$tb_name\$',self.get_root_name(),z)
            inn.append(z)
        rp = os.path.join('nt2/toolbox/',r)
        h = Headers(rp,"include",inner=inn)
        h.write_header2(fname,check=check)

        # phase 2 creation of the CMakeLists global file

        fname = os.path.join(a,'CMakeLists.txt')
        inner_text = [
            "",
            "ADD_SUBDIRECTORY(bench)",
            "ADD_SUBDIRECTORY(unit)",
            "",
            "##############################################################################",
            "## TODO: Write command for building your own sources",
            "##############################################################################"
            ]
        rp = os.path.join('nt2/toolbox/',r)
        h = Headers(rp, "/%s/CMakelists"%key,inner=inner_text, ext='.txt',comment='##')
        h.write_header2(fname,flag='banner+inner',check=check)
        return True

    def mk_base(self,check,a,r,name,key) :
        """the created file is the main include file for the toolboxes users.
        """
        na = os.path.abspath(os.path.join(a,'..'))
        fname = os.path.join(na,name+'.hpp')
        if check == 'check_only' : 
            r = exist(fname)
            if not r : self.logger.info("\nbase file %s does not exist" % fname)
            return r
        self.logger.info(
            "\ncreating toolbox include template for %s\n" % self.get_root_name()
            )
        inner_text = [
            "",
            "// Please do not remove or modify the next line comment",
            "// This toolbox is of %s type" % self.__tb_style,
            "#include <nt2/nt2.hpp>",
            "#include <nt2/toolbox/" + self.get_root_name() + "/"+ \
             self.get_root_name() + ".hpp>",
            ""
            ]
        n = self.get_root_name()+'/'
        rp = 'nt2/toolbox/'
        h = Headers(rp,self.get_root_name(),inner=inner_text)
        h.write_header2(os.path.join(na,name+'.hpp'),check=check)
        return True
        
    def mk_inner(self,check,a,r,name,key) :
        """ creation de CMakeLists.txt dans nt2/<tb>/doc/<name>"""
        fname = os.path.join(a,name)
        if check == 'check_only' : 
            r = exist(fname)
            if not r : self.logger.info("\ninner file %s does not exist" % fname)
            return r
        self.logger.info(
            "\ncreating CMakeLists.txt for %s benches/unit tests\n" % self.get_root_name()
            )
        inner_text = [
            "",
            "################################################################################",
            "# Add global unit driver rules",
            "################################################################################",
            "ADD_CUSTOM_TARGET(%s.scalar.unit)" % self.get_root_name(),
            "ADD_CUSTOM_TARGET(%s.simd.unit)"% self.get_root_name(),
            "ADD_CUSTOM_TARGET(%s.unit)"% self.get_root_name(),
            "",
            "##****************************************************************************",
            "##*     Toolbox %s %s tests" % (self.get_root_name(),key),
            "##****************************************************************************",
            "",
            "ADD_SUBDIRECTORY(scalar)",
            "ADD_SUBDIRECTORY(simd)",
            "",
            "################################################################################",
            "# Add driver rule dependencies",
            "################################################################################",
            "ADD_DEPENDENCIES(%s.unit %s.scalar.unit)" % (self.get_root_name(),self.get_root_name()),  
            "ADD_DEPENDENCIES(%s.unit %s.simd.unit)"% (self.get_root_name(),self.get_root_name()),
            "ADD_DEPENDENCIES(unit %s.unit)"% self.get_root_name(),
            ]
        rp = os.path.join('nt2/toolbox/',r)
        h = Headers(rp,"/%s/CMakelists"%key, inner=inner_text, ext='.txt',comment='##')
        h.write_header2(fname,flag='banner+inner',check=check)
        return True

    def mk_scalar(self,check,a,r,name,key) :
        return self.__mk_s(check,a,r,name,key,"scalar")
        
    def mk_simd(self,check,a,r,name,key) :
        return self.__mk_s(check,a,r,name,key,"simd")
        
    def __mk_s(self,check,a,r,name,key,st) :
        """ creation de CMakeLists.txt dans nt2/<tb>/<unit/bench>/<name>"""
        fname = os.path.join(a,name)
        benchortest = key.split('/')[0] 
        if check == 'check_only' : 
            r = exist(fname)
            if not r : self.logger.info("\ns file %s does not exist" % fname)
            return r
        self.logger.info(
            "\ncreating CMakeLists.txt for %s benchmarks\n" % self.get_root_name()
            )
        inner_text = [
            "",
            "SET( SOURCES",
            "# List of %s test files for toolbox %s"% (st,self.get_root_name()),
            "   )",
            "",
            "##****************************************************************************",
            "# For each filename",
            "##****************************************************************************",
            "FOREACH( EXAMPLE ${SOURCES})",
            "  ##**************************************************************************",
            "  ## Build the executable filename from the example source filename",
            "  ##**************************************************************************",
            '  STRING(REGEX REPLACE ".cpp" ".%s.%s.%s" EXECUTABLE "${EXAMPLE}")'%(self.get_root_name(),st,benchortest),
            '  STRING(REGEX REPLACE ".cpp" "-%s.%s.%s" TEST "${EXAMPLE}")'%(self.get_root_name(),st,benchortest),
            "",
            "  ##**************************************************************************",
            "  ## Add as a target",
            "  ##**************************************************************************",
            "  ADD_EXECUTABLE(${EXECUTABLE} ${EXAMPLE})",
            "  TARGET_LINK_LIBRARIES(${EXECUTABLE} nt2)",
            "  SET_TARGET_PROPERTIES(${EXECUTABLE} PROPERTIES COMPILE_FLAGS ${NT2_CXX_SIMD_FLAGS})" if st=="simd" else "",         
            "  ADD_TEST(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE})" if benchortest == 'unit' else "",
            "ENDFOREACH()",
            ]
        rp = os.path.join('nt2/toolbox/',r)
        h = Headers(rp,"/%s/CMakelists"%key, inner=inner_text, ext='.txt',comment='##')
        h.write_header2(os.path.join(a,name),flag='banner+inner',check=check)
        return True