char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
cd8cdf397
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#include "common.hpp" 14 15sycl::half * ggml_sycl_fattn_kv_buffers::kv_buffer::ensure_half (size_t n_elems ) { 16const size_t need_bytes = n_elems * sizeof (sycl::half ); 17 18if (capacity >=need_bytes ) { 19return ptr ; 20 } 21 22if (ptr ) { 23SYCL_CHECK (CHECK_TRY_ERROR (qptr -> wait ())); 24ggml_sycl_memtrace_del (ptr ); 25SYCL_CHECK (CHECK_TRY_ERROR (sycl::free (ptr ,* qptr ))); 26ptr = nullptr ; 27capacity = 0 ; 28 } 29 30size_t cap = 0 ; 31while (cap < need_bytes ) { 32cap += CHUNK_SIZE ; 33 } 34 35void * dev_ptr ; 36SYCL_CHECK ( 37CHECK_TRY_ERROR (dev_ptr = sycl::malloc_device ( 38cap ,* qptr ))); 39 40if (!dev_ptr ) { 41GGML_LOG_ERROR ("%s: can't allocate %lu Bytes of memory on device\n" ,__func__ ,cap ); 42ggml_sycl_memtrace_fail (GGML_SYCL_MEM_FATTN_KV ,cap ); 43GGML_ABORT ("fattn buffer alloc failed" ); 44 } 45 46ptr = static_cast < sycl::half *> (dev_ptr ); 47capacity = cap ; 48ggml_sycl_memtrace_add (GGML_SYCL_MEM_FATTN_KV ,ptr ,cap ); 49return ptr ; 50} 51 52ggml_sycl_fattn_kv_buffers::kv_buffer::~kv_buffer () { 53#ifdef DEBUG_SYCL_POOL 54GGML_LOG_INFO ("ggml_sycl_fattn_kv_buffer[%d]: %.2f MiB\n" ,device ,capacity /1024.0 /1024.0 ); 55#endif 56if (ptr ) { 57ggml_sycl_memtrace_del (ptr ); 58SYCL_CHECK (CHECK_TRY_ERROR (sycl::free (ptr ,* qptr ))); 59 } 60}