Rate This Document
Findability
Accuracy
Completeness
Readability

krl_fast_table_lookup_step

Interface Definition

int krl_fast_table_lookup_step(int nq, int nsq, const uint8_t* codes, const uint8_t* LUT, uint16_t* dis, const uint16_t* threshold, uint32_t* lt_mask, int keep_min, size_t codes_size, size_t LUT_size, size_t dis_size, size_t threshold_size, size_t lt_mask_size);

Function

An operator designed for 4-bit table lookup, accumulation, filtering, and compression. It is used for batch processing of float-type query vectors. This operator is used to compute distances between a maximum of 16 query vectors and 32 base vectors. After the distance computation, each result is compared against a threshold. If a distance value is less than the threshold, the bit in lt_mask of the corresponding base vector is set to 1. Otherwise, it is set to 0.

Parameters

Parameter

Data Type

Description

Value Range

nq

int

Number of query vectors.

[1, 16]

nsq

int

Number of subspaces.

An even number in [1, 256]

codes

const uint8_t*

Codebook, which stores indexes of base vectors after krl_pack_codes_4b (blocksize=32) processing.

The size is specified by codes_size.

LUT

const uint8_t*

Distance LUT, which stores the uint8 distances between product quantization (PQ) centroids and query vectors in each subspace.

The size is specified by LUT_size.

dis

uint16_t*

Stores the distance computation results.

The size is specified by dis_size. The memory needs to be allocated in advance.

threshold

const uint16_t*

Distance threshold.

The size is specified by threshold_size. The threshold is 65535.

lt_mask

uint32_t*

Filtered and compressed results.

The size is specified by lt_mask_size. The memory needs to be allocated in advance.

keep_min

int

Indicates whether to retain the distance results less than the threshold.

[0, 1]

  • 0: Retain the distance results greater than the threshold.
  • 1: Retain the distance results less than the threshold.

codes_size

size_t

Length of the codebook array.

nsq/2 x 32

LUT_size

size_t

Length of the distance LUT array.

nq x nsq x 16

dis_size

size_t

Specifies the size of the distance result array.

nq x 32

threshold_size

size_t

Length of the distance threshold array.

The size is specified by nq.

lt_mask_size

size_t

Length of the array storing filtered and compressed results.

nq/32

Return Values

Data Type

Description

int

0 is returned on successful execution. In case of failure, an error code is returned to indicate the specific issue:

  • -1: invalid pointer
  • -2: memory allocation failure
  • -3: invalid input parameter
  • -4: double free
  • -5: insecure memory operation
  • -6: I/O failure