diff --git a/IndexSDK/README.md b/IndexSDK/README.md index 14c8f57f83ecd40f9a682b27389f3325ae5a6092..442e4edd604e2f36f87ac7bb4495edcbfa119e98 100644 --- a/IndexSDK/README.md +++ b/IndexSDK/README.md @@ -1,26 +1,22 @@ # Index SDK-test -#### 介绍 +### 介绍 **本仓库提供了昇腾Index SDK 组件实现的几种常见检索算法的demo** #### 版本配套表 | MindSDK版本 | Index SDK版本 | CANN版本 | HDK版本 | 硬件形态 | | -------------- | ------------ | -------- | -------- | --------- | -| master | 6.0.RC3 | 8.0.RC3 | 24.1.RC2 | Atlas推理系列产品 Atlas200/300/500 800I A2推理产品 | - -之前版本请参见:https://gitee.com/ascend/ascend-referenceapps/tree/master/IndexSDK_samples +| master | 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | Atlas推理系列产品 Atlas200/300/500 800I A2推理产品 | master分支对应版本mxIndex 6.0.RC2、mxIndex 6.0.RC1,依赖faiss版本为1.7.4 -mxIndex-faiss1.7.1分支对应版本mxIndex 5.0.0、mxIndex 5.0.1,依赖faiss版本为1.7.1 - #### 关于MindSDK 更多信息 请关注昇腾社区[MindSDK](https://www.hiascend.com/zh/software/mindx-sdk)的最新版本 -#### 安装教程 +### 安装教程 -1. Index SDK [安装文档](https://www.hiascend.com/document/detail/zh/mind-sdk/50rc1/featureretrieval/mxindexfrug/mxindexfrug_0001.html) +1. Index SDK [用户指南](https://www.hiascend.com/document/detail/zh/mindsdk/600/index/indexug/mxindexfrug_0007.html) 2. gtest安装教程 ``` shell wget https://github.com/google/googletest/archive/refs/tags/release-1.8.1.tar.gz && \ @@ -29,29 +25,48 @@ cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/local/gtest . && make - cd .. && rm -rf release-1.8.1.tar.gz googletest-release-1.8.1 ``` -#### 测试用例说明 -| 用例名称 | 用例说明 | -| ---------- | ------------------------------------------- | -| TestAscendIndexFlat | FP32转FP16 暴搜demo | -| TestAscendIndexInt8Flat | 底库数据为int8 暴搜demo | -| TestAscendIndexInt8FlatWithSQ | FP32 SQ 量化为 int8 后, 暴搜demo | -| TestAscendIndexSQ | FP32 SQ 量化为Int8后,反量化暴搜demo | -| TestAscendIndexBinaryFlat | 二值化底库特征汉明距离暴搜demo | -| TestAscendIndexTS | 时空库,hamming距离,带属性过滤demo | -| TestAscendIndexTS_int8Cos | 时空库,int8 cos距离,带属性过滤demo | -| TestAscendIndexIVFSQ.cpp | IVFSQ 算法demo | -| TestAscendIndexAggressTs.cpp | 时空库 IP距离,带属性过滤 支持组batch demo | -| TestAscendIReduction.cpp | 降维算法 NN降维 Pcar降维 demo | -| TestAscendIndexCluster.cpp | FP32 聚类场景 暴搜demo | -| TestAscendIndexIVFSP.cpp | IVFSP近似检索算法demo | -| TestAscendIndexIVFSQT.cpp | IVFSQT近似检索算法demo | -| TestAscendIndexIVFSQTwithCpuFlat.cpp | IVFSQT粗搜加cpu精搜demo | -| TestAscendIndexInt8FlatWithCPU.cpp | 底库数据为int8 CPU同步落盘 demo | -| TestAscendIndexInt8FlatWithReduction.cpp | FP32 降维量化为Int8后,暴搜demo | -| TestAscendMultiSearch.cpp | 多Index批量检索demo | -| TestAscendIndexSQMulPerformance.cpp | 布控库 SQ IP距离 demo | -| TestAscendIndexGreat.cpp | great近似检索算法demo | -| TestAscendIndexVStar.cpp | vstar近似检索算法demo | +### 代码目录结构说明 + +``` +. +|-- CMakeLists.txt +|-- Dockerfile +| |-- Dockerfile-ascend-toolkit.txt # 昇腾镜像文件 +| |-- Dockerfile-ascendbase-infer.txt # 基础镜像文件 +| `-- install_deps.sh # 依赖下载安装脚本 +|-- README.md +|-- TestAscendIReduction.cpp # 降维算法 NN降维 Pcar降维 demo +|-- TestAscendIndexAggressTs.cpp # 时空库 IP距离,带属性过滤 支持组batch demo +|-- TestAscendIndexBinaryFlat.cpp # 二值化底库特征汉明距离 BinaryFlat算法demo +|-- TestAscendIndexCluster.cpp # FP32 聚类场景 AscendCluster算法demo +|-- TestAscendIndexFlat.cpp # FP32转FP16 Flat算法暴搜demo +|-- TestAscendIndexGreat.cpp # Great近似检索算法demo +|-- TestAscendIndexIVFSP.cpp # IVFSP近似检索算法demo +|-- TestAscendIndexIVFSQ.cpp # IVFSQ 近似检索算法demo +|-- TestAscendIndexIVFSQT.cpp # IVFSQT近似检索算法demo +|-- TestAscendIndexIVFSQTwithCpuFlat.cpp # IVFSQT粗搜加cpu精搜demo +|-- TestAscendIndexInt8Flat.cpp # 底库数据为int8 int8Flat算法暴搜demo +|-- TestAscendIndexInt8FlatWithCPU.cpp # 底库数据为int8 int8Flat算法CPU同步落盘 demo +|-- TestAscendIndexInt8FlatWithReduction.cpp # FP32 降维量化为Int8后,int8Flat算法暴搜demo +|-- TestAscendIndexInt8FlatWithSQ.cpp # FP32 SQ 量化为 int8后, 暴搜demo +|-- TestAscendIndexSQ.cpp # FP32 SQ 量化为Int8后,反量化SQ算法暴搜demo +|-- TestAscendIndexSQMulPerformance.cpp # 布控库 IP距离 SQ算法demo +|-- TestAscendIndexTS.cpp # 时空库,汉明距离,带属性过滤demo +|-- TestAscendIndexTS_int8Cos.cpp # 时空库,int8 cos距离,带属性过滤demo +|-- TestAscendIndexVStar.cpp # VStar近似检索算法demo +|-- TestAscendMultiSearch.cpp # 多Index批量检索demo +|-- build.sh # 编译安装脚本 +|-- dependencies.cmake +`-- faiss-python # python接口 + |-- Faiss安装参考.md # python接口安装说明 + |-- MANIFEST.in + |-- Makefile + |-- ascendfaiss.py # 接口配置脚本 + |-- setup.py # 安装脚本 + |-- swig_ascendfaiss.swig # swig 配置文件 + `-- test_ascend_index_flat.py # flat算法demo + +``` **注:**TestAscendIndexIVFSP.cpp 需要根据实际情况填写数据集(特征数据、查询数据、groundtruth数据)、码本,所在的目录。 **注:**TestAscendIndexGreat.cpp 需要根据实际情况填写数据集(特征数据、查询数据、groundtruth数据)、码本,所在的目录。 @@ -59,27 +74,37 @@ cd .. && rm -rf release-1.8.1.tar.gz googletest-release-1.8.1 TestAscendIReduction.cpp 需要根据实际情况填写对应的NN降维模型所在的目录。 -#### Demo使用说明 +### Demo使用说明 -1. 请先正确安装Index SDK 组件及其依赖的driver、firmware、Ascend toolkit、OpenBLAS、Faiss +1. **请先正确安装Index SDK 组件及其依赖的driver、firmware、Ascend toolkit、OpenBLAS、Faiss** (具体可参考用户指南 安装部署章节) -2. 修改dependencies.cmake 中的 MXINDEX_HOME +2. 进入IndexSDK目录 +本例中demo默认安装路径为 /home/work/,可将其修改为demo实际安装路径。 +``` +export INDEXDEMO_INSTALL_PATH=/home/work/ +cd ${INDEXDEMO_INSTALL_PATH}/mindxsdk-referenceapps/IndexSDK/ +``` + +3. 修改dependencies.cmake 中的 MXINDEX_HOME ``` SET(MXINDEX_HOME /home/work/FeatureRetrieval/mxIndex/ CACHE STRING "") ``` 本例中Index SDK默认安装路径为 /home/work/FeatureRetrieval/mxIndex/,可将其修改为Index SDK实际安装路径。 +``` +export INDEX_INSTALL_PATH=/home/work/FeatureRetrieval/mxIndex/ +``` -3. 执行一下命令编译demo +4. 执行build.sh编译demo ``` shell bash build.sh ``` -4. 设置环境变量与生成算子 +5. 设置环境变量与生成算子 执行如下命令设置环境变量(根据CANN软件包的实际安装路径修改): ``` source /usr/local/Ascend/ascend-toolkit/set_env.sh -export LD_LIBRARY_PATH=${MXINDEX_INSTALL_PATH}/host/lib:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${INDEX_INSTALL_PATH}/host/lib:$LD_LIBRARY_PATH ``` MXINDEX_INSTALL_PATH为Index SDK实际安装路径,本例中为/home/work/FeatureRetrieval/mxIndex/ @@ -88,31 +113,29 @@ MXINDEX_INSTALL_PATH为Index SDK实际安装路径,本例中为/home/work/Feat 所有算子生成的python文件均在MXINDEX_INSTALL_PATH/tools/目录下,可执行 -h参数 查看具体参数意义 -用例所需生成算子命令已写明在用例注释里。 - 以TestAscendIndexFlat.cpp中需要生成的Flat算子为例, 执行: ``` -cd ${MXINDEX_INSTALL_PATH}/ops/ +cd ${INDEX_INSTALL_PATH}/ops/ bash custom_opp_{arch}.run -cd ${MXINDEX_INSTALL_PATH}/tools/ -生成aicpu和flat的算子 +cd ${INDEX_INSTALL_PATH}/tools/ +生成aicpu和flat 512维的算子 ``` -算子默认生成在${MXINDEX_INSTALL_PATH}/tools/op_models 路径下,将算子移动至算子目录,执行: +算子默认生成在${INDEX_INSTALL_PATH}/tools/op_models 路径下,将算子移动至算子目录,执行: ``` -mv ${MXINDEX_INSTALL_PATH}/tools/op_models/* ${MXINDEX_INSTALL_PATH}/modelpath/ +mv ${INDEX_INSTALL_PATH}/tools/op_models/* ${INDEX_INSTALL_PATH}/modelpath/ ``` 设置算子的环境变量: ``` -export $MX_INDEX_MODELPATH=${MXINDEX_INSTALL_PATH}/modelpath +export MX_INDEX_MODELPATH=/home/work/FeatureRetrieval/mxIndex-{version}/modelpath/ ``` -注意:算子环境变量请勿使用软链接,而是算子实际所在目录。本例中为/home/work/FeatureRetrieval/mxIndex-{version}/modelpath/ +注意:算子环境变量请勿使用软链接,而是算子实际所在目录。 -5. 在build目录中找到对应的二进制可执行文件 +6. 在build目录中找到对应的二进制可执行文件 以TestAscendIndexFlat.cpp为例,执行: ``` -cd build/ +cd ${INDEXDEMO_INSTALL_PATH}/mindxsdk-referenceapps/IndexSDK/build/ ./TestAscendIndexFlat ``` \ No newline at end of file diff --git a/IndexSDK/TestAscendIndexAggressTs.cpp b/IndexSDK/TestAscendIndexAggressTs.cpp index c0c58cb8782306025cec5e2494c2be590a2cfcd9..89cee55a3907b39c524cf6fcada5f9ec8bb72b9d 100644 --- a/IndexSDK/TestAscendIndexAggressTs.cpp +++ b/IndexSDK/TestAscendIndexAggressTs.cpp @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + // 需要生成aicpu算子+flat算子(-d 512)+ mask算子 #include #include #include diff --git a/IndexSDK/TestAscendIndexBinaryFlat.cpp b/IndexSDK/TestAscendIndexBinaryFlat.cpp index 554d4855da704dd3e3366c1bc655456c324e49ad..6a197b659d75f8e3d3037d84a7b1ff68489d77d1 100644 --- a/IndexSDK/TestAscendIndexBinaryFlat.cpp +++ b/IndexSDK/TestAscendIndexBinaryFlat.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+binary_flat算子(-d 512) + #include #include #include diff --git a/IndexSDK/TestAscendIndexCluster.cpp b/IndexSDK/TestAscendIndexCluster.cpp index a85d05f4a5fe0a65090a63bd2710ad6f06d9add6..72b76b59918aab6b6daa81a4a28f6096eec12ee2 100644 --- a/IndexSDK/TestAscendIndexCluster.cpp +++ b/IndexSDK/TestAscendIndexCluster.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+flat算子(-d 64) + #include #include #include diff --git a/IndexSDK/TestAscendIndexFlat.cpp b/IndexSDK/TestAscendIndexFlat.cpp index 1de8cea9d4f055fd195ddec7dbeeb0df5eb3911b..18f36c0ea5222ae1250e2ed9a96d17588f4455d8 100644 --- a/IndexSDK/TestAscendIndexFlat.cpp +++ b/IndexSDK/TestAscendIndexFlat.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ + // 需要生成aicpu算子+flat算子(-d 512) + #include #include #include diff --git a/IndexSDK/TestAscendIndexIVFSP.cpp b/IndexSDK/TestAscendIndexIVFSP.cpp index 2d96026454e3638ccf14b989efa946fe45dfa2b9..9dfb3162b8a74d49c1020c61f175cabb3db97279 100644 --- a/IndexSDK/TestAscendIndexIVFSP.cpp +++ b/IndexSDK/TestAscendIndexIVFSP.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ + // 需要生成aicpu算子+ivfsp_pycal算子(-d 256 -nonzero_num 64 -nlist 256 -batch_size 64 -code_num 32768)+ivfsp_model算子 + #include #include #include diff --git a/IndexSDK/TestAscendIndexIVFSQ.cpp b/IndexSDK/TestAscendIndexIVFSQ.cpp index 8d4e80fb4fdf3fb705d448deee7689ee6e8cc0ae..c1bd5c0ad41770788cb8f6df84470f26bd45387f 100644 --- a/IndexSDK/TestAscendIndexIVFSQ.cpp +++ b/IndexSDK/TestAscendIndexIVFSQ.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +// 需要生成aicpu算子+ivfsq8算子(-d 64 -c 8192)+flat_at算子(-d 64 -c 8192) #include #include diff --git a/IndexSDK/TestAscendIndexIVFSQT.cpp b/IndexSDK/TestAscendIndexIVFSQT.cpp index b2a0b54d1383b9cb8be586241637bfd13cc358e9..894df28abd8a31744d9bddec3666764339eab83d 100644 --- a/IndexSDK/TestAscendIndexIVFSQT.cpp +++ b/IndexSDK/TestAscendIndexIVFSQT.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成ivfsqt算子(-d 256 -c 16384)+flat_at算子(-d 256 -c 16384)+flat_at_int8算子(-d 256 -c 16384) + #include #include #include diff --git a/IndexSDK/TestAscendIndexIVFSQTwithCpuFlat.cpp b/IndexSDK/TestAscendIndexIVFSQTwithCpuFlat.cpp index 2d37daa9349979736ab47321572ac267bd3aba3d..ace202096de29c5e8f66beb9cd36d7bbee8e9b2d 100644 --- a/IndexSDK/TestAscendIndexIVFSQTwithCpuFlat.cpp +++ b/IndexSDK/TestAscendIndexIVFSQTwithCpuFlat.cpp @@ -1,3 +1,6 @@ + +// 需要生成 aicpu算子+ivfsqt算子(-d 256 -c 16384)+flat_at算子(-d 256 -c 16384) + #include #include #include diff --git a/IndexSDK/TestAscendIndexInt8Flat.cpp b/IndexSDK/TestAscendIndexInt8Flat.cpp index 5f3d2677fbb4bd84ce1f01c426bc98f242c5642f..25fa8f87b5365bcbcae4db932137b168e163b559 100644 --- a/IndexSDK/TestAscendIndexInt8Flat.cpp +++ b/IndexSDK/TestAscendIndexInt8Flat.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+int8flat算子(-d 512) + #include #include #include diff --git a/IndexSDK/TestAscendIndexInt8FlatWithCPU.cpp b/IndexSDK/TestAscendIndexInt8FlatWithCPU.cpp index 4c58352bf7813b785fa260decf2f9f840c31d8f7..3e64fde38424efc38f2d3849e77604e87700873a 100644 --- a/IndexSDK/TestAscendIndexInt8FlatWithCPU.cpp +++ b/IndexSDK/TestAscendIndexInt8FlatWithCPU.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成 aicpu算子+int8flat算子(-d 512) + #include #include #include diff --git a/IndexSDK/TestAscendIndexInt8FlatWithReduction.cpp b/IndexSDK/TestAscendIndexInt8FlatWithReduction.cpp index 3530a1a79a970f3616e1a9c47be16da22ae65bd0..4ff15f7a68ae3b1ec4e6714bcfbaa9fe5ea1836a 100644 --- a/IndexSDK/TestAscendIndexInt8FlatWithReduction.cpp +++ b/IndexSDK/TestAscendIndexInt8FlatWithReduction.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+int8flat算子(-d 64) + #include #include #include diff --git a/IndexSDK/TestAscendIndexInt8FlatWithSQ.cpp b/IndexSDK/TestAscendIndexInt8FlatWithSQ.cpp index de51295726d8680860a337a176a41b093ddda597..378dc8ebda837607c113ecc93c41410fe236f7b1 100644 --- a/IndexSDK/TestAscendIndexInt8FlatWithSQ.cpp +++ b/IndexSDK/TestAscendIndexInt8FlatWithSQ.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+int8flat算子(-d 512) + #include #include #include diff --git a/IndexSDK/TestAscendIndexSQ.cpp b/IndexSDK/TestAscendIndexSQ.cpp index 4d61db7309cb1fdfc174eb049c6cb7064d4fbe56..404dc190ae0941ac969ece6ffd5274ce0af7e882 100644 --- a/IndexSDK/TestAscendIndexSQ.cpp +++ b/IndexSDK/TestAscendIndexSQ.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+sq8算子(-d 256)+sq8算子(-d 512) + #include #include #include diff --git a/IndexSDK/TestAscendIndexSQMulPerformance.cpp b/IndexSDK/TestAscendIndexSQMulPerformance.cpp index c4d7fe13bf218523dbeca91e9e091f4b6f67d012..5846314778c414439b776909e201d52c310bb9fb 100644 --- a/IndexSDK/TestAscendIndexSQMulPerformance.cpp +++ b/IndexSDK/TestAscendIndexSQMulPerformance.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ + // 需要生成aicpu算子+sq8(-d 64) + #include #include #include diff --git a/IndexSDK/TestAscendIndexTS.cpp b/IndexSDK/TestAscendIndexTS.cpp index 76def3cc8693c622fb16bde29d11360fec050afb..51ca53de131f73f44642f4aecf4cb55e7479a5bf 100644 --- a/IndexSDK/TestAscendIndexTS.cpp +++ b/IndexSDK/TestAscendIndexTS.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+binary_flat算子(-d 512)+mask算子 + #include #include #include diff --git a/IndexSDK/TestAscendIndexTS_int8Cos.cpp b/IndexSDK/TestAscendIndexTS_int8Cos.cpp index f150cbad04a63a2151a5683e7827aafb3f326040..a907a32378ec2c2092ce3b686b6b5b195edf2550 100644 --- a/IndexSDK/TestAscendIndexTS_int8Cos.cpp +++ b/IndexSDK/TestAscendIndexTS_int8Cos.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +// 需要生成aicpu算子+int8flat算子(-d 512)+mask算子 + #include #include #include diff --git a/IndexSDK/TestAscendMultiSearch.cpp b/IndexSDK/TestAscendMultiSearch.cpp index 985624a6cd9445745e3990703c266f96796e2e36..8f47c0cc9d8b17d59ac0a29836a46131ca67eee7 100644 --- a/IndexSDK/TestAscendMultiSearch.cpp +++ b/IndexSDK/TestAscendMultiSearch.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ + // 需要生成aicpu算子+int8flat(-d 64)+sq8算子(-d 64) + #include #include #include diff --git "a/IndexSDK/faiss-python/Faiss\345\256\211\350\243\205\345\217\202\350\200\203.md" "b/IndexSDK/faiss-python/Faiss\345\256\211\350\243\205\345\217\202\350\200\203.md" index 8ab75f4297a3ee0a26fb2dac3bfd81e01ef810fb..4cd788bf2d9923c060f60ca245483b7e266d0aaf 100644 --- "a/IndexSDK/faiss-python/Faiss\345\256\211\350\243\205\345\217\202\350\200\203.md" +++ "b/IndexSDK/faiss-python/Faiss\345\256\211\350\243\205\345\217\202\350\200\203.md" @@ -210,6 +210,8 @@ cd faiss-1.7.1 # ascendfaiss编译 +**编译前请完成Index SDK的安装 并生成aicpu和flat 512维的算子** MXINDEX_INSTALL_PATH为安装路径 + 1、设置软件安装路径信息,根据实际情况配置