当前位置: 首页 > news >正文

做商务网站服务软文广告素材

做商务网站服务,软文广告素材,企业网站建设 网络服务,怎么做网盘搜索引擎网站1. 多GPU并行处理设计 设计思路: 实现基于多GPU的并行任务处理#xff0c;每个GPU运行独立的任务#xff0c;以加速整体的处理速度。 实现机制: 进程隔离: 利用multiprocessing.Process为每个GPU创建独立的工作进程。 GPU资源限制: 通过设置CUDA_VISIBLE_DEVICES环境变量每个GPU运行独立的任务以加速整体的处理速度。 实现机制: 进程隔离: 利用multiprocessing.Process为每个GPU创建独立的工作进程。 GPU资源限制: 通过设置CUDA_VISIBLE_DEVICES环境变量确保每个进程仅能访问其对应的GPU。 任务互斥: 每个GPU拥有一个Lock对象确保同一时间只有一个任务在特定的GPU上运行。 2. 动态任务分配与负载均衡 设计思路: 通过动态分配任务至队列实现任务的均匀分布确保负载均衡。 实现机制: 任务队列: 使用Manager().Queue()创建共享队列允许多进程安全地存取任务。 设备ID计算: 通过calculate_device_id函数基于文件路径的哈希值和GPU总数计算出任务应分配至的GPU确保任务均匀分配。 3. 进程间通信与同步 设计思路: 确保多进程间的安全通信避免数据竞争和死锁。 实现机制: 任务获取原子性: 利用Lock对象保护任务获取操作确保任务获取的原子性。 进程同步: 使用task_queue.join()等待所有任务完成确保主进程不会在所有子任务完成前退出。 优雅退出: 通过向队列中放置None信号通知工作进程可以安全退出实现进程间的优雅终止。 4. 异常处理与资源管理 设计思路: 提供异常处理机制确保资源的有效管理。 实现机制: 异常捕获: 在worker函数中使用try-except结构捕获Empty异常处理队列为空的情况。 资源节约: 通过检查输出文件的存在性避免重复处理节省计算资源。 5. 性能优化与监控 设计思路: 优化任务处理流程提供执行状态的实时反馈。 实现机制: 进度监控: 利用tqdm.write在控制台输出任务执行信息提供直观的进度反馈。 效率提升: 通过合理的任务分配和进程设计最大化利用多GPU资源提升整体处理效率。 总结 该代码的关键设计聚焦于多GPU环境下的并行任务处理通过精细的进程管理、资源调度、负载均衡策略以及异常处理机制确保了系统的高效、稳定运行。同时通过进程间通信和同步机制以及性能优化措施进一步提升了系统的整体性能和用户体验。# 多gpu调度 # python multi_swap_10s_v2.py import os import subprocess from tqdm import tqdm import hashlib from multiprocessing import Process, Lock, Manager, Queue from queue import Empty # 用于检查队列是否为空# Locks for each GPU to ensure only one task runs at a time per GPU gpu_locks [Lock(), Lock()] # A shared queue for all tasks using Managers Queue task_queue Manager().Queue()def worker(gpu_id, lock):os.environ[CUDA_VISIBLE_DEVICES] str(gpu_id) # Set the CUDA_VISIBLE_DEVICES for this processwhile True:# Try to acquire the lock and get a task atomicallywith lock:try:cmd task_queue.get_nowait()except Empty:# No more tasks available, exit the workerbreak# Update the progress bar outside the lock to avoid contentiontqdm.write(fGPU {gpu_id} starting task: { .join(cmd)})# Run the subprocesssubprocess.run(cmd)# Worker finishes when it exits the loopdef calculate_device_id(vid_file, img_file):# Calculate a hash of the file paths to determine the device IDhash_object hashlib.md5(f{vid_file}{img_file}.encode())hex_dig hash_object.hexdigest()return int(hex_dig, 16) % len(gpu_locks)def main():source_videos_dir /home/nvidia/data/video/HDTF/10ssource_images_dir /home/nvidia/data/image/CelebA-HQ/300/0output_dir source_images_dirvideo_files_list [os.path.join(source_videos_dir, f)for f in os.listdir(source_videos_dir)if os.path.isfile(os.path.join(source_videos_dir, f)) and f.endswith(.mp4) and not any(char.isalpha() for char in f.split(.)[0])]image_files_list [os.path.join(source_images_dir, f)for f in os.listdir(source_images_dir)if os.path.isfile(os.path.join(source_images_dir, f)) and f.endswith(.jpg)]model_id c# Fill the task queuefor vid_file in video_files_list:for img_file in image_files_list:output_video f{os.path.splitext(os.path.basename(vid_file))[0]}_{os.path.splitext(os.path.basename(img_file))[0]}_{model_id}.mp4output_video_path os.path.join(output_dir, output_video)# Check if the output file already existsif not os.path.exists(output_video_path):device_id calculate_device_id(vid_file, img_file)cmd [python, multi_face_single_source.py,--retina_path, retinaface/RetinaFace-Res50.h5,--arcface_path, arcface_model/ArcFace-Res50.h5,--facedancer_path, model_zoo/FaceDancer_config_c_HQ.h5,--vid_path, vid_file,--swap_source, img_file,--output, output_video_path,--compare, False,--sample_rate, 1,--length, 1,--align_source, True,--device_id, str(device_id)]task_queue.put(cmd)# Create worker processes for each GPUworkers []for gpu_id in range(len(gpu_locks)): # Assuming you have 2 GPUsp Process(targetworker, args(gpu_id, gpu_locks[gpu_id]))p.start()workers.append(p)# Wait for all tasks to be processedtask_queue.join()# Signal workers to exit by adding None to the queue# Ensure enough exit signals for all workersfor _ in workers:task_queue.put(None)# Wait for all workers to finishfor p in workers:p.join()if __name__ __main__:main()在这个版本中我引入了一个calculate_device_id函数它基于视频文件和图像文件的路径计算出一个哈希值然后取模得到设备ID。这样可以确保任务更均匀地分配到不同的GPU上而不仅仅依赖于列表的索引。同时我添加了设置CUDA_VISIBLE_DEVICES的代码到worker函数中虽然这不是严格必需的但它强调了每个工作进程将只看到并使用分配给它的GPU。这有助于避免潜在的GPU资源冲突问题。
http://www.dnsts.com.cn/news/91294.html

相关文章:

  • 免费网站建设必择山东绘政科技淘客个人网站怎么建设
  • 电商网站开发发展和前景长沙市住房和城乡建设局网站
  • 计算机学习网站公司邮箱域名怎么起
  • 租房信息网站建设公众号怎么运营起来
  • 大良营销网站建设策划企业管理咨询自考
  • 做网站要怎么备案湖北省工程建设协会网站
  • iis7配置asp.net网站陕西省建设银行网站
  • 网站怎么做营销seo入门教学
  • 商贸公司的网站建设网站建设找导师蓝林
  • 驾校网站建设在58做网站推广有用没
  • 网站设计psd成全视频免费高清观看在线韩剧
  • 网站建设销售ppt石家庄城乡建设网站
  • 杭州专业网站设计制作公司鹤壁市城市建设投资有限公司网站
  • 步骤图厦门网站快照优化公司
  • 建网站的资料王者荣耀wordpress
  • 太原网站开发模板海南省建设网站
  • 宁波制作网站公司影视网站开发
  • 深圳网站制作公司售后织梦免费网站模块
  • 网站设计主色学校徐州智能模板建站
  • 河南建设银行网站深圳公司网站推广
  • 电商网站的特点三亚市城乡建设局网站
  • 鸿邑科技 网站建设网页的网站建设
  • 猪八戒 网站开发支付重庆网站建设的意义
  • 公司手机版网站制作设计网页的心得体会
  • 一般找素材都是做哪几个网站呢网站建设设计报告
  • 重庆专业做淘宝网站苏州工业园区公共资源交易中心
  • 便宜手机网站建设设计成功一个电子商务网站
  • 有没类似建设通的免费网站微信快速赚100块
  • 开封网站建设培训学校外贸业务员面试常见问题
  • 爱站seo查询软件内蒙古乌海建设局网站