char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
ad0922465
char/aliceai-t5-moe
1#include "fill.hpp" 2#include "common.hpp" 3 4#define SYCL_FILL_BLOCK_SIZE 256 5 6template < typename T > 7static void fill_kernel (T * dst ,const int64_t k ,const T value , 8const sycl::nd_item < 1 > & item ) { 9const int64_t i = (int64_t )item .get_global_id (0 ); 10if (i >=k ) { 11return ; 12 } 13dst [i ]= value ; 14} 15 16inline void ggml_sycl_op_fill (ggml_backend_sycl_context & ctx ,ggml_tensor * dst ) { 17GGML_ASSERT (ggml_is_contiguous (dst )); 18 19 dpct::queue_ptr stream = ctx .stream (); 20SYCL_CHECK (ggml_sycl_set_device (ctx .device )); 21 22float value ; 23memcpy (& value ,dst -> op_params ,sizeof (float )); 24 25const int64_t k = ggml_nelements (dst ); 26const int64_t num_blocks = (k + SYCL_FILL_BLOCK_SIZE - 1 ) /SYCL_FILL_BLOCK_SIZE ; 27void * dst_d = dst -> data ; 28 29switch (dst -> type ) { 30case GGML_TYPE_F32 : 31stream -> parallel_for ( 32 sycl::nd_range < 1 > (num_blocks * SYCL_FILL_BLOCK_SIZE ,SYCL_FILL_BLOCK_SIZE ), 33 [= ](sycl::nd_item < 1 > item ) { 34fill_kernel (static_cast < float *> (dst_d ),k ,value ,item ); 35 }); 36break ; 37case GGML_TYPE_F16 : 38 { 39 sycl::half h_value = sycl::half (value ); 40stream -> parallel_for ( 41 sycl::nd_range < 1 > (num_blocks * SYCL_FILL_BLOCK_SIZE ,SYCL_FILL_BLOCK_SIZE ), 42 [= ](sycl::nd_item < 1 > item ) { 43fill_kernel (static_cast < sycl::half *> (dst_d ),k ,h_value ,item ); 44 }); 45 } 46break ; 47default : 48GGML_ABORT ("unsupported type" ); 49 } 50} 51 52void ggml_sycl_fill (ggml_backend_sycl_context & ctx ,ggml_tensor * dst ) { 53scope_op_debug_print scope_dbg_print (__func__ ,dst ,/*num_src=*/ 0 ); 54ggml_sycl_op_fill (ctx ,dst ); 55}