|
| 1 | +#include "pad_reflect_d1.hpp" |
| 2 | + |
| 3 | +void pad_reflect_d1_f32(const float* src,float* dst, |
| 4 | + const int64_t ne0, const int64_t ne02, const int p0, const int p1, |
| 5 | + const int64_t nb0, const int64_t nb1, const int64_t nb2, const int64_t nb3, |
| 6 | + const int64_t nb00, const int64_t nb01, const int64_t nb02, const int64_t nb03, |
| 7 | + const sycl::nd_item<3> &item_ct1){ |
| 8 | + |
| 9 | + const int i0 = item_ct1.get_group(0) * SYCL_CONCAT_BLOCK_SIZE + item_ct1.get_local_id(0); |
| 10 | + const int i1 = item_ct1.get_group(1); |
| 11 | + const int g2 = item_ct1.get_group(2); |
| 12 | + const int i2 = g2 % ne02; |
| 13 | + const int i3 = g2 / ne02; |
| 14 | + |
| 15 | + if (i0 >= p0 + ne0 + p1) return; |
| 16 | + |
| 17 | + int t = i0 - p0; |
| 18 | + int period = 2 * ne0 -2; |
| 19 | + int m = t % period; |
| 20 | + m += (m < 0) * period; |
| 21 | + int center = ne0 -1; |
| 22 | + int srci0 = center - abs(center - m); |
| 23 | + |
| 24 | + int offest_src = i3*nb3 + i2*nb2 + i1*nb1 + srci0*nb0; |
| 25 | + int offest_dst = i3*nb03 + i2*nb02 + i1*nb01 + i0*nb00; |
| 26 | + dst[offest_dst] = src[offest_src]; |
| 27 | + |
| 28 | +} |
| 29 | + |
| 30 | +void ggml_sycl_op_pad_reflect_d1(ggml_backend_sycl_context& ctx, ggml_tensor* dst){ |
| 31 | + |
| 32 | + const ggml_tensor * src0 = dst->src[0]; |
| 33 | + queue_ptr stream = ctx.stream(); |
| 34 | + |
| 35 | + GGML_ASSERT(src0->type == GGML_TYPE_F32); |
| 36 | + GGML_ASSERT( dst->type == GGML_TYPE_F32); |
| 37 | + |
| 38 | + const int32_t * opts = (const int32_t *) dst->op_params; |
| 39 | + const int p0 = opts[0]; |
| 40 | + const int p1 = opts[1]; |
| 41 | + |
| 42 | + const int64_t ne0 = src0->ne[0]; |
| 43 | + |
| 44 | + const int64_t ne00 = dst->ne[0]; |
| 45 | + const int64_t ne01 = dst->ne[1]; |
| 46 | + const int64_t ne02 = dst->ne[2]; |
| 47 | + const int64_t ne03 = dst->ne[3]; |
| 48 | + |
| 49 | + const int64_t nb00 = dst->nb[0]; |
| 50 | + const int64_t nb01 = dst->nb[1]; |
| 51 | + const int64_t nb02 = dst->nb[2]; |
| 52 | + const int64_t nb03 = dst->nb[3]; |
| 53 | + const int64_t nb0 = src0->nb[0]; |
| 54 | + const int64_t nb1 = src0->nb[1]; |
| 55 | + const int64_t nb2 = src0->nb[2]; |
| 56 | + const int64_t nb3 = src0->nb[3]; |
| 57 | + |
| 58 | + int num_blocks = (ne00 + SYCL_CONCAT_BLOCK_SIZE - 1) / SYCL_CONCAT_BLOCK_SIZE; |
| 59 | + |
| 60 | + sycl::range<3> global(num_blocks * SYCL_CONCAT_BLOCK_SIZE, ne01, ne02*ne03); |
| 61 | + sycl::range<3> local(SYCL_CONCAT_BLOCK_SIZE, 1, 1); |
| 62 | + |
| 63 | + stream->parallel_for( |
| 64 | + sycl::nd_range<3>(global, |
| 65 | + local), |
| 66 | + [=](sycl::nd_item<3> item_ct1) { pad_reflect_d1_f32( |
| 67 | + (const float *) src0->data, (float *) dst->data, |
| 68 | + ne0, ne02, p0, p1, |
| 69 | + nb0, nb1, nb2, nb3, |
| 70 | + nb00, nb01, nb02, nb03 |
| 71 | + , item_ct1); |
| 72 | + }); |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
0 commit comments