{"id":523,"date":"2026-07-08T03:06:52","date_gmt":"2026-07-07T19:06:52","guid":{"rendered":"https:\/\/tech-renaissance.cn\/blog\/?p=523"},"modified":"2026-07-08T21:53:17","modified_gmt":"2026-07-08T13:53:17","slug":"%e5%a4%9a%e6%b5%81%e5%b9%b6%e5%8f%91%e6%9e%b6%e6%9e%84%ef%bc%9a%e8%ae%a1%e7%ae%97%e6%b5%81%e3%80%81%e4%bc%a0%e8%be%93%e6%b5%81%e3%80%81%e6%9b%b4%e6%96%b0%e6%b5%81%e7%9a%84%e5%8d%8f%e5%90%8c","status":"publish","type":"post","link":"https:\/\/tech-renaissance.cn\/blog\/index.php\/2026\/07\/08\/523\/","title":{"rendered":"(17) \u591a\u6d41\u5e76\u53d1\u67b6\u6784\uff1a\u8ba1\u7b97\u6d41\u3001\u4f20\u8f93\u6d41\u3001\u66f4\u65b0\u6d41\u7684\u534f\u540c"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u2014\u2014\u201c\u4e00\u4e2a\u4eba\u7528AI\u5982\u4f55\u5199\u51fa\u6bd4PyTorch\u66f4\u5feb\u7684\u81ea\u7814\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u201d\u7cfb\u5217\u6587\u7ae0\u4e4b\u5341\u4e03<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6df1\u5ea6\u5b66\u4e60\u8bad\u7ec3\u91cc\uff0cGPU \u5e76\u4e0d\u662f\u6c38\u8fdc&#8221;\u6ee1\u8d1f\u8377\u8fd0\u8f6c&#8221;\u7684\u3002\u5f88\u591a\u65f6\u5019\uff0c\u5b83\u4f1a\u5728\u7b49\u6570\u636e\u3001\u7b49\u68af\u5ea6\u3001\u7b49\u4f18\u5316\u5668\u66f4\u65b0\uff0c\u6216\u8005\u5728\u7b49 CPU \u53d1\u51fa\u4e0b\u4e00\u6761\u6307\u4ee4\u3002\u4e00\u4e2a\u6846\u67b6\u80fd\u628a\u8fd9\u4e9b\u7a7a\u9699\u586b\u5f97\u591a\u6ee1\uff0c\u5f80\u5f80\u51b3\u5b9a\u4e86\u5b83\u7684\u5b9e\u6d4b\u541e\u5410\u80fd\u8d70\u591a\u8fdc\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u51e0\u7bc7\u6211\u4eec\u8bb2\u4e86\u9759\u6001\u56fe\u7f16\u8bd1\u3001MemoryPlan \u663e\u5b58\u5206\u533a\u548c DTensor \u5206\u5e03\u5f0f\u5f20\u91cf\u62bd\u8c61\u2014\u2014\u8fd9\u4e9b\u8bbe\u8ba1\u89e3\u51b3\u4e86&#8221;\u7b97\u4ec0\u4e48&#8221;\u548c&#8221;\u6570\u636e\u653e\u5728\u54ea&#8221;\u7684\u95ee\u9898\u3002\u4e00\u65e6\u8fdb\u5165 GPU \u6267\u884c\u9636\u6bb5\uff0c&#8221;\u600e\u4e48\u7b97\u5f97\u5feb&#8221;\u5c31\u53d6\u51b3\u4e8e\u8fd0\u884c\u65f6\u80fd\u4e0d\u80fd\u628a\u72ec\u7acb\u7684\u5de5\u4f5c\u5e76\u884c\u8d77\u6765\u3002CUDA Graph \u53ef\u4ee5\u628a\u8bad\u7ec3\u5faa\u73af\u6355\u83b7\u6210\u4e00\u6b21 GPU \u63d0\u4ea4\uff0c\u4ece\u800c\u6d88\u9664 CPU \u6d3e\u53d1 kernel \u7684\u5f00\u9500\uff1b\u4f46 Graph \u6355\u83b7\u7684\u662f&#8221;\u56fe&#8221;\uff0c\u56fe\u5185\u90e8\u7684\u5e76\u53d1\u7a7a\u95f4\u5230\u5e95\u6709\u591a\u5927\uff0c\u53d6\u51b3\u4e8e\u4f60\u4e8b\u5148\u6709\u6ca1\u6709\u628a\u72ec\u7acb\u7684\u5de5\u4f5c\u62c6\u5230\u72ec\u7acb\u7684 CUDA Stream \u4e0a\u3002\u5982\u679c\u6240\u6709\u7b97\u5b50\u90fd\u6324\u5728\u540c\u4e00\u6761\u6d41\u91cc\uff0c\u54ea\u6015 captured \u6210 Graph\uff0cGPU \u8c03\u5ea6\u5668\u770b\u5230\u7684\u4e5f\u53ea\u662f\u4e00\u6761\u4e32\u884c\u961f\u5217\uff0c\u5f88\u591a\u672c\u53ef\u4ee5\u5e76\u884c\u7684\u673a\u4f1a\u4f1a\u88ab\u767d\u767d\u6d6a\u8d39\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u7bc7\u6587\u7ae0\u5c31\u6765\u804a\u804a Tech-Renaissance \u7684\u8fd0\u884c\u65f6\u591a\u6d41\u5e76\u53d1\u67b6\u6784\uff1a\u4e09\u6761\u8ba1\u7b97\u6d41\u3001\u4e00\u6761\u4f20\u8f93\u6d41\u3001\u4e00\u6761\u66f4\u65b0\u6d41\uff0c\u5b83\u4eec\u5404\u81ea\u8d1f\u8d23\u4ec0\u4e48\u3001\u600e\u4e48\u901a\u8fc7 CUDA Event \u7cbe\u786e\u540c\u6b65\uff0c\u4ee5\u53ca\u8fd9\u79cd\u8bbe\u8ba1\u4e0e A\/B \u53cc\u7f13\u51b2\u3001CUDA Graph \u6355\u83b7\u662f\u5982\u4f55\u914d\u5408\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001CUDA Stream \u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u9700\u8981\u591a\u6d41\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">CUDA Stream \u662f NVIDIA GPU \u4e0a\u4efb\u52a1\u63d0\u4ea4\u7684&#8221;\u961f\u5217&#8221;\u3002\u540c\u4e00\u6761 stream \u5185\u90e8\u7684 kernel\u3001memcpy\u3001event \u6309\u63d0\u4ea4\u987a\u5e8f\u4e32\u884c\u6267\u884c\uff1b\u4e0d\u540c stream \u4e4b\u95f4\u7684\u64cd\u4f5c\uff0c\u53ea\u8981\u786c\u4ef6\u8d44\u6e90\u5141\u8bb8\uff0c\u5c31\u53ef\u4ee5\u5e76\u53d1\u6267\u884c\u3002\u8fd9\u4e2a\u62bd\u8c61\u770b\u4f3c\u7b80\u5355\uff0c\u5374\u89e3\u51b3\u4e86\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u91cc\u4e24\u4e2a\u6700\u5e38\u89c1\u7684\u5e76\u884c\u9700\u6c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e00\uff0c\u8ba1\u7b97\u4e0e\u6570\u636e\u4f20\u8f93\u91cd\u53e0\u3002<\/strong> \u8bad\u7ec3\u6bcf\u4e00\u6b65\u90fd\u9700\u8981\u628a\u4e0b\u4e00\u4e2a batch \u4ece CPU \u9501\u9875\u5185\u5b58\u642c\u5230 GPU\u3002\u5982\u679c\u7528\u9ed8\u8ba4\u7684\u540c\u6b65\u62f7\u8d1d\uff0cGPU \u4f1a\u5728\u62f7\u8d1d\u671f\u95f4\u7a7a\u7b49\uff1b\u5982\u679c\u628a H2D \u5f02\u6b65\u62f7\u8d1d\u653e\u5230\u72ec\u7acb stream \u4e0a\uff0cGPU \u8ba1\u7b97\u5f53\u524d batch \u7684\u540c\u65f6\uff0c\u62f7\u8d1d\u5f15\u64ce\u5df2\u7ecf\u5728\u51c6\u5907\u4e0b\u4e00\u4e2a batch\u3002\u8fd9\u6b63\u662f\u6211\u4eec\u5e38\u8bf4\u7684&#8221;\u8ba9 GPU \u4e0d\u518d\u6328\u997f&#8221;\uff0c\u4e5f\u662f PyTorch <code>DataLoader<\/code> \u91cc <code>pin_memory=True<\/code> \u548c <code>non_blocking=True<\/code> \u642d\u914d\u4f7f\u7528\u7684\u5e95\u5c42\u539f\u7406\u4e4b\u4e00\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e8c\uff0c\u72ec\u7acb\u8ba1\u7b97\u4efb\u52a1\u4e4b\u95f4\u7684\u5e76\u53d1\u3002<\/strong> \u53cd\u5411\u4f20\u64ad\u91cc\uff0c\u5168\u8fde\u63a5\u5c42\u7684 dW\u3001dB\u3001dX \u5728\u6570\u5b66\u4e0a\u662f\u76f8\u5bf9\u72ec\u7acb\u7684\uff1b\u628a\u5b83\u4eec\u6620\u5c04\u5230\u4e0d\u540c stream\uff0cGPU \u8c03\u5ea6\u5668\u5c31\u6709\u673a\u4f1a\u628a\u591a\u4e2a kernel \u540c\u65f6\u6302\u5230 SM \u4e0a\uff0c\u63d0\u5347\u6574\u4f53\u5229\u7528\u7387\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\uff0c\u591a\u6d41\u4e5f\u662f\u4e00\u628a\u53cc\u5203\u5251\u3002\u9ed8\u8ba4\u7684 legacy CUDA \u9ed8\u8ba4\u6d41\uff08stream 0\uff09\u6709\u9690\u5f0f\u540c\u6b65\u8bed\u4e49\uff1a\u4efb\u4f55\u843d\u5230\u9ed8\u8ba4\u6d41\u4e0a\u7684\u64cd\u4f5c\uff0c\u4f1a\u548c\u5176\u4ed6\u6240\u6709\u6d41\u4ea7\u751f\u5168\u5c40\u5e8f\u5217\u5316\u3002\u5f88\u591a\u5f00\u53d1\u8005\u5174\u51b2\u51b2\u5730\u52a0\u4e86\u591a\u6d41\uff0c\u5374\u53d1\u73b0\u6ca1\u6548\u679c\uff0c\u539f\u56e0\u5f80\u5f80\u5c31\u662f\u67d0\u4e2a\u5e93\u8c03\u7528\u6216\u67d0\u6b21 <code>cudaMemcpy<\/code> \u4e0d\u7ecf\u610f\u843d\u56de\u4e86\u9ed8\u8ba4\u6d41\uff0c\u628a\u6240\u6709\u5e76\u53d1&#8221;\u4e00\u5200\u5207&#8221;\u5730\u5835\u6b7b\u3002\u53e6\u4e00\u4e2a\u5e38\u89c1\u9677\u9631\u662f\u4f9d\u8d56\u7ba1\u7406\uff1a\u5982\u679c A stream \u7684\u4ea7\u51fa\u8981\u5582\u7ed9 B stream\uff0c\u5fc5\u987b\u7528 <code>cudaEventRecord<\/code> + <code>cudaStreamWaitEvent<\/code> \u663e\u5f0f\u8868\u8fbe\u4f9d\u8d56\uff0c\u5426\u5219\u5c31\u4f1a\u51fa\u73b0\u6570\u636e\u7ade\u4e89\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e3b\u6d41\u6846\u67b6\u91cc\uff0cPyTorch Eager \u9ed8\u8ba4\u628a\u6240\u6709\u64cd\u4f5c\u53d1\u5230\u5f53\u524d\u8bbe\u5907\u7684\u9ed8\u8ba4\u6d41\u3002\u7528\u6237\u5f53\u7136\u53ef\u4ee5\u624b\u52a8\u521b\u5efa <code>torch.cuda.Stream()<\/code>\uff0c\u7528 <code>with torch.cuda.stream(...)<\/code> \u4e0a\u4e0b\u6587\u5207\u6362\u6d41\uff0c\u751a\u81f3\u81ea\u5df1\u63d2\u5165\u4e8b\u4ef6\u540c\u6b65\uff0c\u4f46\u9700\u8981\u5904\u7406\u9501\u9875\u5185\u5b58\u3001\u7b97\u5b50\u72b6\u6001\u3001\u5f20\u91cf\u751f\u547d\u5468\u671f\u7b49\u5927\u91cf\u7ec6\u8282\u3002TensorFlow \u5728 XLA \u7f16\u8bd1\u6a21\u5f0f\u4e0b\uff0c\u501f\u52a9 HLO \u8c03\u5ea6\u5668\u53ef\u4ee5\u81ea\u52a8\u5c06\u65e0\u4f9d\u8d56\u7684\u5b50\u56fe\u5206\u914d\u5230\u4e0d\u540c\u6d41\u4e0a\u6267\u884c\uff0c\u4f46\u8fd9\u4e00\u80fd\u529b\u4f9d\u8d56\u4e8e\u9759\u6001\u5206\u6790\u548c\u7f16\u8bd1\uff0c\u5e76\u975e\u6240\u6709\u573a\u666f\u90fd\u80fd\u6709\u6548\u89e6\u53d1\u3002JAX \u540c\u6837\u901a\u8fc7 XLA \u83b7\u5f97\u7c7b\u4f3c\u7684\u81ea\u52a8\u6d41\u8c03\u5ea6\u80fd\u529b\u3002\u5bf9\u4e8e\u8ffd\u6c42\u6781\u81f4\u541e\u5410\u4e14\u9700\u8981\u663e\u5f0f\u63a7\u5236\u8bad\u7ec3\u5faa\u73af\u7684\u751f\u4ea7\u6846\u67b6\u800c\u8a00\uff0c&#8221;\u8ba9\u7528\u6237\u81ea\u5df1\u7ba1\u6d41&#8221;\u663e\u7136\u4e0d\u591f\uff1b\u5fc5\u987b\u5728\u6846\u67b6\u5185\u90e8\u628a\u6d41\u7684\u5212\u5206\u3001\u6620\u5c04\u3001\u540c\u6b65\u5168\u90e8\u9759\u6001\u5316\u3001\u81ea\u52a8\u5316\uff0c\u5e76\u4e14\u548c\u9759\u6001\u56fe\u3001CUDA Graph \u6355\u83b7\u5929\u7136\u5951\u5408\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Tech-Renaissance \u7684\u4e94\u6d41\u8bbe\u8ba1<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tech-Renaissance \u5728 <code>include\/renaissance\/core\/types.h<\/code> \u91cc\u5b9a\u4e49\u4e86\u4e94\u4e2a\u7269\u7406\u975e\u963b\u585e\u6d41\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ 5\u4e2a\u7269\u7406\u975e\u963b\u585e\u6d41\uff08STREAM_COMP\u4e3a\u903b\u8f91\u522b\u540d\uff0c\u6307\u5411COMP_1\uff09\nenum class StreamKind : uint8_t { TRANS, COMP_1, COMP_2, COMP_3, UPDATE };<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DeviceContext<\/code> \u4e3a\u6bcf\u4e2a <code>StreamKind<\/code> \u7ef4\u62a4\u72ec\u7acb\u7684 <code>cudaStream_t<\/code>\uff0c\u5e76\u5728 <code>src\/backend\/device_context.cpp<\/code> \u6784\u9020\u65f6\u7edf\u4e00\u521b\u5efa\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for (int i = 0; i &lt; 5; ++i) {\n    err = cudaStreamCreateWithFlags(\n        reinterpret_cast&lt;cudaStream_t*>(&amp;streams_[i]),\n        cudaStreamNonBlocking);\n    \/\/ ... \u9519\u8bef\u5904\u7406 ...\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u975e\u963b\u585e\u6807\u5fd7\u5f88\u91cd\u8981\uff1a\u5b83\u610f\u5473\u7740\u8fd9\u4e9b\u6d41\u4e0d\u4f1a\u548c\u9ed8\u8ba4\u6d41\u4ea7\u751f\u9690\u5f0f\u540c\u6b65\uff0c\u6846\u67b6\u5bf9\u6d41\u62e5\u6709\u5b8c\u5168\u63a7\u5236\u6743\u3002\u5982\u679c\u6f0f\u6389\u8fd9\u4e2a\u6807\u5fd7\uff0c\u5373\u4f7f\u4ee3\u7801\u91cc\u6307\u5b9a\u4e86\u4e0d\u540c\u7684 stream\uff0c\u9ed8\u8ba4\u6d41\u4e0a\u7684\u4e00\u6b21\u540c\u6b65\u62f7\u8d1d\u4ecd\u7136\u4f1a\u8ba9\u6240\u6709\u6d41\u505c\u4e0b\u6765\uff0c\u524d\u9762\u7684\u7cbe\u5fc3\u8bbe\u8ba1\u5c06\u524d\u529f\u5c3d\u5f03\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e94\u6761\u6d41\u7684\u5206\u5de5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>TRANS<\/strong>\uff1a\u4e13\u95e8\u8d1f\u8d23 Host-to-Device \u7684\u6570\u636e\u642c\u8fd0\u3002<code>TRANSFER_A<\/code> \u548c <code>TRANSFER_B<\/code> \u4e24\u5f20\u5b50\u56fe\u8dd1\u5728\u8fd9\u6761\u6d41\u4e0a\uff0c\u914d\u5408 A\/B \u53cc\u7f13\u51b2\u628a CPU \u9884\u5904\u7406\u597d\u7684\u4e0b\u4e00\u4e2a batch \u5f02\u6b65\u62f7\u5165 GPU\u3002<\/li>\n\n\n\n<li><strong>COMP_1<\/strong>\uff1a\u4e3b\u5e72\u8ba1\u7b97\u6d41\u3002\u524d\u5411\u7684\u5377\u79ef\u3001\u5168\u8fde\u63a5\u3001SoftmaxCE\uff0c\u4ee5\u53ca\u9996\u5c42\u524d\u5411\/\u53cd\u5411\u7b49\u8f83\u91cd\u7684 GEMM \u7c7b\u5de5\u4f5c\uff0c\u901a\u5e38\u6620\u5c04\u5230\u8fd9\u91cc\u3002<\/li>\n\n\n\n<li><strong>COMP_2<\/strong>\uff1a\u5f52\u7ea6\u4e0e\u6c60\u5316\u6d41\u3002GAP\u3001MaxPool\/AvgPool\u3001BatchNorm \u524d\u540e\u5411\u3001Dropout\uff0c\u4ee5\u53ca FC \u53cd\u5411\u7684 dB \u8ba1\u7b97\uff0c\u653e\u5728\u8fd9\u6761\u6d41\u4e0a\u3002<\/li>\n\n\n\n<li><strong>COMP_3<\/strong>\uff1a\u8f7b\u91cf\u7ed3\u679c\u6d41\u3002\u6fc0\u6d3b\u51fd\u6570\uff08ReLU\u3001Tanh\u3001SiLU \u7b49\uff09\u4ee5\u53ca FC\/\u5377\u79ef\u53cd\u5411\u7684 dX \u8f93\u51fa\uff0c\u6620\u5c04\u5230\u8fd9\u91cc\u3002\u5bf9 FC BWD \u8fd9\u7c7b\u5185\u90e8\u591a\u8def\u5e76\u53d1\u7684\u7b97\u5b50\uff0cdX \u88ab\u58f0\u660e\u4e3a&#8221;\u4ee3\u8868\u6d41&#8221;\uff0c\u4e0b\u6e38\u7b97\u5b50\u53ea\u9700\u8981\u7b49 COMP_3 \u4e0a\u7684 dX \u5b8c\u6210\u5373\u53ef\u3002<\/li>\n\n\n\n<li><strong>UPDATE<\/strong>\uff1a\u4f18\u5316\u5668\u3001\u68af\u5ea6\u7f29\u653e\u3001NaN \u68c0\u67e5\u3001BN \u7edf\u8ba1\u91cf\u540c\u6b65\u3001EMA \u66f4\u65b0\u3001\u6743\u91cd FP32\u2192FP16 \u8f6c\u6362\u7b49\u8bad\u7ec3\u540e\u52e4\u5de5\u4f5c\u3002\u8fd9\u7c7b Region \u7ea7\u6279\u91cf\u64cd\u4f5c\u7edf\u4e00\u8d70 UPDATE \u6d41\uff0c\u907f\u514d\u548c\u4e3b\u8ba1\u7b97\u6d41\u4e89\u7528 SM\uff0c\u4e5f\u8ba9\u4f18\u5316\u5668\u66f4\u65b0\u4e0e\u524d\u540e\u5411\u8ba1\u7b97\u4e4b\u95f4\u5f62\u6210\u6e05\u6670\u7684\u4f9d\u8d56\u8fb9\u754c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u8981\u62c6\u4e09\u6761\u8ba1\u7b97\u6d41\uff0c\u800c\u4e0d\u662f\u50cf\u4f20\u7edf\u505a\u6cd5\u90a3\u6837\u53ea\u4fdd\u7559\u4e00\u6761\u8ba1\u7b97\u6d41\u52a0\u4e00\u6761\u4f20\u8f93\u6d41\uff1f\u8fd9\u91cc\u6709\u4e24\u5c42\u8003\u8651\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u5c42\u662f\u7b97\u5b50\u5185\u90e8\u7684\u5e76\u53d1\u673a\u4f1a\u3002\u4ee5 FC \u53cd\u5411\u4f20\u64ad\u4e3a\u4f8b\uff1adW \u662f GEMM\uff08\u91cd\u8ba1\u7b97\uff09\u3001dB \u662f\u9010\u901a\u9053\u5f52\u7ea6\u3001dX \u4e5f\u662f GEMM\u3002\u4e09\u8005\u5728\u6570\u5b66\u4e0a\u4e92\u76f8\u72ec\u7acb\uff0c\u7ed9\u5b9a dY\u3001X\u3001W \u540e\u672c\u53ef\u5b8c\u5168\u5e76\u53d1\uff1b\u4f46\u5728\u672c\u6846\u67b6\u7684\u878d\u5408\u5b9e\u73b0\u91cc\uff0cdX \u4f1a\u539f\u5730\u8986\u76d6\u8f93\u5165 X \u7684\u5b58\u50a8\u4f4d\u7f6e\uff0c\u56e0\u6b64\u5fc5\u987b\u7b49 dW \u8bfb\u5b8c X \u540e\u518d\u542f\u52a8\u3002\u8fd9\u4e0d\u662f\u6570\u636e\u4f9d\u8d56\uff0c\u800c\u662f\u8bfb\u5199\u51b2\u7a81\uff08hazard\uff09\u5bfc\u81f4\u7684\u987a\u5e8f\u7ea6\u675f\u3002\u62c6\u5230\u4e09\u6761\u6d41\u540e\uff0cdB \u53ef\u4ee5\u548c dW \u5e76\u53d1\uff0cdX \u5728 dW \u5b8c\u6210\u8bfb\u53d6\u540e\u7acb\u5373\u542f\u52a8\uff0c\u5f62\u6210\u81ea\u7136\u7684 fork-join \u62d3\u6251\u3002\u8fd9\u79cd&#8221;\u628a\u6570\u5b66\u72ec\u7acb\u6027\u663e\u5f0f\u6620\u5c04\u6210\u786c\u4ef6\u5e76\u53d1&#8221;\u7684\u505a\u6cd5\uff0c\u662f\u53cd\u5411\u4f20\u64ad\u6027\u80fd\u7684\u91cd\u8981\u6765\u6e90\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e8c\u5c42\u662f\u7ed9 GPU \u8c03\u5ea6\u5668\u66f4\u591a\u8c03\u5ea6\u9009\u62e9\u3002\u73b0\u4ee3 GPU \u7684\u7247\u4e0a\u8c03\u5ea6\u5668\u975e\u5e38\u806a\u660e\uff0c\u591a\u6761\u72ec\u7acb\u6d41\u610f\u5473\u7740\u591a\u4e2a\u53ef\u4ea4\u9519\u6267\u884c\u7684\u961f\u5217\uff0c\u8c03\u5ea6\u5668\u53ef\u4ee5\u6839\u636e\u5f53\u524d SM\u3001Tensor Core\u3001\u663e\u5b58\u5e26\u5bbd\u7684\u8d1f\u8f7d\u52a8\u6001\u9009\u62e9\u4e0b\u4e00\u6761\u8be5\u53d1\u5c04\u7684 kernel\u3002\u9700\u8981\u5f3a\u8c03\u7684\u662f\uff0c\u8fd9\u4e0d\u662f\u8bf4&#8221;\u6d41\u8d8a\u591a\u8d8a\u597d&#8221;\u2014\u2014\u6d41\u592a\u591a\u4f1a\u589e\u52a0\u4e8b\u4ef6\u540c\u6b65\u5f00\u9500\u3001\u5206\u6563 cache \u5c40\u90e8\u6027\u3002\u4e94\u6761\u6d41\u662f\u5728\u5f53\u524d\u4efb\u52a1\u62d3\u6251\u4e0b\u8c03\u8bd5\u51fa\u7684\u4e00\u4e2a\u5de5\u7a0b\u5e73\u8861\u70b9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001Per-Stream \u8d44\u6e90\u9694\u79bb<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u591a\u6d41\u5e76\u53d1\u7684\u4e00\u4e2a\u5173\u952e\u524d\u63d0\u662f\u6bcf\u4e2a\u6d41\u5fc5\u987b\u62e5\u6709\u72ec\u7acb\u7684\u5e95\u5c42\u5e93\u53e5\u67c4\u3002<code>DeviceContext<\/code> \u4e3a\u6bcf\u6761\u6d41\u7ef4\u62a4\u4e86\u72ec\u7acb\u7684 <code>cudnnHandle_t<\/code>\u3001<code>cublasHandle_t<\/code> \u548c\u4e34\u65f6 workspace\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ include\/renaissance\/backend\/device_context.h\nvoid* cudnn_handles_[5] = {};\nvoid* cublas_handles_[5] = {};\nvoid* streams_[5] = {};\nmutable WSpace workspaces_[5];<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6784\u9020\u65f6\uff0c\u6bcf\u4e2a handle \u90fd\u901a\u8fc7 <code>cudnnSetStream<\/code> \/ <code>cublasSetStream<\/code> \u7ed1\u5b9a\u5230\u5bf9\u5e94 stream\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ src\/backend\/device_context.cpp\ncudnnSetStream(cudnn_handles_[i], streams_[i]);\ncublasSetStream(cublas_handles_[i], streams_[i]);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u591a\u6d41\u5b89\u5168\u7684\u57fa\u7840\u3002cuDNN \u548c cuBLAS \u7684\u5b98\u65b9\u6587\u6863\u660e\u786e\u6307\u51fa\uff0c\u4e0d\u4fdd\u8bc1\u591a\u6d41\u5171\u4eab\u540c\u4e00\u53e5\u67c4\u7684\u7ebf\u7a0b\u5b89\u5168\u6027\u3002\u5982\u679c\u4e24\u6761\u6d41\u5171\u7528\u540c\u4e00\u4e2a cuDNN \u53e5\u67c4\uff0c\u5176\u5185\u90e8\u72b6\u6001\uff08\u5982\u7b97\u6cd5\u9009\u62e9\u7f13\u5b58\u3001workspace \u6307\u9488\uff09\u53ef\u80fd\u88ab\u5e76\u53d1\u4fee\u6539\uff0c\u5bfc\u81f4\u8ba1\u7b97\u9519\u8bef\u6216 CUDA driver \u7684\u9690\u5f0f\u4e32\u884c\u5316\u9501\u3002\u72ec\u7acb\u53e5\u67c4\u52a0\u72ec\u7acb workspace \u7684\u8bbe\u8ba1\u4ece\u7269\u7406\u4e0a\u6d88\u9664\u4e86\u8fd9\u7c7b\u98ce\u9669\uff0c\u4fdd\u8bc1\u4e86\u5e76\u53d1\u7684\u7eaf\u7cb9\u6027\u3002\u6bcf\u4e2a workspace \u7684\u5927\u5c0f\u53d6\u8be5\u6d41\u4e0a\u6240\u6709\u53ef\u80fd\u64cd\u4f5c\u6240\u9700\u7684\u6700\u5927\u503c\uff08\u901a\u8fc7 <code>pre_allocate_workspace<\/code> \u6216 <code>ensure_workspace_grow<\/code> \u6309\u9700\u5206\u914d\uff09\uff0c\u786e\u4fdd\u4e0d\u4f1a\u51fa\u73b0\u8fd0\u884c\u65f6\u7a7a\u95f4\u4e0d\u8db3\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u7b97\u5b50\u5230\u6d41\u7684\u9759\u6001\u6620\u5c04<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d41\u7684\u5212\u5206\u4e0d\u80fd\u9760\u8fd0\u884c\u65f6\u4e34\u65f6\u51b3\u5b9a\uff0c\u5426\u5219\u65e2\u96be\u8c03\u8bd5\u4e5f\u65e0\u6cd5 captured \u6210 CUDA Graph\u3002Tech-Renaissance \u5728 <code>src\/backend\/op_stream_policy.cpp<\/code> \u4e2d\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7eaf\u9759\u6001\u6620\u5c04\u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">StreamKind get_op_default_stream(ComputeOp op) noexcept {\n    switch (op) {\n        \/\/ Conv\/FC \u524d\u5411 \u2192 COMP_1\n        case ComputeOp::FC_FP32_FWD:\n        case ComputeOp::FC_AMP_FWD:\n        case ComputeOp::CONV_FP32_FWD:\n        case ComputeOp::CONV_AMP_FWD:\n            return StreamKind::COMP_1;\n\n        \/\/ Conv\/FC \u53cd\u5411\uff08dX \u662f\u6700\u7ec8\u8f93\u51fa\uff0c\u4e0b\u6e38\u4f9d\u8d56\uff09\u2192 COMP_3\n        case ComputeOp::FC_FP32_BWD:\n        case ComputeOp::FC_AMP_BWD:\n        case ComputeOp::CONV_FP32_BWD:\n        case ComputeOp::CONV_AMP_BWD:\n            return StreamKind::COMP_3;\n\n        \/\/ \u9996\u5c42\u5377\u79ef\u53cd\u5411\uff08\u4ec5 wgrad\uff0c\u65e0 dX \u4e0b\u6e38\uff09\u2192 COMP_1\n        case ComputeOp::CONV_FP32_BWD_FIRST_LAYER:\n        case ComputeOp::CONV_AMP_BWD_FIRST_LAYER:\n            return StreamKind::COMP_1;\n\n        \/\/ BN \/ Pooling \/ Dropout \u2192 COMP_2\n        case ComputeOp::BN2D_AMP_FWD:\n        case ComputeOp::MAXPOOL_AMP_FWD:\n        case ComputeOp::DROPOUT_AMP_FWD:\n            return StreamKind::COMP_2;\n\n        \/\/ \u6fc0\u6d3b\u51fd\u6570 \u2192 COMP_3\n        case ComputeOp::RELU_AMP_FWD:\n        case ComputeOp::TANH_AMP_FWD:\n        case ComputeOp::SILU_AMP_FWD:\n            return StreamKind::COMP_3;\n\n        \/\/ SoftmaxCE \u2192 COMP_1\n        case ComputeOp::SOFTMAX_CE_AMP_FWD:\n        case ComputeOp::SOFTMAX_CE_AMP_BWD:\n            return StreamKind::COMP_1;\n\n        \/\/ \u6807\u91cf\u7b97\u5b50 \/ BN \u53c2\u6570\u66f4\u65b0 \u2192 UPDATE\n        case ComputeOp::SCALAR_INCREMENT:\n        case ComputeOp::ADAM_BIAS_CORRECTION:\n        case ComputeOp::BN_UPDATE_EQ_PARAMS:\n            return StreamKind::UPDATE;\n\n        \/\/ LARS \u6d41\u611f\u77e5\u53d8\u4f53 \u2192 \u5206\u522b\u6620\u5c04\u5230\u4e09\u6761\u8ba1\u7b97\u6d41\n        case ComputeOp::LARS_UPDATE_FC:\n            return StreamKind::COMP_1;\n        case ComputeOp::LARS_UPDATE_FIRST:\n            return StreamKind::COMP_2;\n        case ComputeOp::LARS_UPDATE_DEEP:\n            return StreamKind::COMP_3;\n\n        default:\n            return StreamKind::COMP_1;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e2a <code>ComputeOp<\/code> \u90fd\u6709\u4e00\u4e2a&#8221;\u4ee3\u8868\u6d41&#8221;\uff0c\u4e5f\u5c31\u662f\u8be5\u7b97\u5b50\u7684\u8f93\u51fa\u6d41\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u7cbe\u5999\u7684\u8bbe\u8ba1\u7ec6\u8282\uff1a<strong>FC\/CONV BWD \u7684\u4ee3\u8868\u6d41\u58f0\u660e\u4e3a COMP_3\uff0c\u4f46\u5b83\u5b9e\u9645\u5728\u4e09\u6d41\u4e0a\u90fd\u6709\u5de5\u4f5c<\/strong>\u3002\u4e3a\u4ec0\u4e48\uff1f\u56e0\u4e3a FC BWD \u5185\u90e8\u6709\u4e09\u4e2a\u5b50\u4efb\u52a1\u2014\u2014dW\uff08\u6743\u91cd\u68af\u5ea6\uff09\u3001dB\uff08\u504f\u7f6e\u68af\u5ea6\uff09\u3001dX\uff08\u8f93\u5165\u68af\u5ea6\uff09\u3002dW \u5728 COMP_1 \u4e0a\u7528 GEMM \u8ba1\u7b97\uff0cdB \u5728 COMP_2 \u4e0a\u5f52\u7ea6\uff0cdX \u5728 COMP_3 \u4e0a\u7528 GEMM \u8ba1\u7b97\u3002\u58f0\u660e\u4ee3\u8868\u6d41\u4e3a COMP_3\uff0c\u662f\u56e0\u4e3a dX \u662f\u8be5\u7b97\u5b50\u7684\u6700\u7ec8\u8f93\u51fa\uff0c\u4e0b\u6e38\u7b97\u5b50\u9700\u8981\u7b49\u5b83\u5b8c\u6210\u3002\u800c dW \u548c dB \u53ef\u4ee5\u5728 COMP_1 \u548c COMP_2 \u4e0a\u5e76\u53d1\u6267\u884c\uff0c\u4e0e dX \u7684\u8ba1\u7b97\u5f62\u6210\u6d41\u6c34\u7ebf\u3002\u8fd9\u4e2a\u8bed\u4e49\u7684\u6838\u5fc3\u662f\uff1a<strong>\u4ee3\u8868\u6d41\u544a\u8bc9\u6846\u67b6\u4f9d\u8d56\u65b9\u5411\uff0c\u5b9e\u9645\u5de5\u4f5c\u6d41\u7531\u7b97\u5b50\u5185\u90e8\u51b3\u5b9a<\/strong>\u3002\u6846\u67b6\u53ea\u5173\u5fc3&#8221;\u4e0b\u6e38\u5e94\u8be5\u7b49\u54ea\u6761\u6d41&#8221;\uff0c\u800c\u7b97\u5b50\u5185\u90e8\u5982\u4f55\u5206\u914d\u5de5\u4f5c\u5230\u591a\u6761\u6d41\u4e0a\uff0c\u662f\u7b97\u5b50\u81ea\u5df1\u7684\u4e8b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e RangeOp\uff08Region \u7ea7\u6279\u91cf\u64cd\u4f5c\uff09\uff0c<code>src\/graph\/capture_multi_stream.cpp<\/code> \u4e5f\u505a\u4e86\u7c7b\u4f3c\u7684\u9759\u6001\u5206\u6d41\uff1a\u6e05\u96f6\u3001\u7c7b\u578b\u8f6c\u6362\u3001EMA \u66f4\u65b0\u8d70 UPDATE \u6d41\uff1bNaN \u68c0\u67e5\u8d70 COMP_1 \u6d41\uff1bAllReduce \u901a\u4fe1\u76f8\u5173\u8d70 UPDATE \u6d41\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u8de8\u6d41\u540c\u6b65\uff1a\u7cbe\u786e\u4f9d\u8d56\u94fe<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u591a\u6d41\u5e76\u53d1\u7684\u6838\u5fc3\u96be\u9898\u4e0d\u662f&#8221;\u600e\u4e48\u62c6&#8221;\uff0c\u800c\u662f&#8221;\u600e\u4e48\u4fdd\u8bc1\u6b63\u786e\u6027&#8221;\u3002Tech-Renaissance \u6ca1\u6709\u4f7f\u7528\u7c97\u7c92\u5ea6\u7684 <code>cudaDeviceSynchronize<\/code>\uff0c\u800c\u662f\u91c7\u7528\u4e8b\u4ef6\u9a71\u52a8\u7684\u7cbe\u786e\u4f9d\u8d56\u94fe\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 <code>capture_multi_stream.cpp<\/code> \u4e2d\uff0c\u6846\u67b6\u7ef4\u62a4\u4e86\u4e00\u4e2a <code>MultiStreamCaptureState<\/code>\uff0c\u8bb0\u5f55\u6bcf\u6761\u5df2\u6fc0\u6d3b stream \u7684\u5b8c\u6210\u4e8b\u4ef6\u3002<code>insert_cross_op_barrier<\/code> \u7684\u6838\u5fc3\u903b\u8f91\u975e\u5e38\u514b\u5236\uff1a\u5b83\u53ea\u8ba9&#8221;\u4e0b\u4e00\u4e2a\u7b97\u5b50\u7684\u4ee3\u8868\u6d41&#8221;\u7b49\u5f85&#8221;\u4e0a\u4e00\u4e2a\u7b97\u5b50\u7684\u8f93\u51fa\u6d41&#8221;\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ src\/graph\/capture_multi_stream.cpp\nvoid insert_cross_op_barrier(const GraphNode&amp; \/*prev_node*\/,\n                             const GraphNode&amp; next_node,\n                             MultiStreamCaptureState&amp; state,\n                             const DeviceContext&amp; ctx) {\n    int out_idx = state.output_stream_idx;\n    if (out_idx &lt; 0) return;\n\n    StreamKind target_sk;\n    if (next_node.kind == GraphNode::Kind::COMPUTE) {\n        target_sk = get_op_default_stream(next_node.compute_op);\n    } else if (next_node.kind == GraphNode::Kind::RANGE) {\n        \/\/ RangeOp \u4e5f\u6309\u8bed\u4e49\u9759\u6001\u5206\u6d41...\n        switch (next_node.range_op) {\n            case RangeOp::RANGE_CLEAR:\n            case RangeOp::RANGE_CAST_FP32_TO_FP16:\n            case RangeOp::RANGE_EMA_PARAM_UPDATE:\n                target_sk = StreamKind::UPDATE; break;\n            case RangeOp::RANGE_CHECK_NAN:\n                target_sk = StreamKind::COMP_1; break;\n            case RangeOp::RANGE_SUM_ALLREDUCE:\n            case RangeOp::RANGE_BN_STATS_ALLREDUCE:\n                target_sk = StreamKind::UPDATE; break;\n            default:\n                target_sk = StreamKind::COMP_1; break;\n        }\n    } else {\n        return;\n    }\n\n    cudaStream_t target_s = static_cast&lt;cudaStream_t>(ctx.stream(target_sk));\n    int target_idx = state.find_stream_index(target_s);\n    if (target_idx >= 0 &amp;&amp; target_idx != out_idx) {\n        cudaStreamWaitEvent(target_s,\n            state.streams[out_idx].last_done_event, 0);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4e0a\u4e00\u4e2a\u7b97\u5b50\u8f93\u51fa\u5728 COMP_3\uff0c\u4e0b\u4e00\u4e2a\u7b97\u5b50\u4ee3\u8868\u6d41\u4e5f\u662f COMP_3\uff0c\u5219\u4e0d\u9700\u8981\u989d\u5916\u540c\u6b65\uff1b\u5982\u679c\u4e0b\u4e00\u4e2a\u7b97\u5b50\u4ee3\u8868\u6d41\u662f COMP_1\uff0c\u5c31\u8ba9 COMP_1 wait \u90a3\u4e2a COMP_3 \u4e8b\u4ef6\u3002\u8fd9\u79cd&#8221;\u7cbe\u786e\u70b9\u5230\u70b9&#8221;\u7684\u540c\u6b65\u6709\u4e24\u65b9\u9762\u597d\u5904\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\uff0c\u907f\u514d\u661f\u578b\u5e7f\u64ad\u3002\u4e0d\u4f1a\u8ba9\u4e0d\u76f8\u5e72\u7684\u6d41\u4e5f\u505c\u4e0b\u6765\u7b49\uff0c\u4ece\u800c\u4fdd\u7559\u6700\u5927\u5e76\u53d1\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e8c\uff0c\u4f9d\u8d56\u56fe\u59cb\u7ec8\u662f\u5355\u5411 DAG\u3002\u4e8b\u4ef6\u7684\u4f20\u9012\u65b9\u5411\u6cbf\u7740\u771f\u5b9e\u6570\u636e\u4f9d\u8d56\u8d70\uff0c\u4e0d\u4f1a\u4ea7\u751f\u5faa\u73af\u7b49\u5f85\u6216\u6b7b\u9501\u3002\u8fd9\u4e00\u70b9\u5bf9 CUDA Graph \u6355\u83b7\u5c24\u5176\u91cd\u8981\uff0c\u56e0\u4e3a Graph \u5185\u90e8\u4e0d\u80fd\u51fa\u73b0\u5faa\u73af\u4f9d\u8d56\uff0c\u5426\u5219\u6355\u83b7\u4f1a\u5931\u8d25\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>finalize_cross_stream_barrier<\/code> \u5219\u5728\u6574\u5f20\u56fe\u6355\u83b7\u672b\u5c3e\u6267\u884c\uff1a\u8ba9 primary stream \u7b49\u5f85\u6240\u6709\u8fd8\u6709 pending work \u7684 secondary stream\uff0c\u786e\u4fdd <code>cudaStreamEndCapture<\/code> \u4e4b\u524d\u6240\u6709\u8ba1\u7b97\u7ed3\u679c\u90fd\u5df2\u53ef\u89c1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6240\u6709\u7528\u4e8e capture \u7684\u4e8b\u4ef6\u90fd\u5728 <code>cudaStreamBeginCapture<\/code> \u4e4b\u524d\u9884\u521b\u5efa\uff0ccapture \u671f\u95f4\u53ea\u8fdb\u884c <code>cudaEventRecord<\/code> \u548c <code>cudaStreamWaitEvent<\/code>\u3002\u8fd9\u7b26\u5408 CUDA Graph \u7684\u6355\u83b7\u89c4\u8303\uff1a\u4e0d\u80fd\u5728\u6355\u83b7\u8fc7\u7a0b\u4e2d\u52a8\u6001\u521b\u5efa\u4e8b\u4ef6\u3002<code>MultiStreamCaptureState<\/code> \u7684 <code>kMaxActiveStreams = 5<\/code> \u4e5f\u4e0e\u5e95\u5c42\u4e94\u6761\u6d41\u5b8c\u5168\u5bf9\u9f50\uff0c\u9884\u6ce8\u518c\u9636\u6bb5\u5148\u628a COMP_1\/2\/3 \u6ce8\u518c\u597d\uff0cUPDATE \u548c TRANS \u5728\u9700\u8981\u65f6\u518d\u6309\u9700\u6ce8\u518c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u5b50\u56fe\u5230\u6d41\u7684\u9759\u6001\u6620\u5c04<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b97\u5b50\u6709\u4ee3\u8868\u6d41\uff0c\u5b50\u56fe\u4e5f\u6709\u4ee3\u8868\u6d41\u3002<code>GraphAtlas<\/code> \u7684\u6bcf\u4e2a Slot \u90fd\u8bb0\u5f55\u4e86\u5b83\u5e94\u8be5\u5728\u54ea\u6761\u6d41\u4e0a\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct Slot {\n    const ComputationGraph* cg = nullptr;\n    const MemoryPlan*       mp = nullptr;\n    ShapeId                 shape_id{};\n    StreamKind              stream_kind = StreamKind::COMP_1;\n    int32_t                 captured_idx = -1;\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DeepLearningTask::stream_for(GraphId gid)<\/code> \u628a\u5b50\u56fe\u4e00\u4e00\u6620\u5c04\u5230\u6d41\uff08<code>src\/task\/deep_learning_task.cpp<\/code>\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">StreamKind DeepLearningTask::stream_for(GraphId gid) {\n    switch (gid) {\n        case GraphId::TRANSFER_A:       return StreamKind::TRANS;\n        case GraphId::TRANSFER_B:       return StreamKind::TRANS;\n        case GraphId::FIRST_LAYER_FWD_A:  return StreamKind::COMP_1;\n        case GraphId::FIRST_LAYER_FWD_B:  return StreamKind::COMP_1;\n        case GraphId::DEEP_FWD_BWD:     return StreamKind::COMP_1;\n        case GraphId::FIRST_LAYER_BWD_A:  return StreamKind::COMP_1;\n        case GraphId::FIRST_LAYER_BWD_B:  return StreamKind::COMP_1;\n        case GraphId::ZERO_GRAD:\n        case GraphId::FIRST_COMM:\n        case GraphId::DEEP_COMM:\n        case GraphId::CAST_DEEP_GRAD_FP16_TO_FP32:\n        case GraphId::CAST_FIRST_GRAD_FP16_TO_FP32:\n        case GraphId::NAN_CHECK_AND_GRAD_SCALING:\n        case GraphId::STATS_COMM:\n        case GraphId::UPDATE_STATS:\n        case GraphId::OPTIMIZER:\n        case GraphId::EMA_UPDATE:\n        case GraphId::CAST_MAIN_FP32_TO_FP16:\n            return StreamKind::UPDATE;\n        case GraphId::INF_MAIN_A:\n        case GraphId::INF_MAIN_B:\n            return StreamKind::COMP_1;\n        case GraphId::LARS_FC_OPT:\n            return StreamKind::COMP_1;\n        case GraphId::LARS_FIRST_CONV_OPT:\n            return StreamKind::COMP_2;\n        case GraphId::LARS_DEEP_CONV_OPT:\n            return StreamKind::COMP_3;\n        case GraphId::UPDATE_BN_INF_PARAMS:\n            return StreamKind::UPDATE;\n        default:\n            return StreamKind::COMP_1;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5927\u90e8\u5206 shape \u65e0\u5173\u7684\u5b50\u56fe\uff08ZERO_GRAD\u3001\u901a\u4fe1\u3001\u4f18\u5316\u5668\u3001\u7c7b\u578b\u8f6c\u6362\u3001EMA \u66f4\u65b0\u7b49\uff09\u90fd\u5f52\u5165 UPDATE \u6d41\u3002\u8fd9\u662f\u56e0\u4e3a\u8fd9\u4e9b\u64cd\u4f5c\u4e0e\u8ba1\u7b97\u6d41\u4e0a\u7684\u7b97\u5b50\u6ca1\u6709\u987a\u5e8f\u4f9d\u8d56\uff08\u5b83\u4eec\u64cd\u4f5c\u7684\u662f\u68af\u5ea6\u533a\u548c\u6743\u91cd\u533a\uff0c\u800c\u8ba1\u7b97\u6d41\u64cd\u4f5c\u7684\u662f\u7279\u5f81\u56fe\u533a\u548c\u8f93\u5165\u7f13\u51b2\u533a\uff09\uff0c\u53ef\u4ee5\u5b89\u5168\u5730\u4e0e\u8ba1\u7b97\u5e76\u884c\u3002\u800c LARS \u4f18\u5316\u5668\u4e4b\u6240\u4ee5\u88ab\u62c6\u5206\u5230\u4e09\u6761\u8ba1\u7b97\u6d41\u4e0a\uff0c\u662f\u56e0\u4e3a FC \u5c42\u3001\u9996\u5c42\u5377\u79ef\u3001\u6df1\u5c42\u5377\u79ef\u7684\u6743\u91cd\u4f4d\u4e8e\u4e0d\u540c\u7684 Region \u4e2d\uff0c\u4e14 LARS \u7684\u4fe1\u4efb\u6bd4\u7387\u8ba1\u7b97\u548c\u66f4\u65b0\u64cd\u4f5c\u53ef\u4ee5\u5b8c\u5168\u72ec\u7acb\u8fdb\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd&#8221;\u7f16\u8bd1\u671f\u51b3\u5b9a\u3001\u8fd0\u884c\u671f O(1) \u67e5\u8868&#8221;\u7684\u8bbe\u8ba1\uff0c\u548c\u591a\u6d41\u67b6\u6784\u662f\u76f8\u8f85\u76f8\u6210\u7684\u3002\u5982\u679c\u8fd0\u884c\u65f6\u8fd8\u9700\u8981\u52a8\u6001\u51b3\u5b9a\u6bcf\u4e2a\u7b97\u5b50\u6216\u6bcf\u5f20\u56fe\u8be5\u7528\u54ea\u6761\u6d41\uff0c\u90a3\u8981\u4e48\u65e0\u6cd5 captured \u6210 Graph\uff0c\u8981\u4e48\u6bcf\u6b21 launch \u90fd\u8981\u4ed8\u51fa CPU \u5224\u65ad\u5f00\u9500\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001A\/B \u53cc\u7f13\u51b2\u4e0e\u8bad\u7ec3\u6b65\u8c03\u5ea6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u591a\u6d41\u7684\u4ef7\u503c\u8981\u901a\u8fc7\u8bad\u7ec3\u5faa\u73af\u7684\u5de5\u4f5c\u6d41\u624d\u80fd\u771f\u6b63\u91ca\u653e\u3002<code>run_train_epoch_gpu()<\/code>\uff08<code>src\/task\/deep_learning_task.cpp<\/code>\uff09\u628a\u4e00\u6b65\u8bad\u7ec3\u62c6\u6210\u82e5\u5e72\u5b50\u56fe\uff0c\u5e76\u6309\u4f9d\u8d56\u5173\u7cfb\u8c03\u5ea6\u5b83\u4eec\u3002\u6bcf\u4e2a GPU rank \u90fd\u6709\u81ea\u5df1\u7684 CUDA stream \u5f15\u7528\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cudaStream_t s_up     = ctx.stream(StreamKind::UPDATE);\ncudaStream_t s_trans  = ctx.stream(StreamKind::TRANS);\ncudaStream_t s_c1     = ctx.stream(StreamKind::COMP_1);\ncudaStream_t s_c2     = ctx.stream(StreamKind::COMP_2);\ncudaStream_t s_c3     = ctx.stream(StreamKind::COMP_3);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u666e\u901a\u8bad\u7ec3 batch \u7684\u6838\u5fc3\u8c03\u5ea6\u5982\u4e0b\uff08\u6765\u81ea <code>run_train_epoch_gpu()<\/code> \u7684 normal batch \u5faa\u73af\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ 1. \u5c06\u65b0\u5b66\u4e60\u7387\u901a\u8fc7 TRANS \u6d41\u5f02\u6b65\u62f7\u8d1d\u5230 GPU\ncudaMemcpyAsync(lr_dev_ptr, lr_pinned_[rank], sizeof(float),\n                cudaMemcpyHostToDevice, s_trans);\n\n\/\/ 2. \u5728 UPDATE \u6d41\u4e0a\u542f\u52a8\u68af\u5ea6\u6e05\u96f6\uff0c\u540c\u65f6\u5728 COMP_1 \u6d41\u4e0a\u542f\u52a8\u9996\u5c42\u524d\u5411\nif (n_zg) cudaGraphLaunch(n_zg, s_up);      \/\/ ZERO_GRAD\nif (g_fwd) cudaGraphLaunch(g_fwd, s_c1);    \/\/ FIRST_LAYER_FWD\n\n\/\/ 3. \u7b49\u5b66\u4e60\u7387\u4f20\u8f93\u5b8c\u6210\uff0c\u7136\u540e\u542f\u52a8\u4e0b\u4e00\u4e2a batch \u7684 H2D \u4f20\u8f93\nsync_tr();\nts->wait_buffer_readable(next_buf);\nif (g_xfer_n) cudaGraphLaunch(g_xfer_n, s_trans);\n\n\/\/ 4. \u7b49\u8ba1\u7b97\u5b8c\u6210\uff0c\u542f\u52a8\u6df1\u5c42\u524d\u5411+\u53cd\u5411\nsync_comp(); sync_up();\nif (g_deep) cudaGraphLaunch(g_deep, s_c1);\nsync_comp();\n\n\/\/ 5. \u542f\u52a8\u9996\u5c42\u53cd\u5411\uff08COMP_1\uff09\uff0c\u4ee5\u53ca\u68af\u5ea6 cast\u3001AllReduce\uff08UPDATE\uff09\nif (!frozen &amp;&amp; g_first) cudaGraphLaunch(g_first, s_c1);\nif (using_amp &amp;&amp; n_cdg) cudaGraphLaunch(n_cdg, s_up);\nif (n_dar) cudaGraphLaunch(n_dar, s_up);\n\n\/\/ 6. \u542f\u52a8\u5269\u4f59\u901a\u4fe1\/\u7edf\u8ba1\/\u68c0\u67e5\u5b50\u56fe\uff08UPDATE\uff09\nsync_up(); sync_comp();\nif (using_amp &amp;&amp; n_cfg) cudaGraphLaunch(n_cfg, s_up);\nif (n_far) cudaGraphLaunch(n_far, s_up);\nif (n_accum) cudaGraphLaunch(n_accum, s_up);\nif (n_ncg) cudaGraphLaunch(n_ncg, s_up);\nif (n_sc) cudaGraphLaunch(n_sc, s_up);\nif (n_us) cudaGraphLaunch(n_us, s_up);\nsync_up();\n\n\/\/ 7. \u542f\u52a8\u4f18\u5316\u5668\u66f4\u65b0\uff08UPDATE\uff09+ LARS \u6d41\u611f\u77e5\u66f4\u65b0\uff08\u4e09\u6761\u8ba1\u7b97\u6d41\uff09\nif (n_wu) cudaGraphLaunch(n_wu, s_up);\nif (n_lars_fc)  cudaGraphLaunch(n_lars_fc,  s_c1);  \/\/ FC \u5c42\nif (n_lars_fc2) cudaGraphLaunch(n_lars_fc2, s_c2);  \/\/ \u9996\u5c42\u5377\u79ef\nif (n_lars_dc)  cudaGraphLaunch(n_lars_dc,  s_c3);  \/\/ \u6df1\u5c42\u5377\u79ef\nsync_up(); sync_comp();\n\n\/\/ 8. AMP \u6743\u91cd FP32\u2192FP16 \u8f6c\u6362\uff08UPDATE\uff09\uff0c\u6700\u540e\u540c\u6b65\u4f20\u8f93\u6d41\nif (using_amp &amp;&amp; n_cm) { cudaGraphLaunch(n_cm, s_up); sync_up(); }\nsync_tr();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u7684\u8bbe\u8ba1\u7528\u610f\u503c\u5f97\u4ed4\u7ec6\u54c1\u5473\u3002\u7b2c 2 \u6b65\u4e2d\uff0c\u68af\u5ea6\u6e05\u96f6\u548c\u9996\u5c42\u524d\u5411\u540c\u65f6\u542f\u52a8\uff0c\u4e00\u4e2a\u662f UPDATE \u6d41\u4e0a\u7684\u8f7b\u91cf RangeOp\uff0c\u4e00\u4e2a\u662f COMP_1 \u6d41\u4e0a\u7684\u91cd\u8ba1\u7b97\uff0c\u4e24\u8005\u4e92\u4e0d\u963b\u585e\u3002\u7b2c 3 \u6b65\u4e2d\uff0c<code>sync_tr()<\/code> \u88ab\u653e\u5728\u542f\u52a8\u9996\u5c42\u8ba1\u7b97\u4e4b\u540e\u624d\u6267\u884c\u2014\u2014\u56e0\u4e3a H2D \u4f20\u8f93\u5ef6\u8fdf\u9ad8\uff0c\u5c3d\u65e9\u542f\u52a8\u4e0b\u4e00\u4e2a batch \u7684\u4f20\u8f93\u53ef\u4ee5\u6700\u5927\u5316\u4e0e\u5f53\u524d batch \u8ba1\u7b97\u7684\u91cd\u53e0\u3002\u7b2c 5 \u6b65\u4e2d\uff0c\u9996\u5c42\u53cd\u5411 <code>g_first<\/code> \u8dd1\u5728 COMP_1 \u4e0a\uff0c\u800c\u4e0d\u662f UPDATE\uff0c\u56e0\u4e3a\u5b83\u4ecd\u7136\u5c5e\u4e8e\u53cd\u5411\u8ba1\u7b97\u7684\u6570\u5b66\u8def\u5f84\uff1b\u68af\u5ea6 cast \u548c AllReduce \u624d\u8d70 UPDATE \u6d41\u3002\u7b2c 7 \u6b65\u4e2d\uff0cLARS \u4f18\u5316\u5668\u7684\u66f4\u65b0\u88ab\u62c6\u5206\u5230\u4e09\u6761\u8ba1\u7b97\u6d41\u4e0a\u5e76\u53d1\u6267\u884c\uff0c\u56e0\u4e3a\u4e0d\u540c\u5c42\u7684\u6743\u91cd\u4f4d\u4e8e\u4e0d\u540c\u7684 Region\uff0c\u4e92\u4e0d\u51b2\u7a81\u3002\u7b2c 8 \u6b65\u4e2d\uff0cTRANS \u6d41\u7684\u540c\u6b65\u88ab\u653e\u5230\u6700\u540e\uff0c\u7ed9\u6570\u636e\u4f20\u8f93\u7559\u51fa\u4e86\u6700\u5927\u65f6\u95f4\u7a97\u53e3\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u4e2a\u8bad\u7ec3\u5faa\u73af\u4e2d\uff0c\u4e94\u6761\u6d41\u5404\u53f8\u5176\u804c\uff1aTRANS \u5728\u642c\u8fd0\u4e0b\u4e00\u4e2a batch \u7684\u6570\u636e\uff0cCOMP_1\/2\/3 \u5728\u8dd1\u5f53\u524d batch \u7684\u8ba1\u7b97\uff0cUPDATE \u5728\u5904\u7406\u68af\u5ea6\u6e05\u96f6\u3001\u901a\u4fe1\u3001\u4f18\u5316\u5668\u66f4\u65b0\u7b49\u540e\u5904\u7406\u3002\u8fd9\u79cd\u7f16\u6392\u8ba9 GPU \u5185\u90e8\u7684\u8ba1\u7b97\u5f15\u64ce\u3001\u62f7\u8d1d\u5f15\u64ce\u3001\u4ee5\u53ca NCCL \u901a\u4fe1\u5f15\u64ce\u5c3d\u53ef\u80fd\u540c\u65f6\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001CUDA Graph \u4e2d\u7684\u591a\u6d41\u56fa\u5316<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u591a\u6d41\u62d3\u6251\u7684\u6700\u7ec8\u5f52\u5bbf\u662f CUDA Graph \u6355\u83b7\u3002\u6355\u83b7\u8fc7\u7a0b\u5c06\u591a\u6d41\u64cd\u4f5c\u56fa\u5316\u4e3a\u4e00\u5f20\u9759\u6001 GPU \u4fa7\u6267\u884c\u56fe\uff0c\u5305\u542b\u6240\u6709\u7684\u4e8b\u4ef6\u4f9d\u8d56\u548c kernel \u8c03\u7528\u3002\u6355\u83b7\u540e\uff0c\u4e00\u6b21 <code>cudaGraphLaunch<\/code> \u5c31\u80fd\u89e6\u53d1\u6574\u4e2a\u591a\u6d41\u62d3\u6251\u7684\u6267\u884c\uff0c\u65e0\u9700 CPU \u53cd\u590d\u4ecb\u5165\u6bcf\u6b21 kernel launch\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 <code>src\/graph\/capture_cuda.cpp<\/code> \u4e2d\uff0c\u6355\u83b7\u6d41\u7a0b\u5206\u4e3a\u56db\u4e2a\u9636\u6bb5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u9884\u6ce8\u518c\u9636\u6bb5<\/strong>\uff1a\u5728 <code>cudaStreamBeginCapture<\/code> \u4e4b\u524d\uff0c\u628a primary stream \u548c COMP_1\/2\/3 \u6ce8\u518c\u5230 <code>MultiStreamCaptureState<\/code>\uff0c\u5e76\u91cd\u65b0\u521b\u5efa <code>last_done_event<\/code>\u3002CUDA Graph \u8981\u6c42\u4e8b\u4ef6\u4e0d\u80fd\u5728\u6355\u83b7\u8fc7\u7a0b\u4e2d\u52a8\u6001\u521b\u5efa\u3002<\/li>\n\n\n\n<li><strong>\u5f15\u5165 secondary \u6d41<\/strong>\uff1a\u8c03\u7528 <code>cudaStreamBeginCapture<\/code> \u5f00\u59cb\u6355\u83b7\u540e\uff0c\u5728 primary stream \u4e0a\u8bb0\u5f55\u4e00\u4e2a dummy event\uff0c\u7136\u540e\u8ba9\u6240\u6709 secondary \u6d41 wait \u8fd9\u4e2a event\u3002\u8fd9\u4e00\u6b65\u5c06 secondary \u6d41\u5f15\u5165 CUDA Graph \u7684\u6355\u83b7\u4e0a\u4e0b\u6587\uff0c\u907f\u514d\u540e\u7eed primary wait secondary \u65f6\u62a5 &#8220;dependency created on uncaptured work&#8221;\u3002<\/li>\n\n\n\n<li><strong>\u9010\u8282\u70b9 replay<\/strong>\uff1a\u904d\u5386 ComputationGraph \u7684\u8282\u70b9\uff0c\u6bcf\u4e2a\u8282\u70b9\u524d\u8c03\u7528 <code>insert_cross_op_barrier<\/code> \u505a\u7cbe\u786e\u540c\u6b65\uff0c\u7136\u540e\u8c03\u7528\u7b97\u5b50\u6ce8\u518c\u7684 <code>launch_cuda<\/code> \u6216\u9ed8\u8ba4 replay \u51fd\u6570\u3002\u9ed8\u8ba4 replay \u51fd\u6570\u4f1a\u6839\u636e <code>get_op_default_stream<\/code> \u9009\u62e9\u4ee3\u8868\u6d41\uff0c\u5e76\u5728\u8be5\u6d41\u4e0a\u8bb0\u5f55\u5b8c\u6210\u4e8b\u4ef6\u3002<\/li>\n\n\n\n<li><strong>\u6536\u675f\u4e0e\u5b9e\u4f8b\u5316<\/strong>\uff1a\u8c03\u7528 <code>finalize_cross_stream_barrier<\/code> \u8ba9 primary stream \u7b49\u5f85\u6240\u6709\u8fd8\u6709 pending work \u7684 secondary stream\uff0c\u7136\u540e <code>cudaStreamEndCapture<\/code> \u548c <code>cudaGraphInstantiate<\/code> \u5b8c\u6210\u56fa\u5316\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u6355\u83b7\u5b8c\u6210\u540e\u7684 CUDA Graph \u662f\u4e00\u4e2a\u81ea\u5305\u542b\u7684 GPU \u4fa7\u6267\u884c\u8ba1\u5212\uff1a\u6240\u6709\u7684 kernel \u8c03\u7528\u3001\u4e8b\u4ef6\u540c\u6b65\u90fd\u5df2\u88ab\u7f16\u7801\u4e3a\u4e00\u5f20\u9759\u6001 DAG\u3002\u8fd0\u884c\u65f6\u53ea\u9700\u8981\u4e00\u6b21 <code>cudaGraphLaunch<\/code>\uff0cGPU \u5c31\u4f1a\u6309\u7167\u9884\u7f16\u8bd1\u7684\u62d3\u6251\u81ea\u884c\u8c03\u5ea6\u2014\u2014CPU \u5b8c\u5168\u89e3\u653e\u51fa\u6765\uff0c\u4e0d\u518d\u53c2\u4e0e\u6bcf\u4e00\u6b21 kernel launch \u7684\u6d3e\u53d1\u3002\u8fd9\u5bf9\u4e8e\u8bad\u7ec3\u541e\u5410\u7684\u63d0\u5347\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5728\u9ad8\u9891\u8fed\u4ee3\u4e2d\uff0cCPU \u7684 kernel launch \u5f00\u9500\u4f1a\u7d2f\u79ef\u4e3a\u4e0d\u53ef\u5ffd\u89c6\u7684\u5ef6\u8fdf\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001\u4e00\u4e9b\u5fc5\u8981\u7684\u8c28\u614e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u5230\u8fd9\u91cc\uff0c\u5fc5\u987b\u5f3a\u8c03\u4e00\u4ef6\u4e8b\uff1a\u591a\u6d41\u67b6\u6784\u7684\u6536\u76ca\u4e0d\u662f&#8221;\u666e\u4e16\u771f\u7406&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u9ad8\u5ea6\u4f9d\u8d56\u4e8e\u5177\u4f53\u4efb\u52a1\u62d3\u6251\u3001kernel \u5927\u5c0f\u3001GPU \u67b6\u6784\u3001batch size \u548c\u663e\u5b58\u5e26\u5bbd\u538b\u529b\u3002\u67d0\u4e9b\u5927\u7279\u5f81\u56fe\u3001\u4f4e\u8ba1\u7b97\u5bc6\u5ea6\u7684\u5c42\uff0c\u62c6\u6d41\u540e\u53cd\u800c\u53ef\u80fd\u56e0\u4e3a\u540c\u6b65\u5f00\u9500\u6216\u8c03\u5ea6\u788e\u7247\u5316\u800c\u53d8\u6162\u3002Tech-Renaissance \u9009\u62e9\u4e94\u6761\u6d41\u3001\u4e09\u6761\u8ba1\u7b97\u6d41\uff0c\u662f\u57fa\u4e8e\u5f53\u524d\u6846\u67b6\u652f\u6301\u7684\u7f51\u7edc\u7ed3\u6784\uff08ResNet\u3001VGG \u7b49\uff09\u3001NHWC \u5e03\u5c40\u3001AMP FP16 \u8def\u7ebf\u4ee5\u53ca A100\/RTX 50 \u7cfb GPU \u4e0a\u7684\u5b9e\u6d4b\u53cd\u9988\u6240\u505a\u7684\u5de5\u7a0b\u6298\u4e2d\uff0c\u800c\u4e0d\u662f\u67d0\u79cd\u653e\u4e4b\u56db\u6d77\u800c\u7686\u51c6\u7684\u516c\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u5916\uff0c&#8221;\u6bd4 PyTorch \u5feb&#8221;\u4ece\u6765\u4e0d\u53ea\u662f\u591a\u6d41\u7684\u529f\u52b3\u3002\u5b83\u662f\u9759\u6001\u56fe\u3001CUDA Graph \u5168\u6355\u83b7\u3001MemoryPlan \u663e\u5b58\u5206\u533a\u3001CBR \u878d\u5408\u7b97\u5b50\u3001DTS \u6570\u636e\u683c\u5f0f\u3001\u591a\u6d41\u5e76\u53d1\u3001per-stream \u8d44\u6e90\u9694\u79bb\u7b49\u8bb8\u591a\u8bbe\u8ba1\u53e0\u52a0\u540e\u7684\u7efc\u5408\u7ed3\u679c\u3002\u4efb\u4f55\u628a\u6027\u80fd\u4f18\u52bf\u5f52\u56e0\u4e8e\u5355\u4e00\u5947\u6280\u7684\u8bf4\u6cd5\uff0c\u90fd\u662f\u4e0d\u8d1f\u8d23\u4efb\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ed3\u8bed<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tech-Renaissance \u7684\u591a\u6d41\u5e76\u53d1\u67b6\u6784\u53ef\u4ee5\u6982\u62ec\u4e3a\u4e00\u53e5\u8bdd\uff1a<strong>\u7528\u9759\u6001\u6620\u5c04\u628a\u7b97\u5b50\u5206\u914d\u5230\u5408\u9002\u7684\u6d41\uff0c\u7528\u7cbe\u786e\u4e8b\u4ef6\u628a\u4f9d\u8d56\u5173\u7cfb\u8868\u8fbe\u6210\u5355\u5411 DAG\uff0c\u7528 A\/B \u53cc\u7f13\u51b2\u628a\u6570\u636e\u4f20\u8f93\u585e\u8fdb\u8ba1\u7b97\u7684\u7a7a\u9699\u3002<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u4e0d\u662f\u76f2\u76ee\u589e\u52a0\u5e76\u53d1\uff0c\u800c\u662f\u628a\u8bad\u7ec3\u4efb\u52a1\u7684\u6570\u5b66\u4f9d\u8d56\u7ed3\u6784\u663e\u5f0f\u7ffb\u8bd1\u7ed9 GPU \u8c03\u5ea6\u5668\u3002\u914d\u5408 CUDA Graph \u5168\u6355\u83b7\uff0c\u8fd9\u4e9b\u6d41\u62d3\u6251\u5728\u7f16\u8bd1\u671f\u5c31\u88ab\u56fa\u5316\u4e0b\u6765\uff0c\u8fd0\u884c\u65f6\u53ea\u9700\u8981\u4e00\u6b21\u6027 replay\uff0c\u51e0\u4e4e\u4e0d\u518d\u6709 CPU \u4fa7\u7684 stream \u9009\u62e9\u3001\u4e8b\u4ef6\u63d2\u5165\u3001\u540c\u6b65\u5224\u65ad\u5f00\u9500\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u4e00\u7bc7\u6587\u7ae0\uff0c\u6211\u4eec\u5c06\u7ee7\u7eed\u6df1\u5165\u8fd0\u884c\u65f6\uff0c\u8bb2\u8bb2 Tech-Renaissance \u5982\u4f55\u628a\u6574\u4e2a\u8bad\u7ec3\u5faa\u73af\u6355\u83b7\u6210 CUDA Graph\uff0c\u4ee5\u53ca\u591a\u6d41\u6355\u83b7\u4e2d\u7684\u4f9d\u8d56\u7ba1\u7406\u7ec6\u8282\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u2014\u2014\u201c\u4e00\u4e2a\u4eba\u7528AI\u5982\u4f55\u5199\u51fa\u6bd4PyTorch\u66f4\u5feb\u7684\u81ea\u7814\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u201d\u7cfb\u5217\u6587\u7ae0\u4e4b\u5341\u4e03 \u5728\u6df1\u5ea6\u5b66\u4e60\u8bad\u7ec3\u91cc\uff0cGPU \u5e76 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":704,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[15],"tags":[],"class_list":["post-523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-15"],"_links":{"self":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=523"}],"version-history":[{"count":3,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/523\/revisions"}],"predecessor-version":[{"id":716,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/523\/revisions\/716"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/media\/704"}],"wp:attachment":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}