Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-sycl/fill.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-sycl / fill.cpp` 55 lines ยท 1807 bytes Raw Blame History 1 #include "fill.hpp" 2 #include "common.hpp" 3 4 #define SYCL_FILL_BLOCK_SIZE 256 5 6 template 7 static void fill_kernel(T * dst, const int64_t k, const T value, 8 const sycl::nd_item<1> & item) { 9 const int64_t i = (int64_t)item.get_global_id(0); 10 if (i >= k) { 11 return; 12 } 13 dst[i] = value; 14 } 15 16 inline void ggml_sycl_op_fill(ggml_backend_sycl_context & ctx, ggml_tensor * dst) { 17 GGML_ASSERT(ggml_is_contiguous(dst)); 18 19 dpct::queue_ptr stream = ctx.stream(); 20 SYCL_CHECK(ggml_sycl_set_device(ctx.device)); 21 22 float value; 23 memcpy(&value, dst->op_params, sizeof(float)); 24 25 const int64_t k = ggml_nelements(dst); 26 const int64_t num_blocks = (k + SYCL_FILL_BLOCK_SIZE - 1) / SYCL_FILL_BLOCK_SIZE; 27 void * dst_d = dst->data; 28 29 switch (dst->type) { 30 case GGML_TYPE_F32: 31 stream->parallel_for( 32 sycl::nd_range<1>(num_blocks * SYCL_FILL_BLOCK_SIZE, SYCL_FILL_BLOCK_SIZE), 33 [=](sycl::nd_item<1> item) { 34 fill_kernel(static_cast(dst_d), k, value, item); 35 }); 36 break; 37 case GGML_TYPE_F16: 38 { 39 sycl::half h_value = sycl::half(value); 40 stream->parallel_for( 41 sycl::nd_range<1>(num_blocks * SYCL_FILL_BLOCK_SIZE, SYCL_FILL_BLOCK_SIZE), 42 [=](sycl::nd_item<1> item) { 43 fill_kernel(static_cast(dst_d), k, h_value, item); 44 }); 45 } 46 break; 47 default: 48 GGML_ABORT("unsupported type"); 49 } 50 } 51 52 void ggml_sycl_fill(ggml_backend_sycl_context & ctx, ggml_tensor * dst) { 53 scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/0); 54 ggml_sycl_op_fill(ctx, dst); 55 }