Beispiel #1
0
    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'
Beispiel #2
0
 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
Beispiel #3
0
 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)
Beispiel #4
0
 def treat_variant(self,s,variant) :
     mode = "simd"
     tb_name = s[0]
     fct = Functor(tb_name,'modify','sys')
     for ss in s[1:] :
         ss = re.sub('\b',' ',ss)
         if len(ss) == 0 : continue
         l = ss.split()
         if len(l) == 0 : continue
         fct_name = l[0]
         arity = 1 if len(l) <=1 else int(l[1])
         path = "simd/sse/"+variant
         fct.add_functor(fct_name,arity)
         st = fct.read_functor(fct_name,path)
         src = os.path.join(Recover.Pname,path,fct_name+'.hpp')
         if exist(src) and (os.path.getsize(src) > 1536) :
             print "adding functor %s of arity %d in variant %s (size %s)" % (fct_name, arity, variant,os.path.getsize(src))
             sys.stdout.flush()
             #                print"orig-----------------"
             #show(st)
             d = read(src)
             #                print"src-----------------"
             #show(d)
             v = get_struct(d,"validate")
             c = get_struct(d,"call")
             i = self.get_includes(d,tb_name,mode,fct.get_path_to_nt2())
             st = self.insert_variants(st,v,c,i,
                                       fct.get_tb_style(),
                                       fct.get_tb_name(),
                                       fct_name,
                                       mode)
             #                print"avant-----------------"
             #show(st)
             #                print"apr-Aès-----------------"-b
             fct.write_functor(fct_name,path,st,False)
Beispiel #5
0
 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)
Beispiel #6
0
 def treat_one_tb(self,s,mode) :
     if mode == 'simd' :
         path = mode+'/common'
     else :
         path = mode
     tb_name = s[0]
     fct = Functor(tb_name,'modify','sys')
     for ss in s[1:] :
         ss = re.sub('\b',' ',ss)
         if len(ss) == 0 : continue
         l = ss.split()
         if len(l) == 0 : continue
         fct_name = l[0]
         arity = 1 if len(l) <=1 else int(l[1])
         fct.add_functor(fct_name,arity)
         st = fct.read_functor(fct_name,path)
         print "in toolbox %s adding functor %s of arity %d" % (tb_name,fct_name, arity) 
         sys.stdout.flush()
         src = os.path.join(Recover.Pname,path,fct_name+'.hpp')
         if exist(src) :
             d = read(src)
             v = get_struct(d,"validate")
             c = get_struct(d,"call")
             i = self.get_includes(d,tb_name,mode,fct.get_path_to_nt2())
             st = self.insert_validate_and_call(st,v,c,i,
                                                fct.get_tb_style(),
                                                fct.get_tb_name(),
                                                fct_name,
                                                mode)
             #            show(st)
             fct.write_functor(fct_name,path,st,False)
Beispiel #7
0
 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       
Beispiel #8
0
 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
Beispiel #9
0
 def get_functor_list(self) :
     l = []
     print self.get_new_bench_path()
     for name in os.listdir(self.get_new_scal_path()) :
         if name[-4:]=='.cpp' :
             h = name[:-4]
             if exist(os.path.join(self.get_old_bench_path(),'time_'+name)) :
                 l.append(h)
     return l
Beispiel #10
0
 def get_replacmt(self,target) :
     for d in self.get_list_dirs() :
         for h in self.get_list_hpps() :
             f = os.path.join(d,h)
             if exist(f) :
                 s = read(f)
                 st ='\n'.join(s)
                 if re.search(target,st) :
                    s=sub_list(target, Insert.Replacement[target],s)
                    write(f,s,False)
                    print "%s -> %s"%(target,Insert.Replacement[target])
Beispiel #11
0
 def get_fctors_dict(self) :
     l = {}
     p0 = self.get_path()
     for name in os.listdir(p0) :
         if name[-4:]=='.hpp' :
             h = name[:-4]
             p = os.path.join(p0,h+'/py_data.py')
             if exist(p) :
                 s = ' '.join(read(p))
                 l[h] ='usr' if s.find('usr') > 0 else 'sys' 
     return l
Beispiel #12
0
 def get_matches(self,target) :
     for d in self.get_list_dirs() :
         for h in self.get_list_hpps() :
             f = os.path.join(d,h)
             if exist(f) :
                 s = read(f)
                 st ='\n'.join(s)
                 if re.search(target,st) :
                    rep = Insert.Insertions[target]
                    if not re.search(rep,st) :
                        s.insert(10,rep)
                        write(f,s,False)
                        print "%s -> %s"%(target,h)
Beispiel #13
0
def get_arity(pname) :
    if exist(pname) :
        s = read(pname)
        r = []
        for l in s :
            m = re.search('  NT2_FUNCTION_IMPLEMENTATION',l)
            if m :
                #            print "l = %s " % l
                m = re.search('([0-9]+)\)',l)
                if m :
                    #                print " arity %s "% m.groups()[0]
                    return m.groups()[0]
    return ""
Beispiel #14
0
    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
Beispiel #15
0
 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
Beispiel #16
0
def create_impl_dirs(dirs=None) :
    if dirs is None :
        dirs = [
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/elliptic/function/scalar/impl/horner",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/trigonometric/function/scalar/impl/trigo",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/elliptic/function/simd/impl/horner",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/trigonometric/function/scalar/impl/invtrig",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/exponential/function/scalar/impl/expo",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/exponential/function/simd/impl/logs",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/exponential/function/simd/impl/expo",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/exponential/function/simd/impl/horner",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/trigonometric/function/simd/impl/invtrig",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/exponential/function/scalar/impl/logs",
            "/home/jt/DevC++/dev_lasmea/github/nt2/include/nt2/toolbox/trigonometric/function/simd/impl/trigo",
            ]
        for d in dirs :
            if not exist(d) :
                os.makedirs(d)
Beispiel #17
0
    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
Beispiel #18
0
 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
Beispiel #19
0
 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
Beispiel #20
0
 def get_arity_and_tplness(self,pname) :
     if exist(pname) :
         s = read(pname)
         r = []
         for l in s :
             m = re.search('  NT2_FUNCTION_IMPLEMENTATION',l)
             if m :
                 #            print "l = %s " % l
                 m = re.search('([0-9]+)\)',l)
                 if m :
                     #                print " arity %s "% m.groups()[0]
                     return (int(m.groups()[0]),False)
             else :
                 m = re.search('  inline NT2_FUNCTION_RETURN_TYPE',l)
                 if m :
                     #            print "l = %s " % l
                     m = re.search('([0-9]+)\)',l)
                     if m :
                         #                print " arity %s "% m.groups()[0]
                         return (int(m.groups()[0]),True)
                 
     return ""
Beispiel #21
0
 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
Beispiel #22
0
 def get_all_toolboxes(self) :
     p = self.absolute_path_to_mode()
     return [ f for f in os.listdir(p) if exist(os.path.join(p,f+'.hpp'))]
Beispiel #23
0
 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)