Sample样例(C++)
#include "AscendHac.h" #include "ErrorCode.h" #include <string> #include <iostream> #include <map> using namespace ascendhac; int main(int argc, char *argv[]) { std::map<std::string, std::string> configData; // < ---------- General Config ---------- > configData["ArchiveName"] = "Demo"; configData["ArchiveMode"] = "ARCHIVE"; configData["FeatureDim"] = "512"; configData["FeatureDataType"] = "FP32"; configData["FeatureSource"] = "RANDOM"; configData["MetricType"] = "IP"; configData["ExactSearchIndexType"] = "FLAT"; configData["ExactSearchThreshold"] = "50000"; configData["ApproximateSearchIndexType"] = "IVFSQ"; configData["ApproximateSearchThreshold"] = "5000000"; configData["Nlist"] = "1024"; configData["Nprobe"] = "32"; configData["DimReduction"] = "TRUE"; configData["ShortDim"] = "64"; configData["Devices"] = "0,1,2,3"; configData["ThreadNum"] = "16"; configData["ResourcesSize"] = "128"; // < ---------- Archive Config ---------- > configData["FeatureCount"] = "10000"; configData["NeedNormalize"] = "TRUE"; configData["PointPointThreshold"] = "0.875"; configData["PointClusterThreshold"] = "0.7"; configData["ClusterClusterThreshold"] = "0.8"; configData["MinRankDistance"] = "6"; configData["MaxRankDistance"] = "10"; configData["MinPicNum"] = "2"; configData["MaxCoverNum"] = "1"; AscendHac ascendHac; if (ascendHac.Init(configData) != APP_ERR_OK) { std::cout << "[Error] Init Archive failed, please check config file!" << std::endl; ascendHac.Release(); return -1; } if (ascendHac.SetArchiveInputRandomly() != APP_ERR_OK) { std::cout << "[Error] Set input data failed!" << std::endl; ascendHac.Release(); return -1; } if (ascendHac.Run() != APP_ERR_OK) { std::cout << "[Error] Archive failed, please check config file!" << std::endl; ascendHac.Release(); return -1; } if (ascendHac.SaveDataToFile() != APP_ERR_OK) { std::cout << "[ERROR] Save to file failed" << std::endl; ascendHac.Release(); return -1; } if (ascendHac.Release() != APP_ERR_OK) { std::cout << "[ERROR] Resources released failed" << std::endl; ascendHac.Release(); return -1; } std::cout << "Archive successfully!" << std::endl; return 0; }
父主题: 代码参考