【caffe】internal_thread.cpp/internal_thread.hpp代码解析

本文详细解析了Caffe中线程管理的实现机制,包括线程的启动、停止及状态检查。通过实例展示了如何利用Boost库进行线程操作,并深入探讨了shared_ptr与boost::thread的结合使用。

thread_(线程)创建函数为:

thread_.reset(new boost::thread(&InternalThread::entry, this, device, mode, rand_seed, solver_count, root_solver));

thread_作为shared_ptr<boost::thread>对象,自然可以调用shared_ptr<boost::thread>类的成员函数reset。

但为什么可以调用boost::thread的成员函数joinable():thread_->joinable()

原因是shared_ptr<boost::thread>类对->运算符进行了重载,返回的是boost::thread的指针。

 

class InternalThread {
 public:
  // 构造函数和析构函数
  InternalThread() : thread_() {}
  virtual ~InternalThread();
 
  /**
   * Caffe's thread local state will be initialized using the current
   * thread values, e.g. device id, solver index etc. The random seed
   * is initialized using caffe_rng_rand.  
   *  caffe的线程局部状态将会使用当前线程值来进行初始化,当前的线程的值有设备id,solver的编号、随机数种子等
   */
  void StartInternalThread();
 
  /** Will not return until the internal thread has exited. */
  // 是否知道线程退出才返回
  void StopInternalThread();
  // 线程是否已经起来了
  bool is_started() const;
 
 protected:
  /* Implement this method in your subclass
      with the code you want your thread to run. */
  // 定义了一个虚函数,要求继承该类的必须要实现之
  virtual void InternalThreadEntry() {}
 
  /* Should be tested when running loops to exit when requested. */
  // 在当请求退出的时候应该调用该函数
  bool must_stop();
 
 private:
  void entry(int device, Caffe::Brew mode, int rand_seed, int solver_count,
      bool root_solver);
  // 内部的成员变量
  shared_ptr<boost::thread> thread_;
};
 
}  // namespace caffe

-------------------------------------------------------------------

namespace caffe {
// 析构函数,调用停止内部线程函数
InternalThread::~InternalThread() {
  StopInternalThread();
}
 
// 测试线程是否起来
bool InternalThread::is_started() const {
  return thread_ && thread_->joinable(); // 首先thread_指针不能为空,然后该线程是可等待的(joinable)
}
 
bool InternalThread::must_stop() {
  //  if interruption has been requested for the current thread, false otherwise. 见boost的doc
  return thread_ && thread_->interruption_requested();
}
 
// 初始化工作,然后
void InternalThread::StartInternalThread() {
  CHECK(!is_started()) << "Threads should persist and not be restarted.";
 
  int device = 0;
#ifndef CPU_ONLY
  CUDA_CHECK(cudaGetDevice(&device));
#endif
  Caffe::Brew mode = Caffe::mode();
  int rand_seed = caffe_rng_rand();
  int solver_count = Caffe::solver_count();
  bool root_solver = Caffe::root_solver();
 
  try {// 然后重新实例化一个thread对象给thread_指针,该线程的执行的是entry函数
    thread_.reset(new boost::thread(&InternalThread::entry, this, device, mode,
          rand_seed, solver_count, root_solver));
  } catch (std::exception& e) {
    LOG(FATAL) << "Thread exception: " << e.what();
  }
}
 
// 线程所要执行的函数
void InternalThread::entry(int device, Caffe::Brew mode, int rand_seed,
    int solver_count, bool root_solver) {
#ifndef CPU_ONLY
  CUDA_CHECK(cudaSetDevice(device));
#endif
  Caffe::set_mode(mode);
  Caffe::set_random_seed(rand_seed);
  Caffe::set_solver_count(solver_count);
  Caffe::set_root_solver(root_solver);
 
  InternalThreadEntry();
}
 
// 停止线程
void InternalThread::StopInternalThread() {
  if (is_started()) {// 如果线程已经开始
    thread_->interrupt();// 那么打断
    try {
      thread_->join();// 等待线程结束
    } catch (boost::thread_interrupted&) {//如果被打断,啥也不干,因为是自己要打断的^_^
    } catch (std::exception& e) {// 如果发生其他错误则记录到日志
      LOG(FATAL) << "Thread exception: " << e.what();
    }
  }
}
 
}  // namespace caffe

本文转自:https://blog.youkuaiyun.com/langb2014/article/details/51000007

PowerShell 7 环境已加载 (版本: 7.5.2) PS C:\Users\Administrator\Desktop> cd E:\PyTorch_Build\pytorch PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\activate (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 设置环境变量 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:CUDA_PATH = "E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0" (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:Path = "$env:CUDA_PATH\bin;$env:Path" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 配置构建参数 - 使用独立-G参数 (rtx5070_env) PS E:\PyTorch_Build\pytorch> mkdir build -Force Directory: E:\PyTorch_Build\pytorch Mode LastWriteTime Length Name ---- ------------- ------ ---- da--- 2025/9/3 18:43 build (rtx5070_env) PS E:\PyTorch_Build\pytorch> cd build (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> cmake .. -G "Ninja" ` >> -DBUILD_PYTHON=ON ` >> -DUSE_CUDA=ON ` >> -DUSE_CUDNN=ON ` >> -DCUDNN_INCLUDE_DIR="E:\Program Files\NVIDIA\CUNND\v9.12\include\13.0" ` >> -DCUDNN_LIBRARY="E:\Program Files\NVIDIA\CUNND\v9.12\lib\13.0\x64\cudnn64_9.lib" ` >> -DTORCH_CUDA_ARCH_LIST="8.9" ` >> -DCMAKE_BUILD_TYPE=Release -- Configuring done (0.1s) CMake Error at CMakeLists.txt:5 (add_library): Cannot find source file: libshm_windows.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc CMake Error at CMakeLists.txt:5 (add_library): No SOURCES given to target: shm_windows CMake Generate step failed. Build files cannot be regenerated correctly. (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> # 开始构建 (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> ninja install [0/1] Re-running CMake... FAILED: [code=1] build.ninja E:/PyTorch_Build/pytorch/build/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/protobuf/cmake/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/pthreadpool/cmake_install.cmake E:/PyTorch_Build/pytorch/build/FXdiv/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/cpuinfo/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/XNNPACK/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googlemock/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googletest/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/src/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ittapi/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/FP16/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/psimd/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/onnx/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/common/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/x64/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/interface/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/fake/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/dnnl/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/graph_compiler/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/utils/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/examples/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/tests/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/fmt/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/third_party/dynolog/dynolog/src/ipcfabric/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/mimalloc/cmake_install.cmake E:/PyTorch_Build/pytorch/build/torch/headeronly/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/test/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/benchmark/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/test/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/THC/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/quantized/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/nnapi/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/src/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/src/libm/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/src/common/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/test/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/core/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/serialize/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/utils/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/perfkernels/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_jit/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_nativert/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_inductor/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_api/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_lazy/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/lib/libshm_windows/cmake_install.cmake E:/PyTorch_Build/pytorch/build/functorch/cmake_install.cmake E:/PyTorch_Build/pytorch/build/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/protobuf/cmake/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/pthreadpool/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/FXdiv/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/cpuinfo/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/XNNPACK/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googlemock/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googletest/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/src/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ittapi/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/FP16/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/psimd/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/onnx/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/common/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/x64/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/interface/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/fake/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/dnnl/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/graph_compiler/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/utils/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/examples/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/tests/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/fmt/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/third_party/dynolog/dynolog/src/ipcfabric/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/mimalloc/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/torch/headeronly/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/test/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/benchmark/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/test/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/THC/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/quantized/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/nnapi/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/src/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/src/libm/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/src/common/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/test/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/core/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/serialize/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/utils/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/perfkernels/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_jit/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_nativert/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_inductor/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_api/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_lazy/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/lib/libshm_windows/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/functorch/CTestTestfile.cmake E:\PyTorch_Build\pytorch\rtx5070_env\Lib\site-packages\cmake\data\bin\cmake.exe --regenerate-during-build -SE:\PyTorch_Build\pytorch -BE:\PyTorch_Build\pytorch\build CreateProcess failed: The system cannot find the file specified. ninja: error: rebuilding 'build.ninja': subcommand failed (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> # 验证安装 (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> cd .. (rtx5070_env) PS E:\PyTorch_Build\pytorch> python -c "import torch; print(f'PyTorch版本: {torch.__version__}, CUDA可用: {torch.cuda.is_available()}')" Traceback (most recent call last): File "<string>", line 1, in <module> File "E:\PyTorch_Build\pytorch\torch\__init__.py", line 35, in <module> from typing_extensions import ParamSpec as _ParamSpec, TypeIs as _TypeIs ModuleNotFoundError: No module named 'typing_extensions' (rtx5070_env) PS E:\PyTorch_Build\pytorch> pip install typing_extensions pyyaml future Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting typing_extensions Downloading https://pypi.tuna.tsinghua.edu.cn/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl (44 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.6/44.6 kB 1.1 MB/s eta 0:00:00 Collecting pyyaml Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b5/84/0fa4b06f6d6c958d207620fc60005e241ecedceee58931bb20138e1e5776/PyYAML-6.0.2-cp310-cp310-win_amd64.whl (161 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 161.8/161.8 kB 4.9 MB/s eta 0:00:00 Collecting future Using cached https://pypi.tuna.tsinghua.edu.cn/packages/da/71/ae30dadffc90b9006d77af76b393cb9dfbfc9629f339fc1574a1c52e6806/future-1.0.0-py3-none-any.whl (491 kB) Installing collected packages: typing_extensions, pyyaml, future Successfully installed future-1.0.0 pyyaml-6.0.2 typing_extensions-4.15.0 [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 创建虚拟环境 (rtx5070_env) PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env Error: [Errno 13] Permission denied: 'E:\\PyTorch_Build\\pytorch\\rtx5070_env\\Scripts\\python.exe' (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\Activate.ps1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 安装构建依赖 (rtx5070_env) PS E:\PyTorch_Build\pytorch> pip install numpy ninja pybind11 typing_extensions pyyaml future Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: numpy in e:\pytorch_build\pytorch\rtx5070_env\lib\site-packages (2.2.6) Requirement already satisfied: ninja in e:\pytorch_build\pytorch\rtx5070_env\lib\site-packages (1.13.0) Requirement already satisfied: pybind11 in e:\pytorch_build\pytorch\rtx5070_env\lib\site-packages (3.0.1) Requirement already satisfied: typing_extensions in e:\pytorch_build\pytorch\rtx5070_env\lib\site-packages (4.15.0) Requirement already satisfied: pyyaml in e:\pytorch_build\pytorch\rtx5070_env\lib\site-packages (6.0.2) Requirement already satisfied: future in e:\pytorch_build\pytorch\rtx5070_env\lib\site-packages (1.0.0) [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # CUDA环境设置 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:CUDA_PATH = "E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0" (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:Path = "$env:CUDA_PATH\bin;$env:Path" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 配置构建 (rtx5070_env) PS E:\PyTorch_Build\pytorch> mkdir build -Force Directory: E:\PyTorch_Build\pytorch Mode LastWriteTime Length Name ---- ------------- ------ ---- da--- 2025/9/3 18:45 build (rtx5070_env) PS E:\PyTorch_Build\pytorch> cd build (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> cmake .. -G "Ninja" ` >> -DBUILD_PYTHON=ON ` >> -DUSE_CUDA=ON ` >> -DUSE_CUDNN=ON ` >> -DCUDNN_INCLUDE_DIR="E:\Program Files\NVIDIA\CUNND\v9.12\include\13.0" ` >> -DCUDNN_LIBRARY="E:\Program Files\NVIDIA\CUNND\v9.12\lib\13.0\x64\cudnn64_9.lib" ` >> -DTORCH_CUDA_ARCH_LIST="8.9" ` >> -DCMAKE_BUILD_TYPE=Release -- Configuring done (0.0s) CMake Error at CMakeLists.txt:5 (add_library): Cannot find source file: libshm_windows.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc CMake Error at CMakeLists.txt:5 (add_library): No SOURCES given to target: shm_windows CMake Generate step failed. Build files cannot be regenerated correctly. (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> # 并行构建 (使用8个线程) (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> ninja install -j 8 [0/1] Re-running CMake... FAILED: [code=1] build.ninja E:/PyTorch_Build/pytorch/build/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/protobuf/cmake/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/pthreadpool/cmake_install.cmake E:/PyTorch_Build/pytorch/build/FXdiv/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/cpuinfo/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/XNNPACK/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googlemock/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googletest/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/src/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ittapi/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/FP16/cmake_install.cmake E:/PyTorch_Build/pytorch/build/confu-deps/psimd/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/onnx/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/common/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/x64/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/interface/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/fake/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/dnnl/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/graph_compiler/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/utils/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/examples/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/tests/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/fmt/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/third_party/dynolog/dynolog/src/ipcfabric/cmake_install.cmake E:/PyTorch_Build/pytorch/build/third_party/mimalloc/cmake_install.cmake E:/PyTorch_Build/pytorch/build/torch/headeronly/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/test/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/benchmark/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/cmake_install.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/test/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/THC/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/quantized/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/nnapi/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/src/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/src/libm/cmake_install.cmake E:/PyTorch_Build/pytorch/build/sleef/src/common/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/test/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/core/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/serialize/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/utils/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/perfkernels/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_jit/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_nativert/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_inductor/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_api/cmake_install.cmake E:/PyTorch_Build/pytorch/build/test_lazy/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/cmake_install.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/lib/libshm_windows/cmake_install.cmake E:/PyTorch_Build/pytorch/build/functorch/cmake_install.cmake E:/PyTorch_Build/pytorch/build/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/protobuf/cmake/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/pthreadpool/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/FXdiv/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/cpuinfo/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/XNNPACK/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googlemock/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/googletest/googletest/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/benchmark/src/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ittapi/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/FP16/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/confu-deps/psimd/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/onnx/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/common/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/cpu/x64/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/interface/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/fake/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/dnnl/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/backend/graph_compiler/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/src/graph/utils/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/examples/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/ideep/mkl-dnn/tests/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/fmt/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/kineto/libkineto/third_party/dynolog/dynolog/src/ipcfabric/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/third_party/mimalloc/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/torch/headeronly/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/test/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/benchmark/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/c10/cuda/test/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/THC/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/quantized/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/nnapi/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/src/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/src/libm/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/sleef/src/common/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/aten/src/ATen/test/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/core/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/serialize/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/utils/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/perfkernels/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_jit/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_nativert/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_inductor/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_api/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/test_lazy/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/caffe2/torch/lib/libshm_windows/CTestTestfile.cmake E:/PyTorch_Build/pytorch/build/functorch/CTestTestfile.cmake E:\PyTorch_Build\pytorch\rtx5070_env\Lib\site-packages\cmake\data\bin\cmake.exe --regenerate-during-build -SE:\PyTorch_Build\pytorch -BE:\PyTorch_Build\pytorch\build CreateProcess failed: The system cannot find the file specified. ninja: error: rebuilding 'build.ninja': subcommand failed (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> # 安装Python包 (rtx5070_env) PS E:\PyTorch_Build\pytorch\build> cd .. (rtx5070_env) PS E:\PyTorch_Build\pytorch> python setup.py install Traceback (most recent call last): File "E:\PyTorch_Build\pytorch\setup.py", line 288, in <module> import setuptools.command.bdist_wheel ModuleNotFoundError: No module named 'setuptools.command.bdist_wheel' (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 验证安装 (rtx5070_env) PS E:\PyTorch_Build\pytorch> python -c "import torch; print(f'PyTorch {torch.__version__} built successfully! CUDA: {torch.cuda.is_available()}")" >> >> @' >> # 上述build_pytorch.ps1内容 >> '@ | Set-Content build_pytorch.ps1 -Encoding UTF8 >> >> # 启用脚本执行权限 >> Set-ExecutionPolicy Bypass -Scope Process -Force >> >> # 执行完整构建 >> .\build_pytorch.ps1 >>
最新发布
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值