You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IIS环境下Blender脚本无法调用GPU问题求助

在IIS服务器中调用GPU运行Blender脚本的问题

我们编写了用于生成STL文件的Blender Python脚本,该脚本在命令行运行时可正常使用GPU并生成正确文件。但将其集成到C#代码并部署到IIS服务器后,脚本无法调用GPU,偶尔会生成畸形对象。请问是否可在IIS服务器中调用GPU?

相关C#代码

using (var process = new Process())
{
    string command = string.Empty;
    command = @"--debug-all --background --python " + "\"" + scriptFilePath + "\"" + " " + "\"" + stlFilePath + "\"" + " "
        + "\"" + newStlFilePath + "\"" + " " + "\"" + fileName + "\"" + " "
        + rows + " " + columns + " " + numberofcoin + " \"" + coinDiameter + "\"" + " \"" + printerTypeId + "\"" + " \"" + objectType + "\"";

    process.StartInfo.FileName = blenderExePath;
    process.StartInfo.Arguments = $"{command}";
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;

    process.OutputDataReceived += (sender, data) => Console.WriteLine(data.Data);
    //process.OutputDataReceived += (Object _sender, DataReceivedEventArgs _args) => Process_OutputDataReceived(_sender, _args);
    //process.ErrorDataReceived += (sender, data) => Console.WriteLine(data.Data);
    process.ErrorDataReceived += (Object _sender, DataReceivedEventArgs _args) => Process_ErrorDataReceived(_sender, _args);

    //Console.WriteLine("starting");
    process.Start();
    process.BeginOutputReadLine();
    process.BeginErrorReadLine();
    process.WaitForExit(1000 * 5); // (optional) wait up to 5 seconds
}

可以在IIS中调用GPU,但需要解决几个关键限制:

  1. IIS应用池身份权限问题

    • 默认IIS应用池用的是ApplicationPoolIdentity或Network Service这类受限账户,没有访问GPU硬件的权限。需要把应用池的身份改成本地系统账户(Local System),或者给当前账户添加GPU访问权限(比如通过NVIDIA/AMD控制面板将账户加入GPU用户组)。
  2. Blender后台模式的GPU启用配置

    • Blender的--background模式默认不会主动启用GPU加速,尤其是无桌面会话的服务器环境。必须在Python脚本里强制指定GPU设备:
      import bpy
      # 根据GPU类型选择CUDA/OptiX/OPENCL
      bpy.context.preferences.addons["cycles"].preferences.compute_device_type = "CUDA"
      bpy.context.preferences.addons["cycles"].preferences.get_devices()
      # 启用所有可用GPU设备
      for device in bpy.context.preferences.addons["cycles"].preferences.devices:
          if device.type == "CUDA":
              device.use = True
      # 设置渲染/计算用GPU
      bpy.context.scene.cycles.device = "GPU"
      
    • 部分GPU驱动依赖桌面会话,若服务器是无桌面环境(如Server Core),需安装虚拟桌面组件(如保持RDP会话,或使用第三方虚拟显示驱动)。
  3. 进程等待时间不足

    • 你的C#代码里process.WaitForExit(1000 * 5)仅等待5秒,复杂模型的STL生成耗时可能远超这个时间,导致进程被强制终止,生成畸形文件。建议延长等待时间,或去掉超时参数让进程自然退出,同时记录进程退出码排查异常。
  4. GPU驱动与Blender版本兼容

    • 确保服务器GPU驱动是最新稳定版,且与使用的Blender版本匹配。旧驱动在服务器环境下可能无法被Blender正确识别。

验证步骤:

  • 先在服务器命令行手动运行Blender命令,确认能正常调用GPU生成STL,排除脚本和服务器GPU环境本身的问题。
  • 切换IIS应用池身份后,重启应用池再测试。
  • 查看Blender的错误输出(代码已重定向ErrorDataReceived),检查是否有"无法找到CUDA设备"等GPU相关报错。

内容的提问来源于stack exchange,提问作者Tarlok

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 10:57:20