def batch_process(self, resized_image_list, batch): resized_img_data_list = [] resized_img_size = resized_image_list[0].size total_size = batch * resized_img_size stride = 0 for resized_image in resized_image_list: resized_img_data_list.append(resized_image.data()) self.total_buffer, ret = acl.rt.malloc(total_size, ACL_MEM_MALLOC_HUGE_FIRST) check_ret("acl.rt.malloc", ret) for i in range(len(resized_image_list)): ret = acl.rt.memcpy(self.total_buffer + stride, resized_img_size,\ resized_img_data_list[i], resized_img_size,\ ACL_MEMCPY_DEVICE_TO_DEVICE) check_ret("acl.rt.memcpy", ret) stride += resized_img_size return total_size
def pip_install(module, requirements): print('<<<< pip_install module: {} requirements: {} '.format( module, requirements)) cmd = 'sh ./{}.sh {}'.format(module, requirements) print('cmd: {}'.format(cmd)) _ret = os.system(cmd) ret = check_ret(_ret) return ret
def co(self): # pro_path = self.build_path + '/' + self.version + '/' + self.sec_name + '/' + self.pros_name sec_dir = '/'.join((self.build_path, self.version, self.sec_name)) if not os.path.exists(sec_dir): os.system('mkdir -p {}'.format(sec_dir)) pro_path = '/'.join( (self.build_path, self.version, self.sec_name, self.pros_name)) self.pro_path = pro_path # 2020/9/4 如果已存在项目名,将之前的项目名打包 if os.path.exists(pro_path): new_pro_name = '' for i in range(100): new_pro_name = '_'.join((pro_path, str(i + 1))) if os.path.exists(new_pro_name): pass else: break os.system('mv {} {}'.format(pro_path, new_pro_name)) ret1 = os.system('svn co {} {} --username {} --password {}'.format( self.url, pro_path, self.username, self.password)) _ret1 = check_ret(ret1) if _ret1: print('<<<< SUCCESS svn co {}'.format(self.url)) # 2020/9/7 如果是web应用,需要checkout前端代码 if self.web_app: web_path = pro_path + '/' + 'webapp' if not os.path.exists(web_path): os.system('mkdir -p {}'.format(web_path)) ret2 = os.system( 'svn co {} . {} --username {} --password {}'.format( self.web_app_url, web_path, self.username, self.password)) _ret2 = check_ret(ret2) if ret2: print('<<<< SUCCESS svn co {}'.format(self.web_app_url)) else: print('<<<< FAIL svn co {}'.format(self.web_app_url)) return False return True else: print('<<<< FAIL svn co {}'.format(self.url)) return False
def init(self): """init""" print("[Sample] init resource stage:") ret = acl.init() check_ret("acl.rt.set_device", ret) ret = acl.rt.set_device(self.device_id) check_ret("acl.rt.set_device", ret) self.context, ret = acl.rt.create_context(self.device_id) check_ret("acl.rt.create_context", ret) self.stream, ret = acl.rt.create_stream() check_ret("acl.rt.create_stream", ret) self.run_mode, ret = acl.rt.get_run_mode() check_ret("acl.rt.get_run_mode", ret) print("Init resource success") return
def _init_resource(self): print("Init model resource") #load model file self.model_id, ret = acl.mdl.load_from_file(self.model_path) check_ret("acl.mdl.load_from_file", ret) self.model_desc = acl.mdl.create_desc() ret = acl.mdl.get_desc(self.model_desc, self.model_id) check_ret("acl.mdl.get_desc", ret) #get model output output_size = acl.mdl.get_num_outputs(self.model_desc) #create model output dataset self._gen_output_dataset(output_size) print("[Model] class Model init resource stage success") #get model output description self._get_output_desc(output_size) #create input buffer self._init_input_buffer() return SUCCESS
def _gen_output_dataset(self, size): print("[Model] create model output dataset:") dataset = acl.mdl.create_dataset() for i in range(size): # create output memory temp_buffer_size = acl.mdl.\ get_output_size_by_index(self.model_desc, i) temp_buffer, ret = acl.rt.malloc(temp_buffer_size, ACL_MEM_MALLOC_NORMAL_ONLY) check_ret("acl.rt.malloc", ret) #create output data buffer dataset_buffer = acl.create_data_buffer(temp_buffer, temp_buffer_size) #add data buffer to output dataset _, ret = acl.mdl.add_dataset_buffer(dataset, dataset_buffer) if ret: #free resource acl.rt.free(temp_buffer) acl.destroy_data_buffer(dataset) check_ret("acl.destroy_data_buffer", ret) self.output_dataset = dataset print("[Model] create model output dataset success") return
def check_vir_env(): with open('/root/.bashrc') as file: for line in file.readlines(): if 'WORKON_HOME' in line: vm_path = line.split('=')[-1].replace('\n', '').replace( '~', '/root', 1) return vm_path # 2020/9/9 如果没有这一行,就说明没安装虚拟环境,直接运行安装virtualen的脚本 _ret = os.system('sh ./install_virtualenv_tool.sh') ret = check_ret(_ret) if ret: return '/root/py_vm' else: return False
def install(self): _ret = os.system('sh {}'.format(os.path.join(os.path.dirname(self.service_filename), 'install.sh'))) ret = check_ret(_ret) return ret