char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
47e1de77a
char/aliceai-t5-moe
1#include "col2im-1d.hpp" 2 3template < typename T > 4static void col2im_1d_sycl ( 5const T * col , 6T * dst , 7const int T_in , 8const sycl::uint3 T_out_fd , 9const int K , 10const int K_OC , 11const int32_t s0 , 12const int32_t p0 , 13const int total , 14 dpct::queue_ptr stream ) { 15 16const uint32_t block_size = SYCL_COL2IM_1D_BLOCK_SIZE ; 17const uint32_t num_blocks = (uint32_t ) ((total + block_size - 1 ) /block_size ); 18 19stream -> parallel_for ( 20 sycl::nd_range < 3 > ( 21 sycl::range < 3 > (1 ,1 ,num_blocks * block_size ), 22 sycl::range < 3 > (1 ,1 ,block_size )), 23 [= ](sycl::nd_item < 3 > item_ct1 ) { 24const int idx = (int )item_ct1 .get_global_id (2 ); 25if (idx >=total ) { 26return ; 27 } 28 29const sycl::uint2 qr = fast_div_modulo ((uint32_t )idx ,T_out_fd ); 30const int oc = (int )qr .x (); 31const int t_out = (int )qr .y (); 32const int t_abs = t_out + p0 ; 33 34int t_in_min = (t_abs - K + s0 ) /s0 ; 35if (t_in_min < 0 ) { 36t_in_min = 0 ; 37 } 38int t_in_max = t_abs /s0 ; 39if (t_in_max >=T_in ) { 40t_in_max = T_in - 1 ; 41 } 42 43float sum = 0.0f ; 44for (int t_in = t_in_min ;t_in <=t_in_max ;++ t_in ) { 45const int k = t_abs - t_in * s0 ; 46sum += static_cast < float > (col [(oc * K + k )+ t_in * K_OC ]); 47 } 48 49dst [idx ]= static_cast < T > (sum ); 50 }); 51} 52 53void ggml_sycl_op_col2im_1d (ggml_backend_sycl_context & ctx ,ggml_tensor * dst ) { 54const ggml_tensor * src0 = dst -> src [0 ]; 55 56GGML_ASSERT (src0 != nullptr ); 57GGML_ASSERT (ggml_is_contiguous (src0 )); 58GGML_ASSERT (src0 -> type == dst -> type ); 59 60const int32_t s0 = ((const int32_t * )dst -> op_params )[0 ]; 61const int32_t OC = ((const int32_t * )dst -> op_params )[1 ]; 62const int32_t p0 = ((const int32_t * )dst -> op_params )[2 ]; 63 64const int K_OC = (int )src0 -> ne [0 ]; 65const int T_in = (int )src0 -> ne [1 ]; 66const int K = K_OC /OC ; 67const int T_out = (int )dst -> ne [0 ]; 68 69GGML_ASSERT (OC > 0 ); 70GGML_ASSERT (K_OC %OC == 0 ); 71 72const sycl::uint3 T_out_fd = init_fastdiv_values ((uint32_t )T_out ); 73 74const int total = T_out * OC ; 75 76 dpct::queue_ptr stream = ctx .stream (); 77 78switch (src0 -> type ) { 79case GGML_TYPE_F32 : 80col2im_1d_sycl < float > ( 81 (const float * )src0 -> data , 82 (float * )dst -> data , 83T_in ,T_out_fd ,K ,K_OC ,s0 ,p0 ,total ,stream ); 84break ; 85case GGML_TYPE_F16 : 86col2im_1d_sycl < sycl::half > ( 87 (const sycl::half * )src0 -> data , 88 (sycl::half * )dst -> data , 89T_in ,T_out_fd ,K ,K_OC ,s0 ,p0 ,total ,stream ); 90break ; 91#ifdef GGML_SYCL_HAS_BF16 92case GGML_TYPE_BF16 : 93col2im_1d_sycl < sycl::ext::oneapi::bfloat16 > ( 94 (const sycl::ext::oneapi::bfloat16 * )src0 -> data , 95 (sycl::ext::oneapi::bfloat16 * )dst -> data , 96T_in ,T_out_fd ,K ,K_OC ,s0 ,p0 ,total ,stream ); 97break ; 98#endif 99default : 100GGML_ABORT ("col2im_1d: unsupported type %d" ,src0 -> type ); 101 } 102}