Interface Description
Table 1 describes the interfaces provided by KRL.
Type |
API |
Function |
|---|---|---|
Handle class interfaces |
krl_create_distance_handle |
Initializes and constructs a KRLDistanceHandle instance for dense distance computation. |
krl_create_reorder_handle |
Initializes and constructs a KRLDistanceHandle instance for reordering computation. |
|
krl_clean_distance_handle |
Destroys the KRLDistanceHandle instance and releases memory space. |
|
krl_create_LUT8b_handle |
Initializes and constructs a KRLLUT8bHandle instance for accumulation based on 8-bit table lookup. |
|
krl_clean_LUT8b_handle |
Destroys the KRLLUT8bHandle instance and releases memory space. |
|
krl_get_idx_pointer |
Obtains the IDs of to-be-computed base vectors stored in the KRLLUT8bHandle instance. |
|
krl_get_dist_pointer |
Obtains the start address of the distance array stored in the KRLLUT8bHandle instance. The address contains a random number before a table lookup-based accumulation operator is called, and holds the computed distance value after the operator is called. |
|
Distance computation interfaces |
krl_L2sqr |
Performs one-to-one Euclidean distance computation on vectors represented in float precision. |
krl_L2sqr_f16f32 |
Performs one-to-one Euclidean distance computation on vectors represented in fp16 precision. |
|
krl_L2sqr_u8u32 |
Performs one-to-one Euclidean distance computation on vectors represented as 8-bit unsigned integers (uint8). |
|
krl_ipdis |
Performs one-to-one distance computation using inner product on vectors represented in float precision. |
|
krl_negative_ipdis_f16f32 |
Performs one-to-one distance computation using inner product on vectors represented in fp16 precision. |
|
krl_negative_ipdis_s8s32 |
Performs one-to-one distance computation using inner product on vectors represented as 8-bit unsigned integers (uint8). |
|
krl_L2sqr_by_idx |
Performs one-to-many Euclidean distance computation on vectors represented in float precision. |
|
krl_L2sqr_by_idx_f16f32 |
Performs one-to-many Euclidean distance computation on vectors represented in fp16 precision. |
|
krl_L2sqr_by_idx_u8f32 |
Performs one-to-many Euclidean distance computation on vectors represented as 8-bit unsigned integers (uint8). |
|
krl_inner_product_by_idx |
Performs one-to-many distance computation using inner product on vectors represented in float precision. |
|
krl_inner_product_by_idx_f16f32 |
Performs one-to-many distance computation using inner product on vectors represented in fp16 precision. |
|
krl_negative_inner_product_by_idx_f16f32 |
Performs one-to-many distance computation using inner product on vectors represented in fp16 precision, and negates the computation results. |
|
krl_inner_product_by_idx_s8f32 |
Performs one-to-many distance computation using inner product on vectors represented as 8-bit unsigned integers (uint8). |
|
krl_L2sqr_ny |
Performs one-to-many Euclidean distance computation on vectors represented in float precision. |
|
krl_L2sqr_ny_f16f32 |
Performs one-to-many Euclidean distance computation on vectors represented in fp16 precision. |
|
krl_L2sqr_ny_u8f32 |
Performs one-to-many Euclidean distance computation on vectors represented as 8-bit unsigned integers (uint8). |
|
krl_L2sqr_ny_with_handle |
Performs one-to-many Euclidean distance computation on vectors represented in float precision. The base vectors and dimensions are stored in the handle. |
|
krl_inner_product_ny |
Performs one-to-many distance computation using inner product on vectors represented in float precision. |
|
krl_inner_product_ny_f16f32 |
Performs one-to-many distance computation using inner product on vectors represented in fp16 precision. |
|
krl_inner_product_ny_s8f32 |
Performs one-to-many distance computation using inner product on vectors represented as 8-bit unsigned integers (uint8). |
|
krl_inner_product_ny_with_handle |
Performs one-to-many distance computation using inner product on vectors represented in float precision. The base vectors and dimensions are stored in the handle. |
|
8-bit table lookup-based accumulation interfaces |
krl_table_lookup_8b_f32 |
Obtains distance values from the float-type LUT using 8-bit indexes, accumulates the distance values, adds dis0 to the result after accumulation, and stores the final result in distance. |
krl_table_lookup_8b_f32_by_idx |
Obtains distance values from the float-type LUT using 8-bit indexes, accumulates the distance values, adds dis0 to the result after accumulation, and stores the final result in distance. Only the base vectors whose IDs are in the idx array are used for computation. |
|
krl_table_lookup_8b_f32_with_handle |
Obtains distance values from the float-type LUT using 8-bit indexes, accumulates the distance values, adds dis0 to the result after accumulation, and stores the final result in distance. The idx and distance arrays are contained in the KRLLUT8bHandle instance. Only the base vectors whose IDs are in the idx array are used for computation. |
|
4-bit table lookup-based accumulation interfaces |
krl_fast_table_lookup_step |
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. |
krl_L2_table_lookup_fast_scan_bs64 |
An operator designed for 4-bit table lookup, accumulation, filtering, and compression. It is used for processing float-type query vectors individually. Computes Euclidean distances between a query vector and 64 base vectors. Based on the distance comparison rule, if a distance value meets the comparison rule, the bit in lt_mask of the corresponding base vector is set to 1. Otherwise, it is set to 0. |
|
krl_IP_table_lookup_fast_scan_bs64 |
An operator designed for 4-bit table lookup, accumulation, filtering, and compression. It is used for processing float-type query vectors individually. Computes distances between a query vector and 64 base vectors using inner product. Based on the distance comparison rule, if a distance value meets the comparison rule, the bit in lt_mask of the corresponding base vector is set to 1. Otherwise, it is set to 0. |
|
krl_L2_table_lookup_fast_scan_bs96 |
An operator designed for 4-bit table lookup, accumulation, filtering, and compression. It is used for processing float-type query vectors individually. Computes Euclidean distances between a query vector and 96 base vectors. Based on the distance comparison rule, if a distance value meets the comparison rule, the bit in lt_mask of the corresponding base vector is set to 1. Otherwise, it is set to 0. |
|
krl_IP_table_lookup_fast_scan_bs96 |
An operator designed for 4-bit table lookup, accumulation, filtering, and compression. It is used for processing float-type query vectors individually. Computes distances between a query vector and 96 base vectors using inner product. Based on the distance comparison rule, if a distance value meets the comparison rule, the bit in lt_mask of the corresponding base vector is set to 1. Otherwise, it is set to 0. |
|
krl_table_lookup_4b_f16 |
An operator designed for 4-bit table lookup, accumulation, filtering, and compression. It is used for processing fp16 query vectors individually. Computes distances between a query vector and multiple base vectors using inner product. The initial distance is dis_f16. This interface does not perform filtering or compression (that is, comparison with the threshold). |
|
krl_pack_codes_4b |
An operator designed for 4-bit table lookup, accumulation, filtering, and compression. It is used for processing fp16 query vectors individually. Computes distances between a query vector and multiple base vectors using inner product. The initial distance is dis_f16. This interface does not perform filtering or compression (that is, comparison with the threshold). |
|
Reranking interfaces |
krl_reorder_2_vector |
Computes high-accuracy distances between a single query vector and multiple non-contiguous base vectors, and returns the results sorted by distance. |
krl_reorder_2_vector_continuous |
Computes high-accuracy distances between a single query vector and multiple contiguous base vectors, and returns the results sorted by distance. |
|
Store/Load interfaces |
krl_store_LUT8Handle |
Stores the handle of an 8-bit lookup table into a file. |
krl_build_LUT8Handle_fromfile |
Reads data of an 8-bit lookup table from a file and rebuilds a handle. |
|
krl_store_distanceHandle |
Stores the handle for distance computation into a file. |
|
krl_build_distanceHandle_fromfile |
Reads data of a distance computation handle from a file and rebuilds the handle. |