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 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 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 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 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_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
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