char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
ad0922465
char/aliceai-t5-moe
1#include "diag.hpp" 2#include "common.hpp" 3 4#define SYCL_DIAG_BLOCK_SIZE 256 5 6template < typename T > 7static void diag_kernel (T * __restrict__dst ,const T * __restrict__src , 8const int64_t ne0 ,const int64_t ne1 , 9const int64_t ne2 ,const int64_t ne3 , 10const int64_t total_elements , 11const sycl::nd_item < 1 > & item ) { 12const int64_t i = item .get_global_id (0 ); 13if (i >=total_elements ) { 14return ; 15 } 16 17const int64_t i0 = i %ne0 ; 18const int64_t i1 = (i /ne0 ) %ne1 ; 19const int64_t i2 = (i / (ne0 * ne1 )) %ne2 ; 20const int64_t i3 = i / (ne0 * ne1 * ne2 ); 21 22const int64_t dst_idx = ((i3 * ne2 + i2 )* ne1 + i1 )* ne0 + i0 ; 23 24if (i0 == i1 ) { 25const int64_t batch_idx = i3 * ne2 + i2 ; 26dst [dst_idx ]= src [batch_idx * ne0 + i0 ]; 27 }else { 28dst [dst_idx ]= T (0 ); 29 } 30 31 (void )ne3 ; 32} 33 34inline void ggml_sycl_op_diag (ggml_backend_sycl_context & ctx ,ggml_tensor * dst ) { 35const ggml_tensor * src0 = dst -> src [0 ]; 36 37GGML_ASSERT (ggml_is_contiguous (dst )); 38GGML_ASSERT (ggml_is_contiguous (src0 )); 39GGML_ASSERT (src0 -> ne [1 ]== 1 ); 40 41 dpct::queue_ptr stream = ctx .stream (); 42SYCL_CHECK (ggml_sycl_set_device (ctx .device )); 43 44const void * src0_d = src0 -> data ; 45void * dst_d = dst -> data ; 46 47const int64_t ne0 = dst -> ne [0 ]; 48const int64_t ne1 = dst -> ne [1 ]; 49const int64_t ne2 = dst -> ne [2 ]; 50const int64_t ne3 = dst -> ne [3 ]; 51const int64_t n_elems = ggml_nelements (dst ); 52const int64_t num_blocks = (n_elems + SYCL_DIAG_BLOCK_SIZE - 1 ) /SYCL_DIAG_BLOCK_SIZE ; 53 54GGML_ASSERT (dst -> type == GGML_TYPE_F32 ); 55stream -> parallel_for ( 56 sycl::nd_range < 1 > (num_blocks * SYCL_DIAG_BLOCK_SIZE ,SYCL_DIAG_BLOCK_SIZE ), 57 [= ](sycl::nd_item < 1 > item ) { 58diag_kernel (static_cast < float *> (dst_d ), 59static_cast < const float *> (src0_d ), 60ne0 ,ne1 ,ne2 ,ne3 ,n_elems ,item ); 61 }); 62} 63 64void ggml_sycl_diag (ggml_backend_sycl_context & ctx ,ggml_tensor * dst ) { 65scope_op_debug_print scope_dbg_print (__func__ ,dst ,/*num_src=*/ 1 ); 66ggml_sycl_op_diag (ctx ,dst ); 67}