char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
53dc8b59b
char/aliceai-t5-moe
1#include <sycl/sycl.hpp> 2#include "common.hpp" 3#include "add-id.hpp" 4 5static void add_id_kernel ( 6const float * src0 , 7const float * src1 , 8const int32_t * src2 , 9float * dst , 10int64_t ne0 , 11int64_t ne1 , 12size_t nb01 , 13size_t nb02 , 14size_t nb11 , 15size_t nb21 , 16 sycl::nd_item < 3 > item_ct1 ) { 17const int64_t i1 = item_ct1 .get_group (2 ); 18const int64_t i2 = item_ct1 .get_group (1 ); 19 20const int i11 = 21* (const int32_t * )((const char * )src2 + i1 * sizeof (int32_t )+ i2 * nb21 ); 22 23const size_t nb1 = ne0 * sizeof (float ); 24const size_t nb2 = ne1 * nb1 ; 25 26float * dst_row = (float * )((char * )dst + i1 * nb1 + i2 * nb2 ); 27const float * src0_row = 28 (const float * )((const char * )src0 + i1 * nb01 + i2 * nb02 ); 29const float * src1_row = (const float * )((const char * )src1 + i11 * nb11 ); 30 31for (int64_t i0 = item_ct1 .get_local_id (2 );i0 < ne0 ; 32i0 += item_ct1 .get_local_range (2 )) { 33dst_row [i0 ]= src0_row [i0 ]+ src1_row [i0 ]; 34 } 35} 36 37void ggml_sycl_add_id (ggml_backend_sycl_context & ctx ,ggml_tensor * dst ) { 38const ggml_tensor * src0 = dst -> src [0 ]; 39const ggml_tensor * src1 = dst -> src [1 ]; 40const ggml_tensor * src2 = dst -> src [2 ]; 41 42GGML_TENSOR_TERNARY_OP_LOCALS 43 44GGML_ASSERT (dst -> type == GGML_TYPE_F32 ); 45GGML_ASSERT (src0 -> type == GGML_TYPE_F32 ); 46GGML_ASSERT (src1 -> type == GGML_TYPE_F32 ); 47GGML_ASSERT (src2 -> type == GGML_TYPE_I32 ); 48 49GGML_ASSERT (nb00 == sizeof (float )); 50GGML_ASSERT (nb10 == sizeof (float )); 51GGML_ASSERT (nb20 == sizeof (int32_t )); 52 53const float * src0_d = (const float * )src0 -> data ; 54const float * src1_d = (const float * )src1 -> data ; 55const int32_t * src2_d = (const int32_t * )src2 -> data ; 56float * dst_d = (float * )dst -> data ; 57 58const unsigned int max_work_group_size = ggml_sycl_info ().max_work_group_sizes [ctx .device ]; 59GGML_ASSERT (max_work_group_size % (WARP_SIZE * WARP_SIZE )== 0 ); 60 61int threads = std::min ((unsigned int )ne00 ,max_work_group_size );// cols 62 63ctx .stream ()-> parallel_for ( 64 sycl::nd_range < 3 > ( 65 sycl::range < 3 > (1 ,ne02 ,ne01 )* sycl::range < 3 > (1 ,1 ,threads ), 66 sycl::range < 3 > (1 ,1 ,threads )), 67 [= ](sycl::nd_item < 3 > item_ct1 ) { 68add_id_kernel ( 69src0_d , 70src1_d , 71src2_d , 72dst_d , 73ne0 , 74ne1 , 75nb01 , 76nb02 , 77nb11 , 78nb21 , 79item_ct1 ); 80 }); 81}