You've already forked FrameTour-RenderWorker
feat(gpu): 添加多显卡调度支持
- 新增 GPUDevice 数据类定义 GPU 设备信息 - 扩展 WorkerConfig 添加 gpu_devices 配置项 - 从环境变量 GPU_DEVICES 读取多显卡设备配置 - 实现 GPUScheduler 提供轮询调度功能 - 修改 FFmpeg 参数生成支持设备指定 - 添加线程本地存储管理当前 GPU 设备 - 更新任务执行器集成 GPU 设备分配 - 实现 GPU 设备自动检测和验证功能 - 添加相关日志记录和状态监控
This commit is contained in:
@@ -5,12 +5,15 @@ Worker 配置模型
|
||||
定义 Worker 运行时的配置参数。
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List, Optional
|
||||
|
||||
from constant import HW_ACCEL_NONE, HW_ACCEL_QSV, HW_ACCEL_CUDA, HW_ACCEL_TYPES
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# 默认支持的任务类型
|
||||
DEFAULT_CAPABILITIES = [
|
||||
@@ -59,6 +62,9 @@ class WorkerConfig:
|
||||
# 硬件加速配置
|
||||
hw_accel: str = HW_ACCEL_NONE # 硬件加速类型: none, qsv, cuda
|
||||
|
||||
# GPU 设备配置(多显卡调度)
|
||||
gpu_devices: List[int] = field(default_factory=list) # 空列表表示使用默认设备
|
||||
|
||||
# 素材缓存配置
|
||||
cache_enabled: bool = True # 是否启用素材缓存
|
||||
cache_dir: str = "" # 缓存目录,默认为 temp_dir/cache
|
||||
@@ -113,6 +119,16 @@ class WorkerConfig:
|
||||
if hw_accel not in HW_ACCEL_TYPES:
|
||||
hw_accel = HW_ACCEL_NONE
|
||||
|
||||
# GPU 设备列表(用于多显卡调度)
|
||||
gpu_devices_str = os.getenv('GPU_DEVICES', '')
|
||||
gpu_devices: List[int] = []
|
||||
if gpu_devices_str:
|
||||
try:
|
||||
gpu_devices = [int(d.strip()) for d in gpu_devices_str.split(',') if d.strip()]
|
||||
except ValueError:
|
||||
logger.warning(f"Invalid GPU_DEVICES value: {gpu_devices_str}, using auto-detect")
|
||||
gpu_devices = []
|
||||
|
||||
# 素材缓存配置
|
||||
cache_enabled = os.getenv('CACHE_ENABLED', 'true').lower() in ('true', '1', 'yes')
|
||||
cache_dir = os.getenv('CACHE_DIR', '') # 空字符串表示使用默认路径
|
||||
@@ -132,6 +148,7 @@ class WorkerConfig:
|
||||
download_timeout=download_timeout,
|
||||
upload_timeout=upload_timeout,
|
||||
hw_accel=hw_accel,
|
||||
gpu_devices=gpu_devices,
|
||||
cache_enabled=cache_enabled,
|
||||
cache_dir=cache_dir if cache_dir else os.path.join(temp_dir, 'cache'),
|
||||
cache_max_size_gb=cache_max_size_gb
|
||||
@@ -156,3 +173,11 @@ class WorkerConfig:
|
||||
def is_cuda(self) -> bool:
|
||||
"""是否使用 CUDA 硬件加速"""
|
||||
return self.hw_accel == HW_ACCEL_CUDA
|
||||
|
||||
def has_multi_gpu(self) -> bool:
|
||||
"""是否配置了多 GPU"""
|
||||
return len(self.gpu_devices) > 1
|
||||
|
||||
def get_gpu_devices(self) -> List[int]:
|
||||
"""获取 GPU 设备列表"""
|
||||
return self.gpu_devices.copy()
|
||||
|
||||
Reference in New Issue
Block a user