| 1 | /* |
| 2 | Copyright (C) 2024 Sutou Kouhei <[email protected]> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #if defined(GRN_WITH_SIMSIMD) && defined(GRN_INSTANTIATION_SIMSIMD_ARCH) |
| 20 | namespace grn { |
| 21 | namespace distance { |
| 22 | namespace simsimd { |
| 23 | # ifdef GRN_INSTANTIATION_EXTERN |
| 24 | # define FUNC_EXPANDED(simsimd_backend, \ |
| 25 | c_type, \ |
| 26 | simsimd_type, \ |
| 27 | grn_metric, \ |
| 28 | simsimd_metric) \ |
| 29 | float compute_distance_##grn_metric##_##simsimd_backend( \ |
| 30 | const c_type *vector_raw1, \ |
| 31 | const c_type *vector_raw2, \ |
| 32 | size_t n_elements); |
| 33 | # else |
| 34 | # define FUNC_EXPANDED(simsimd_backend, \ |
| 35 | c_type, \ |
| 36 | simsimd_type, \ |
| 37 | grn_metric, \ |
| 38 | simsimd_metric) \ |
| 39 | float compute_distance_##grn_metric##_##simsimd_backend( \ |
| 40 | const c_type *vector_raw1, \ |
| 41 | const c_type *vector_raw2, \ |
| 42 | size_t n_elements) \ |
| 43 | { \ |
| 44 | return simsimd_##simsimd_backend##_##simsimd_type##_##simsimd_metric( \ |
| 45 | vector_raw1, \ |
| 46 | vector_raw2, \ |
| 47 | n_elements); \ |
| 48 | } |
| 49 | # endif |
| 50 | # define FUNC(simsimd_backend, \ |
| 51 | c_type, \ |
| 52 | simsimd_type, \ |
| 53 | grn_metric, \ |
| 54 | simsimd_metric) \ |
| 55 | FUNC_EXPANDED(simsimd_backend, \ |
| 56 | c_type, \ |
| 57 | simsimd_type, \ |
| 58 | grn_metric, \ |
| 59 | simsimd_metric) |
| 60 | |
| 61 | FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, float, f32, cosine, cos) |
| 62 | FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, double, f64, cosine, cos) |
| 63 | |
| 64 | FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, float, f32, inner_product, ip) |
| 65 | FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, double, f64, inner_product, ip) |
| 66 | |
| 67 | FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, float, f32, l2_norm_squared, l2sq) |
| 68 | FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, double, f64, l2_norm_squared, l2sq) |
| 69 | |
| 70 | # undef FUNC |
| 71 | # undef FUNC_EXPANDED |
| 72 | } // namespace simsimd |
| 73 | } // namespace distance |
| 74 | } // namespace grn |
| 75 | #endif |
| 76 | |
| 77 | #ifdef GRN_WITH_XSIMD |
| 78 | |
| 79 | # ifndef GRN_INSTANTIATION_EXTERN |
| 80 | # define GRN_INSTANTIATION_EXTERN |
| 81 | # endif |
| 82 | |
| 83 | GRN_INSTANTIATION_EXTERN template float |
| 84 | grn::distance::l2_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>( |
| 85 | GRN_INSTANTIATION_XSIMD_ARCH, const float *vector_raw, size_t n_elements); |
| 86 | GRN_INSTANTIATION_EXTERN template float |
| 87 | grn::distance::l2_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>( |
| 88 | GRN_INSTANTIATION_XSIMD_ARCH, const double *vector_raw, size_t n_elements); |
| 89 | |
| 90 | GRN_INSTANTIATION_EXTERN template float |
| 91 | grn::distance::inner_product::operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>( |
| 92 | GRN_INSTANTIATION_XSIMD_ARCH, |
| 93 | const float *vector_raw1, |
| 94 | const float *vector_raw2, |
| 95 | size_t n_elements); |
| 96 | GRN_INSTANTIATION_EXTERN template float |
| 97 | grn::distance::inner_product::operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>( |
| 98 | GRN_INSTANTIATION_XSIMD_ARCH, |
| 99 | const double *vector_raw1, |
| 100 | const double *vector_raw2, |
| 101 | size_t n_elements); |
| 102 | |
| 103 | GRN_INSTANTIATION_EXTERN template float |
| 104 | grn::distance::difference_l1_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH, |
| 105 | float>( |
| 106 | GRN_INSTANTIATION_XSIMD_ARCH, |
| 107 | const float *vector_raw1, |
| 108 | const float *vector_raw2, |
| 109 | size_t n_elements); |
| 110 | |
| 111 | GRN_INSTANTIATION_EXTERN template float |
| 112 | grn::distance::difference_l1_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH, |
| 113 | double>( |
| 114 | GRN_INSTANTIATION_XSIMD_ARCH, |
| 115 | const double *vector_raw1, |
| 116 | const double *vector_raw2, |
| 117 | size_t n_elements); |
| 118 | |
| 119 | GRN_INSTANTIATION_EXTERN template float |
| 120 | grn::distance::difference_l2_norm_squared:: |
| 121 | operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>(GRN_INSTANTIATION_XSIMD_ARCH, |
| 122 | const float *vector_raw1, |
| 123 | const float *vector_raw2, |
| 124 | size_t n_elements); |
| 125 | GRN_INSTANTIATION_EXTERN template float |
| 126 | grn::distance::difference_l2_norm_squared:: |
| 127 | operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>(GRN_INSTANTIATION_XSIMD_ARCH, |
| 128 | const double *vector_raw1, |
| 129 | const double *vector_raw2, |
| 130 | size_t n_elements); |
| 131 | |
| 132 | GRN_INSTANTIATION_EXTERN template float |
| 133 | grn::distance::cosine::operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>( |
| 134 | GRN_INSTANTIATION_XSIMD_ARCH, |
| 135 | const float *vector_raw1, |
| 136 | const float *vector_raw2, |
| 137 | size_t n_elements); |
| 138 | GRN_INSTANTIATION_EXTERN template float |
| 139 | grn::distance::cosine::operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>( |
| 140 | GRN_INSTANTIATION_XSIMD_ARCH, |
| 141 | const double *vector_raw1, |
| 142 | const double *vector_raw2, |
| 143 | size_t n_elements); |
| 144 | #endif |