char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e20b83930
char/aliceai-t5-moe
1// 2// MIT license 3// Copyright (C) 2025 Intel Corporation 4// SPDX-License-Identifier: MIT 5// 6 7// 8// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 9// See https://llvm.org/LICENSE.txt for license information. 10// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 11// 12 13#ifndef GGML_SYCL_FATTN_BUFFERS_HPP 14#define GGML_SYCL_FATTN_BUFFERS_HPP 15 16#include <sycl/sycl.hpp> 17 18typedef sycl::queue * queue_ptr ; 19 20struct ggml_sycl_fattn_kv_buffers { 21// buffers grow in chunks of this size 22static constexpr size_t CHUNK_SIZE = 16ull <<20 ;// 16 MiB 23 24struct kv_buffer { 25kv_buffer (queue_ptr qptr_ ,int device_ ) :qptr (qptr_ ),device (device_ ) {} 26 ~kv_buffer (); 27 28kv_buffer (const kv_buffer & )= delete ; 29kv_buffer & operator= (const kv_buffer & )= delete ; 30 31 sycl::half * ensure_half (size_t n_elems ); 32 33private : 34 sycl::half * ptr = nullptr ; 35size_t capacity = 0 ; 36queue_ptr qptr = nullptr ; 37 [[maybe_unused ]]int device = 0 ; 38 }; 39 40kv_buffer K ; 41kv_buffer V ; 42 43ggml_sycl_fattn_kv_buffers (queue_ptr qptr ,int device ) :K (qptr ,device ),V (qptr ,device ) {} 44 45ggml_sycl_fattn_kv_buffers (const ggml_sycl_fattn_kv_buffers & )= delete ; 46ggml_sycl_fattn_kv_buffers & operator= (const ggml_sycl_fattn_kv_buffers & )= delete ; 47}; 48 49/** 50* Imitates `ggml_sycl_pool_alloc` to keep the code calling alloc unchanged. 51*/ 52struct ggml_sycl_fattn_alloc { 53 ggml_sycl_fattn_kv_buffers::kv_buffer & buf ; 54 sycl::half * ptr = nullptr ; 55 56explicit ggml_sycl_fattn_alloc (ggml_sycl_fattn_kv_buffers::kv_buffer & buf_ ) :buf (buf_ ) {} 57 58 sycl::half * alloc (size_t n_elems ) { 59ptr = buf .ensure_half (n_elems ); 60return ptr ; 61 } 62}; 63#endif