|
| 1 | +// |
| 2 | +// distance-rvv.c |
| 3 | +// sqlitevector |
| 4 | +// |
| 5 | +// Created by Afonso Bordado on 2026/02/19. |
| 6 | +// |
| 7 | + |
| 8 | + |
| 9 | +#include "distance-rvv.h" |
| 10 | +#include "distance-cpu.h" |
| 11 | + |
| 12 | +#if defined(__riscv_vector) |
| 13 | +#include <riscv_vector.h> |
| 14 | + |
| 15 | +extern distance_function_t dispatch_distance_table[VECTOR_DISTANCE_MAX][VECTOR_TYPE_MAX]; |
| 16 | +extern const char *distance_backend_name; |
| 17 | + |
| 18 | +// MARK: - FLOAT32 - |
| 19 | + |
| 20 | +float float32_distance_l2_rvv (const void *v1, const void *v2, int n) { |
| 21 | + panic("float32_distance_l2_rvv: unimplemented"); |
| 22 | + return 0.0f; |
| 23 | +} |
| 24 | + |
| 25 | +float float32_distance_l2_squared_rvv (const void *v1, const void *v2, int n) { |
| 26 | + panic("float32_distance_l2_squared_rvv: unimplemented"); |
| 27 | + return 0.0f; |
| 28 | +} |
| 29 | + |
| 30 | +float float32_distance_l1_rvv (const void *v1, const void *v2, int n) { |
| 31 | + panic("float32_distance_l1_rvv: unimplemented"); |
| 32 | + return 0.0f; |
| 33 | +} |
| 34 | + |
| 35 | +float float32_distance_dot_rvv (const void *v1, const void *v2, int n) { |
| 36 | + panic("float32_distance_dot_rvv: unimplemented"); |
| 37 | + return 0.0f; |
| 38 | +} |
| 39 | + |
| 40 | +float float32_distance_cosine_rvv (const void *v1, const void *v2, int n) { |
| 41 | + panic("float32_distance_cosine_rvv: unimplemented"); |
| 42 | + return 0.0f; |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +// MARK: - FLOAT16 - |
| 47 | + |
| 48 | +float float16_distance_l2_rvv (const void *v1, const void *v2, int n) { |
| 49 | + panic("float16_distance_l2_rvv: unimplemented"); |
| 50 | + return 0.0f; |
| 51 | +} |
| 52 | + |
| 53 | +float float16_distance_l2_squared_rvv (const void *v1, const void *v2, int n) { |
| 54 | + panic("float16_distance_l2_squared_rvv: unimplemented"); |
| 55 | + return 0.0f; |
| 56 | +} |
| 57 | + |
| 58 | +float float16_distance_l1_rvv (const void *v1, const void *v2, int n) { |
| 59 | + panic("float16_distance_l1_rvv: unimplemented"); |
| 60 | + return 0.0f; |
| 61 | +} |
| 62 | + |
| 63 | +float float16_distance_dot_rvv (const void *v1, const void *v2, int n) { |
| 64 | + panic("float16_distance_dot_rvv: unimplemented"); |
| 65 | + return 0.0f; |
| 66 | +} |
| 67 | + |
| 68 | +float float16_distance_cosine_rvv (const void *v1, const void *v2, int n) { |
| 69 | + panic("float16_distance_cosine_rvv: unimplemented"); |
| 70 | + return 0.0f; |
| 71 | +} |
| 72 | + |
| 73 | +// MARK: - BFLOAT16 - |
| 74 | + |
| 75 | +float bfloat16_distance_l2_rvv (const void *v1, const void *v2, int n) { |
| 76 | + panic("bfloat16_distance_l2_rvv: unimplemented"); |
| 77 | + return 0.0f; |
| 78 | +} |
| 79 | + |
| 80 | +float bfloat16_distance_l2_squared_rvv (const void *v1, const void *v2, int n) { |
| 81 | + panic("bfloat16_distance_l2_squared_rvv: unimplemented"); |
| 82 | + return 0.0f; |
| 83 | +} |
| 84 | + |
| 85 | +float bfloat16_distance_l1_rvv (const void *v1, const void *v2, int n) { |
| 86 | + panic("bfloat16_distance_l1_rvv: unimplemented"); |
| 87 | + return 0.0f; |
| 88 | +} |
| 89 | + |
| 90 | +float bfloat16_distance_dot_rvv (const void *v1, const void *v2, int n) { |
| 91 | + panic("bfloat16_distance_dot_rvv: unimplemented"); |
| 92 | + return 0.0f; |
| 93 | +} |
| 94 | + |
| 95 | +float bfloat16_distance_cosine_rvv (const void *v1, const void *v2, int n) { |
| 96 | + panic("bfloat16_distance_cosine_rvv: unimplemented"); |
| 97 | + return 0.0f; |
| 98 | +} |
| 99 | + |
| 100 | +// MARK: - UINT8 - |
| 101 | + |
| 102 | +float uint8_distance_l2_rvv (const void *v1, const void *v2, int n) { |
| 103 | + panic("uint8_distance_l2_rvv: unimplemented"); |
| 104 | + return 0.0f; |
| 105 | +} |
| 106 | + |
| 107 | +float uint8_distance_l2_squared_rvv (const void *v1, const void *v2, int n) { |
| 108 | + panic("uint8_distance_l2_squared_rvv: unimplemented"); |
| 109 | + return 0.0f; |
| 110 | +} |
| 111 | + |
| 112 | +float uint8_distance_dot_rvv (const void *v1, const void *v2, int n) { |
| 113 | + panic("uint8_distance_dot_rvv: unimplemented"); |
| 114 | + return 0.0f; |
| 115 | +} |
| 116 | + |
| 117 | +float uint8_distance_l1_rvv (const void *v1, const void *v2, int n) { |
| 118 | + panic("uint8_distance_l1_rvv: unimplemented"); |
| 119 | + return 0.0f; |
| 120 | +} |
| 121 | + |
| 122 | +float uint8_distance_cosine_rvv (const void *v1, const void *v2, int n) { |
| 123 | + panic("uint8_distance_cosine_rvv: unimplemented"); |
| 124 | + return 0.0f; |
| 125 | +} |
| 126 | + |
| 127 | +// MARK: - INT8 - |
| 128 | + |
| 129 | +float int8_distance_l2_rvv (const void *v1, const void *v2, int n) { |
| 130 | + panic("int8_distance_l2_rvv: unimplemented"); |
| 131 | + return 0.0f; |
| 132 | +} |
| 133 | + |
| 134 | +float int8_distance_l2_squared_rvv (const void *v1, const void *v2, int n) { |
| 135 | + panic("int8_distance_l2_squared_rvv: unimplemented"); |
| 136 | + return 0.0f; |
| 137 | +} |
| 138 | + |
| 139 | +float int8_distance_dot_rvv (const void *v1, const void *v2, int n) { |
| 140 | + panic("int8_distance_dot_rvv: unimplemented"); |
| 141 | + return 0.0f; |
| 142 | +} |
| 143 | + |
| 144 | +float int8_distance_l1_rvv (const void *v1, const void *v2, int n) { |
| 145 | + panic("int8_distance_l1_rvv: unimplemented"); |
| 146 | + return 0.0f; |
| 147 | +} |
| 148 | + |
| 149 | +float int8_distance_cosine_rvv (const void *v1, const void *v2, int n) { |
| 150 | + panic("int8_distance_cosine_rvv: unimplemented"); |
| 151 | + return 0.0f; |
| 152 | +} |
| 153 | + |
| 154 | +// MARK: - BIT - |
| 155 | + |
| 156 | +float bit1_distance_hamming_rvv (const void *v1, const void *v2, int n) { |
| 157 | + panic("bit1_distance_hamming_rvv: unimplemented"); |
| 158 | + return 0.0f; |
| 159 | +} |
| 160 | + |
| 161 | +#endif |
| 162 | + |
| 163 | +// MARK: - |
| 164 | + |
| 165 | +void init_distance_functions_rvv (void) { |
| 166 | +#if defined(__riscv_vector) |
| 167 | + dispatch_distance_table[VECTOR_DISTANCE_L2][VECTOR_TYPE_F32] = float32_distance_l2_rvv; |
| 168 | + dispatch_distance_table[VECTOR_DISTANCE_L2][VECTOR_TYPE_F16] = float16_distance_l2_rvv; |
| 169 | + dispatch_distance_table[VECTOR_DISTANCE_L2][VECTOR_TYPE_BF16] = bfloat16_distance_l2_rvv; |
| 170 | + dispatch_distance_table[VECTOR_DISTANCE_L2][VECTOR_TYPE_U8] = uint8_distance_l2_rvv; |
| 171 | + dispatch_distance_table[VECTOR_DISTANCE_L2][VECTOR_TYPE_I8] = int8_distance_l2_rvv; |
| 172 | + |
| 173 | + dispatch_distance_table[VECTOR_DISTANCE_SQUARED_L2][VECTOR_TYPE_F32] = float32_distance_l2_squared_rvv; |
| 174 | + dispatch_distance_table[VECTOR_DISTANCE_SQUARED_L2][VECTOR_TYPE_F16] = float16_distance_l2_squared_rvv; |
| 175 | + dispatch_distance_table[VECTOR_DISTANCE_SQUARED_L2][VECTOR_TYPE_BF16] = bfloat16_distance_l2_squared_rvv; |
| 176 | + dispatch_distance_table[VECTOR_DISTANCE_SQUARED_L2][VECTOR_TYPE_U8] = uint8_distance_l2_squared_rvv; |
| 177 | + dispatch_distance_table[VECTOR_DISTANCE_SQUARED_L2][VECTOR_TYPE_I8] = int8_distance_l2_squared_rvv; |
| 178 | + |
| 179 | + dispatch_distance_table[VECTOR_DISTANCE_COSINE][VECTOR_TYPE_F32] = float32_distance_cosine_rvv; |
| 180 | + dispatch_distance_table[VECTOR_DISTANCE_COSINE][VECTOR_TYPE_F16] = float16_distance_cosine_rvv; |
| 181 | + dispatch_distance_table[VECTOR_DISTANCE_COSINE][VECTOR_TYPE_BF16] = bfloat16_distance_cosine_rvv; |
| 182 | + dispatch_distance_table[VECTOR_DISTANCE_COSINE][VECTOR_TYPE_U8] = uint8_distance_cosine_rvv; |
| 183 | + dispatch_distance_table[VECTOR_DISTANCE_COSINE][VECTOR_TYPE_I8] = int8_distance_cosine_rvv; |
| 184 | + |
| 185 | + dispatch_distance_table[VECTOR_DISTANCE_DOT][VECTOR_TYPE_F32] = float32_distance_dot_rvv; |
| 186 | + dispatch_distance_table[VECTOR_DISTANCE_DOT][VECTOR_TYPE_F16] = float16_distance_dot_rvv; |
| 187 | + dispatch_distance_table[VECTOR_DISTANCE_DOT][VECTOR_TYPE_BF16] = bfloat16_distance_dot_rvv; |
| 188 | + dispatch_distance_table[VECTOR_DISTANCE_DOT][VECTOR_TYPE_U8] = uint8_distance_dot_rvv; |
| 189 | + dispatch_distance_table[VECTOR_DISTANCE_DOT][VECTOR_TYPE_I8] = int8_distance_dot_rvv; |
| 190 | + |
| 191 | + dispatch_distance_table[VECTOR_DISTANCE_L1][VECTOR_TYPE_F32] = float32_distance_l1_rvv; |
| 192 | + dispatch_distance_table[VECTOR_DISTANCE_L1][VECTOR_TYPE_F16] = float16_distance_l1_rvv; |
| 193 | + dispatch_distance_table[VECTOR_DISTANCE_L1][VECTOR_TYPE_BF16] = bfloat16_distance_l1_rvv; |
| 194 | + dispatch_distance_table[VECTOR_DISTANCE_L1][VECTOR_TYPE_U8] = uint8_distance_l1_rvv; |
| 195 | + dispatch_distance_table[VECTOR_DISTANCE_L1][VECTOR_TYPE_I8] = int8_distance_l1_rvv; |
| 196 | + |
| 197 | + dispatch_distance_table[VECTOR_DISTANCE_HAMMING][VECTOR_TYPE_BIT] = bit1_distance_hamming_rvv; |
| 198 | + |
| 199 | + distance_backend_name = "RVV"; |
| 200 | +#endif |
| 201 | +} |
0 commit comments