Init

API定义

APP_ERROR Init(uint32_t deviceId, uint32_t dim, uint32_t tokenNum, AlgorithmType algType = AlgorithmType::FLAT_COS_INT8, MemoryStrategy memoryStrategy = MemoryStrategy::PURE_DEVICE_MEMORY, uint32_t customAttrLen = 0, uint32_t customAttrBlockSize = 0);

功能描述

实例初始化函数。

输入

uint32_t deviceId:Index使用的设备ID。

uint32_t dim:底库向量的维度。

uint32_t tokenNum:当前时空库Token的最大数量,需要和生成对应的Mask生成算子Token数量一致

AlgorithmType type:底层使用的距离比对算法,默认为“AlgorithmType::FLAT_COS_INT8”,可选算法参见如下。

  • “AlgorithmType::FLAT_HAMMING”:二值化特征检索(汉明距离)。
  • “AlgorithmType::FLAT_COS_INT8”:Int8Flat(cos距离)。
  • “AlgorithmType::FLAT_L2_INT8”:Int8Flat(L2距离)。
  • “AlgorithmType::FLAT_IP_FP16”:Fp16Flat(IP距离)。
MemoryStrategy memoryStrategy:底层使用的内存策略,默认为“MemoryStrategy::PURE_DEVICE_MEMORY”,可选策略参见如下。
  • MemoryStrategy::PURE_DEVICE_MEMORY:纯Device内存策略。
  • MemoryStrategy::HETERO_MEMORY:异构内存策略。

customAttrLen:自定义属性长度。

customAttrBlockSize:自定义属性blocksize的大小。

输出

返回值

约束说明

  • 需要紧跟在构造函数后调用。
  • “deviceId”为有效的设备ID,设置范围为[0, 1024]。
  • “tokenNum”设置范围为(0, 1e5]。
  • 对于二值化特征检索(汉明距离)算法,dim ∈ {256, 512, 1024}。
  • 对于Int8Flat(cos距离、L2距离)、Fp16Flat(IP距离)算法,dim ∈ {64, 128, 256, 384, 512, 1024}。
  • “memoryStrategy::HETERO_MEMORY”当前只支持“AlgorithmType::FLAT_COS_INT8”算法。
  • “customAttrLen”设置范围为[0, 32],默认值为“0”,设置为“0”时表示无自定义属性。
  • “customAttrBlockSize”设置范围为[0, 262144*64],需要为1024*256的整数倍。默认值为“0”,设置为“0”时表示无自定义属性。