rope.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. #include "rope.hpp"
  2. #include "ggml-sycl/common.hpp"
  3. #include "ggml.h"
  4. struct rope_corr_dims {
  5. float v[2];
  6. };
  7. struct mrope_sections {
  8. int v[4];
  9. };
  10. static float rope_yarn_ramp(const float low, const float high, const int i0) {
  11. const float y = (i0 / 2 - low) / sycl::max(0.001f, high - low);
  12. return 1.0f - sycl::min(1.0f, sycl::max(0.0f, y));
  13. }
  14. // YaRN algorithm based on LlamaYaRNScaledRotaryEmbedding.py from https://github.com/jquesnelle/yarn
  15. // MIT licensed. Copyright (c) 2023 Jeffrey Quesnelle and Bowen Peng.
  16. static void rope_yarn(
  17. float theta_extrap, float freq_scale, rope_corr_dims corr_dims, int64_t i0, float ext_factor, float mscale,
  18. float * cos_theta, float * sin_theta) {
  19. // Get n-d rotational scaling corrected for extrapolation
  20. float theta_interp = freq_scale * theta_extrap;
  21. float theta = theta_interp;
  22. if (ext_factor != 0.0f) {
  23. float ramp_mix = rope_yarn_ramp(corr_dims.v[0], corr_dims.v[1], i0) * ext_factor;
  24. theta = theta_interp * (1 - ramp_mix) + theta_extrap * ramp_mix;
  25. // Get n-d magnitude scaling corrected for interpolation
  26. mscale *= 1.0f + 0.1f * sycl::log(1.0f / freq_scale);
  27. }
  28. *cos_theta = sycl::cos(theta) * mscale;
  29. *sin_theta = sycl::sin(theta) * mscale;
  30. }
  31. template <typename T, bool has_ff>
  32. static void rope_norm(const T * x, T * dst, const int ne0, const int ne1, const int s1, const int s2, const int n_dims,
  33. const int32_t * pos, float freq_scale, float ext_factor, float attn_factor,
  34. const rope_corr_dims corr_dims, const float theta_scale, const float * freq_factors,
  35. const sycl::nd_item<3> & item_ct1) {
  36. const int i0 = 2 * (item_ct1.get_local_range(1) * item_ct1.get_group(1) + item_ct1.get_local_id(1));
  37. if (i0 >= ne0) {
  38. return;
  39. }
  40. const int row = item_ct1.get_local_range(2) * item_ct1.get_group(2) + item_ct1.get_local_id(2);
  41. if (i0 >= n_dims) {
  42. const int i = row * ne0 + i0;
  43. *reinterpret_cast<sycl::vec<T, 2> *>(dst + i) = *reinterpret_cast<const sycl::vec<T, 2> *>(x + i);
  44. return;
  45. }
  46. const int row0 = row % ne1;
  47. const int channel0 = row / ne1;
  48. const int i = row * ne0 + i0;
  49. const int i2 = channel0 * s2 + row0 * s1 + i0;
  50. const float theta_base = pos[channel0] * sycl::pow(theta_scale, i0 / 2.0f);
  51. const float freq_factor = has_ff ? freq_factors[i0 / 2] : 1.0f;
  52. float cos_theta;
  53. float sin_theta;
  54. rope_yarn(theta_base / freq_factor, freq_scale, corr_dims, i0, ext_factor, attn_factor, &cos_theta, &sin_theta);
  55. const float x0 = x[i2 + 0];
  56. const float x1 = x[i2 + 1];
  57. dst[i + 0] = x0 * cos_theta - x1 * sin_theta;
  58. dst[i + 1] = x0 * sin_theta + x1 * cos_theta;
  59. }
  60. template <typename T, bool has_ff>
  61. static void rope_neox(const T * x, T * dst, const int ne0, const int ne1, const int s1, const int s2, const int n_dims,
  62. const int32_t * pos, const float freq_scale, const float ext_factor, const float attn_factor,
  63. const rope_corr_dims corr_dims, const float theta_scale, const float * freq_factors,
  64. const sycl::nd_item<3> & item_ct1) {
  65. const int i0 = 2 * (item_ct1.get_local_range(1) * item_ct1.get_group(1) + item_ct1.get_local_id(1));
  66. if (i0 >= ne0) {
  67. return;
  68. }
  69. const int row = item_ct1.get_local_range(2) * item_ct1.get_group(2) + item_ct1.get_local_id(2);
  70. if (i0 >= n_dims) {
  71. const int i = row * ne0 + i0;
  72. *reinterpret_cast<sycl::vec<T, 2> *>(dst + i) = *reinterpret_cast<const sycl::vec<T, 2> *>(x + i);
  73. return;
  74. }
  75. const int row0 = row % ne1;
  76. const int channel0 = row / ne1;
  77. const int i = row * ne0 + i0 / 2;
  78. const int i2 = channel0 * s2 + row0 * s1 + i0 / 2;
  79. const float theta_base = pos[channel0] * sycl::pow(theta_scale, i0 / 2.0f);
  80. const float freq_factor = has_ff ? freq_factors[i0 / 2] : 1.0f;
  81. float cos_theta;
  82. float sin_theta;
  83. rope_yarn(theta_base / freq_factor, freq_scale, corr_dims, i0, ext_factor, attn_factor, &cos_theta, &sin_theta);
  84. const float x0 = x[i2 + 0];
  85. const float x1 = x[i2 + n_dims / 2];
  86. dst[i + 0] = x0 * cos_theta - x1 * sin_theta;
  87. dst[i + n_dims / 2] = x0 * sin_theta + x1 * cos_theta;
  88. }
  89. template <typename T, bool has_ff>
  90. static void rope_multi(const T * x, T * dst, const int ne0, const int ne1, const int ne2, const size_t s1,
  91. const size_t s2, const int n_dims, const int32_t * pos, const float freq_scale,
  92. const float ext_factor, const float attn_factor, const rope_corr_dims corr_dims,
  93. const float theta_scale, const float * freq_factors, const mrope_sections sections,
  94. const sycl::nd_item<3> & item_ct1) {
  95. // get index pos
  96. const int i0 = 2 * (item_ct1.get_group(1) * item_ct1.get_local_range(1) + item_ct1.get_local_id(1));
  97. if (i0 >= ne0) {
  98. return;
  99. }
  100. const int row_dst = (item_ct1.get_group(2) * item_ct1.get_local_range(2)) + item_ct1.get_local_id(2);
  101. if (i0 >= n_dims) {
  102. const int i = row_dst*ne0 + i0;
  103. *reinterpret_cast<sycl::vec<T, 2> *>(dst + i) = *reinterpret_cast<const sycl::vec<T, 2> *>(x + i);
  104. return;
  105. }
  106. const int row_x = row_dst % ne1;
  107. const int channel_x = row_dst / ne1;
  108. const int idst = (row_dst * ne0) + (i0 / 2);
  109. const size_t ix = ((size_t) channel_x * s2) + ((size_t) row_x * s1) + (i0 / 2);
  110. const int sect_dims = sections.v[0] + sections.v[1] + sections.v[2] + sections.v[3];
  111. const int sec_w = sections.v[1] + sections.v[0];
  112. const int sector = (i0 / 2) % sect_dims;
  113. float theta_base = 0.0;
  114. if (sector < sections.v[0]) {
  115. theta_base = pos[channel_x]*sycl::pow(theta_scale, i0/2.0f);
  116. }
  117. else if (sector >= sections.v[0] && sector < sec_w) {
  118. theta_base = pos[channel_x + ne2 * 1]*sycl::pow(theta_scale, i0/2.0f);
  119. }
  120. else if (sector >= sec_w && sector < sec_w + sections.v[2]) {
  121. theta_base = pos[channel_x + ne2 * 2]*sycl::pow(theta_scale, i0/2.0f);
  122. }
  123. else if (sector >= sec_w + sections.v[2]) {
  124. theta_base = pos[channel_x + ne2 * 3]*sycl::pow(theta_scale, i0/2.0f);
  125. }
  126. const float freq_factor = has_ff ? freq_factors[i0 / 2] : 1.0f;
  127. float cos_theta;
  128. float sin_theta;
  129. rope_yarn(theta_base / freq_factor, freq_scale, corr_dims, i0, ext_factor, attn_factor, &cos_theta, &sin_theta);
  130. const float x0 = x[ix + 0];
  131. const float x1 = x[ix + n_dims/2];
  132. // store results in dst
  133. dst[idst + 0] = x0 * cos_theta - x1 * sin_theta;
  134. dst[idst + n_dims/2] = x0 * sin_theta + x1 * cos_theta;
  135. }
  136. template <typename T, bool has_ff>
  137. static void rope_vision(const T * x, T * dst, const int ne0, const int ne1, const int ne2, const size_t s1,
  138. const size_t s2, const int n_dims, const int32_t * pos, const float freq_scale,
  139. const float ext_factor, const float attn_factor, const rope_corr_dims corr_dims,
  140. const float theta_scale, const float * freq_factors, const mrope_sections sections,
  141. const sycl::nd_item<3> & item_ct1) {
  142. // get index pos
  143. const int i0 = 2 * (item_ct1.get_group(1) * item_ct1.get_local_range(1) + item_ct1.get_local_id(1));
  144. if (i0 >= ne0) {
  145. return;
  146. }
  147. const int row_dst = (item_ct1.get_group(2) * item_ct1.get_local_range(2)) + item_ct1.get_local_id(2);
  148. const int row_x = row_dst % ne1;
  149. const int channel_x = row_dst / ne1;
  150. const int idst = (row_dst * ne0) + (i0 / 2);
  151. const size_t ix = ((size_t) channel_x * s2) + ((size_t) row_x * s1) + (i0 / 2);
  152. const int sect_dims = sections.v[0] + sections.v[1];
  153. const int sector = (i0 / 2) % sect_dims;
  154. float theta_base = 0.0f;
  155. if (sector < sections.v[0]) {
  156. const int p = sector;
  157. theta_base = pos[channel_x] * sycl::pow(theta_scale, (float) p);
  158. } else {
  159. // Simplified from CUDA backend code: if (sector >= sections.v[0] && sector < sec_w) which is just sector >= sections.v[0]
  160. const int p = sector - sections.v[0];
  161. theta_base = pos[channel_x + ne2] * sycl::pow(theta_scale, (float) p);
  162. }
  163. const float freq_factor = has_ff ? freq_factors[i0 / 2] : 1.0f;
  164. float cos_theta;
  165. float sin_theta;
  166. rope_yarn(theta_base / freq_factor, freq_scale, corr_dims, i0, ext_factor, attn_factor, &cos_theta, &sin_theta);
  167. const float x0 = x[ix + 0];
  168. const float x1 = x[ix + n_dims];
  169. // store results in dst
  170. dst[idst + 0] = x0 * cos_theta - x1 * sin_theta;
  171. dst[idst + n_dims] = x0 * sin_theta + x1 * cos_theta;
  172. }
  173. template <typename T>
  174. static void rope_norm_sycl(const T * x, T * dst, const int ne0, const int ne1, const int s1, const int s2,
  175. const int n_dims, int nr, const int32_t * pos, const float freq_scale, const float freq_base,
  176. const float ext_factor, const float attn_factor, const rope_corr_dims corr_dims,
  177. const float * freq_factors, queue_ptr stream) {
  178. GGML_ASSERT(ne0 % 2 == 0);
  179. const sycl::range<3> block_dims(1, SYCL_ROPE_BLOCK_SIZE, 1);
  180. const int num_blocks_x = ceil_div(ne0, (2 * SYCL_ROPE_BLOCK_SIZE));
  181. const sycl::range<3> block_nums(1, num_blocks_x, nr);
  182. const float theta_scale = powf(freq_base, -2.0f / n_dims);
  183. dpct::has_capability_or_fail(stream->get_device(), { sycl::aspect::fp16 });
  184. if (freq_factors == nullptr) {
  185. /*
  186. DPCT1049:40: The work-group size passed to the SYCL kernel may exceed
  187. the limit. To get the device limit, query
  188. info::device::max_work_group_size. Adjust the work-group size if needed.
  189. */
  190. stream->parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), [=](sycl::nd_item<3> item_ct1) {
  191. rope_norm<T, false>(x, dst, ne0, ne1, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor, corr_dims,
  192. theta_scale, freq_factors, item_ct1);
  193. });
  194. } else {
  195. /*
  196. DPCT1049:41: The work-group size passed to the SYCL kernel may exceed
  197. the limit. To get the device limit, query
  198. info::device::max_work_group_size. Adjust the work-group size if needed.
  199. */
  200. stream->parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), [=](sycl::nd_item<3> item_ct1) {
  201. rope_norm<T, true>(x, dst, ne0, ne1, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor, corr_dims,
  202. theta_scale, freq_factors, item_ct1);
  203. });
  204. }
  205. }
  206. template <typename T>
  207. static void rope_neox_sycl(const T * x, T * dst, const int ne0, const int ne1, const int s1, const int s2,
  208. const int n_dims, const int nr, const int32_t * pos, const float freq_scale,
  209. const float freq_base, const float ext_factor, const float attn_factor,
  210. const rope_corr_dims corr_dims, const float * freq_factors, queue_ptr stream) {
  211. GGML_ASSERT(ne0 % 2 == 0);
  212. const sycl::range<3> block_dims(1, SYCL_ROPE_BLOCK_SIZE, 1);
  213. const int num_blocks_x = ceil_div(ne0, (2 * SYCL_ROPE_BLOCK_SIZE));
  214. const sycl::range<3> block_nums(1, num_blocks_x, nr);
  215. const float theta_scale = powf(freq_base, -2.0f / n_dims);
  216. dpct::has_capability_or_fail(stream->get_device(), { sycl::aspect::fp16 });
  217. if (freq_factors == nullptr) {
  218. stream->parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), [=](sycl::nd_item<3> item_ct1) {
  219. rope_neox<T, false>(x, dst, ne0, ne1, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor, corr_dims,
  220. theta_scale, freq_factors, item_ct1);
  221. });
  222. } else {
  223. stream->parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), [=](sycl::nd_item<3> item_ct1) {
  224. rope_neox<T, true>(x, dst, ne0, ne1, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor, corr_dims,
  225. theta_scale, freq_factors, item_ct1);
  226. });
  227. }
  228. }
  229. template <typename T>
  230. static void rope_multi_sycl(const T * x, T * dst, const int ne0, const int ne1, const int ne2, const size_t s1,
  231. const size_t s2, const int n_dims, const int nr, const int32_t * pos,
  232. const float freq_scale, const float freq_base, const float ext_factor,
  233. const float attn_factor, const rope_corr_dims corr_dims, const float * freq_factors,
  234. const mrope_sections sections, queue_ptr stream) {
  235. GGML_ASSERT(ne0 % 2 == 0);
  236. const sycl::range<3> block_dims(1, SYCL_ROPE_BLOCK_SIZE, 1);
  237. const int n_blocks_y = ceil_div(ne0, (2 * SYCL_ROPE_BLOCK_SIZE));
  238. const sycl::range<3> grid_dims(1, n_blocks_y, nr);
  239. const sycl::nd_range<3> nd_range(grid_dims * block_dims, block_dims);
  240. const float theta_scale = std::pow(freq_base, -2.0f / n_dims);
  241. // Add FP16 capability check if T could be sycl::half
  242. if constexpr (std::is_same_v<T, sycl::half>) {
  243. dpct::has_capability_or_fail(stream->get_device(), { sycl::aspect::fp16 });
  244. }
  245. // launch kernel
  246. if (freq_factors == nullptr) {
  247. stream->parallel_for(nd_range, [=](sycl::nd_item<3> item_ct1) {
  248. rope_multi<T, false>(x, dst, ne0, ne1, ne2, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor,
  249. corr_dims, theta_scale, freq_factors, sections, item_ct1);
  250. });
  251. } else {
  252. stream->parallel_for(nd_range, [=](sycl::nd_item<3> item_ct1) {
  253. rope_multi<T, true>(x, dst, ne0, ne1, ne2, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor,
  254. corr_dims, theta_scale, freq_factors, sections, item_ct1);
  255. });
  256. }
  257. }
  258. // rope vision
  259. template <typename T>
  260. static void rope_vision_sycl(const T * x, T * dst, const int ne0, const int ne1, const int ne2, const size_t s1,
  261. const size_t s2, const int n_dims, const int nr, const int32_t * pos,
  262. const float freq_scale, const float freq_base, const float ext_factor,
  263. const float attn_factor, const rope_corr_dims corr_dims, const float * freq_factors,
  264. const mrope_sections sections, queue_ptr stream) {
  265. GGML_ASSERT(ne0 % 2 == 0);
  266. const sycl::range<3> block_dims(1, SYCL_ROPE_BLOCK_SIZE, 1);
  267. const int n_blocks_y = ceil_div(ne0, (2 * SYCL_ROPE_BLOCK_SIZE));
  268. const sycl::range<3> grid_dims(1, n_blocks_y, nr);
  269. const sycl::nd_range<3> nd_range(grid_dims * block_dims, block_dims);
  270. const float theta_scale = std::pow(freq_base, -2.0f / n_dims);
  271. // Add FP16 capability check if T could be sycl::half
  272. if constexpr (std::is_same_v<T, sycl::half>) {
  273. dpct::has_capability_or_fail(stream->get_device(), { sycl::aspect::fp16 });
  274. }
  275. // launch kernel
  276. if (freq_factors == nullptr) {
  277. stream->parallel_for(nd_range, [=](sycl::nd_item<3> item_ct1) {
  278. rope_vision<T, false>(x, dst, ne0, ne1, ne2, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor,
  279. corr_dims, theta_scale, freq_factors, sections, item_ct1);
  280. });
  281. } else {
  282. stream->parallel_for(nd_range, [=](sycl::nd_item<3> item_ct1) {
  283. rope_vision<T, true>(x, dst, ne0, ne1, ne2, s1, s2, n_dims, pos, freq_scale, ext_factor, attn_factor,
  284. corr_dims, theta_scale, freq_factors, sections, item_ct1);
  285. });
  286. }
  287. }
  288. inline void ggml_sycl_op_rope(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
  289. GGML_ASSERT(dst->src[0]->type == GGML_TYPE_F32 || dst->src[0]->type == GGML_TYPE_F16);
  290. GGML_ASSERT( dst->type == GGML_TYPE_F32 || dst->type == GGML_TYPE_F16);
  291. GGML_ASSERT(dst->src[0]->type == dst->type);
  292. const int64_t ne00 = dst->src[0]->ne[0]; // head dims
  293. const int64_t ne01 = dst->src[0]->ne[1]; // num heads
  294. const int64_t ne02 = dst->src[0]->ne[2]; // num heads
  295. const int64_t nr = ggml_nrows(dst->src[0]);
  296. const size_t s01 = dst->src[0]->nb[1] / ggml_type_size(dst->src[0]->type);
  297. const size_t s02 = dst->src[0]->nb[2] / ggml_type_size(dst->src[0]->type);
  298. //const int n_past = ((int32_t *) dst->op_params)[0];
  299. const int n_dims = ((int32_t *) dst->op_params)[1];
  300. const int mode = ((int32_t *) dst->op_params)[2];
  301. //const int n_ctx = ((int32_t *) dst->op_params)[3];
  302. const int n_ctx_orig = ((int32_t *) dst->op_params)[4];
  303. mrope_sections sections;
  304. // RoPE alteration for extended context
  305. float freq_base;
  306. float freq_scale;
  307. float ext_factor;
  308. float attn_factor;
  309. float beta_fast;
  310. float beta_slow;
  311. memcpy(&freq_base, (int32_t *) dst->op_params + 5, sizeof(float));
  312. memcpy(&freq_scale, (int32_t *) dst->op_params + 6, sizeof(float));
  313. memcpy(&ext_factor, (int32_t *) dst->op_params + 7, sizeof(float));
  314. memcpy(&attn_factor, (int32_t *) dst->op_params + 8, sizeof(float));
  315. memcpy(&beta_fast, (int32_t *) dst->op_params + 9, sizeof(float));
  316. memcpy(&beta_slow, (int32_t *) dst->op_params + 10, sizeof(float));
  317. memcpy(&sections.v, (int32_t *) dst->op_params + 11, sizeof(int)*4);
  318. const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
  319. const bool is_mrope = mode & GGML_ROPE_TYPE_MROPE;
  320. const bool is_vision = mode == GGML_ROPE_TYPE_VISION;
  321. if (is_mrope) {
  322. GGML_ASSERT(sections.v[0] > 0 || sections.v[1] > 0 || sections.v[2] > 0);
  323. }
  324. if (is_vision) {
  325. GGML_ASSERT(n_dims == ne00/2);
  326. }
  327. const int32_t * pos = (const int32_t *) dst->src[1]->data;
  328. const float * freq_factors = nullptr;
  329. if (dst->src[2] != nullptr) {
  330. freq_factors = (const float *) dst->src[2]->data;
  331. }
  332. rope_corr_dims corr_dims;
  333. ggml_rope_yarn_corr_dims(n_dims, n_ctx_orig, freq_base, beta_fast, beta_slow, corr_dims.v);
  334. dpct::queue_ptr main_stream = ctx.stream();
  335. SYCL_CHECK(ggml_sycl_set_device(ctx.device));
  336. // compute
  337. if (is_neox) {
  338. GGML_SYCL_DEBUG("%s: neox path\n", __func__);
  339. if (dst->src[0]->type == GGML_TYPE_F32) {
  340. rope_neox_sycl((const float *) dst->src[0]->data, (float *) dst->data, ne00, ne01, s01, s02, n_dims, nr,
  341. pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims, freq_factors, main_stream);
  342. } else if (dst->src[0]->type == GGML_TYPE_F16) {
  343. rope_neox_sycl((const sycl::half *) dst->src[0]->data, (sycl::half *) dst->data, ne00, ne01, s01, s02,
  344. n_dims, nr, pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims, freq_factors,
  345. main_stream);
  346. } else {
  347. GGML_ABORT("fatal error");
  348. }
  349. } else if (is_mrope && !is_vision) {
  350. GGML_SYCL_DEBUG("%s: mrope path\n", __func__);
  351. if (dst->src[0]->type == GGML_TYPE_F16) {
  352. rope_multi_sycl((const sycl::half *)dst->src[0]->data, (sycl::half *)dst->data, ne00, ne01, ne02, s01,
  353. s02, n_dims, nr, pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims,
  354. freq_factors, sections, main_stream);
  355. } else if (dst->src[0]->type == GGML_TYPE_F32) {
  356. rope_multi_sycl((const float *) dst->src[0]->data, (float *) dst->data, ne00, ne01, ne02, s01, s02, n_dims,
  357. nr, pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims, freq_factors, sections,
  358. main_stream);
  359. } else {
  360. GGML_ABORT("Fatal error: Tensor type unsupported!");
  361. }
  362. } else if (is_vision) {
  363. GGML_SYCL_DEBUG("%s: vision path\n", __func__);
  364. if (dst->src[0]->type == GGML_TYPE_F16) {
  365. rope_vision_sycl((const sycl::half *) dst->src[0]->data, (sycl::half *) dst->data, ne00, ne01, ne02, s01,
  366. s02, n_dims, nr, pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims,
  367. freq_factors, sections, main_stream);
  368. } else if (dst->src[0]->type == GGML_TYPE_F32) {
  369. rope_vision_sycl((const float *) dst->src[0]->data, (float *) dst->data, ne00, ne01, ne02, s01, s02, n_dims,
  370. nr, pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims, freq_factors, sections,
  371. main_stream);
  372. } else {
  373. GGML_ABORT("Fatal error: Tensor type unsupported!");
  374. }
  375. } else {
  376. GGML_SYCL_DEBUG("%s: norm path\n", __func__);
  377. if (dst->src[0]->type == GGML_TYPE_F32) {
  378. rope_norm_sycl((const float *) dst->src[0]->data, (float *) dst->data, ne00, ne01, s01, s02, n_dims, nr,
  379. pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims, freq_factors, main_stream);
  380. } else if (dst->src[0]->type == GGML_TYPE_F16) {
  381. rope_norm_sycl((const sycl::half *) dst->src[0]->data, (sycl::half *) dst->data, ne00, ne01, s01, s02,
  382. n_dims, nr, pos, freq_scale, freq_base, ext_factor, attn_factor, corr_dims, freq_factors,
  383. main_stream);
  384. } else {
  385. GGML_ABORT("fatal error");
  386. }
  387. }
  388. }
  389. void ggml_sycl_rope(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
  390. scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/3);
  391. ggml_sycl_op_rope(ctx, dst);
  392. }