{"id":10006932,"date":"2022-11-29T14:11:16","date_gmt":"2022-11-29T06:11:16","guid":{"rendered":"https:\/\/ityet.com\/?p=10006932"},"modified":"2022-11-29T14:11:16","modified_gmt":"2022-11-29T06:11:16","slug":"%e6%8a%80%e6%9c%af%e8%a7%a3%e8%af%bb%e5%80%9a%e5%a4%a9-ecs-%e5%ae%9e%e4%be%8b-arm-%e8%8a%af%e7%89%87%e7%9a%84-python-ai-%e7%ae%97%e5%8a%9b%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006932","title":{"rendered":"\u6280\u672f\u89e3\u8bfb\u501a\u5929 ECS \u5b9e\u4f8b \u2014 Arm \u82af\u7247\u7684 Python-AI \u7b97\u529b\u4f18\u5316"},"content":{"rendered":"<p>\u6df1\u5ea6\u5b66\u4e60\u6280\u672f\u5728\u56fe\u50cf\u8bc6\u522b\u3001\u641c\u7d22\u63a8\u8350\u7b49\u9886\u57df\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\u3002\u8fd1\u5e74\u6765\u5404\u5927 CPU \u5382\u5546\u4e5f\u9010\u6e10\u628a AI \u7b97\u529b\u7eb3\u5165\u4e86\u91cd\u70b9\u53d1\u5c55\u65b9\u5411\uff0c\u901a\u8fc7\u300aArm \u82af\u7247 Python-AI \u7b97\u529b\u4f18\u5316\u300b\u6211\u4eec\u5c06\u770b\u5230\u9f99\u8725\u793e\u533a Arm \u67b6\u6784 SIG\uff08Special Interest Group\uff09 \u5229\u7528\u6700\u65b0\u7684 Arm \u6307\u4ee4\u96c6\u4f18\u5316 Python-AI \u63a8\u7406 workload \u7684\u6027\u80fd\u3002<\/p>\n<h3>\u501a\u5929ECS\u5b9e\u4f8b\u7684AI\u63a8\u7406\u8f6f\u4ef6\u4f18\u5316<\/h3>\n<p>\u963f\u91cc\u4e91\u63a8\u51fa\u7684\u501a\u5929Arm ECS\u5b9e\u4f8b\uff0c\u62e5\u6709\u9488\u5bf9AI\u573a\u666f\u7684\u63a8\u7406\u52a0\u901f\u80fd\u529b\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u52a0\u901f\u7684\u539f\u7406\u4ee5\u53ca\u4ee5\u53ca\u76f8\u5173\u7684\u8f6f\u4ef6\u751f\u6001\u9002\u914d\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924452\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u5377\u79ef\u795e\u7ecf\u7f51\u7edc(CNN)\u5728\u56fe\u50cf\u548c\u8bed\u97f3\u9886\u57df\u4f7f\u7528\u5e7f\u6cdb\uff0c\u795e\u7ecf\u7f51\u7edc\u7b97\u6cd5\u76f8\u6bd4\u4f20\u7edf\u7684\u7b97\u6cd5\u6d88\u8017\u4e86\u66f4\u591a\u7b97\u529b\u3002\u4e3a\u4e86\u63a2\u7d22\u5bf9\u8ba1\u7b97\u7684\u4f18\u5316\uff0c\u6211\u4eec\u8fdb\u4e00\u6b65\u770b\u5230AlexNet\u6a21\u578b(\u4e00\u79cdCNN)\u7684\u63a8\u7406\u8fc7\u7a0b\u7684\u5404\u4e2a\u5c42\u7684\u8ba1\u7b97\u8d44\u6e90\u6d88\u8017\u5360\u6bd4\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u540d\u4e3aconv[1-5]\u76845\u4e2a\u5377\u79ef\u5c42\u6d88\u8017\u4e8690%\u7684\u8ba1\u7b97\u8d44\u6e90\uff0c\u56e0\u6b64\u4f18\u5316CNN\u63a8\u7406\u7684\u5173\u952e\u5c31\u662f\u4f18\u5316\u5377\u79ef\u5c42\u7684\u8ba1\u7b97\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924453\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u6211\u4eec\u8fdb\u4e00\u6b65\u6765\u770b\u5982\u4f55\u5bf9\u56fe\u50cf\u5e94\u7528\u5377\u79ef\u6838\uff1a<\/p>\n<p>1.\u4f7f\u7528im2col\u6839\u636e\u5377\u79ef\u6838\u5c3a\u5bf8\uff0c\u5c06\u56fe\u50cf\u8f6c\u5316\u4e3a\u82e5\u5e72\u5757(patch)<br \/>2.\u5c06\u591a\u4e2a\u5377\u79ef\u6838\u5c55\u5f00\u6210\u82e5\u5e72\u5411\u91cf<br \/>3.\u5bf9\u7531\u56fe\u50cf\u5757\u7ec4\u6210\u7684\u77e9\u9635\u548c\u7531\u591a\u4e2a\u5377\u79ef\u6838\u5c55\u5f00\u7ec4\u6210\u7684\u77e9\u9635\u5e94\u7528\u77e9\u9635\u4e58\u6cd5<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924454\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u4e0a\u9762\u4e00\u9875\u7684\u8ba1\u7b97\u5e94\u7528\u4e86\u77e9\u9635\u4e58\u6cd5\u64cd\u4f5c\uff0c\u4e3a\u4ec0\u4e48\u6211\u4eec\u4e0d\u91c7\u7528\u66f4\u52a0\u76f4\u63a5\u7684\u8fed\u4ee3\u8ba1\u7b97\u65b9\u5f0f\uff0c\u800c\u662f\u91c7\u7528\u9700\u8981\u989d\u5916\u5185\u5b58\u7684\u77e9\u9635\u4e58\u6cd5\u5462\uff1f\u8fd9\u91cc\u6709\u4e24\u4e2a\u5173\u952e\u56e0\u7d20\uff1a<\/p>\n<ul>\n<li>\u6df1\u5ea6\u5b66\u4e60\u7684\u5377\u79ef\u8ba1\u7b97\u91cf\u5f88\u5927\uff0c\u5178\u578b\u8ba1\u7b97\u9700\u8981\u6d89\u53ca5000\u4e07\u6b21\u4e58\u6cd5\u548c\u52a0\u6cd5\u64cd\u4f5c\uff0c\u56e0\u6b64\u5bf9\u8ba1\u7b97\u7684\u4f18\u5316\u5341\u5206\u91cd\u8981<\/li>\n<li>\u8ba1\u7b97\u673a\u79d1\u5b66\u5bb6\u4eec\u5df2\u7ecf\u6df1\u5165\u63a2\u7d22\u4e86\u77e9\u9635\u4e58\u6cd5\u64cd\u4f5c\uff0c\u77e9\u9635\u4e58\u6cd5\u64cd\u4f5c\u53ef\u4ee5\u88ab\u4f18\u5316\u5f97\u975e\u5e38\u5feb\u3002<\/li>\n<\/ul>\n<p>\u5728fortran\u4e16\u754c\u4e2d\uff0cGEMM(general matrix multiplication)\u5df2\u7ecf\u6210\u4e3a\u4e00\u4e2a\u901a\u7528\u64cd\u4f5c:<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924455\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\">\u8be5\u64cd\u4f5c\u901a\u8fc7\u5bf9\u6570\u636e\u91cd\u65b0\u6392\u5217\uff0c\u7cbe\u5fc3\u8bbe\u8ba1\u8ba1\u7b97\u8fc7\u7a0b\uff0c\u5229\u7528\u591a\u7ebf\u7a0b\u548c\u5411\u91cf\u6307\u4ee4\uff0c\u53ef\u4ee5\u6bd4\u81ea\u5df1\u5b9e\u73b0\u7684\u6734\u7d20\u7248\u672c\u5feb\u5341\u500d\u4ee5\u4e0a\u3002\u56e0\u6b64\u4f7f\u7528\u77e9\u9635\u8fd0\u7b97\u5e26\u6765\u7684\u6536\u76ca\u76f8\u6bd4\u989d\u5916\u7684\u5f00\u9500\u662f\u503c\u5f97\u7684\u3002<\/p>\n<p>\u56e0\u4e3aAI\u63a8\u7406\u5927\u91cf\u4f7f\u7528\u4e86\u77e9\u9635\u4e58\u6cd5\uff0c\u5982\u4eca\u4e5f\u6709\u8bb8\u591a\u786c\u4ef6\u5bf9\u77e9\u9635\u8fd0\u7b97\u8fdb\u884c\u4e86\u52a0\u901f\uff1a<\/p>\n<ul>\n<li>NVIDIA Volta\u67b6\u6784\u5f15\u5165\u4e86tensor core\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u4ee5\u6df7\u5408\u7cbe\u5ea6\u5904\u7406\u77e9\u9635\u4e58<\/li>\n<li>Intel AMX(Advanced Matrix Extensions) \u901a\u8fc7\u8109\u52a8\u9635\u5217\u5728\u786c\u4ef6\u5c42\u9762\u652f\u6301\u77e9\u9635\u4e58<\/li>\n<li>ARM SME(Scalable Matrix Extension) \u652f\u6301\u5411\u91cf\u5916\u79ef\u8fd0\u7b97\uff0c\u52a0\u901f\u77e9\u9635\u4e58<\/li>\n<\/ul>\n<p>\u867d\u7136\u5728AI\u7b97\u529b\u4e0aGPU\u8981\u8fdc\u9ad8\u4e8eCPU\uff0c\u4f46\u662fCPU\u56e0\u4e3a\u5176\u90e8\u7f72\u65b9\u4fbf\uff0c\u4e14\u65e0\u9700\u5728\u4e3b\u673a-\u8bbe\u5907\u95f4\u62f7\u8d1d\u5185\u5b58\uff0c\u5728AI\u63a8\u7406\u573a\u666f\u5360\u6709\u4e00\u5e2d\u4e4b\u5730\u3002\u76ee\u524d\u5e02\u9762\u4e0a\u5c1a\u6ca1\u6709\u53ef\u4ee5\u5927\u89c4\u6a21\u4f7f\u7528\u7684\u652f\u6301AMX\u6216\u8005SME\u7684\u786c\u4ef6\uff0c\u5728\u8fd9\u4e2a\u9636\u6bb5\u6211\u4eec\u5e94\u8be5\u5982\u4f55\u4f18\u5316CPU\u4e0a\u7684AI\u63a8\u7406\u7b97\u529b\u5462\uff1f\u6211\u4eec\u9996\u5148\u8981\u4e86\u89e3BF16\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924456\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>BF16(Brain Float 16)\u662f\u7531Google Brain \u5f00\u53d1\u8bbe\u8ba1\u768416\u4f4d\u6d6e\u70b9\u6570\u683c\u5f0f\u3002\u76f8\u6bd4\u4f20\u7edf\u7684IEEE16\u4f4d\u6d6e\u70b9\u6570\uff0cBF16\u62e5\u6709\u548cIEEE\u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570(FP32)\u4e00\u6837\u7684\u53d6\u503c\u8303\u56f4\uff0c\u4f46\u662f\u7cbe\u5ea6\u8f83\u5dee\u3002\u7814\u7a76\u4eba\u5458\u53d1\u73b0\uff0c\u5728AI\u8bad\u7ec3\u548c\u63a8\u7406\u4e2d\uff0c\u4f7f\u7528BF16\u53ef\u4ee5\u8282\u7ea6\u4e00\u534a\u7684\u5185\u5b58\uff0c\u83b7\u5f97\u548c\u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570\u63a5\u8fd1\u7684\u51c6\u786e\u7387\u3002<\/p>\n<p>\u6839\u636e\u53f3\u56fe\uff0cBF16\u6307\u6570\u7684\u4f4d\u6570\u548cFP32\u662f\u4e00\u81f4\u7684\uff0c\u56e0\u6b64BF16\u548cFP32\u7684\u76f8\u4e92\u8f6c\u6362\u53ea\u8981\u622a\u65ad\u5c3e\u6570\u5373\u53ef\uff0c\u5de6\u4e0b\u89d2\u56fe\u4e0a\u4fbf\u662ftensorflow\u6e90\u7801\u4e2d\u7684\u8f6c\u6362\u5b9e\u73b0\u3002<\/p>\n<p>\u5f15\u5165BF16\u7684\u4e00\u5927\u4ef7\u503c\u662f\u5982\u4eca\u7684\u5f88\u591a\u786c\u4ef6\u8ba1\u7b97\u7684\u74f6\u9888\u5728\u5bc4\u5b58\u5668\u5bbd\u5ea6\u6216\u8005\u8bbf\u95ee\u5185\u5b58\u7684\u901f\u5ea6\u4e0a\uff0c\u66f4\u7d27\u51d1\u7684\u5185\u5b58\u8868\u793a\u5f80\u5f80\u53ef\u4ee5\u83b7\u5f97\u66f4\u9ad8\u7684\u8ba1\u7b97\u541e\u5410\uff0c\u5728\u7406\u60f3\u60c5\u51b5\u4e0b\uff0cBF16\u76f8\u6bd4FP32\u53ef\u4ee5\u63d0\u9ad8\u4e00\u500d\u7684\u541e\u5410(FLOPS)\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924457\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u5982\u4eca\u6211\u4eec\u867d\u7136\u65e0\u6cd5\u5927\u89c4\u6a21\u4f7f\u7528\u5230\u652f\u6301AMX\/SME\u7684\u786c\u4ef6\uff0c\u4f46\u662fArmv8.6-A\u63d0\u4f9b\u4e86bf16\u6269\u5c55\uff0c\u8be5\u6269\u5c55\u5229\u7528\u4e86\u6709\u9650\u7684128bit\u5411\u91cf\u5bc4\u5b58\u5668\uff0c\u901a\u8fc7BFMMLA\u6307\u4ee4\u6267\u884c\u77e9\u9635\u4e58\u6cd5\u8fd0\u7b97\uff1a<\/p>\n<ul>\n<li>\u8f93\u5165A: \u5927\u5c0f\u4e3a2*4\u7684BF16\u77e9\u9635\uff0c\u6309\u884c\u5b58\u50a8<\/li>\n<li>\u8f93\u5165B: \u5927\u5c0f\u4e3a4*2\u7684BF16\u77e9\u9635\uff0c\u6309\u5217\u5b58\u50a8<\/li>\n<li>\u8f93\u51faC: \u5927\u5c0f\u4e3a2*2\u7684FP32\u77e9\u9635\u8be5\u6307\u4ee4<\/li>\n<\/ul>\n<p>\u5355\u6b21\u6267\u884c\u8fdb\u884c\u4e8616\u6b21\u6d6e\u70b9\u6570\u4e58\u6cd5\u548c16\u6b21\u6d6e\u70b9\u6570\u52a0\u6cd5\u8fd0\u7b97\uff0c\u8ba1\u7b97\u541e\u5410\u975e\u5e38\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924458\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u963f\u91cc\u5df4\u5df4\u5411OpenBLAS\u9879\u76ee\u8d21\u732e\u4e86sbgemm(s\u8868\u793a\u8fd4\u56de\u5355\u7cbe\u5ea6\uff0cb\u8868\u793a\u8f93\u5165bf16)\u7684\u786c\u4ef6\u52a0\u901f\u5b9e\u73b0\uff0c\u4eceGEMM\u541e\u5410\u4e0a\u770b\uff0cBF16\u76f8\u6bd4FP32 GEMM\u541e\u5410\u63d0\u5347\u8d85\u8fc7100%\u3002<\/p>\n<p>\u501a\u5929ECS\u5b9e\u4f8b\u662f\u5e02\u9762\u4e0a\u5c11\u6570\u53ef\u4ee5\u652f\u6301bf16\u6307\u4ee4\u6269\u5c55\u7684ARM\u670d\u52a1\u5668\u3002\u76ee\u524d\u5df2\u7ecf\u652f\u6301\u4e86Tensorflow\u548cPytorch\u4e24\u79cd\u6846\u67b6\u7684AI\u63a8\u7406<\/p>\n<ul>\n<li>Tensorflow\u4e0b\u53ef\u4ee5\u901a\u8fc7OneDNN + ACL(Arm Compute Library)\u6765\u4f7f\u7528BFMMLA\u52a0<\/li>\n<li>Pytorch\u5df2\u7ecf\u652f\u6301\u4e86OneDNN + ACL\uff0c\u4f46\u662f\u76ee\u524d\u8fd8\u5728\u8bd5\u9a8c\u72b6\u6001\uff0c\u65e0\u6cd5\u5f88\u597d\u5730\u53d1\u6325\u6027\u80fd\u3002\u4f46\u662fPytorch\u540c\u65f6\u652f\u6301OpenBLAS\u4f5c\u4e3a\u5176\u8ba1\u7b97\u540e\u7aef\uff0c\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7OpenBLAS\u6765\u4eab\u53d7ARM bf16\u6269\u5c55\u5e26\u6765\u7684\u6027\u80fd\u6536\u76ca<\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924459\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u76f8\u6bd4\u9ed8\u8ba4\u7684eigen\u5b9e\u73b0\uff0c\u5f00\u542fOneDNN + ACL\u540e\uff0cperf\u83b7\u5f97\u7684\u8ba1\u7b97\u70ed\u70b9\u5df2\u7ecf\u4ecefmla(\u5411\u91cf\u4e58\u52a0)\u8f6c\u6362\u5230\u4e86bfmmla\uff0c\u7b97\u529b\u663e\u8457\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924460\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u4eceworkload\u89d2\u5ea6\u8bc4\u6d4b\uff0c\u4e0a\u56fe\u5bf9\u6bd4\u4e86\u4e24\u79cd\u673a\u578b:<\/p>\n<ul>\n<li>g7\uff1aIntel IceLake\u5b9e\u4f8b<\/li>\n<li>g8m\uff1a\u501a\u5929ARM\u670d\u52a1\u5668<\/li>\n<\/ul>\n<p>\u5de6\u8fb9\u67f1\u72b6\u56fe\u4e2d\u84dd\u8272\u67f1\u5b50\u8868\u793a\u7b97\u529b\u5bf9\u6bd4\uff0c\u6a59\u8272\u67f1\u5b50\u8868\u793a\u8003\u8651\u6027\u4ef7\u6bd4\u540e\u4f7f\u7528\u501a\u5929\u5904\u7406\u5668\u83b7\u5f97\u7684\u6536\u76ca\u3002\u53ef\u4ee5\u770b\u5230\u5728Resnet50\u548cBERT-Large\u6a21\u578b\u7684\u63a8\u7406\u573a\u666f\u4e0b\uff0c\u8f6f\u4ef6\u4f18\u5316\u540e\u7684\u501a\u5929\u5904\u7406\u5668\u7686\u53ef\u83b7\u5f97\u4e00\u500d\u5de6\u53f3\u7684\u6027\u4ef7\u6bd4\u6536\u76ca\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924461\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u5728\u4e0a\u6587\u4e2d\uff0c\u6211\u4eec\u770b\u5230\u4f7f\u7528\u501a\u5929\u5904\u7406\u5668\u82e5\u60f3\u83b7\u5f97\u8f83\u9ad8\u6536\u76ca\uff0c\u8f6f\u4ef6\u7248\u672c\u7684\u9009\u62e9\u5341\u5206\u91cd\u8981\u3002\u968f\u610f\u9009\u62e9tensorflow\u6216\u8005pytorch\u5305\u53ef\u80fd\u906d\u9047\uff1a<\/p>\n<ul>\n<li>\u672a\u9002\u914darm\u67b6\u6784\uff0c\u5b89\u88c5\u5931\u8d25<\/li>\n<li>\u8f6f\u4ef6\u672a\u9002\u914dbf16\u6269\u5c55\u6216\u8005\u73af\u5883\u53c2\u6570\u6709\u8bef\uff0c\u65e0\u6cd5\u53d1\u6325\u786c\u4ef6\u7684\u5168\u90e8\u7b97\u529b\uff0c\u6027\u80fd\u6253\u6298<\/li>\n<li>\u9700\u8981\u7cbe\u5fc3\u9009\u62e9\u8ba1\u7b97\u540e\u7aef\uff0c\u4f8b\u5982\u76ee\u524dpytorch\u4e0bOpenBLAS\u8f83\u5feb<\/li>\n<\/ul>\n<p>\u56e0\u6b64\u6211\u4eec\u63d0\u4f9b\u4e86Docker\u955c\u50cf\uff0c\u5e2e\u52a9\u4e91\u4e0a\u7684\u7528\u6237\u5145\u5206\u4f7f\u7528\u501a\u5929ECS\u5b9e\u4f8b\u7684AI\u63a8\u7406\u6027\u80fd\uff1a<\/p>\n<ul>\n<li>accc-registry.cn-hangzhou.cr.aliyuncs.com\/tensorflow\/tensorflow<\/li>\n<li>accc-registry.cn-hangzhou.cr.aliyuncs.com\/pytorch\/pytorch<\/li>\n<\/ul>\n<h3>\u901a\u8fc7Serverless\u80fd\u529b\u5145\u5206\u91ca\u653e<\/h3>\n<p>\u7b97\u529b\u9664\u4e86\u4f7f\u80fd\u66f4\u591a\u7684\u786c\u4ef6\u6307\u4ee4\uff0c\u53e6\u4e00\u79cd\u5145\u5206\u91ca\u653e\u786c\u4ef6\u7b97\u529b\u7684\u65b9\u5f0f\u5c31\u662f\u901a\u8fc7Serverless\u67b6\u6784\u63d0\u9ad8CPU\u5229\u7528\u7387\u3002Python\u4f5c\u4e3a\u52a8\u6001\u8bed\u8a00\uff0c\u5176\u6a21\u5757\u662f\u52a8\u6001\u5bfc\u5165\u7684\uff0c\u56e0\u6b64\u542f\u52a8\u901f\u5ea6\u4e0d\u662fPython\u7684\u5f3a\u9879\uff0c\u8fd9\u4e5f\u5236\u7ea6\u4e86Python workload\u5728Serverless\u573a\u666f\u7684\u666e\u53ca\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924462\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>Python\u5e94\u7528\u542f\u52a8\u7684\u4e3b\u8981\u8017\u65f6\u5728\u6a21\u5757\u5bfc\u5165\uff0cPython\u6a21\u5757\u5bfc\u5165\u6b65\u9aa4\u4e3a:<\/p>\n<ol>\n<li>\u5bfb\u627e\u5230\u6a21\u5757\u6240\u5728\u7684\u6587\u4ef6<\/li>\n<li>\u83b7\u5f97\u4ee3\u7801\u5bf9\u8c61code_object<\/li>\n<li>\u6267\u884c\u4ee3\u7801\u5bf9\u8c61<\/li>\n<\/ol>\n<p>\u5176\u4e2d\u7684\u7b2c\u4e8c\u6b65\u5728\u9996\u6b21\u52a0\u8f7d\u6a21\u5757\u65f6\uff0c\u8981\u5bf9.py\u6587\u4ef6\u8fdb\u884c\u7f16\u8bd1\uff0c\u83b7\u5f97code_object, \u4e3a\u4e86\u964d\u4f4e\u5c06\u6765\u52a0\u8f7d\u7684\u5f00\u9500\uff0cPython\u89e3\u91ca\u5668\u4f1a\u5e8f\u5217\u5316\u5e76\u7f13\u5b58code_object\u5230.pyc\u6587\u4ef6\u3002<\/p>\n<p>\u5373\u4fbf\u6a21\u5757\u5bfc\u5165\u8fc7\u7a0b\u5df2\u7ecf\u901a\u8fc7\u7f13\u5b58\u673a\u5236\u4f18\u5316\u8fc7\u4e86\uff0c\u4f46\u662f\u8bfb\u53d6.pyc\u6587\u4ef6\u5e76\u53cd\u5e8f\u5217\u5316\u4f9d\u65e7\u6bd4\u8f83\u8017\u65f6\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924463\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u5728\u8fd9\u91cc\u6211\u4eec\u501f\u52a9\u4e86OpenJDK\u7684AppCDS\u7684\u601d\u8def\uff1a\u5c06heap\u4e0a\u7684code_object\u590d\u5236\u5230\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u4e2d(mmap)\u3002\u5728\u4e0b\u6b21\u52a0\u8f7d\u6a21\u5757\u65f6\uff0c\u76f4\u63a5\u4f7f\u7528mmap\u4e2d\u7684code_object\u3002<\/p>\n<p>\u8fd9\u79cd\u6846\u67b6\u4e0b\u6709\u4e24\u4e2a\u96be\u70b9:<\/p>\n<ul>\n<li>Python\u7684code_object\u662f\u6563\u843d\u5728heap\u7684\u5404\u5904\u4e14\u4e0d\u8fde\u7eed\u7684\uff0c\u56e0\u6b64mmap\u590d\u5236\u6574\u4e2aheap\u662f\u884c\u4e0d\u901a\u7684\u3002\u6211\u4eec\u91c7\u7528\u7684\u65b9\u5f0f\u662f\u4ee5code_object\u4e3a\u6839\uff0c\u904d\u5386\u5bf9\u8c61\u56fe\uff0c\u5bf9\u611f\u5174\u8da3\u7684\u5185\u5bb9\u590d\u5236\u5e76\u7d27\u51d1\u6392\u5e03<\/li>\n<li>Python\u7684code_object\u4f1a\u5f15\u7528.data\u6bb5\u7684\u53d8\u91cf\uff0c\u5728Linux\u7684\u968f\u673a\u5730\u5740\u5b89\u5168\u673a\u5236\u4e0b\uff0c.data\u6bb5\u7684\u6570\u636e\u7684\u5730\u5740\u5728\u6bcf\u6b21\u8fd0\u884c\u65f6\u90fd\u4f1a\u968f\u673a\u53d8\u5316\uff0c\u8fd9\u6837mmap\u4e2d\u7684\u6307\u9488\u5c31\u5931\u6548\u4e86\u3002\u6211\u4eec\u7684\u89e3\u51b3\u65b9\u5f0f\u662f\u904d\u5386\u6240\u6709\u5bf9\u8c61\uff0c\u9488\u5bf9.data\u6bb5\u7684\u6307\u9488\u8fdb\u884c\u504f\u79fb\u91cf\u4fee\u590d<\/li>\n<\/ul>\n<p>\u56e0\u4e3a\u8be5\u9879\u76ee\u5171\u4eab\u4e86python\u7684code_object\uff0c\u56e0\u6b64\u540d\u5b57\u662fcode-data-share-for-python\uff0c\u7b80\u79f0pycds\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042924464\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u6211\u4eec\u6d4b\u8bd5\u4e86bota3\u3001numpy\u3001flask\u7b49\u5e38\u7528\u7684python\u82e6\uff0c\u5e73\u5747\u53ef\u4ee5\u8282\u770120%\u7684\u6a21\u5757\u5bfc\u5165\u8017\u65f6\u3002<\/p>\n<p>\u5bf9\u4e8e\u73b0\u6709\u7684python\u5e94\u7528\u53ef\u4ee5\u8f7b\u6613\u5730\u4f7f\u7528pycds\uff0c\u4e14\u65e0\u9700\u4fee\u6539\u4efb\u4f55\u4ee3\u7801\uff1a<\/p>\n<pre><code># \u5b89\u88c5pycds\npip install code-data-share # \u5b89\u88c5pycds\n # \u751f\u6210\u6a21\u5757\u5217\u8868\nPYCDSMODE=TRACE PYCDSLIST=mod.lst python -c 'import numpy\u2019\n# \u751f\u6210 archive\npython -c 'import cds.dump; cds.dump.run_dump(&quot;mod.lst&quot;, &quot;mod.img&quot;)\u2019\n# \u4f7f\u7528archive\ntime PYCDSMODE=SHARE PYCDSARCHIVE=mod.img python -c 'import numpy'\nreal 0m0.090s\nuser 0m0.180s\nsys 0m0.339s\n# \u5bf9\u6bd4\u57fa\u7ebf\ntime python -c 'import numpy'\nreal 0m0.105s\nuser 0m0.216s\nsys 0m0.476s<\/code><\/pre>\n<p>\u6211\u4eec\u4ec5\u4ec5\u901a\u8fc7\u5b89\u88c5PyPI\uff0c\u4fee\u6539\u73af\u5883\u53d8\u91cf\u8fd0\u884c\u548c\u4f7f\u7528cdsAPI\u505adump\u5373\u53ef\u5bf9\u73b0\u6709\u7684\u5e94\u7528\u542f\u52a8\u8fdb\u884c\u52a0\u901f\u4e86\u3002<\/p>\n<p>code-data-share-for-python\u662f\u4e00\u4e2a\u65b0\u9879\u76ee\uff0c\u9700\u8981\u5927\u5bb6\u7684\u53c2\u4e0e\u548c\u53cd\u9988\uff0c\u6b22\u8fce\u901a\u8fc7\u4ee5\u4e0b\u94fe\u63a5\u4e86\u89e3\u548c\u4f7f\u7528:<\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=%2Fnd%2Be%2F%2BdMGRh1X7XD7Qa1g%3D%3D.obc7tNcY7LuOPgx9S06CEUCZ0qUjXMql1xF%2B%2F1EacePhifVRFluwoWiA9T80oKAdVMylQ8dDTOnWqfuqu2PF7A%3D%3D\" rel=\"nofollow\">https:\/\/github.com\/alibaba\/code-data-share-for-python<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=EzUsxOemar16%2Bv%2BbUmEFVg%3D%3D.IXD6NwEolqucSnnY3k4RsjWa6YeQmRLzwke6%2Fy6h12VOjAT5swK8NYyDZJcT1OsqBWPP89PN9RFUdIBuYxXE5Q%3D%3D\" rel=\"nofollow\">https:\/\/pypi.org\/project\/code-data-share-for-python<\/a><\/li>\n<\/ul>\n<p><strong>ARM \u67b6\u6784 SIG\u94fe\u63a5\u5730\u5740\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=TUJfXYR5f4owl5my02QdDg%3D%3D.rp2gdirxskISrG1YnXbH0XO99oc%2BlQ%2B1c%2BAbDyTC8WQ8Lvi6HBr8w33V2pet1%2F2%2F\" rel=\"nofollow\">https:\/\/openanolis.cn\/sig\/ARM_ARCH_SIG<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/link.segmentfault.com\/?enc=wkwKzrrGkP8djaxyNh9eJQ%3D%3D.DTF54kCBPchoSZFTSVY2rmJWXKAQJMEXWCjBrTwgNqQ3eWO8i5i3ZQ0pcHCEyE60\" rel=\"nofollow\">\u539f\u6587\u94fe\u63a5<\/a><\/strong><\/p>\n<p><strong>\u672c\u6587\u4e3a\u963f\u91cc\u4e91\u539f\u521b\u5185\u5bb9\uff0c\u672a\u7ecf\u5141\u8bb8\u4e0d\u5f97\u8f6c\u8f7d\u3002<\/strong><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042924450\">https:\/\/segmentfault.com\/a\/1190000042924450<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5ea6\u5b66\u4e60\u6280\u672f\u5728\u56fe\u50cf\u8bc6\u522b\u3001\u641c\u7d22\u63a8\u8350\u7b49\u9886\u57df\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\u3002\u8fd1\u5e74\u6765\u5404\u5927 CPU \u5382\u5546\u4e5f\u9010\u6e10\u628a AI \u7b97\u529b\u7eb3\u5165\u4e86\u91cd\u70b9\u53d1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10006932","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006932"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006932\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}