{"id":340,"date":"2022-03-12T18:46:26","date_gmt":"2022-03-12T10:46:26","guid":{"rendered":"https:\/\/blog.simbot.net\/?p=340"},"modified":"2022-03-21T14:33:01","modified_gmt":"2022-03-21T06:33:01","slug":"the-fastest-knn-search-algorithm","status":"publish","type":"post","link":"https:\/\/blog.simbot.net\/2022\/03\/12\/the-fastest-knn-search-algorithm\/","title":{"rendered":"\u53f2\u4e0a\u6700\u5feb\u7684knn\u641c\u7d22\u7b97\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"\n

\u00a0 \u00a0 \u00a0 \u00a0 \u4f5c\u8005\uff1ahws000\uff08hws.000#163.com\uff09
\u00a0 \u00a0 \u00a0 \u00a0 \u58f0\u660e\uff1a\u7248\u6743\u6240\u6709\uff0c\u8f6c\u8f7d\u8bf7\u8054\u7cfb\u4f5c\u8005\u3002
\u00a0 \u00a0 \u00a0 \u00a0 \u51fa\u5904\uff1ahttps:\/\/blog.simbot.net\/2022\/03\/12\/the-fastest-knn-search-algorithm\/<\/a><\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u521b\u65b0\u65b9\u6cd5\u5e94\u7528\u4e8eknn\uff08k nearest neighbor\uff09\u641c\u7d22\uff0cGPU\u52a0\u901f\u6548\u679c\u975e\u5e38\u60ca\u8273\uff0c\u786c\u4ef6\u7684\u5229\u7528\u7387\u8fbe\u523090%\u4ee5\u4e0a\uff0c\u8fd9\u6548\u679c\u82f1\u4f1f\u8fbe\u90fd\u505a\u4e0d\u5230\u3002\u524d\u65e0\u53e4\u4eba\uff0c\u540e\u65e0\u6765\u8005\uff01<\/p>\n

1.\u641c\u7d22\u901f\u5ea6\u5bf9\u6bd4\u3002<\/h3>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u6d4b\u8bd5\u5e73\u53f0RTX 2080ti\uff0c\u4f7f\u7528TensorCore\uff0c\u8f93\u5165\u8f93\u51fa\u5747\u4e3ahalf\uff08\u534a\u7cbe\u5ea6FP16\uff09\u65f6\uff0c\u7406\u8bba\u7b97\u529b107TFLOPS\uff1b\u8f93\u5165\u4e3aint8\uff088\u4f4d\u6574\u6570\uff09\uff0c\u8f93\u51fa\u4e3aint\u65f6\uff0c\u7406\u8bba\u7b97\u529b214TOPS\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u6570\u636e\u5e93\u5927\u5c0f\u4e3a200\u4e07\uff0c\u641c\u7d22\u65b9\u5f0f\u4e3a\u66b4\u529b\u641c\u7d22\uff0c\u7ed3\u679c\u53d6Top1\uff0c\u8ddd\u79bb\u8ba1\u7b97\u65b9\u5f0f\u4e3a\u5185\u79ef\uff08\u7b49\u540c\u4e8e\u77e9\u9635\u4e58\uff09\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u7b97\u529b=\u8ba1\u7b97\u91cf\/\u8017\u65f6\uff0c\u8ba1\u7b97\u91cf=MxNxKx2\u3002
\u00a0 \u00a0 \u00a0 \u00a0 knn\u641c\u7d22\u8017\u65f6\u5305\u542b\u6392\u5e8f\u7684\u65f6\u95f4\uff0c\u4f46\u6ca1\u6709\u5305\u542b\u6392\u5e8f\u7684\u8ba1\u7b97\u91cf\u3002<\/p>\n

\"\"<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u521b\u65b0\u65b9\u6cd5New IP\uff08\u8f93\u51fahalf\uff09\uff1b
\u00a0 \u00a0 \u00a0 \u00a0 \u77e9\u9635\u8ba1\u7b97\u51fd\u6570cublasHgemm\uff08\u8f93\u51fahalf\uff09\uff1b
\u00a0 \u00a0 \u00a0 \u00a0 \u77e9\u9635\u8ba1\u7b97\u51fd\u6570cublasSgemmEx\uff08\u8f93\u51fafloat\uff09\uff1b
\u00a0 \u00a0 \u00a0 \u00a0 \u73b0\u6709\u5f00\u6e90\u65b9\u6cd5Faiss IP\uff08\u4f7f\u7528cublasSgemmEx\u51fd\u6570\uff0c\u8f93\u51fafloat\uff09\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u8f93\u5165\u6570\u636e\u7c7b\u578b\u5747\u4e3ahalf \uff0c\u8f93\u51fahalf\u6216float\uff0c\u5728\u4e0d\u540c\u7ef4\u5ea6\u65f6\u7684\u7b97\u529b\u3002<\/p>\n

\"\"<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u521b\u65b0\u65b9\u6cd5\u3001\u77e9\u9635\u8ba1\u7b97\u51fd\u6570cublasGemmEx\uff0c\u8f93\u5165\u4e3aint8\uff0c\u8f93\u51fa\u4e3aint\uff0c\u5728\u4e0d\u540c\u7ef4\u5ea6\u65f6\u7684\u7b97\u529b\u3002<\/p>\n

\"\"<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u521b\u65b0\u65b9\u6cd5\u3001faiss\uff0c\u5728\u4e0d\u540c\u6570\u636e\u5e93\u5927\u5c0f\uff0cTopK\u53d61\u30012\u30014…1024\u65f6\u7684\u641c\u7d22\u6548\u7387\u3002
\u00a0 \u00a0 \u00a0 \u00a0 \u521b\u65b0\u65b9\u6cd5\u5728\u6570\u636e\u5e93\u8d8a\u5927\u65f6\u641c\u7d22\u6548\u7387\u8d8a\u9ad8\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u4e0b\u8868\u4e3a\u4e0d\u540c\u7ef4\u5ea6\u65f6\uff0c\u521b\u65b0\u65b9\u6cd5\u76f8\u5bf9faiss\u7684\u7b97\u529b\u500d\u6570\u3002
\u00a0 \u00a0 \u00a0 \u00a0 knn\u641c\u7d22\u7684\u6570\u636e\u7ef4\u5ea6\u4e00\u822c\u5728128\uff5e512\u4e4b\u95f4\uff0c128\u7ef4\u65f6\u662f5.83\u500d\uff0c512\u7ef4\u65f6\u662f2.07\u500d\u3002<\/p>\n

\"\"<\/p>\n

2.\u7b97\u6cd5\u4ecb\u7ecd<\/h3>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u7b97\u6cd5\u7684\u5185\u5bb9\u5f88\u7b80\u5355\uff0c\u4e3b\u8981\u5305\u542b\u8ddd\u79bb\u8ba1\u7b97\u548c\u6392\u5e8f\u4e24\u90e8\u5206\u3002
\u00a0 \u00a0 \u00a0 \u00a0 \u81ea\u5df1\u5b9e\u73b0\u8ddd\u79bb\u8ba1\u7b97\u51fd\u6570\uff0c\u8ba1\u7b97\u51fa\u8ddd\u79bb\u540e\u7acb\u5373\u8fc7\u6ee4\uff0c\u53ea\u5c06\u7b26\u5408\u8fc7\u6ee4\u6761\u4ef6\u7684\u7ed3\u679c\u5199\u5165\u663e\u5b58\uff0c\u7ed3\u679c\u8fbe\u5230\u4e00\u5b9a\u6570\u91cf\u540e\u518d\u6392\u5e8f\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u8ddd\u79bb\u8ba1\u7b97\u51fd\u6570\u6709\u591a\u4e2a\u4f18\u5316\u70b9\uff0c\u8fc7\u6ee4\u662f\u6700\u6838\u5fc3\u7684\u4e00\u4e2a\uff0c\u53ea\u5199\u8fc7\u6ee4\u540e\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u5199\u5165\u5e26\u5bbd\uff0c\u540c\u65f6\u51cf\u5c11\u6392\u5e8f\u51fd\u6570\u7684\u8bfb\u53d6\u5e26\u5bbd\uff0c\u95f4\u63a5\u51cf\u5c11\u6392\u5e8f\u51fd\u6570\u7684\u8c03\u7528\u6b21\u6570\u3002
\u00a0 \u00a0 \u00a0 \u00a0 \u4f4e\u7ef4\u7684\u8ddd\u79bb\u8ba1\u7b97\u51fd\u6570\u4e5f\u53ef\u4ee5\u5355\u72ec\u5b9e\u73b0\uff0c\u7531\u4e8e\u7ef4\u5ea6\u4f4e\u6570\u636e\u91cf\u5c0f\uff0c\u67e5\u8be2\u6570\u636e\u53ef\u4ee5\u5e38\u9a7b\u5bc4\u5b58\u5668\uff0c\u8ba1\u7b97\u8fc7\u7a0b\u4e2d\u53ea\u9700\u8fde\u7eed\u52a0\u8f7d\u6570\u636e\u5e93\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u63d0\u5347\u6570\u636e\u52a0\u8f7d\u6548\u7387\u3002
\u00a0 \u00a0 \u00a0 \u00a0 \u6bd4\u8f83\u7d27\u51d1\u7684\u8fc7\u6ee4\u8bed\u53e5\u4e5f\u53ef\u4ee5\u63d0\u9ad8\u6267\u884c\u6548\u7387\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u6392\u5e8f\u90e8\u5206\u53ea\u662f\u7b80\u5355\u4f7f\u7528\u4e86\u53cc\u8c03\u6392\u5e8f\uff0c\u8fd8\u81f3\u5c11\u67092-3\u500d\u7684\u4f18\u5316\u7a7a\u95f4\u3002<\/p>\n

<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u4e0a\u56fe\u662f\u641c\u7d22\u7b97\u6cd5\u7684\u4e00\u5f20\u6267\u884c\u622a\u56fe\uff0c\u6570\u636e\u5e93\u5927\u5c0f200\u4e07\uff0c\u6570\u636e\u7c7b\u578bhalf\uff0cTopK\u4e3a128\uff0c\u5faa\u73af13\u6b21\u7ed3\u675f\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u7b2c\u4e00\u4e2a\u7ea2\u6846\u662f\u8ddd\u79bb\u8ba1\u7b97\u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\uff08\u5355\u4f4dms\uff09\u548c\u7b97\u529b\uff1b
\u00a0 \u00a0 \u00a0 \u00a0 \u7b2c\u4e8c\u4e2a\u7ea2\u6846\u662f\u7ed3\u679c\u5904\u7406\u548c\u6392\u5e8f\u7684\u8017\u65f6\uff1b
\u00a0 \u00a0 \u00a0 \u00a0 \u7b2c\u4e09\u4e2a\u7ea2\u6846\u662f\u5f53\u6b21\u5faa\u73af\u7684\u6570\u636e\u91cf\uff1b
\u00a0 \u00a0 \u00a0 \u00a0 \u7b2c\u56db\u4e2a\u7ea2\u6846\u662f\u8fc7\u6ee4\u7ed3\u679c\u6570\u7684\u7edf\u8ba1\u4fe1\u606f\uff0c\u5206\u522b\u4e3a\u5e73\u5747\u503c\u3001\u5e73\u65b9\u548c\u7684\u5e73\u5747\u503c\u3001\u6700\u5927\u503c\u3001\u6700\u5c0f\u503c\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u6bcf\u4e2a\u5faa\u73af\u5904\u7406\u7684\u6570\u636e\u91cf\u5747\u6bd4\u4e0a\u6b21\u7ffb\u500d\uff0c\u4f46\u7ed3\u679c\u6570\u51e0\u4e4e\u4e0d\u53d8\u3002\u56e0\u6b64\u82e5\u603b\u6570\u636e\u91cf\u7ffb1\u500d\uff0c\u5faa\u73af\u6b21\u6570\u52a01\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u7ea2\u6846\u4e2d\u663e\u793a\u7684\u662f\u8ddd\u79bb\u8ba1\u7b97\u51fd\u6570\u7684\u7b97\u529b\uff0c\u4e0d\u5305\u62ec\u6392\u5e8f\u90e8\u5206\uff0c\u56e0\u6b64\u6bd4\u6700\u7ec8\u7684\u7edf\u8ba1\u503c\u9ad8\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u4e00\u6b21\u5b8c\u6574\u67e5\u8be2\u8017\u65f6258ms\uff0c\u8c03\u6574\u53c2\u6570\u51cf\u5c0f\u67e5\u8be2\u91cf\u540e\uff0c\u53ef\u4ee5\u5c06\u8017\u65f6\u7f29\u77ed\u523010ms\u4ee5\u5185\u3002<\/p>\n

3.\u7ed3\u8bed<\/h3>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u65b0\u7b97\u6cd5\u901a\u8fc7\u4e13\u95e8\u9488\u5bf9\u5411\u91cf\u8ba1\u7b97\u8fdb\u884c\u4f18\u5316\uff0c\u5c06\u786c\u4ef6\u7684\u5229\u7528\u7387\u63d0\u5347\u523090%\u4ee5\u4e0a\uff0c\u5c24\u5176\u5728\u5e38\u7528\u7684128\uff5e512\u7ef4\u5ea6\u533a\u95f4\uff0c\u8868\u73b0\u6548\u679c\u6bd4\u4f20\u7edf\u65b9\u6cd5\u66f4\u597d\u3002\u65b0\u7b97\u6cd5\u7684\u74f6\u9888\u5728\u786c\u4ef6\u80fd\u529b\uff0c\u5806\u66f4\u591a\u7684\u786c\u4ef6\u53ef\u4ee5\u6709\u66f4\u9ad8\u7684\u7b97\u529b\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 knn\u7b97\u6cd5\u662f\u7cbe\u786e\u641c\u7d22\uff0c\u53ef\u4ee5\u5e94\u7528\u4e8e\u4eba\u8138\u8bc6\u522b\u7b49\u573a\u666f\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u6784\u5efa\u56fe\u7d22\u5f15\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u65b0\u7b97\u6cd5\u7406\u8bba\u4e0a\u4e5f\u53ef\u4ee5\u5728\u4e13\u4e1a\u7684\u77e9\u9635\u52a0\u901f\u5361\u4e0a\u6267\u884c\u3002<\/p>\n

\u00a0 \u00a0 \u00a0 \u00a0 \u672c\u7b97\u6cd5\u53d7\u4e13\u5229\u4fdd\u62a4\uff0c\u4e13\u5229\u53f7\uff1aCN114003630A\u3002\u6b22\u8fce\u6709\u9700\u8981\u7684\u9700\u6c42\u65b9\u5408\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u521b\u65b0\u65b9\u6cd5\u5e94\u7528\u4e8eknn\uff08k nearest neighbor\uff09\u641c\u7d22\uff0cGPU\u52a0\u901f\u6548\u679c\u975e\u5e38\u60ca\u8273\uff0c\u786c\u4ef6\u7684\u5229\u7528\u7387\u8fbe\u523090%\u4ee5\u4e0a\uff0c\u8fd9\u6548\u679c\u82f1\u4f1f\u8fbe\u90fd\u505a\u4e0d\u5230\u3002\u524d\u65e0\u53e4\u4eba\uff0c\u540e\u65e0\u6765\u8005\uff01<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[36,39,37,35,34],"_links":{"self":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts\/340"}],"collection":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":9,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":391,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts\/340\/revisions\/391"}],"wp:attachment":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}