Init

API Definition

APP_ERROR Init(int dim, int capacity, AscendMetricType metricType, int resourceSize = -1) override

Function

Initializes feature library parameters and allocates base library memory resources.

Input

int dim: dimension of the feature vector.

AscendMetricType metricType: feature distance category (vector inner product, Euclidean distance, and cosine similarity).

int capacity: maximum capacity of the base library. The API allocates capacity x dim x sizeof(fp16) bytes of memory data based on the value of capacity.

int resourceSize: allocates cache resources of the device in advance. When the search interface is called, the resources can be directly used without calling aclrtmalloc to allocate memory resources, achieving optimization acceleration.

The default value is -1, indicating that cache resources (128 MB) are allocated based on the default size. You can configure the size based on the data volume of the search service and the resource usage on the device.

For example, if batch of a query operation is set to 64, the base library has 1 million vectors, and an FP32 value occupies four bytes, resourceSize is 256,000,000 bytes (64 x 1000000 x 4). Note that the maximum cache resources can be allocated internally by the API is 1 GB.

Output

N/A

Return Value

APP_ERROR: return status. For details, see Return Code Reference.

Restrictions

  • dim ∈ {32, 64, 128, 256, 384, 512, 1024}
  • metricType: Currently, IndexILFlat supports only the vector inner product distance, that is, only AscendMetricType::ASCEND_METRIC_INNER_PRODUCT is supported.
  • capacity: The upper limit of the memory that can be allocated to the base library is 12,288,000,000 bytes, and the value range of capacity is [0, 12000000].
    • For 512-dimensional base library vector of the FP16 type, the maximum supported capacity is 12,000,000 (12288000000/(512 x sizeof(fp_16))).
    • For 256-dimensional base library vector of the FP16 type, the maximum capacity can only be 12,000,000, though memory supports a larger capacity value.
  • resourceSize: The value can be -1 or a value in the range of [134217728, 1073741824], in bytes, which is equivalent to [128 MB, 1024 MB].