From 57bf62ce7cb75cca589943e2050d29bff4026e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20P=C3=A9rez?= Date: Sun, 9 Jun 2024 11:24:29 -0400 Subject: [PATCH 01/37] docs: Added initial PR template with directions for doc only changes and squash merges [no ci] (#7700) This commit adds pull_request_template.md and CONTRIBUTING.md . It focuses on explaining to contributors the need to rate PR complexity level, when to add [no ci] and how to format PR title and descriptions. Co-authored-by: Brian Co-authored-by: compilade --- .../PULL_REQUEST_TEMPLATE/pull_request_template.md | 5 +++++ CONTRIBUTING.md | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md create mode 100644 CONTRIBUTING.md diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 000000000..0852fded5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,5 @@ +- Self Reported Review Complexity: + - [ ] Review Complexity : Low + - [ ] Review Complexity : Medium + - [ ] Review Complexity : High +- [ ] I have read the [contributing guidelines](CONTRIBUTING.md) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..991d85e49 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,14 @@ +# Contributing Guidelines + +## Checklist + +* Make sure your PR follows the [coding guidelines](https://github.com/ggerganov/llama.cpp/blob/master/README.md#coding-guidelines) +* Test your changes using the commands in the [`tests`](tests) folder. For instance, running the `./tests/test-backend-ops` command tests different backend implementations of the GGML library +* Execute [the full CI locally on your machine](ci/README.md) before publishing + +## PR formatting + +* Please rate the complexity of your PR (i.e. `Review Complexity : Low`, `Review Complexity : Medium`, `Review Complexity : High`). This makes it easier for maintainers to triage the PRs. + - The PR template has a series of review complexity checkboxes `[ ]` that you can mark as `[X]` for your conveience. Refer to [About task lists](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/about-task-lists) for more information. +* If the pull request only contains documentation changes (e.g., updating READMEs, adding new wiki pages), please add `[no ci]` to the commit title. This will skip unnecessary CI checks and help reduce build times. +* When squashing multiple commits on merge, use the following format for your commit title: ` : (#)`. For example: `utils : Fix typo in utils.py (#1234)` From e95beeb1fc4621826ddd616776dbdf717366bf5c Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 9 Jun 2024 20:19:35 +0300 Subject: [PATCH 02/37] imatrix : handle partial entries (#7833) --- examples/imatrix/imatrix.cpp | 58 +++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/examples/imatrix/imatrix.cpp b/examples/imatrix/imatrix.cpp index e18f49563..574f5ed9c 100644 --- a/examples/imatrix/imatrix.cpp +++ b/examples/imatrix/imatrix.cpp @@ -218,20 +218,64 @@ void IMatrixCollector::save_imatrix(int ncall) const { fname += std::to_string(ncall); } + // avoid writing imatrix entries that do not have full data + // this can happen with MoE models where some of the experts end up not being exercised by the provided training data + + int n_entries = 0; + std::vector to_store; + + bool is_first = true; // for printing + for (const auto & kv : m_stats) { + const int n_all = kv.second.counts.size(); + + if (n_all == 0) { + continue; + } + + int n_zeros = 0; + for (const int c : kv.second.counts) { + if (c == 0) { + n_zeros++; + } + } + + if (n_zeros != 0 && is_first) { + fprintf(stderr, "\n"); + is_first = false; + } + + if (n_zeros == n_all) { + fprintf(stderr, "%s: entry '%40s' has no data - skipping\n", __func__, kv.first.c_str()); + continue; + } + + if (n_zeros > 0) { + fprintf(stderr, "%s: entry '%40s' has partial data (%.2f%%) - skipping\n", __func__, kv.first.c_str(), 100.0f * (n_all - n_zeros) / n_all); + continue; + } + + n_entries++; + to_store.push_back(kv.first); + } + + if (to_store.size() < m_stats.size()) { + fprintf(stderr, "%s: warning: storing only %zu out of %zu entries\n", __func__, to_store.size(), m_stats.size()); + } + std::ofstream out(fname, std::ios::binary); - int n_entries = m_stats.size(); out.write((const char *) &n_entries, sizeof(n_entries)); - for (const auto & p : m_stats) { - int len = p.first.size(); + for (const auto & name : to_store) { + const auto & stat = m_stats.at(name); + int len = name.size(); out.write((const char *) &len, sizeof(len)); - out.write(p.first.c_str(), len); - out.write((const char *) &p.second.ncall, sizeof(p.second.ncall)); - int nval = p.second.values.size(); + out.write(name.c_str(), len); + out.write((const char *) &stat.ncall, sizeof(stat.ncall)); + int nval = stat.values.size(); out.write((const char *) &nval, sizeof(nval)); if (nval > 0) { std::vector tmp(nval); for (int i = 0; i < nval; i++) { - tmp[i] = (p.second.values[i] / static_cast(p.second.counts[i])) * static_cast(p.second.ncall); + tmp[i] = (stat.values[i] / static_cast(stat.counts[i])) * static_cast(stat.ncall); } out.write((const char*)tmp.data(), nval*sizeof(float)); } From 10ceba354a3b152ff425e9fa97f9caaef99a46b1 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Mon, 10 Jun 2024 02:04:50 +0300 Subject: [PATCH 03/37] flake.lock: Update (#7838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/ad57eef4ef0659193044870c731987a6df5cf56b?narHash=sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs%3D' (2024-05-29) → 'github:NixOS/nixpkgs/051f920625ab5aabe37c920346e3e69d7d34400e?narHash=sha256-4q0s6m0GUcN7q%2BY2DqD27iLvbcd1G50T2lv08kKxkSI%3D' (2024-06-07) Co-authored-by: github-actions[bot] --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 09047ab10..7272e65fa 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1716948383, - "narHash": "sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs=", + "lastModified": 1717786204, + "narHash": "sha256-4q0s6m0GUcN7q+Y2DqD27iLvbcd1G50T2lv08kKxkSI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ad57eef4ef0659193044870c731987a6df5cf56b", + "rev": "051f920625ab5aabe37c920346e3e69d7d34400e", "type": "github" }, "original": { From af4ae502ddaeb03cd5861273ca2e9a5ae4551db7 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Mon, 10 Jun 2024 02:21:31 -0700 Subject: [PATCH 04/37] use the correct SYCL context for host USM allocations (#7777) Signed-off-by: Ben Ashbaugh --- ggml-sycl.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ggml-sycl.cpp b/ggml-sycl.cpp index 0a645b2e1..42fc0df20 100644 --- a/ggml-sycl.cpp +++ b/ggml-sycl.cpp @@ -13089,10 +13089,12 @@ void *ggml_sycl_host_malloc(size_t size) try { return nullptr; } + ggml_sycl_set_device(g_main_device); + dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0]; + void * ptr = nullptr; - //allow to use dpct::get_in_order_queue() for host malloc dpct::err0 err = CHECK_TRY_ERROR( - ptr = (void *)sycl::malloc_host(size, dpct::get_in_order_queue())); + ptr = (void *)sycl::malloc_host(size, *main_stream)); if (err != 0) { // clear the error @@ -13113,8 +13115,9 @@ catch (sycl::exception const &exc) { } void ggml_sycl_host_free(void *ptr) try { - //allow to use dpct::get_in_order_queue() for host malloc - SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(ptr, dpct::get_in_order_queue()))); + ggml_sycl_set_device(g_main_device); + dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0]; + SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(ptr, *main_stream))); } catch (sycl::exception const &exc) { std::cerr << exc.what() << "Exception caught at file:" << __FILE__ From 1f0dabda8d5c131f9d4632aa41de74317cdd61fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Mon, 10 Jun 2024 11:45:13 +0200 Subject: [PATCH 05/37] CUDA: use tensor cores for MMQ (#7676) * CUDA: int8 tensor cores for MMQ (legacy quants) * fix out-of-bounds writes * __builtin_assume -> GGML_CUDA_ASSUME * fix writeback returning too early --- ggml-cuda/common.cuh | 21 +- ggml-cuda/fattn-common.cuh | 20 +- ggml-cuda/fattn-tile-f16.cu | 2 +- ggml-cuda/fattn-vec-f16.cuh | 2 +- ggml-cuda/fattn-wmma-f16.cuh | 6 +- ggml-cuda/mma.cuh | 95 ++++++++ ggml-cuda/mmq.cuh | 459 ++++++++++++++++++++++++++++++++--- 7 files changed, 550 insertions(+), 55 deletions(-) create mode 100644 ggml-cuda/mma.cuh diff --git a/ggml-cuda/common.cuh b/ggml-cuda/common.cuh index 90a0a81ea..7f4764d60 100644 --- a/ggml-cuda/common.cuh +++ b/ggml-cuda/common.cuh @@ -139,6 +139,7 @@ #define CC_PASCAL 600 #define MIN_CC_DP4A 610 // minimum compute capability for __dp4a, an intrinsic for byte-wise dot products #define CC_VOLTA 700 +#define CC_TURING 750 #define CC_AMPERE 800 #define CC_OFFSET_AMD 1000000 #define CC_RDNA1 (CC_OFFSET_AMD + 1010) @@ -326,9 +327,17 @@ static __device__ __forceinline__ half2 __shfl_xor(half2 var, int laneMask, int #endif // defined(__HIP_PLATFORM_AMD__) && HIP_VERSION < 50600000 #endif // defined(GGML_USE_HIPBLAS) -#define FP16_AVAILABLE (defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) || __CUDA_ARCH__ >= CC_PASCAL +#if (defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) || __CUDA_ARCH__ >= CC_PASCAL +#define FP16_AVAILABLE +#endif // (defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) || __CUDA_ARCH__ >= CC_PASCAL -#define FP16_MMA_AVAILABLE !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && __CUDA_ARCH__ >= CC_VOLTA +#if !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && __CUDA_ARCH__ >= CC_VOLTA +#define FP16_MMA_AVAILABLE +#endif // !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && __CUDA_ARCH__ >= CC_VOLTA + +#if !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && __CUDA_ARCH__ >= CC_TURING +#define INT8_MMA_AVAILABLE +#endif // !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && __CUDA_ARCH__ >= CC_TURING static bool fast_fp16_available(const int cc) { return cc >= CC_PASCAL && cc != 610; @@ -338,6 +347,10 @@ static bool fp16_mma_available(const int cc) { return cc < CC_OFFSET_AMD && cc >= CC_VOLTA; } +static bool int8_mma_available(const int cc) { + return cc < CC_OFFSET_AMD && cc >= CC_TURING; +} + [[noreturn]] static __device__ void no_device_code( const char * file_name, const int line, const char * function_name, const int arch, const char * arch_list) { @@ -379,7 +392,7 @@ static __device__ __forceinline__ float2 warp_reduce_sum(float2 a) { } static __device__ __forceinline__ half2 warp_reduce_sum(half2 a) { -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE #if defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__) #pragma unroll @@ -412,7 +425,7 @@ static __device__ __forceinline__ float warp_reduce_max(float x) { } static __device__ __forceinline__ half ggml_cuda_hmax(const half a, const half b) { -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE #if !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && CUDART_VERSION < CUDART_HMAX return __float2half(fmaxf(__half2float(a), __half2float(b))); diff --git a/ggml-cuda/fattn-common.cuh b/ggml-cuda/fattn-common.cuh index c00f8606a..37b3b9932 100644 --- a/ggml-cuda/fattn-common.cuh +++ b/ggml-cuda/fattn-common.cuh @@ -74,7 +74,7 @@ static __device__ __forceinline__ T vec_dot_fattn_vec_KQ_q4_0( const int sumi = __dp4a(v, u, 0); -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { const half2 * Q_ds = (const half2 *) Q_ds_v; @@ -122,7 +122,7 @@ static __device__ __forceinline__ T vec_dot_fattn_vec_KQ_q4_1( const int sumi = __dp4a(v, u, 0); -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { const half2 * Q_ds = (const half2 *) Q_ds_v; @@ -181,7 +181,7 @@ static __device__ __forceinline__ T vec_dot_fattn_vec_KQ_q5_0( const int sumi = __dp4a(v, u, 0); -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { const half2 * Q_ds = (const half2 *) Q_ds_v; @@ -236,7 +236,7 @@ static __device__ __forceinline__ T vec_dot_fattn_vec_KQ_q5_1( const int sumi = __dp4a(v, u, 0); -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { const half2 * Q_ds = (const half2 *) Q_ds_v; @@ -314,7 +314,7 @@ static __device__ __forceinline__ T vec_dot_fattn_vec_KQ_f16( GGML_UNUSED(Q_q8); GGML_UNUSED(Q_ds_v); -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { const half2 * Q_h2 = (const half2 *) Q_v; @@ -407,7 +407,7 @@ static __device__ __forceinline__ T dequantize_1_q4_0(const void * __restrict__ const int q0 = x[ib].qs[iqs]; const int q = ((q0 >> (4*shift)) & 0x0F) - 8; -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { return ((half) d)*((half) q); } @@ -428,7 +428,7 @@ static __device__ __forceinline__ T dequantize_1_q4_1(const void * __restrict__ const int q0 = x[ib].qs[iqs]; const int q = ((q0 >> (4*shift)) & 0x0F); -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { return __low2half(dm)*((half) q) + __high2half(dm); } @@ -453,7 +453,7 @@ static __device__ __forceinline__ T dequantize_1_q5_0(const void * __restrict__ const int qh = ((qh0 >> idq) << 4) & 0x10; const int q = (ql | qh) - 16; -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { return ((half) d)*((half) q); } @@ -478,7 +478,7 @@ static __device__ __forceinline__ T dequantize_1_q5_1(const void * __restrict__ const int qh = ((qh0 >> idq) << 4) & 0x10; const int q = (ql | qh); -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { return __low2half(dm)*((half) q) + __high2half(dm); } @@ -497,7 +497,7 @@ static __device__ __forceinline__ T dequantize_1_q8_0(const void * __restrict__ const T d = x[ib].d; const int q = x[ib].qs[iqs]; -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE if (std::is_same::value) { return ((half) d)*((half) q); } diff --git a/ggml-cuda/fattn-tile-f16.cu b/ggml-cuda/fattn-tile-f16.cu index cb11d7212..c6c35134d 100644 --- a/ggml-cuda/fattn-tile-f16.cu +++ b/ggml-cuda/fattn-tile-f16.cu @@ -43,7 +43,7 @@ static __global__ void flash_attn_tile_ext_f16( const int ne1, const int ne2, const int ne3) { -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE //In this kernel Q, K, V are matrices while i, j, k are matrix indices. const int ic0 = (blockIdx.x / parallel_blocks) * ncols; // Index of the Q/QKV column to work on. diff --git a/ggml-cuda/fattn-vec-f16.cuh b/ggml-cuda/fattn-vec-f16.cuh index 9e1aa2c6b..02a4ad072 100644 --- a/ggml-cuda/fattn-vec-f16.cuh +++ b/ggml-cuda/fattn-vec-f16.cuh @@ -40,7 +40,7 @@ static __global__ void flash_attn_vec_ext_f16( const int ne1, const int ne2, const int ne3) { -#if FP16_AVAILABLE +#ifdef FP16_AVAILABLE //In this kernel Q, K, V are matrices while i, j, k are matrix indices. constexpr vec_dot_KQ_f16_t vec_dot_KQ = get_vec_dot_KQ_f16(type_K); diff --git a/ggml-cuda/fattn-wmma-f16.cuh b/ggml-cuda/fattn-wmma-f16.cuh index 59cd30d78..ae2322242 100644 --- a/ggml-cuda/fattn-wmma-f16.cuh +++ b/ggml-cuda/fattn-wmma-f16.cuh @@ -1,9 +1,9 @@ #include "common.cuh" #include "fattn-common.cuh" -#if FP16_MMA_AVAILABLE +#ifdef FP16_MMA_AVAILABLE #include -#endif +#endif // FP16_MMA_AVAILABLE // D == head size, VKQ_stride == num VKQ rows calculated in parallel: template @@ -45,7 +45,7 @@ static __global__ void flash_attn_ext_f16( const int ne1, const int ne2, const int ne3) { -#if FP16_MMA_AVAILABLE +#ifdef FP16_MMA_AVAILABLE //In this kernel Q, K, V are matrices while i, j, k are matrix indices. const int ic0 = ncols*(blockIdx.x / parallel_blocks); // Index of the first Q/QKV column to work on. diff --git a/ggml-cuda/mma.cuh b/ggml-cuda/mma.cuh new file mode 100644 index 000000000..71e8e3429 --- /dev/null +++ b/ggml-cuda/mma.cuh @@ -0,0 +1,95 @@ +#include "common.cuh" + +struct mma_int_A_I16K8 { + static constexpr int I = 16; + static constexpr int K = 8; + static constexpr int ne = 4; + + int x[ne] = {0}; + + static __device__ __forceinline__ int get_i(const int l) { + const int ret = (l%2) * (I/2) + threadIdx.x / (K/2); + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < I); + return ret; + } + + static __device__ __forceinline__ int get_k(const int l) { + const int ret = (l/2) * (K/2) + threadIdx.x % (K/2); + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < K); + return ret; + } +}; + +struct mma_int_B_J8K8 { + static constexpr int J = 8; + static constexpr int K = 8; + static constexpr int ne = 2; + + int x[ne] = {0}; + + static __device__ __forceinline__ int get_j(const int /* l */) { + const int ret = threadIdx.x / (K/2); + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < J); + return ret; + } + + static __device__ __forceinline__ int get_k(const int l) { + const int ret = l * (K/2) + threadIdx.x % (K/2); + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < K); + return ret; + } +}; + +struct mma_int_C_I16J8 { + static constexpr int I = 16; + static constexpr int J = 8; + static constexpr int ne = 4; + + int x[ne] = {0}; + + static __device__ __forceinline__ int get_i(const int l) { + const int ret = (l/2) * (I/2) + threadIdx.x / (J/2); + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < I); + return ret; + } + + static __device__ __forceinline__ int get_j(const int l) { + const int ret = 2 * (threadIdx.x % (J/2)) + l%2; + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < J); + return ret; + } + + __device__ __forceinline__ void mma_K8(const mma_int_A_I16K8 & mma_A, const mma_int_B_J8K8 & mma_B) { +#ifdef INT8_MMA_AVAILABLE +#if __CUDA_ARCH__ >= CC_AMPERE + asm("mma.sync.aligned.m16n8k32.row.col.s32.s8.s8.s32 {%0, %1, %2, %3}, {%4, %5, %6, %7}, {%8, %9}, {%0, %1, %2, %3};" + : "+r"(x[0]), "+r"(x[1]), "+r"(x[2]), "+r"(x[3]) + : "r"(mma_A.x[0]), "r"(mma_A.x[1]), "r"(mma_A.x[2]), "r"(mma_A.x[3]), "r"(mma_B.x[0]), "r"(mma_B.x[1])); +#else + // On Turing m16n8k32 mma is not available, use 4x m8n8k16 mma instead: + asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};" + : "+r"(x[0]), "+r"(x[1]) + : "r"(mma_A.x[0]), "r"(mma_B.x[0])); + asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};" + : "+r"(x[2]), "+r"(x[3]) + : "r"(mma_A.x[1]), "r"(mma_B.x[0])); + asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};" + : "+r"(x[0]), "+r"(x[1]) + : "r"(mma_A.x[2]), "r"(mma_B.x[1])); + asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};" + : "+r"(x[2]), "+r"(x[3]) + : "r"(mma_A.x[3]), "r"(mma_B.x[1])); +#endif // __CUDA_ARCH__ >= CC_AMPERE +#else + GGML_UNUSED(mma_A); + GGML_UNUSED(mma_B); + NO_DEVICE_CODE; +#endif // INT8_MMA_AVAILABLE + } +}; diff --git a/ggml-cuda/mmq.cuh b/ggml-cuda/mmq.cuh index 3ccae8a0c..62111f376 100644 --- a/ggml-cuda/mmq.cuh +++ b/ggml-cuda/mmq.cuh @@ -2,6 +2,7 @@ #include "common.cuh" #include "vecdotq.cuh" +#include "mma.cuh" #include #include @@ -14,6 +15,7 @@ typedef void (*load_tiles_mmq_t)( typedef void (*vec_dot_mmq_t)( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0); +typedef void (*mmq_write_back_t)(const float * __restrict__ sum, float * __restrict__ dst, const int & ne0, const int & ne1); struct block_q8_1_mmq { half2 ds[4]; @@ -141,15 +143,15 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q4_0_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q4_0_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); - const float * x_dmf = (const float *) x_dm; - const int * y_qs = (const int *) y + 4; - const half2 * y_ds = (const half2 *) y; + const float * x_df = (const float *) x_dm; + const int * y_qs = (const int *) y + 4; + const half2 * y_ds = (const half2 *) y; #pragma unroll for (int j0 = 0; j0 < mmq_x; j0 += nwarps) { @@ -170,12 +172,76 @@ static __device__ __forceinline__ void vec_dot_q4_0_q8_1_mul_mat( } sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q4_0_q8_1_impl - (&x_ql[i*(WARP_SIZE + 1) + k0], u, x_dmf[i*(WARP_SIZE/QI4_0) + i/QI4_0 + k0/QI4_0], + (&x_ql[i*(WARP_SIZE + 1) + k0], u, x_df[i*(WARP_SIZE/QI4_0) + i/QI4_0 + k0/QI4_0], y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]); } } } +template +static __device__ __forceinline__ void vec_dot_q4_0_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K8 mma_A; + typedef mma_int_B_J8K8 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const float * x_df = (const float *) x_dm; + const int * y_qs = (const int *) y + 4; + const half2 * y_ds = (const half2 *) y; + + mma_A A; + float dA[mma_C::ne/2]; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = k0 + mma_A::get_k(l) % QI4_0; + const int shift = 4*(mma_A::get_k(l) / QI4_0); + + A.x[l] = __vsubss4((x_ql[i*(WARP_SIZE + 1) + k] >> shift) & 0x0F0F0F0F, 0x08080808); + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dA[l] = x_df[i*(WARP_SIZE/QI4_0) + i/QI4_0 + k0/QI4_0]; + } + + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + mma_C C; + mma_B B; + half2 dsB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = (2*k0 + mma_B::get_k(l)) % WARP_SIZE; + + B.x[l] = y_qs[j*MMQ_TILE_Y_K + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dsB[l] = y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]; + } + + C.mma_K8(A, B); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + sum[(j0/B.J)*C.ne + l] += dA[l/2]*__low2float(dsB[l%2])*C.x[l]; + } + } +} + template static __device__ __forceinline__ void load_tiles_q4_1( const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh, int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) { @@ -215,7 +281,7 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q4_1_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q4_1_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { @@ -249,6 +315,70 @@ static __device__ __forceinline__ void vec_dot_q4_1_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void vec_dot_q4_1_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K8 mma_A; + typedef mma_int_B_J8K8 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const int * y_qs = (const int *) y + 4; + const half2 * y_ds = (const half2 *) y; + + mma_A A; + half2 dmA[mma_C::ne/2]; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = k0 + mma_A::get_k(l) % QI4_0; + const int shift = 4*(mma_A::get_k(l) / QI4_0); + + A.x[l] = (x_ql[i*(WARP_SIZE + 1) + k] >> shift) & 0x0F0F0F0F; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dmA[l] = x_dm[i*(WARP_SIZE/QI4_0) + i/QI4_0 + k0/QI4_0]; + } + + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + mma_C C; + mma_B B; + half2 dsB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = (2*k0 + mma_B::get_k(l)) % WARP_SIZE; + + B.x[l] = y_qs[j*MMQ_TILE_Y_K + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dsB[l] = y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]; + } + + C.mma_K8(A, B); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + const half2 dmA_dsB = dmA[l/2]*dsB[l%2]; + sum[(j0/B.J)*C.ne + l] += __low2float(dmA_dsB)*C.x[l] + __high2float(dmA_dsB); + } + } +} + template static __device__ __forceinline__ void load_tiles_q5_0( const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh, int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) { @@ -308,7 +438,7 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q5_0_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q5_0_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { @@ -343,6 +473,68 @@ static __device__ __forceinline__ void vec_dot_q5_0_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void vec_dot_q5_0_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K8 mma_A; + typedef mma_int_B_J8K8 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const float * x_df = (const float *) x_dm; + const int * y_qs = (const int *) y + 4; + const float * y_df = (const float *) y; + + mma_A A; + float dA[mma_C::ne/2]; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = 2*(k0 + mma_A::get_k(l) % QI5_0) + mma_A::get_k(l) / QI5_0; + + A.x[l] = x_ql[i*(2*WARP_SIZE + 1) + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dA[l] = x_df[i*(WARP_SIZE/QI5_0) + i/QI5_0 + k0/QI5_0]; + } + + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + mma_C C; + mma_B B; + float dB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = (2*k0 + mma_B::get_k(l)) % WARP_SIZE; + + B.x[l] = y_qs[j*MMQ_TILE_Y_K + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dB[l] = y_df[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]; + } + + C.mma_K8(A, B); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + sum[(j0/B.J)*C.ne + l] += dA[l/2]*dB[l%2]*C.x[l]; + } + } +} template static __device__ __forceinline__ void load_tiles_q5_1( const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh, @@ -400,7 +592,7 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q5_1_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q5_1_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { @@ -434,6 +626,69 @@ static __device__ __forceinline__ void vec_dot_q5_1_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void vec_dot_q5_1_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K8 mma_A; + typedef mma_int_B_J8K8 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const int * y_qs = (const int *) y + 4; + const half2 * y_ds = (const half2 *) y; + + mma_A A; + half2 dmA[mma_C::ne/2]; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = 2*(k0 + mma_A::get_k(l) % QI5_1) + mma_A::get_k(l) / QI5_1; + + A.x[l] = x_ql[i*(2*WARP_SIZE + 1) + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dmA[l] = x_dm[i*(WARP_SIZE/QI5_1) + i/QI5_1 + k0/QI5_1]; + } + + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + mma_C C; + mma_B B; + half2 dsB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = (2*k0 + mma_B::get_k(l)) % WARP_SIZE; + + B.x[l] = y_qs[j*MMQ_TILE_Y_K + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dsB[l] = y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]; + } + + C.mma_K8(A, B); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + const half2 dmA_dsB = dmA[l/2]*dsB[l%2]; + sum[(j0/B.J)*C.ne + l] += __low2float(dmA_dsB)*C.x[l] + __high2float(dmA_dsB); + } + } +} + template static __device__ __forceinline__ void load_tiles_q8_0( const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh, int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) { @@ -475,7 +730,7 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q8_0_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q8_0_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { @@ -500,6 +755,69 @@ static __device__ __forceinline__ void vec_dot_q8_0_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void vec_dot_q8_0_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K8 mma_A; + typedef mma_int_B_J8K8 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const float * x_df = (const float *) x_dm; + const int * y_qs = (const int *) y + 4; + const float * y_df = (const float *) y; + + mma_A A; + float dA[mma_C::ne/2]; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = k0 + mma_A::get_k(l); + + A.x[l] = x_ql[i*(WARP_SIZE + 1) + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dA[l] = x_df[i*(WARP_SIZE/QI8_0) + i/QI8_0 + k0/QI8_0]; + } + + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + mma_C C; + mma_B B; + float dB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = k0 + mma_B::get_k(l); + + B.x[l] = y_qs[j*MMQ_TILE_Y_K + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dB[l] = y_df[j*MMQ_TILE_Y_K + k0/QI8_1]; + } + + C.mma_K8(A, B); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + sum[(j0/B.J)*C.ne + l] += C.x[l]*dA[l/2]*dB[l%2]; + } + } +} + template static __device__ __forceinline__ void load_tiles_q2_K( const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh, int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) { @@ -989,6 +1307,57 @@ static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void mmq_write_back_dp4a(const float * __restrict__ sum, float * __restrict__ dst, const int & ne0, const int & ne1) { +#pragma unroll + for (int j0 = 0; j0 < mmq_x; j0 += nwarps) { + const int j = blockIdx.y*mmq_x + j0 + threadIdx.y; + + if (j >= ne1) { + return; + } + +#pragma unroll + for (int i0 = 0; i0 < mmq_y; i0 += WARP_SIZE) { + const int i = blockIdx.x*mmq_y + i0 + threadIdx.x; + + if (need_check && i >= ne0) { + continue; + } + + dst[j*ne0 + i] = sum[(j0/nwarps) * (mmq_y/WARP_SIZE) + i0/WARP_SIZE]; + } + } +} + +template +static __device__ __forceinline__ void mmq_write_back_mma(const float * __restrict__ sum, float * __restrict__ dst, const int & ne0, const int & ne1) { + typedef mma_int_C_I16J8 mma_C; + + const int i0 = threadIdx.y*mma_C::I; + static_assert(nwarps*mma_C::I == mmq_y, "nwarps*mma_C::I != mmq_y"); + +#pragma unroll + for (int j0 = 0; j0 < mmq_x; j0 += mma_C::J) { +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + const int j = blockIdx.y*mmq_x + j0 + mma_C::get_j(l); + + if (j >= ne1) { + continue; + } + + const int i = blockIdx.x*mmq_y + i0 + mma_C::get_i(l); + + if (need_check && i >= ne0) { + continue; + } + + dst[j*ne0 + i] = sum[(j0/mma_C::J)*mma_C::ne + l]; + } + } +} + // ------------------------------------------------------------------------------------------------------------------------------------- template @@ -998,35 +1367,65 @@ template struct mmq_type_traits { static constexpr int vdr = VDR_Q4_0_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q4_0; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_0_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_0_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_0_q8_1_dp4a; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; template struct mmq_type_traits { static constexpr int vdr = VDR_Q4_1_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q4_1; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_1_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_1_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_1_q8_1_dp4a; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; template struct mmq_type_traits { static constexpr int vdr = VDR_Q5_0_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q5_0; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_0_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_0_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_0_q8_1_dp4a; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; template struct mmq_type_traits { static constexpr int vdr = VDR_Q5_1_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q5_1; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_1_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_1_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_1_q8_1_dp4a; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; template struct mmq_type_traits { static constexpr int vdr = VDR_Q8_0_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q8_0; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q8_0_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q8_0_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q8_0_q8_1_dp4a; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; template @@ -1034,6 +1433,7 @@ struct mmq_type_traits { static constexpr int vdr = VDR_Q2_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q2_K; static constexpr vec_dot_mmq_t vec_dot = vec_dot_q2_K_q8_1_mul_mat; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; }; template @@ -1041,6 +1441,7 @@ struct mmq_type_traits { static constexpr int vdr = VDR_Q3_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q3_K; static constexpr vec_dot_mmq_t vec_dot = vec_dot_q3_K_q8_1_mul_mat; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; }; template @@ -1048,6 +1449,7 @@ struct mmq_type_traits { static constexpr int vdr = VDR_Q4_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q4_K; static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_K_q8_1_mul_mat; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; }; template @@ -1055,6 +1457,7 @@ struct mmq_type_traits { static constexpr int vdr = VDR_Q5_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q5_K; static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_K_q8_1_mul_mat; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; }; template @@ -1062,6 +1465,7 @@ struct mmq_type_traits { static constexpr int vdr = VDR_Q6_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q6_K; static constexpr vec_dot_mmq_t vec_dot = vec_dot_q6_K_q8_1_mul_mat; + static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; }; static int mmq_need_sum(const ggml_type type_x) { @@ -1118,6 +1522,7 @@ static __global__ void mul_mat_q( constexpr int vdr = mmq_type_traits::vdr; constexpr load_tiles_mmq_t load_tiles = mmq_type_traits::load_tiles; constexpr vec_dot_mmq_t vec_dot = mmq_type_traits::vec_dot; + constexpr mmq_write_back_t write_back = mmq_type_traits::write_back; constexpr tile_x_sizes txs = get_tile_x_sizes_device(type); @@ -1137,7 +1542,7 @@ static __global__ void mul_mat_q( const int * y = (const int *) yc + blockIdx.y*(mmq_x*sizeof(block_q8_1_mmq)/sizeof(int)); - float sum[(mmq_x/nwarps) * (mmq_y/WARP_SIZE)] = {0.0f}; + float sum[mmq_x*mmq_y / (nwarps*WARP_SIZE)] = {0.0f}; for (int kb0 = 0; kb0 < blocks_per_row_x; kb0 += blocks_per_warp) { @@ -1164,25 +1569,7 @@ static __global__ void mul_mat_q( } } -#pragma unroll - for (int j0 = 0; j0 < mmq_x; j0 += nwarps) { - const int j = blockIdx.y*mmq_x + j0 + threadIdx.y; - - if (j >= ne1) { - return; - } - -#pragma unroll - for (int i0 = 0; i0 < mmq_y; i0 += WARP_SIZE) { - const int i = blockIdx.x*mmq_y + i0 + threadIdx.x; - - if (need_check && i >= ne0) { - continue; - } - - dst[j*ne0 + i] = sum[(j0/nwarps) * (mmq_y/WARP_SIZE) + i0/WARP_SIZE]; - } - } + write_back(sum, dst, ne0, ne1); } struct mmq_args { @@ -1256,10 +1643,10 @@ void mul_mat_q_case(const mmq_args & args, cudaStream_t stream) { launch_mul_mat_q(args, stream); break; case 16: - launch_mul_mat_q(args, stream); + launch_mul_mat_q(args, stream); break; case 24: - launch_mul_mat_q(args, stream); + launch_mul_mat_q(args, stream); break; case 32: launch_mul_mat_q(args, stream); From d9da0e4986f121c727bdd9579a6688097b11602c Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Mon, 10 Jun 2024 14:59:55 +0300 Subject: [PATCH 06/37] server : improve "prompt" handling (#7847) --- examples/server/server.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index 6ffaa8d9f..80714fa58 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -147,7 +147,7 @@ struct server_slot { int32_t n_prompt_tokens = 0; int32_t n_prompt_tokens_processed = 0; - json prompt; + std::string prompt; // when a task is submitted, we first tokenize the prompt and store it here std::vector prompt_tokens; @@ -822,13 +822,8 @@ struct server_context { continue; } - // skip the slot if it does not contains prompt - if (!slot.prompt.is_string()) { - continue; - } - // current slot's prompt - std::string slot_prompt = slot.prompt.get(); + std::string slot_prompt = slot.prompt; // length of the current slot's prompt int slot_prompt_len = slot_prompt.size(); @@ -958,13 +953,16 @@ struct server_context { if (!task.infill) { const auto & prompt = data.find("prompt"); if (prompt == data.end()) { - send_error(task, "Either \"prompt\" or \"messages\" must be provided", ERROR_TYPE_INVALID_REQUEST); + send_error(task, "\"prompt\" must be provided", ERROR_TYPE_INVALID_REQUEST); return false; - } else { - slot.prompt = *prompt; } - if (slot.prompt.is_array() && slot.prompt.size() == 0) { - send_error(task, "\"prompt\" cannot be an empty array", ERROR_TYPE_INVALID_REQUEST); + + if (prompt->is_string()) { + slot.prompt = prompt->get(); + } else if (prompt->is_array() && prompt->size() == 1 && prompt->at(0).is_string()) { + slot.prompt = prompt->at(0).get(); + } else { + send_error(task, "\"prompt\" must be a string or an array of strings", ERROR_TYPE_INVALID_REQUEST); return false; } } @@ -1582,14 +1580,18 @@ struct server_context { switch (task.type) { case SERVER_TASK_TYPE_COMPLETION: { - int id_slot = json_value(task.data, "id_slot", -1); - std::string prompt = json_value(task.data, "prompt", std::string()); + const int id_slot = json_value(task.data, "id_slot", -1); server_slot * slot; if (id_slot != -1) { slot = get_slot_by_id(id_slot); } else { + std::string prompt; + if (task.data.contains("prompt") && task.data.at("prompt").is_string()) { + json_value(task.data, "prompt", std::string()); + } + slot = get_available_slot(prompt); } From c28a83902cf6ab6a9e085ad6d4cc2e95c4ccfe40 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Mon, 10 Jun 2024 15:00:15 +0300 Subject: [PATCH 07/37] examples : remove --instruct remnants (#7846) --- README.md | 29 ----------------------------- examples/alpaca.sh | 19 ------------------- examples/gpt4all.sh | 15 --------------- examples/llama2-13b.sh | 18 ------------------ examples/llama2.sh | 18 ------------------ 5 files changed, 99 deletions(-) delete mode 100755 examples/alpaca.sh delete mode 100755 examples/gpt4all.sh delete mode 100755 examples/llama2-13b.sh delete mode 100755 examples/llama2.sh diff --git a/README.md b/README.md index 09e8cad31..ecb9d00db 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ Inference of Meta's [LLaMA](https://arxiv.org/abs/2302.13971) model (and others)
  • Quantization
  • Interactive mode
  • Constrained output with grammars
  • -
  • Instruct mode
  • Obtaining and using the Facebook LLaMA 2 model
  • Seminal papers and background on the models
  • Perplexity (measuring model quality)
  • @@ -769,34 +768,6 @@ The `grammars/` folder contains a handful of sample grammars. To write your own, For authoring more complex JSON grammars, you can also check out https://grammar.intrinsiclabs.ai/, a browser app that lets you write TypeScript interfaces which it compiles to GBNF grammars that you can save for local use. Note that the app is built and maintained by members of the community, please file any issues or FRs on [its repo](http://github.com/intrinsiclabsai/gbnfgen) and not this one. -### Instruct mode - -1. First, download and place the `ggml` model into the `./models` folder -2. Run the `main` tool like this: - -``` -./examples/alpaca.sh -``` - -Sample run: - -``` -== Running in interactive mode. == - - Press Ctrl+C to interject at any time. - - Press Return to return control to LLaMA. - - If you want to submit another line, end your input in '\'. - - Below is an instruction that describes a task. Write a response that appropriately completes the request. - -> How many letters are there in the English alphabet? -There 26 letters in the English Alphabet -> What is the most common way of transportation in Amsterdam? -The majority (54%) are using public transit. This includes buses, trams and metros with over 100 lines throughout the city which make it very accessible for tourists to navigate around town as well as locals who commute by tram or metro on a daily basis -> List 5 words that start with "ca". -cadaver, cauliflower, cabbage (vegetable), catalpa (tree) and Cailleach. -> -``` - ### Obtaining and using the Facebook LLaMA 2 model - Refer to [Facebook's LLaMA download page](https://ai.meta.com/resources/models-and-libraries/llama-downloads/) if you want to access the model data. diff --git a/examples/alpaca.sh b/examples/alpaca.sh deleted file mode 100755 index 8d2bae691..000000000 --- a/examples/alpaca.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# -# Temporary script - will be removed in the future -# - -cd `dirname $0` -cd .. - -./main -m ./models/alpaca.13b.ggmlv3.q8_0.bin \ - --color \ - -f ./prompts/alpaca.txt \ - --ctx_size 2048 \ - -n -1 \ - -ins -b 256 \ - --top_k 10000 \ - --temp 0.2 \ - --repeat_penalty 1.1 \ - -t 7 diff --git a/examples/gpt4all.sh b/examples/gpt4all.sh deleted file mode 100755 index 5fd739e55..000000000 --- a/examples/gpt4all.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# -# Temporary script - will be removed in the future -# - -cd `dirname $0` -cd .. - -./main --color --instruct --threads 4 \ - --model ./models/gpt4all-7B/gpt4all-lora-quantized.bin \ - --file ./prompts/alpaca.txt \ - --batch_size 8 --ctx_size 2048 -n -1 \ - --repeat_last_n 64 --repeat_penalty 1.3 \ - --n_predict 128 --temp 0.1 --top_k 40 --top_p 0.95 diff --git a/examples/llama2-13b.sh b/examples/llama2-13b.sh deleted file mode 100755 index 92b3f6dd8..000000000 --- a/examples/llama2-13b.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# -# Temporary script - will be removed in the future -# - -cd `dirname $0` -cd .. - -./main -m models/available/Llama2/13B/llama-2-13b.ggmlv3.q4_0.bin \ - --color \ - --ctx_size 2048 \ - -n -1 \ - -ins -b 256 \ - --top_k 10000 \ - --temp 0.2 \ - --repeat_penalty 1.1 \ - -t 8 diff --git a/examples/llama2.sh b/examples/llama2.sh deleted file mode 100755 index 221b37553..000000000 --- a/examples/llama2.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# -# Temporary script - will be removed in the future -# - -cd `dirname $0` -cd .. - -./main -m models/available/Llama2/7B/llama-2-7b.ggmlv3.q4_0.bin \ - --color \ - --ctx_size 2048 \ - -n -1 \ - -ins -b 256 \ - --top_k 10000 \ - --temp 0.2 \ - --repeat_penalty 1.1 \ - -t 8 From fd5ea0f897ecb3659d6c269ef6f3d833e865ead7 Mon Sep 17 00:00:00 2001 From: slaren Date: Mon, 10 Jun 2024 14:18:41 +0200 Subject: [PATCH 08/37] ci : try win-2019 on server windows test (#7854) --- .github/workflows/server.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 0789efd18..0d16ef5f1 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -16,11 +16,9 @@ on: branches: - master paths: ['.github/workflows/server.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.swift', '**/*.m', 'examples/server/**.*'] - pull_request_target: + pull_request: types: [opened, synchronize, reopened] paths: ['.github/workflows/server.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.swift', '**/*.m', 'examples/server/**.*'] - schedule: - - cron: '2 4 * * *' concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || github.run_id }} @@ -115,7 +113,7 @@ jobs: server-windows: - runs-on: windows-latest + runs-on: windows-2019 steps: - name: Clone From 864a99e7a01d9422d2f55618dbe62c8099a2175c Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Mon, 10 Jun 2024 18:32:10 -0400 Subject: [PATCH 09/37] cmake : fix CMake requirement for CUDA (#7821) --- CMakeLists.txt | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1d6afbbc..8e280f87d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -402,12 +402,26 @@ if (LLAMA_CUBLAS) endif() if (LLAMA_CUDA) - cmake_minimum_required(VERSION 3.17) + cmake_minimum_required(VERSION 3.18) # for CMAKE_CUDA_ARCHITECTURES find_package(CUDAToolkit) if (CUDAToolkit_FOUND) message(STATUS "CUDA found") + if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES) + # 52 == lowest CUDA 12 standard + # 60 == f16 CUDA intrinsics + # 61 == integer CUDA intrinsics + # 70 == compute capability at which unrolling a loop in mul_mat_q kernels is faster + if (LLAMA_CUDA_F16 OR LLAMA_CUDA_DMMV_F16) + set(CMAKE_CUDA_ARCHITECTURES "60;61;70") # needed for f16 CUDA intrinsics + else() + set(CMAKE_CUDA_ARCHITECTURES "52;61;70") # lowest CUDA 12 standard + lowest for integer intrinsics + #set(CMAKE_CUDA_ARCHITECTURES "OFF") # use this to compile much faster, but only F16 models work + endif() + endif() + message(STATUS "Using CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}") + enable_language(CUDA) set(GGML_HEADERS_CUDA ggml-cuda.h) @@ -472,21 +486,6 @@ if (LLAMA_CUDA) else() set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} CUDA::cuda_driver) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ... endif() - - if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES) - # 52 == lowest CUDA 12 standard - # 60 == f16 CUDA intrinsics - # 61 == integer CUDA intrinsics - # 70 == compute capability at which unrolling a loop in mul_mat_q kernels is faster - if (LLAMA_CUDA_F16 OR LLAMA_CUDA_DMMV_F16) - set(CMAKE_CUDA_ARCHITECTURES "60;61;70") # needed for f16 CUDA intrinsics - else() - set(CMAKE_CUDA_ARCHITECTURES "52;61;70") # lowest CUDA 12 standard + lowest for integer intrinsics - #set(CMAKE_CUDA_ARCHITECTURES "") # use this to compile much faster, but only F16 models work - endif() - endif() - message(STATUS "Using CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}") - else() message(WARNING "CUDA not found") endif() From 396b18dfec2c56846e80362db70af09b9e1d70ba Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Tue, 11 Jun 2024 01:00:30 +0100 Subject: [PATCH 10/37] `json`: document schema conversion in GBNF readme, align manual grammar examples & converters (#7841) * json: fix char pattern in grammar converters * json: prevent number precision & whitespace runaways in example grammars * json: add doc to grammar readme --- common/json-schema-to-grammar.cpp | 2 +- examples/json_schema_to_grammar.py | 2 +- .../server/public/json-schema-to-grammar.mjs | 2 +- grammars/README.md | 39 +++++++++++++++++++ grammars/json.gbnf | 6 +-- grammars/json_arr.gbnf | 6 +-- tests/test-json-schema-to-grammar.cpp | 38 +++++++++--------- 7 files changed, 67 insertions(+), 28 deletions(-) diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp index 737bae27c..11221a32f 100644 --- a/common/json-schema-to-grammar.cpp +++ b/common/json-schema-to-grammar.cpp @@ -57,7 +57,7 @@ std::unordered_map PRIMITIVE_RULES = { {"object", {"\"{\" space ( string \":\" space value (\",\" space string \":\" space value)* )? \"}\" space", {"string", "value"}}}, {"array", {"\"[\" space ( value (\",\" space value)* )? \"]\" space", {"value"}}}, {"uuid", {"\"\\\"\" [0-9a-fA-F]{8} \"-\" [0-9a-fA-F]{4} \"-\" [0-9a-fA-F]{4} \"-\" [0-9a-fA-F]{4} \"-\" [0-9a-fA-F]{12} \"\\\"\" space", {}}}, - {"char", {"[^\"\\\\] | \"\\\\\" ([\"\\\\/bfnrt] | \"u\" [0-9a-fA-F]{4})", {}}}, + {"char", {"[^\"\\\\\\x7F\\x00-\\x1F] | [\\\\] ([\"\\\\bfnrt] | \"u\" [0-9a-fA-F]{4})", {}}}, {"string", {"\"\\\"\" char* \"\\\"\" space", {"char"}}}, {"null", {"\"null\" space", {}}}, }; diff --git a/examples/json_schema_to_grammar.py b/examples/json_schema_to_grammar.py index 7d889c3fe..cd444d010 100755 --- a/examples/json_schema_to_grammar.py +++ b/examples/json_schema_to_grammar.py @@ -43,7 +43,7 @@ PRIMITIVE_RULES = { 'object' : BuiltinRule('"{" space ( string ":" space value ("," space string ":" space value)* )? "}" space', ['string', 'value']), 'array' : BuiltinRule('"[" space ( value ("," space value)* )? "]" space', ['value']), 'uuid' : BuiltinRule(r'"\"" [0-9a-fA-F]{8} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{12} "\"" space', []), - 'char' : BuiltinRule(r'[^"\\] | "\\" (["\\/bfnrt] | "u" [0-9a-fA-F]{4})', []), + 'char' : BuiltinRule(r'[^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})', []), 'string' : BuiltinRule(r'"\"" char* "\"" space', ['char']), 'null' : BuiltinRule('"null" space', []), } diff --git a/examples/server/public/json-schema-to-grammar.mjs b/examples/server/public/json-schema-to-grammar.mjs index cef11eab8..dc2468396 100644 --- a/examples/server/public/json-schema-to-grammar.mjs +++ b/examples/server/public/json-schema-to-grammar.mjs @@ -41,7 +41,7 @@ const PRIMITIVE_RULES = { object : new BuiltinRule('"{" space ( string ":" space value ("," space string ":" space value)* )? "}" space', ['string', 'value']), array : new BuiltinRule('"[" space ( value ("," space value)* )? "]" space', ['value']), uuid : new BuiltinRule('"\\"" [0-9a-fA-F]{8} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{4} "-" [0-9a-fA-F]{12} "\\"" space', []), - char : new BuiltinRule(`[^"\\\\] | "\\\\" (["\\\\/bfnrt] | "u" [0-9a-fA-F]{4})`, []), + char : new BuiltinRule(`[^"\\\\\\x7F\\x00-\\x1F] | [\\\\] (["\\\\bfnrt] | "u" [0-9a-fA-F]{4})`, []), string : new BuiltinRule(`"\\"" char* "\\"" space`, ['char']), null : new BuiltinRule('"null" space', []), }; diff --git a/grammars/README.md b/grammars/README.md index 3ffc7cec0..2ec21a4c0 100644 --- a/grammars/README.md +++ b/grammars/README.md @@ -94,6 +94,8 @@ This guide provides a brief overview. Check out the GBNF files in this directory ./main -m --grammar-file grammars/some-grammar.gbnf -p 'Some prompt' ``` +`llama.cpp` can also convert JSON schemas to grammars either ahead of time or at each request, see below. + ## Troubleshooting Grammars currently have performance gotchas (see https://github.com/ggerganov/llama.cpp/issues/4218). @@ -103,3 +105,40 @@ Grammars currently have performance gotchas (see https://github.com/ggerganov/ll A common pattern is to allow repetitions of a pattern `x` up to N times. While semantically correct, the syntax `x? x? x?.... x?` (with N repetitions) may result in extremely slow sampling. Instead, you can write `x{0,N}` (or `(x (x (x ... (x)?...)?)?)?` w/ N-deep nesting in earlier llama.cpp versions). + +## Using GBNF grammars + +You can use GBNF grammars: + +- In the [server](../examples/server)'s completion endpoints, passed as the `grammar` body field +- In the [main](../examples/main) CLI, passed as the `--grammar` & `--grammar-file` flags +- With the [gbnf-validator](../examples/gbnf-validator) tool, to test them against strings. + +## JSON Schemas → GBNF + +`llama.cpp` supports converting a subset of https://json-schema.org/ to GBNF grammars: + +- In the [server](../examples/server): + - For any completion endpoints, passed as the `json_schema` body field + - For the `/chat/completions` endpoint, passed inside the `result_format` body field (e.g. `{"type", "json_object", "schema": {"items": {}}}`) +- In the [main](../examples/main) CLI, passed as the `--json` / `-j` flag +- To convert to a grammar ahead of time: + - in CLI, with [json_schema_to_grammar.py](../examples/json_schema_to_grammar.py) + - in JavaScript with [json-schema-to-grammar.mjs](../examples/server/public/json-schema-to-grammar.mjs) (this is used by the [server](../examples/server)'s Web UI) + +Take a look at [tests](../../tests/test-json-schema-to-grammar.cpp) to see which features are likely supported (you'll also find usage examples in https://github.com/ggerganov/llama.cpp/pull/5978, https://github.com/ggerganov/llama.cpp/pull/6659 & https://github.com/ggerganov/llama.cpp/pull/6555). + +Here is also a non-exhaustive list of **unsupported** features: + +- `additionalProperties`: to be fixed in https://github.com/ggerganov/llama.cpp/pull/7840 +- `minimum`, `exclusiveMinimum`, `maximum`, `exclusiveMaximum` + - `integer` constraints to be implemented in https://github.com/ggerganov/llama.cpp/pull/7797 +- Remote `$ref`s in the C++ version (Python & JavaScript versions fetch https refs) +- Mixing `properties` w/ `anyOf` / `oneOf` in the same type (https://github.com/ggerganov/llama.cpp/issues/7703) +- `string` formats `uri`, `email` +- [`contains`](https://json-schema.org/draft/2020-12/json-schema-core#name-contains) / `minContains` +- `uniqueItems` +- `$anchor` (cf. [dereferencing](https://json-schema.org/draft/2020-12/json-schema-core#name-dereferencing)) +- [`not`](https://json-schema.org/draft/2020-12/json-schema-core#name-not) +- [Conditionals](https://json-schema.org/draft/2020-12/json-schema-core#name-keywords-for-applying-subsche) `if` / `then` / `else` / `dependentSchemas` +- [`patternProperties`](https://json-schema.org/draft/2020-12/json-schema-core#name-patternproperties) diff --git a/grammars/json.gbnf b/grammars/json.gbnf index a8a80752e..064a53f8a 100644 --- a/grammars/json.gbnf +++ b/grammars/json.gbnf @@ -16,10 +16,10 @@ array ::= string ::= "\"" ( [^"\\\x7F\x00-\x1F] | - "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes + "\\" (["\\bfnrt] | "u" [0-9a-fA-F]{4}) # escapes )* "\"" ws -number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws +number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws # Optional space: by convention, applied in this grammar after literal chars when allowed -ws ::= ([ \t\n] ws)? +ws ::= [ \t\n]{0,20} diff --git a/grammars/json_arr.gbnf b/grammars/json_arr.gbnf index 31a3202f8..bd1312d96 100644 --- a/grammars/json_arr.gbnf +++ b/grammars/json_arr.gbnf @@ -25,10 +25,10 @@ array ::= string ::= "\"" ( [^"\\\x7F\x00-\x1F] | - "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes + "\\" (["\\bfnrt] | "u" [0-9a-fA-F]{4}) # escapes )* "\"" ws -number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws +number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [1-9] [0-9]{0,15})? ws # Optional space: by convention, applied in this grammar after literal chars when allowed -ws ::= ([ \t\n] ws)? +ws ::= [ \t\n]{0,20} diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index 052c08073..bea876bd1 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -105,7 +105,7 @@ static void test_all(const std::string & lang, std::function Date: Tue, 11 Jun 2024 02:22:57 +0100 Subject: [PATCH 11/37] json: refine constraint for whitespace to avoid runaways yet allow pretty print (#7866) --- common/json-schema-to-grammar.cpp | 2 +- examples/json_schema_to_grammar.py | 5 +- .../server/public/json-schema-to-grammar.mjs | 2 +- grammars/json.gbnf | 2 +- grammars/json_arr.gbnf | 2 +- tests/test-json-schema-to-grammar.cpp | 76 +++++++++---------- 6 files changed, 44 insertions(+), 45 deletions(-) diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp index 11221a32f..10b9b3d1d 100644 --- a/common/json-schema-to-grammar.cpp +++ b/common/json-schema-to-grammar.cpp @@ -40,7 +40,7 @@ static std::string build_repetition(const std::string & item_rule, int min_items return result; } -const std::string SPACE_RULE = "\" \"?"; +const std::string SPACE_RULE = "| \" \" | \"\\n\" [ \\t]{0,20}"; struct BuiltinRule { std::string content; diff --git a/examples/json_schema_to_grammar.py b/examples/json_schema_to_grammar.py index cd444d010..ab19e20df 100755 --- a/examples/json_schema_to_grammar.py +++ b/examples/json_schema_to_grammar.py @@ -29,9 +29,8 @@ class BuiltinRule: self.content = content self.deps = deps or [] -# whitespace is constrained to a single space char to prevent model "running away" in -# whitespace. Also maybe improves generation quality? -SPACE_RULE = '" "?' +# Constraining spaces to prevent model "running away". +SPACE_RULE = '| " " | "\\n" [ \\t]{0,20}' PRIMITIVE_RULES = { 'boolean' : BuiltinRule('("true" | "false") space', []), diff --git a/examples/server/public/json-schema-to-grammar.mjs b/examples/server/public/json-schema-to-grammar.mjs index dc2468396..faed6a32c 100644 --- a/examples/server/public/json-schema-to-grammar.mjs +++ b/examples/server/public/json-schema-to-grammar.mjs @@ -1,5 +1,5 @@ // WARNING: This file was ported from json_schema_to_grammar.py, please fix bugs / add features there first. -const SPACE_RULE = '" "?'; +const SPACE_RULE = '| " " | "\\n" [ \\t]{0,20}'; function _buildRepetition(itemRule, minItems, maxItems, opts={}) { if (minItems === 0 && maxItems === 1) { diff --git a/grammars/json.gbnf b/grammars/json.gbnf index 064a53f8a..b6448c87b 100644 --- a/grammars/json.gbnf +++ b/grammars/json.gbnf @@ -22,4 +22,4 @@ string ::= number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws # Optional space: by convention, applied in this grammar after literal chars when allowed -ws ::= [ \t\n]{0,20} +ws ::= | " " | "\n" [ \t]{0,20} diff --git a/grammars/json_arr.gbnf b/grammars/json_arr.gbnf index bd1312d96..b3dc6f9b1 100644 --- a/grammars/json_arr.gbnf +++ b/grammars/json_arr.gbnf @@ -31,4 +31,4 @@ string ::= number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [1-9] [0-9]{0,15})? ws # Optional space: by convention, applied in this grammar after literal chars when allowed -ws ::= [ \t\n]{0,20} +ws ::= | " " | "\n" [ \t]{0,20} diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index bea876bd1..a33104dea 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -112,7 +112,7 @@ static void test_all(const std::string & lang, std::function Date: Tue, 11 Jun 2024 07:59:20 +0200 Subject: [PATCH 12/37] fix CUDA CI by using a windows-2019 image (#7861) * try to fix CUDA ci with --allow-unsupported-compiler * trigger when build.yml changes * another test * try exllama/bdashore3 method * install vs build tools before cuda toolkit * try win-2019 --- .github/workflows/build.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 93669d531..3c04cfc29 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ on: paths: ['.github/workflows/**', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.swift', '**/*.m'] pull_request: types: [opened, synchronize, reopened] - paths: ['**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.swift', '**/*.m'] + paths: ['.github/workflows/build.yml', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cuh', '**/*.swift', '**/*.m'] concurrency: group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }} @@ -684,7 +684,7 @@ jobs: cmake --build build --config ${{ matrix.build }} -j $(nproc) windows-latest-cmake: - runs-on: windows-latest + runs-on: windows-2019 env: OPENBLAS_VERSION: 0.3.23 @@ -829,7 +829,7 @@ jobs: name: llama-bin-win-${{ matrix.build }}.zip windows-latest-cmake-cuda: - runs-on: windows-latest + runs-on: windows-2019 strategy: matrix: @@ -843,8 +843,9 @@ jobs: with: fetch-depth: 0 - - uses: Jimver/cuda-toolkit@v0.2.11 + - name: Install CUDA toolkit id: cuda-toolkit + uses: Jimver/cuda-toolkit@v0.2.15 with: cuda: ${{ matrix.cuda }} method: 'network' From bdcb8f42221bc40c411150a009a3d3a30fa74722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Tue, 11 Jun 2024 08:26:07 +0200 Subject: [PATCH 13/37] CUDA: int8 tensor cores for MMQ (q4_K, q5_K, q6_K) (#7860) --- ggml-cuda/mma.cuh | 66 ++++++++++ ggml-cuda/mmq.cuh | 300 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 360 insertions(+), 6 deletions(-) diff --git a/ggml-cuda/mma.cuh b/ggml-cuda/mma.cuh index 71e8e3429..63e07fbc2 100644 --- a/ggml-cuda/mma.cuh +++ b/ggml-cuda/mma.cuh @@ -1,5 +1,27 @@ #include "common.cuh" +struct mma_int_A_I16K4 { + static constexpr int I = 16; + static constexpr int K = 4; + static constexpr int ne = 2; + + int x[ne] = {0}; + + static __device__ __forceinline__ int get_i(const int l) { + const int ret = (l%2) * (I/2) + threadIdx.x / K; + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < I); + return ret; + } + + static __device__ __forceinline__ int get_k(const int /* l */) { + const int ret = threadIdx.x % K; + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < K); + return ret; + } +}; + struct mma_int_A_I16K8 { static constexpr int I = 16; static constexpr int K = 8; @@ -22,6 +44,28 @@ struct mma_int_A_I16K8 { } }; +struct mma_int_B_J8K4 { + static constexpr int J = 8; + static constexpr int K = 4; + static constexpr int ne = 1; + + int x[ne] = {0}; + + static __device__ __forceinline__ int get_j(const int /* l */) { + const int ret = threadIdx.x / K; + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < J); + return ret; + } + + static __device__ __forceinline__ int get_k(const int /* l */) { + const int ret = threadIdx.x % K; + GGML_CUDA_ASSUME(ret >= 0); + GGML_CUDA_ASSUME(ret < K); + return ret; + } +}; + struct mma_int_B_J8K8 { static constexpr int J = 8; static constexpr int K = 8; @@ -65,6 +109,28 @@ struct mma_int_C_I16J8 { return ret; } + __device__ __forceinline__ void mma_K4(const mma_int_A_I16K4 & mma_A, const mma_int_B_J8K4 & mma_B) { +#ifdef INT8_MMA_AVAILABLE +#if __CUDA_ARCH__ >= CC_AMPERE + asm("mma.sync.aligned.m16n8k16.row.col.s32.s8.s8.s32 {%0, %1, %2, %3}, {%4, %5}, {%6}, {%0, %1, %2, %3};" + : "+r"(x[0]), "+r"(x[1]), "+r"(x[2]), "+r"(x[3]) + : "r"(mma_A.x[0]), "r"(mma_A.x[1]), "r"(mma_B.x[0])); +#else + // On Turing m16n8k16 mma is not available, use 2x m8n8k16 mma instead: + asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};" + : "+r"(x[0]), "+r"(x[1]) + : "r"(mma_A.x[0]), "r"(mma_B.x[0])); + asm("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 {%0, %1}, {%2}, {%3}, {%0, %1};" + : "+r"(x[2]), "+r"(x[3]) + : "r"(mma_A.x[1]), "r"(mma_B.x[0])); +#endif // __CUDA_ARCH__ >= CC_AMPERE +#else + GGML_UNUSED(mma_A); + GGML_UNUSED(mma_B); + NO_DEVICE_CODE; +#endif // INT8_MMA_AVAILABLE + } + __device__ __forceinline__ void mma_K8(const mma_int_A_I16K8 & mma_A, const mma_int_B_J8K8 & mma_B) { #ifdef INT8_MMA_AVAILABLE #if __CUDA_ARCH__ >= CC_AMPERE diff --git a/ggml-cuda/mmq.cuh b/ggml-cuda/mmq.cuh index 62111f376..01e2086b4 100644 --- a/ggml-cuda/mmq.cuh +++ b/ggml-cuda/mmq.cuh @@ -1089,7 +1089,7 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q4_K_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q4_K_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { @@ -1115,6 +1115,97 @@ static __device__ __forceinline__ void vec_dot_q4_K_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void vec_dot_q4_K_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K8 mma_A; + typedef mma_int_B_J8K8 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const int * y_qs = (const int *) y + 4; + const half2 * y_ds = (const half2 *) y; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + + mma_A A[2]; + int scA[mma_C::ne/2][2]; + int mA[mma_C::ne/2][2]; + half2 dmA[mma_C::ne/2]; +#pragma unroll + for (int kvdr = 0; kvdr < VDR_Q4_K_Q8_1_MMQ; kvdr += 4) { +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = k0 + mma_A::get_k(l); + + A[kvdr/4].x[l] = (x_ql[i*(WARP_SIZE + 1) + k] >> kvdr) & 0x0F0F0F0F; + } + +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + const uint8_t * sc = ((const uint8_t *) &x_sc[i * (WARP_SIZE/8) + i/8 + k0/16]) + 2 * ((k0 % 16) / 8); + const uint8_t * m = sc + 8; + + scA[l][kvdr/4] = sc[kvdr/4]; + mA[l][kvdr/4] = m[kvdr/4]; + } + } + +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dmA[l] = x_dm[i*(WARP_SIZE/QI5_K) + i/QI5_K + k0/QI5_K]; + } + +#pragma unroll + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + float tmpd[mma_C::ne] = {0.0f}; + float tmpm[mma_C::ne] = {0.0f}; + +#pragma unroll + for (int kvdr = 0; kvdr < VDR_Q5_K_Q8_1_MMQ; kvdr += 4) { + mma_C C; + mma_B B; + half2 dsB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = (2*k0 + 2*kvdr + mma_B::get_k(l)) % WARP_SIZE; + + B.x[l] = y_qs[j*MMQ_TILE_Y_K + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dsB[l] = y_ds[j*MMQ_TILE_Y_K + ((2*k0 + 2*kvdr)/QI8_1) % (WARP_SIZE/QI8_1)]; + } + + C.mma_K8(A[kvdr/4], B); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + tmpd[l] += (C.x[l]*scA[l/2][kvdr/4]) * __low2float(dsB[l%2]); + tmpm[l] += mA[l/2][kvdr/4] * __high2float(dsB[l%2]); + } + } + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + sum[(j0/mma_B::J)*mma_C::ne + l] += __low2float(dmA[l/2])*tmpd[l] - __high2float(dmA[l/2])*tmpm[l]; + } + } +} + template static __device__ __forceinline__ void load_tiles_q5_K( const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh, int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) { @@ -1188,7 +1279,7 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q5_K_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q5_K_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { @@ -1214,6 +1305,97 @@ static __device__ __forceinline__ void vec_dot_q5_K_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void vec_dot_q5_K_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K8 mma_A; + typedef mma_int_B_J8K8 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const int * y_qs = (const int *) y + 4; + const half2 * y_ds = (const half2 *) y; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + + mma_A A[2]; + int scA[mma_C::ne/2][2]; + int mA[mma_C::ne/2][2]; + half2 dmA[mma_C::ne/2]; +#pragma unroll + for (int kvdr = 0; kvdr < VDR_Q5_K_Q8_1_MMQ; kvdr += 4) { +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = QR5_K*k0 + QR5_K*kvdr + mma_A::get_k(l); + + A[kvdr/4].x[l] = x_ql[i*(QR5_K*WARP_SIZE + 1) + k]; + } + +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + const uint8_t * sc = ((const uint8_t *) &x_sc[i * (WARP_SIZE/8) + i/8 + k0/16]) + 2 * ((k0 % 16) / 8); + const uint8_t * m = sc + 8; + + scA[l][kvdr/4] = sc[kvdr/4]; + mA[l][kvdr/4] = m[kvdr/4]; + } + } + +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dmA[l] = x_dm[i*(WARP_SIZE/QI5_K) + i/QI5_K + k0/QI5_K]; + } + +#pragma unroll + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + float tmpd[mma_C::ne] = {0.0f}; + float tmpm[mma_C::ne] = {0.0f}; + +#pragma unroll + for (int kvdr = 0; kvdr < VDR_Q5_K_Q8_1_MMQ; kvdr += 4) { + mma_C C; + mma_B B; + half2 dsB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = (2*k0 + 2*kvdr + mma_B::get_k(l)) % WARP_SIZE; + + B.x[l] = y_qs[j*MMQ_TILE_Y_K + k]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dsB[l] = y_ds[j*MMQ_TILE_Y_K + ((2*k0 + 2*kvdr)/QI8_1) % (WARP_SIZE/QI8_1)]; + } + + C.mma_K8(A[kvdr/4], B); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + tmpd[l] += (C.x[l]*scA[l/2][kvdr/4]) * __low2float(dsB[l%2]); + tmpm[l] += mA[l/2][kvdr/4] * __high2float(dsB[l%2]); + } + } + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + sum[(j0/mma_B::J)*mma_C::ne + l] += __low2float(dmA[l/2])*tmpd[l] - __high2float(dmA[l/2])*tmpm[l]; + } + } +} + template static __device__ __forceinline__ void load_tiles_q6_K( const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh, int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) { @@ -1280,7 +1462,7 @@ template static __device__ __forceinlin } template -static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mul_mat( +static __device__ __forceinline__ void vec_dot_q6_K_q8_1_dp4a( const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, const int * __restrict__ y, float * __restrict__ sum, const int & k0) { @@ -1307,6 +1489,97 @@ static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mul_mat( } } +template +static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mma( + const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc, + const int * __restrict__ y, float * __restrict__ sum, const int & k0) { + + GGML_UNUSED(x_qh); GGML_UNUSED(x_sc); + + typedef mma_int_A_I16K4 mma_A; + typedef mma_int_B_J8K4 mma_B; + typedef mma_int_C_I16J8 mma_C; + + const float * x_df = (const float *) x_dm; + const int * y_qs = (const int *) y + 4; + const float * y_df = (const float *) y; + + const int i0 = threadIdx.y*mma_A::I; + static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y"); + + mma_A A[4]; + int scA[mma_C::ne/2][4]; + float dA[mma_C::ne/2]; +#pragma unroll + for (int kvdr = 0; kvdr < VDR_Q6_K_Q8_1_MMQ; kvdr += 4) { +#pragma unroll + for (int l = 0; l < mma_A::ne; ++l) { + const int i = i0 + mma_A::get_i(l); + const int k = QR6_K*k0 + QR6_K*kvdr + mma_A::get_k(l); + + A[kvdr/2 + 0].x[l] = x_ql[i*(QR6_K*WARP_SIZE + 1) + k + 0]; + A[kvdr/2 + 1].x[l] = x_ql[i*(QR6_K*WARP_SIZE + 1) + k + mma_A::K]; + } + +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + const int8_t * sc = ((const int8_t *) &x_sc[i * (WARP_SIZE/8) + i/8 + k0/8]); + + scA[l][kvdr/2 + 0] = sc[kvdr/2 + 0]; + scA[l][kvdr/2 + 1] = sc[kvdr/2 + 1]; + } + } + +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int i = i0 + mma_C::get_i(2*l); + + dA[l] = x_df[i*(WARP_SIZE/QI6_K) + i/QI6_K + k0/QI6_K]; + } + +#pragma unroll + for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) { + float tmp[mma_C::ne] = {0.0f}; + +#pragma unroll + for (int kvdr = 0; kvdr < VDR_Q6_K_Q8_1_MMQ; kvdr += 4) { + mma_C C[2]; + mma_B B[2]; + float dB[mma_C::ne/2]; + +#pragma unroll + for (int l = 0; l < mma_B::ne; ++l) { + const int j = j0 + mma_B::get_j(l); + const int k = (2*k0 + 2*kvdr + mma_B::get_k(l)) % WARP_SIZE; + + B[0].x[l] = y_qs[j*MMQ_TILE_Y_K + k + 0]; + B[1].x[l] = y_qs[j*MMQ_TILE_Y_K + k + mma_B::K]; + } +#pragma unroll + for (int l = 0; l < mma_C::ne/2; ++l) { + const int j = j0 + mma_C::get_j(l); + + dB[l] = y_df[j*MMQ_TILE_Y_K + ((2*k0 + 2*kvdr)/QI8_1) % (WARP_SIZE/QI8_1)]; + } + + C[0].mma_K4(A[kvdr/2 + 0], B[0]); + C[1].mma_K4(A[kvdr/2 + 1], B[1]); + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + tmp[l] += (C[0].x[l]*scA[l/2][kvdr/2 + 0] + C[1].x[l]*scA[l/2][kvdr/2 + 1])*dB[l%2]; + } + } + +#pragma unroll + for (int l = 0; l < mma_C::ne; ++l) { + sum[(j0/mma_B::J)*mma_C::ne + l] += tmp[l]*dA[l/2]; + } + } +} + template static __device__ __forceinline__ void mmq_write_back_dp4a(const float * __restrict__ sum, float * __restrict__ dst, const int & ne0, const int & ne1) { #pragma unroll @@ -1448,24 +1721,39 @@ template struct mmq_type_traits { static constexpr int vdr = VDR_Q4_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q4_K; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_K_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_K_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q4_K_q8_1_dp4a; static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; template struct mmq_type_traits { static constexpr int vdr = VDR_Q5_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q5_K; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_K_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_K_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q5_K_q8_1_dp4a; static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; template struct mmq_type_traits { static constexpr int vdr = VDR_Q6_K_Q8_1_MMQ; static constexpr load_tiles_mmq_t load_tiles = load_tiles_q6_K; - static constexpr vec_dot_mmq_t vec_dot = vec_dot_q6_K_q8_1_mul_mat; +#ifdef INT8_MMA_AVAILABLE + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q6_K_q8_1_mma; + static constexpr mmq_write_back_t write_back = mmq_write_back_mma; +#else + static constexpr vec_dot_mmq_t vec_dot = vec_dot_q6_K_q8_1_dp4a; static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a; +#endif // INT8_MMA_AVAILABLE }; static int mmq_need_sum(const ggml_type type_x) { From 4bfe50f741479c1df1c377260c3ff5702586719e Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Tue, 11 Jun 2024 10:10:20 +0300 Subject: [PATCH 14/37] tests : check the Python version (#7872) ggml-ci --- tests/test-json-schema-to-grammar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index a33104dea..87bc66b69 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -870,7 +870,7 @@ int main() { } }); - if (getenv("LLAMA_PYTHON_AVAILABLE") || (std::system("python --version") == 0)) { + if (getenv("LLAMA_PYTHON_AVAILABLE") || (std::system("python -c \"import sys; exit(1) if sys.version_info < (3, 8) else print('Python version is sufficient')\"") == 0)) { test_all("Python", [](const TestCase & tc) { write("test-json-schema-input.tmp", tc.schema); tc.verify_status(std::system( @@ -878,7 +878,7 @@ int main() { tc.verify(read("test-grammar-output.tmp")); }); } else { - fprintf(stderr, "\033[33mWARNING: Python not found, skipping Python JSON schema -> grammar tests.\n\033[0m"); + fprintf(stderr, "\033[33mWARNING: Python not found (min version required is 3.8), skipping Python JSON schema -> grammar tests.\n\033[0m"); } if (getenv("LLAMA_NODE_AVAILABLE") || (std::system("node --version") == 0)) { From 148995e5e57b313cce2672f75610db58c6327a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Tue, 11 Jun 2024 14:45:40 +0200 Subject: [PATCH 15/37] llama-bench: more compact markdown tables (#7879) --- examples/llama-bench/llama-bench.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/examples/llama-bench/llama-bench.cpp b/examples/llama-bench/llama-bench.cpp index 5c31548a6..61f5a5a09 100644 --- a/examples/llama-bench/llama-bench.cpp +++ b/examples/llama-bench/llama-bench.cpp @@ -1033,6 +1033,27 @@ struct markdown_printer : public printer { if (field == "n_gpu_layers") { return 3; } + if (field == "n_threads") { + return 7; + } + if (field == "n_batch") { + return 7; + } + if (field == "n_ubatch") { + return 8; + } + if (field == "type_k" || field == "type_v") { + return 6; + } + if (field == "split_mode") { + return 5; + } + if (field == "flash_attn") { + return 2; + } + if (field == "use_mmap") { + return 4; + } if (field == "test") { return 13; } From 6fe42d073f0554eada93ac9d40574025aeedb703 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 12 Jun 2024 00:43:41 +1000 Subject: [PATCH 16/37] github: move PR template to .github/ root (#7868) --- .github/{PULL_REQUEST_TEMPLATE => }/pull_request_template.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{PULL_REQUEST_TEMPLATE => }/pull_request_template.md (100%) diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/pull_request_template.md similarity index 100% rename from .github/PULL_REQUEST_TEMPLATE/pull_request_template.md rename to .github/pull_request_template.md From 14f83526cd27f638c856ea6eff08110b9860eb2a Mon Sep 17 00:00:00 2001 From: Deven Mistry <31466137+deven367@users.noreply.github.com> Date: Tue, 11 Jun 2024 12:18:58 -0400 Subject: [PATCH 17/37] fix broken link in pr template (#7880) [no ci] * fix broken link in pr template * Update pull_request_template.md [no ci] --------- Co-authored-by: Brian --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 0852fded5..e6d032d87 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,4 +2,4 @@ - [ ] Review Complexity : Low - [ ] Review Complexity : Medium - [ ] Review Complexity : High -- [ ] I have read the [contributing guidelines](CONTRIBUTING.md) +- [ ] I have read the [contributing guidelines](https://github.com/ggerganov/llama.cpp/blob/master/CONTRIBUTING.md) From ef52d1d16afc695d798396cdd13594ea5e45a9dd Mon Sep 17 00:00:00 2001 From: 0cc4m Date: Tue, 11 Jun 2024 21:20:29 +0200 Subject: [PATCH 18/37] Update Vulkan RoPE implementation (#7818) * Update Vulkan RoPE implementation * Return nullptr on alloc_buffer when allocation fails, instead of throwing an exception Minor fixes * Fix segfault when running out of VRAM Co-authored-by: slaren --------- Co-authored-by: slaren --- ggml-alloc.c | 2 +- ggml-vulkan-shaders.hpp | 2377 ++++++++++++++++++----------------- ggml-vulkan.cpp | 93 +- ggml_vk_generate_shaders.py | 66 +- 4 files changed, 1311 insertions(+), 1227 deletions(-) diff --git a/ggml-alloc.c b/ggml-alloc.c index 73a3c1575..eb75962d4 100644 --- a/ggml-alloc.c +++ b/ggml-alloc.c @@ -886,7 +886,7 @@ static bool alloc_tensor_range(struct ggml_context * ctx, fprintf(stderr, "%s: failed to allocate %s buffer of size %zu\n", __func__, ggml_backend_buft_name(buft), size); #endif for (size_t i = 0; i < *n_buffers; i++) { - ggml_backend_buffer_free(*buffers[i]); + ggml_backend_buffer_free((*buffers)[i]); } free(*buffers); return false; diff --git a/ggml-vulkan-shaders.hpp b/ggml-vulkan-shaders.hpp index b50f55860..4a8ee3415 100644 --- a/ggml-vulkan-shaders.hpp +++ b/ggml-vulkan-shaders.hpp @@ -137706,326 +137706,72 @@ unsigned char rms_norm_f32_data[] = { }; const uint64_t rms_norm_f32_len = 2344; -unsigned char rope_f16_data[] = { +unsigned char rope_neox_f16_data[] = { 0x03,0x02,0x23,0x07,0x00,0x05,0x01,0x00,0x0b,0x00,0x0d,0x00, -0x1c,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, +0x50,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, 0x01,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x51,0x11,0x00,0x00, 0x0b,0x00,0x06,0x00,0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c, 0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,0x00,0x00,0x00,0x00, 0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x0f,0x00,0x0a,0x00,0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x67,0x00,0x00,0x00,0x8b,0x00,0x00,0x00,0xad,0x00,0x00,0x00, -0xbd,0x00,0x00,0x00,0x10,0x00,0x06,0x00,0x04,0x00,0x00,0x00, -0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x29,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x10,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x05,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x2a,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x67,0x00,0x00,0x00, -0x0b,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x88,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x48,0x00,0x04,0x00,0x89,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x89,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x03,0x00,0x89,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x8b,0x00,0x00,0x00,0x22,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x8b,0x00,0x00,0x00, -0x21,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xaa,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x48,0x00,0x04,0x00,0xab,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0xab,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x03,0x00,0xab,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xad,0x00,0x00,0x00,0x22,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xad,0x00,0x00,0x00, -0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xba,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x48,0x00,0x04,0x00,0xbb,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x19,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0xbb,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x03,0x00,0xbb,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xbd,0x00,0x00,0x00,0x22,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xbd,0x00,0x00,0x00, -0x21,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xd5,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x19,0x00,0x00,0x00, -0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00, -0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00, -0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x15,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x1b,0x00,0x00,0x00,0x6f,0x12,0x83,0x3a,0x2b,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x80,0x3f, -0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0x28,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x1c,0x00,0x04,0x00, -0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x28,0x00,0x00,0x00, -0x1e,0x00,0x09,0x00,0x2a,0x00,0x00,0x00,0x07,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x29,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x2b,0x00,0x00,0x00,0x09,0x00,0x00,0x00, -0x2a,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x2b,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x15,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x2e,0x00,0x00,0x00, -0x05,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2f,0x00,0x00,0x00, -0x09,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x39,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x14,0x00,0x02,0x00,0x3c,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x41,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x52,0x00,0x00,0x00,0xcd,0xcc,0xcc,0x3d, -0x17,0x00,0x04,0x00,0x65,0x00,0x00,0x00,0x07,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x66,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0x66,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x68,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x69,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x72,0x00,0x00,0x00,0x09,0x00,0x00,0x00, -0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x82,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, -0x88,0x00,0x00,0x00,0x2d,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, -0x89,0x00,0x00,0x00,0x88,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0x8a,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x89,0x00,0x00,0x00, -0x3b,0x00,0x04,0x00,0x8a,0x00,0x00,0x00,0x8b,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x8d,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0x2d,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x93,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0x16,0x00,0x03,0x00,0xa9,0x00,0x00,0x00,0x10,0x00,0x00,0x00, -0x1d,0x00,0x03,0x00,0xaa,0x00,0x00,0x00,0xa9,0x00,0x00,0x00, -0x1e,0x00,0x03,0x00,0xab,0x00,0x00,0x00,0xaa,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0xac,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0xab,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0xac,0x00,0x00,0x00, -0xad,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0xb0,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0xa9,0x00,0x00,0x00, -0x1d,0x00,0x03,0x00,0xba,0x00,0x00,0x00,0xa9,0x00,0x00,0x00, -0x1e,0x00,0x03,0x00,0xbb,0x00,0x00,0x00,0xba,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0xbc,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0xbb,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0xbc,0x00,0x00,0x00, -0xbd,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0xd4,0x00,0x00,0x00,0x00,0x01,0x00,0x00, -0x2c,0x00,0x06,0x00,0x65,0x00,0x00,0x00,0xd5,0x00,0x00,0x00, -0x68,0x00,0x00,0x00,0xd4,0x00,0x00,0x00,0x68,0x00,0x00,0x00, -0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0xd6,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00,0x6e,0x00,0x00,0x00, -0xd7,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xd7,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x69,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, -0x67,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x6b,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, -0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, -0x6b,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x69,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x67,0x00,0x00,0x00, -0x6e,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0x70,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x72,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0x74,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0xae,0x00,0x05,0x00, -0x3c,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, -0x74,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x77,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x75,0x00,0x00,0x00, -0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0x76,0x00,0x00,0x00,0xf9,0x00,0x02,0x00,0xd6,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00,0x84,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x70,0x00,0x00,0x00, -0x74,0x00,0x00,0x00,0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x7f,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x72,0x00,0x00,0x00,0x83,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x82,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x84,0x00,0x00,0x00,0x83,0x00,0x00,0x00, -0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x85,0x00,0x00,0x00, -0x70,0x00,0x00,0x00,0x84,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0x8d,0x00,0x00,0x00,0x8e,0x00,0x00,0x00,0x8b,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x85,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x8f,0x00,0x00,0x00,0x8e,0x00,0x00,0x00, -0x6f,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x92,0x00,0x00,0x00, -0x8f,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00, -0x94,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x93,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x95,0x00,0x00,0x00, -0x94,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x97,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x7f,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x98,0x00,0x00,0x00,0x97,0x00,0x00,0x00, -0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x9b,0x00,0x00,0x00, -0x74,0x00,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x9c,0x00,0x00,0x00,0x98,0x00,0x00,0x00,0x9b,0x00,0x00,0x00, -0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x9d,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0x95,0x00,0x00,0x00, -0x9c,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x9e,0x00,0x00,0x00,0x92,0x00,0x00,0x00,0x9d,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00,0xe1,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0xe1,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00,0xe3,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xe4,0x00,0x00,0x00,0xe3,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xe5,0x00,0x00,0x00, -0xe4,0x00,0x00,0x00,0x9e,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x2f,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x39,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0xe8,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0xb7,0x00,0x05,0x00, -0x3c,0x00,0x00,0x00,0xe9,0x00,0x00,0x00,0xe8,0x00,0x00,0x00, -0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x02,0x01,0x00,0x00, -0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0xe9,0x00,0x00,0x00, -0xea,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, -0xea,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0x2f,0x00,0x00,0x00, -0xeb,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x41,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0xec,0x00,0x00,0x00,0xeb,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0x2f,0x00,0x00,0x00,0xed,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x41,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xee,0x00,0x00,0x00,0xed,0x00,0x00,0x00, -0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x0e,0x01,0x00,0x00, -0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x70,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x0f,0x01,0x00,0x00,0x0e,0x01,0x00,0x00, -0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x10,0x01,0x00,0x00, -0x0f,0x01,0x00,0x00,0xec,0x00,0x00,0x00,0x83,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0xee,0x00,0x00,0x00, -0xec,0x00,0x00,0x00,0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x12,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00, -0x1b,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x88,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x13,0x01,0x00,0x00,0x10,0x01,0x00,0x00, -0x12,0x01,0x00,0x00,0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x15,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00, -0x20,0x00,0x00,0x00,0x13,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, -0x06,0x00,0x00,0x00,0x16,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x25,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x15,0x01,0x00,0x00, -0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x17,0x01,0x00,0x00, -0x1f,0x00,0x00,0x00,0x16,0x01,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0xf2,0x00,0x00,0x00,0x17,0x01,0x00,0x00, -0xe8,0x00,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x1a,0x01,0x00,0x00,0x16,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, -0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0xf5,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x1a,0x01,0x00,0x00, -0xe8,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x9e,0x00,0x00,0x00, -0xf2,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0xf9,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0xe5,0x00,0x00,0x00,0xf5,0x00,0x00,0x00,0xf8,0x00,0x00,0x00, -0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xfc,0x00,0x00,0x00, -0x1f,0x00,0x00,0x00,0xe4,0x00,0x00,0x00,0x0c,0x00,0x06,0x00, -0x06,0x00,0x00,0x00,0xfd,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x1c,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, -0x06,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x32,0x00,0x00,0x00,0x52,0x00,0x00,0x00,0xfd,0x00,0x00,0x00, -0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x01,0x01,0x00,0x00,0xe2,0x00,0x00,0x00,0xff,0x00,0x00,0x00, -0xf9,0x00,0x02,0x00,0x02,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, -0x02,0x01,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x19,0x01,0x00,0x00,0xe2,0x00,0x00,0x00,0x77,0x00,0x00,0x00, -0x01,0x01,0x00,0x00,0xea,0x00,0x00,0x00,0xf5,0x00,0x07,0x00, -0x06,0x00,0x00,0x00,0x18,0x01,0x00,0x00,0xe5,0x00,0x00,0x00, -0x77,0x00,0x00,0x00,0xf9,0x00,0x00,0x00,0xea,0x00,0x00,0x00, -0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x04,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x0e,0x00,0x00,0x00,0x18,0x01,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x06,0x01,0x00,0x00, -0x04,0x01,0x00,0x00,0x19,0x01,0x00,0x00,0x0c,0x00,0x06,0x00, -0x06,0x00,0x00,0x00,0x08,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x0d,0x00,0x00,0x00,0x18,0x01,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x0a,0x01,0x00,0x00,0x08,0x01,0x00,0x00, -0x19,0x01,0x00,0x00,0x41,0x00,0x06,0x00,0xb0,0x00,0x00,0x00, -0xb1,0x00,0x00,0x00,0xad,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0x7f,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0xa9,0x00,0x00,0x00, -0xb2,0x00,0x00,0x00,0xb1,0x00,0x00,0x00,0x73,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xb3,0x00,0x00,0x00,0xb2,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xb6,0x00,0x00,0x00, -0x7f,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0xb0,0x00,0x00,0x00,0xb7,0x00,0x00,0x00,0xad,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0xb6,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0xa9,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0xb7,0x00,0x00,0x00, -0x73,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xb9,0x00,0x00,0x00, -0xb8,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0xc5,0x00,0x00,0x00,0xb9,0x00,0x00,0x00,0x0a,0x01,0x00,0x00, -0x7f,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x1b,0x01,0x00,0x00, -0xc5,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0xc6,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0xb3,0x00,0x00,0x00,0x06,0x01,0x00,0x00,0x1b,0x01,0x00,0x00, -0x73,0x00,0x04,0x00,0xa9,0x00,0x00,0x00,0xc7,0x00,0x00,0x00, -0xc6,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xb0,0x00,0x00,0x00, -0xc8,0x00,0x00,0x00,0xbd,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0x7f,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0xc8,0x00,0x00,0x00, -0xc7,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0xd0,0x00,0x00,0x00,0xb9,0x00,0x00,0x00,0x06,0x01,0x00,0x00, -0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0xd1,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0xb3,0x00,0x00,0x00, -0x0a,0x01,0x00,0x00,0xd0,0x00,0x00,0x00,0x73,0x00,0x04,0x00, -0xa9,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0xd1,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0xb0,0x00,0x00,0x00,0xd3,0x00,0x00,0x00, -0xbd,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0xb6,0x00,0x00,0x00, -0x3e,0x00,0x03,0x00,0xd3,0x00,0x00,0x00,0xd2,0x00,0x00,0x00, -0xf9,0x00,0x02,0x00,0xd6,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0xd6,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00, - -}; -const uint64_t rope_f16_len = 3156; - -unsigned char rope_f32_data[] = { -0x03,0x02,0x23,0x07,0x00,0x05,0x01,0x00,0x0b,0x00,0x0d,0x00, -0x17,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, -0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,0x01,0x00,0x00,0x00, -0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30, -0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x0f,0x00,0x0a,0x00,0x05,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x8b,0x00,0x00,0x00, -0xac,0x00,0x00,0x00,0xba,0x00,0x00,0x00,0x10,0x00,0x06,0x00, +0x0f,0x00,0x0b,0x00,0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x8a,0x00,0x00,0x00,0x90,0x00,0x00,0x00, +0xb1,0x00,0x00,0x00,0xcb,0x00,0x00,0x00,0x10,0x00,0x06,0x00, 0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00, 0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, +0x29,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, 0x02,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x08,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x03,0x00,0x00,0x00, 0x23,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x10,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, +0x29,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x10,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, 0x05,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x14,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x47,0x00,0x03,0x00, -0x2a,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x29,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x1c,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x08,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x24,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x09,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0x29,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, 0x67,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x88,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x89,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x89,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x89,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x8b,0x00,0x00,0x00, -0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x8b,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xa9,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xaa,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0xaa,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xaa,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xac,0x00,0x00,0x00, -0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xac,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xb7,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xb8,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x87,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x88,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0xb8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xb8,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xba,0x00,0x00,0x00, +0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x88,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x8a,0x00,0x00,0x00, 0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xba,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xd0,0x00,0x00,0x00,0x0b,0x00,0x00,0x00, +0x8a,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x8d,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x8e,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x8e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x8e,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x90,0x00,0x00,0x00, +0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x90,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xae,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xaf,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0xaf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xaf,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xb1,0x00,0x00,0x00, +0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0xb1,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xc8,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xc9,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0xc9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xc9,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xcb,0x00,0x00,0x00, +0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0xcb,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x07,0x01,0x00,0x00,0x0b,0x00,0x00,0x00, 0x19,0x00,0x00,0x00,0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00, 0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00, 0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00, @@ -138035,25 +137781,26 @@ unsigned char rope_f32_data[] = { 0x06,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x6f,0x12,0x83,0x3a, 0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, 0x00,0x00,0x80,0x3f,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x1c,0x00,0x04,0x00,0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x28,0x00,0x00,0x00,0x1e,0x00,0x09,0x00,0x2a,0x00,0x00,0x00, +0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x04,0x00, +0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x17,0x00,0x00,0x00, +0x1e,0x00,0x0c,0x00,0x29,0x00,0x00,0x00,0x07,0x00,0x00,0x00, 0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x07,0x00,0x00,0x00, 0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x29,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2b,0x00,0x00,0x00, -0x09,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0x2b,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x09,0x00,0x00,0x00, -0x15,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x20,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x2e,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0x2f,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x33,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x39,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x14,0x00,0x02,0x00, -0x3c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x41,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x2a,0x00,0x00,0x00,0x09,0x00,0x00,0x00, +0x29,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x2a,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x15,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2e,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x38,0x00,0x00,0x00, +0x05,0x00,0x00,0x00,0x14,0x00,0x02,0x00,0x3b,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x40,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x44,0x00,0x00,0x00,0x01,0x00,0x00,0x00, 0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x52,0x00,0x00,0x00, 0xcd,0xcc,0xcc,0x3d,0x17,0x00,0x04,0x00,0x65,0x00,0x00,0x00, 0x07,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00, @@ -138064,593 +137811,627 @@ unsigned char rope_f32_data[] = { 0x69,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00, 0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x6e,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x72,0x00,0x00,0x00, -0x09,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x82,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x1d,0x00,0x03,0x00,0x88,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, -0x1e,0x00,0x03,0x00,0x89,0x00,0x00,0x00,0x88,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x8a,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x89,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x8a,0x00,0x00,0x00, -0x8b,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0x8d,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x93,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0xa9,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0xaa,0x00,0x00,0x00, -0xa9,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xab,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0xaa,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0xab,0x00,0x00,0x00,0xac,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0xaf,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0xb7,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0xb8,0x00,0x00,0x00, -0xb7,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xb9,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0xb9,0x00,0x00,0x00,0xba,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0xcf,0x00,0x00,0x00, -0x00,0x01,0x00,0x00,0x2c,0x00,0x06,0x00,0x65,0x00,0x00,0x00, -0xd0,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0xcf,0x00,0x00,0x00, -0x68,0x00,0x00,0x00,0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0xd1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00, -0x6e,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0xd2,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x69,0x00,0x00,0x00, -0x6a,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x68,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x6b,0x00,0x00,0x00, -0x6a,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x6c,0x00,0x00,0x00,0x6b,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x69,0x00,0x00,0x00,0x6f,0x00,0x00,0x00, -0x67,0x00,0x00,0x00,0x6e,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x6f,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x72,0x00,0x00,0x00,0x73,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x74,0x00,0x00,0x00,0x73,0x00,0x00,0x00, -0xae,0x00,0x05,0x00,0x3c,0x00,0x00,0x00,0x75,0x00,0x00,0x00, -0x6c,0x00,0x00,0x00,0x74,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0x77,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, -0x75,0x00,0x00,0x00,0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0x76,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, -0xd1,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00, -0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x7d,0x00,0x00,0x00, -0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00,0x80,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x7d,0x00,0x00,0x00, -0x6c,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x72,0x00,0x00,0x00, -0x83,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x82,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x84,0x00,0x00,0x00, -0x83,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x85,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x84,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0x8d,0x00,0x00,0x00,0x8e,0x00,0x00,0x00, -0x8b,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x85,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, -0x8e,0x00,0x00,0x00,0x6f,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x92,0x00,0x00,0x00,0x8f,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x2f,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x93,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x95,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x70,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x97,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, -0x7f,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x98,0x00,0x00,0x00, -0x97,0x00,0x00,0x00,0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x9b,0x00,0x00,0x00,0x74,0x00,0x00,0x00,0x88,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x9c,0x00,0x00,0x00,0x98,0x00,0x00,0x00, -0x9b,0x00,0x00,0x00,0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x9d,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x1a,0x00,0x00,0x00, -0x95,0x00,0x00,0x00,0x9c,0x00,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x9e,0x00,0x00,0x00,0x92,0x00,0x00,0x00, -0x9d,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00, -0xdc,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x2e,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xdd,0x00,0x00,0x00, -0xdc,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00, -0xde,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x33,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xdf,0x00,0x00,0x00, -0xde,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0xe0,0x00,0x00,0x00,0xdf,0x00,0x00,0x00,0x9e,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00,0xe2,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xe3,0x00,0x00,0x00,0xe2,0x00,0x00,0x00, -0xb7,0x00,0x05,0x00,0x3c,0x00,0x00,0x00,0xe4,0x00,0x00,0x00, -0xe3,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0xfd,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, -0xe4,0x00,0x00,0x00,0xe5,0x00,0x00,0x00,0xfd,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0xe5,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0x2f,0x00,0x00,0x00,0xe6,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x41,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0xe6,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0x2f,0x00,0x00,0x00,0xe8,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x33,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xe9,0x00,0x00,0x00, -0xe8,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x09,0x01,0x00,0x00,0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x0a,0x01,0x00,0x00, -0x09,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x0b,0x01,0x00,0x00,0x0a,0x01,0x00,0x00,0xe7,0x00,0x00,0x00, -0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x0c,0x01,0x00,0x00, -0xe9,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0x0c,0x00,0x07,0x00, -0x06,0x00,0x00,0x00,0x0d,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x28,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x0c,0x01,0x00,0x00, -0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x0e,0x01,0x00,0x00, -0x0b,0x01,0x00,0x00,0x0d,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, -0x06,0x00,0x00,0x00,0x10,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x28,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x0e,0x01,0x00,0x00, -0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x11,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, -0x10,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x12,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x11,0x01,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xed,0x00,0x00,0x00, -0x12,0x01,0x00,0x00,0xe3,0x00,0x00,0x00,0x83,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x15,0x01,0x00,0x00,0x11,0x01,0x00,0x00, -0x1f,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0xf0,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0x15,0x01,0x00,0x00,0xe3,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xf3,0x00,0x00,0x00, -0x9e,0x00,0x00,0x00,0xed,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, -0x06,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x32,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0xf0,0x00,0x00,0x00, -0xf3,0x00,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0xf7,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0xdf,0x00,0x00,0x00, -0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0xf8,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0xf7,0x00,0x00,0x00, -0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0xfa,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x52,0x00,0x00,0x00, -0xf8,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0xdd,0x00,0x00,0x00, -0xfa,0x00,0x00,0x00,0xf9,0x00,0x02,0x00,0xfd,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0xfd,0x00,0x00,0x00,0xf5,0x00,0x07,0x00, -0x06,0x00,0x00,0x00,0x14,0x01,0x00,0x00,0xdd,0x00,0x00,0x00, -0x77,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0xe5,0x00,0x00,0x00, -0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x13,0x01,0x00,0x00, -0xe0,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0xf4,0x00,0x00,0x00, -0xe5,0x00,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, -0xff,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0e,0x00,0x00,0x00, -0x13,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x01,0x01,0x00,0x00,0xff,0x00,0x00,0x00,0x14,0x01,0x00,0x00, -0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x03,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x13,0x01,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x05,0x01,0x00,0x00, -0x03,0x01,0x00,0x00,0x14,0x01,0x00,0x00,0x41,0x00,0x06,0x00, -0xaf,0x00,0x00,0x00,0xb0,0x00,0x00,0x00,0xac,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xb1,0x00,0x00,0x00,0xb0,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xb4,0x00,0x00,0x00, -0x7f,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0xaf,0x00,0x00,0x00,0xb5,0x00,0x00,0x00,0xac,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0xb4,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xb6,0x00,0x00,0x00,0xb5,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xc2,0x00,0x00,0x00, -0xb6,0x00,0x00,0x00,0x05,0x01,0x00,0x00,0x7f,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x16,0x01,0x00,0x00,0xc2,0x00,0x00,0x00, -0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0xc3,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0xb1,0x00,0x00,0x00, -0x01,0x01,0x00,0x00,0x16,0x01,0x00,0x00,0x41,0x00,0x06,0x00, -0xaf,0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0xba,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, -0xc4,0x00,0x00,0x00,0xc3,0x00,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0xcc,0x00,0x00,0x00,0xb6,0x00,0x00,0x00, -0x01,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0xcd,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0xb1,0x00,0x00,0x00,0x05,0x01,0x00,0x00,0xcc,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0xaf,0x00,0x00,0x00,0xce,0x00,0x00,0x00, -0xba,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0xb4,0x00,0x00,0x00, -0x3e,0x00,0x03,0x00,0xce,0x00,0x00,0x00,0xcd,0x00,0x00,0x00, -0xf9,0x00,0x02,0x00,0xd1,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0xd1,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00, - -}; -const uint64_t rope_f32_len = 3072; - -unsigned char rope_neox_f16_data[] = { -0x03,0x02,0x23,0x07,0x00,0x05,0x01,0x00,0x0b,0x00,0x0d,0x00, -0x69,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, -0x01,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x51,0x11,0x00,0x00, -0x0b,0x00,0x06,0x00,0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c, -0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,0x00,0x00,0x00,0x00, -0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x0f,0x00,0x0b,0x00,0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x68,0x00,0x00,0x00,0x98,0x00,0x00,0x00,0x9e,0x00,0x00,0x00, -0xc5,0x00,0x00,0x00,0xd5,0x00,0x00,0x00,0x10,0x00,0x06,0x00, -0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x08,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x10,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, -0x05,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x14,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x1c,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, -0x08,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x09,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x34,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x2a,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x68,0x00,0x00,0x00, -0x0b,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x95,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x48,0x00,0x04,0x00,0x96,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x19,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x96,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x03,0x00,0x96,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x98,0x00,0x00,0x00,0x22,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x98,0x00,0x00,0x00, -0x21,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x9b,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x48,0x00,0x04,0x00,0x9c,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x9c,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x03,0x00,0x9c,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x9e,0x00,0x00,0x00,0x22,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x9e,0x00,0x00,0x00, -0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xc2,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x48,0x00,0x04,0x00,0xc3,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0xc3,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x03,0x00,0xc3,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xc5,0x00,0x00,0x00,0x22,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xc5,0x00,0x00,0x00, -0x21,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xd2,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x48,0x00,0x04,0x00,0xd3,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0xd3,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x03,0x00,0xd3,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xd5,0x00,0x00,0x00,0x22,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xd5,0x00,0x00,0x00, -0x21,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x20,0x01,0x00,0x00,0x0b,0x00,0x00,0x00,0x19,0x00,0x00,0x00, -0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00, -0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00, -0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x15,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x1b,0x00,0x00,0x00,0x6f,0x12,0x83,0x3a,0x2b,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x80,0x3f, -0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0x28,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x1c,0x00,0x04,0x00, -0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x28,0x00,0x00,0x00, -0x1e,0x00,0x0d,0x00,0x2a,0x00,0x00,0x00,0x07,0x00,0x00,0x00, -0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x07,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x07,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2b,0x00,0x00,0x00, -0x09,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0x2b,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x09,0x00,0x00,0x00, -0x15,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x20,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x2e,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0x2f,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x33,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x39,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x14,0x00,0x02,0x00, -0x3c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x41,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x45,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x53,0x00,0x00,0x00,0xcd,0xcc,0xcc,0x3d,0x17,0x00,0x04,0x00, -0x66,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x67,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x66,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x67,0x00,0x00,0x00, -0x68,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x69,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x6a,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0x6f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0x73,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x07,0x00,0x00,0x00, -0x16,0x00,0x03,0x00,0x94,0x00,0x00,0x00,0x10,0x00,0x00,0x00, -0x1d,0x00,0x03,0x00,0x95,0x00,0x00,0x00,0x94,0x00,0x00,0x00, -0x1e,0x00,0x03,0x00,0x96,0x00,0x00,0x00,0x95,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x97,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x96,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x97,0x00,0x00,0x00, -0x98,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, -0x9b,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, -0x9c,0x00,0x00,0x00,0x9b,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0x9d,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x9c,0x00,0x00,0x00, -0x3b,0x00,0x04,0x00,0x9d,0x00,0x00,0x00,0x9e,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xa1,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0xbc,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0x1d,0x00,0x03,0x00,0xc2,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, -0x1e,0x00,0x03,0x00,0xc3,0x00,0x00,0x00,0xc2,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0xc4,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0xc3,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0xc4,0x00,0x00,0x00, -0xc5,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0xc7,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0xcb,0x00,0x00,0x00, -0x0a,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0xd2,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0xd3,0x00,0x00,0x00, -0xd2,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xd4,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0xd3,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0xd4,0x00,0x00,0x00,0xd5,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0xd8,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0xe3,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x1f,0x01,0x00,0x00,0x00,0x01,0x00,0x00, -0x2c,0x00,0x06,0x00,0x66,0x00,0x00,0x00,0x20,0x01,0x00,0x00, -0x69,0x00,0x00,0x00,0x1f,0x01,0x00,0x00,0x69,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x66,0x01,0x00,0x00, -0x00,0x00,0x00,0x3f,0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0x21,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00, -0x6f,0x00,0x00,0x00,0x22,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, -0x22,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x6a,0x00,0x00,0x00, -0x6b,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x69,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, -0x6b,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x6d,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x6a,0x00,0x00,0x00,0x70,0x00,0x00,0x00, -0x68,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x71,0x00,0x00,0x00,0x70,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x73,0x00,0x00,0x00,0x74,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x74,0x00,0x00,0x00, -0xae,0x00,0x05,0x00,0x3c,0x00,0x00,0x00,0x76,0x00,0x00,0x00, -0x6d,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, -0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x78,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, -0x21,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x78,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x73,0x00,0x00,0x00,0x7c,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x45,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x7c,0x00,0x00,0x00, -0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x7e,0x00,0x00,0x00, -0x6d,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x89,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, -0x7d,0x00,0x00,0x00,0xac,0x00,0x05,0x00,0x3c,0x00,0x00,0x00, -0x85,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x6f,0x00,0x00,0x00, -0xf7,0x00,0x03,0x00,0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0xfa,0x00,0x04,0x00,0x85,0x00,0x00,0x00,0x86,0x00,0x00,0x00, -0x87,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x86,0x00,0x00,0x00, -0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x8c,0x00,0x00,0x00, -0x71,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x84,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x7e,0x00,0x00,0x00, -0x7d,0x00,0x00,0x00,0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x91,0x00,0x00,0x00,0x8c,0x00,0x00,0x00,0x90,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x93,0x00,0x00,0x00, -0x91,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0xa1,0x00,0x00,0x00,0xa2,0x00,0x00,0x00,0x9e,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x93,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x94,0x00,0x00,0x00,0xa3,0x00,0x00,0x00,0xa2,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0xa1,0x00,0x00,0x00,0xa4,0x00,0x00,0x00, -0x98,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x93,0x00,0x00,0x00, -0x3e,0x00,0x03,0x00,0xa4,0x00,0x00,0x00,0xa3,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xa6,0x00,0x00,0x00, -0x93,0x00,0x00,0x00,0x69,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0xa1,0x00,0x00,0x00,0xa9,0x00,0x00,0x00,0x9e,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0xa6,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x94,0x00,0x00,0x00,0xaa,0x00,0x00,0x00,0xa9,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0xa1,0x00,0x00,0x00,0xab,0x00,0x00,0x00, -0x98,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0xa6,0x00,0x00,0x00, -0x3e,0x00,0x03,0x00,0xab,0x00,0x00,0x00,0xaa,0x00,0x00,0x00, -0xf9,0x00,0x02,0x00,0x21,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, -0x87,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0xb1,0x00,0x00,0x00,0x71,0x00,0x00,0x00,0x75,0x00,0x00,0x00, -0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xb5,0x00,0x00,0x00, -0x7e,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x80,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0xb6,0x00,0x00,0x00,0xb1,0x00,0x00,0x00, -0xb5,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0xb8,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xb9,0x00,0x00,0x00, -0xb6,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x73,0x00,0x00,0x00,0xbd,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0xbc,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0xbe,0x00,0x00,0x00,0xbd,0x00,0x00,0x00,0x86,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x71,0x00,0x00,0x00, -0xbe,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xc7,0x00,0x00,0x00, -0xc8,0x00,0x00,0x00,0xc5,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0xbf,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0xc9,0x00,0x00,0x00,0xc8,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x73,0x00,0x00,0x00,0xcc,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0xcb,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0xcd,0x00,0x00,0x00,0xcc,0x00,0x00,0x00,0xab,0x00,0x05,0x00, -0x3c,0x00,0x00,0x00,0xce,0x00,0x00,0x00,0xcd,0x00,0x00,0x00, -0x6f,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0xd1,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0xce,0x00,0x00,0x00, -0xd0,0x00,0x00,0x00,0xdb,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0xd0,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xd8,0x00,0x00,0x00, -0xd9,0x00,0x00,0x00,0xd5,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0xb8,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0xda,0x00,0x00,0x00,0xd9,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, -0xd1,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xdb,0x00,0x00,0x00, -0xf9,0x00,0x02,0x00,0xd1,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0xd1,0x00,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x63,0x01,0x00,0x00,0xda,0x00,0x00,0x00,0xd0,0x00,0x00,0x00, -0x1f,0x00,0x00,0x00,0xdb,0x00,0x00,0x00,0x6f,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xdf,0x00,0x00,0x00,0xc9,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00,0xe0,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xe1,0x00,0x00,0x00,0xe0,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xe2,0x00,0x00,0x00, -0xdf,0x00,0x00,0x00,0xe1,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x2f,0x00,0x00,0x00,0xe4,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0xe3,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0xe5,0x00,0x00,0x00,0xe4,0x00,0x00,0x00,0x70,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xe9,0x00,0x00,0x00, -0xe7,0x00,0x00,0x00,0x66,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, -0x06,0x00,0x00,0x00,0xea,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x1a,0x00,0x00,0x00,0xe5,0x00,0x00,0x00,0xe9,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xeb,0x00,0x00,0x00, -0xe2,0x00,0x00,0x00,0xea,0x00,0x00,0x00,0x88,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0xed,0x00,0x00,0x00,0xeb,0x00,0x00,0x00, -0x63,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00, -0x2c,0x01,0x00,0x00,0x2c,0x00,0x00,0x00,0x2e,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x2d,0x01,0x00,0x00, -0x2c,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x30,0x01,0x00,0x00,0xe1,0x00,0x00,0x00,0xed,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00,0x32,0x01,0x00,0x00, -0x2c,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x33,0x01,0x00,0x00,0x32,0x01,0x00,0x00, -0xb7,0x00,0x05,0x00,0x3c,0x00,0x00,0x00,0x34,0x01,0x00,0x00, -0x33,0x01,0x00,0x00,0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0x4d,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, -0x34,0x01,0x00,0x00,0x35,0x01,0x00,0x00,0x4d,0x01,0x00,0x00, -0xf8,0x00,0x02,0x00,0x35,0x01,0x00,0x00,0x41,0x00,0x06,0x00, -0x2f,0x00,0x00,0x00,0x36,0x01,0x00,0x00,0x2c,0x00,0x00,0x00, -0x41,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x37,0x01,0x00,0x00,0x36,0x01,0x00,0x00, -0x41,0x00,0x06,0x00,0x2f,0x00,0x00,0x00,0x38,0x01,0x00,0x00, -0x2c,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x45,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x39,0x01,0x00,0x00, -0x38,0x01,0x00,0x00,0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x5a,0x01,0x00,0x00,0xb8,0x00,0x00,0x00,0x83,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x5b,0x01,0x00,0x00,0x5a,0x01,0x00,0x00, -0x37,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x5c,0x01,0x00,0x00,0x39,0x01,0x00,0x00,0x37,0x01,0x00,0x00, -0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x5d,0x01,0x00,0x00, +0x09,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x16,0x00,0x03,0x00, +0x86,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0x87,0x00,0x00,0x00,0x86,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0x88,0x00,0x00,0x00,0x87,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x89,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x88,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0x89,0x00,0x00,0x00,0x8a,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0x8d,0x00,0x00,0x00, +0x86,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0x8e,0x00,0x00,0x00, +0x8d,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x8f,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x8e,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, +0x8f,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x93,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x86,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0xa9,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0xae,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0xaf,0x00,0x00,0x00,0xae,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0xb0,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0xaf,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0xb0,0x00,0x00,0x00,0xb1,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xb3,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0xb7,0x00,0x00,0x00,0x08,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0xc1,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0xc8,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0xc9,0x00,0x00,0x00, +0xc8,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xca,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0xc9,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, +0xca,0x00,0x00,0x00,0xcb,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0xce,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x06,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x2c,0x00,0x06,0x00, +0x65,0x00,0x00,0x00,0x07,0x01,0x00,0x00,0x68,0x00,0x00,0x00, +0x06,0x01,0x00,0x00,0x68,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x4d,0x01,0x00,0x00,0x00,0x00,0x00,0x3f, +0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x08,0x01,0x00,0x00, +0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00,0x6e,0x00,0x00,0x00, +0x09,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x09,0x01,0x00,0x00, +0x41,0x00,0x05,0x00,0x69,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0x6b,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x6b,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x69,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x67,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x70,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x77,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x75,0x00,0x00,0x00, +0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x76,0x00,0x00,0x00,0xf9,0x00,0x02,0x00,0x08,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x44,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x7e,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x7c,0x00,0x00,0x00, +0x7d,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7d,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x93,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x90,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x86,0x00,0x00,0x00,0x95,0x00,0x00,0x00,0x94,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00,0x96,0x00,0x00,0x00, +0x8a,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x96,0x00,0x00,0x00,0x95,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x98,0x00,0x00,0x00, +0x85,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x93,0x00,0x00,0x00,0x9b,0x00,0x00,0x00,0x90,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x98,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x86,0x00,0x00,0x00,0x9c,0x00,0x00,0x00,0x9b,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00,0x9d,0x00,0x00,0x00, +0x8a,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x98,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x9d,0x00,0x00,0x00,0x9c,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0x08,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7e,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xa3,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xa5,0x00,0x00,0x00, +0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x80,0x00,0x05,0x00, +0x07,0x00,0x00,0x00,0xa6,0x00,0x00,0x00,0xa3,0x00,0x00,0x00, +0xa5,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x72,0x00,0x00,0x00, +0xaa,0x00,0x00,0x00,0x2b,0x00,0x00,0x00,0xa9,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0xab,0x00,0x00,0x00, +0xaa,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xac,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0xab,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0xb3,0x00,0x00,0x00,0xb4,0x00,0x00,0x00, +0xb1,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xac,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0xb5,0x00,0x00,0x00, +0xb4,0x00,0x00,0x00,0x6f,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xb6,0x00,0x00,0x00,0xb5,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x2e,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0xb7,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xb9,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0x70,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xbb,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xbd,0x00,0x00,0x00, +0xbb,0x00,0x00,0x00,0x4d,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, +0x06,0x00,0x00,0x00,0xbe,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x1a,0x00,0x00,0x00,0xb9,0x00,0x00,0x00,0xbd,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xbf,0x00,0x00,0x00, +0xb6,0x00,0x00,0x00,0xbe,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0xc2,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0xc1,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0xc3,0x00,0x00,0x00,0xc2,0x00,0x00,0x00,0xab,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0xc3,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0xc7,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0xc4,0x00,0x00,0x00, +0xc6,0x00,0x00,0x00,0xd1,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0xc6,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xce,0x00,0x00,0x00, +0xcf,0x00,0x00,0x00,0xcb,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xa5,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xd0,0x00,0x00,0x00,0xcf,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, +0xc7,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xd1,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0xc7,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0xc7,0x00,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x4a,0x01,0x00,0x00,0xd0,0x00,0x00,0x00,0xc6,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0xd1,0x00,0x00,0x00,0x88,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xd5,0x00,0x00,0x00,0xbf,0x00,0x00,0x00, +0x4a,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x13,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x14,0x01,0x00,0x00, +0x13,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x15,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x16,0x01,0x00,0x00, +0x15,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x17,0x01,0x00,0x00,0x16,0x01,0x00,0x00,0xd5,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00,0x19,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x1a,0x01,0x00,0x00,0x19,0x01,0x00,0x00, +0xb7,0x00,0x05,0x00,0x3b,0x00,0x00,0x00,0x1b,0x01,0x00,0x00, +0x1a,0x01,0x00,0x00,0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, +0x34,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, +0x1b,0x01,0x00,0x00,0x1c,0x01,0x00,0x00,0x34,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x1c,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x2e,0x00,0x00,0x00,0x1d,0x01,0x00,0x00,0x2b,0x00,0x00,0x00, +0x40,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x1e,0x01,0x00,0x00,0x1d,0x01,0x00,0x00, +0x41,0x00,0x06,0x00,0x2e,0x00,0x00,0x00,0x1f,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x44,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x20,0x01,0x00,0x00, +0x1f,0x01,0x00,0x00,0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x41,0x01,0x00,0x00,0xa5,0x00,0x00,0x00,0x83,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x42,0x01,0x00,0x00,0x41,0x01,0x00,0x00, +0x1e,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x43,0x01,0x00,0x00,0x20,0x01,0x00,0x00,0x1e,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x44,0x01,0x00,0x00, 0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x1b,0x00,0x00,0x00, -0x5c,0x01,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x5e,0x01,0x00,0x00,0x5b,0x01,0x00,0x00,0x5d,0x01,0x00,0x00, -0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x60,0x01,0x00,0x00, +0x43,0x01,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x45,0x01,0x00,0x00,0x42,0x01,0x00,0x00,0x44,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x47,0x01,0x00,0x00, 0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x20,0x00,0x00,0x00, -0x5e,0x01,0x00,0x00,0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x61,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00, -0x1f,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x83,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x62,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, -0x61,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x3d,0x01,0x00,0x00,0x62,0x01,0x00,0x00,0x33,0x01,0x00,0x00, -0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x67,0x01,0x00,0x00, -0x61,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, -0x06,0x00,0x00,0x00,0x40,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x32,0x00,0x00,0x00,0x67,0x01,0x00,0x00,0x33,0x01,0x00,0x00, +0x45,0x01,0x00,0x00,0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x48,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0x47,0x01,0x00,0x00,0x83,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x49,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x48,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x24,0x01,0x00,0x00,0x49,0x01,0x00,0x00,0x1a,0x01,0x00,0x00, +0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x4e,0x01,0x00,0x00, +0x48,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, +0x06,0x00,0x00,0x00,0x27,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x32,0x00,0x00,0x00,0x4e,0x01,0x00,0x00,0x1a,0x01,0x00,0x00, 0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x43,0x01,0x00,0x00,0xed,0x00,0x00,0x00,0x3d,0x01,0x00,0x00, -0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0x44,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x30,0x01,0x00,0x00, -0x40,0x01,0x00,0x00,0x43,0x01,0x00,0x00,0x88,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x47,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, -0xe1,0x00,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, -0x48,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, -0x47,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0x4a,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0x53,0x00,0x00,0x00,0x48,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x4c,0x01,0x00,0x00, -0x2d,0x01,0x00,0x00,0x4a,0x01,0x00,0x00,0xf9,0x00,0x02,0x00, -0x4d,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x4d,0x01,0x00,0x00, -0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x65,0x01,0x00,0x00, -0x2d,0x01,0x00,0x00,0xd1,0x00,0x00,0x00,0x4c,0x01,0x00,0x00, -0x35,0x01,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x64,0x01,0x00,0x00,0x30,0x01,0x00,0x00,0xd1,0x00,0x00,0x00, -0x44,0x01,0x00,0x00,0x35,0x01,0x00,0x00,0x0c,0x00,0x06,0x00, -0x06,0x00,0x00,0x00,0x4f,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x0e,0x00,0x00,0x00,0x64,0x01,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x51,0x01,0x00,0x00,0x4f,0x01,0x00,0x00, -0x65,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, -0x53,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00, -0x64,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x55,0x01,0x00,0x00,0x53,0x01,0x00,0x00,0x65,0x01,0x00,0x00, -0x41,0x00,0x06,0x00,0xa1,0x00,0x00,0x00,0xfa,0x00,0x00,0x00, -0x9e,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0xb9,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x94,0x00,0x00,0x00,0xfb,0x00,0x00,0x00, -0xfa,0x00,0x00,0x00,0x73,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0xfc,0x00,0x00,0x00,0xfb,0x00,0x00,0x00,0x86,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x7d,0x00,0x00,0x00, +0x2a,0x01,0x00,0x00,0xd5,0x00,0x00,0x00,0x24,0x01,0x00,0x00, +0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0x2b,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x17,0x01,0x00,0x00, +0x27,0x01,0x00,0x00,0x2a,0x01,0x00,0x00,0x88,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x2e,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x16,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, +0x2f,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, +0x2e,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0x31,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x52,0x00,0x00,0x00,0x2f,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x33,0x01,0x00,0x00, +0x14,0x01,0x00,0x00,0x31,0x01,0x00,0x00,0xf9,0x00,0x02,0x00, +0x34,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x34,0x01,0x00,0x00, +0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x4c,0x01,0x00,0x00, +0x14,0x01,0x00,0x00,0xc7,0x00,0x00,0x00,0x33,0x01,0x00,0x00, +0x1c,0x01,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x4b,0x01,0x00,0x00,0x17,0x01,0x00,0x00,0xc7,0x00,0x00,0x00, +0x2b,0x01,0x00,0x00,0x1c,0x01,0x00,0x00,0x0c,0x00,0x06,0x00, +0x06,0x00,0x00,0x00,0x36,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x0e,0x00,0x00,0x00,0x4b,0x01,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x38,0x01,0x00,0x00,0x36,0x01,0x00,0x00, +0x4c,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, +0x3a,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00, +0x4b,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x3c,0x01,0x00,0x00,0x3a,0x01,0x00,0x00,0x4c,0x01,0x00,0x00, +0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00,0xe1,0x00,0x00,0x00, +0x90,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xa6,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x86,0x00,0x00,0x00,0xe2,0x00,0x00,0x00, +0xe1,0x00,0x00,0x00,0x73,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xe3,0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x86,0x00,0x05,0x00, +0x07,0x00,0x00,0x00,0xe8,0x00,0x00,0x00,0x7b,0x00,0x00,0x00, 0x17,0x00,0x00,0x00,0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x02,0x01,0x00,0x00,0xb9,0x00,0x00,0x00,0x01,0x01,0x00,0x00, -0x41,0x00,0x06,0x00,0xa1,0x00,0x00,0x00,0x03,0x01,0x00,0x00, -0x9e,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x02,0x01,0x00,0x00, -0x3d,0x00,0x04,0x00,0x94,0x00,0x00,0x00,0x04,0x01,0x00,0x00, -0x03,0x01,0x00,0x00,0x73,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x05,0x01,0x00,0x00,0x04,0x01,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x0d,0x01,0x00,0x00,0x05,0x01,0x00,0x00, -0x55,0x01,0x00,0x00,0x7f,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x68,0x01,0x00,0x00,0x0d,0x01,0x00,0x00,0x0c,0x00,0x08,0x00, -0x06,0x00,0x00,0x00,0x0e,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x32,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x51,0x01,0x00,0x00, -0x68,0x01,0x00,0x00,0x73,0x00,0x04,0x00,0x94,0x00,0x00,0x00, -0x0f,0x01,0x00,0x00,0x0e,0x01,0x00,0x00,0x41,0x00,0x06,0x00, -0xa1,0x00,0x00,0x00,0x10,0x01,0x00,0x00,0x98,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0xb9,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, -0x10,0x01,0x00,0x00,0x0f,0x01,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x1b,0x01,0x00,0x00,0x05,0x01,0x00,0x00, -0x51,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0x1c,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0xfc,0x00,0x00,0x00,0x55,0x01,0x00,0x00,0x1b,0x01,0x00,0x00, -0x73,0x00,0x04,0x00,0x94,0x00,0x00,0x00,0x1d,0x01,0x00,0x00, -0x1c,0x01,0x00,0x00,0x41,0x00,0x06,0x00,0xa1,0x00,0x00,0x00, -0x1e,0x01,0x00,0x00,0x98,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0x02,0x01,0x00,0x00,0x3e,0x00,0x03,0x00,0x1e,0x01,0x00,0x00, -0x1d,0x01,0x00,0x00,0xf9,0x00,0x02,0x00,0x21,0x01,0x00,0x00, -0xf8,0x00,0x02,0x00,0x21,0x01,0x00,0x00,0xfd,0x00,0x01,0x00, +0xe9,0x00,0x00,0x00,0xa6,0x00,0x00,0x00,0xe8,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00,0xea,0x00,0x00,0x00, +0x90,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xe9,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x86,0x00,0x00,0x00,0xeb,0x00,0x00,0x00, +0xea,0x00,0x00,0x00,0x73,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xec,0x00,0x00,0x00,0xeb,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0xec,0x00,0x00,0x00, +0x3c,0x01,0x00,0x00,0x7f,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x4f,0x01,0x00,0x00,0xf4,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, +0x06,0x00,0x00,0x00,0xf5,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x32,0x00,0x00,0x00,0xe3,0x00,0x00,0x00,0x38,0x01,0x00,0x00, +0x4f,0x01,0x00,0x00,0x73,0x00,0x04,0x00,0x86,0x00,0x00,0x00, +0xf6,0x00,0x00,0x00,0xf5,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x93,0x00,0x00,0x00,0xf7,0x00,0x00,0x00,0x8a,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xa6,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, +0xf7,0x00,0x00,0x00,0xf6,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0xec,0x00,0x00,0x00, +0x38,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0x03,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0xe3,0x00,0x00,0x00,0x3c,0x01,0x00,0x00,0x02,0x01,0x00,0x00, +0x73,0x00,0x04,0x00,0x86,0x00,0x00,0x00,0x04,0x01,0x00,0x00, +0x03,0x01,0x00,0x00,0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00, +0x05,0x01,0x00,0x00,0x8a,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xe9,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0x05,0x01,0x00,0x00, +0x04,0x01,0x00,0x00,0xf9,0x00,0x02,0x00,0x08,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x08,0x01,0x00,0x00,0xfd,0x00,0x01,0x00, 0x38,0x00,0x01,0x00, }; -const uint64_t rope_neox_f16_len = 4132; +const uint64_t rope_neox_f16_len = 3952; unsigned char rope_neox_f32_data[] = { 0x03,0x02,0x23,0x07,0x00,0x05,0x01,0x00,0x0b,0x00,0x0d,0x00, -0x63,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, +0x4a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, 0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,0x01,0x00,0x00,0x00, 0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30, 0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00, 0x01,0x00,0x00,0x00,0x0f,0x00,0x0b,0x00,0x05,0x00,0x00,0x00, 0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x97,0x00,0x00,0x00, -0x9d,0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0xd4,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x89,0x00,0x00,0x00, +0x8f,0x00,0x00,0x00,0xb0,0x00,0x00,0x00,0xca,0x00,0x00,0x00, 0x10,0x00,0x06,0x00,0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x01,0x00,0x00,0x00, 0x23,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x08,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, +0x29,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x08,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, 0x03,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x04,0x00,0x00,0x00, 0x23,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x14,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, +0x29,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x14,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, 0x06,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x18,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x07,0x00,0x00,0x00, 0x23,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x2a,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00, -0x09,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x30,0x00,0x00,0x00, -0x48,0x00,0x05,0x00,0x2a,0x00,0x00,0x00,0x0a,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x34,0x00,0x00,0x00,0x47,0x00,0x03,0x00, -0x2a,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x68,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x94,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x95,0x00,0x00,0x00, +0x29,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x24,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x28,0x00,0x00,0x00, +0x47,0x00,0x03,0x00,0x29,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x67,0x00,0x00,0x00,0x0b,0x00,0x00,0x00, +0x1c,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x86,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0x87,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x89,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x89,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x03,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x8c,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0x8d,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x8f,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x8f,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xad,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0xae,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0xae,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0xae,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0xb0,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xb0,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xc7,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0xc8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0xc8,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0xc8,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0xca,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xca,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x01,0x01,0x00,0x00, +0x0b,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x13,0x00,0x02,0x00, +0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00, +0x20,0x00,0x00,0x00,0x15,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x1b,0x00,0x00,0x00, +0x6f,0x12,0x83,0x3a,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,0x2b,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x1c,0x00,0x04,0x00,0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x17,0x00,0x00,0x00,0x1e,0x00,0x0c,0x00,0x29,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2a,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, +0x2a,0x00,0x00,0x00,0x2b,0x00,0x00,0x00,0x09,0x00,0x00,0x00, +0x15,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x20,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x2d,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x2e,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x38,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x14,0x00,0x02,0x00, +0x3b,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x40,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x44,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x52,0x00,0x00,0x00,0xcd,0xcc,0xcc,0x3d,0x17,0x00,0x04,0x00, +0x65,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x66,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x65,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x66,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x69,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x72,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x1d,0x00,0x03,0x00,0x86,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x1e,0x00,0x03,0x00,0x87,0x00,0x00,0x00,0x86,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x88,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x87,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x88,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0x8c,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0x8d,0x00,0x00,0x00,0x8c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x8e,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x8d,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0x8e,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x92,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0xa8,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x1d,0x00,0x03,0x00,0xad,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, +0x1e,0x00,0x03,0x00,0xae,0x00,0x00,0x00,0xad,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0xaf,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0xae,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0xaf,0x00,0x00,0x00, +0xb0,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0xb2,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0xb6,0x00,0x00,0x00, +0x08,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0xc0,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0xc7,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0xc8,0x00,0x00,0x00,0xc7,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0xc9,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0xc8,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0xc9,0x00,0x00,0x00,0xca,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x2c,0x00,0x06,0x00, +0x65,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x68,0x00,0x00,0x00, +0x00,0x01,0x00,0x00,0x68,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x47,0x01,0x00,0x00,0x00,0x00,0x00,0x3f, +0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x02,0x01,0x00,0x00, +0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00,0x6e,0x00,0x00,0x00, +0x03,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x03,0x01,0x00,0x00, +0x41,0x00,0x05,0x00,0x69,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0x6b,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x6b,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x69,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x67,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x70,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x77,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x75,0x00,0x00,0x00, +0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x76,0x00,0x00,0x00,0xf9,0x00,0x02,0x00,0x02,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x44,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x7e,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x7c,0x00,0x00,0x00, +0x7d,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7d,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0x93,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x93,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00,0x95,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x95,0x00,0x00,0x00,0x94,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x97,0x00,0x00,0x00, +0x85,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0x9a,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x97,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x9b,0x00,0x00,0x00,0x9a,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00,0x9c,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x97,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x9c,0x00,0x00,0x00,0x9b,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0x02,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7e,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xa2,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xa4,0x00,0x00,0x00, +0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x80,0x00,0x05,0x00, +0x07,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0xa2,0x00,0x00,0x00, +0xa4,0x00,0x00,0x00,0x41,0x00,0x05,0x00,0x72,0x00,0x00,0x00, +0xa9,0x00,0x00,0x00,0x2b,0x00,0x00,0x00,0xa8,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0xaa,0x00,0x00,0x00, +0xa9,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xab,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0xaa,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0xb2,0x00,0x00,0x00,0xb3,0x00,0x00,0x00, +0xb0,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xab,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0xb4,0x00,0x00,0x00, +0xb3,0x00,0x00,0x00,0x6f,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xb5,0x00,0x00,0x00,0xb4,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x2e,0x00,0x00,0x00,0xb7,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0xb6,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xb8,0x00,0x00,0x00,0xb7,0x00,0x00,0x00,0x70,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xba,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xbc,0x00,0x00,0x00, +0xba,0x00,0x00,0x00,0x47,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, +0x06,0x00,0x00,0x00,0xbd,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x1a,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0xbc,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xbe,0x00,0x00,0x00, +0xb5,0x00,0x00,0x00,0xbd,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0xc1,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0xc0,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0xc2,0x00,0x00,0x00,0xc1,0x00,0x00,0x00,0xab,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0xc3,0x00,0x00,0x00,0xc2,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0xc6,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0xc3,0x00,0x00,0x00, +0xc5,0x00,0x00,0x00,0xcf,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0xc5,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00, +0xcd,0x00,0x00,0x00,0xca,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xa4,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xce,0x00,0x00,0x00,0xcd,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, +0xc6,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xcf,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0xc6,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0xc6,0x00,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x44,0x01,0x00,0x00,0xce,0x00,0x00,0x00,0xc5,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0xcf,0x00,0x00,0x00,0x88,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xd3,0x00,0x00,0x00,0xbe,0x00,0x00,0x00, +0x44,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x0d,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x0e,0x01,0x00,0x00, +0x0d,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x0f,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x10,0x01,0x00,0x00, +0x0f,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x11,0x01,0x00,0x00,0x10,0x01,0x00,0x00,0xd3,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00,0x13,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x14,0x01,0x00,0x00,0x13,0x01,0x00,0x00, +0xb7,0x00,0x05,0x00,0x3b,0x00,0x00,0x00,0x15,0x01,0x00,0x00, +0x14,0x01,0x00,0x00,0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, +0x2e,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, +0x15,0x01,0x00,0x00,0x16,0x01,0x00,0x00,0x2e,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x16,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x2e,0x00,0x00,0x00,0x17,0x01,0x00,0x00,0x2b,0x00,0x00,0x00, +0x40,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x18,0x01,0x00,0x00,0x17,0x01,0x00,0x00, +0x41,0x00,0x06,0x00,0x2e,0x00,0x00,0x00,0x19,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x44,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x1a,0x01,0x00,0x00, +0x19,0x01,0x00,0x00,0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x3b,0x01,0x00,0x00,0xa4,0x00,0x00,0x00,0x83,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x3c,0x01,0x00,0x00,0x3b,0x01,0x00,0x00, +0x18,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x3d,0x01,0x00,0x00,0x1a,0x01,0x00,0x00,0x18,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x3e,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x1b,0x00,0x00,0x00, +0x3d,0x01,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x3f,0x01,0x00,0x00,0x3c,0x01,0x00,0x00,0x3e,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x41,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x20,0x00,0x00,0x00, +0x3f,0x01,0x00,0x00,0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x42,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0x41,0x01,0x00,0x00,0x83,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x43,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x42,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x1e,0x01,0x00,0x00,0x43,0x01,0x00,0x00,0x14,0x01,0x00,0x00, +0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x48,0x01,0x00,0x00, +0x42,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, +0x06,0x00,0x00,0x00,0x21,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x32,0x00,0x00,0x00,0x48,0x01,0x00,0x00,0x14,0x01,0x00,0x00, +0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x24,0x01,0x00,0x00,0xd3,0x00,0x00,0x00,0x1e,0x01,0x00,0x00, +0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0x25,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x11,0x01,0x00,0x00, +0x21,0x01,0x00,0x00,0x24,0x01,0x00,0x00,0x88,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x28,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x10,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, +0x29,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, +0x28,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0x2b,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x52,0x00,0x00,0x00,0x29,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x2d,0x01,0x00,0x00, +0x0e,0x01,0x00,0x00,0x2b,0x01,0x00,0x00,0xf9,0x00,0x02,0x00, +0x2e,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x2e,0x01,0x00,0x00, +0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x46,0x01,0x00,0x00, +0x0e,0x01,0x00,0x00,0xc6,0x00,0x00,0x00,0x2d,0x01,0x00,0x00, +0x16,0x01,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x45,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0xc6,0x00,0x00,0x00, +0x25,0x01,0x00,0x00,0x16,0x01,0x00,0x00,0x0c,0x00,0x06,0x00, +0x06,0x00,0x00,0x00,0x30,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x0e,0x00,0x00,0x00,0x45,0x01,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x32,0x01,0x00,0x00,0x30,0x01,0x00,0x00, +0x46,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, +0x34,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00, +0x45,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x36,0x01,0x00,0x00,0x34,0x01,0x00,0x00,0x46,0x01,0x00,0x00, +0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00,0xdf,0x00,0x00,0x00, +0x8f,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xa5,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xe0,0x00,0x00,0x00, +0xdf,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xe5,0x00,0x00,0x00,0x7b,0x00,0x00,0x00,0x17,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xe6,0x00,0x00,0x00, +0xa5,0x00,0x00,0x00,0xe5,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xe6,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xe8,0x00,0x00,0x00,0xe7,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xf0,0x00,0x00,0x00, +0xe8,0x00,0x00,0x00,0x36,0x01,0x00,0x00,0x7f,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x49,0x01,0x00,0x00,0xf0,0x00,0x00,0x00, +0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0xf1,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0xe0,0x00,0x00,0x00, +0x32,0x01,0x00,0x00,0x49,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0xf2,0x00,0x00,0x00,0x89,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, +0xf2,0x00,0x00,0x00,0xf1,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xfd,0x00,0x00,0x00,0xe8,0x00,0x00,0x00, +0x32,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0xfe,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0xe0,0x00,0x00,0x00,0x36,0x01,0x00,0x00,0xfd,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00,0xff,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xe6,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0xff,0x00,0x00,0x00,0xfe,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0x02,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, +0x02,0x01,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00, + +}; +const uint64_t rope_neox_f32_len = 3852; + +unsigned char rope_norm_f16_data[] = { +0x03,0x02,0x23,0x07,0x00,0x05,0x01,0x00,0x0b,0x00,0x0d,0x00, +0x49,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, +0x01,0x00,0x00,0x00,0x11,0x00,0x02,0x00,0x51,0x11,0x00,0x00, +0x0b,0x00,0x06,0x00,0x01,0x00,0x00,0x00,0x47,0x4c,0x53,0x4c, +0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30,0x00,0x00,0x00,0x00, +0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x0f,0x00,0x0b,0x00,0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x8a,0x00,0x00,0x00,0x90,0x00,0x00,0x00, +0xb0,0x00,0x00,0x00,0xca,0x00,0x00,0x00,0x10,0x00,0x06,0x00, +0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x29,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x08,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x29,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x10,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x05,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x14,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x29,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x1c,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x08,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x24,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x09,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0x29,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x67,0x00,0x00,0x00,0x0b,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x87,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x88,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x95,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x95,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x97,0x00,0x00,0x00, +0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x88,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x8a,0x00,0x00,0x00, 0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x97,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x9a,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x9b,0x00,0x00,0x00, +0x8a,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x8d,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0x8e,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0x9b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x9b,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x9d,0x00,0x00,0x00, +0x8e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0x8e,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x90,0x00,0x00,0x00, 0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0x9d,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xc1,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xc2,0x00,0x00,0x00, +0x90,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xad,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xae,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0xc2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xc2,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xc4,0x00,0x00,0x00, +0xae,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xae,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xb0,0x00,0x00,0x00, 0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xc4,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0xd1,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xd2,0x00,0x00,0x00, +0xb0,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xc7,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00,0xc8,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x48,0x00,0x05,0x00, -0xd2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xd2,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xd4,0x00,0x00,0x00, +0xc8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00,0xc8,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xca,0x00,0x00,0x00, 0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00, -0xd4,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x47,0x00,0x04,0x00,0x1a,0x01,0x00,0x00,0x0b,0x00,0x00,0x00, +0xca,0x00,0x00,0x00,0x21,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x00,0x01,0x00,0x00,0x0b,0x00,0x00,0x00, 0x19,0x00,0x00,0x00,0x13,0x00,0x02,0x00,0x02,0x00,0x00,0x00, 0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x02,0x00,0x00,0x00, 0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00, @@ -138660,270 +138441,590 @@ unsigned char rope_neox_f32_data[] = { 0x06,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x6f,0x12,0x83,0x3a, 0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, 0x00,0x00,0x80,0x3f,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x04,0x00, +0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x17,0x00,0x00,0x00, +0x1e,0x00,0x0c,0x00,0x29,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x2a,0x00,0x00,0x00,0x09,0x00,0x00,0x00, +0x29,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x2a,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x15,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2e,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x38,0x00,0x00,0x00, +0x05,0x00,0x00,0x00,0x14,0x00,0x02,0x00,0x3b,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x40,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x44,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x52,0x00,0x00,0x00, +0xcd,0xcc,0xcc,0x3d,0x17,0x00,0x04,0x00,0x65,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x66,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x65,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0x66,0x00,0x00,0x00,0x67,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x68,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x69,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x6e,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x72,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x16,0x00,0x03,0x00, +0x86,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0x87,0x00,0x00,0x00,0x86,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0x88,0x00,0x00,0x00,0x87,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x89,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x88,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0x89,0x00,0x00,0x00,0x8a,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0x8d,0x00,0x00,0x00, +0x86,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0x8e,0x00,0x00,0x00, +0x8d,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x8f,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x8e,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, +0x8f,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x93,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x86,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0xa8,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0xad,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0xae,0x00,0x00,0x00,0xad,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0xaf,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0xae,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0xaf,0x00,0x00,0x00,0xb0,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xb2,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0xb6,0x00,0x00,0x00,0x08,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0xc0,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0xc7,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0xc8,0x00,0x00,0x00, +0xc7,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xc9,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0xc8,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, +0xc9,0x00,0x00,0x00,0xca,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0xcd,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0xff,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x2c,0x00,0x06,0x00, +0x65,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x68,0x00,0x00,0x00, +0xff,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x46,0x01,0x00,0x00,0x00,0x00,0x00,0x3f, +0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x01,0x01,0x00,0x00, +0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00,0x6e,0x00,0x00,0x00, +0x02,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x02,0x01,0x00,0x00, +0x41,0x00,0x05,0x00,0x69,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0x6b,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x6b,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x69,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x67,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x70,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x77,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x75,0x00,0x00,0x00, +0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x76,0x00,0x00,0x00,0xf9,0x00,0x02,0x00,0x01,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x44,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x7e,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x7c,0x00,0x00,0x00, +0x7d,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7d,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x93,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x90,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x86,0x00,0x00,0x00,0x95,0x00,0x00,0x00,0x94,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00,0x96,0x00,0x00,0x00, +0x8a,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x96,0x00,0x00,0x00,0x95,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x98,0x00,0x00,0x00, +0x85,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x93,0x00,0x00,0x00,0x9b,0x00,0x00,0x00,0x90,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x98,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x86,0x00,0x00,0x00,0x9c,0x00,0x00,0x00,0x9b,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00,0x9d,0x00,0x00,0x00, +0x8a,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x98,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x9d,0x00,0x00,0x00,0x9c,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0x01,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7e,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xa3,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xa5,0x00,0x00,0x00, +0xa3,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0xa9,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0xa8,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0xaa,0x00,0x00,0x00,0xa9,0x00,0x00,0x00,0x86,0x00,0x05,0x00, +0x07,0x00,0x00,0x00,0xab,0x00,0x00,0x00,0x70,0x00,0x00,0x00, +0xaa,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xb2,0x00,0x00,0x00, +0xb3,0x00,0x00,0x00,0xb0,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xab,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0xb4,0x00,0x00,0x00,0xb3,0x00,0x00,0x00,0x6f,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xb5,0x00,0x00,0x00,0xb4,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00,0xb7,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0xb6,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0xb7,0x00,0x00,0x00, +0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xba,0x00,0x00,0x00, +0x6c,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0xbc,0x00,0x00,0x00,0xba,0x00,0x00,0x00,0x46,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0xbd,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0xb8,0x00,0x00,0x00, +0xbc,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0xbe,0x00,0x00,0x00,0xb5,0x00,0x00,0x00,0xbd,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x72,0x00,0x00,0x00,0xc1,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0xc0,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0xc2,0x00,0x00,0x00,0xc1,0x00,0x00,0x00, +0xab,0x00,0x05,0x00,0x3b,0x00,0x00,0x00,0xc3,0x00,0x00,0x00, +0xc2,0x00,0x00,0x00,0x6e,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, +0xc6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, +0xc3,0x00,0x00,0x00,0xc5,0x00,0x00,0x00,0xd0,0x00,0x00,0x00, +0xf8,0x00,0x02,0x00,0xc5,0x00,0x00,0x00,0x86,0x00,0x05,0x00, +0x07,0x00,0x00,0x00,0xcc,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x17,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xcd,0x00,0x00,0x00, +0xce,0x00,0x00,0x00,0xca,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xcc,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xcf,0x00,0x00,0x00,0xce,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, +0xc6,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xd0,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0xc6,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0xc6,0x00,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x43,0x01,0x00,0x00,0xcf,0x00,0x00,0x00,0xc5,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0xd0,0x00,0x00,0x00,0x88,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xd4,0x00,0x00,0x00,0xbe,0x00,0x00,0x00, +0x43,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x0c,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x0d,0x01,0x00,0x00, +0x0c,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x0e,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x0f,0x01,0x00,0x00, +0x0e,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x10,0x01,0x00,0x00,0x0f,0x01,0x00,0x00,0xd4,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00,0x12,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x13,0x01,0x00,0x00,0x12,0x01,0x00,0x00, +0xb7,0x00,0x05,0x00,0x3b,0x00,0x00,0x00,0x14,0x01,0x00,0x00, +0x13,0x01,0x00,0x00,0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, +0x2d,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, +0x14,0x01,0x00,0x00,0x15,0x01,0x00,0x00,0x2d,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x15,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x2e,0x00,0x00,0x00,0x16,0x01,0x00,0x00,0x2b,0x00,0x00,0x00, +0x40,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x17,0x01,0x00,0x00,0x16,0x01,0x00,0x00, +0x41,0x00,0x06,0x00,0x2e,0x00,0x00,0x00,0x18,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x44,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x19,0x01,0x00,0x00, +0x18,0x01,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0x39,0x01,0x00,0x00,0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00, +0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x3a,0x01,0x00,0x00, +0x39,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x3b,0x01,0x00,0x00,0x3a,0x01,0x00,0x00,0x17,0x01,0x00,0x00, +0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x3c,0x01,0x00,0x00, +0x19,0x01,0x00,0x00,0x17,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, +0x06,0x00,0x00,0x00,0x3d,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x28,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x3c,0x01,0x00,0x00, +0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x3e,0x01,0x00,0x00, +0x3b,0x01,0x00,0x00,0x3d,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, +0x06,0x00,0x00,0x00,0x40,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x28,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x3e,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x41,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, +0x40,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x42,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x41,0x01,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x1d,0x01,0x00,0x00, +0x42,0x01,0x00,0x00,0x13,0x01,0x00,0x00,0x83,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x47,0x01,0x00,0x00,0x41,0x01,0x00,0x00, +0x1f,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0x20,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x47,0x01,0x00,0x00,0x13,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x23,0x01,0x00,0x00, +0xd4,0x00,0x00,0x00,0x1d,0x01,0x00,0x00,0x0c,0x00,0x08,0x00, +0x06,0x00,0x00,0x00,0x24,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x32,0x00,0x00,0x00,0x10,0x01,0x00,0x00,0x20,0x01,0x00,0x00, +0x23,0x01,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x27,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x0f,0x01,0x00,0x00, +0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x28,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x27,0x01,0x00,0x00, +0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0x2a,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x52,0x00,0x00,0x00, +0x28,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x2c,0x01,0x00,0x00,0x0d,0x01,0x00,0x00, +0x2a,0x01,0x00,0x00,0xf9,0x00,0x02,0x00,0x2d,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x2d,0x01,0x00,0x00,0xf5,0x00,0x07,0x00, +0x06,0x00,0x00,0x00,0x45,0x01,0x00,0x00,0x0d,0x01,0x00,0x00, +0xc6,0x00,0x00,0x00,0x2c,0x01,0x00,0x00,0x15,0x01,0x00,0x00, +0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x44,0x01,0x00,0x00, +0x10,0x01,0x00,0x00,0xc6,0x00,0x00,0x00,0x24,0x01,0x00,0x00, +0x15,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, +0x2f,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x0e,0x00,0x00,0x00, +0x44,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x31,0x01,0x00,0x00,0x2f,0x01,0x00,0x00,0x45,0x01,0x00,0x00, +0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x33,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x44,0x01,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x35,0x01,0x00,0x00, +0x33,0x01,0x00,0x00,0x45,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x93,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x90,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x86,0x00,0x00,0x00,0xe1,0x00,0x00,0x00,0xe0,0x00,0x00,0x00, +0x73,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xe2,0x00,0x00,0x00, +0xe1,0x00,0x00,0x00,0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xe5,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x68,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00,0xe6,0x00,0x00,0x00, +0x90,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xe5,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x86,0x00,0x00,0x00,0xe7,0x00,0x00,0x00, +0xe6,0x00,0x00,0x00,0x73,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xe8,0x00,0x00,0x00,0xe7,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xf0,0x00,0x00,0x00,0xe8,0x00,0x00,0x00, +0x35,0x01,0x00,0x00,0x7f,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x48,0x01,0x00,0x00,0xf0,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, +0x06,0x00,0x00,0x00,0xf1,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x32,0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x31,0x01,0x00,0x00, +0x48,0x01,0x00,0x00,0x73,0x00,0x04,0x00,0x86,0x00,0x00,0x00, +0xf2,0x00,0x00,0x00,0xf1,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x93,0x00,0x00,0x00,0xf3,0x00,0x00,0x00,0x8a,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, +0xf3,0x00,0x00,0x00,0xf2,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xfb,0x00,0x00,0x00,0xe8,0x00,0x00,0x00, +0x31,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0xfc,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0xe2,0x00,0x00,0x00,0x35,0x01,0x00,0x00,0xfb,0x00,0x00,0x00, +0x73,0x00,0x04,0x00,0x86,0x00,0x00,0x00,0xfd,0x00,0x00,0x00, +0xfc,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0x93,0x00,0x00,0x00, +0xfe,0x00,0x00,0x00,0x8a,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xe5,0x00,0x00,0x00,0x3e,0x00,0x03,0x00,0xfe,0x00,0x00,0x00, +0xfd,0x00,0x00,0x00,0xf9,0x00,0x02,0x00,0x01,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x01,0x01,0x00,0x00,0xfd,0x00,0x01,0x00, +0x38,0x00,0x01,0x00, +}; +const uint64_t rope_norm_f16_len = 3952; + +unsigned char rope_norm_f32_data[] = { +0x03,0x02,0x23,0x07,0x00,0x05,0x01,0x00,0x0b,0x00,0x0d,0x00, +0x43,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x02,0x00, +0x01,0x00,0x00,0x00,0x0b,0x00,0x06,0x00,0x01,0x00,0x00,0x00, +0x47,0x4c,0x53,0x4c,0x2e,0x73,0x74,0x64,0x2e,0x34,0x35,0x30, +0x00,0x00,0x00,0x00,0x0e,0x00,0x03,0x00,0x00,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x0f,0x00,0x0b,0x00,0x05,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x6d,0x61,0x69,0x6e,0x00,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0x67,0x00,0x00,0x00,0x89,0x00,0x00,0x00, +0x8f,0x00,0x00,0x00,0xaf,0x00,0x00,0x00,0xc9,0x00,0x00,0x00, +0x10,0x00,0x06,0x00,0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x29,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x08,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x03,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x29,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x14,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x18,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x48,0x00,0x05,0x00, +0x29,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x23,0x00,0x00,0x00, +0x24,0x00,0x00,0x00,0x48,0x00,0x05,0x00,0x29,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x28,0x00,0x00,0x00, +0x47,0x00,0x03,0x00,0x29,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x67,0x00,0x00,0x00,0x0b,0x00,0x00,0x00, +0x1c,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x86,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0x87,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x89,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x89,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x03,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0x8c,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0x8d,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0x8f,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0x8f,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xac,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0xad,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0xad,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0xad,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0xaf,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xaf,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xc6,0x00,0x00,0x00, +0x06,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x48,0x00,0x04,0x00, +0xc7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00, +0x48,0x00,0x05,0x00,0xc7,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x00,0x03,0x00, +0xc7,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00, +0xc9,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x47,0x00,0x04,0x00,0xc9,0x00,0x00,0x00,0x21,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x47,0x00,0x04,0x00,0xfa,0x00,0x00,0x00, +0x0b,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x13,0x00,0x02,0x00, +0x02,0x00,0x00,0x00,0x21,0x00,0x03,0x00,0x03,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x16,0x00,0x03,0x00,0x06,0x00,0x00,0x00, +0x20,0x00,0x00,0x00,0x15,0x00,0x04,0x00,0x07,0x00,0x00,0x00, 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x04,0x00,0x00,0x00, -0x1c,0x00,0x04,0x00,0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x28,0x00,0x00,0x00,0x1e,0x00,0x0d,0x00,0x2a,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x02,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x1b,0x00,0x00,0x00, +0x6f,0x12,0x83,0x3a,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,0x2b,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x1c,0x00,0x04,0x00,0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x17,0x00,0x00,0x00,0x1e,0x00,0x0c,0x00,0x29,0x00,0x00,0x00, 0x07,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00, 0x07,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0x2b,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x2a,0x00,0x00,0x00, -0x3b,0x00,0x04,0x00,0x2b,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0x09,0x00,0x00,0x00,0x15,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x20,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x2f,0x00,0x00,0x00,0x09,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x33,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x05,0x00,0x00,0x00, -0x14,0x00,0x02,0x00,0x3c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x2d,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x07,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0x45,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x53,0x00,0x00,0x00,0xcd,0xcc,0xcc,0x3d, -0x17,0x00,0x04,0x00,0x66,0x00,0x00,0x00,0x07,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x67,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x66,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0x67,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x69,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x6a,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x73,0x00,0x00,0x00,0x09,0x00,0x00,0x00, -0x07,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0x94,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0x95,0x00,0x00,0x00, -0x94,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x96,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0x95,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0x96,0x00,0x00,0x00,0x97,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x1d,0x00,0x03,0x00,0x9a,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x1e,0x00,0x03,0x00,0x9b,0x00,0x00,0x00,0x9a,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0x9c,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x9b,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x9c,0x00,0x00,0x00, -0x9d,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0xa0,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x06,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00,0xbb,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x1d,0x00,0x03,0x00,0xc1,0x00,0x00,0x00, -0x2d,0x00,0x00,0x00,0x1e,0x00,0x03,0x00,0xc2,0x00,0x00,0x00, -0xc1,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0xc3,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0xc2,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, -0xc3,0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x20,0x00,0x04,0x00,0xc6,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, -0x2d,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0xca,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, -0xd1,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, -0xd2,0x00,0x00,0x00,0xd1,0x00,0x00,0x00,0x20,0x00,0x04,0x00, -0xd3,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0xd2,0x00,0x00,0x00, -0x3b,0x00,0x04,0x00,0xd3,0x00,0x00,0x00,0xd4,0x00,0x00,0x00, -0x0c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0xe1,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x19,0x01,0x00,0x00,0x00,0x01,0x00,0x00, -0x2c,0x00,0x06,0x00,0x66,0x00,0x00,0x00,0x1a,0x01,0x00,0x00, -0x69,0x00,0x00,0x00,0x19,0x01,0x00,0x00,0x69,0x00,0x00,0x00, -0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x60,0x01,0x00,0x00, -0x00,0x00,0x00,0x3f,0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0x1b,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00, -0x6f,0x00,0x00,0x00,0x1c,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, -0x1c,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x6a,0x00,0x00,0x00, -0x6b,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x69,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, -0x6b,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x6d,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x6a,0x00,0x00,0x00,0x70,0x00,0x00,0x00, -0x68,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x71,0x00,0x00,0x00,0x70,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x73,0x00,0x00,0x00,0x74,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x74,0x00,0x00,0x00, -0xae,0x00,0x05,0x00,0x3c,0x00,0x00,0x00,0x76,0x00,0x00,0x00, -0x6d,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, -0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x78,0x00,0x00,0x00, -0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, -0x1b,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x78,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x73,0x00,0x00,0x00,0x7c,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x45,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x07,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x7c,0x00,0x00,0x00, -0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x7e,0x00,0x00,0x00, -0x6d,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x89,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, -0x7d,0x00,0x00,0x00,0xac,0x00,0x05,0x00,0x3c,0x00,0x00,0x00, -0x85,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x6f,0x00,0x00,0x00, -0xf7,0x00,0x03,0x00,0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0xfa,0x00,0x04,0x00,0x85,0x00,0x00,0x00,0x86,0x00,0x00,0x00, -0x87,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0x86,0x00,0x00,0x00, -0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x8c,0x00,0x00,0x00, -0x71,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x84,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x7e,0x00,0x00,0x00, -0x7d,0x00,0x00,0x00,0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0x91,0x00,0x00,0x00,0x8c,0x00,0x00,0x00,0x90,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x93,0x00,0x00,0x00, -0x91,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0xa0,0x00,0x00,0x00,0xa1,0x00,0x00,0x00,0x9d,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0x93,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xa2,0x00,0x00,0x00,0xa1,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0xa0,0x00,0x00,0x00,0xa3,0x00,0x00,0x00, -0x97,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x93,0x00,0x00,0x00, -0x3e,0x00,0x03,0x00,0xa3,0x00,0x00,0x00,0xa2,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xa5,0x00,0x00,0x00, -0x93,0x00,0x00,0x00,0x69,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0xa0,0x00,0x00,0x00,0xa8,0x00,0x00,0x00,0x9d,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0xa5,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xa9,0x00,0x00,0x00,0xa8,0x00,0x00,0x00, -0x41,0x00,0x06,0x00,0xa0,0x00,0x00,0x00,0xaa,0x00,0x00,0x00, -0x97,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0xa5,0x00,0x00,0x00, -0x3e,0x00,0x03,0x00,0xaa,0x00,0x00,0x00,0xa9,0x00,0x00,0x00, -0xf9,0x00,0x02,0x00,0x1b,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, -0x87,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0xb0,0x00,0x00,0x00,0x71,0x00,0x00,0x00,0x75,0x00,0x00,0x00, -0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xb4,0x00,0x00,0x00, -0x7e,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x80,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0xb5,0x00,0x00,0x00,0xb0,0x00,0x00,0x00, -0xb4,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0xb7,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xb8,0x00,0x00,0x00, -0xb5,0x00,0x00,0x00,0xb7,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x73,0x00,0x00,0x00,0xbc,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0xbb,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0xbd,0x00,0x00,0x00,0xbc,0x00,0x00,0x00,0x86,0x00,0x05,0x00, -0x07,0x00,0x00,0x00,0xbe,0x00,0x00,0x00,0x71,0x00,0x00,0x00, -0xbd,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xc6,0x00,0x00,0x00, -0xc7,0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0xbe,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x2d,0x00,0x00,0x00, -0xc8,0x00,0x00,0x00,0xc7,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x73,0x00,0x00,0x00,0xcb,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0xca,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, -0xcc,0x00,0x00,0x00,0xcb,0x00,0x00,0x00,0xab,0x00,0x05,0x00, -0x3c,0x00,0x00,0x00,0xcd,0x00,0x00,0x00,0xcc,0x00,0x00,0x00, -0x6f,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0xd0,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0xcd,0x00,0x00,0x00, -0xcf,0x00,0x00,0x00,0xd9,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0xcf,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xa0,0x00,0x00,0x00, -0xd7,0x00,0x00,0x00,0xd4,0x00,0x00,0x00,0x42,0x00,0x00,0x00, -0xb7,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0xd8,0x00,0x00,0x00,0xd7,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, -0xd0,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xd9,0x00,0x00,0x00, -0xf9,0x00,0x02,0x00,0xd0,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, -0xd0,0x00,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x5d,0x01,0x00,0x00,0xd8,0x00,0x00,0x00,0xcf,0x00,0x00,0x00, -0x1f,0x00,0x00,0x00,0xd9,0x00,0x00,0x00,0x6f,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xdd,0x00,0x00,0x00,0xc8,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00,0xde,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xdf,0x00,0x00,0x00,0xde,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xe0,0x00,0x00,0x00, -0xdd,0x00,0x00,0x00,0xdf,0x00,0x00,0x00,0x41,0x00,0x05,0x00, -0x2f,0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, -0xe1,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0xe3,0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x70,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0xe5,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xe7,0x00,0x00,0x00, -0xe5,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, -0x06,0x00,0x00,0x00,0xe8,0x00,0x00,0x00,0x01,0x00,0x00,0x00, -0x1a,0x00,0x00,0x00,0xe3,0x00,0x00,0x00,0xe7,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xe9,0x00,0x00,0x00, -0xe0,0x00,0x00,0x00,0xe8,0x00,0x00,0x00,0x88,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0xeb,0x00,0x00,0x00,0xe9,0x00,0x00,0x00, -0x5d,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00, -0x26,0x01,0x00,0x00,0x2c,0x00,0x00,0x00,0x2e,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x27,0x01,0x00,0x00, -0x26,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x2a,0x01,0x00,0x00,0xdf,0x00,0x00,0x00,0xeb,0x00,0x00,0x00, -0x41,0x00,0x05,0x00,0x2f,0x00,0x00,0x00,0x2c,0x01,0x00,0x00, -0x2c,0x00,0x00,0x00,0x39,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x2d,0x01,0x00,0x00,0x2c,0x01,0x00,0x00, -0xb7,0x00,0x05,0x00,0x3c,0x00,0x00,0x00,0x2e,0x01,0x00,0x00, -0x2d,0x01,0x00,0x00,0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, -0x47,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, -0x2e,0x01,0x00,0x00,0x2f,0x01,0x00,0x00,0x47,0x01,0x00,0x00, -0xf8,0x00,0x02,0x00,0x2f,0x01,0x00,0x00,0x41,0x00,0x06,0x00, -0x2f,0x00,0x00,0x00,0x30,0x01,0x00,0x00,0x2c,0x00,0x00,0x00, -0x41,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x31,0x01,0x00,0x00,0x30,0x01,0x00,0x00, -0x41,0x00,0x06,0x00,0x2f,0x00,0x00,0x00,0x32,0x01,0x00,0x00, -0x2c,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x45,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x33,0x01,0x00,0x00, -0x32,0x01,0x00,0x00,0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00, -0x54,0x01,0x00,0x00,0xb7,0x00,0x00,0x00,0x83,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x55,0x01,0x00,0x00,0x54,0x01,0x00,0x00, -0x31,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x56,0x01,0x00,0x00,0x33,0x01,0x00,0x00,0x31,0x01,0x00,0x00, -0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x57,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x1b,0x00,0x00,0x00, -0x56,0x01,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x58,0x01,0x00,0x00,0x55,0x01,0x00,0x00,0x57,0x01,0x00,0x00, -0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x5a,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x20,0x00,0x00,0x00, -0x58,0x01,0x00,0x00,0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x5b,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00, -0x1f,0x00,0x00,0x00,0x5a,0x01,0x00,0x00,0x83,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x5c,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, -0x5b,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x37,0x01,0x00,0x00,0x5c,0x01,0x00,0x00,0x2d,0x01,0x00,0x00, -0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x61,0x01,0x00,0x00, -0x5b,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x0c,0x00,0x08,0x00, +0x06,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x2a,0x00,0x00,0x00, +0x09,0x00,0x00,0x00,0x29,0x00,0x00,0x00,0x3b,0x00,0x04,0x00, +0x2a,0x00,0x00,0x00,0x2b,0x00,0x00,0x00,0x09,0x00,0x00,0x00, +0x15,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x20,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x2d,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x2e,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x02,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x38,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x14,0x00,0x02,0x00, +0x3b,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0x40,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0x44,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0x52,0x00,0x00,0x00,0xcd,0xcc,0xcc,0x3d,0x17,0x00,0x04,0x00, +0x65,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x66,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x65,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x66,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x69,0x00,0x00,0x00,0x01,0x00,0x00,0x00, +0x07,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x72,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x07,0x00,0x00,0x00, +0x1d,0x00,0x03,0x00,0x86,0x00,0x00,0x00,0x06,0x00,0x00,0x00, +0x1e,0x00,0x03,0x00,0x87,0x00,0x00,0x00,0x86,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0x88,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0x87,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0x88,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0x8c,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0x8d,0x00,0x00,0x00,0x8c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0x8e,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x8d,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0x8e,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00,0x92,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x2c,0x00,0x00,0x00,0xa7,0x00,0x00,0x00,0x03,0x00,0x00,0x00, +0x1d,0x00,0x03,0x00,0xac,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, +0x1e,0x00,0x03,0x00,0xad,0x00,0x00,0x00,0xac,0x00,0x00,0x00, +0x20,0x00,0x04,0x00,0xae,0x00,0x00,0x00,0x0c,0x00,0x00,0x00, +0xad,0x00,0x00,0x00,0x3b,0x00,0x04,0x00,0xae,0x00,0x00,0x00, +0xaf,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0xb1,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x2c,0x00,0x00,0x00, +0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00,0xb5,0x00,0x00,0x00, +0x08,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0xbf,0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x1d,0x00,0x03,0x00, +0xc6,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x1e,0x00,0x03,0x00, +0xc7,0x00,0x00,0x00,0xc6,0x00,0x00,0x00,0x20,0x00,0x04,0x00, +0xc8,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0xc7,0x00,0x00,0x00, +0x3b,0x00,0x04,0x00,0xc8,0x00,0x00,0x00,0xc9,0x00,0x00,0x00, +0x0c,0x00,0x00,0x00,0x2b,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0xf9,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x2c,0x00,0x06,0x00, +0x65,0x00,0x00,0x00,0xfa,0x00,0x00,0x00,0x68,0x00,0x00,0x00, +0xf9,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x2b,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x40,0x01,0x00,0x00,0x00,0x00,0x00,0x3f, +0x36,0x00,0x05,0x00,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x05,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0xfb,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfb,0x00,0x03,0x00,0x6e,0x00,0x00,0x00, +0xfc,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xfc,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x69,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x67,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0x6b,0x00,0x00,0x00,0x6a,0x00,0x00,0x00, +0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x6b,0x00,0x00,0x00,0x17,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x69,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x67,0x00,0x00,0x00, +0x6e,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x70,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x74,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x77,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x75,0x00,0x00,0x00, +0x76,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x76,0x00,0x00,0x00,0xf9,0x00,0x02,0x00,0xfb,0x00,0x00,0x00, +0xf8,0x00,0x02,0x00,0x77,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0x44,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0xae,0x00,0x05,0x00, +0x3b,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x7b,0x00,0x00,0x00,0xf7,0x00,0x03,0x00,0x7e,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00,0x7c,0x00,0x00,0x00, +0x7d,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7d,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x83,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0x93,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x94,0x00,0x00,0x00,0x93,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00,0x95,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x85,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x95,0x00,0x00,0x00,0x94,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0x97,0x00,0x00,0x00, +0x85,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0x9a,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0x97,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x9b,0x00,0x00,0x00,0x9a,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00,0x9c,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x97,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0x9c,0x00,0x00,0x00,0x9b,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0xfb,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0x7e,0x00,0x00,0x00,0x84,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0xa2,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x74,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xa4,0x00,0x00,0x00, +0xa2,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x41,0x00,0x05,0x00, +0x72,0x00,0x00,0x00,0xa8,0x00,0x00,0x00,0x2b,0x00,0x00,0x00, +0xa7,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x07,0x00,0x00,0x00, +0xa9,0x00,0x00,0x00,0xa8,0x00,0x00,0x00,0x86,0x00,0x05,0x00, +0x07,0x00,0x00,0x00,0xaa,0x00,0x00,0x00,0x70,0x00,0x00,0x00, +0xa9,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0xb1,0x00,0x00,0x00, +0xb2,0x00,0x00,0x00,0xaf,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xaa,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x2c,0x00,0x00,0x00, +0xb3,0x00,0x00,0x00,0xb2,0x00,0x00,0x00,0x6f,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xb4,0x00,0x00,0x00,0xb3,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00,0xb6,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0xb5,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xb7,0x00,0x00,0x00,0xb6,0x00,0x00,0x00, +0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xb9,0x00,0x00,0x00, +0x6c,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0xbb,0x00,0x00,0x00,0xb9,0x00,0x00,0x00,0x40,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0xbc,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x1a,0x00,0x00,0x00,0xb7,0x00,0x00,0x00, +0xbb,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0xbd,0x00,0x00,0x00,0xb4,0x00,0x00,0x00,0xbc,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x72,0x00,0x00,0x00,0xc0,0x00,0x00,0x00, +0x2b,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x07,0x00,0x00,0x00,0xc1,0x00,0x00,0x00,0xc0,0x00,0x00,0x00, +0xab,0x00,0x05,0x00,0x3b,0x00,0x00,0x00,0xc2,0x00,0x00,0x00, +0xc1,0x00,0x00,0x00,0x6e,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, +0xc5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, +0xc2,0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0xce,0x00,0x00,0x00, +0xf8,0x00,0x02,0x00,0xc4,0x00,0x00,0x00,0x86,0x00,0x05,0x00, +0x07,0x00,0x00,0x00,0xcb,0x00,0x00,0x00,0x6c,0x00,0x00,0x00, +0x17,0x00,0x00,0x00,0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00, +0xcc,0x00,0x00,0x00,0xc9,0x00,0x00,0x00,0x41,0x00,0x00,0x00, +0xcb,0x00,0x00,0x00,0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00, +0xcd,0x00,0x00,0x00,0xcc,0x00,0x00,0x00,0xf9,0x00,0x02,0x00, +0xc5,0x00,0x00,0x00,0xf8,0x00,0x02,0x00,0xce,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0xc5,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0xc5,0x00,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, +0x3d,0x01,0x00,0x00,0xcd,0x00,0x00,0x00,0xc4,0x00,0x00,0x00, +0x1f,0x00,0x00,0x00,0xce,0x00,0x00,0x00,0x88,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0xbd,0x00,0x00,0x00, +0x3d,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x06,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x2d,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x07,0x01,0x00,0x00, +0x06,0x01,0x00,0x00,0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00, +0x08,0x01,0x00,0x00,0x2b,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x09,0x01,0x00,0x00, +0x08,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x0a,0x01,0x00,0x00,0x09,0x01,0x00,0x00,0xd2,0x00,0x00,0x00, +0x41,0x00,0x05,0x00,0x2e,0x00,0x00,0x00,0x0c,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x0d,0x01,0x00,0x00,0x0c,0x01,0x00,0x00, +0xb7,0x00,0x05,0x00,0x3b,0x00,0x00,0x00,0x0e,0x01,0x00,0x00, +0x0d,0x01,0x00,0x00,0x20,0x00,0x00,0x00,0xf7,0x00,0x03,0x00, +0x27,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xfa,0x00,0x04,0x00, +0x0e,0x01,0x00,0x00,0x0f,0x01,0x00,0x00,0x27,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x0f,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x2e,0x00,0x00,0x00,0x10,0x01,0x00,0x00,0x2b,0x00,0x00,0x00, +0x40,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x11,0x01,0x00,0x00,0x10,0x01,0x00,0x00, +0x41,0x00,0x06,0x00,0x2e,0x00,0x00,0x00,0x12,0x01,0x00,0x00, +0x2b,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x44,0x00,0x00,0x00, +0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x13,0x01,0x00,0x00, +0x12,0x01,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, +0x33,0x01,0x00,0x00,0x6c,0x00,0x00,0x00,0x17,0x00,0x00,0x00, +0x70,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0x34,0x01,0x00,0x00, +0x33,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x35,0x01,0x00,0x00,0x34,0x01,0x00,0x00,0x11,0x01,0x00,0x00, +0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x36,0x01,0x00,0x00, +0x13,0x01,0x00,0x00,0x11,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, +0x06,0x00,0x00,0x00,0x37,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x28,0x00,0x00,0x00,0x1b,0x00,0x00,0x00,0x36,0x01,0x00,0x00, +0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x38,0x01,0x00,0x00, +0x35,0x01,0x00,0x00,0x37,0x01,0x00,0x00,0x0c,0x00,0x07,0x00, 0x06,0x00,0x00,0x00,0x3a,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x32,0x00,0x00,0x00,0x61,0x01,0x00,0x00,0x2d,0x01,0x00,0x00, -0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x3d,0x01,0x00,0x00,0xeb,0x00,0x00,0x00,0x37,0x01,0x00,0x00, -0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0x3e,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x2a,0x01,0x00,0x00, -0x3a,0x01,0x00,0x00,0x3d,0x01,0x00,0x00,0x88,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x41,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, -0xdf,0x00,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, -0x42,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00, -0x41,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0x44,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0x53,0x00,0x00,0x00,0x42,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x46,0x01,0x00,0x00, -0x27,0x01,0x00,0x00,0x44,0x01,0x00,0x00,0xf9,0x00,0x02,0x00, -0x47,0x01,0x00,0x00,0xf8,0x00,0x02,0x00,0x47,0x01,0x00,0x00, -0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x5f,0x01,0x00,0x00, -0x27,0x01,0x00,0x00,0xd0,0x00,0x00,0x00,0x46,0x01,0x00,0x00, -0x2f,0x01,0x00,0x00,0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00, -0x5e,0x01,0x00,0x00,0x2a,0x01,0x00,0x00,0xd0,0x00,0x00,0x00, -0x3e,0x01,0x00,0x00,0x2f,0x01,0x00,0x00,0x0c,0x00,0x06,0x00, -0x06,0x00,0x00,0x00,0x49,0x01,0x00,0x00,0x01,0x00,0x00,0x00, -0x0e,0x00,0x00,0x00,0x5e,0x01,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x4b,0x01,0x00,0x00,0x49,0x01,0x00,0x00, -0x5f,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, -0x4d,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00, -0x5e,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, -0x4f,0x01,0x00,0x00,0x4d,0x01,0x00,0x00,0x5f,0x01,0x00,0x00, -0x41,0x00,0x06,0x00,0xa0,0x00,0x00,0x00,0xf8,0x00,0x00,0x00, -0x9d,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0xb8,0x00,0x00,0x00, -0x3d,0x00,0x04,0x00,0x06,0x00,0x00,0x00,0xf9,0x00,0x00,0x00, -0xf8,0x00,0x00,0x00,0x86,0x00,0x05,0x00,0x07,0x00,0x00,0x00, -0xfe,0x00,0x00,0x00,0x7d,0x00,0x00,0x00,0x17,0x00,0x00,0x00, -0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xff,0x00,0x00,0x00, -0xb8,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x41,0x00,0x06,0x00, -0xa0,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x9d,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00, -0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x09,0x01,0x00,0x00, -0x01,0x01,0x00,0x00,0x4f,0x01,0x00,0x00,0x7f,0x00,0x04,0x00, -0x06,0x00,0x00,0x00,0x62,0x01,0x00,0x00,0x09,0x01,0x00,0x00, -0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0x0a,0x01,0x00,0x00, -0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0xf9,0x00,0x00,0x00, -0x4b,0x01,0x00,0x00,0x62,0x01,0x00,0x00,0x41,0x00,0x06,0x00, -0xa0,0x00,0x00,0x00,0x0b,0x01,0x00,0x00,0x97,0x00,0x00,0x00, -0x42,0x00,0x00,0x00,0xb8,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, -0x0b,0x01,0x00,0x00,0x0a,0x01,0x00,0x00,0x85,0x00,0x05,0x00, -0x06,0x00,0x00,0x00,0x16,0x01,0x00,0x00,0x01,0x01,0x00,0x00, -0x4b,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, -0x17,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, -0xf9,0x00,0x00,0x00,0x4f,0x01,0x00,0x00,0x16,0x01,0x00,0x00, -0x41,0x00,0x06,0x00,0xa0,0x00,0x00,0x00,0x18,0x01,0x00,0x00, -0x97,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0xff,0x00,0x00,0x00, -0x3e,0x00,0x03,0x00,0x18,0x01,0x00,0x00,0x17,0x01,0x00,0x00, -0xf9,0x00,0x02,0x00,0x1b,0x01,0x00,0x00,0xf8,0x00,0x02,0x00, -0x1b,0x01,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00, +0x28,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x38,0x01,0x00,0x00, +0x0c,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x3b,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x1f,0x00,0x00,0x00, +0x3a,0x01,0x00,0x00,0x83,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x3c,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x3b,0x01,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x17,0x01,0x00,0x00, +0x3c,0x01,0x00,0x00,0x0d,0x01,0x00,0x00,0x83,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x41,0x01,0x00,0x00,0x3b,0x01,0x00,0x00, +0x1f,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0x1a,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0x41,0x01,0x00,0x00,0x0d,0x01,0x00,0x00,0x1f,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x1d,0x01,0x00,0x00, +0xd2,0x00,0x00,0x00,0x17,0x01,0x00,0x00,0x0c,0x00,0x08,0x00, +0x06,0x00,0x00,0x00,0x1e,0x01,0x00,0x00,0x01,0x00,0x00,0x00, +0x32,0x00,0x00,0x00,0x0a,0x01,0x00,0x00,0x1a,0x01,0x00,0x00, +0x1d,0x01,0x00,0x00,0x88,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x21,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x09,0x01,0x00,0x00, +0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x22,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x21,0x01,0x00,0x00, +0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0x24,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x52,0x00,0x00,0x00, +0x22,0x01,0x00,0x00,0x1f,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0x26,0x01,0x00,0x00,0x07,0x01,0x00,0x00, +0x24,0x01,0x00,0x00,0xf9,0x00,0x02,0x00,0x27,0x01,0x00,0x00, +0xf8,0x00,0x02,0x00,0x27,0x01,0x00,0x00,0xf5,0x00,0x07,0x00, +0x06,0x00,0x00,0x00,0x3f,0x01,0x00,0x00,0x07,0x01,0x00,0x00, +0xc5,0x00,0x00,0x00,0x26,0x01,0x00,0x00,0x0f,0x01,0x00,0x00, +0xf5,0x00,0x07,0x00,0x06,0x00,0x00,0x00,0x3e,0x01,0x00,0x00, +0x0a,0x01,0x00,0x00,0xc5,0x00,0x00,0x00,0x1e,0x01,0x00,0x00, +0x0f,0x01,0x00,0x00,0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00, +0x29,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x0e,0x00,0x00,0x00, +0x3e,0x01,0x00,0x00,0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00, +0x2b,0x01,0x00,0x00,0x29,0x01,0x00,0x00,0x3f,0x01,0x00,0x00, +0x0c,0x00,0x06,0x00,0x06,0x00,0x00,0x00,0x2d,0x01,0x00,0x00, +0x01,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x3e,0x01,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0x2f,0x01,0x00,0x00, +0x2d,0x01,0x00,0x00,0x3f,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0xde,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xa4,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xdf,0x00,0x00,0x00,0xde,0x00,0x00,0x00, +0x80,0x00,0x05,0x00,0x07,0x00,0x00,0x00,0xe2,0x00,0x00,0x00, +0xa4,0x00,0x00,0x00,0x68,0x00,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0xe3,0x00,0x00,0x00,0x8f,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x3d,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0xe4,0x00,0x00,0x00,0xe3,0x00,0x00,0x00, +0x85,0x00,0x05,0x00,0x06,0x00,0x00,0x00,0xec,0x00,0x00,0x00, +0xe4,0x00,0x00,0x00,0x2f,0x01,0x00,0x00,0x7f,0x00,0x04,0x00, +0x06,0x00,0x00,0x00,0x42,0x01,0x00,0x00,0xec,0x00,0x00,0x00, +0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00,0xed,0x00,0x00,0x00, +0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0xdf,0x00,0x00,0x00, +0x2b,0x01,0x00,0x00,0x42,0x01,0x00,0x00,0x41,0x00,0x06,0x00, +0x92,0x00,0x00,0x00,0xee,0x00,0x00,0x00,0x89,0x00,0x00,0x00, +0x41,0x00,0x00,0x00,0xa4,0x00,0x00,0x00,0x3e,0x00,0x03,0x00, +0xee,0x00,0x00,0x00,0xed,0x00,0x00,0x00,0x85,0x00,0x05,0x00, +0x06,0x00,0x00,0x00,0xf6,0x00,0x00,0x00,0xe4,0x00,0x00,0x00, +0x2b,0x01,0x00,0x00,0x0c,0x00,0x08,0x00,0x06,0x00,0x00,0x00, +0xf7,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x32,0x00,0x00,0x00, +0xdf,0x00,0x00,0x00,0x2f,0x01,0x00,0x00,0xf6,0x00,0x00,0x00, +0x41,0x00,0x06,0x00,0x92,0x00,0x00,0x00,0xf8,0x00,0x00,0x00, +0x89,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0xe2,0x00,0x00,0x00, +0x3e,0x00,0x03,0x00,0xf8,0x00,0x00,0x00,0xf7,0x00,0x00,0x00, +0xf9,0x00,0x02,0x00,0xfb,0x00,0x00,0x00,0xf8,0x00,0x02,0x00, +0xfb,0x00,0x00,0x00,0xfd,0x00,0x01,0x00,0x38,0x00,0x01,0x00, }; -const uint64_t rope_neox_f32_len = 4032; +const uint64_t rope_norm_f32_len = 3852; unsigned char scale_f32_data[] = { 0x03,0x02,0x23,0x07,0x00,0x05,0x01,0x00,0x0b,0x00,0x0d,0x00, diff --git a/ggml-vulkan.cpp b/ggml-vulkan.cpp index 128769177..05cfa3159 100644 --- a/ggml-vulkan.cpp +++ b/ggml-vulkan.cpp @@ -150,7 +150,7 @@ struct vk_device { vk_pipeline pipeline_relu_f32; vk_pipeline pipeline_diag_mask_inf_f32; vk_pipeline pipeline_soft_max_f32, pipeline_soft_max_f32_f16; - vk_pipeline pipeline_rope_f32, pipeline_rope_f16; + vk_pipeline pipeline_rope_norm_f32, pipeline_rope_norm_f16; vk_pipeline pipeline_rope_neox_f32, pipeline_rope_neox_f16; vk_pipeline pipeline_argsort_f32; vk_pipeline pipeline_sum_rows_f32; @@ -283,26 +283,15 @@ struct vk_op_diag_mask_push_constants { struct vk_op_rope_push_constants { uint32_t ncols; + uint32_t n_dims; float freq_scale; uint32_t p_delta_rows; float freq_base; float ext_factor; float attn_factor; - float corr_dims[4]; -}; - -struct vk_op_rope_neox_push_constants { - uint32_t ncols; - uint32_t ndims; - float freq_scale; - uint32_t p_delta_rows; - float freq_base; - float ext_factor; - float attn_factor; - float corr_dims[4]; + float corr_dims[2]; float theta_scale; - float inv_ndims; - uint32_t has_freq_facs; + uint32_t has_ff; }; struct vk_op_soft_max_push_constants { @@ -1534,11 +1523,11 @@ static void ggml_vk_load_shaders(ggml_backend_vk_context * ctx) { ggml_vk_create_pipeline(ctx, ctx->device->pipeline_soft_max_f32, "soft_max_f32", soft_max_f32_len, soft_max_f32_data, "main", 3, sizeof(vk_op_soft_max_push_constants), {1, 1, 1}, {}, 1); ggml_vk_create_pipeline(ctx, ctx->device->pipeline_soft_max_f32_f16, "soft_max_f32_f16", soft_max_f32_f16_len, soft_max_f32_f16_data, "main", 3, sizeof(vk_op_soft_max_push_constants), {1, 1, 1}, {}, 1); - ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_f32, "rope_f32", rope_f32_len, rope_f32_data, "main", 3, sizeof(vk_op_rope_push_constants), {1, 512, 1}, {}, 1); - ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_f16, "rope_f16", rope_f16_len, rope_f16_data, "main", 3, sizeof(vk_op_rope_push_constants), {1, 512, 1}, {}, 1); + ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_norm_f32, "rope_norm_f32", rope_norm_f32_len, rope_norm_f32_data, "main", 4, sizeof(vk_op_rope_push_constants), {1, 512, 1}, {}, 1); + ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_norm_f16, "rope_norm_f16", rope_norm_f16_len, rope_norm_f16_data, "main", 4, sizeof(vk_op_rope_push_constants), {1, 512, 1}, {}, 1); - ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_neox_f32, "rope_neox_f32", rope_neox_f32_len, rope_neox_f32_data, "main", 4, sizeof(vk_op_rope_neox_push_constants), {1, 512, 1}, {}, 1); - ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_neox_f16, "rope_neox_f16", rope_neox_f16_len, rope_neox_f16_data, "main", 4, sizeof(vk_op_rope_neox_push_constants), {1, 512, 1}, {}, 1); + ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_neox_f32, "rope_neox_f32", rope_neox_f32_len, rope_neox_f32_data, "main", 4, sizeof(vk_op_rope_push_constants), {1, 512, 1}, {}, 1); + ggml_vk_create_pipeline(ctx, ctx->device->pipeline_rope_neox_f16, "rope_neox_f16", rope_neox_f16_len, rope_neox_f16_data, "main", 4, sizeof(vk_op_rope_push_constants), {1, 512, 1}, {}, 1); ggml_vk_create_pipeline(ctx, ctx->device->pipeline_argsort_f32, "argsort_f32", argsort_f32_len, argsort_f32_data, "main", 2, sizeof(vk_op_argsort_push_constants), {1024, 1, 1}, {}, 1); @@ -3905,10 +3894,10 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const } } else { if (src0->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32) { - return ctx->device->pipeline_rope_f32; + return ctx->device->pipeline_rope_norm_f32; } if (src0->type == GGML_TYPE_F16 && dst->type == GGML_TYPE_F16) { - return ctx->device->pipeline_rope_f16; + return ctx->device->pipeline_rope_norm_f16; } } return nullptr; @@ -4152,24 +4141,16 @@ static void ggml_vk_op_f32(ggml_backend_vk_context * ctx, vk_context * subctx, c ggml_vk_sync_buffers(subctx); ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { { d_X, x_buf_offset, x_sz }, subbuf_y, { d_D, d_buf_offset, d_sz } }, sizeof(PC), &pc, elements); } else if (op == GGML_OP_ROPE) { - const int mode = ((int32_t *) dst->op_params)[2]; - const bool is_neox = mode & 2; - - if (is_neox) { - // Empty src2 is possible in rope, but the shader needs a buffer - vk_subbuffer subbuf_z; - if (use_src2) { - subbuf_z = { d_Z, z_buf_offset, z_sz }; - } else { - subbuf_z = { d_X, 0, d_X->size }; - } - - ggml_vk_sync_buffers(subctx); - ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { { d_X, x_buf_offset, x_sz }, { d_Y, y_buf_offset, y_sz }, subbuf_z, { d_D, d_buf_offset, d_sz } }, sizeof(PC), &pc, elements); + // Empty src2 is possible in rope, but the shader needs a buffer + vk_subbuffer subbuf_z; + if (use_src2) { + subbuf_z = { d_Z, z_buf_offset, z_sz }; } else { - ggml_vk_sync_buffers(subctx); - ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { { d_X, x_buf_offset, x_sz }, { d_Y, y_buf_offset, y_sz }, { d_D, d_buf_offset, d_sz } }, sizeof(PC), &pc, elements); + subbuf_z = { d_X, 0, d_X->size }; } + + ggml_vk_sync_buffers(subctx); + ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { { d_X, x_buf_offset, x_sz }, { d_Y, y_buf_offset, y_sz }, subbuf_z, { d_D, d_buf_offset, d_sz } }, sizeof(PC), &pc, elements); } else if (use_src2) { ggml_vk_sync_buffers(subctx); ggml_vk_dispatch_pipeline(ctx, subctx, pipeline, { { d_X, x_buf_offset, x_sz }, { d_Y, y_buf_offset, y_sz }, { d_Z, z_buf_offset, z_sz }, { d_D, d_buf_offset, d_sz } }, sizeof(PC), &pc, elements); @@ -4391,7 +4372,7 @@ static void ggml_vk_soft_max(ggml_backend_vk_context * ctx, vk_context * subctx, static void ggml_vk_rope(ggml_backend_vk_context * ctx, vk_context * subctx, const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * src2, ggml_tensor * dst) { const int n_dims = ((int32_t *) dst->op_params)[1]; - const int mode = ((int32_t *) dst->op_params)[2]; + // const int mode = ((int32_t *) dst->op_params)[2]; // const int n_ctx = ((int32_t *) dst->op_params)[3]; const int n_ctx_orig = ((int32_t *) dst->op_params)[4]; const float freq_base = ((float *) dst->op_params)[5]; @@ -4401,28 +4382,16 @@ static void ggml_vk_rope(ggml_backend_vk_context * ctx, vk_context * subctx, con const float beta_fast = ((float *) dst->op_params)[9]; const float beta_slow = ((float *) dst->op_params)[10]; - const bool is_neox = mode & 2; - -#pragma message("TODO: update rope NORM mode to match NEOX mode") -#pragma message(" https://github.com/ggerganov/llama.cpp/pull/7634") - float corr_dims[2]; ggml_rope_yarn_corr_dims(n_dims, n_ctx_orig, freq_base, beta_fast, beta_slow, corr_dims); - if (is_neox) { - const float theta_scale = powf(freq_base, -2.0f/n_dims); - const float inv_ndims = -1.0f / n_dims; - ggml_vk_op_f32(ctx, subctx, src0, src1, src2, dst, GGML_OP_ROPE, { - (uint32_t)src0->ne[0], (uint32_t)n_dims, freq_scale, (uint32_t)src0->ne[1], - freq_base, ext_factor, attn_factor, {corr_dims[0], corr_dims[1], 0.0f, 0.0f}, theta_scale, inv_ndims, - src2 != nullptr, - }); - } else { - ggml_vk_op_f32(ctx, subctx, src0, src1, src2, dst, GGML_OP_ROPE, { - (uint32_t)src0->ne[0], freq_scale, (uint32_t)src0->ne[1], - freq_base, ext_factor, attn_factor, {corr_dims[0], corr_dims[1], 0.0f, 0.0f} - }); - } + const float theta_scale = powf(freq_base, -2.0f/n_dims); + + ggml_vk_op_f32(ctx, subctx, src0, src1, src2, dst, GGML_OP_ROPE, { + (uint32_t)src0->ne[0], (uint32_t)n_dims, freq_scale, (uint32_t)src0->ne[1], + freq_base, ext_factor, attn_factor, {corr_dims[0], corr_dims[1]}, theta_scale, + src2 != nullptr, + }); } static void ggml_vk_argsort(ggml_backend_vk_context * ctx, vk_context * subctx, const ggml_tensor * src0, ggml_tensor * dst) { @@ -6070,7 +6039,13 @@ GGML_CALL static ggml_backend_buffer_t ggml_backend_vk_buffer_type_alloc_buffer( std::cerr << "ggml_backend_vk_buffer_type_alloc_buffer(" << size << ")" << std::endl; #endif ggml_backend_vk_buffer_type_context * ctx = (ggml_backend_vk_buffer_type_context *) buft->context; - vk_buffer dev_buffer = ggml_vk_create_buffer_device(ctx->ctx, size); + + vk_buffer dev_buffer = nullptr; + try { + dev_buffer = ggml_vk_create_buffer_device(ctx->ctx, size); + } catch (const vk::SystemError& e) { + return nullptr; + } ggml_backend_vk_buffer_context * bufctx = new ggml_backend_vk_buffer_context(ctx->ctx, std::move(dev_buffer), ctx->name); @@ -6466,7 +6441,7 @@ GGML_CALL static bool ggml_backend_vk_supports_op(ggml_backend_t backend, const // return src0_type != GGML_TYPE_I32 && src0_type != GGML_TYPE_I16; // } break; case GGML_OP_ROPE: - return true; + return ggml_is_contiguous(op->src[0]); case GGML_OP_NONE: case GGML_OP_RESHAPE: case GGML_OP_VIEW: diff --git a/ggml_vk_generate_shaders.py b/ggml_vk_generate_shaders.py index a905f570c..400a63f57 100644 --- a/ggml_vk_generate_shaders.py +++ b/ggml_vk_generate_shaders.py @@ -2400,7 +2400,7 @@ void main() { """ # ROPE -rope_src = """ +rope_norm_src = """ #version 450 #extension GL_EXT_shader_16bit_storage : require @@ -2408,17 +2408,21 @@ rope_src = """ layout(local_size_x = 1, local_size_y = 256, local_size_z = 1) in; layout (binding = 0) readonly buffer X {A_TYPE data_a[];}; -layout (binding = 1) readonly buffer Y {int data_b[];}; -layout (binding = 2) writeonly buffer D {D_TYPE data_d[];}; +layout (binding = 1) readonly buffer Y {int data_pos[];}; +layout (binding = 2) readonly buffer Z {float data_ff[];}; +layout (binding = 3) writeonly buffer D {D_TYPE data_d[];}; layout (push_constant) uniform parameter { uint ncols; + uint n_dims; float freq_scale; uint p_delta_rows; float freq_base; float ext_factor; float attn_factor; - float corr_dims[4]; + float corr_dims[2]; + float theta_scale; + uint has_ff; } p; float rope_yarn_ramp(const float low, const float high, const uint i0) { @@ -2450,14 +2454,24 @@ void main() { return; } + if (col >= p.n_dims) { + const uint i = row*p.ncols + col; + + data_d[i + 0] = data_a[i + 0]; + data_d[i + 1] = data_a[i + 1]; + + return; + } + const uint i = row*p.ncols + col; const uint i2 = row/p.p_delta_rows; - const int pos = data_b[i2]; - const float theta_base = pos * pow(p.freq_base, -float(col)/p.ncols); + const float theta_base = data_pos[i2] * pow(p.theta_scale, col/2.0f); + + const float freq_factor = p.has_ff != 0 ? data_ff[col/2] : 1.0f; float cos_theta, sin_theta; - rope_yarn(theta_base, col, cos_theta, sin_theta); + rope_yarn(theta_base / freq_factor, col, cos_theta, sin_theta); const float x0 = float(data_a[i + 0]); const float x1 = float(data_a[i + 1]); @@ -2475,22 +2489,21 @@ rope_neox_src = """ layout(local_size_x = 1, local_size_y = 256, local_size_z = 1) in; layout (binding = 0) readonly buffer X {A_TYPE data_a[];}; -layout (binding = 1) readonly buffer Y {int data_b[];}; -layout (binding = 2) readonly buffer Z {float data_freq_factors[];}; +layout (binding = 1) readonly buffer Y {int data_pos[];}; +layout (binding = 2) readonly buffer Z {float data_ff[];}; layout (binding = 3) writeonly buffer D {D_TYPE data_d[];}; layout (push_constant) uniform parameter { uint ncols; - uint ndims; + uint n_dims; float freq_scale; uint p_delta_rows; float freq_base; float ext_factor; float attn_factor; - float corr_dims[4]; + float corr_dims[2]; float theta_scale; - float inv_ndims; - uint has_freq_facs; + uint has_ff; } p; float rope_yarn_ramp(const float low, const float high, const uint i0) { @@ -2522,11 +2535,8 @@ void main() { return; } - const uint ib = col / p.ndims; - const uint ic = col % p.ndims; - - if (ib > 0) { - const uint i = row*p.ncols + ib*p.ndims + ic; + if (col >= p.n_dims) { + const uint i = row*p.ncols + col; data_d[i + 0] = data_a[i + 0]; data_d[i + 1] = data_a[i + 1]; @@ -2534,29 +2544,27 @@ void main() { return; } - const uint i = row*p.ncols + ib*p.ndims + ic/2; + const uint i = row*p.ncols + col/2; const uint i2 = row/p.p_delta_rows; - const int pos = data_b[i2]; - const float freq_factor = p.has_freq_facs != 0 ? data_freq_factors[ic/2] : 1.0f; - const float theta_base = pos*p.freq_scale*pow(p.theta_scale, col/2.0f) / freq_factor; + const float theta_base = data_pos[i2] * pow(p.theta_scale, col/2.0f); + + const float freq_factor = p.has_ff != 0 ? data_ff[col/2] : 1.0f; float cos_theta, sin_theta; - rope_yarn(theta_base, ic, cos_theta, sin_theta); + rope_yarn(theta_base / freq_factor, col, cos_theta, sin_theta); const float x0 = float(data_a[i + 0]); - const float x1 = float(data_a[i + p.ndims/2]); + const float x1 = float(data_a[i + p.n_dims/2]); data_d[i + 0] = D_TYPE(x0*cos_theta - x1*sin_theta); - data_d[i + p.ndims/2] = D_TYPE(x0*sin_theta + x1*cos_theta); + data_d[i + p.n_dims/2] = D_TYPE(x0*sin_theta + x1*cos_theta); } """ argsort_src = """ #version 450 -#extension GL_EXT_shader_16bit_storage : require - #define BLOCK_SIZE 1024 #define ASC 0 @@ -3039,8 +3047,8 @@ async def main(): tasks.append(string_to_spv("soft_max_f32", f"{soft_max_head}\n{shader_f32}\n{soft_max_body}", {"A_TYPE": "float", "B_TYPE": "float", "C_TYPE": "float", "D_TYPE": "float"})) tasks.append(string_to_spv("soft_max_f32_f16", f"{soft_max_head}\n{shader_f32}\n{soft_max_body}", {"A_TYPE": "float", "B_TYPE": "float16_t", "C_TYPE": "float16_t", "D_TYPE": "float"})) - tasks.append(string_to_spv("rope_f32", rope_src, {"A_TYPE": "float", "D_TYPE": "float"})) - tasks.append(string_to_spv("rope_f16", rope_src, {"A_TYPE": "float16_t", "D_TYPE": "float16_t"})) + tasks.append(string_to_spv("rope_norm_f32", rope_norm_src, {"A_TYPE": "float", "D_TYPE": "float"})) + tasks.append(string_to_spv("rope_norm_f16", rope_norm_src, {"A_TYPE": "float16_t", "D_TYPE": "float16_t"})) tasks.append(string_to_spv("rope_neox_f32", rope_neox_src, {"A_TYPE": "float", "D_TYPE": "float"})) tasks.append(string_to_spv("rope_neox_f16", rope_neox_src, {"A_TYPE": "float16_t", "D_TYPE": "float16_t"})) From 73bac2b11d7d3e20982fc9ee607625836387db8b Mon Sep 17 00:00:00 2001 From: "k.h.lai" Date: Wed, 12 Jun 2024 03:26:05 +0800 Subject: [PATCH 19/37] vulkan: select only one device for single gpu with multiple drivers (#7582) --- ggml-vulkan.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/ggml-vulkan.cpp b/ggml-vulkan.cpp index 05cfa3159..06ba23313 100644 --- a/ggml-vulkan.cpp +++ b/ggml-vulkan.cpp @@ -1,5 +1,5 @@ #include "ggml-vulkan.h" - +#include #ifdef GGML_VULKAN_RUN_TESTS #include #endif @@ -9,12 +9,13 @@ #include #include #include -#include #include #include #include #include #include +#include +#include #include "ggml.h" #include "ggml-backend-impl.h" @@ -1555,8 +1556,10 @@ static void ggml_vk_print_gpu_info(size_t idx) { vk::PhysicalDeviceProperties2 props2; vk::PhysicalDeviceMaintenance3Properties props3; vk::PhysicalDeviceSubgroupProperties subgroup_props; + vk::PhysicalDeviceDriverProperties driver_props; props2.pNext = &props3; props3.pNext = &subgroup_props; + subgroup_props.pNext = &driver_props; physical_device.getProperties2(&props2); const size_t subgroup_size = subgroup_props.subgroupSize; @@ -1600,7 +1603,7 @@ static void ggml_vk_print_gpu_info(size_t idx) { fp16 = fp16 && vk12_features.shaderFloat16; std::string device_name = props2.properties.deviceName.data(); - std::cerr << GGML_VK_NAME << idx << ": " << device_name << " | uma: " << uma << " | fp16: " << fp16 << " | warp size: " << subgroup_size << std::endl; + std::cerr << GGML_VK_NAME << idx << ": " << device_name << " (" << driver_props.driverName << ") | uma: " << uma << " | fp16: " << fp16 << " | warp size: " << subgroup_size << std::endl; if (props2.properties.deviceType == vk::PhysicalDeviceType::eCpu) { std::cerr << "ggml_vulkan: Warning: Device type is CPU. This is probably not the device you want." << std::endl; @@ -1696,7 +1699,78 @@ void ggml_vk_instance_init() { vk::PhysicalDeviceProperties props = devices[i].getProperties(); if (props.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) { - vk_instance.device_indices.push_back(i); + // Check if there are two physical devices corresponding to the same GPU + auto old_device = std::find_if( + vk_instance.device_indices.begin(), + vk_instance.device_indices.end(), + [&devices, &props](const size_t k){ return devices[k].getProperties().deviceID == props.deviceID; } + ); + if (old_device == vk_instance.device_indices.end()) { + vk_instance.device_indices.push_back(i); + } else { + // There can be two physical devices corresponding to the same GPU if there are 2 different drivers + // This can cause error when splitting layers aross the devices, need to keep only 1 +#ifdef GGML_VULKAN_DEBUG + std::cerr << "Device " << i << " and device " << *old_device << " have the same device id" << std::endl; +#endif + + vk::PhysicalDeviceProperties2 old_prop; + vk::PhysicalDeviceDriverProperties old_driver; + old_prop.pNext = &old_driver; + devices[*old_device].getProperties2(&old_prop); + + vk::PhysicalDeviceProperties2 new_prop; + vk::PhysicalDeviceDriverProperties new_driver; + new_prop.pNext = &new_driver; + devices[i].getProperties2(&new_prop); + + std::map driver_priorities {}; + int old_priority = std::numeric_limits::max(); + int new_priority = std::numeric_limits::max(); + + // Check https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDriverId.html for the list of driver id + // Smaller number -> higher priority + switch (old_prop.properties.vendorID) { + case VK_VENDOR_ID_AMD: + driver_priorities[vk::DriverId::eMesaRadv] = 1; + driver_priorities[vk::DriverId::eAmdOpenSource] = 2; + driver_priorities[vk::DriverId::eAmdProprietary] = 3; + break; + case VK_VENDOR_ID_INTEL: + driver_priorities[vk::DriverId::eIntelOpenSourceMESA] = 1; + driver_priorities[vk::DriverId::eIntelProprietaryWindows] = 2; + break; + case VK_VENDOR_ID_NVIDIA: + driver_priorities[vk::DriverId::eNvidiaProprietary] = 1; +#if defined(VK_API_VERSION_1_3) && VK_HEADER_VERSION >= 235 + driver_priorities[vk::DriverId::eMesaNvk] = 2; +#endif + break; + } + + if (driver_priorities.count(old_driver.driverID)) { + old_priority = driver_priorities[old_driver.driverID]; + } + if (driver_priorities.count(new_driver.driverID)) { + new_priority = driver_priorities[new_driver.driverID]; + } + + if (new_priority < old_priority) { + auto r = std::remove(vk_instance.device_indices.begin(), vk_instance.device_indices.end(), *old_device); + vk_instance.device_indices.erase(r, vk_instance.device_indices.end()); + vk_instance.device_indices.push_back(i); + +#ifdef GGML_VULKAN_DEBUG + std::cerr << "Prioritize device " << i << " driver " << new_driver.driverName << " over device " << *old_device << " driver " << old_driver.driverName << std::endl; +#endif + } +#ifdef GGML_VULKAN_DEBUG + else { + std::cerr << "Prioritize device " << *old_device << " driver " << old_driver.driverName << " over device " << i << " driver " << new_driver.driverName << std::endl; + + } +#endif + } } } From f2b5764beb35583295e2475479c18f249b139b58 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Wed, 12 Jun 2024 03:18:16 +0200 Subject: [PATCH 20/37] Fix a typo and add Fedora 40 pacakge to install for Vulkan (#7794) [no ci] Fix "appropiate" to "appropriate" and add Fedora 40 packages to install to compile with Vulkan support --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ecb9d00db..8c065aace 100644 --- a/README.md +++ b/README.md @@ -576,7 +576,9 @@ Building the program with BLAS support may lead to some performance improvements vulkaninfo ``` - Alternatively your package manager might be able to provide the appropiate libraries. For example for Ubuntu 22.04 you can install `libvulkan-dev` instead. + Alternatively your package manager might be able to provide the appropriate libraries. + For example for Ubuntu 22.04 you can install `libvulkan-dev` instead. + For Fedora 40, you can install `vulkan-devel`, `glslc` and `glslang` packages. Then, build llama.cpp using the cmake command below: From dcf752707d96eb305f546526c7bc5d01f0831130 Mon Sep 17 00:00:00 2001 From: "Meng, Hengyu" Date: Wed, 12 Jun 2024 17:05:35 +0800 Subject: [PATCH 21/37] update intel docker oneapi-basekit to 2024.1.1-devel-ubuntu22.04 (#7894) In addition this reverts a workaround we had to do to workaround the upstream issue with expired intel GPG package keys in 2024.0.1-devel-ubuntu22.04 --- .devops/main-intel.Dockerfile | 10 +--------- .devops/server-intel.Dockerfile | 18 +----------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/.devops/main-intel.Dockerfile b/.devops/main-intel.Dockerfile index 7516c8313..b7992f47b 100644 --- a/.devops/main-intel.Dockerfile +++ b/.devops/main-intel.Dockerfile @@ -1,15 +1,7 @@ -ARG ONEAPI_VERSION=2024.0.1-devel-ubuntu22.04 +ARG ONEAPI_VERSION=2024.1.1-devel-ubuntu22.04 FROM intel/oneapi-basekit:$ONEAPI_VERSION as build -RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | tee /usr/share/keyrings/intel-oneapi-archive-keyring.gpg > /dev/null && \ - echo "deb [signed-by=/usr/share/keyrings/intel-oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main " | tee /etc/apt/sources.list.d/oneAPI.list && \ - chmod 644 /usr/share/keyrings/intel-oneapi-archive-keyring.gpg && \ - rm /etc/apt/sources.list.d/intel-graphics.list && \ - wget -O- https://repositories.intel.com/graphics/intel-graphics.key | gpg --dearmor | tee /usr/share/keyrings/intel-graphics.gpg > /dev/null && \ - echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc" | tee /etc/apt/sources.list.d/intel.gpu.jammy.list && \ - chmod 644 /usr/share/keyrings/intel-graphics.gpg - ARG LLAMA_SYCL_F16=OFF RUN apt-get update && \ apt-get install -y git diff --git a/.devops/server-intel.Dockerfile b/.devops/server-intel.Dockerfile index 13d00b737..c5adcb6da 100644 --- a/.devops/server-intel.Dockerfile +++ b/.devops/server-intel.Dockerfile @@ -1,15 +1,7 @@ -ARG ONEAPI_VERSION=2024.0.1-devel-ubuntu22.04 +ARG ONEAPI_VERSION=2024.1.1-devel-ubuntu22.04 FROM intel/oneapi-basekit:$ONEAPI_VERSION as build -RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | tee /usr/share/keyrings/intel-oneapi-archive-keyring.gpg > /dev/null && \ - echo "deb [signed-by=/usr/share/keyrings/intel-oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main " | tee /etc/apt/sources.list.d/oneAPI.list && \ - chmod 644 /usr/share/keyrings/intel-oneapi-archive-keyring.gpg && \ - rm /etc/apt/sources.list.d/intel-graphics.list && \ - wget -O- https://repositories.intel.com/graphics/intel-graphics.key | gpg --dearmor | tee /usr/share/keyrings/intel-graphics.gpg > /dev/null && \ - echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc" | tee /etc/apt/sources.list.d/intel.gpu.jammy.list && \ - chmod 644 /usr/share/keyrings/intel-graphics.gpg - ARG LLAMA_SYCL_F16=OFF RUN apt-get update && \ apt-get install -y git libcurl4-openssl-dev @@ -27,14 +19,6 @@ RUN if [ "${LLAMA_SYCL_F16}" = "ON" ]; then \ FROM intel/oneapi-basekit:$ONEAPI_VERSION as runtime -RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | tee /usr/share/keyrings/intel-oneapi-archive-keyring.gpg > /dev/null && \ - echo "deb [signed-by=/usr/share/keyrings/intel-oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main " | tee /etc/apt/sources.list.d/oneAPI.list && \ - chmod 644 /usr/share/keyrings/intel-oneapi-archive-keyring.gpg && \ - rm /etc/apt/sources.list.d/intel-graphics.list && \ - wget -O- https://repositories.intel.com/graphics/intel-graphics.key | gpg --dearmor | tee /usr/share/keyrings/intel-graphics.gpg > /dev/null && \ - echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc" | tee /etc/apt/sources.list.d/intel.gpu.jammy.list && \ - chmod 644 /usr/share/keyrings/intel-graphics.gpg - RUN apt-get update && \ apt-get install -y libcurl4-openssl-dev From 704a35b183748954013bd875bbbfdd9eaca14e62 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Wed, 12 Jun 2024 14:42:29 +0300 Subject: [PATCH 22/37] server : restore numeric prompts (#7883) --- examples/server/server.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index 80714fa58..919078f2b 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -147,7 +147,7 @@ struct server_slot { int32_t n_prompt_tokens = 0; int32_t n_prompt_tokens_processed = 0; - std::string prompt; + json prompt; // can be either a string, array of strings or array of token ids // when a task is submitted, we first tokenize the prompt and store it here std::vector prompt_tokens; @@ -822,8 +822,13 @@ struct server_context { continue; } + // skip the slot if it does not contains prompt + if (!slot.prompt.is_string()) { + continue; + } + // current slot's prompt - std::string slot_prompt = slot.prompt; + std::string slot_prompt = slot.prompt.get(); // length of the current slot's prompt int slot_prompt_len = slot_prompt.size(); @@ -957,12 +962,12 @@ struct server_context { return false; } - if (prompt->is_string()) { - slot.prompt = prompt->get(); - } else if (prompt->is_array() && prompt->size() == 1 && prompt->at(0).is_string()) { - slot.prompt = prompt->at(0).get(); + if ((prompt->is_string()) || + (prompt->is_array() && prompt->size() == 1 && prompt->at(0).is_string()) || + (prompt->is_array() && !prompt->empty() && prompt->at(0).is_number_integer())) { + slot.prompt = *prompt; } else { - send_error(task, "\"prompt\" must be a string or an array of strings", ERROR_TYPE_INVALID_REQUEST); + send_error(task, "\"prompt\" must be a string or an array of integers", ERROR_TYPE_INVALID_REQUEST); return false; } } From bfaa676b0841617d4ef3596e63aca6be1a8eb1b5 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Wed, 12 Jun 2024 15:24:20 +0300 Subject: [PATCH 23/37] ggml : improve ggml_is_contiguous logic (#7856) * ggml : improve ggml_is_contiguous logic ggml-ci * ggml : support more contiguous cases ggml-ci --- ggml.c | 75 +++++++++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/ggml.c b/ggml.c index 1fc77743b..5fb9e9a32 100644 --- a/ggml.c +++ b/ggml.c @@ -3212,35 +3212,42 @@ GGML_CALL bool ggml_is_transposed(const struct ggml_tensor * tensor) { return tensor->nb[0] > tensor->nb[1]; } -GGML_CALL bool ggml_is_contiguous(const struct ggml_tensor * tensor) { - static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function"); +static bool ggml_is_contiguous_n(const struct ggml_tensor * tensor, int n) { + size_t next_nb = ggml_type_size(tensor->type); + if (tensor->ne[0] != ggml_blck_size(tensor->type) && tensor->nb[0] != next_nb) { + return false; + } + next_nb *= tensor->ne[0]/ggml_blck_size(tensor->type); + for (int i = 1; i < GGML_MAX_DIMS; i++) { + if (tensor->ne[i] != 1) { + if (i > n) { + if (tensor->nb[i] != next_nb) { + return false; + } + next_nb *= tensor->ne[i]; + } else { + // this dimension does not need to be contiguous + next_nb = tensor->ne[i]*tensor->nb[i]; + } + } + } + return true; +} - return - tensor->nb[0] == ggml_type_size(tensor->type) && - tensor->nb[1] == (tensor->nb[0]*tensor->ne[0])/ggml_blck_size(tensor->type) && - tensor->nb[2] == tensor->nb[1]*tensor->ne[1] && - tensor->nb[3] == tensor->nb[2]*tensor->ne[2]; +GGML_CALL bool ggml_is_contiguous(const struct ggml_tensor * tensor) { + return ggml_is_contiguous_0(tensor); } GGML_CALL bool ggml_is_contiguous_0(const struct ggml_tensor * tensor) { - return ggml_is_contiguous(tensor); + return ggml_is_contiguous_n(tensor, 0); } GGML_CALL bool ggml_is_contiguous_1(const struct ggml_tensor * tensor) { - static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function"); - - return - tensor->nb[0] == ggml_type_size(tensor->type) && - tensor->nb[2] == tensor->nb[1]*tensor->ne[1] && - tensor->nb[3] == tensor->nb[2]*tensor->ne[2]; + return ggml_is_contiguous_n(tensor, 1); } GGML_CALL bool ggml_is_contiguous_2(const struct ggml_tensor * tensor) { - static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function"); - - return - tensor->nb[0] == ggml_type_size(tensor->type) && - tensor->nb[3] == tensor->nb[2]*tensor->ne[2]; + return ggml_is_contiguous_n(tensor, 2); } GGML_CALL bool ggml_is_permuted(const struct ggml_tensor * tensor) { @@ -3272,20 +3279,20 @@ bool ggml_are_same_shape(const struct ggml_tensor * t0, const struct ggml_tensor static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function"); return - (t0->ne[0] == t1->ne[0] ) && - (t0->ne[1] == t1->ne[1] ) && - (t0->ne[2] == t1->ne[2] ) && - (t0->ne[3] == t1->ne[3] ); + (t0->ne[0] == t1->ne[0]) && + (t0->ne[1] == t1->ne[1]) && + (t0->ne[2] == t1->ne[2]) && + (t0->ne[3] == t1->ne[3]); } bool ggml_are_same_stride(const struct ggml_tensor * t0, const struct ggml_tensor * t1) { static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function"); return - (t0->nb[0] == t1->nb[0] ) && - (t0->nb[1] == t1->nb[1] ) && - (t0->nb[2] == t1->nb[2] ) && - (t0->nb[3] == t1->nb[3] ); + (t0->nb[0] == t1->nb[0]) && + (t0->nb[1] == t1->nb[1]) && + (t0->nb[2] == t1->nb[2]) && + (t0->nb[3] == t1->nb[3]); } // check if t1 can be represented as a repeatition of t0 @@ -4078,32 +4085,26 @@ float ggml_get_f32_1d(const struct ggml_tensor * tensor, int i) { switch (tensor->type) { case GGML_TYPE_I8: { - GGML_ASSERT(tensor->nb[0] == sizeof(int8_t)); return ((int8_t *)(tensor->data))[i]; } case GGML_TYPE_I16: { - GGML_ASSERT(tensor->nb[0] == sizeof(int16_t)); return ((int16_t *)(tensor->data))[i]; } case GGML_TYPE_I32: { - GGML_ASSERT(tensor->nb[0] == sizeof(int32_t)); return ((int32_t *)(tensor->data))[i]; } case GGML_TYPE_F16: { - GGML_ASSERT(tensor->nb[0] == sizeof(ggml_fp16_t)); return GGML_FP16_TO_FP32(((ggml_fp16_t *)(tensor->data))[i]); } case GGML_TYPE_BF16: { - GGML_ASSERT(tensor->nb[0] == sizeof(ggml_bf16_t)); return GGML_BF16_TO_FP32(((ggml_bf16_t *)(tensor->data))[i]); } case GGML_TYPE_F32: { - GGML_ASSERT(tensor->nb[0] == sizeof(float)); return ((float *)(tensor->data))[i]; } default: @@ -4125,32 +4126,26 @@ void ggml_set_f32_1d(const struct ggml_tensor * tensor, int i, float value) { switch (tensor->type) { case GGML_TYPE_I8: { - GGML_ASSERT(tensor->nb[0] == sizeof(int8_t)); ((int8_t *)(tensor->data))[i] = value; } break; case GGML_TYPE_I16: { - GGML_ASSERT(tensor->nb[0] == sizeof(int16_t)); ((int16_t *)(tensor->data))[i] = value; } break; case GGML_TYPE_I32: { - GGML_ASSERT(tensor->nb[0] == sizeof(int32_t)); ((int32_t *)(tensor->data))[i] = value; } break; case GGML_TYPE_F16: { - GGML_ASSERT(tensor->nb[0] == sizeof(ggml_fp16_t)); ((ggml_fp16_t *)(tensor->data))[i] = GGML_FP32_TO_FP16(value); } break; case GGML_TYPE_BF16: { - GGML_ASSERT(tensor->nb[0] == sizeof(ggml_bf16_t)); ((ggml_bf16_t *)(tensor->data))[i] = GGML_FP32_TO_BF16(value); } break; case GGML_TYPE_F32: { - GGML_ASSERT(tensor->nb[0] == sizeof(float)); ((float *)(tensor->data))[i] = value; } break; default: @@ -7343,7 +7338,7 @@ struct ggml_tensor * ggml_add_rel_pos_inplace( return ggml_add_rel_pos_impl(ctx, a, pw, ph, true); } -// gmml_unary +// ggml_unary static struct ggml_tensor * ggml_unary_impl( struct ggml_context * ctx, From a9cae48003dfc4fe95b8f5c81682fc6e63425235 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Wed, 12 Jun 2024 16:00:22 +0300 Subject: [PATCH 24/37] tests : add non-cont unary tests (#7857) * tests : add non-cont unary tests * ggml : update unary asserts and "supports_op" ggml-ci --- ggml-cuda.cu | 2 +- ggml-cuda/unary.cu | 20 ++++++++ ggml-kompute.cpp | 2 +- ggml-metal.m | 2 +- ggml-sycl.cpp | 2 +- ggml-vulkan.cpp | 2 +- ggml.c | 97 ++++++++++++++++++-------------------- tests/test-backend-ops.cpp | 29 ++++++++---- 8 files changed, 90 insertions(+), 66 deletions(-) diff --git a/ggml-cuda.cu b/ggml-cuda.cu index af10f21a0..c6bc3f64c 100644 --- a/ggml-cuda.cu +++ b/ggml-cuda.cu @@ -2740,7 +2740,7 @@ GGML_CALL static bool ggml_backend_cuda_supports_op(ggml_backend_t backend, cons case GGML_UNARY_OP_HARDSWISH: case GGML_UNARY_OP_GELU_QUICK: case GGML_UNARY_OP_TANH: - return true; + return ggml_is_contiguous(op->src[0]); default: return false; } diff --git a/ggml-cuda/unary.cu b/ggml-cuda/unary.cu index ac03d5c6f..a5ff96320 100644 --- a/ggml-cuda/unary.cu +++ b/ggml-cuda/unary.cu @@ -148,6 +148,8 @@ void ggml_cuda_op_gelu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -160,6 +162,8 @@ void ggml_cuda_op_silu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -172,6 +176,8 @@ void ggml_cuda_op_gelu_quick(ggml_backend_cuda_context & ctx, ggml_tensor * dst) float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -184,6 +190,8 @@ void ggml_cuda_op_tanh(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -196,6 +204,8 @@ void ggml_cuda_op_relu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -208,6 +218,8 @@ void ggml_cuda_op_sigmoid(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -220,6 +232,8 @@ void ggml_cuda_op_hardsigmoid(ggml_backend_cuda_context & ctx, ggml_tensor * dst float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -232,6 +246,8 @@ void ggml_cuda_op_hardswish(ggml_backend_cuda_context & ctx, ggml_tensor * dst) float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -244,6 +260,8 @@ void ggml_cuda_op_leaky_relu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); @@ -259,6 +277,8 @@ void ggml_cuda_op_sqr(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { float * dst_d = (float *)dst->data; cudaStream_t stream = ctx.stream(); + GGML_ASSERT(ggml_is_contiguous(src0)); + GGML_ASSERT(src0->type == GGML_TYPE_F32); GGML_ASSERT( dst->type == GGML_TYPE_F32); diff --git a/ggml-kompute.cpp b/ggml-kompute.cpp index 5592741be..18c6f4a10 100644 --- a/ggml-kompute.cpp +++ b/ggml-kompute.cpp @@ -1340,7 +1340,7 @@ static bool ggml_vk_supports_op(const struct ggml_tensor * op) { case GGML_UNARY_OP_RELU: case GGML_UNARY_OP_GELU: case GGML_UNARY_OP_SILU: - return true; + return ggml_is_contiguous(op->src[0]); default: ; } diff --git a/ggml-metal.m b/ggml-metal.m index 946f11813..b5c287347 100644 --- a/ggml-metal.m +++ b/ggml-metal.m @@ -744,7 +744,7 @@ static bool ggml_metal_supports_op(const struct ggml_metal_context * ctx, const case GGML_UNARY_OP_GELU: case GGML_UNARY_OP_GELU_QUICK: case GGML_UNARY_OP_SILU: - return true; + return ggml_is_contiguous(op->src[0]); default: return false; } diff --git a/ggml-sycl.cpp b/ggml-sycl.cpp index 42fc0df20..e7d260bd4 100644 --- a/ggml-sycl.cpp +++ b/ggml-sycl.cpp @@ -17190,7 +17190,7 @@ GGML_CALL static bool ggml_backend_sycl_supports_op(ggml_backend_t backend, cons case GGML_UNARY_OP_HARDSWISH: case GGML_UNARY_OP_GELU_QUICK: case GGML_UNARY_OP_TANH: - return true; + return ggml_is_contiguous(op->src[0]); default: return false; } diff --git a/ggml-vulkan.cpp b/ggml-vulkan.cpp index 06ba23313..5b9280491 100644 --- a/ggml-vulkan.cpp +++ b/ggml-vulkan.cpp @@ -6439,7 +6439,7 @@ GGML_CALL static bool ggml_backend_vk_supports_op(ggml_backend_t backend, const case GGML_UNARY_OP_GELU: case GGML_UNARY_OP_SILU: case GGML_UNARY_OP_RELU: - return true; + return ggml_is_contiguous(op->src[0]); default: return false; } diff --git a/ggml.c b/ggml.c index 5fb9e9a32..2ea1d7677 100644 --- a/ggml.c +++ b/ggml.c @@ -7345,6 +7345,8 @@ static struct ggml_tensor * ggml_unary_impl( struct ggml_tensor * a, enum ggml_unary_op op, bool inplace) { + GGML_ASSERT(ggml_is_contiguous_1(a)); + bool is_node = false; if (!inplace && (a->grad)) { @@ -11009,6 +11011,8 @@ static void ggml_compute_forward_abs_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11018,9 +11022,6 @@ static void ggml_compute_forward_abs_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_abs_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11055,6 +11056,8 @@ static void ggml_compute_forward_sgn_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11064,9 +11067,6 @@ static void ggml_compute_forward_sgn_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_sgn_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11101,6 +11101,8 @@ static void ggml_compute_forward_neg_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11110,9 +11112,6 @@ static void ggml_compute_forward_neg_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_neg_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11147,6 +11146,8 @@ static void ggml_compute_forward_step_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11156,9 +11157,6 @@ static void ggml_compute_forward_step_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_step_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11193,6 +11191,8 @@ static void ggml_compute_forward_tanh_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11202,9 +11202,6 @@ static void ggml_compute_forward_tanh_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_tanh_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11239,6 +11236,8 @@ static void ggml_compute_forward_elu_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11248,9 +11247,6 @@ static void ggml_compute_forward_elu_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_elu_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11285,6 +11281,8 @@ static void ggml_compute_forward_relu_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11294,9 +11292,6 @@ static void ggml_compute_forward_relu_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_relu_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11331,6 +11326,8 @@ static void ggml_compute_forward_sigmoid_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11340,9 +11337,6 @@ static void ggml_compute_forward_sigmoid_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_sigmoid_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11376,9 +11370,9 @@ static void ggml_compute_forward_gelu_f32( const struct ggml_tensor * src0 = dst->src[0]; - GGML_ASSERT(ggml_is_contiguous_1(src0)); - GGML_ASSERT(ggml_is_contiguous_1(dst)); - GGML_ASSERT(ggml_are_same_shape(src0, dst)); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); + assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { return; @@ -11439,9 +11433,9 @@ static void ggml_compute_forward_gelu_quick_f32( const struct ggml_tensor * src0 = dst->src[0]; - GGML_ASSERT(ggml_is_contiguous_1(src0)); - GGML_ASSERT(ggml_is_contiguous_1(dst)); - GGML_ASSERT(ggml_are_same_shape(src0, dst)); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); + assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { return; @@ -11502,9 +11496,9 @@ static void ggml_compute_forward_silu_f32( const struct ggml_tensor * src0 = dst->src[0]; - GGML_ASSERT(ggml_is_contiguous_1(src0)); - GGML_ASSERT(ggml_is_contiguous_1(dst)); - GGML_ASSERT(ggml_are_same_shape(src0, dst)); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); + assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { return; @@ -11565,6 +11559,8 @@ static void ggml_compute_forward_leaky_relu_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11614,11 +11610,11 @@ static void ggml_compute_forward_silu_back_f32( const struct ggml_tensor * src0 = dst->src[0]; const struct ggml_tensor * grad = dst->src[1]; - GGML_ASSERT(ggml_is_contiguous_1(grad)); - GGML_ASSERT(ggml_is_contiguous_1(src0)); - GGML_ASSERT(ggml_is_contiguous_1(dst)); - GGML_ASSERT(ggml_are_same_shape(src0, dst)); - GGML_ASSERT(ggml_are_same_shape(src0, grad)); + assert(ggml_is_contiguous_1(grad)); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); + assert(ggml_are_same_shape(src0, dst)); + assert(ggml_are_same_shape(src0, grad)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { return; @@ -11680,6 +11676,8 @@ static void ggml_compute_forward_hardswish_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11689,9 +11687,6 @@ static void ggml_compute_forward_hardswish_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_hardswish_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -11723,6 +11718,8 @@ static void ggml_compute_forward_hardsigmoid_f32( const struct ggml_tensor * src0 = dst->src[0]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -11732,9 +11729,6 @@ static void ggml_compute_forward_hardsigmoid_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert(dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { ggml_vec_hardsigmoid_f32(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -16681,7 +16675,10 @@ static void ggml_compute_forward_map_unary_f32( const struct ggml_tensor * src0 = dst->src[0]; - GGML_ASSERT(ggml_are_same_shape(src0, dst)); + assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(dst)); + assert(ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { return; @@ -16690,9 +16687,6 @@ static void ggml_compute_forward_map_unary_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert( dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { fun(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), @@ -16730,6 +16724,9 @@ static void ggml_compute_forward_map_binary_f32( const struct ggml_tensor * src1 = dst->src[1]; assert(params->ith == 0); + assert(ggml_is_contiguous_1(src0)); + assert(ggml_is_contiguous_1(src1)); + assert(ggml_is_contiguous_1(dst)); assert(ggml_are_same_shape(src0, src1) && ggml_are_same_shape(src0, dst)); if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) { @@ -16739,10 +16736,6 @@ static void ggml_compute_forward_map_binary_f32( const int n = ggml_nrows(src0); const int nc = src0->ne[0]; - assert( dst->nb[0] == sizeof(float)); - assert(src0->nb[0] == sizeof(float)); - assert(src1->nb[0] == sizeof(float)); - for (int i = 0; i < n; i++) { fun(nc, (float *) ((char *) dst->data + i*( dst->nb[1])), diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp index ce406a8af..2b48e623e 100644 --- a/tests/test-backend-ops.cpp +++ b/tests/test-backend-ops.cpp @@ -642,20 +642,29 @@ struct test_case { struct test_unary : public test_case { const ggml_unary_op op; const ggml_type type; - const std::array ne; + const std::array ne_a; + int v; // view (1 : non-contiguous a) std::string vars() override { - return VARS_TO_STR2(type, ne); + return VARS_TO_STR3(type, ne_a, v); } test_unary(ggml_unary_op op, ggml_type type = GGML_TYPE_F32, - std::array ne = {128, 10, 10, 10}) - : op(op), type(type), ne(ne) {} + std::array ne_a = {128, 10, 10, 10}, + int v = 0) + : op(op), type(type), ne_a(ne_a), v(v) {} ggml_tensor * build_graph(ggml_context * ctx) override { - ggml_tensor * in = ggml_new_tensor(ctx, type, 4, ne.data()); - ggml_tensor * out = ggml_unary(ctx, in, op); + ggml_tensor * a; + if (v & 1) { + auto ne = ne_a; ne[0] *= 3; + a = ggml_new_tensor(ctx, type, 4, ne.data()); + a = ggml_view_4d(ctx, a, ne_a[0], ne_a[1], ne_a[2], ne_a[3], a->nb[1], a->nb[2], a->nb[3], 0); + } else { + a = ggml_new_tensor(ctx, type, 4, ne_a.data()); + } + ggml_tensor * out = ggml_unary(ctx, a, op); return out; } @@ -2016,9 +2025,11 @@ static bool test_backend(ggml_backend_t backend, test_mode mode, const char * op }; // unary ops - for (int op = 0; op < GGML_UNARY_OP_COUNT; op++) { - test_cases.emplace_back(new test_unary((ggml_unary_op) op)); - test_cases.emplace_back(new test_unary((ggml_unary_op) op, GGML_TYPE_F32, { 7, 13, 19, 23 })); + for (int v : {0, 1}) { + for (int op = 0; op < GGML_UNARY_OP_COUNT; op++) { + test_cases.emplace_back(new test_unary((ggml_unary_op) op, GGML_TYPE_F32, { 128, 10, 10, 10 }, v)); + test_cases.emplace_back(new test_unary((ggml_unary_op) op, GGML_TYPE_F32, { 7, 13, 19, 23 }, v)); + } } test_cases.emplace_back(new test_get_rows(GGML_TYPE_F32, 1, 8, 2, 1, false)); From 963552903f51043ee947a8deeaaa7ec00bc3f1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Wed, 12 Jun 2024 17:41:51 +0200 Subject: [PATCH 25/37] CUDA: fix broken oob check for FA vec f32 kernel (#7904) --- ggml-cuda/fattn-vec-f32.cuh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggml-cuda/fattn-vec-f32.cuh b/ggml-cuda/fattn-vec-f32.cuh index ddf0c8374..11a5e355f 100644 --- a/ggml-cuda/fattn-vec-f32.cuh +++ b/ggml-cuda/fattn-vec-f32.cuh @@ -149,7 +149,7 @@ static __global__ void flash_attn_vec_ext_f32( for (int i0 = 0; i0 < D/2; i0 += WARP_SIZE) { const int i = i0 + threadIdx.x; - Q_f2[j][i0/WARP_SIZE] = ncols <= 2 || ic0 + j ? Q_f2_j[i] : make_float2(0.0f, 0.0f); + Q_f2[j][i0/WARP_SIZE] = ncols <= 2 || ic0 + j < ne01 ? Q_f2_j[i] : make_float2(0.0f, 0.0f); Q_f2[j][i0/WARP_SIZE].x *= scale; Q_f2[j][i0/WARP_SIZE].y *= scale; } From 1c641e6aac5c18b964e7b32d9dbbb4bf5301d0d7 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Thu, 13 Jun 2024 00:41:52 +0100 Subject: [PATCH 26/37] =?UTF-8?q?`build`:=20rename=20main=20=E2=86=92=20ll?= =?UTF-8?q?ama-cli,=20server=20=E2=86=92=20llama-server,=20llava-cli=20?= =?UTF-8?q?=E2=86=92=20llama-llava-cli,=20etc...=20(#7809)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * `main`/`server`: rename to `llama` / `llama-server` for consistency w/ homebrew * server: update refs -> llama-server gitignore llama-server * server: simplify nix package * main: update refs -> llama fix examples/main ref * main/server: fix targets * update more names * Update build.yml * rm accidentally checked in bins * update straggling refs * Update .gitignore * Update server-llm.sh * main: target name -> llama-cli * Prefix all example bins w/ llama- * fix main refs * rename {main->llama}-cmake-pkg binary * prefix more cmake targets w/ llama- * add/fix gbnf-validator subfolder to cmake * sort cmake example subdirs * rm bin files * fix llama-lookup-* Makefile rules * gitignore /llama-* * rename Dockerfiles * rename llama|main -> llama-cli; consistent RPM bin prefixes * fix some missing -cli suffixes * rename dockerfile w/ llama-cli * rename(make): llama-baby-llama * update dockerfile refs * more llama-cli(.exe) * fix test-eval-callback * rename: llama-cli-cmake-pkg(.exe) * address gbnf-validator unused fread warning (switched to C++ / ifstream) * add two missing llama- prefixes * Updating docs for eval-callback binary to use new `llama-` prefix. * Updating a few lingering doc references for rename of main to llama-cli * Updating `run-with-preset.py` to use new binary names. Updating docs around `perplexity` binary rename. * Updating documentation references for lookup-merge and export-lora * Updating two small `main` references missed earlier in the finetune docs. * Update apps.nix * update grammar/README.md w/ new llama-* names * update llama-rpc-server bin name + doc * Revert "update llama-rpc-server bin name + doc" This reverts commit e474ef1df481fd8936cd7d098e3065d7de378930. * add hot topic notice to README.md * Update README.md * Update README.md * rename gguf-split & quantize bins refs in **/tests.sh --------- Co-authored-by: HanClinto --- .devops/cloud-v-pipeline | 2 +- ...a.Dockerfile => llama-cli-cuda.Dockerfile} | 6 +- ....Dockerfile => llama-cli-intel.Dockerfile} | 6 +- ...m.Dockerfile => llama-cli-rocm.Dockerfile} | 4 +- ...Dockerfile => llama-cli-vulkan.Dockerfile} | 6 +- .../{main.Dockerfile => llama-cli.Dockerfile} | 6 +- .devops/llama-cpp-clblast.srpm.spec | 14 +- .devops/llama-cpp-cuda.srpm.spec | 14 +- .devops/llama-cpp.srpm.spec | 14 +- ...ockerfile => llama-server-cuda.Dockerfile} | 6 +- ...ckerfile => llama-server-intel.Dockerfile} | 6 +- ...ockerfile => llama-server-rocm.Dockerfile} | 4 +- ...kerfile => llama-server-vulkan.Dockerfile} | 6 +- ...ver.Dockerfile => llama-server.Dockerfile} | 6 +- .devops/nix/apps.nix | 6 +- .devops/nix/package.nix | 4 +- .devops/tools.sh | 10 +- .dockerignore | 4 +- .github/ISSUE_TEMPLATE/01-bug-low.yml | 2 +- .github/ISSUE_TEMPLATE/02-bug-medium.yml | 2 +- .github/ISSUE_TEMPLATE/03-bug-high.yml | 2 +- .github/ISSUE_TEMPLATE/04-bug-critical.yml | 2 +- .github/workflows/bench.yml | 2 +- .github/workflows/build.yml | 10 +- .github/workflows/docker.yml | 16 +- .github/workflows/server.yml | 4 +- .gitignore | 43 +--- Makefile | 138 +++++++---- README-sycl.md | 18 +- README.md | 33 +-- ci/run.sh | 224 +++++++++--------- docs/HOWTO-add-model.md | 2 +- docs/token_generation_performance_tips.md | 4 +- examples/CMakeLists.txt | 47 ++-- examples/Miku.sh | 2 +- examples/baby-llama/CMakeLists.txt | 2 +- examples/base-translate.sh | 2 +- examples/batched-bench/CMakeLists.txt | 2 +- examples/batched-bench/README.md | 8 +- examples/batched.swift/Makefile | 6 +- examples/batched.swift/Package.swift | 4 +- examples/batched.swift/README.md | 2 +- examples/batched/CMakeLists.txt | 2 +- examples/batched/README.md | 2 +- examples/benchmark/CMakeLists.txt | 2 +- examples/chat-13B.sh | 2 +- examples/chat-persistent.sh | 10 +- examples/chat-vicuna.sh | 2 +- examples/chat.sh | 2 +- .../convert-llama2c-to-ggml/CMakeLists.txt | 2 +- examples/convert-llama2c-to-ggml/README.md | 6 +- examples/embedding/CMakeLists.txt | 2 +- examples/embedding/README.md | 4 +- examples/eval-callback/CMakeLists.txt | 4 +- examples/eval-callback/README.md | 2 +- examples/export-lora/CMakeLists.txt | 2 +- examples/export-lora/README.md | 4 +- examples/finetune/CMakeLists.txt | 2 +- examples/finetune/README.md | 12 +- examples/finetune/finetune.sh | 2 +- examples/gbnf-validator/CMakeLists.txt | 4 +- examples/gbnf-validator/gbnf-validator.cpp | 36 ++- examples/gguf-split/CMakeLists.txt | 2 +- examples/gguf-split/tests.sh | 4 +- examples/gguf/CMakeLists.txt | 2 +- examples/gritlm/CMakeLists.txt | 2 +- examples/gritlm/README.md | 2 +- examples/imatrix/CMakeLists.txt | 2 +- examples/imatrix/README.md | 6 +- examples/infill/CMakeLists.txt | 2 +- examples/infill/README.md | 2 +- examples/jeopardy/jeopardy.sh | 2 +- examples/json-schema-pydantic-example.py | 2 +- examples/json_schema_to_grammar.py | 2 +- examples/llama-bench/README.md | 2 +- examples/llava/CMakeLists.txt | 11 +- examples/llava/MobileVLM-README.md | 18 +- examples/llava/README.md | 10 +- examples/llava/android/adb_run.sh | 2 +- examples/lookahead/CMakeLists.txt | 2 +- examples/lookup/CMakeLists.txt | 8 +- examples/lookup/lookup-merge.cpp | 8 +- examples/main-cmake-pkg/CMakeLists.txt | 8 +- examples/main-cmake-pkg/README.md | 4 +- examples/main/CMakeLists.txt | 2 +- examples/main/README.md | 24 +- examples/parallel/CMakeLists.txt | 2 +- examples/passkey/CMakeLists.txt | 2 +- examples/passkey/README.md | 2 +- examples/perplexity/CMakeLists.txt | 2 +- examples/perplexity/perplexity.cpp | 2 +- examples/quantize-stats/CMakeLists.txt | 2 +- examples/quantize/CMakeLists.txt | 2 +- examples/quantize/tests.sh | 6 +- examples/reason-act.sh | 2 +- examples/retrieval/CMakeLists.txt | 2 +- examples/retrieval/README.md | 2 +- examples/rpc/README.md | 2 +- examples/save-load-state/CMakeLists.txt | 2 +- examples/server-llama2-13B.sh | 2 +- examples/server/CMakeLists.txt | 2 +- examples/server/README.md | 22 +- examples/server/bench/README.md | 2 +- examples/server/bench/bench.py | 2 +- examples/server/public_simplechat/readme.md | 4 +- examples/server/tests/README.md | 8 +- examples/server/tests/features/steps/steps.py | 4 +- examples/simple/CMakeLists.txt | 2 +- examples/speculative/CMakeLists.txt | 2 +- examples/sycl/CMakeLists.txt | 2 +- examples/sycl/README.md | 6 +- examples/sycl/run-llama2.sh | 8 +- examples/tokenize/CMakeLists.txt | 2 +- .../train-text-from-scratch/CMakeLists.txt | 2 +- examples/train-text-from-scratch/README.md | 4 +- flake.nix | 2 +- grammars/README.md | 14 +- pocs/vdot/CMakeLists.txt | 4 +- scripts/get-hellaswag.sh | 2 +- scripts/get-wikitext-103.sh | 2 +- scripts/get-wikitext-2.sh | 2 +- scripts/get-winogrande.sh | 2 +- scripts/hf.sh | 6 +- scripts/pod-llama.sh | 56 ++--- scripts/qnt-all.sh | 2 +- scripts/run-all-ppl.sh | 2 +- scripts/run-with-preset.py | 16 +- scripts/server-llm.sh | 8 +- 128 files changed, 578 insertions(+), 578 deletions(-) rename .devops/{main-cuda.Dockerfile => llama-cli-cuda.Dockerfile} (88%) rename .devops/{main-intel.Dockerfile => llama-cli-intel.Dockerfile} (78%) rename .devops/{main-rocm.Dockerfile => llama-cli-rocm.Dockerfile} (94%) rename .devops/{main-vulkan.Dockerfile => llama-cli-vulkan.Dockerfile} (81%) rename .devops/{main.Dockerfile => llama-cli.Dockerfile} (72%) rename .devops/{server-cuda.Dockerfile => llama-server-cuda.Dockerfile} (88%) rename .devops/{server-intel.Dockerfile => llama-server-intel.Dockerfile} (80%) rename .devops/{server-rocm.Dockerfile => llama-server-rocm.Dockerfile} (94%) rename .devops/{server-vulkan.Dockerfile => llama-server-vulkan.Dockerfile} (82%) rename .devops/{server.Dockerfile => llama-server.Dockerfile} (74%) diff --git a/.devops/cloud-v-pipeline b/.devops/cloud-v-pipeline index f3a4944f8..af8c0cea6 100644 --- a/.devops/cloud-v-pipeline +++ b/.devops/cloud-v-pipeline @@ -15,7 +15,7 @@ node('x86_runner1'){ // Running on x86 runner containing latest vecto stage('Running llama.cpp'){ sh'''#!/bin/bash module load gnu-bin2/0.1 # loading latest versions of vector qemu and vector gcc - qemu-riscv64 -L /softwares/gnu-bin2/sysroot -cpu rv64,v=true,vlen=256,elen=64,vext_spec=v1.0 ./main -m /home/alitariq/codellama-7b.Q4_K_M.gguf -p "Anything" -n 9 > llama_log.txt # Running llama.cpp on vector qemu-riscv64 + qemu-riscv64 -L /softwares/gnu-bin2/sysroot -cpu rv64,v=true,vlen=256,elen=64,vext_spec=v1.0 ./llama-cli -m /home/alitariq/codellama-7b.Q4_K_M.gguf -p "Anything" -n 9 > llama_log.txt # Running llama.cpp on vector qemu-riscv64 cat llama_log.txt # Printing results ''' } diff --git a/.devops/main-cuda.Dockerfile b/.devops/llama-cli-cuda.Dockerfile similarity index 88% rename from .devops/main-cuda.Dockerfile rename to .devops/llama-cli-cuda.Dockerfile index 2aec4a85d..d5ce538f6 100644 --- a/.devops/main-cuda.Dockerfile +++ b/.devops/llama-cli-cuda.Dockerfile @@ -23,13 +23,13 @@ ENV CUDA_DOCKER_ARCH=${CUDA_DOCKER_ARCH} # Enable CUDA ENV LLAMA_CUDA=1 -RUN make -j$(nproc) main +RUN make -j$(nproc) llama-cli FROM ${BASE_CUDA_RUN_CONTAINER} as runtime RUN apt-get update && \ apt-get install -y libgomp1 -COPY --from=build /app/main /main +COPY --from=build /app/llama-cli /llama-cli -ENTRYPOINT [ "/main" ] +ENTRYPOINT [ "/llama-cli" ] diff --git a/.devops/main-intel.Dockerfile b/.devops/llama-cli-intel.Dockerfile similarity index 78% rename from .devops/main-intel.Dockerfile rename to .devops/llama-cli-intel.Dockerfile index b7992f47b..6789e17af 100644 --- a/.devops/main-intel.Dockerfile +++ b/.devops/llama-cli-intel.Dockerfile @@ -15,12 +15,12 @@ RUN if [ "${LLAMA_SYCL_F16}" = "ON" ]; then \ export OPT_SYCL_F16="-DLLAMA_SYCL_F16=ON"; \ fi && \ cmake -B build -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx ${OPT_SYCL_F16} && \ - cmake --build build --config Release --target main + cmake --build build --config Release --target llama-cli FROM intel/oneapi-basekit:$ONEAPI_VERSION as runtime -COPY --from=build /app/build/bin/main /main +COPY --from=build /app/build/bin/llama-cli /llama-cli ENV LC_ALL=C.utf8 -ENTRYPOINT [ "/main" ] +ENTRYPOINT [ "/llama-cli" ] diff --git a/.devops/main-rocm.Dockerfile b/.devops/llama-cli-rocm.Dockerfile similarity index 94% rename from .devops/main-rocm.Dockerfile rename to .devops/llama-cli-rocm.Dockerfile index dcaeb3e72..7e8a6f0fa 100644 --- a/.devops/main-rocm.Dockerfile +++ b/.devops/llama-cli-rocm.Dockerfile @@ -40,6 +40,6 @@ ENV LLAMA_HIPBLAS=1 ENV CC=/opt/rocm/llvm/bin/clang ENV CXX=/opt/rocm/llvm/bin/clang++ -RUN make -j$(nproc) main +RUN make -j$(nproc) llama-cli -ENTRYPOINT [ "/app/main" ] +ENTRYPOINT [ "/app/llama-cli" ] diff --git a/.devops/main-vulkan.Dockerfile b/.devops/llama-cli-vulkan.Dockerfile similarity index 81% rename from .devops/main-vulkan.Dockerfile rename to .devops/llama-cli-vulkan.Dockerfile index 1bdb52803..7a0abe71f 100644 --- a/.devops/main-vulkan.Dockerfile +++ b/.devops/llama-cli-vulkan.Dockerfile @@ -15,13 +15,13 @@ RUN wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | apt-key WORKDIR /app COPY . . RUN cmake -B build -DLLAMA_VULKAN=1 && \ - cmake --build build --config Release --target main + cmake --build build --config Release --target llama-cli # Clean up WORKDIR / -RUN cp /app/build/bin/main /main && \ +RUN cp /app/build/bin/llama-cli /llama-cli && \ rm -rf /app ENV LC_ALL=C.utf8 -ENTRYPOINT [ "/main" ] +ENTRYPOINT [ "/llama-cli" ] diff --git a/.devops/main.Dockerfile b/.devops/llama-cli.Dockerfile similarity index 72% rename from .devops/main.Dockerfile rename to .devops/llama-cli.Dockerfile index d2514c4ba..38382bfc9 100644 --- a/.devops/main.Dockerfile +++ b/.devops/llama-cli.Dockerfile @@ -9,15 +9,15 @@ WORKDIR /app COPY . . -RUN make -j$(nproc) main +RUN make -j$(nproc) llama-cli FROM ubuntu:$UBUNTU_VERSION as runtime RUN apt-get update && \ apt-get install -y libgomp1 -COPY --from=build /app/main /main +COPY --from=build /app/llama-cli /llama-cli ENV LC_ALL=C.utf8 -ENTRYPOINT [ "/main" ] +ENTRYPOINT [ "/llama-cli" ] diff --git a/.devops/llama-cpp-clblast.srpm.spec b/.devops/llama-cpp-clblast.srpm.spec index 774f63ddd..013952191 100644 --- a/.devops/llama-cpp-clblast.srpm.spec +++ b/.devops/llama-cpp-clblast.srpm.spec @@ -36,9 +36,9 @@ make -j LLAMA_CLBLAST=1 %install mkdir -p %{buildroot}%{_bindir}/ -cp -p main %{buildroot}%{_bindir}/llamaclblast -cp -p server %{buildroot}%{_bindir}/llamaclblastserver -cp -p simple %{buildroot}%{_bindir}/llamaclblastsimple +cp -p llama-cli %{buildroot}%{_bindir}/llama-clblast-cli +cp -p llama-server %{buildroot}%{_bindir}/llama-clblast-server +cp -p llama-simple %{buildroot}%{_bindir}/llama-clblast-simple mkdir -p %{buildroot}/usr/lib/systemd/system %{__cat} < %{buildroot}/usr/lib/systemd/system/llamaclblast.service @@ -49,7 +49,7 @@ After=syslog.target network.target local-fs.target remote-fs.target nss-lookup.t [Service] Type=simple EnvironmentFile=/etc/sysconfig/llama -ExecStart=/usr/bin/llamaclblastserver $LLAMA_ARGS +ExecStart=/usr/bin/llama-clblast-server $LLAMA_ARGS ExecReload=/bin/kill -s HUP $MAINPID Restart=never @@ -67,9 +67,9 @@ rm -rf %{buildroot} rm -rf %{_builddir}/* %files -%{_bindir}/llamaclblast -%{_bindir}/llamaclblastserver -%{_bindir}/llamaclblastsimple +%{_bindir}/llama-clblast-cli +%{_bindir}/llama-clblast-server +%{_bindir}/llama-clblast-simple /usr/lib/systemd/system/llamaclblast.service %config /etc/sysconfig/llama diff --git a/.devops/llama-cpp-cuda.srpm.spec b/.devops/llama-cpp-cuda.srpm.spec index ba9cb7cbb..cbdf43626 100644 --- a/.devops/llama-cpp-cuda.srpm.spec +++ b/.devops/llama-cpp-cuda.srpm.spec @@ -36,9 +36,9 @@ make -j LLAMA_CUDA=1 %install mkdir -p %{buildroot}%{_bindir}/ -cp -p main %{buildroot}%{_bindir}/llamacppcuda -cp -p server %{buildroot}%{_bindir}/llamacppcudaserver -cp -p simple %{buildroot}%{_bindir}/llamacppcudasimple +cp -p llama-cli %{buildroot}%{_bindir}/llama-cuda-cli +cp -p llama-server %{buildroot}%{_bindir}/llama-cuda-server +cp -p llama-simple %{buildroot}%{_bindir}/llama-cuda-simple mkdir -p %{buildroot}/usr/lib/systemd/system %{__cat} < %{buildroot}/usr/lib/systemd/system/llamacuda.service @@ -49,7 +49,7 @@ After=syslog.target network.target local-fs.target remote-fs.target nss-lookup.t [Service] Type=simple EnvironmentFile=/etc/sysconfig/llama -ExecStart=/usr/bin/llamacppcudaserver $LLAMA_ARGS +ExecStart=/usr/bin/llama-cuda-server $LLAMA_ARGS ExecReload=/bin/kill -s HUP $MAINPID Restart=never @@ -67,9 +67,9 @@ rm -rf %{buildroot} rm -rf %{_builddir}/* %files -%{_bindir}/llamacppcuda -%{_bindir}/llamacppcudaserver -%{_bindir}/llamacppcudasimple +%{_bindir}/llama-cuda-cli +%{_bindir}/llama-cuda-server +%{_bindir}/llama-cuda-simple /usr/lib/systemd/system/llamacuda.service %config /etc/sysconfig/llama diff --git a/.devops/llama-cpp.srpm.spec b/.devops/llama-cpp.srpm.spec index 1d9e4f425..4d5560089 100644 --- a/.devops/llama-cpp.srpm.spec +++ b/.devops/llama-cpp.srpm.spec @@ -38,9 +38,9 @@ make -j %install mkdir -p %{buildroot}%{_bindir}/ -cp -p main %{buildroot}%{_bindir}/llama -cp -p server %{buildroot}%{_bindir}/llamaserver -cp -p simple %{buildroot}%{_bindir}/llamasimple +cp -p llama-cli %{buildroot}%{_bindir}/llama-cli +cp -p llama-server %{buildroot}%{_bindir}/llama-server +cp -p llama-simple %{buildroot}%{_bindir}/llama-simple mkdir -p %{buildroot}/usr/lib/systemd/system %{__cat} < %{buildroot}/usr/lib/systemd/system/llama.service @@ -51,7 +51,7 @@ After=syslog.target network.target local-fs.target remote-fs.target nss-lookup.t [Service] Type=simple EnvironmentFile=/etc/sysconfig/llama -ExecStart=/usr/bin/llamaserver $LLAMA_ARGS +ExecStart=/usr/bin/llama-server $LLAMA_ARGS ExecReload=/bin/kill -s HUP $MAINPID Restart=never @@ -69,9 +69,9 @@ rm -rf %{buildroot} rm -rf %{_builddir}/* %files -%{_bindir}/llama -%{_bindir}/llamaserver -%{_bindir}/llamasimple +%{_bindir}/llama-cli +%{_bindir}/llama-server +%{_bindir}/llama-simple /usr/lib/systemd/system/llama.service %config /etc/sysconfig/llama diff --git a/.devops/server-cuda.Dockerfile b/.devops/llama-server-cuda.Dockerfile similarity index 88% rename from .devops/server-cuda.Dockerfile rename to .devops/llama-server-cuda.Dockerfile index 4e9747b82..0010ffd4c 100644 --- a/.devops/server-cuda.Dockerfile +++ b/.devops/llama-server-cuda.Dockerfile @@ -25,13 +25,13 @@ ENV LLAMA_CUDA=1 # Enable cURL ENV LLAMA_CURL=1 -RUN make -j$(nproc) server +RUN make -j$(nproc) llama-server FROM ${BASE_CUDA_RUN_CONTAINER} as runtime RUN apt-get update && \ apt-get install -y libcurl4-openssl-dev libgomp1 -COPY --from=build /app/server /server +COPY --from=build /app/llama-server /llama-server -ENTRYPOINT [ "/server" ] +ENTRYPOINT [ "/llama-server" ] diff --git a/.devops/server-intel.Dockerfile b/.devops/llama-server-intel.Dockerfile similarity index 80% rename from .devops/server-intel.Dockerfile rename to .devops/llama-server-intel.Dockerfile index c5adcb6da..cec436452 100644 --- a/.devops/server-intel.Dockerfile +++ b/.devops/llama-server-intel.Dockerfile @@ -15,15 +15,15 @@ RUN if [ "${LLAMA_SYCL_F16}" = "ON" ]; then \ export OPT_SYCL_F16="-DLLAMA_SYCL_F16=ON"; \ fi && \ cmake -B build -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_CURL=ON ${OPT_SYCL_F16} && \ - cmake --build build --config Release --target server + cmake --build build --config Release --target llama-server FROM intel/oneapi-basekit:$ONEAPI_VERSION as runtime RUN apt-get update && \ apt-get install -y libcurl4-openssl-dev -COPY --from=build /app/build/bin/server /server +COPY --from=build /app/build/bin/llama-server /llama-server ENV LC_ALL=C.utf8 -ENTRYPOINT [ "/server" ] +ENTRYPOINT [ "/llama-server" ] diff --git a/.devops/server-rocm.Dockerfile b/.devops/llama-server-rocm.Dockerfile similarity index 94% rename from .devops/server-rocm.Dockerfile rename to .devops/llama-server-rocm.Dockerfile index a6b76dee8..f88cf20e5 100644 --- a/.devops/server-rocm.Dockerfile +++ b/.devops/llama-server-rocm.Dockerfile @@ -45,6 +45,6 @@ ENV LLAMA_CURL=1 RUN apt-get update && \ apt-get install -y libcurl4-openssl-dev -RUN make -j$(nproc) +RUN make -j$(nproc) llama-server -ENTRYPOINT [ "/app/server" ] +ENTRYPOINT [ "/app/llama-server" ] diff --git a/.devops/server-vulkan.Dockerfile b/.devops/llama-server-vulkan.Dockerfile similarity index 82% rename from .devops/server-vulkan.Dockerfile rename to .devops/llama-server-vulkan.Dockerfile index 6e757e171..b0fa0b8e6 100644 --- a/.devops/server-vulkan.Dockerfile +++ b/.devops/llama-server-vulkan.Dockerfile @@ -19,13 +19,13 @@ RUN apt-get update && \ WORKDIR /app COPY . . RUN cmake -B build -DLLAMA_VULKAN=1 -DLLAMA_CURL=1 && \ - cmake --build build --config Release --target server + cmake --build build --config Release --target llama-server # Clean up WORKDIR / -RUN cp /app/build/bin/server /server && \ +RUN cp /app/build/bin/llama-server /llama-server && \ rm -rf /app ENV LC_ALL=C.utf8 -ENTRYPOINT [ "/server" ] +ENTRYPOINT [ "/llama-server" ] diff --git a/.devops/server.Dockerfile b/.devops/llama-server.Dockerfile similarity index 74% rename from .devops/server.Dockerfile rename to .devops/llama-server.Dockerfile index bee63b966..aa93369be 100644 --- a/.devops/server.Dockerfile +++ b/.devops/llama-server.Dockerfile @@ -11,15 +11,15 @@ COPY . . ENV LLAMA_CURL=1 -RUN make -j$(nproc) server +RUN make -j$(nproc) llama-server FROM ubuntu:$UBUNTU_VERSION as runtime RUN apt-get update && \ apt-get install -y libcurl4-openssl-dev libgomp1 -COPY --from=build /app/server /server +COPY --from=build /app/llama-server /llama-server ENV LC_ALL=C.utf8 -ENTRYPOINT [ "/server" ] +ENTRYPOINT [ "/llama-server" ] diff --git a/.devops/nix/apps.nix b/.devops/nix/apps.nix index b8a12cc0a..897fce4d3 100644 --- a/.devops/nix/apps.nix +++ b/.devops/nix/apps.nix @@ -6,11 +6,11 @@ let inherit (config.packages) default; binaries = [ - "llama" + "llama-cli" "llama-embedding" "llama-server" - "quantize" - "train-text-from-scratch" + "llama-quantize" + "llama-train-text-from-scratch" ]; mkApp = name: { type = "app"; diff --git a/.devops/nix/package.nix b/.devops/nix/package.nix index e8d5b0bd9..87bb3a20f 100644 --- a/.devops/nix/package.nix +++ b/.devops/nix/package.nix @@ -243,8 +243,6 @@ effectiveStdenv.mkDerivation ( # TODO(SomeoneSerge): It's better to add proper install targets at the CMake level, # if they haven't been added yet. postInstall = '' - mv $out/bin/main${executableSuffix} $out/bin/llama${executableSuffix} - mv $out/bin/server${executableSuffix} $out/bin/llama-server${executableSuffix} mkdir -p $out/include cp $src/llama.h $out/include/ ''; @@ -294,7 +292,7 @@ effectiveStdenv.mkDerivation ( license = lib.licenses.mit; # Accommodates `nix run` and `lib.getExe` - mainProgram = "llama"; + mainProgram = "llama-cli"; # These people might respond, on the best effort basis, if you ping them # in case of Nix-specific regressions or for reviewing Nix-specific PRs. diff --git a/.devops/tools.sh b/.devops/tools.sh index 97424c3aa..335382f69 100755 --- a/.devops/tools.sh +++ b/.devops/tools.sh @@ -10,11 +10,11 @@ shift if [[ "$arg1" == '--convert' || "$arg1" == '-c' ]]; then python3 ./convert-hf-to-gguf.py "$@" elif [[ "$arg1" == '--quantize' || "$arg1" == '-q' ]]; then - ./quantize "$@" + ./llama-quantize "$@" elif [[ "$arg1" == '--run' || "$arg1" == '-r' ]]; then - ./main "$@" + ./llama-cli "$@" elif [[ "$arg1" == '--finetune' || "$arg1" == '-f' ]]; then - ./finetune "$@" + ./llama-finetune "$@" elif [[ "$arg1" == '--all-in-one' || "$arg1" == '-a' ]]; then echo "Converting PTH to GGML..." for i in `ls $1/$2/ggml-model-f16.bin*`; do @@ -22,11 +22,11 @@ elif [[ "$arg1" == '--all-in-one' || "$arg1" == '-a' ]]; then echo "Skip model quantization, it already exists: ${i/f16/q4_0}" else echo "Converting PTH to GGML: $i into ${i/f16/q4_0}..." - ./quantize "$i" "${i/f16/q4_0}" q4_0 + ./llama-quantize "$i" "${i/f16/q4_0}" q4_0 fi done elif [[ "$arg1" == '--server' || "$arg1" == '-s' ]]; then - ./server "$@" + ./llama-server "$@" else echo "Unknown command: $arg1" echo "Available commands: " diff --git a/.dockerignore b/.dockerignore index 633bbc3a9..8916e2a66 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,8 +12,8 @@ build*/ models/* -/main -/quantize +/llama-cli +/llama-quantize arm_neon.h compile_commands.json diff --git a/.github/ISSUE_TEMPLATE/01-bug-low.yml b/.github/ISSUE_TEMPLATE/01-bug-low.yml index bfb9d9a06..54785854f 100644 --- a/.github/ISSUE_TEMPLATE/01-bug-low.yml +++ b/.github/ISSUE_TEMPLATE/01-bug-low.yml @@ -24,7 +24,7 @@ body: label: Name and Version description: Which executable and which version of our software are you running? (use `--version` to get a version string) placeholder: | - $./main --version + $./llama-cli --version version: 2999 (42b4109e) built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu validations: diff --git a/.github/ISSUE_TEMPLATE/02-bug-medium.yml b/.github/ISSUE_TEMPLATE/02-bug-medium.yml index e8297eea0..a6285c6f0 100644 --- a/.github/ISSUE_TEMPLATE/02-bug-medium.yml +++ b/.github/ISSUE_TEMPLATE/02-bug-medium.yml @@ -24,7 +24,7 @@ body: label: Name and Version description: Which executable and which version of our software are you running? (use `--version` to get a version string) placeholder: | - $./main --version + $./llama-cli --version version: 2999 (42b4109e) built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu validations: diff --git a/.github/ISSUE_TEMPLATE/03-bug-high.yml b/.github/ISSUE_TEMPLATE/03-bug-high.yml index 3c9d50d16..ff816b937 100644 --- a/.github/ISSUE_TEMPLATE/03-bug-high.yml +++ b/.github/ISSUE_TEMPLATE/03-bug-high.yml @@ -24,7 +24,7 @@ body: label: Name and Version description: Which executable and which version of our software are you running? (use `--version` to get a version string) placeholder: | - $./main --version + $./llama-cli --version version: 2999 (42b4109e) built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu validations: diff --git a/.github/ISSUE_TEMPLATE/04-bug-critical.yml b/.github/ISSUE_TEMPLATE/04-bug-critical.yml index d089d5fa1..7af42a80b 100644 --- a/.github/ISSUE_TEMPLATE/04-bug-critical.yml +++ b/.github/ISSUE_TEMPLATE/04-bug-critical.yml @@ -24,7 +24,7 @@ body: label: Name and Version description: Which executable and which version of our software are you running? (use `--version` to get a version string) placeholder: | - $./main --version + $./llama-cli --version version: 2999 (42b4109e) built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu validations: diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index de0d994c8..88ab4844e 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -119,7 +119,7 @@ jobs: -DLLAMA_FATAL_WARNINGS=OFF \ -DLLAMA_ALL_WARNINGS=OFF \ -DCMAKE_BUILD_TYPE=Release; - cmake --build build --config Release -j $(nproc) --target server + cmake --build build --config Release -j $(nproc) --target llama-server - name: Download the dataset id: download_dataset diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c04cfc29..81ce770cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -103,12 +103,10 @@ jobs: id: cmake_build run: | sysctl -a - mkdir build - cd build # Metal is disabled due to intermittent failures with Github runners not having a GPU: # https://github.com/ggerganov/llama.cpp/actions/runs/8635935781/job/23674807267#step:5:2313 - cmake -DLLAMA_FATAL_WARNINGS=ON -DLLAMA_METAL=OFF -DLLAMA_CURL=ON .. - cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) + cmake -B build -DLLAMA_FATAL_WARNINGS=ON -DLLAMA_METAL=OFF -DLLAMA_CURL=ON + cmake --build build --config Release -j $(sysctl -n hw.logicalcpu) - name: Test id: cmake_test @@ -241,8 +239,8 @@ jobs: wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories260K/tok512.bin echo "Fetch llama2c model" wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories260K/stories260K.bin - ./bin/convert-llama2c-to-ggml --copy-vocab-from-model ./tok512.bin --llama2c-model stories260K.bin --llama2c-output-model stories260K.gguf - ./bin/main -m stories260K.gguf -p "One day, Lily met a Shoggoth" -n 500 -c 256 + ./bin/llama-convert-llama2c-to-ggml --copy-vocab-from-model ./tok512.bin --llama2c-model stories260K.bin --llama2c-output-model stories260K.gguf + ./bin/llama-cli -m stories260K.gguf -p "One day, Lily met a Shoggoth" -n 500 -c 256 - name: Determine tag name id: tag diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 9b03d19bc..6244b4812 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,20 +30,20 @@ jobs: strategy: matrix: config: - - { tag: "light", dockerfile: ".devops/main.Dockerfile", platforms: "linux/amd64,linux/arm64" } + - { tag: "light", dockerfile: ".devops/llama-cli.Dockerfile", platforms: "linux/amd64,linux/arm64" } + - { tag: "server", dockerfile: ".devops/llama-server.Dockerfile", platforms: "linux/amd64,linux/arm64" } - { tag: "full", dockerfile: ".devops/full.Dockerfile", platforms: "linux/amd64,linux/arm64" } - - { tag: "server", dockerfile: ".devops/server.Dockerfile", platforms: "linux/amd64,linux/arm64" } # NOTE(canardletter): The CUDA builds on arm64 are very slow, so I # have disabled them for now until the reason why # is understood. - - { tag: "light-cuda", dockerfile: ".devops/main-cuda.Dockerfile", platforms: "linux/amd64" } + - { tag: "light-cuda", dockerfile: ".devops/llama-cli-cuda.Dockerfile", platforms: "linux/amd64" } + - { tag: "server-cuda", dockerfile: ".devops/llama-server-cuda.Dockerfile", platforms: "linux/amd64" } - { tag: "full-cuda", dockerfile: ".devops/full-cuda.Dockerfile", platforms: "linux/amd64" } - - { tag: "server-cuda", dockerfile: ".devops/server-cuda.Dockerfile", platforms: "linux/amd64" } - - { tag: "light-rocm", dockerfile: ".devops/main-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" } + - { tag: "light-rocm", dockerfile: ".devops/llama-cli-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" } + - { tag: "server-rocm", dockerfile: ".devops/llama-server-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" } - { tag: "full-rocm", dockerfile: ".devops/full-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" } - - { tag: "server-rocm", dockerfile: ".devops/server-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" } - - { tag: "light-intel", dockerfile: ".devops/main-intel.Dockerfile", platforms: "linux/amd64" } - - { tag: "server-intel", dockerfile: ".devops/server-intel.Dockerfile", platforms: "linux/amd64" } + - { tag: "light-intel", dockerfile: ".devops/llama-cli-intel.Dockerfile", platforms: "linux/amd64" } + - { tag: "server-intel", dockerfile: ".devops/llama-server-intel.Dockerfile", platforms: "linux/amd64" } steps: - name: Check out the repo uses: actions/checkout@v4 diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 0d16ef5f1..1fee9ac28 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -96,7 +96,7 @@ jobs: -DLLAMA_CURL=ON \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON ; - cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target server + cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target llama-server - name: Tests id: server_integration_tests @@ -136,7 +136,7 @@ jobs: id: cmake_build run: | cmake -B build -DLLAMA_CURL=ON -DCURL_LIBRARY="$env:RUNNER_TEMP/libcurl/lib/libcurl.dll.a" -DCURL_INCLUDE_DIR="$env:RUNNER_TEMP/libcurl/include" - cmake --build build --config Release -j ${env:NUMBER_OF_PROCESSORS} --target server + cmake --build build --config Release -j ${env:NUMBER_OF_PROCESSORS} --target llama-server - name: Python setup id: setup_python diff --git a/.gitignore b/.gitignore index 5223c6963..529659495 100644 --- a/.gitignore +++ b/.gitignore @@ -46,48 +46,9 @@ models/* models-mnt /Pipfile -/baby-llama -/beam-search -/benchmark-matmult -/convert-llama2c-to-ggml -/embd-input-test -/embedding -/eval-callback -/gguf -/gguf-llama-simple -/gguf-split -/gritlm -/imatrix -/infill /libllama.so -/llama-bench -/llava-cli -/lookahead -/lookup -/lookup-create -/lookup-merge -/lookup-stats -/main -/metal -/passkey -/perplexity -/q8dot -/quantize -/quantize-stats -/result -/save-load-state -/server -/simple -/batched -/batched-bench -/export-lora -/finetune -/retrieval -/speculative -/parallel -/train-text-from-scratch -/tokenize -/vdot +/llama-* +llama-batched-swift /common/build-info.cpp arm_neon.h compile_commands.json diff --git a/Makefile b/Makefile index 895c62f84..a4cab1bb2 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,44 @@ # Define the default target now so that it is always the first target BUILD_TARGETS = \ - main quantize quantize-stats perplexity imatrix embedding vdot q8dot train-text-from-scratch convert-llama2c-to-ggml \ - simple batched batched-bench save-load-state server gguf gguf-split eval-callback llama-bench libllava.a llava-cli baby-llama \ - retrieval speculative infill tokenize benchmark-matmult parallel finetune export-lora lookahead lookup passkey gritlm tests/test-c.o + libllava.a \ + llama-baby-llama \ + llama-batched \ + llama-batched-bench \ + llama-bench \ + llama-benchmark-matmult \ + llama-cli \ + llama-convert-llama2c-to-ggml \ + llama-embedding \ + llama-eval-callback \ + llama-export-lora \ + llama-finetune \ + llama-gbnf-validator \ + llama-gguf \ + llama-gguf-split \ + llama-gritlm \ + llama-imatrix \ + llama-infill \ + llama-llava-cli \ + llama-lookahead \ + llama-lookup \ + llama-lookup-create \ + llama-lookup-merge \ + llama-lookup-stats \ + llama-parallel \ + llama-passkey \ + llama-perplexity \ + llama-q8dot \ + llama-quantize \ + llama-quantize-stats \ + llama-retrieval \ + llama-save-load-state \ + llama-server \ + llama-simple \ + llama-speculative \ + llama-tokenize \ + llama-train-text-from-scratch \ + llama-vdot \ + tests/test-c.o # Binaries only useful for tests TEST_TARGETS = \ @@ -777,7 +813,7 @@ libllama.a: llama.o ggml.o $(OBJS) $(COMMON_DEPS) ar rcs libllama.a llama.o ggml.o $(OBJS) $(COMMON_DEPS) clean: - rm -vrf *.o tests/*.o *.so *.a *.dll benchmark-matmult lookup-create lookup-merge lookup-stats common/build-info.cpp *.dot $(COV_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS) + rm -vrf *.o tests/*.o *.so *.a *.dll common/build-info.cpp *.dot $(COV_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS) rm -vrf ggml-cuda/*.o rm -vrf ggml-cuda/template-instances/*.o find examples pocs -type f -name "*.o" -delete @@ -793,62 +829,62 @@ clean: # Helper function that replaces .c, .cpp, and .cu file endings with .o: GET_OBJ_FILE = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(patsubst %.cu,%.o,$(1)))) -main: examples/main/main.cpp ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS) +llama-cli: examples/main/main.cpp ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) @echo - @echo '==== Run ./main -h for help. ====' + @echo '==== Run ./llama-cli -h for help. ====' @echo -infill: examples/infill/infill.cpp ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS) +llama-infill: examples/infill/infill.cpp ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -simple: examples/simple/simple.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-simple: examples/simple/simple.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -tokenize: examples/tokenize/tokenize.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-tokenize: examples/tokenize/tokenize.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -batched: examples/batched/batched.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-batched: examples/batched/batched.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -batched-bench: examples/batched-bench/batched-bench.cpp build-info.o ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-batched-bench: examples/batched-bench/batched-bench.cpp build-info.o ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -quantize: examples/quantize/quantize.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-quantize: examples/quantize/quantize.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.o ggml.o llama.o $(OBJS) +llama-quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.o ggml.o llama.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -perplexity: examples/perplexity/perplexity.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-perplexity: examples/perplexity/perplexity.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -imatrix: examples/imatrix/imatrix.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-imatrix: examples/imatrix/imatrix.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -embedding: examples/embedding/embedding.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-embedding: examples/embedding/embedding.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -gritlm: examples/gritlm/gritlm.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-gritlm: examples/gritlm/gritlm.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -save-load-state: examples/save-load-state/save-load-state.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-save-load-state: examples/save-load-state/save-load-state.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -server: examples/server/server.cpp examples/server/utils.hpp examples/server/httplib.h common/json.hpp examples/server/colorthemes.css.hpp examples/server/style.css.hpp examples/server/theme-beeninorder.css.hpp examples/server/theme-ketivah.css.hpp examples/server/theme-mangotango.css.hpp examples/server/theme-playground.css.hpp examples/server/theme-polarnight.css.hpp examples/server/theme-snowstorm.css.hpp examples/server/index.html.hpp examples/server/index-new.html.hpp examples/server/index.js.hpp examples/server/completion.js.hpp examples/server/system-prompts.js.hpp examples/server/prompt-formats.js.hpp examples/server/json-schema-to-grammar.mjs.hpp common/stb_image.h ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS) +llama-server: examples/server/server.cpp examples/server/utils.hpp examples/server/httplib.h common/json.hpp examples/server/colorthemes.css.hpp examples/server/style.css.hpp examples/server/theme-beeninorder.css.hpp examples/server/theme-ketivah.css.hpp examples/server/theme-mangotango.css.hpp examples/server/theme-playground.css.hpp examples/server/theme-polarnight.css.hpp examples/server/theme-snowstorm.css.hpp examples/server/index.html.hpp examples/server/index-new.html.hpp examples/server/index.js.hpp examples/server/completion.js.hpp examples/server/system-prompts.js.hpp examples/server/prompt-formats.js.hpp examples/server/json-schema-to-grammar.mjs.hpp common/stb_image.h ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h %.hpp $<,$^) -Iexamples/server $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) $(LWINSOCK2) @@ -861,23 +897,23 @@ examples/server/%.hpp: examples/server/public/% Makefile echo "unsigned int $${NAME}_len = $(shell cat $< | wc -c );" \ ) > $@ -gguf: examples/gguf/gguf.cpp ggml.o $(OBJS) +llama-gguf: examples/gguf/gguf.cpp ggml.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -gguf-split: examples/gguf-split/gguf-split.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-gguf-split: examples/gguf-split/gguf-split.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -eval-callback: examples/eval-callback/eval-callback.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-eval-callback: examples/eval-callback/eval-callback.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS) +llama-train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -convert-llama2c-to-ggml: examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp ggml.o llama.o $(OBJS) +llama-convert-llama2c-to-ggml: examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp ggml.o llama.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) @@ -888,55 +924,61 @@ llama-bench: examples/llama-bench/llama-bench.cpp ggml.o llama.o $(COMMON_DEPS) libllava.a: examples/llava/llava.cpp examples/llava/llava.h examples/llava/clip.cpp examples/llava/clip.h common/stb_image.h common/base64.hpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -static -fPIC -c $< -o $@ -Wno-cast-qual -llava-cli: examples/llava/llava-cli.cpp examples/llava/clip.h examples/llava/clip.cpp examples/llava/llava.h examples/llava/llava.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-llava-cli: examples/llava/llava-cli.cpp examples/llava/clip.h examples/llava/clip.cpp examples/llava/llava.h examples/llava/llava.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) -c examples/llava/clip.cpp -o $(call GET_OBJ_FILE, examples/llava/clip.cpp) -Wno-cast-qual $(CXX) $(CXXFLAGS) -c examples/llava/llava.cpp -o $(call GET_OBJ_FILE, examples/llava/llava.cpp) $(CXX) $(CXXFLAGS) $(filter-out %.h $< examples/llava/clip.cpp examples/llava/llava.cpp,$^) $(call GET_OBJ_FILE, $<) $(call GET_OBJ_FILE, examples/llava/clip.cpp) $(call GET_OBJ_FILE, examples/llava/llava.cpp) -o $@ $(LDFLAGS) -baby-llama: examples/baby-llama/baby-llama.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS) +llama-baby-llama: examples/baby-llama/baby-llama.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -finetune: examples/finetune/finetune.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS) +llama-finetune: examples/finetune/finetune.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -export-lora: examples/export-lora/export-lora.cpp ggml.o common/common.h $(OBJS) +llama-export-lora: examples/export-lora/export-lora.cpp ggml.o common/common.h $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -retrieval: examples/retrieval/retrieval.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-retrieval: examples/retrieval/retrieval.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -speculative: examples/speculative/speculative.cpp ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS) +llama-speculative: examples/speculative/speculative.cpp ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -parallel: examples/parallel/parallel.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-parallel: examples/parallel/parallel.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -lookahead: examples/lookahead/lookahead.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-lookahead: examples/lookahead/lookahead.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -lookup: examples/lookup/lookup.cpp ggml.o llama.o ngram-cache.o $(COMMON_DEPS) $(OBJS) - $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) - $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) - $(CXX) $(CXXFLAGS) -c examples/lookup/lookup-create.cpp -o $(call GET_OBJ_FILE, examples/lookup/lookup-create.cpp) - $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, examples/lookup/lookup-create.cpp) -o lookup-create $(LDFLAGS) - $(CXX) $(CXXFLAGS) -c examples/lookup/lookup-merge.cpp -o $(call GET_OBJ_FILE, examples/lookup/lookup-merge.cpp) - $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, examples/lookup/lookup-merge.cpp) -o lookup-merge $(LDFLAGS) - $(CXX) $(CXXFLAGS) -c examples/lookup/lookup-stats.cpp -o $(call GET_OBJ_FILE, examples/lookup/lookup-stats.cpp) - $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, examples/lookup/lookup-stats.cpp) -o lookup-stats $(LDFLAGS) - -passkey: examples/passkey/passkey.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) +llama-lookup: examples/lookup/lookup.cpp ggml.o llama.o ngram-cache.o $(COMMON_DEPS) $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -gbnf-validator: examples/gbnf-validator/gbnf-validator.cpp ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS) +llama-lookup-create: examples/lookup/lookup-create.cpp ggml.o llama.o ngram-cache.o $(COMMON_DEPS) $(OBJS) + $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) + $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) + +llama-lookup-merge: examples/lookup/lookup-merge.cpp ggml.o llama.o ngram-cache.o $(COMMON_DEPS) $(OBJS) + $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) + $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) + +llama-lookup-stats: examples/lookup/lookup-stats.cpp ggml.o llama.o ngram-cache.o $(COMMON_DEPS) $(OBJS) + $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) + $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) + +llama-passkey: examples/passkey/passkey.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS) + $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) + $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) + +llama-gbnf-validator: examples/gbnf-validator/gbnf-validator.cpp ggml.o llama.o $(COMMON_DEPS) grammar-parser.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) @@ -962,20 +1004,20 @@ build-info.o: common/build-info.cpp tests: $(TEST_TARGETS) -benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.o ggml.o $(OBJS) +llama-benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.o ggml.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -run-benchmark-matmult: benchmark-matmult +run-benchmark-matmult: llama-benchmark-matmult ./$@ .PHONY: run-benchmark-matmult swift -vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS) +llama-vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) -q8dot: pocs/vdot/q8dot.cpp ggml.o $(OBJS) +llama-q8dot: pocs/vdot/q8dot.cpp ggml.o $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) $(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) diff --git a/README-sycl.md b/README-sycl.md index 62b38135c..93b623daf 100644 --- a/README-sycl.md +++ b/README-sycl.md @@ -77,7 +77,7 @@ It has the similar design of other llama.cpp BLAS-based paths such as *OpenBLAS, *Notes:* - **Memory** - - The device memory is a limitation when running a large model. The loaded model size, *`llm_load_tensors: buffer_size`*, is displayed in the log when running `./bin/main`. + - The device memory is a limitation when running a large model. The loaded model size, *`llm_load_tensors: buffer_size`*, is displayed in the log when running `./bin/llama-cli`. - Please make sure the GPU shared memory from the host is large enough to account for the model's size. For e.g. the *llama-2-7b.Q4_0* requires at least 8.0GB for integrated GPU and 4.0GB for discrete GPU. @@ -99,14 +99,14 @@ The docker build option is currently limited to *intel GPU* targets. ### Build image ```sh # Using FP16 -docker build -t llama-cpp-sycl --build-arg="LLAMA_SYCL_F16=ON" -f .devops/main-intel.Dockerfile . +docker build -t llama-cpp-sycl --build-arg="LLAMA_SYCL_F16=ON" -f .devops/llama-cli-intel.Dockerfile . ``` *Notes*: To build in default FP32 *(Slower than FP16 alternative)*, you can remove the `--build-arg="LLAMA_SYCL_F16=ON"` argument from the previous command. -You can also use the `.devops/server-intel.Dockerfile`, which builds the *"server"* alternative. +You can also use the `.devops/llama-server-intel.Dockerfile`, which builds the *"server"* alternative. ### Run container @@ -275,7 +275,7 @@ source /opt/intel/oneapi/setvars.sh Similar to the native `sycl-ls`, available SYCL devices can be queried as follow: ```sh -./build/bin/ls-sycl-device +./build/bin/llama-ls-sycl-device ``` A example of such log in a system with 1 *intel CPU* and 1 *intel GPU* can look like the following: ``` @@ -313,7 +313,7 @@ Examples: - Use device 0: ```sh -ZES_ENABLE_SYSMAN=1 ./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33 -sm none -mg 0 +ZES_ENABLE_SYSMAN=1 ./build/bin/llama-cli -m models/llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33 -sm none -mg 0 ``` or run by script: @@ -324,7 +324,7 @@ or run by script: - Use multiple devices: ```sh -ZES_ENABLE_SYSMAN=1 ./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33 -sm layer +ZES_ENABLE_SYSMAN=1 ./build/bin/llama-cli -m models/llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33 -sm layer ``` Otherwise, you can run the script: @@ -427,7 +427,7 @@ Otherwise, run the `win-build-sycl.bat` wrapper which encapsulates the former in *Notes:* -- By default, calling `make` will build all target binary files. In case of a minimal experimental setup, the user can build the inference executable only through `make main`. +- By default, calling `make` will build all target binary files. In case of a minimal experimental setup, the user can build the inference executable only through `make llama-cli`. ### III. Run the inference @@ -488,13 +488,13 @@ Examples: - Use device 0: ``` -build\bin\main.exe -m models\llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e -ngl 33 -s 0 -sm none -mg 0 +build\bin\llama-cli.exe -m models\llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e -ngl 33 -s 0 -sm none -mg 0 ``` - Use multiple devices: ``` -build\bin\main.exe -m models\llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e -ngl 33 -s 0 -sm layer +build\bin\llama-cli.exe -m models\llama-2-7b.Q4_0.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e -ngl 33 -s 0 -sm layer ``` Otherwise, run the following wrapper script: diff --git a/README.md b/README.md index 8c065aace..d1c6190dd 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ Inference of Meta's [LLaMA](https://arxiv.org/abs/2302.13971) model (and others) in pure C/C++ +> [!IMPORTANT] +[2024 Jun 12] Binaries have been renamed w/ a `llama-` prefix. `main` is now `llama-cli`, `server` is `llama-server`, etc (https://github.com/ggerganov/llama.cpp/pull/7809) + ### Recent API changes - [2024 Apr 21] `llama_token_to_piece` can now optionally render special tokens https://github.com/ggerganov/llama.cpp/pull/6807 @@ -217,7 +220,7 @@ Unless otherwise noted these projects are open-source with permissive licensing: Here is a typical run using LLaMA v2 13B on M2 Ultra: ``` -$ make -j && ./main -m models/llama-13b-v2/ggml-model-q4_0.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e +$ make -j && ./llama-cli -m models/llama-13b-v2/ggml-model-q4_0.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e I llama.cpp build info: I UNAME_S: Darwin I UNAME_P: arm @@ -555,7 +558,7 @@ Building the program with BLAS support may lead to some performance improvements ```sh # Build the image - docker build -t llama-cpp-vulkan -f .devops/main-vulkan.Dockerfile . + docker build -t llama-cpp-vulkan -f .devops/llama-cli-vulkan.Dockerfile . # Then, use it: docker run -it --rm -v "$(pwd):/app:Z" --device /dev/dri/renderD128:/dev/dri/renderD128 --device /dev/dri/card1:/dev/dri/card1 llama-cpp-vulkan -m "/app/models/YOUR_MODEL_FILE" -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33 @@ -586,7 +589,7 @@ Building the program with BLAS support may lead to some performance improvements cmake -B build -DLLAMA_VULKAN=1 cmake --build build --config Release # Test the output binary (with "-ngl 33" to offload all layers to GPU) - ./bin/main -m "PATH_TO_MODEL" -p "Hi you how are you" -n 50 -e -ngl 33 -t 4 + ./bin/llama-cli -m "PATH_TO_MODEL" -p "Hi you how are you" -n 50 -e -ngl 33 -t 4 # You should see in the output, ggml_vulkan detected your GPU. For example: # ggml_vulkan: Using Intel(R) Graphics (ADL GT2) | uma: 1 | fp16: 1 | warp size: 32 @@ -623,17 +626,17 @@ python3 convert-hf-to-gguf.py models/mymodel/ python convert-hf-to-gguf.py models/mymodel/ --vocab-type bpe # quantize the model to 4-bits (using Q4_K_M method) -./quantize ./models/mymodel/ggml-model-f16.gguf ./models/mymodel/ggml-model-Q4_K_M.gguf Q4_K_M +./llama-quantize ./models/mymodel/ggml-model-f16.gguf ./models/mymodel/ggml-model-Q4_K_M.gguf Q4_K_M # update the gguf filetype to current version if older version is now unsupported -./quantize ./models/mymodel/ggml-model-Q4_K_M.gguf ./models/mymodel/ggml-model-Q4_K_M-v2.gguf COPY +./llama-quantize ./models/mymodel/ggml-model-Q4_K_M.gguf ./models/mymodel/ggml-model-Q4_K_M-v2.gguf COPY ``` ### Run the quantized model ```bash # start inference on a gguf model -./main -m ./models/mymodel/ggml-model-Q4_K_M.gguf -n 128 +./llama-cli -m ./models/mymodel/ggml-model-Q4_K_M.gguf -n 128 ``` When running the larger models, make sure you have enough disk space to store all the intermediate files. @@ -708,7 +711,7 @@ The time per token is measured on a MacBook M1 Pro 32GB RAM using 4 and 8 thread #### How to run 1. Download/extract: https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip -2. Run `./perplexity -m models/7B/ggml-model-q4_0.gguf -f wiki.test.raw` +2. Run `./llama-perplexity -m models/7B/ggml-model-q4_0.gguf -f wiki.test.raw` 3. Output: ``` perplexity : calculating perplexity over 655 chunks @@ -732,16 +735,16 @@ Here is an example of a few-shot interaction, invoked with the command ./examples/chat-13B.sh # custom arguments using a 13B model -./main -m ./models/13B/ggml-model-q4_0.gguf -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-bob.txt +./llama-cli -m ./models/13B/ggml-model-q4_0.gguf -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-bob.txt ``` -Note the use of `--color` to distinguish between user input and generated text. Other parameters are explained in more detail in the [README](examples/main/README.md) for the `main` example program. +Note the use of `--color` to distinguish between user input and generated text. Other parameters are explained in more detail in the [README](examples/main/README.md) for the `llama-cli` example program. ![image](https://user-images.githubusercontent.com/1991296/224575029-2af3c7dc-5a65-4f64-a6bb-517a532aea38.png) ### Persistent Interaction -The prompt, user inputs, and model generations can be saved and resumed across calls to `./main` by leveraging `--prompt-cache` and `--prompt-cache-all`. The `./examples/chat-persistent.sh` script demonstrates this with support for long-running, resumable chat sessions. To use this example, you must provide a file to cache the initial chat prompt and a directory to save the chat session, and may optionally provide the same variables as `chat-13B.sh`. The same prompt cache can be reused for new chat sessions. Note that both prompt cache and chat directory are tied to the initial prompt (`PROMPT_TEMPLATE`) and the model file. +The prompt, user inputs, and model generations can be saved and resumed across calls to `./llama-cli` by leveraging `--prompt-cache` and `--prompt-cache-all`. The `./examples/chat-persistent.sh` script demonstrates this with support for long-running, resumable chat sessions. To use this example, you must provide a file to cache the initial chat prompt and a directory to save the chat session, and may optionally provide the same variables as `chat-13B.sh`. The same prompt cache can be reused for new chat sessions. Note that both prompt cache and chat directory are tied to the initial prompt (`PROMPT_TEMPLATE`) and the model file. ```bash # Start a new chat @@ -763,7 +766,7 @@ PROMPT_TEMPLATE=./prompts/chat-with-bob.txt PROMPT_CACHE_FILE=bob.prompt.bin \ `llama.cpp` supports grammars to constrain model output. For example, you can force the model to output JSON only: ```bash -./main -m ./models/13B/ggml-model-q4_0.gguf -n 256 --grammar-file grammars/json.gbnf -p 'Request: schedule a call at 8pm; Command:' +./llama-cli -m ./models/13B/ggml-model-q4_0.gguf -n 256 --grammar-file grammars/json.gbnf -p 'Request: schedule a call at 8pm; Command:' ``` The `grammars/` folder contains a handful of sample grammars. To write your own, check out the [GBNF Guide](./grammars/README.md). @@ -842,7 +845,7 @@ $mv /sdcard/llama.cpp/llama-2-7b-chat.Q4_K_M.gguf /data/data/com.termux/files/ho Now, you can start chatting: ``` $cd /data/data/com.termux/files/home/bin -$./main -m ../model/llama-2-7b-chat.Q4_K_M.gguf -n 128 -cml +$./llama-cli -m ../model/llama-2-7b-chat.Q4_K_M.gguf -n 128 -cml ``` Here's a demo of an interactive session running on Pixel 5 phone: @@ -909,8 +912,8 @@ Assuming one has the [nvidia-container-toolkit](https://github.com/NVIDIA/nvidia ```bash docker build -t local/llama.cpp:full-cuda -f .devops/full-cuda.Dockerfile . -docker build -t local/llama.cpp:light-cuda -f .devops/main-cuda.Dockerfile . -docker build -t local/llama.cpp:server-cuda -f .devops/server-cuda.Dockerfile . +docker build -t local/llama.cpp:light-cuda -f .devops/llama-cli-cuda.Dockerfile . +docker build -t local/llama.cpp:server-cuda -f .devops/llama-server-cuda.Dockerfile . ``` You may want to pass in some different `ARGS`, depending on the CUDA environment supported by your container host, as well as the GPU architecture. @@ -960,7 +963,7 @@ docker run --gpus all -v /path/to/models:/models local/llama.cpp:server-cuda -m ### Docs -- [main](./examples/main/README.md) +- [main (cli)](./examples/main/README.md) - [server](./examples/server/README.md) - [jeopardy](./examples/jeopardy/README.md) - [BLIS](./docs/BLIS.md) diff --git a/ci/run.sh b/ci/run.sh index 3fc5f48b2..291c44f47 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -303,47 +303,47 @@ function gg_run_open_llama_7b_v2 { wiki_test="${path_wiki}/wiki.test.raw" - ./bin/quantize ${model_f16} ${model_q8_0} q8_0 - ./bin/quantize ${model_f16} ${model_q4_0} q4_0 - ./bin/quantize ${model_f16} ${model_q4_1} q4_1 - ./bin/quantize ${model_f16} ${model_q5_0} q5_0 - ./bin/quantize ${model_f16} ${model_q5_1} q5_1 - ./bin/quantize ${model_f16} ${model_q2_k} q2_k - ./bin/quantize ${model_f16} ${model_q3_k} q3_k - ./bin/quantize ${model_f16} ${model_q4_k} q4_k - ./bin/quantize ${model_f16} ${model_q5_k} q5_k - ./bin/quantize ${model_f16} ${model_q6_k} q6_k + ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0 + ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0 + ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1 + ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0 + ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1 + ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k + ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k + ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k + ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k + ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k - (time ./bin/main --model ${model_f16} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log - (time ./bin/main --model ${model_q8_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log - (time ./bin/main --model ${model_q4_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log - (time ./bin/main --model ${model_q4_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log - (time ./bin/main --model ${model_q5_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log - (time ./bin/main --model ${model_q5_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log - (time ./bin/main --model ${model_q2_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log - (time ./bin/main --model ${model_q3_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log - (time ./bin/main --model ${model_q4_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log - (time ./bin/main --model ${model_q5_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log - (time ./bin/main --model ${model_q6_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log + (time ./bin/llama-cli --model ${model_f16} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log + (time ./bin/llama-cli --model ${model_q8_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log + (time ./bin/llama-cli --model ${model_q4_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log + (time ./bin/llama-cli --model ${model_q4_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log + (time ./bin/llama-cli --model ${model_q5_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log + (time ./bin/llama-cli --model ${model_q5_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log + (time ./bin/llama-cli --model ${model_q2_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log + (time ./bin/llama-cli --model ${model_q3_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log + (time ./bin/llama-cli --model ${model_q4_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log + (time ./bin/llama-cli --model ${model_q5_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log + (time ./bin/llama-cli --model ${model_q6_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log - (time ./bin/perplexity --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log - (time ./bin/perplexity --model ${model_q8_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log - (time ./bin/perplexity --model ${model_q4_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log - (time ./bin/perplexity --model ${model_q4_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log - (time ./bin/perplexity --model ${model_q5_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log - (time ./bin/perplexity --model ${model_q5_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log - (time ./bin/perplexity --model ${model_q2_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log - (time ./bin/perplexity --model ${model_q3_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log - (time ./bin/perplexity --model ${model_q4_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log - (time ./bin/perplexity --model ${model_q5_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log - (time ./bin/perplexity --model ${model_q6_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log + (time ./bin/llama-perplexity --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log + (time ./bin/llama-perplexity --model ${model_q8_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log + (time ./bin/llama-perplexity --model ${model_q4_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log + (time ./bin/llama-perplexity --model ${model_q4_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log + (time ./bin/llama-perplexity --model ${model_q5_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log + (time ./bin/llama-perplexity --model ${model_q5_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log + (time ./bin/llama-perplexity --model ${model_q2_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log + (time ./bin/llama-perplexity --model ${model_q3_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log + (time ./bin/llama-perplexity --model ${model_q4_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log + (time ./bin/llama-perplexity --model ${model_q5_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log + (time ./bin/llama-perplexity --model ${model_q6_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log - (time ./bin/imatrix --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log + (time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log - (time ./bin/save-load-state -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log - (time ./bin/save-load-state -fa -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log - (time ./bin/save-load-state -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log - (time ./bin/save-load-state -fa -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -fa -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -fa -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log function check_ppl { qnt="$1" @@ -437,45 +437,45 @@ function gg_run_pythia_1_4b { wiki_test_60="${path_wiki}/wiki.test-60.raw" - ./bin/quantize ${model_f16} ${model_q8_0} q8_0 - ./bin/quantize ${model_f16} ${model_q4_0} q4_0 - ./bin/quantize ${model_f16} ${model_q4_1} q4_1 - ./bin/quantize ${model_f16} ${model_q5_0} q5_0 - ./bin/quantize ${model_f16} ${model_q5_1} q5_1 - ./bin/quantize ${model_f16} ${model_q2_k} q2_k - ./bin/quantize ${model_f16} ${model_q3_k} q3_k - ./bin/quantize ${model_f16} ${model_q4_k} q4_k - ./bin/quantize ${model_f16} ${model_q5_k} q5_k - ./bin/quantize ${model_f16} ${model_q6_k} q6_k + ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0 + ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0 + ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1 + ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0 + ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1 + ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k + ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k + ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k + ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k + ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k - (time ./bin/main --model ${model_f16} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log - (time ./bin/main --model ${model_q8_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log - (time ./bin/main --model ${model_q4_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log - (time ./bin/main --model ${model_q4_1} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log - (time ./bin/main --model ${model_q5_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log - (time ./bin/main --model ${model_q5_1} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log - (time ./bin/main --model ${model_q2_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log - (time ./bin/main --model ${model_q3_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log - (time ./bin/main --model ${model_q4_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log - (time ./bin/main --model ${model_q5_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log - (time ./bin/main --model ${model_q6_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log + (time ./bin/llama-cli --model ${model_f16} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log + (time ./bin/llama-cli --model ${model_q8_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log + (time ./bin/llama-cli --model ${model_q4_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log + (time ./bin/llama-cli --model ${model_q4_1} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log + (time ./bin/llama-cli --model ${model_q5_0} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log + (time ./bin/llama-cli --model ${model_q5_1} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log + (time ./bin/llama-cli --model ${model_q2_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log + (time ./bin/llama-cli --model ${model_q3_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log + (time ./bin/llama-cli --model ${model_q4_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log + (time ./bin/llama-cli --model ${model_q5_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log + (time ./bin/llama-cli --model ${model_q6_k} -s 1234 -n 64 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log - (time ./bin/perplexity --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log - (time ./bin/perplexity --model ${model_q8_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log - (time ./bin/perplexity --model ${model_q4_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log - (time ./bin/perplexity --model ${model_q4_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log - (time ./bin/perplexity --model ${model_q5_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log - (time ./bin/perplexity --model ${model_q5_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log - (time ./bin/perplexity --model ${model_q2_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log - (time ./bin/perplexity --model ${model_q3_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log - (time ./bin/perplexity --model ${model_q4_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log - (time ./bin/perplexity --model ${model_q5_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log - (time ./bin/perplexity --model ${model_q6_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log + (time ./bin/llama-perplexity --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log + (time ./bin/llama-perplexity --model ${model_q8_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log + (time ./bin/llama-perplexity --model ${model_q4_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log + (time ./bin/llama-perplexity --model ${model_q4_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log + (time ./bin/llama-perplexity --model ${model_q5_0} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log + (time ./bin/llama-perplexity --model ${model_q5_1} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log + (time ./bin/llama-perplexity --model ${model_q2_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log + (time ./bin/llama-perplexity --model ${model_q3_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log + (time ./bin/llama-perplexity --model ${model_q4_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log + (time ./bin/llama-perplexity --model ${model_q5_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log + (time ./bin/llama-perplexity --model ${model_q6_k} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log - (time ./bin/imatrix --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log + (time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test_60} -c 128 -b 128 --chunks 1 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log - (time ./bin/save-load-state --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log - (time ./bin/save-load-state -fa --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -fa --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log function check_ppl { qnt="$1" @@ -569,47 +569,47 @@ function gg_run_pythia_2_8b { wiki_test="${path_wiki}/wiki.test.raw" - ./bin/quantize ${model_f16} ${model_q8_0} q8_0 - ./bin/quantize ${model_f16} ${model_q4_0} q4_0 - ./bin/quantize ${model_f16} ${model_q4_1} q4_1 - ./bin/quantize ${model_f16} ${model_q5_0} q5_0 - ./bin/quantize ${model_f16} ${model_q5_1} q5_1 - ./bin/quantize ${model_f16} ${model_q2_k} q2_k - ./bin/quantize ${model_f16} ${model_q3_k} q3_k - ./bin/quantize ${model_f16} ${model_q4_k} q4_k - ./bin/quantize ${model_f16} ${model_q5_k} q5_k - ./bin/quantize ${model_f16} ${model_q6_k} q6_k + ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0 + ./bin/llama-quantize ${model_f16} ${model_q4_0} q4_0 + ./bin/llama-quantize ${model_f16} ${model_q4_1} q4_1 + ./bin/llama-quantize ${model_f16} ${model_q5_0} q5_0 + ./bin/llama-quantize ${model_f16} ${model_q5_1} q5_1 + ./bin/llama-quantize ${model_f16} ${model_q2_k} q2_k + ./bin/llama-quantize ${model_f16} ${model_q3_k} q3_k + ./bin/llama-quantize ${model_f16} ${model_q4_k} q4_k + ./bin/llama-quantize ${model_f16} ${model_q5_k} q5_k + ./bin/llama-quantize ${model_f16} ${model_q6_k} q6_k - (time ./bin/main --model ${model_f16} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log - (time ./bin/main --model ${model_q8_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log - (time ./bin/main --model ${model_q4_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log - (time ./bin/main --model ${model_q4_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log - (time ./bin/main --model ${model_q5_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log - (time ./bin/main --model ${model_q5_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log - (time ./bin/main --model ${model_q2_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log - (time ./bin/main --model ${model_q3_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log - (time ./bin/main --model ${model_q4_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log - (time ./bin/main --model ${model_q5_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log - (time ./bin/main --model ${model_q6_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log + (time ./bin/llama-cli --model ${model_f16} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log + (time ./bin/llama-cli --model ${model_q8_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log + (time ./bin/llama-cli --model ${model_q4_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log + (time ./bin/llama-cli --model ${model_q4_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log + (time ./bin/llama-cli --model ${model_q5_0} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log + (time ./bin/llama-cli --model ${model_q5_1} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log + (time ./bin/llama-cli --model ${model_q2_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log + (time ./bin/llama-cli --model ${model_q3_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log + (time ./bin/llama-cli --model ${model_q4_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log + (time ./bin/llama-cli --model ${model_q5_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log + (time ./bin/llama-cli --model ${model_q6_k} -t 1 -ngl 999 -s 1234 -n 256 --ignore-eos -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log - (time ./bin/perplexity --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log - (time ./bin/perplexity --model ${model_q8_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log - (time ./bin/perplexity --model ${model_q4_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log - (time ./bin/perplexity --model ${model_q4_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log - (time ./bin/perplexity --model ${model_q5_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log - (time ./bin/perplexity --model ${model_q5_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log - (time ./bin/perplexity --model ${model_q2_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log - (time ./bin/perplexity --model ${model_q3_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log - (time ./bin/perplexity --model ${model_q4_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log - (time ./bin/perplexity --model ${model_q5_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log - (time ./bin/perplexity --model ${model_q6_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log + (time ./bin/llama-perplexity --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log + (time ./bin/llama-perplexity --model ${model_q8_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log + (time ./bin/llama-perplexity --model ${model_q4_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_0.log + (time ./bin/llama-perplexity --model ${model_q4_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_1.log + (time ./bin/llama-perplexity --model ${model_q5_0} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_0.log + (time ./bin/llama-perplexity --model ${model_q5_1} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_1.log + (time ./bin/llama-perplexity --model ${model_q2_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q2_k.log + (time ./bin/llama-perplexity --model ${model_q3_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q3_k.log + (time ./bin/llama-perplexity --model ${model_q4_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q4_k.log + (time ./bin/llama-perplexity --model ${model_q5_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q5_k.log + (time ./bin/llama-perplexity --model ${model_q6_k} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-tg-q6_k.log - (time ./bin/imatrix --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log + (time ./bin/llama-imatrix --model ${model_f16} -f ${wiki_test} -t 1 -ngl 999 -c 2048 -b 512 --chunks 4 ) 2>&1 | tee -a $OUT/${ci}-imatrix.log - (time ./bin/save-load-state -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log - (time ./bin/save-load-state -fa -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log - (time ./bin/save-load-state -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log - (time ./bin/save-load-state -fa -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -fa -ngl 10 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log + (time ./bin/llama-save-load-state -fa -ngl 99 --model ${model_q4_0} ) 2>&1 | tee -a $OUT/${ci}-save-load-state.log function check_ppl { qnt="$1" @@ -693,10 +693,10 @@ function gg_run_embd_bge_small { model_f16="${path_models}/ggml-model-f16.gguf" model_q8_0="${path_models}/ggml-model-q8_0.gguf" - ./bin/quantize ${model_f16} ${model_q8_0} q8_0 + ./bin/llama-quantize ${model_f16} ${model_q8_0} q8_0 - (time ./bin/embedding --model ${model_f16} -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log - (time ./bin/embedding --model ${model_q8_0} -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log + (time ./bin/llama-embedding --model ${model_f16} -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-f16.log + (time ./bin/llama-embedding --model ${model_q8_0} -p "I believe the meaning of life is" ) 2>&1 | tee -a $OUT/${ci}-tg-q8_0.log set +e } diff --git a/docs/HOWTO-add-model.md b/docs/HOWTO-add-model.md index 138124248..3eec077ea 100644 --- a/docs/HOWTO-add-model.md +++ b/docs/HOWTO-add-model.md @@ -100,7 +100,7 @@ Have a look at existing implementation like `build_llama`, `build_dbrx` or `buil When implementing a new graph, please note that the underlying `ggml` backends might not support them all, support for missing backend operations can be added in another PR. -Note: to debug the inference graph: you can use [eval-callback](../examples/eval-callback). +Note: to debug the inference graph: you can use [llama-eval-callback](../examples/eval-callback). ## GGUF specification diff --git a/docs/token_generation_performance_tips.md b/docs/token_generation_performance_tips.md index 3c4343147..c0840cad5 100644 --- a/docs/token_generation_performance_tips.md +++ b/docs/token_generation_performance_tips.md @@ -3,7 +3,7 @@ ## Verifying that the model is running on the GPU with CUDA Make sure you compiled llama with the correct env variables according to [this guide](../README.md#CUDA), so that llama accepts the `-ngl N` (or `--n-gpu-layers N`) flag. When running llama, you may configure `N` to be very large, and llama will offload the maximum possible number of layers to the GPU, even if it's less than the number you configured. For example: ```shell -./main -m "path/to/model.gguf" -ngl 200000 -p "Please sir, may I have some " +./llama-cli -m "path/to/model.gguf" -ngl 200000 -p "Please sir, may I have some " ``` When running llama, before it starts the inference work, it will output diagnostic information that shows whether cuBLAS is offloading work to the GPU. Look for these lines: @@ -27,7 +27,7 @@ RAM: 32GB Model: `TheBloke_Wizard-Vicuna-30B-Uncensored-GGML/Wizard-Vicuna-30B-Uncensored.q4_0.gguf` (30B parameters, 4bit quantization, GGML) -Run command: `./main -m "path/to/model.gguf" -p "An extremely detailed description of the 10 best ethnic dishes will follow, with recipes: " -n 1000 [additional benchmark flags]` +Run command: `./llama-cli -m "path/to/model.gguf" -p "An extremely detailed description of the 10 best ethnic dishes will follow, with recipes: " -n 1000 [additional benchmark flags]` Result: diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 53002f8e1..d6ce35f4c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,42 +13,43 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) if (EMSCRIPTEN) else() add_subdirectory(baby-llama) - add_subdirectory(batched) add_subdirectory(batched-bench) + add_subdirectory(batched) add_subdirectory(benchmark) add_subdirectory(convert-llama2c-to-ggml) add_subdirectory(embedding) add_subdirectory(eval-callback) + add_subdirectory(export-lora) add_subdirectory(finetune) - add_subdirectory(gritlm) + add_subdirectory(gbnf-validator) add_subdirectory(gguf-split) + add_subdirectory(gguf) + add_subdirectory(gritlm) + add_subdirectory(imatrix) add_subdirectory(infill) add_subdirectory(llama-bench) add_subdirectory(llava) - if (LLAMA_SYCL) - add_subdirectory(sycl) - endif() - add_subdirectory(main) - add_subdirectory(tokenize) - add_subdirectory(parallel) - add_subdirectory(perplexity) - add_subdirectory(quantize) - add_subdirectory(quantize-stats) - add_subdirectory(retrieval) - add_subdirectory(save-load-state) - add_subdirectory(simple) - add_subdirectory(passkey) - add_subdirectory(speculative) add_subdirectory(lookahead) add_subdirectory(lookup) - add_subdirectory(gguf) - add_subdirectory(train-text-from-scratch) - add_subdirectory(imatrix) - if (LLAMA_BUILD_SERVER) - add_subdirectory(server) - endif() - add_subdirectory(export-lora) + add_subdirectory(main) + add_subdirectory(parallel) + add_subdirectory(passkey) + add_subdirectory(perplexity) + add_subdirectory(quantize-stats) + add_subdirectory(quantize) + add_subdirectory(retrieval) if (LLAMA_RPC) add_subdirectory(rpc) endif() + if (LLAMA_BUILD_SERVER) + add_subdirectory(server) + endif() + if (LLAMA_SYCL) + add_subdirectory(sycl) + endif() + add_subdirectory(save-load-state) + add_subdirectory(simple) + add_subdirectory(speculative) + add_subdirectory(tokenize) + add_subdirectory(train-text-from-scratch) endif() diff --git a/examples/Miku.sh b/examples/Miku.sh index b9174b4e6..0f6c8c878 100755 --- a/examples/Miku.sh +++ b/examples/Miku.sh @@ -22,7 +22,7 @@ if [ -n "$N_THREAD" ]; then GEN_OPTIONS+=(--threads "$N_THREAD") fi -./main "${GEN_OPTIONS[@]}" \ +./llama-cli "${GEN_OPTIONS[@]}" \ --model "$MODEL" \ --in-prefix " " \ --in-suffix "${AI_NAME}:" \ diff --git a/examples/baby-llama/CMakeLists.txt b/examples/baby-llama/CMakeLists.txt index 7b70227a5..71b82105c 100644 --- a/examples/baby-llama/CMakeLists.txt +++ b/examples/baby-llama/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET baby-llama) +set(TARGET llama-baby-llama) add_executable(${TARGET} baby-llama.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/base-translate.sh b/examples/base-translate.sh index 00dedd0df..103a52f55 100755 --- a/examples/base-translate.sh +++ b/examples/base-translate.sh @@ -58,4 +58,4 @@ echo "$2 model=$1 # generate the most likely continuation until the string "===" is found -./main -m $model -f $ftmp -n 64 --temp 0 --repeat-penalty 1.0 --no-penalize-nl -r "===" $eargs +./llama-cli -m $model -f $ftmp -n 64 --temp 0 --repeat-penalty 1.0 --no-penalize-nl -r "===" $eargs diff --git a/examples/batched-bench/CMakeLists.txt b/examples/batched-bench/CMakeLists.txt index 40a032c51..959acaeee 100644 --- a/examples/batched-bench/CMakeLists.txt +++ b/examples/batched-bench/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET batched-bench) +set(TARGET llama-batched-bench) add_executable(${TARGET} batched-bench.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/batched-bench/README.md b/examples/batched-bench/README.md index fa4baf640..4a07fe6bb 100644 --- a/examples/batched-bench/README.md +++ b/examples/batched-bench/README.md @@ -10,16 +10,16 @@ There are 2 modes of operation: - `prompt is shared` - there is a common prompt of size `PP` used by all batches (i.e. `N_KV = PP + B*TG`) ```bash -./batched-bench -m model.gguf -c 2048 -b 2048 -ub 512 -npp 128,256,512 -ntg 128,256 -npl 1,2,4,8,16,32 [-pps] +./llama-batched-bench -m model.gguf -c 2048 -b 2048 -ub 512 -npp 128,256,512 -ntg 128,256 -npl 1,2,4,8,16,32 [-pps] # LLaMA 7B, F16, N_KV_MAX = 16384 (8GB), prompt not shared -./batched-bench -m ./models/llama-7b/ggml-model-f16.gguf -c 16384 -b 2048 -ub 512 -ngl 99 +./llama-batched-bench -m ./models/llama-7b/ggml-model-f16.gguf -c 16384 -b 2048 -ub 512 -ngl 99 # LLaMA 7B, Q8_0, N_KV_MAX = 16384 (8GB), prompt is shared -./batched-bench -m ./models/llama-7b/ggml-model-q8_0.gguf -c 16384 -b 2048 -ub 512 -ngl 99 -pps +./llama-batched-bench -m ./models/llama-7b/ggml-model-q8_0.gguf -c 16384 -b 2048 -ub 512 -ngl 99 -pps # custom set of batches -./batched-bench -m ./models/llama-7b/ggml-model-q8_0.gguf -c 2048 -b 512 -ub 512 -ngl 999 -npp 128,256,512 -ntg 128,256 -npl 1,2,4,8,16,32 +./llama-batched-bench -m ./models/llama-7b/ggml-model-q8_0.gguf -c 2048 -b 512 -ub 512 -ngl 999 -npp 128,256,512 -ntg 128,256 -npl 1,2,4,8,16,32 ``` ## Sample results diff --git a/examples/batched.swift/Makefile b/examples/batched.swift/Makefile index 2afb24fb8..1f9156e58 100755 --- a/examples/batched.swift/Makefile +++ b/examples/batched.swift/Makefile @@ -1,6 +1,6 @@ .PHONY: build build: - xcodebuild -scheme batched_swift -destination "generic/platform=macOS" -derivedDataPath build - rm -f ./batched_swift - ln -s ./build/Build/Products/Debug/batched_swift ./batched_swift + xcodebuild -scheme llama-batched-swift -destination "generic/platform=macOS" -derivedDataPath build + rm -f ./llama-batched-swift + ln -s ./build/Build/Products/Debug/llama-batched-swift ./llama-batched-swift diff --git a/examples/batched.swift/Package.swift b/examples/batched.swift/Package.swift index 826491def..7e8afd084 100644 --- a/examples/batched.swift/Package.swift +++ b/examples/batched.swift/Package.swift @@ -4,7 +4,7 @@ import PackageDescription let package = Package( - name: "batched_swift", + name: "llama-batched-swift", platforms: [.macOS(.v12)], dependencies: [ .package(name: "llama", path: "../../"), @@ -13,7 +13,7 @@ let package = Package( // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. .executableTarget( - name: "batched_swift", + name: "llama-batched-swift", dependencies: ["llama"], path: "Sources", linkerSettings: [.linkedFramework("Foundation"), .linkedFramework("AppKit")] diff --git a/examples/batched.swift/README.md b/examples/batched.swift/README.md index 4c2721fe8..7f2e2fcdc 100644 --- a/examples/batched.swift/README.md +++ b/examples/batched.swift/README.md @@ -1,4 +1,4 @@ This is a swift clone of `examples/batched`. $ `make` -$ `./batched_swift MODEL_PATH [PROMPT] [PARALLEL]` +$ `./llama-batched-swift MODEL_PATH [PROMPT] [PARALLEL]` diff --git a/examples/batched/CMakeLists.txt b/examples/batched/CMakeLists.txt index 6aa178d4d..77e33343b 100644 --- a/examples/batched/CMakeLists.txt +++ b/examples/batched/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET batched) +set(TARGET llama-batched) add_executable(${TARGET} batched.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/batched/README.md b/examples/batched/README.md index ed204c308..6013aab01 100644 --- a/examples/batched/README.md +++ b/examples/batched/README.md @@ -3,7 +3,7 @@ The example demonstrates batched generation from a given prompt ```bash -./batched -m ./models/llama-7b-v2/ggml-model-f16.gguf -p "Hello my name is" -np 4 +./llama-batched -m ./models/llama-7b-v2/ggml-model-f16.gguf -p "Hello my name is" -np 4 ... diff --git a/examples/benchmark/CMakeLists.txt b/examples/benchmark/CMakeLists.txt index 2bb47bab5..34a58cc02 100644 --- a/examples/benchmark/CMakeLists.txt +++ b/examples/benchmark/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET benchmark) +set(TARGET llama-bench-matmult) add_executable(${TARGET} benchmark-matmult.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE llama build_info ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/chat-13B.sh b/examples/chat-13B.sh index 35c089d57..1828903c3 100755 --- a/examples/chat-13B.sh +++ b/examples/chat-13B.sh @@ -30,7 +30,7 @@ sed -e "s/\[\[USER_NAME\]\]/$USER_NAME/g" \ $PROMPT_TEMPLATE > $PROMPT_FILE # shellcheck disable=SC2086 # Intended splitting of GEN_OPTIONS -./main $GEN_OPTIONS \ +./llama-cli $GEN_OPTIONS \ --model "$MODEL" \ --threads "$N_THREAD" \ --n_predict "$N_PREDICTS" \ diff --git a/examples/chat-persistent.sh b/examples/chat-persistent.sh index 22f5b83d3..d9cab9836 100755 --- a/examples/chat-persistent.sh +++ b/examples/chat-persistent.sh @@ -62,7 +62,7 @@ fi if [[ ! -e "$PROMPT_CACHE_FILE" ]]; then echo 'Prompt cache does not exist, building...' # Default batch_size to 64 here for better user feedback during initial prompt processing - ./main 2>>"$LOG" \ + ./llama-cli 2>>"$LOG" \ --batch_size 64 \ "${OPTS[@]}" \ --prompt-cache "$PROMPT_CACHE_FILE" \ @@ -109,13 +109,13 @@ while read -e line; do printf '%s: ' "$AI_NAME" >>"$CUR_PROMPT_FILE" - ./main 2>>"$LOG" "${OPTS[@]}" \ + ./llama-cli 2>>"$LOG" "${OPTS[@]}" \ --prompt-cache "$CUR_PROMPT_CACHE" \ --prompt-cache-all \ --file "$CUR_PROMPT_FILE" \ --reverse-prompt "${USER_NAME}:" \ --n_predict "$n_predict" | - skip_bytes 1 | # skip BOS token added by ./main + skip_bytes 1 | # skip BOS token added by ./llama-cli tee "$CUR_PROMPT_FILE.tmp" | # save prompt + generation to tmp file skip_bytes "$n_prompt_len_pre" # print generation @@ -133,7 +133,7 @@ while read -e line; do # TODO get both messages in one go if ! session_size_msg="$(tail -n30 "$LOG" | grep -oE "$SESSION_SIZE_MSG_PATTERN")" || ! sample_time_msg="$(tail -n10 "$LOG" | grep -oE "$SAMPLE_TIME_MSG_PATTERN")"; then - echo >&2 "Couldn't get number of tokens from ./main output!" + echo >&2 "Couldn't get number of tokens from ./llama-cli output!" exit 1 fi @@ -144,7 +144,7 @@ while read -e line; do fi # Update cache for next prompt in background, ideally during user input - ./main >>"$LOG_BG" 2>&1 "${OPTS[@]}" \ + ./llama-cli >>"$LOG_BG" 2>&1 "${OPTS[@]}" \ --prompt-cache "$NEXT_PROMPT_CACHE" \ --file "$NEXT_PROMPT_FILE" \ --n_predict 1 & diff --git a/examples/chat-vicuna.sh b/examples/chat-vicuna.sh index 8c7b7bef4..ffdd20084 100755 --- a/examples/chat-vicuna.sh +++ b/examples/chat-vicuna.sh @@ -30,7 +30,7 @@ sed -e "s/\[\[USER_NAME\]\]/$USER_NAME/g" \ $PROMPT_TEMPLATE > $PROMPT_FILE # shellcheck disable=SC2086 # Intended splitting of GEN_OPTIONS -./bin/main $GEN_OPTIONS \ +./bin/llama-cli $GEN_OPTIONS \ --model "$MODEL" \ --threads "$N_THREAD" \ --n_predict "$N_PREDICTS" \ diff --git a/examples/chat.sh b/examples/chat.sh index d567acecd..9f85d1e26 100755 --- a/examples/chat.sh +++ b/examples/chat.sh @@ -11,6 +11,6 @@ cd .. # # "--keep 48" is based on the contents of prompts/chat-with-bob.txt # -./main -m ./models/llama-7b/ggml-model-q4_0.gguf -c 512 -b 1024 -n 256 --keep 48 \ +./llama-cli -m ./models/llama-7b/ggml-model-q4_0.gguf -c 512 -b 1024 -n 256 --keep 48 \ --repeat_penalty 1.0 --color -i \ -r "User:" -f prompts/chat-with-bob.txt diff --git a/examples/convert-llama2c-to-ggml/CMakeLists.txt b/examples/convert-llama2c-to-ggml/CMakeLists.txt index e262d44f9..a6790e617 100644 --- a/examples/convert-llama2c-to-ggml/CMakeLists.txt +++ b/examples/convert-llama2c-to-ggml/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET convert-llama2c-to-ggml) +set(TARGET llama-convert-llama2c-to-ggml) add_executable(${TARGET} convert-llama2c-to-ggml.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/convert-llama2c-to-ggml/README.md b/examples/convert-llama2c-to-ggml/README.md index 742dcf7a3..5774ac83c 100644 --- a/examples/convert-llama2c-to-ggml/README.md +++ b/examples/convert-llama2c-to-ggml/README.md @@ -8,7 +8,7 @@ To convert the model first download the models from the [llama2.c](https://githu After successful compilation, following usage options are available: ``` -usage: ./convert-llama2c-to-ggml [options] +usage: ./llama-convert-llama2c-to-ggml [options] options: -h, --help show this help message and exit @@ -19,10 +19,10 @@ options: An example command using a model from [karpathy/tinyllamas](https://huggingface.co/karpathy/tinyllamas) is as follows: -`$ ./convert-llama2c-to-ggml --copy-vocab-from-model llama-2-7b-chat.gguf.q2_K.bin --llama2c-model stories42M.bin --llama2c-output-model stories42M.gguf.bin` +`$ ./llama-convert-llama2c-to-ggml --copy-vocab-from-model llama-2-7b-chat.gguf.q2_K.bin --llama2c-model stories42M.bin --llama2c-output-model stories42M.gguf.bin` Note: The vocabulary for `stories260K.bin` should be its own tokenizer `tok512.bin` found in [karpathy/tinyllamas/stories260K](https://huggingface.co/karpathy/tinyllamas/tree/main/stories260K). Now you can use the model with a command like: -`$ ./main -m stories42M.gguf.bin -p "One day, Lily met a Shoggoth" -n 500 -c 256` +`$ ./llama-cli -m stories42M.gguf.bin -p "One day, Lily met a Shoggoth" -n 500 -c 256` diff --git a/examples/embedding/CMakeLists.txt b/examples/embedding/CMakeLists.txt index 8ffc33868..8256e789a 100644 --- a/examples/embedding/CMakeLists.txt +++ b/examples/embedding/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET embedding) +set(TARGET llama-embedding) add_executable(${TARGET} embedding.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/embedding/README.md b/examples/embedding/README.md index 6929454c5..2298ec3e7 100644 --- a/examples/embedding/README.md +++ b/examples/embedding/README.md @@ -9,13 +9,13 @@ To get started right away, run the following command, making sure to use the cor ### Unix-based systems (Linux, macOS, etc.): ```bash -./embedding -m ./path/to/model --log-disable -p "Hello World!" 2>/dev/null +./llama-embedding -m ./path/to/model --log-disable -p "Hello World!" 2>/dev/null ``` ### Windows: ```powershell -embedding.exe -m ./path/to/model --log-disable -p "Hello World!" 2>$null +llama-embedding.exe -m ./path/to/model --log-disable -p "Hello World!" 2>$null ``` The above command will output space-separated float values. diff --git a/examples/eval-callback/CMakeLists.txt b/examples/eval-callback/CMakeLists.txt index c56ba780b..a48753d38 100644 --- a/examples/eval-callback/CMakeLists.txt +++ b/examples/eval-callback/CMakeLists.txt @@ -1,9 +1,9 @@ -set(TARGET eval-callback) +set(TARGET llama-eval-callback) add_executable(${TARGET} eval-callback.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PRIVATE cxx_std_11) set(TEST_TARGET test-eval-callback) -add_test(NAME ${TEST_TARGET} COMMAND eval-callback --hf-repo ggml-org/models --hf-file tinyllamas/stories260K.gguf --model stories260K.gguf --prompt hello --seed 42 -ngl 0) +add_test(NAME ${TEST_TARGET} COMMAND llama-eval-callback --hf-repo ggml-org/models --hf-file tinyllamas/stories260K.gguf --model stories260K.gguf --prompt hello --seed 42 -ngl 0) set_property(TEST ${TEST_TARGET} PROPERTY LABELS eval-callback curl) diff --git a/examples/eval-callback/README.md b/examples/eval-callback/README.md index 66a37e878..63a57ad6b 100644 --- a/examples/eval-callback/README.md +++ b/examples/eval-callback/README.md @@ -6,7 +6,7 @@ It simply prints to the console all operations and tensor data. Usage: ```shell -eval-callback \ +llama-eval-callback \ --hf-repo ggml-org/models \ --hf-file phi-2/ggml-model-q4_0.gguf \ --model phi-2-q4_0.gguf \ diff --git a/examples/export-lora/CMakeLists.txt b/examples/export-lora/CMakeLists.txt index cbbdaec67..1cef6e716 100644 --- a/examples/export-lora/CMakeLists.txt +++ b/examples/export-lora/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET export-lora) +set(TARGET llama-export-lora) add_executable(${TARGET} export-lora.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/export-lora/README.md b/examples/export-lora/README.md index 0cf3e8e45..1fb17feec 100644 --- a/examples/export-lora/README.md +++ b/examples/export-lora/README.md @@ -3,7 +3,7 @@ Apply LORA adapters to base model and export the resulting model. ``` -usage: export-lora [options] +usage: llama-export-lora [options] options: -h, --help show this help message and exit @@ -17,7 +17,7 @@ options: For example: ```bash -./bin/export-lora \ +./bin/llama-export-lora \ -m open-llama-3b-v2-q8_0.gguf \ -o open-llama-3b-v2-q8_0-english2tokipona-chat.gguf \ -l lora-open-llama-3b-v2-q8_0-english2tokipona-chat-LATEST.bin diff --git a/examples/finetune/CMakeLists.txt b/examples/finetune/CMakeLists.txt index 2b52d21cf..64afe6ddc 100644 --- a/examples/finetune/CMakeLists.txt +++ b/examples/finetune/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET finetune) +set(TARGET llama-finetune) add_executable(${TARGET} finetune.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/finetune/README.md b/examples/finetune/README.md index 2fafd505e..a6ae64983 100644 --- a/examples/finetune/README.md +++ b/examples/finetune/README.md @@ -7,7 +7,7 @@ Basic usage instructions: wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt # finetune LORA adapter -./bin/finetune \ +./bin/llama-finetune \ --model-base open-llama-3b-v2-q8_0.gguf \ --checkpoint-in chk-lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.gguf \ --checkpoint-out chk-lora-open-llama-3b-v2-q8_0-shakespeare-ITERATION.gguf \ @@ -18,7 +18,7 @@ wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/s --use-checkpointing # predict -./bin/main -m open-llama-3b-v2-q8_0.gguf --lora lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin +./bin/llama-cli -m open-llama-3b-v2-q8_0.gguf --lora lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin ``` **Only llama based models are supported!** The output files will be saved every N iterations (config with `--save-every N`). @@ -38,14 +38,14 @@ After 10 more iterations: Checkpoint files (`--checkpoint-in FN`, `--checkpoint-out FN`) store the training process. When the input checkpoint file does not exist, it will begin finetuning a new randomly initialized adapter. llama.cpp compatible LORA adapters will be saved with filename specified by `--lora-out FN`. -These LORA adapters can then be used by `main` together with the base model, like in the 'predict' example command above. +These LORA adapters can then be used by `llama-cli` together with the base model, like in the 'predict' example command above. -In `main` you can also load multiple LORA adapters, which will then be mixed together. +In `llama-cli` you can also load multiple LORA adapters, which will then be mixed together. For example if you have two LORA adapters `lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin` and `lora-open-llama-3b-v2-q8_0-bible-LATEST.bin`, you can mix them together like this: ```bash -./bin/main -m open-llama-3b-v2-q8_0.gguf \ +./bin/llama-cli -m open-llama-3b-v2-q8_0.gguf \ --lora lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin \ --lora lora-open-llama-3b-v2-q8_0-bible-LATEST.bin ``` @@ -55,7 +55,7 @@ You can change how strong each LORA adapter is applied to the base model by usin For example to apply 40% of the 'shakespeare' LORA adapter, 80% of the 'bible' LORA adapter and 100% of yet another one: ```bash -./bin/main -m open-llama-3b-v2-q8_0.gguf \ +./bin/llama-cli -m open-llama-3b-v2-q8_0.gguf \ --lora-scaled lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin 0.4 \ --lora-scaled lora-open-llama-3b-v2-q8_0-bible-LATEST.bin 0.8 \ --lora lora-open-llama-3b-v2-q8_0-yet-another-one-LATEST.bin diff --git a/examples/finetune/finetune.sh b/examples/finetune/finetune.sh index 079bfa113..d7f2165e5 100644 --- a/examples/finetune/finetune.sh +++ b/examples/finetune/finetune.sh @@ -2,7 +2,7 @@ cd `dirname $0` cd ../.. -EXE="./finetune" +EXE="./llama-finetune" if [[ ! $LLAMA_MODEL_DIR ]]; then LLAMA_MODEL_DIR="./models"; fi if [[ ! $LLAMA_TRAINING_DIR ]]; then LLAMA_TRAINING_DIR="."; fi diff --git a/examples/gbnf-validator/CMakeLists.txt b/examples/gbnf-validator/CMakeLists.txt index 166e3ad2a..4edd6ec73 100644 --- a/examples/gbnf-validator/CMakeLists.txt +++ b/examples/gbnf-validator/CMakeLists.txt @@ -1,5 +1,5 @@ -set(TARGET gbnf-validator) +set(TARGET llama-gbnf-validator) add_executable(${TARGET} gbnf-validator.cpp) install(TARGETS ${TARGET} RUNTIME) -target_link_libraries(${TARGET} PRIVATE common grammar-parser llama ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PRIVATE cxx_std_11) diff --git a/examples/gbnf-validator/gbnf-validator.cpp b/examples/gbnf-validator/gbnf-validator.cpp index 091069ffa..0406dc339 100644 --- a/examples/gbnf-validator/gbnf-validator.cpp +++ b/examples/gbnf-validator/gbnf-validator.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include @@ -69,13 +71,14 @@ int main(int argc, char** argv) { return 1; } - fseek(grammar_file, 0, SEEK_END); - size_t grammar_size = ftell(grammar_file); - fseek(grammar_file, 0, SEEK_SET); - - std::string grammar_str(grammar_size, ' '); - fread(&grammar_str[0], 1, grammar_size, grammar_file); - fclose(grammar_file); + std::string grammar_str; + { + std::ifstream grammar_file(grammar_filename); + GGML_ASSERT(grammar_file.is_open() && "Failed to open grammar file"); + std::stringstream buffer; + buffer << grammar_file.rdbuf(); + grammar_str = buffer.str(); + } // Parse the GBNF grammar auto parsed_grammar = grammar_parser::parse(grammar_str.c_str()); @@ -100,20 +103,15 @@ int main(int argc, char** argv) { grammar_rules.size(), parsed_grammar.symbol_ids.at("root")); // Read the input file - FILE* input_file = fopen(input_filename.c_str(), "r"); - if (!input_file) { - fprintf(stdout, "Failed to open input file: %s\n", input_filename.c_str()); - return 1; + std::string input_str; + { + std::ifstream input_file(input_filename); + GGML_ASSERT(input_file.is_open() && "Failed to open input file"); + std::stringstream buffer; + buffer << input_file.rdbuf(); + input_str = buffer.str(); } - fseek(input_file, 0, SEEK_END); - size_t input_size = ftell(input_file); - fseek(input_file, 0, SEEK_SET); - - std::string input_str(input_size, ' '); - fread(&input_str[0], 1, input_size, input_file); - fclose(input_file); - // Validate the input string against the grammar size_t error_pos; std::string error_msg; diff --git a/examples/gguf-split/CMakeLists.txt b/examples/gguf-split/CMakeLists.txt index 828e62435..f63887da7 100644 --- a/examples/gguf-split/CMakeLists.txt +++ b/examples/gguf-split/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET gguf-split) +set(TARGET llama-gguf-split) add_executable(${TARGET} gguf-split.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/gguf-split/tests.sh b/examples/gguf-split/tests.sh index 3bc0fa471..d5a92d605 100755 --- a/examples/gguf-split/tests.sh +++ b/examples/gguf-split/tests.sh @@ -18,8 +18,8 @@ fi set -x -SPLIT=$1/gguf-split -MAIN=$1/main +SPLIT=$1/llama-gguf-split +MAIN=$1/llama-cli WORK_PATH=$TMP_DIR/gguf-split ROOT_DIR=$(realpath $(dirname $0)/../../) diff --git a/examples/gguf/CMakeLists.txt b/examples/gguf/CMakeLists.txt index 6481f087b..a9569b411 100644 --- a/examples/gguf/CMakeLists.txt +++ b/examples/gguf/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET gguf) +set(TARGET llama-gguf) add_executable(${TARGET} gguf.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/gritlm/CMakeLists.txt b/examples/gritlm/CMakeLists.txt index ac4a5ae79..86dfddca3 100644 --- a/examples/gritlm/CMakeLists.txt +++ b/examples/gritlm/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET gritlm) +set(TARGET llama-gritlm) add_executable(${TARGET} gritlm.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/gritlm/README.md b/examples/gritlm/README.md index a3a3c1389..786ba5736 100644 --- a/examples/gritlm/README.md +++ b/examples/gritlm/README.md @@ -26,7 +26,7 @@ $ scripts/hf.sh --repo cohesionet/GritLM-7B_gguf --file gritlm-7b_q4_1.gguf --ou Run the example using the downloaded model: ```console -$ ./gritlm -m models/gritlm-7b_q4_1.gguf +$ ./llama-gritlm -m models/gritlm-7b_q4_1.gguf Cosine similarity between "Bitcoin: A Peer-to-Peer Electronic Cash System" and "A purely peer-to-peer version of electronic cash w" is: 0.605 Cosine similarity between "Bitcoin: A Peer-to-Peer Electronic Cash System" and "All text-based language problems can be reduced to" is: 0.103 diff --git a/examples/imatrix/CMakeLists.txt b/examples/imatrix/CMakeLists.txt index d688a1620..d4c8265bd 100644 --- a/examples/imatrix/CMakeLists.txt +++ b/examples/imatrix/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET imatrix) +set(TARGET llama-imatrix) add_executable(${TARGET} imatrix.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/imatrix/README.md b/examples/imatrix/README.md index 866ca9f56..38b36ee5a 100644 --- a/examples/imatrix/README.md +++ b/examples/imatrix/README.md @@ -6,7 +6,7 @@ More information is available here: https://github.com/ggerganov/llama.cpp/pull/ ## Usage ``` -./imatrix \ +./llama-imatrix \ -m model.gguf -f some-text.txt [-o imatrix.dat] [--process-output] [--verbosity 1] \ [--no-ppl] [--chunk 123] [--output-frequency 10] [--save-frequency 0] \ [--in-file imatrix-prev-0.dat --in-file imatrix-prev-1.dat ...] @@ -28,8 +28,8 @@ For faster computation, make sure to use GPU offloading via the `-ngl` argument LLAMA_CUDA=1 make -j # generate importance matrix (imatrix.dat) -./imatrix -m ggml-model-f16.gguf -f train-data.txt -ngl 99 +./llama-imatrix -m ggml-model-f16.gguf -f train-data.txt -ngl 99 # use the imatrix to perform a Q4_K_M quantization -./quantize --imatrix imatrix.dat ggml-model-f16.gguf ./ggml-model-q4_k_m.gguf q4_k_m +./llama-quantize --imatrix imatrix.dat ggml-model-f16.gguf ./ggml-model-q4_k_m.gguf q4_k_m ``` diff --git a/examples/infill/CMakeLists.txt b/examples/infill/CMakeLists.txt index e4e8028da..9b1aa3b63 100644 --- a/examples/infill/CMakeLists.txt +++ b/examples/infill/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET infill) +set(TARGET llama-infill) add_executable(${TARGET} infill.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/infill/README.md b/examples/infill/README.md index 6b076c839..74f42d2fc 100644 --- a/examples/infill/README.md +++ b/examples/infill/README.md @@ -42,5 +42,5 @@ scripts/hf.sh --repo TheBloke/CodeLlama-13B-GGUF --file codellama-13b.Q5_K_S.ggu ``` ```bash -./infill -t 10 -ngl 0 -m models/codellama-13b.Q5_K_S.gguf -c 4096 --temp 0.7 --repeat_penalty 1.1 -n 20 --in-prefix "def helloworld():\n print(\"hell" --in-suffix "\n print(\"goodbye world\")\n " +./llama-infill -t 10 -ngl 0 -m models/codellama-13b.Q5_K_S.gguf -c 4096 --temp 0.7 --repeat_penalty 1.1 -n 20 --in-prefix "def helloworld():\n print(\"hell" --in-suffix "\n print(\"goodbye world\")\n " ``` diff --git a/examples/jeopardy/jeopardy.sh b/examples/jeopardy/jeopardy.sh index 9bdbc755c..07bcb3b8d 100755 --- a/examples/jeopardy/jeopardy.sh +++ b/examples/jeopardy/jeopardy.sh @@ -21,7 +21,7 @@ counter=1 echo 'Running' while IFS= read -r question do - exe_cmd="./main -p "\"$prefix$introduction$nl$prefix$question\"" "$opts" -m ""\"$MODEL\""" >> ""\"$output_file\"" + exe_cmd="./llama-cli -p "\"$prefix$introduction$nl$prefix$question\"" "$opts" -m ""\"$MODEL\""" >> ""\"$output_file\"" echo $counter echo "Current Question: $question" eval "$exe_cmd" diff --git a/examples/json-schema-pydantic-example.py b/examples/json-schema-pydantic-example.py index 69ebfd409..cc64e572b 100644 --- a/examples/json-schema-pydantic-example.py +++ b/examples/json-schema-pydantic-example.py @@ -1,5 +1,5 @@ # Usage: -#! ./server -m some-model.gguf & +#! ./llama-server -m some-model.gguf & #! pip install pydantic #! python json-schema-pydantic-example.py diff --git a/examples/json_schema_to_grammar.py b/examples/json_schema_to_grammar.py index ab19e20df..b588497b9 100755 --- a/examples/json_schema_to_grammar.py +++ b/examples/json_schema_to_grammar.py @@ -523,7 +523,7 @@ class SchemaConverter: def main(args_in = None): parser = argparse.ArgumentParser( description=''' - Generates a grammar (suitable for use in ./main) that produces JSON conforming to a + Generates a grammar (suitable for use in ./llama-cli) that produces JSON conforming to a given JSON schema. Only a subset of JSON schema features are supported; more may be added in the future. ''', diff --git a/examples/llama-bench/README.md b/examples/llama-bench/README.md index fd95b35f4..52b0e74d3 100644 --- a/examples/llama-bench/README.md +++ b/examples/llama-bench/README.md @@ -1,4 +1,4 @@ -# llama.cpp/example/llama-bench +# llama.cpp/examples/llama-bench Performance testing tool for llama.cpp. diff --git a/examples/llava/CMakeLists.txt b/examples/llava/CMakeLists.txt index 2985caff8..e9fa73acb 100644 --- a/examples/llava/CMakeLists.txt +++ b/examples/llava/CMakeLists.txt @@ -30,8 +30,9 @@ if(TARGET BUILD_INFO) add_dependencies(llava BUILD_INFO) endif() -set(TARGET llava-cli) -add_executable(llava-cli llava-cli.cpp) -install(TARGETS llava-cli RUNTIME) -target_link_libraries(llava-cli PRIVATE common llava ${CMAKE_THREAD_LIBS_INIT}) -target_compile_features(llava PRIVATE cxx_std_11) +set(TARGET llama-llava-cli) +add_executable(${TARGET} llava-cli.cpp) +set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama-llava-cli) +install(TARGETS ${TARGET} RUNTIME) +target_link_libraries(${TARGET} PRIVATE common llava ${CMAKE_THREAD_LIBS_INIT}) +target_compile_features(${TARGET} PRIVATE cxx_std_11) diff --git a/examples/llava/MobileVLM-README.md b/examples/llava/MobileVLM-README.md index 74f021dec..05a8207e6 100644 --- a/examples/llava/MobileVLM-README.md +++ b/examples/llava/MobileVLM-README.md @@ -9,12 +9,12 @@ The implementation is based on llava, and is compatible with llava and mobileVLM Notice: The overall process of model inference for both **MobileVLM** and **MobileVLM_V2** models is the same, but the process of model conversion is a little different. Therefore, using **MobileVLM-1.7B** as an example, the different conversion step will be shown. ## Usage -Build with cmake or run `make llava-cli` to build it. +Build with cmake or run `make llama-llava-cli` to build it. -After building, run: `./llava-cli` to see the usage. For example: +After building, run: `./llama-llava-cli` to see the usage. For example: ```sh -./llava-cli -m MobileVLM-1.7B/ggml-model-q4_k.gguf \ +./llama-llava-cli -m MobileVLM-1.7B/ggml-model-q4_k.gguf \ --mmproj MobileVLM-1.7B/mmproj-model-f16.gguf \ --image path/to/an/image.jpg \ -p "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: \nWho is the author of this book? Answer the question using a single word or phrase. ASSISTANT:" @@ -62,7 +62,7 @@ python ./examples/convert-legacy-llama.py path/to/MobileVLM-1.7B 5. Use `quantize` to convert LLaMA part's DataType from `fp16` to `q4_k` ```sh -./quantize path/to/MobileVLM-1.7B/ggml-model-f16.gguf path/to/MobileVLM-1.7B/ggml-model-q4_k.gguf q4_k_s +./llama-quantize path/to/MobileVLM-1.7B/ggml-model-f16.gguf path/to/MobileVLM-1.7B/ggml-model-q4_k.gguf q4_k_s ``` Now both the LLaMA part and the image encoder is in the `MobileVLM-1.7B` directory. @@ -82,7 +82,7 @@ refer to `android/adb_run.sh`, modify resources' `name` and `path` ### case 1 **input** ```sh -/data/local/tmp/llava-cli \ +/data/local/tmp/llama-llava-cli \ -m /data/local/tmp/ggml-model-q4_k.gguf \ --mmproj /data/local/tmp/mmproj-model-f16.gguf \ -t 4 \ @@ -102,7 +102,7 @@ llama_print_timings: total time = 34731.93 ms ### case 2 **input** ```sh -/data/local/tmp/llava-cli \ +/data/local/tmp/llama-llava-cli \ -m /data/local/tmp/ggml-model-q4_k.gguf \ --mmproj /data/local/tmp/mmproj-model-f16.gguf \ -t 4 \ @@ -126,7 +126,7 @@ llama_print_timings: total time = 34570.79 ms #### llava-cli release-b2005 **input** ```sh -/data/local/tmp/llava-cli \ +/data/local/tmp/llama-llava-cli \ -m /data/local/tmp/ggml-model-q4_k.gguf \ --mmproj /data/local/tmp/mmproj-model-f16.gguf \ -t 4 \ @@ -200,7 +200,7 @@ make LLAMA_CUDA=1 CUDA_DOCKER_ARCH=sm_87 LLAMA_CUDA_F16=1 -j 32 ### case 1 **input** ```sh -./llava-cli \ +./llama-llava-cli \ -m /data/local/tmp/ggml-model-q4_k.gguf \ --mmproj /data/local/tmp/mmproj-model-f16.gguf \ --image /data/local/tmp/demo.jpeg \ @@ -224,7 +224,7 @@ llama_print_timings: total time = 1352.63 ms / 252 tokens ### case 2 **input** ```sh -./llava-cli \ +./llama-llava-cli \ -m /data/local/tmp/ggml-model-q4_k.gguf \ --mmproj /data/local/tmp/mmproj-model-f16.gguf \ -p "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: \nWhat is in the image? ASSISTANT:" \ diff --git a/examples/llava/README.md b/examples/llava/README.md index 8d1ae5270..f4554de67 100644 --- a/examples/llava/README.md +++ b/examples/llava/README.md @@ -11,12 +11,12 @@ For llava-1.6 a variety of prepared gguf models are available as well [7b-34b](h After API is confirmed, more models will be supported / uploaded. ## Usage -Build with cmake or run `make llava-cli` to build it. +Build with cmake or run `make llama-llava-cli` to build it. -After building, run: `./llava-cli` to see the usage. For example: +After building, run: `./llama-llava-cli` to see the usage. For example: ```sh -./llava-cli -m ../llava-v1.5-7b/ggml-model-f16.gguf --mmproj ../llava-v1.5-7b/mmproj-model-f16.gguf --image path/to/an/image.jpg +./llama-llava-cli -m ../llava-v1.5-7b/ggml-model-f16.gguf --mmproj ../llava-v1.5-7b/mmproj-model-f16.gguf --image path/to/an/image.jpg ``` **note**: A lower temperature like 0.1 is recommended for better quality. add `--temp 0.1` to the command to do so. @@ -95,9 +95,9 @@ python ./examples/llava/convert-image-encoder-to-gguf.py -m vit --llava-projecto python ./examples/convert-legacy-llama.py ../llava-v1.6-vicuna-7b/ --skip-unknown ``` -7) And finally we can run the llava-cli using the 1.6 model version: +7) And finally we can run the llava cli using the 1.6 model version: ```console -./llava-cli -m ../llava-v1.6-vicuna-7b/ggml-model-f16.gguf --mmproj vit/mmproj-model-f16.gguf --image some-image.jpg -c 4096 +./llama-llava-cli -m ../llava-v1.6-vicuna-7b/ggml-model-f16.gguf --mmproj vit/mmproj-model-f16.gguf --image some-image.jpg -c 4096 ``` **note** llava-1.6 needs more context than llava-1.5, at least 3000 is needed (just run it at -c 4096) diff --git a/examples/llava/android/adb_run.sh b/examples/llava/android/adb_run.sh index f73623ae3..45ccf8d70 100755 --- a/examples/llava/android/adb_run.sh +++ b/examples/llava/android/adb_run.sh @@ -10,7 +10,7 @@ prompt="A chat between a curious user and an artificial intelligence assistant. # prompt="A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: \nWhat is in the image? ASSISTANT:" program_dir="build_64/bin" -binName="llava-cli" +binName="llama-llava-cli" n_threads=4 diff --git a/examples/lookahead/CMakeLists.txt b/examples/lookahead/CMakeLists.txt index 8827e3f11..f0ae5cd89 100644 --- a/examples/lookahead/CMakeLists.txt +++ b/examples/lookahead/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET lookahead) +set(TARGET llama-lookahead) add_executable(${TARGET} lookahead.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/lookup/CMakeLists.txt b/examples/lookup/CMakeLists.txt index b91633f63..ef19fe25e 100644 --- a/examples/lookup/CMakeLists.txt +++ b/examples/lookup/CMakeLists.txt @@ -1,22 +1,22 @@ -set(TARGET lookup) +set(TARGET llama-lookup) add_executable(${TARGET} lookup.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PRIVATE cxx_std_11) -set(TARGET lookup-create) +set(TARGET llama-lookup-create) add_executable(${TARGET} lookup-create.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PRIVATE cxx_std_11) -set(TARGET lookup-merge) +set(TARGET llama-lookup-merge) add_executable(${TARGET} lookup-merge.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PRIVATE cxx_std_11) -set(TARGET lookup-stats) +set(TARGET llama-lookup-stats) add_executable(${TARGET} lookup-stats.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/lookup/lookup-merge.cpp b/examples/lookup/lookup-merge.cpp index 07c93eb8d..81e2b0436 100644 --- a/examples/lookup/lookup-merge.cpp +++ b/examples/lookup/lookup-merge.cpp @@ -11,14 +11,14 @@ #include #include -static void print_usage() { +static void print_usage(char* argv0) { fprintf(stderr, "Merges multiple lookup cache files into a single one.\n"); - fprintf(stderr, "Usage: lookup-merge [--help] lookup_part_1.bin lookup_part_2.bin ... lookup_merged.bin\n"); + fprintf(stderr, "Usage: %s [--help] lookup_part_1.bin lookup_part_2.bin ... lookup_merged.bin\n", argv0); } int main(int argc, char ** argv){ if (argc < 3) { - print_usage(); + print_usage(argv[0]); exit(1); } @@ -27,7 +27,7 @@ int main(int argc, char ** argv){ for (int i = 0; i < argc-1; ++i) { args[i] = argv[i+1]; if (args[i] == "-h" || args[i] == "--help") { - print_usage(); + print_usage(argv[0]); exit(0); } } diff --git a/examples/main-cmake-pkg/CMakeLists.txt b/examples/main-cmake-pkg/CMakeLists.txt index deb77d588..a97ded365 100644 --- a/examples/main-cmake-pkg/CMakeLists.txt +++ b/examples/main-cmake-pkg/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.12) -project("main-cmake-pkg" C CXX) -set(TARGET main-cmake-pkg) +project("llama-cli-cmake-pkg" C CXX) +set(TARGET llama-cli-cmake-pkg) find_package(Llama 0.0.1 REQUIRED) # Bake common functionality in with target. Because applications # using the relocatable Llama package should be outside of the -# source tree, main-cmake-pkg pretends the dependencies are built-in. +# source tree, llama-cli-cmake-pkg pretends the dependencies are built-in. set(_common_path "${CMAKE_CURRENT_LIST_DIR}/../../common") add_library(common OBJECT) file(GLOB _common_files @@ -15,7 +15,7 @@ file(GLOB _common_files ) target_sources(common PRIVATE ${_common_files}) -# If the common project was part of "main-cmake-pkg" the transient +# If the common project was part of "llama-cli-cmake-pkg" the transient # defines would automatically be attached. Because the common func- # tionality is separate, but dependent upon the defines, it must be # explicitly extracted from the "llama" target. diff --git a/examples/main-cmake-pkg/README.md b/examples/main-cmake-pkg/README.md index a88e92f23..08d83dd08 100644 --- a/examples/main-cmake-pkg/README.md +++ b/examples/main-cmake-pkg/README.md @@ -1,6 +1,6 @@ # llama.cpp/example/main-cmake-pkg -This program builds the [main](../main) application using a relocatable CMake package. It serves as an example of using the `find_package()` CMake command to conveniently include [llama.cpp](https://github.com/ggerganov/llama.cpp) in projects which live outside of the source tree. +This program builds [llama-cli](../main) using a relocatable CMake package. It serves as an example of using the `find_package()` CMake command to conveniently include [llama.cpp](https://github.com/ggerganov/llama.cpp) in projects which live outside of the source tree. ## Building @@ -20,7 +20,7 @@ cmake --build build --config Release cmake --install build --prefix C:/LlamaCPP ``` -### Build main-cmake-pkg +### Build llama-cli-cmake-pkg ```cmd diff --git a/examples/main/CMakeLists.txt b/examples/main/CMakeLists.txt index d532980b7..5f6efaa9a 100644 --- a/examples/main/CMakeLists.txt +++ b/examples/main/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET main) +set(TARGET llama-cli) add_executable(${TARGET} main.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/main/README.md b/examples/main/README.md index cdc002f15..61e4a42f7 100644 --- a/examples/main/README.md +++ b/examples/main/README.md @@ -1,4 +1,4 @@ -# llama.cpp/example/main +# llama.cpp/examples/main This example program allows you to use various LLaMA language models in an easy and efficient way. It is specifically designed to work with the [llama.cpp](https://github.com/ggerganov/llama.cpp) project, which provides a plain C/C++ implementation with optional 4-bit quantization support for faster, lower memory inference, and is optimized for desktop CPUs. This program can be used to perform various inference tasks with LLaMA models, including generating text based on user-provided prompts and chat-like interactions with reverse prompts. @@ -20,13 +20,13 @@ To get started right away, run the following command, making sure to use the cor #### Unix-based systems (Linux, macOS, etc.): ```bash -./main -m models/7B/ggml-model.bin --prompt "Once upon a time" +./llama-cli -m models/7B/ggml-model.bin --prompt "Once upon a time" ``` #### Windows: ```powershell -main.exe -m models\7B\ggml-model.bin --prompt "Once upon a time" +llama-cli.exe -m models\7B\ggml-model.bin --prompt "Once upon a time" ``` For an interactive experience, try this command: @@ -34,7 +34,7 @@ For an interactive experience, try this command: #### Unix-based systems (Linux, macOS, etc.): ```bash -./main -m models/7B/ggml-model.bin -n -1 --color -r "User:" --in-prefix " " -i -p \ +./llama-cli -m models/7B/ggml-model.bin -n -1 --color -r "User:" --in-prefix " " -i -p \ 'User: Hi AI: Hello. I am an AI chatbot. Would you like to talk? User: Sure! @@ -45,7 +45,7 @@ User:' #### Windows: ```powershell -main.exe -m models\7B\ggml-model.bin -n -1 --color -r "User:" --in-prefix " " -i -e -p "User: Hi\nAI: Hello. I am an AI chatbot. Would you like to talk?\nUser: Sure!\nAI: What would you like to talk about?\nUser:" +llama-cli.exe -m models\7B\ggml-model.bin -n -1 --color -r "User:" --in-prefix " " -i -e -p "User: Hi\nAI: Hello. I am an AI chatbot. Would you like to talk?\nUser: Sure!\nAI: What would you like to talk about?\nUser:" ``` The following command generates "infinite" text from a starting prompt (you can use `Ctrl-C` to stop it): @@ -53,18 +53,18 @@ The following command generates "infinite" text from a starting prompt (you can #### Unix-based systems (Linux, macOS, etc.): ```bash -./main -m models/7B/ggml-model.bin --ignore-eos -n -1 +./llama-cli -m models/7B/ggml-model.bin --ignore-eos -n -1 ``` #### Windows: ```powershell -main.exe -m models\7B\ggml-model.bin --ignore-eos -n -1 +llama-cli.exe -m models\7B\ggml-model.bin --ignore-eos -n -1 ``` ## Common Options -In this section, we cover the most commonly used options for running the `main` program with the LLaMA models: +In this section, we cover the most commonly used options for running the `llama-cli` program with the LLaMA models: - `-m FNAME, --model FNAME`: Specify the path to the LLaMA model file (e.g., `models/7B/ggml-model.gguf`; inferred from `--model-url` if set). - `-mu MODEL_URL --model-url MODEL_URL`: Specify a remote http url to download the file (e.g https://huggingface.co/ggml-org/models/resolve/main/phi-2/ggml-model-q4_0.gguf). @@ -74,7 +74,7 @@ In this section, we cover the most commonly used options for running the `main` ## Input Prompts -The `main` program provides several ways to interact with the LLaMA models using input prompts: +The `llama-cli` program provides several ways to interact with the LLaMA models using input prompts: - `--prompt PROMPT`: Provide a prompt directly as a command-line option. - `--file FNAME`: Provide a file containing a prompt or multiple prompts. @@ -82,7 +82,7 @@ The `main` program provides several ways to interact with the LLaMA models using ## Interaction -The `main` program offers a seamless way to interact with LLaMA models, allowing users to engage in real-time conversations or provide instructions for specific tasks. The interactive mode can be triggered using various options, including `--interactive` and `--interactive-first`. +The `llama-cli` program offers a seamless way to interact with LLaMA models, allowing users to engage in real-time conversations or provide instructions for specific tasks. The interactive mode can be triggered using various options, including `--interactive` and `--interactive-first`. In interactive mode, users can participate in text generation by injecting their input during the process. Users can press `Ctrl+C` at any time to interject and type their input, followed by pressing `Return` to submit it to the LLaMA model. To submit additional lines without finalizing input, users can end the current line with a backslash (`\`) and continue typing. @@ -107,7 +107,7 @@ To overcome this limitation, you can use the `--in-prefix` flag to add a space o The `--in-prefix` flag is used to add a prefix to your input, primarily, this is used to insert a space after the reverse prompt. Here's an example of how to use the `--in-prefix` flag in conjunction with the `--reverse-prompt` flag: ```sh -./main -r "User:" --in-prefix " " +./llama-cli -r "User:" --in-prefix " " ``` ### In-Suffix @@ -115,7 +115,7 @@ The `--in-prefix` flag is used to add a prefix to your input, primarily, this is The `--in-suffix` flag is used to add a suffix after your input. This is useful for adding an "Assistant:" prompt after the user's input. It's added after the new-line character (`\n`) that's automatically added to the end of the user's input. Here's an example of how to use the `--in-suffix` flag in conjunction with the `--reverse-prompt` flag: ```sh -./main -r "User:" --in-prefix " " --in-suffix "Assistant:" +./llama-cli -r "User:" --in-prefix " " --in-suffix "Assistant:" ``` ## Context Management diff --git a/examples/parallel/CMakeLists.txt b/examples/parallel/CMakeLists.txt index 319535a6e..c13557bac 100644 --- a/examples/parallel/CMakeLists.txt +++ b/examples/parallel/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET parallel) +set(TARGET llama-parallel) add_executable(${TARGET} parallel.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/passkey/CMakeLists.txt b/examples/passkey/CMakeLists.txt index 3161bf3ef..dc467a5d3 100644 --- a/examples/passkey/CMakeLists.txt +++ b/examples/passkey/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET passkey) +set(TARGET llama-passkey) add_executable(${TARGET} passkey.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/passkey/README.md b/examples/passkey/README.md index 9e7a119ba..a48a6283a 100644 --- a/examples/passkey/README.md +++ b/examples/passkey/README.md @@ -8,5 +8,5 @@ See the following PRs for more info: ### Usage ```bash -make -j && ./passkey -m ./models/llama-7b-v2/ggml-model-f16.gguf --junk 250 +make -j && ./llama-passkey -m ./models/llama-7b-v2/ggml-model-f16.gguf --junk 250 ``` diff --git a/examples/perplexity/CMakeLists.txt b/examples/perplexity/CMakeLists.txt index 3c76d3221..be0f2fd02 100644 --- a/examples/perplexity/CMakeLists.txt +++ b/examples/perplexity/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET perplexity) +set(TARGET llama-perplexity) add_executable(${TARGET} perplexity.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/perplexity/perplexity.cpp b/examples/perplexity/perplexity.cpp index 0bd78c21a..efde8dfdf 100644 --- a/examples/perplexity/perplexity.cpp +++ b/examples/perplexity/perplexity.cpp @@ -476,7 +476,7 @@ static results_perplexity perplexity(llama_context * ctx, const gpt_params & par } // Download: https://huggingface.co/datasets/ggml-org/ci/resolve/main/wikitext-2-raw-v1.zip - // Run `./perplexity -m models/7B/ggml-model-q4_0.bin -f wiki.test.raw` + // Run `./llama-perplexity -m models/7B/ggml-model-q4_0.bin -f wiki.test.raw` // Output: `perplexity: 13.5106 [114/114]` // BOS tokens will be added for each chunk before eval diff --git a/examples/quantize-stats/CMakeLists.txt b/examples/quantize-stats/CMakeLists.txt index e31cf5e38..bb986a716 100644 --- a/examples/quantize-stats/CMakeLists.txt +++ b/examples/quantize-stats/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET quantize-stats) +set(TARGET llama-quantize-stats) add_executable(${TARGET} quantize-stats.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE llama build_info ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/quantize/CMakeLists.txt b/examples/quantize/CMakeLists.txt index 6b977fde8..3ee4eb971 100644 --- a/examples/quantize/CMakeLists.txt +++ b/examples/quantize/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET quantize) +set(TARGET llama-quantize) add_executable(${TARGET} quantize.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE llama common ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/quantize/tests.sh b/examples/quantize/tests.sh index 38e28ffc3..24bc970e8 100644 --- a/examples/quantize/tests.sh +++ b/examples/quantize/tests.sh @@ -18,9 +18,9 @@ fi set -x -SPLIT=$1/gguf-split -QUANTIZE=$1/quantize -MAIN=$1/main +SPLIT=$1/llama-gguf-split +QUANTIZE=$1/llama-quantize +MAIN=$1/llama-cli WORK_PATH=$TMP_DIR/quantize ROOT_DIR=$(realpath $(dirname $0)/../../) diff --git a/examples/reason-act.sh b/examples/reason-act.sh index 046c48db5..06d592799 100755 --- a/examples/reason-act.sh +++ b/examples/reason-act.sh @@ -8,7 +8,7 @@ if [ "$1" == "-m" ]; then MODEL="-m $2 " fi -./main $MODEL --color \ +./llama-cli $MODEL --color \ -f ./prompts/reason-act.txt \ -i --interactive-first \ --top_k 10000 --temp 0.2 --repeat_penalty 1 -t 7 -c 2048 \ diff --git a/examples/retrieval/CMakeLists.txt b/examples/retrieval/CMakeLists.txt index eaabae08d..66610f311 100644 --- a/examples/retrieval/CMakeLists.txt +++ b/examples/retrieval/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET retrieval) +set(TARGET llama-retrieval) add_executable(${TARGET} retrieval.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/retrieval/README.md b/examples/retrieval/README.md index 2b2595c46..bc5f22e2f 100644 --- a/examples/retrieval/README.md +++ b/examples/retrieval/README.md @@ -15,7 +15,7 @@ https://github.com/ggerganov/llama.cpp/pull/6193 `retrieval` example can be tested as follows: ```bash -make -j && ./retrieval --model ./models/bge-base-en-v1.5-f16.gguf --top-k 3 --context-file README.md --context-file License --chunk-size 100 --chunk-separator . +make -j && ./llama-retrieval --model ./models/bge-base-en-v1.5-f16.gguf --top-k 3 --context-file README.md --context-file License --chunk-size 100 --chunk-separator . ``` This chunks and embeds all given files and starts a loop requesting query inputs: diff --git a/examples/rpc/README.md b/examples/rpc/README.md index eeec71a8e..86544e3fe 100644 --- a/examples/rpc/README.md +++ b/examples/rpc/README.md @@ -70,5 +70,5 @@ cmake --build . --config Release Finally, use the `--rpc` option to specify the host and port of each `rpc-server`: ```bash -$ bin/main -m ../models/tinyllama-1b/ggml-model-f16.gguf -p "Hello, my name is" --repeat-penalty 1.0 -n 64 --rpc 192.168.88.10:50052,192.168.88.11:50052 -ngl 99 +$ bin/llama-cli -m ../models/tinyllama-1b/ggml-model-f16.gguf -p "Hello, my name is" --repeat-penalty 1.0 -n 64 --rpc 192.168.88.10:50052,192.168.88.11:50052 -ngl 99 ``` diff --git a/examples/save-load-state/CMakeLists.txt b/examples/save-load-state/CMakeLists.txt index cc6ed8554..0fb5e359b 100644 --- a/examples/save-load-state/CMakeLists.txt +++ b/examples/save-load-state/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET save-load-state) +set(TARGET llama-save-load-state) add_executable(${TARGET} save-load-state.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/server-llama2-13B.sh b/examples/server-llama2-13B.sh index 17fedc2b1..4ce79b7fa 100755 --- a/examples/server-llama2-13B.sh +++ b/examples/server-llama2-13B.sh @@ -16,7 +16,7 @@ GEN_OPTIONS="${GEN_OPTIONS:---ctx_size 4096 --batch-size 1024}" # shellcheck disable=SC2086 # Intended splitting of GEN_OPTIONS -./server $GEN_OPTIONS \ +./llama-server $GEN_OPTIONS \ --model "$MODEL" \ --threads "$N_THREAD" \ --rope-freq-scale 1.0 \ diff --git a/examples/server/CMakeLists.txt b/examples/server/CMakeLists.txt index dab709619..8365f9510 100644 --- a/examples/server/CMakeLists.txt +++ b/examples/server/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET server) +set(TARGET llama-server) option(LLAMA_SERVER_VERBOSE "Build verbose logging option for Server" ON) option(LLAMA_SERVER_SSL "Build SSL support for the server" OFF) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/examples/server/README.md b/examples/server/README.md index ccbdcdbdb..e7fb0bf64 100644 --- a/examples/server/README.md +++ b/examples/server/README.md @@ -80,26 +80,26 @@ The project is under active development, and we are [looking for feedback and co ## Build -`server` is built alongside everything else from the root of the project +`llama-server` is built alongside everything else from the root of the project - Using `make`: ```bash - make server + make llama-server ``` - Using `CMake`: ```bash cmake -B build - cmake --build build --config Release -t server + cmake --build build --config Release -t llama-server ``` - Binary is at `./build/bin/server` + Binary is at `./build/bin/llama-server` ## Build with SSL -`server` can also be built with SSL support using OpenSSL 3 +`llama-server` can also be built with SSL support using OpenSSL 3 - Using `make`: @@ -107,14 +107,14 @@ The project is under active development, and we are [looking for feedback and co # NOTE: For non-system openssl, use the following: # CXXFLAGS="-I /path/to/openssl/include" # LDFLAGS="-L /path/to/openssl/lib" - make LLAMA_SERVER_SSL=true server + make LLAMA_SERVER_SSL=true llama-server ``` - Using `CMake`: ```bash cmake -B build -DLLAMA_SERVER_SSL=ON - cmake --build build --config Release -t server + cmake --build build --config Release -t llama-server ``` ## Quick Start @@ -124,13 +124,13 @@ To get started right away, run the following command, making sure to use the cor ### Unix-based systems (Linux, macOS, etc.) ```bash -./server -m models/7B/ggml-model.gguf -c 2048 +./llama-server -m models/7B/ggml-model.gguf -c 2048 ``` ### Windows ```powershell -server.exe -m models\7B\ggml-model.gguf -c 2048 +llama-server.exe -m models\7B\ggml-model.gguf -c 2048 ``` The above command will start a server that by default listens on `127.0.0.1:8080`. @@ -629,11 +629,11 @@ bash chat.sh ### OAI-like API -The HTTP `server` supports an OAI-like API: https://github.com/openai/openai-openapi +The HTTP `llama-server` supports an OAI-like API: https://github.com/openai/openai-openapi ### API errors -`server` returns errors in the same format as OAI: https://github.com/openai/openai-openapi +`llama-server` returns errors in the same format as OAI: https://github.com/openai/openai-openapi Example of an error: diff --git a/examples/server/bench/README.md b/examples/server/bench/README.md index 23a3ec975..0f18ca396 100644 --- a/examples/server/bench/README.md +++ b/examples/server/bench/README.md @@ -99,7 +99,7 @@ The `bench.py` script does several steps: It aims to be used in the CI, but you can run it manually: ```shell -LLAMA_SERVER_BIN_PATH=../../../cmake-build-release/bin/server python bench.py \ +LLAMA_SERVER_BIN_PATH=../../../cmake-build-release/bin/llama-server python bench.py \ --runner-label local \ --name local \ --branch `git rev-parse --abbrev-ref HEAD` \ diff --git a/examples/server/bench/bench.py b/examples/server/bench/bench.py index 86c5de101..4fbbb2032 100644 --- a/examples/server/bench/bench.py +++ b/examples/server/bench/bench.py @@ -245,7 +245,7 @@ def start_server(args): def start_server_background(args): # Start the server - server_path = '../../../build/bin/server' + server_path = '../../../build/bin/llama-server' if 'LLAMA_SERVER_BIN_PATH' in os.environ: server_path = os.environ['LLAMA_SERVER_BIN_PATH'] server_args = [ diff --git a/examples/server/public_simplechat/readme.md b/examples/server/public_simplechat/readme.md index 36a46885d..2dc177825 100644 --- a/examples/server/public_simplechat/readme.md +++ b/examples/server/public_simplechat/readme.md @@ -44,12 +44,12 @@ http module. ### running using examples/server -bin/server -m path/model.gguf --path ../examples/server/public_simplechat [--port PORT] +./llama-server -m path/model.gguf --path examples/server/public_simplechat [--port PORT] ### running using python3's server module first run examples/server -* bin/server -m path/model.gguf +* ./llama-server -m path/model.gguf next run this web front end in examples/server/public_simplechat * cd ../examples/server/public_simplechat diff --git a/examples/server/tests/README.md b/examples/server/tests/README.md index 83c0208f3..5e6cb277b 100644 --- a/examples/server/tests/README.md +++ b/examples/server/tests/README.md @@ -27,10 +27,8 @@ To mitigate it, you can increase values in `n_predict`, `kv_size`. ```shell cd ../../.. -mkdir build -cd build -cmake -DLLAMA_CURL=ON ../ -cmake --build . --target server +cmake -B build -DLLAMA_CURL=ON +cmake --build build --target llama-server ``` 2. Start the test: `./tests.sh` @@ -40,7 +38,7 @@ It's possible to override some scenario steps values with environment variables: | variable | description | |--------------------------|------------------------------------------------------------------------------------------------| | `PORT` | `context.server_port` to set the listening port of the server during scenario, default: `8080` | -| `LLAMA_SERVER_BIN_PATH` | to change the server binary path, default: `../../../build/bin/server` | +| `LLAMA_SERVER_BIN_PATH` | to change the server binary path, default: `../../../build/bin/llama-server` | | `DEBUG` | "ON" to enable steps and server verbose mode `--verbose` | | `SERVER_LOG_FORMAT_JSON` | if set switch server logs to json format | | `N_GPU_LAYERS` | number of model layers to offload to VRAM `-ngl --n-gpu-layers` | diff --git a/examples/server/tests/features/steps/steps.py b/examples/server/tests/features/steps/steps.py index 26d9359d7..7b5dabb01 100644 --- a/examples/server/tests/features/steps/steps.py +++ b/examples/server/tests/features/steps/steps.py @@ -1272,9 +1272,9 @@ def context_text(context): def start_server_background(context): if os.name == 'nt': - context.server_path = '../../../build/bin/Release/server.exe' + context.server_path = '../../../build/bin/Release/llama-server.exe' else: - context.server_path = '../../../build/bin/server' + context.server_path = '../../../build/bin/llama-server' if 'LLAMA_SERVER_BIN_PATH' in os.environ: context.server_path = os.environ['LLAMA_SERVER_BIN_PATH'] server_listen_addr = context.server_fqdn diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt index 7da5ff6f3..070cfbe7a 100644 --- a/examples/simple/CMakeLists.txt +++ b/examples/simple/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET simple) +set(TARGET llama-simple) add_executable(${TARGET} simple.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/speculative/CMakeLists.txt b/examples/speculative/CMakeLists.txt index 810f3c46a..aa208e7aa 100644 --- a/examples/speculative/CMakeLists.txt +++ b/examples/speculative/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET speculative) +set(TARGET llama-speculative) add_executable(${TARGET} speculative.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/sycl/CMakeLists.txt b/examples/sycl/CMakeLists.txt index 69cf8932e..e4d5083e6 100644 --- a/examples/sycl/CMakeLists.txt +++ b/examples/sycl/CMakeLists.txt @@ -2,7 +2,7 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: MIT -set(TARGET ls-sycl-device) +set(TARGET llama-ls-sycl-device) add_executable(${TARGET} ls-sycl-device.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/sycl/README.md b/examples/sycl/README.md index c589c2d3a..0e3acd35b 100644 --- a/examples/sycl/README.md +++ b/examples/sycl/README.md @@ -6,9 +6,9 @@ This example program provides the tools for llama.cpp for SYCL on Intel GPU. |Tool Name| Function|Status| |-|-|-| -|ls-sycl-device| List all SYCL devices with ID, compute capability, max work group size, ect.|Support| +|llama-ls-sycl-device| List all SYCL devices with ID, compute capability, max work group size, ect.|Support| -### ls-sycl-device +### llama-ls-sycl-device List all SYCL devices with ID, compute capability, max work group size, ect. @@ -23,7 +23,7 @@ source /opt/intel/oneapi/setvars.sh 3. Execute ``` -./build/bin/ls-sycl-device +./build/bin/llama-ls-sycl-device ``` Check the ID in startup log, like: diff --git a/examples/sycl/run-llama2.sh b/examples/sycl/run-llama2.sh index 7b39a18c0..da0e4aaba 100755 --- a/examples/sycl/run-llama2.sh +++ b/examples/sycl/run-llama2.sh @@ -23,15 +23,15 @@ fi if [ $GGML_SYCL_SINGLE_GPU -eq 1 ]; then echo "use $GGML_SYCL_DEVICE as main GPU" #use signle GPU only - ZES_ENABLE_SYSMAN=1 ./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 -mg $GGML_SYCL_DEVICE -sm none + ZES_ENABLE_SYSMAN=1 ./build/bin/llama-cli -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 -mg $GGML_SYCL_DEVICE -sm none else #use multiple GPUs with same max compute units - ZES_ENABLE_SYSMAN=1 ./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 + ZES_ENABLE_SYSMAN=1 ./build/bin/llama-cli -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 fi #use main GPU only -#ZES_ENABLE_SYSMAN=1 ./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 -mg $GGML_SYCL_DEVICE -sm none +#ZES_ENABLE_SYSMAN=1 ./build/bin/llama-cli -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 -mg $GGML_SYCL_DEVICE -sm none #use multiple GPUs with same max compute units -#ZES_ENABLE_SYSMAN=1 ./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 +#ZES_ENABLE_SYSMAN=1 ./build/bin/llama-cli -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33 -s 0 diff --git a/examples/tokenize/CMakeLists.txt b/examples/tokenize/CMakeLists.txt index 5e6654d7e..b704dcae1 100644 --- a/examples/tokenize/CMakeLists.txt +++ b/examples/tokenize/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET tokenize) +set(TARGET llama-tokenize) add_executable(${TARGET} tokenize.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/train-text-from-scratch/CMakeLists.txt b/examples/train-text-from-scratch/CMakeLists.txt index 4459516d0..9a1d2a35e 100644 --- a/examples/train-text-from-scratch/CMakeLists.txt +++ b/examples/train-text-from-scratch/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET train-text-from-scratch) +set(TARGET llama-train-text-from-scratch) add_executable(${TARGET} train-text-from-scratch.cpp) install(TARGETS ${TARGET} RUNTIME) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/train-text-from-scratch/README.md b/examples/train-text-from-scratch/README.md index 1b3454069..3abae2380 100644 --- a/examples/train-text-from-scratch/README.md +++ b/examples/train-text-from-scratch/README.md @@ -7,7 +7,7 @@ Basic usage instructions: wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt # train -./bin/train-text-from-scratch \ +./bin/llama-train-text-from-scratch \ --vocab-model ../models/ggml-vocab-llama.gguf \ --ctx 64 --embd 256 --head 8 --layer 16 \ --checkpoint-in chk-shakespeare-256x16-LATEST.gguf \ @@ -18,7 +18,7 @@ wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/s --no-checkpointing # predict -./bin/main -m ggml-shakespeare-256x16-f32.gguf +./bin/llama-cli -m ggml-shakespeare-256x16-f32.gguf ``` Output files will be saved every N iterations (config with `--save-every N`). diff --git a/flake.nix b/flake.nix index 0a52ea52e..c69637d11 100644 --- a/flake.nix +++ b/flake.nix @@ -63,7 +63,7 @@ # nix-repl> :lf github:ggerganov/llama.cpp # Added 13 variables. # nix-repl> outputs.apps.x86_64-linux.quantize - # { program = "/nix/store/00000000000000000000000000000000-llama.cpp/bin/quantize"; type = "app"; } + # { program = "/nix/store/00000000000000000000000000000000-llama.cpp/bin/llama-quantize"; type = "app"; } # ``` outputs = { self, flake-parts, ... }@inputs: diff --git a/grammars/README.md b/grammars/README.md index 2ec21a4c0..2f685eb6d 100644 --- a/grammars/README.md +++ b/grammars/README.md @@ -91,7 +91,7 @@ item ::= [^\n]+ "\n" This guide provides a brief overview. Check out the GBNF files in this directory (`grammars/`) for examples of full grammars. You can try them out with: ``` -./main -m --grammar-file grammars/some-grammar.gbnf -p 'Some prompt' +./llama-cli -m --grammar-file grammars/some-grammar.gbnf -p 'Some prompt' ``` `llama.cpp` can also convert JSON schemas to grammars either ahead of time or at each request, see below. @@ -110,20 +110,20 @@ While semantically correct, the syntax `x? x? x?.... x?` (with N repetitions) ma You can use GBNF grammars: -- In the [server](../examples/server)'s completion endpoints, passed as the `grammar` body field -- In the [main](../examples/main) CLI, passed as the `--grammar` & `--grammar-file` flags -- With the [gbnf-validator](../examples/gbnf-validator) tool, to test them against strings. +- In [llama-server](../examples/server)'s completion endpoints, passed as the `grammar` body field +- In [llama-cli](../examples/main), passed as the `--grammar` & `--grammar-file` flags +- With [llama-gbnf-validator](../examples/gbnf-validator) tool, to test them against strings. ## JSON Schemas → GBNF `llama.cpp` supports converting a subset of https://json-schema.org/ to GBNF grammars: -- In the [server](../examples/server): +- In [llama-server](../examples/server): - For any completion endpoints, passed as the `json_schema` body field - For the `/chat/completions` endpoint, passed inside the `result_format` body field (e.g. `{"type", "json_object", "schema": {"items": {}}}`) -- In the [main](../examples/main) CLI, passed as the `--json` / `-j` flag +- In [llama-cli](../examples/main), passed as the `--json` / `-j` flag - To convert to a grammar ahead of time: - - in CLI, with [json_schema_to_grammar.py](../examples/json_schema_to_grammar.py) + - in CLI, with [examples/json_schema_to_grammar.py](../examples/json_schema_to_grammar.py) - in JavaScript with [json-schema-to-grammar.mjs](../examples/server/public/json-schema-to-grammar.mjs) (this is used by the [server](../examples/server)'s Web UI) Take a look at [tests](../../tests/test-json-schema-to-grammar.cpp) to see which features are likely supported (you'll also find usage examples in https://github.com/ggerganov/llama.cpp/pull/5978, https://github.com/ggerganov/llama.cpp/pull/6659 & https://github.com/ggerganov/llama.cpp/pull/6555). diff --git a/pocs/vdot/CMakeLists.txt b/pocs/vdot/CMakeLists.txt index fb89a1cd4..d5405ad29 100644 --- a/pocs/vdot/CMakeLists.txt +++ b/pocs/vdot/CMakeLists.txt @@ -1,9 +1,9 @@ -set(TARGET vdot) +set(TARGET llama-vdot) add_executable(${TARGET} vdot.cpp) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PRIVATE cxx_std_11) -set(TARGET q8dot) +set(TARGET llama-q8dot) add_executable(${TARGET} q8dot.cpp) target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) target_compile_features(${TARGET} PRIVATE cxx_std_11) diff --git a/scripts/get-hellaswag.sh b/scripts/get-hellaswag.sh index 121979fe2..4e1b1cc15 100755 --- a/scripts/get-hellaswag.sh +++ b/scripts/get-hellaswag.sh @@ -4,7 +4,7 @@ wget https://raw.githubusercontent.com/klosax/hellaswag_text_data/main/hellaswag echo "Usage:" echo "" -echo " ./perplexity -m model.gguf -f hellaswag_val_full.txt --hellaswag [--hellaswag-tasks N] [other params]" +echo " ./llama-perplexity -m model.gguf -f hellaswag_val_full.txt --hellaswag [--hellaswag-tasks N] [other params]" echo "" exit 0 diff --git a/scripts/get-wikitext-103.sh b/scripts/get-wikitext-103.sh index 880dd5cbe..9c65fafbc 100755 --- a/scripts/get-wikitext-103.sh +++ b/scripts/get-wikitext-103.sh @@ -4,7 +4,7 @@ wget https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-103-raw-v1. echo "Usage:" echo "" -echo " ./perplexity -m model.gguf -f wiki.test.raw [other params]" +echo " ./llama-perplexity -m model.gguf -f wiki.test.raw [other params]" echo "" exit 0 diff --git a/scripts/get-wikitext-2.sh b/scripts/get-wikitext-2.sh index b01476a46..5f3845ef5 100755 --- a/scripts/get-wikitext-2.sh +++ b/scripts/get-wikitext-2.sh @@ -5,7 +5,7 @@ unzip wikitext-2-raw-v1.zip echo "Usage:" echo "" -echo " ./perplexity -m model.gguf -f wikitext-2-raw/wiki.test.raw [other params]" +echo " ./llama-perplexity -m model.gguf -f wikitext-2-raw/wiki.test.raw [other params]" echo "" exit 0 diff --git a/scripts/get-winogrande.sh b/scripts/get-winogrande.sh index 5f234468e..f1fc0e2d4 100755 --- a/scripts/get-winogrande.sh +++ b/scripts/get-winogrande.sh @@ -4,7 +4,7 @@ wget https://huggingface.co/datasets/ikawrakow/winogrande-eval-for-llama.cpp/raw echo "Usage:" echo "" -echo " ./perplexity -m model.gguf -f winogrande-debiased-eval.csv --winogrande [--winogrande-tasks N] [other params]" +echo " ./llama-perplexity -m model.gguf -f winogrande-debiased-eval.csv --winogrande [--winogrande-tasks N] [other params]" echo "" exit 0 diff --git a/scripts/hf.sh b/scripts/hf.sh index 58f83d6fe..85c2c4d9a 100755 --- a/scripts/hf.sh +++ b/scripts/hf.sh @@ -3,9 +3,9 @@ # Shortcut for downloading HF models # # Usage: -# ./main -m $(./scripts/hf.sh https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q4_K_M.gguf) -# ./main -m $(./scripts/hf.sh --url https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/blob/main/mixtral-8x7b-v0.1.Q4_K_M.gguf) -# ./main -m $(./scripts/hf.sh --repo TheBloke/Mixtral-8x7B-v0.1-GGUF --file mixtral-8x7b-v0.1.Q4_K_M.gguf) +# ./llama-cli -m $(./scripts/hf.sh https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q4_K_M.gguf) +# ./llama-cli -m $(./scripts/hf.sh --url https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/blob/main/mixtral-8x7b-v0.1.Q4_K_M.gguf) +# ./llama-cli -m $(./scripts/hf.sh --repo TheBloke/Mixtral-8x7B-v0.1-GGUF --file mixtral-8x7b-v0.1.Q4_K_M.gguf) # # all logs go to stderr diff --git a/scripts/pod-llama.sh b/scripts/pod-llama.sh index 5dabbf60e..6ba499a2a 100644 --- a/scripts/pod-llama.sh +++ b/scripts/pod-llama.sh @@ -77,9 +77,9 @@ if [ "$1" -eq "1" ]; then python3 examples/convert-legacy-llama.py ./models/tinyllama-1b --outfile ./models/tinyllama-1b/ggml-model-f16.gguf --outtype f16 - ./quantize ./models/tinyllama-1b/ggml-model-f16.gguf ./models/tinyllama-1b/ggml-model-q4_0.gguf q4_0 - ./quantize ./models/tinyllama-1b/ggml-model-f16.gguf ./models/tinyllama-1b/ggml-model-q4_k.gguf q4_k - ./quantize ./models/tinyllama-1b/ggml-model-f16.gguf ./models/tinyllama-1b/ggml-model-q8_0.gguf q8_0 + ./llama-quantize ./models/tinyllama-1b/ggml-model-f16.gguf ./models/tinyllama-1b/ggml-model-q4_0.gguf q4_0 + ./llama-quantize ./models/tinyllama-1b/ggml-model-f16.gguf ./models/tinyllama-1b/ggml-model-q4_k.gguf q4_k + ./llama-quantize ./models/tinyllama-1b/ggml-model-f16.gguf ./models/tinyllama-1b/ggml-model-q8_0.gguf q8_0 fi if [ "$1" -eq "2" ]; then @@ -92,9 +92,9 @@ if [ "$1" -eq "2" ]; then python3 examples/convert-legacy-llama.py ./models/codellama-7b --outfile ./models/codellama-7b/ggml-model-f16.gguf --outtype f16 - ./quantize ./models/codellama-7b/ggml-model-f16.gguf ./models/codellama-7b/ggml-model-q4_0.gguf q4_0 - ./quantize ./models/codellama-7b/ggml-model-f16.gguf ./models/codellama-7b/ggml-model-q4_k.gguf q4_k - ./quantize ./models/codellama-7b/ggml-model-f16.gguf ./models/codellama-7b/ggml-model-q8_0.gguf q8_0 + ./llama-quantize ./models/codellama-7b/ggml-model-f16.gguf ./models/codellama-7b/ggml-model-q4_0.gguf q4_0 + ./llama-quantize ./models/codellama-7b/ggml-model-f16.gguf ./models/codellama-7b/ggml-model-q4_k.gguf q4_k + ./llama-quantize ./models/codellama-7b/ggml-model-f16.gguf ./models/codellama-7b/ggml-model-q8_0.gguf q8_0 fi if [ "$1" -eq "3" ]; then @@ -107,9 +107,9 @@ if [ "$1" -eq "3" ]; then python3 examples/convert-legacy-llama.py ./models/codellama-13b --outfile ./models/codellama-13b/ggml-model-f16.gguf --outtype f16 - ./quantize ./models/codellama-13b/ggml-model-f16.gguf ./models/codellama-13b/ggml-model-q4_0.gguf q4_0 - ./quantize ./models/codellama-13b/ggml-model-f16.gguf ./models/codellama-13b/ggml-model-q4_k.gguf q4_k - ./quantize ./models/codellama-13b/ggml-model-f16.gguf ./models/codellama-13b/ggml-model-q8_0.gguf q8_0 + ./llama-quantize ./models/codellama-13b/ggml-model-f16.gguf ./models/codellama-13b/ggml-model-q4_0.gguf q4_0 + ./llama-quantize ./models/codellama-13b/ggml-model-f16.gguf ./models/codellama-13b/ggml-model-q4_k.gguf q4_k + ./llama-quantize ./models/codellama-13b/ggml-model-f16.gguf ./models/codellama-13b/ggml-model-q8_0.gguf q8_0 fi if [ "$1" -eq "4" ]; then @@ -122,9 +122,9 @@ if [ "$1" -eq "4" ]; then python3 examples/convert-legacy-llama.py ./models/codellama-34b --outfile ./models/codellama-34b/ggml-model-f16.gguf --outtype f16 - ./quantize ./models/codellama-34b/ggml-model-f16.gguf ./models/codellama-34b/ggml-model-q4_0.gguf q4_0 - ./quantize ./models/codellama-34b/ggml-model-f16.gguf ./models/codellama-34b/ggml-model-q4_k.gguf q4_k - ./quantize ./models/codellama-34b/ggml-model-f16.gguf ./models/codellama-34b/ggml-model-q8_0.gguf q8_0 + ./llama-quantize ./models/codellama-34b/ggml-model-f16.gguf ./models/codellama-34b/ggml-model-q4_0.gguf q4_0 + ./llama-quantize ./models/codellama-34b/ggml-model-f16.gguf ./models/codellama-34b/ggml-model-q4_k.gguf q4_k + ./llama-quantize ./models/codellama-34b/ggml-model-f16.gguf ./models/codellama-34b/ggml-model-q8_0.gguf q8_0 fi if [ "$1" -eq "5" ]; then @@ -137,9 +137,9 @@ if [ "$1" -eq "5" ]; then python3 examples/convert-legacy-llama.py ./models/codellama-7b-instruct --outfile ./models/codellama-7b-instruct/ggml-model-f16.gguf --outtype f16 - ./quantize ./models/codellama-7b-instruct/ggml-model-f16.gguf ./models/codellama-7b-instruct/ggml-model-q4_0.gguf q4_0 - ./quantize ./models/codellama-7b-instruct/ggml-model-f16.gguf ./models/codellama-7b-instruct/ggml-model-q4_k.gguf q4_k - ./quantize ./models/codellama-7b-instruct/ggml-model-f16.gguf ./models/codellama-7b-instruct/ggml-model-q8_0.gguf q8_0 + ./llama-quantize ./models/codellama-7b-instruct/ggml-model-f16.gguf ./models/codellama-7b-instruct/ggml-model-q4_0.gguf q4_0 + ./llama-quantize ./models/codellama-7b-instruct/ggml-model-f16.gguf ./models/codellama-7b-instruct/ggml-model-q4_k.gguf q4_k + ./llama-quantize ./models/codellama-7b-instruct/ggml-model-f16.gguf ./models/codellama-7b-instruct/ggml-model-q8_0.gguf q8_0 fi if [ "$1" -eq "6" ]; then @@ -152,9 +152,9 @@ if [ "$1" -eq "6" ]; then python3 examples/convert-legacy-llama.py ./models/codellama-13b-instruct --outfile ./models/codellama-13b-instruct/ggml-model-f16.gguf --outtype f16 - ./quantize ./models/codellama-13b-instruct/ggml-model-f16.gguf ./models/codellama-13b-instruct/ggml-model-q4_0.gguf q4_0 - ./quantize ./models/codellama-13b-instruct/ggml-model-f16.gguf ./models/codellama-13b-instruct/ggml-model-q4_k.gguf q4_k - ./quantize ./models/codellama-13b-instruct/ggml-model-f16.gguf ./models/codellama-13b-instruct/ggml-model-q8_0.gguf q8_0 + ./llama-quantize ./models/codellama-13b-instruct/ggml-model-f16.gguf ./models/codellama-13b-instruct/ggml-model-q4_0.gguf q4_0 + ./llama-quantize ./models/codellama-13b-instruct/ggml-model-f16.gguf ./models/codellama-13b-instruct/ggml-model-q4_k.gguf q4_k + ./llama-quantize ./models/codellama-13b-instruct/ggml-model-f16.gguf ./models/codellama-13b-instruct/ggml-model-q8_0.gguf q8_0 fi if [ "$1" -eq "7" ]; then @@ -167,9 +167,9 @@ if [ "$1" -eq "7" ]; then python3 examples/convert-legacy-llama.py ./models/codellama-34b-instruct --outfile ./models/codellama-34b-instruct/ggml-model-f16.gguf --outtype f16 - ./quantize ./models/codellama-34b-instruct/ggml-model-f16.gguf ./models/codellama-34b-instruct/ggml-model-q4_0.gguf q4_0 - ./quantize ./models/codellama-34b-instruct/ggml-model-f16.gguf ./models/codellama-34b-instruct/ggml-model-q4_k.gguf q4_k - ./quantize ./models/codellama-34b-instruct/ggml-model-f16.gguf ./models/codellama-34b-instruct/ggml-model-q8_0.gguf q8_0 + ./llama-quantize ./models/codellama-34b-instruct/ggml-model-f16.gguf ./models/codellama-34b-instruct/ggml-model-q4_0.gguf q4_0 + ./llama-quantize ./models/codellama-34b-instruct/ggml-model-f16.gguf ./models/codellama-34b-instruct/ggml-model-q4_k.gguf q4_k + ./llama-quantize ./models/codellama-34b-instruct/ggml-model-f16.gguf ./models/codellama-34b-instruct/ggml-model-q8_0.gguf q8_0 fi if [ "$1" -eq "1" ]; then @@ -181,22 +181,22 @@ if [ "$1" -eq "1" ]; then ../scripts/get-wikitext-2.sh unzip wikitext-2-raw-v1.zip - make -j && ./bin/perplexity -m ../models/tinyllama-1b/ggml-model-f16.gguf -f ./wikitext-2-raw/wiki.test.raw -ngl 100 --chunks 32 + make -j && ./bin/llama-perplexity -m ../models/tinyllama-1b/ggml-model-f16.gguf -f ./wikitext-2-raw/wiki.test.raw -ngl 100 --chunks 32 # batched cd /workspace/llama.cpp - LLAMA_CUDA=1 make -j && ./batched ./models/tinyllama-1b/ggml-model-f16.gguf "Hello, my name is" 8 128 999 + LLAMA_CUDA=1 make -j && ./llama-batched ./models/tinyllama-1b/ggml-model-f16.gguf "Hello, my name is" 8 128 999 # batched-bench cd /workspace/llama.cpp - LLAMA_CUDA=1 make -j && ./batched-bench ./models/tinyllama-1b/ggml-model-f16.gguf 4608 1 99 0 512 128 1,2,3,4,5,6,7,8,16,32 + LLAMA_CUDA=1 make -j && ./llama-batched-bench ./models/tinyllama-1b/ggml-model-f16.gguf 4608 1 99 0 512 128 1,2,3,4,5,6,7,8,16,32 # parallel cd /workspace/llama.cpp - LLAMA_CUDA=1 make -j && ./parallel -m ./models/tinyllama-1b/ggml-model-f16.gguf -t 1 -ngl 100 -c 4096 -b 512 -s 1 -np 8 -ns 128 -n 100 -cb + LLAMA_CUDA=1 make -j && ./llama-parallel -m ./models/tinyllama-1b/ggml-model-f16.gguf -t 1 -ngl 100 -c 4096 -b 512 -s 1 -np 8 -ns 128 -n 100 -cb fi @@ -204,10 +204,10 @@ fi #if [ "$1" -eq "7" ]; then # cd /workspace/llama.cpp # -# LLAMA_CUDA=1 make -j && ./speculative -m ./models/codellama-34b-instruct/ggml-model-f16.gguf -md ./models/codellama-7b-instruct/ggml-model-q4_0.gguf -p "# Dijkstra's shortest path algorithm in Python (4 spaces indentation) + complexity analysis:\n\n" -e -ngl 999 -ngld 999 -t 4 -n 512 -c 4096 -s 21 --draft 16 -np 1 --temp 0.0 +# LLAMA_CUDA=1 make -j && ./llama-speculative -m ./models/codellama-34b-instruct/ggml-model-f16.gguf -md ./models/codellama-7b-instruct/ggml-model-q4_0.gguf -p "# Dijkstra's shortest path algorithm in Python (4 spaces indentation) + complexity analysis:\n\n" -e -ngl 999 -ngld 999 -t 4 -n 512 -c 4096 -s 21 --draft 16 -np 1 --temp 0.0 #fi # more benches -#LLAMA_CUDA=1 make -j && ./batched-bench ./models/codellama-7b/ggml-model-q4_k.gguf 4096 1 99 1 512,3200 128,128,800 1 -#LLAMA_CUDA=1 make -j && ./batched-bench ./models/codellama-13b/ggml-model-q4_k.gguf 4096 1 99 1 512,3200 128,128,800 1 +#LLAMA_CUDA=1 make -j && ./llama-batched-bench ./models/codellama-7b/ggml-model-q4_k.gguf 4096 1 99 1 512,3200 128,128,800 1 +#LLAMA_CUDA=1 make -j && ./llama-batched-bench ./models/codellama-13b/ggml-model-q4_k.gguf 4096 1 99 1 512,3200 128,128,800 1 diff --git a/scripts/qnt-all.sh b/scripts/qnt-all.sh index b4c2a159e..bc43738a2 100755 --- a/scripts/qnt-all.sh +++ b/scripts/qnt-all.sh @@ -26,5 +26,5 @@ set -e mkdir -p ${out} for q in ${qnt[@]}; do - time ./bin/quantize ../models/${model}/ggml-model-f16.gguf ../models/${model}/ggml-model-${q}.gguf ${q} 2>&1 ${args} | tee ${out}/qnt-${q}.txt + time ./bin/llama-quantize ../models/${model}/ggml-model-f16.gguf ../models/${model}/ggml-model-${q}.gguf ${q} 2>&1 ${args} | tee ${out}/qnt-${q}.txt done diff --git a/scripts/run-all-ppl.sh b/scripts/run-all-ppl.sh index e04d61d7f..e15f74f1b 100755 --- a/scripts/run-all-ppl.sh +++ b/scripts/run-all-ppl.sh @@ -26,5 +26,5 @@ out="../tmp/results-${model}" mkdir -p ${out} for q in ${qnt[@]}; do - time ./bin/perplexity -m ../models/${model}/ggml-model-f16.gguf -f ./wiki.test.raw ${args} 2>&1 | tee ${out}/ppl-${q}.txt + time ./bin/llama-perplexity -m ../models/${model}/ggml-model-f16.gguf -f ./wiki.test.raw ${args} 2>&1 | tee ${out}/ppl-${q}.txt done diff --git a/scripts/run-with-preset.py b/scripts/run-with-preset.py index 0d7219113..ee21eab37 100755 --- a/scripts/run-with-preset.py +++ b/scripts/run-with-preset.py @@ -10,7 +10,7 @@ import yaml logger = logging.getLogger("run-with-preset") -CLI_ARGS_MAIN_PERPLEXITY = [ +CLI_ARGS_LLAMA_CLI_PERPLEXITY = [ "batch-size", "cfg-negative-prompt", "cfg-scale", "chunks", "color", "ctx-size", "escape", "export", "file", "frequency-penalty", "grammar", "grammar-file", "hellaswag", "hellaswag-tasks", "ignore-eos", "in-prefix", "in-prefix-bos", "in-suffix", @@ -29,7 +29,7 @@ CLI_ARGS_LLAMA_BENCH = [ "n-prompt", "output", "repetitions", "tensor-split", "threads", "verbose" ] -CLI_ARGS_SERVER = [ +CLI_ARGS_LLAMA_SERVER = [ "alias", "batch-size", "ctx-size", "embedding", "host", "memory-f32", "lora", "lora-base", "low-vram", "main-gpu", "mlock", "model", "n-gpu-layers", "n-probs", "no-mmap", "no-mul-mat-q", "numa", "path", "port", "rope-freq-base", "timeout", "rope-freq-scale", "tensor-split", @@ -37,7 +37,7 @@ CLI_ARGS_SERVER = [ ] description = """Run llama.cpp binaries with presets from YAML file(s). -To specify which binary should be run, specify the "binary" property (main, perplexity, llama-bench, and server are supported). +To specify which binary should be run, specify the "binary" property (llama-cli, llama-perplexity, llama-bench, and llama-server are supported). To get a preset file template, run a llama.cpp binary with the "--logdir" CLI argument. Formatting considerations: @@ -77,19 +77,19 @@ for yaml_file in known_args.yaml_files: props = {prop.replace("_", "-"): val for prop, val in props.items()} -binary = props.pop("binary", "main") +binary = props.pop("binary", "llama-cli") if known_args.binary: binary = known_args.binary if os.path.exists(f"./{binary}"): binary = f"./{binary}" -if binary.lower().endswith("main") or binary.lower().endswith("perplexity"): - cli_args = CLI_ARGS_MAIN_PERPLEXITY +if binary.lower().endswith("llama-cli") or binary.lower().endswith("llama-perplexity"): + cli_args = CLI_ARGS_LLAMA_CLI_PERPLEXITY elif binary.lower().endswith("llama-bench"): cli_args = CLI_ARGS_LLAMA_BENCH -elif binary.lower().endswith("server"): - cli_args = CLI_ARGS_SERVER +elif binary.lower().endswith("llama-server"): + cli_args = CLI_ARGS_LLAMA_SERVER else: logger.error(f"Unknown binary: {binary}") sys.exit(1) diff --git a/scripts/server-llm.sh b/scripts/server-llm.sh index b3715e204..199232440 100644 --- a/scripts/server-llm.sh +++ b/scripts/server-llm.sh @@ -380,13 +380,13 @@ fi if [[ "$backend" == "cuda" ]]; then printf "[+] Building with CUDA backend\n" - LLAMA_CUDA=1 make -j server $log + LLAMA_CUDA=1 make -j llama-server $log elif [[ "$backend" == "cpu" ]]; then printf "[+] Building with CPU backend\n" - make -j server $log + make -j llama-server $log elif [[ "$backend" == "metal" ]]; then printf "[+] Building with Metal backend\n" - make -j server $log + make -j llama-server $log else printf "[-] Unknown backend: %s\n" "$backend" exit 1 @@ -413,6 +413,6 @@ if [[ $verbose -eq 1 ]]; then args="$args --verbose" fi -./server -m "../$wfile" --host 0.0.0.0 --port "$port" -c $n_kv -np "$n_parallel" $args +./llama-server -m "../$wfile" --host 0.0.0.0 --port "$port" -c $n_kv -np "$n_parallel" $args exit 0 From f578b86b2123d0f92afbaa98a031df4d4464e582 Mon Sep 17 00:00:00 2001 From: slaren Date: Thu, 13 Jun 2024 03:11:35 +0200 Subject: [PATCH 27/37] move BLAS to a separate backend (#6210) * move BLAS to a separate backend * rename GGML_USE_OPENBLAS to GGML_USE_BLAS * alloc : reuse same buffer when the same buffer type if used multiple times * set number of threads automatically for openblas and blis * sched : print assignments when GGML_SCHED_DEBUG env variable is set * sched : allow ops with weights on an incompatible buffer type This will cause the weight to be copied to a backend that supports the op, which is very costly. The weight should have been stored in a buffer of a backend that can run the op, but llama.cpp cannot do this automatically at the moment. --------- Co-authored-by: Georgi Gerganov --- CMakeLists.txt | 23 +- Makefile | 27 +- examples/llama-bench/llama-bench.cpp | 1 + ggml-alloc.c | 98 ++++++-- ggml-backend-impl.h | 28 ++- ggml-backend.c | 242 +++++++++++++----- ggml-backend.h | 6 +- ggml-blas.cpp | 363 +++++++++++++++++++++++++++ ggml-blas.h | 23 ++ ggml-cuda.cu | 44 ++-- ggml-kompute.cpp | 13 +- ggml-metal.m | 15 +- ggml-rpc.cpp | 21 +- ggml-sycl.cpp | 28 +-- ggml-vulkan.cpp | 26 +- ggml.c | 205 ++------------- llama.cpp | 37 ++- 17 files changed, 821 insertions(+), 379 deletions(-) create mode 100644 ggml-blas.cpp create mode 100644 ggml-blas.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e280f87d..08481334f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,8 +39,12 @@ endif() if (APPLE) set(LLAMA_METAL_DEFAULT ON) + set(LLAMA_BLAS_DEFAULT ON) + set(LLAMA_BLAS_VENDOR_DEFAULT "Apple") else() set(LLAMA_METAL_DEFAULT OFF) + set(LLAMA_BLAS_DEFAULT OFF) + set(LLAMA_BLAS_VENDOR_DEFAULT "Generic") endif() set(LLAMA_LLAMAFILE_DEFAULT ON) @@ -91,9 +95,10 @@ endif() # 3rd party libs option(LLAMA_ACCELERATE "llama: enable Accelerate framework" ON) -option(LLAMA_BLAS "llama: use BLAS" OFF) +option(LLAMA_BLAS "llama: use BLAS" ${LLAMA_BLAS_DEFAULT}) +set(LLAMA_BLAS_VENDOR ${LLAMA_BLAS_VENDOR_DEFAULT} CACHE STRING + "llama: BLAS library vendor") option(LLAMA_LLAMAFILE "llama: use llamafile SGEMM" ${LLAMA_LLAMAFILE_DEFAULT}) -set(LLAMA_BLAS_VENDOR "Generic" CACHE STRING "llama: BLAS library vendor") option(LLAMA_CUDA "llama: use CUDA" OFF) option(LLAMA_CUBLAS "llama: use CUDA (deprecated, use LLAMA_CUDA)" OFF) option(LLAMA_CUDA_FORCE_DMMV "llama: use dmmv instead of mmvq CUDA kernels" OFF) @@ -311,9 +316,9 @@ if (LLAMA_BLAS) if (LLAMA_STATIC) set(BLA_STATIC ON) endif() - if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) - set(BLA_SIZEOF_INTEGER 8) - endif() + #if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) + # set(BLA_SIZEOF_INTEGER 8) + #endif() set(BLA_VENDOR ${LLAMA_BLAS_VENDOR}) find_package(BLAS) @@ -321,7 +326,7 @@ if (LLAMA_BLAS) if (BLAS_FOUND) message(STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES}") - if ("${BLAS_INCLUDE_DIRS}" STREQUAL "") + if (("${BLAS_INCLUDE_DIRS}" STREQUAL "") AND NOT (${LLAMA_BLAS_VENDOR} MATCHES "Apple")) # BLAS_INCLUDE_DIRS is missing in FindBLAS.cmake. # see https://gitlab.kitware.com/cmake/cmake/-/issues/20268 find_package(PkgConfig REQUIRED) @@ -374,12 +379,15 @@ if (LLAMA_BLAS) add_compile_options(${BLAS_LINKER_FLAGS}) - add_compile_definitions(GGML_USE_OPENBLAS) + add_compile_definitions(GGML_USE_BLAS) if (${BLAS_INCLUDE_DIRS} MATCHES "mkl" AND (${LLAMA_BLAS_VENDOR} MATCHES "Generic" OR ${LLAMA_BLAS_VENDOR} MATCHES "Intel")) add_compile_definitions(GGML_BLAS_USE_MKL) endif() + set(GGML_HEADERS_BLAS ggml-blas.h) + set(GGML_SOURCES_BLAS ggml-blas.cpp) + set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} ${BLAS_LIBRARIES}) set(LLAMA_EXTRA_INCLUDES ${LLAMA_EXTRA_INCLUDES} ${BLAS_INCLUDE_DIRS}) else() @@ -1258,6 +1266,7 @@ add_library(ggml OBJECT ${GGML_SOURCES_KOMPUTE} ${GGML_HEADERS_KOMPUTE} ${GGML_SOURCES_VULKAN} ${GGML_HEADERS_VULKAN} ${GGML_SOURCES_ROCM} ${GGML_HEADERS_ROCM} + ${GGML_SOURCES_BLAS} ${GGML_HEADERS_BLAS} ${GGML_SOURCES_LLAMAFILE} ${GGML_HEADERS_LLAMAFILE} ) diff --git a/Makefile b/Makefile index a4cab1bb2..744fe5739 100644 --- a/Makefile +++ b/Makefile @@ -440,10 +440,11 @@ ifndef LLAMA_NO_ACCELERATE # Mac OS - include Accelerate framework. # `-framework Accelerate` works both with Apple Silicon and Mac Intel ifeq ($(UNAME_S),Darwin) - MK_CPPFLAGS += -DGGML_USE_ACCELERATE + MK_CPPFLAGS += -DGGML_USE_ACCELERATE -DGGML_USE_BLAS MK_CPPFLAGS += -DACCELERATE_NEW_LAPACK MK_CPPFLAGS += -DACCELERATE_LAPACK_ILP64 MK_LDFLAGS += -framework Accelerate + OBJS += ggml-blas.o endif endif # LLAMA_NO_ACCELERATE @@ -454,21 +455,30 @@ ifndef LLAMA_NO_OPENMP endif # LLAMA_NO_OPENMP ifdef LLAMA_OPENBLAS - MK_CPPFLAGS += -DGGML_USE_OPENBLAS $(shell pkg-config --cflags-only-I openblas) + MK_CPPFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas) MK_CFLAGS += $(shell pkg-config --cflags-only-other openblas) MK_LDFLAGS += $(shell pkg-config --libs openblas) + OBJS += ggml-blas.o endif # LLAMA_OPENBLAS +ifdef LLAMA_OPENBLAS64 + MK_CPPFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas64) + MK_CFLAGS += $(shell pkg-config --cflags-only-other openblas64) + MK_LDFLAGS += $(shell pkg-config --libs openblas64) + OBJS += ggml-blas.o +endif # LLAMA_OPENBLAS64 + +ifdef LLAMA_BLIS + MK_CPPFLAGS += -DGGML_USE_BLAS -I/usr/local/include/blis -I/usr/include/blis + MK_LDFLAGS += -lblis -L/usr/local/lib + OBJS += ggml-blas.o +endif # LLAMA_BLIS + ifndef LLAMA_NO_LLAMAFILE MK_CPPFLAGS += -DGGML_USE_LLAMAFILE OBJS += sgemm.o endif -ifdef LLAMA_BLIS - MK_CPPFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/blis -I/usr/include/blis - MK_LDFLAGS += -lblis -L/usr/local/lib -endif # LLAMA_BLIS - ifdef LLAMA_RPC MK_CPPFLAGS += -DGGML_USE_RPC OBJS += ggml-rpc.o @@ -776,6 +786,9 @@ ggml-backend.o: ggml-backend.c ggml.h ggml-backend.h ggml-quants.o: ggml-quants.c ggml.h ggml-quants.h ggml-common.h $(CC) $(CFLAGS) -c $< -o $@ +ggml-blas.o: ggml-blas.cpp ggml-blas.h + $(CXX) $(CXXFLAGS) -c $< -o $@ + unicode.o: unicode.cpp unicode.h $(CXX) $(CXXFLAGS) -c $< -o $@ diff --git a/examples/llama-bench/llama-bench.cpp b/examples/llama-bench/llama-bench.cpp index 61f5a5a09..61dd1d71a 100644 --- a/examples/llama-bench/llama-bench.cpp +++ b/examples/llama-bench/llama-bench.cpp @@ -293,6 +293,7 @@ static cmd_params parse_cmd_params(int argc, char ** argv) { params.output_format = cmd_params_defaults.output_format; params.output_format_stderr = cmd_params_defaults.output_format_stderr; params.reps = cmd_params_defaults.reps; + params.numa = cmd_params_defaults.numa; for (int i = 1; i < argc; i++) { arg = argv[i]; diff --git a/ggml-alloc.c b/ggml-alloc.c index eb75962d4..bd367c42d 100644 --- a/ggml-alloc.c +++ b/ggml-alloc.c @@ -339,6 +339,7 @@ struct hash_node { }; struct tensor_alloc { + int buffer_id; size_t offset; size_t size_max; // 0 = pre-allocated, unused, or view }; @@ -349,7 +350,6 @@ struct leaf_alloc { }; struct node_alloc { - int buffer_id; struct tensor_alloc dst; struct tensor_alloc src[GGML_MAX_SRC]; }; @@ -386,8 +386,19 @@ ggml_gallocr_t ggml_gallocr_new_n(ggml_backend_buffer_type_t * bufts, int n_bufs for (int i = 0; i < n_bufs; i++) { galloc->bufts[i] = bufts[i]; galloc->buffers[i] = NULL; - size_t alignment = ggml_backend_buft_get_alignment(bufts[i]); - galloc->buf_tallocs[i] = ggml_dyn_tallocr_new(alignment); + + // check if the same buffer type is used multiple times and reuse the same allocator + for (int j = 0; j < i; j++) { + if (bufts[i] == bufts[j]) { + galloc->buf_tallocs[i] = galloc->buf_tallocs[j]; + break; + } + } + + if (galloc->buf_tallocs[i] == NULL) { + size_t alignment = ggml_backend_buft_get_alignment(bufts[i]); + galloc->buf_tallocs[i] = ggml_dyn_tallocr_new(alignment); + } } galloc->n_buffers = n_bufs; @@ -405,10 +416,30 @@ void ggml_gallocr_free(ggml_gallocr_t galloc) { for (int i = 0; i < galloc->n_buffers; i++) { if (galloc->buffers != NULL) { - ggml_backend_buffer_free(galloc->buffers[i]); + // skip if already freed + bool freed = false; + for (int j = 0; j < i; j++) { + if (galloc->buffers[j] == galloc->buffers[i]) { + freed = true; + break; + } + } + if (!freed) { + ggml_backend_buffer_free(galloc->buffers[i]); + } } if (galloc->buf_tallocs != NULL) { - ggml_dyn_tallocr_free(galloc->buf_tallocs[i]); + // skip if already freed + bool freed = false; + for (int j = 0; j < i; j++) { + if (galloc->buf_tallocs[j] == galloc->buf_tallocs[i]) { + freed = true; + break; + } + } + if (!freed) { + ggml_dyn_tallocr_free(galloc->buf_tallocs[i]); + } } } @@ -511,17 +542,18 @@ static void ggml_gallocr_allocate_node(ggml_gallocr_t galloc, struct ggml_tensor } } -static void ggml_gallocr_free_node(ggml_gallocr_t galloc, struct ggml_tensor * node, int buffer_id) { +static void ggml_gallocr_free_node(ggml_gallocr_t galloc, struct ggml_tensor * node) { // graph outputs are never freed if (node->flags & GGML_TENSOR_FLAG_OUTPUT) { AT_PRINTF("not freeing output %s\n", node->name); return; } - struct ggml_dyn_tallocr * alloc = galloc->buf_tallocs[buffer_id]; - ggml_backend_buffer_type_t buft = galloc->bufts[buffer_id]; struct hash_node * hn = ggml_gallocr_hash_get(galloc, node); size_t offset = hn->offset; + int buffer_id = hn->buffer_id; + struct ggml_dyn_tallocr * alloc = galloc->buf_tallocs[buffer_id]; + ggml_backend_buffer_type_t buft = galloc->bufts[buffer_id]; size_t size = ggml_backend_buft_get_alloc_size(buft, node); ggml_dyn_tallocr_free_tensor(alloc, offset, size, node); hn->allocated = false; @@ -626,11 +658,11 @@ static void ggml_gallocr_alloc_graph_impl(ggml_gallocr_t galloc, struct ggml_cgr AT_PRINTF("view_src %s: %d children, %d views\n", view_src->name, view_src_hn->n_children, view_src_hn->n_views); if (view_src_hn->n_views == 0 && view_src_hn->n_children == 0 && view_src_hn->allocated) { - ggml_gallocr_free_node(galloc, view_src, buffer_id); + ggml_gallocr_free_node(galloc, view_src); } } else if (p_hn->allocated) { - ggml_gallocr_free_node(galloc, parent, buffer_id); + ggml_gallocr_free_node(galloc, parent); } } AT_PRINTF("\n"); @@ -674,22 +706,25 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c for (int i = 0; i < graph->n_nodes; i++) { struct ggml_tensor * node = graph->nodes[i]; struct node_alloc * node_alloc = &galloc->node_allocs[i]; - node_alloc->buffer_id = get_node_buffer_id(node_buffer_ids, i); if (node->view_src || node->data) { + node_alloc->dst.buffer_id = -1; node_alloc->dst.offset = SIZE_MAX; node_alloc->dst.size_max = 0; } else { struct hash_node * hn = ggml_gallocr_hash_get(galloc, node); - node_alloc->dst.offset = hn->offset; - node_alloc->dst.size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], node); + node_alloc->dst.buffer_id = hn->buffer_id; + node_alloc->dst.offset = hn->offset; + node_alloc->dst.size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], node); } for (int j = 0; j < GGML_MAX_SRC; j++) { struct ggml_tensor * src = node->src[j]; if (!src || src->view_src || src->data) { + node_alloc->src[j].buffer_id = -1; node_alloc->src[j].offset = SIZE_MAX; node_alloc->src[j].size_max = 0; } else { struct hash_node * hn = ggml_gallocr_hash_get(galloc, src); + node_alloc->src[j].buffer_id = hn->buffer_id; node_alloc->src[j].offset = hn->offset; node_alloc->src[j].size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], src); } @@ -706,9 +741,11 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c struct hash_node * hn = ggml_gallocr_hash_get(galloc, leaf); galloc->leaf_allocs[i].buffer_id = hn->buffer_id; if (leaf->view_src || leaf->data) { + galloc->leaf_allocs[i].leaf.buffer_id = -1; galloc->leaf_allocs[i].leaf.offset = SIZE_MAX; galloc->leaf_allocs[i].leaf.size_max = 0; } else { + galloc->leaf_allocs[i].leaf.buffer_id = hn->buffer_id; galloc->leaf_allocs[i].leaf.offset = hn->offset; galloc->leaf_allocs[i].leaf.size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], leaf); } @@ -716,6 +753,14 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c // reallocate buffers if needed for (int i = 0; i < galloc->n_buffers; i++) { + // if the buffer type is used multiple times, we reuse the same buffer + for (int j = 0; j < i; j++) { + if (galloc->buf_tallocs[j] == galloc->buf_tallocs[i]) { + galloc->buffers[i] = galloc->buffers[j]; + break; + } + } + size_t cur_size = galloc->buffers[i] ? ggml_backend_buffer_get_size(galloc->buffers[i]) : 0; size_t new_size = ggml_dyn_tallocr_max_size(galloc->buf_tallocs[i]); @@ -724,6 +769,7 @@ bool ggml_gallocr_reserve_n(ggml_gallocr_t galloc, struct ggml_cgraph * graph, c #ifndef NDEBUG fprintf(stderr, "%s: reallocating %s buffer from size %.02f MiB to %.02f MiB\n", __func__, ggml_backend_buft_name(galloc->bufts[i]), cur_size / 1024.0 / 1024.0, new_size / 1024.0 / 1024.0); #endif + ggml_backend_buffer_free(galloc->buffers[i]); galloc->buffers[i] = ggml_backend_buft_alloc_buffer(galloc->bufts[i], new_size); if (galloc->buffers[i] == NULL) { @@ -740,7 +786,8 @@ bool ggml_gallocr_reserve(ggml_gallocr_t galloc, struct ggml_cgraph *graph) { return ggml_gallocr_reserve_n(galloc, graph, NULL, NULL); } -static void ggml_gallocr_init_tensor(ggml_gallocr_t galloc, struct ggml_tensor * tensor, int buffer_id, struct tensor_alloc * tensor_alloc) { +static void ggml_gallocr_init_tensor(ggml_gallocr_t galloc, struct ggml_tensor * tensor, struct tensor_alloc * tensor_alloc) { + int buffer_id = tensor_alloc->buffer_id; assert(tensor->data || tensor->view_src || ggml_backend_buffer_get_alloc_size(galloc->buffers[buffer_id], tensor) <= tensor_alloc->size_max); if (tensor->view_src != NULL) { @@ -768,8 +815,8 @@ static void ggml_gallocr_init_tensor(ggml_gallocr_t galloc, struct ggml_tensor * } } -static bool ggml_gallocr_node_needs_realloc(ggml_gallocr_t galloc, struct ggml_tensor * node, struct node_alloc * nalloc, struct tensor_alloc * talloc) { - ggml_backend_buffer_type_t buft = galloc->bufts[nalloc->buffer_id]; +static bool ggml_gallocr_node_needs_realloc(ggml_gallocr_t galloc, struct ggml_tensor * node, struct tensor_alloc * talloc) { + ggml_backend_buffer_type_t buft = talloc->buffer_id != -1 ? galloc->bufts[talloc->buffer_id] : NULL; size_t node_size = (node->data || node->view_src) ? 0 : ggml_backend_buft_get_alloc_size(buft, node); return talloc->size_max >= node_size; } @@ -793,7 +840,7 @@ static bool ggml_gallocr_needs_realloc(ggml_gallocr_t galloc, struct ggml_cgraph struct ggml_tensor * node = graph->nodes[i]; struct node_alloc * node_alloc = &galloc->node_allocs[i]; - if (!ggml_gallocr_node_needs_realloc(galloc, node, node_alloc, &node_alloc->dst)) { + if (!ggml_gallocr_node_needs_realloc(galloc, node, &node_alloc->dst)) { #ifndef NDEBUG fprintf(stderr, "%s: node %s is not valid\n", __func__, node->name); #endif @@ -805,7 +852,7 @@ static bool ggml_gallocr_needs_realloc(ggml_gallocr_t galloc, struct ggml_cgraph if (src == NULL) { continue; } - if (!ggml_gallocr_node_needs_realloc(galloc, src, node_alloc, &node_alloc->src[j])) { + if (!ggml_gallocr_node_needs_realloc(galloc, src, &node_alloc->src[j])) { #ifndef NDEBUG fprintf(stderr, "%s: src %d (%s) of node %s is not valid\n", __func__, j, src->name, node->name); #endif @@ -846,7 +893,7 @@ bool ggml_gallocr_alloc_graph(ggml_gallocr_t galloc, struct ggml_cgraph * graph) for (int i = 0; i < graph->n_leafs; i++) { struct ggml_tensor * leaf = graph->leafs[i]; struct leaf_alloc * leaf_alloc = &galloc->leaf_allocs[i]; - ggml_gallocr_init_tensor(galloc, leaf, leaf_alloc->buffer_id, &leaf_alloc->leaf); + ggml_gallocr_init_tensor(galloc, leaf, &leaf_alloc->leaf); } // nodes for (int i = 0; i < graph->n_nodes; i++) { @@ -857,9 +904,9 @@ bool ggml_gallocr_alloc_graph(ggml_gallocr_t galloc, struct ggml_cgraph * graph) if (src == NULL) { continue; } - ggml_gallocr_init_tensor(galloc, src, node_alloc->buffer_id, &node_alloc->src[j]); + ggml_gallocr_init_tensor(galloc, src, &node_alloc->src[j]); } - ggml_gallocr_init_tensor(galloc, node, node_alloc->buffer_id, &node_alloc->dst); + ggml_gallocr_init_tensor(galloc, node, &node_alloc->dst); } return true; @@ -871,6 +918,15 @@ size_t ggml_gallocr_get_buffer_size(ggml_gallocr_t galloc, int buffer_id) { if (galloc->buffers[buffer_id] == NULL) { return 0; } + + for (int i = 0; i < buffer_id; i++) { + if (galloc->buffers[i] == galloc->buffers[buffer_id]) { + // this buffer is the same as a previous one due to the same buffer type being used multiple times + // only return the buffer size the first time it appears to avoid double counting + return 0; + } + } + return ggml_backend_buffer_get_size(galloc->buffers[buffer_id]); } diff --git a/ggml-backend-impl.h b/ggml-backend-impl.h index f121e1de4..36ca37086 100644 --- a/ggml-backend-impl.h +++ b/ggml-backend-impl.h @@ -17,13 +17,15 @@ extern "C" { struct ggml_backend_buffer_type_i { const char * (*GGML_CALL get_name) (ggml_backend_buffer_type_t buft); + // allocate a buffer of this type ggml_backend_buffer_t (*GGML_CALL alloc_buffer) (ggml_backend_buffer_type_t buft, size_t size); - size_t (*GGML_CALL get_alignment) (ggml_backend_buffer_type_t buft); // tensor alignment - size_t (*GGML_CALL get_max_size) (ggml_backend_buffer_type_t buft); // allocation max size - size_t (*GGML_CALL get_alloc_size) (ggml_backend_buffer_type_t buft, const struct ggml_tensor * tensor); // data size needed to allocate the tensor, including padding - bool (*GGML_CALL supports_backend)(ggml_backend_buffer_type_t buft, ggml_backend_t backend); // check if the buffer type is usable by the backend + // tensor alignment + size_t (*GGML_CALL get_alignment) (ggml_backend_buffer_type_t buft); + // max buffer size that can be allocated + size_t (*GGML_CALL get_max_size) (ggml_backend_buffer_type_t buft); + // data size needed to allocate the tensor, including padding + size_t (*GGML_CALL get_alloc_size) (ggml_backend_buffer_type_t buft, const struct ggml_tensor * tensor); // check if tensor data is in host memory - // should be equivalent to supports_backend(buft, ggml_backend_cpu_init()) bool (*GGML_CALL is_host) (ggml_backend_buffer_type_t buft); }; @@ -92,27 +94,37 @@ extern "C" { void (*GGML_CALL synchronize)(ggml_backend_t backend); // compute graph with a plan (not used currently) + // create a new plan for a graph ggml_backend_graph_plan_t (*GGML_CALL graph_plan_create) (ggml_backend_t backend, const struct ggml_cgraph * cgraph); void (*GGML_CALL graph_plan_free) (ggml_backend_t backend, ggml_backend_graph_plan_t plan); + // update the plan with a new graph - this should be faster than creating a new plan when the graph has the same topology + void (*GGML_CALL graph_plan_update) (ggml_backend_t backend, ggml_backend_graph_plan_t plan, const struct ggml_cgraph * cgraph); + // compute the graph with the plan + enum ggml_status (*GGML_CALL graph_plan_compute)(ggml_backend_t backend, ggml_backend_graph_plan_t plan); - // compute graph with a plan - enum ggml_status (*GGML_CALL graph_plan_compute)(ggml_backend_t backend, ggml_backend_graph_plan_t plan); // compute graph without a plan (async) enum ggml_status (*GGML_CALL graph_compute) (ggml_backend_t backend, struct ggml_cgraph * cgraph); - // check if the backend supports an operation + // check if the backend can compute an operation bool (*GGML_CALL supports_op)(ggml_backend_t backend, const struct ggml_tensor * op); + // check if the backend can use tensors allocated in a buffer type + bool (*GGML_CALL supports_buft)(ggml_backend_t backend, ggml_backend_buffer_type_t buft); + // check if the backend wants to run an operation, even if the weights are allocated in a CPU buffer // these should be expensive operations with large batch sizes that may benefit from running on this backend // even if the weight has to be copied from the CPU temporarily bool (*GGML_CALL offload_op)(ggml_backend_t backend, const struct ggml_tensor * op); // (optional) event synchronization + // create a new event that can record events on this backend instance ggml_backend_event_t (*GGML_CALL event_new) (ggml_backend_t backend); void (*GGML_CALL event_free) (ggml_backend_event_t event); + // record an event on the backend instance that created it void (*GGML_CALL event_record) (ggml_backend_event_t event); + // wait for an event on on a different backend instance void (*GGML_CALL event_wait) (ggml_backend_t backend, ggml_backend_event_t event); + // block until an event is recorded void (*GGML_CALL event_synchronize) (ggml_backend_event_t event); }; diff --git a/ggml-backend.c b/ggml-backend.c index 05737ed69..2bec7bea3 100644 --- a/ggml-backend.c +++ b/ggml-backend.c @@ -44,10 +44,6 @@ GGML_CALL size_t ggml_backend_buft_get_alloc_size(ggml_backend_buffer_type_t buf return ggml_nbytes(tensor); } -bool ggml_backend_buft_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - return buft->iface.supports_backend(buft, backend); -} - bool ggml_backend_buft_is_host(ggml_backend_buffer_type_t buft) { if (buft->iface.is_host) { return buft->iface.is_host(buft); @@ -286,6 +282,10 @@ bool ggml_backend_supports_op(ggml_backend_t backend, const struct ggml_tensor * return backend->iface.supports_op(backend, op); } +bool ggml_backend_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + return backend->iface.supports_buft(backend, buft); +} + bool ggml_backend_offload_op(ggml_backend_t backend, const struct ggml_tensor * op) { if (backend->iface.offload_op != NULL) { return backend->iface.offload_op(backend, op); @@ -639,12 +639,6 @@ GGML_CALL static size_t ggml_backend_cpu_buffer_type_get_alignment(ggml_backend_ GGML_UNUSED(buft); } -GGML_CALL static bool ggml_backend_cpu_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - return ggml_backend_is_cpu(backend); - - GGML_UNUSED(buft); -} - GGML_CALL static bool ggml_backend_cpu_buffer_type_is_host(ggml_backend_buffer_type_t buft) { return true; @@ -659,7 +653,6 @@ GGML_CALL ggml_backend_buffer_type_t ggml_backend_cpu_buffer_type(void) { /* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment, /* .get_max_size = */ NULL, // defaults to SIZE_MAX /* .get_alloc_size = */ NULL, // defaults to ggml_nbytes - /* .supports_backend = */ ggml_backend_cpu_buffer_type_supports_backend, /* .is_host = */ ggml_backend_cpu_buffer_type_is_host, }, /* .context = */ NULL, @@ -715,7 +708,6 @@ ggml_backend_buffer_type_t ggml_backend_cpu_hbm_buffer_type(void) { /* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment, /* .get_max_size = */ NULL, // defaults to SIZE_MAX /* .get_alloc_size = */ NULL, // defaults to ggml_nbytes - /* .supports_backend = */ ggml_backend_cpu_buffer_type_supports_backend, /* .is_host = */ ggml_backend_cpu_buffer_type_is_host, }, /* .context = */ NULL, @@ -836,6 +828,12 @@ GGML_CALL static bool ggml_backend_cpu_supports_op(ggml_backend_t backend, const GGML_UNUSED(backend); } +GGML_CALL static bool ggml_backend_cpu_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + return ggml_backend_buft_is_host(buft); + + GGML_UNUSED(backend); +} + static struct ggml_backend_i cpu_backend_i = { /* .get_name = */ ggml_backend_cpu_name, /* .free = */ ggml_backend_cpu_free, @@ -846,9 +844,11 @@ static struct ggml_backend_i cpu_backend_i = { /* .synchronize = */ NULL, /* .graph_plan_create = */ ggml_backend_cpu_graph_plan_create, /* .graph_plan_free = */ ggml_backend_cpu_graph_plan_free, + /* .graph_plan_update = */ NULL, /* .graph_plan_compute = */ ggml_backend_cpu_graph_plan_compute, /* .graph_compute = */ ggml_backend_cpu_graph_compute, /* .supports_op = */ ggml_backend_cpu_supports_op, + /* .supports_buft = */ ggml_backend_cpu_supports_buft, /* .offload_op = */ NULL, /* .event_new = */ NULL, /* .event_free = */ NULL, @@ -1055,6 +1055,9 @@ struct ggml_backend_sched { int * node_backend_ids; // [graph_size] int * leaf_backend_ids; // [graph_size] + int * prev_node_backend_ids; // [graph_size] + int * prev_leaf_backend_ids; // [graph_size] + // copy of the graph with modified inputs struct ggml_cgraph * graph; @@ -1075,6 +1078,8 @@ struct ggml_backend_sched { ggml_backend_sched_eval_callback callback_eval; void * callback_eval_user_data; + bool debug; + // align context_buffer to GGML_MEM_ALIGN #ifdef _MSC_VER __declspec(align(GGML_MEM_ALIGN)) @@ -1097,22 +1102,24 @@ static int ggml_backend_sched_backend_id(ggml_backend_sched_t sched, ggml_backen return -1; } -static int ggml_backend_sched_backend_from_buffer(ggml_backend_sched_t sched, const struct ggml_tensor * tensor) { +static int ggml_backend_sched_backend_from_buffer(ggml_backend_sched_t sched, const struct ggml_tensor * tensor, const struct ggml_tensor * op) { ggml_backend_buffer_t buffer = tensor->buffer; if (buffer == NULL) { return -1; } - // find highest prio backend that supports the buffer type + // find highest prio backend that supports the buffer type and the op for (int i = 0; i < sched->n_backends; i++) { - if (ggml_backend_buft_supports_backend(buffer->buft, sched->backends[i])) { + if (ggml_backend_supports_buft(sched->backends[i], buffer->buft) && + ggml_backend_supports_op(sched->backends[i], op)) { return i; } } - fprintf(stderr, "%s: error: no backend supports buffer type %s used in tensor %s\n", - __func__, ggml_backend_buffer_name(buffer), tensor->name); - GGML_ASSERT(false); +#ifndef NDEBUG + fprintf(stderr, "%s: warning: no backend supports op %s with a weight with buffer type %s used in tensor %s, the weight will need to be copied\n", + __func__, ggml_op_desc(tensor), ggml_backend_buffer_name(buffer), tensor->name); +#endif return -1; } @@ -1131,7 +1138,7 @@ static int ggml_backend_sched_backend_id_from_cur(ggml_backend_sched_t sched, st // TODO: use supports_op to check if the backend supports the op // assign pre-allocated nodes to their backend - int cur_backend_id = ggml_backend_sched_backend_from_buffer(sched, tensor); + int cur_backend_id = ggml_backend_sched_backend_from_buffer(sched, tensor, tensor); if (cur_backend_id != -1) { SET_CAUSE(tensor, "1.dst"); return cur_backend_id; @@ -1139,7 +1146,7 @@ static int ggml_backend_sched_backend_id_from_cur(ggml_backend_sched_t sched, st // view_src if (tensor->view_src != NULL) { - cur_backend_id = ggml_backend_sched_backend_from_buffer(sched, tensor->view_src); + cur_backend_id = ggml_backend_sched_backend_from_buffer(sched, tensor->view_src, tensor); if (cur_backend_id != -1) { SET_CAUSE(tensor, "1.vsrc"); return cur_backend_id; @@ -1161,7 +1168,7 @@ static int ggml_backend_sched_backend_id_from_cur(ggml_backend_sched_t sched, st continue; } if (src->buffer != NULL && src->buffer->usage == GGML_BACKEND_BUFFER_USAGE_WEIGHTS) { - int src_backend_id = ggml_backend_sched_backend_from_buffer(sched, src); + int src_backend_id = ggml_backend_sched_backend_from_buffer(sched, src, tensor); // check if a backend with higher prio wants to offload the op if (src_backend_id == sched->n_backends - 1) { for (int b = 0; b < src_backend_id; b++) { @@ -1223,10 +1230,33 @@ static void ggml_backend_sched_print_assignments(ggml_backend_sched_t sched, str } } -//#define DEBUG_PASS1 -//#define DEBUG_PASS2 -//#define DEBUG_PASS3 -//#define DEBUG_PASS4 +static bool ggml_backend_sched_buffer_supported(ggml_backend_sched_t sched, struct ggml_tensor * t, int backend_id) { + ggml_backend_buffer_t buf = t->view_src ? t->view_src->buffer : t->buffer; + ggml_backend_buffer_type_t buft = NULL; + + if (buf) { + // the tensor is already allocated + buft = buf->buft; + } else { + // see if the tensor already has a backend assigned, and use the buffer type of that backend + int tensor_backend_id = tensor_backend_id(t); + if (tensor_backend_id == -1 && t->view_src) { + tensor_backend_id = tensor_backend_id(t->view_src); + } + if (tensor_backend_id != -1) { + buft = sched->bufts[tensor_backend_id]; + } + } + + return buft != NULL && ggml_backend_supports_buft(sched->backends[backend_id], buft); +} + +static void ggml_backend_sched_set_if_supported(ggml_backend_sched_t sched, struct ggml_tensor * node, int cur_backend_id, int * node_backend_id) { + if (ggml_backend_supports_op(sched->backends[cur_backend_id], node)) { + *node_backend_id = cur_backend_id; + SET_CAUSE(node, "2.sup"); + } +} // assigns backends to ops and splits the graph into subgraphs that can be computed on the same backend static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct ggml_cgraph * graph) { @@ -1280,17 +1310,13 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg } } } -#ifdef DEBUG_PASS1 - fprintf(stderr, "PASS 1 ASSIGNMENTS\n"); ggml_backend_sched_print_assignments(sched, graph); -#endif // pass 2: expand current backend assignments // assign the same backend to adjacent nodes // expand gpu backends (i.e. non last prio) up and down, ignoring cpu (the lowest priority backend) // thus, cpu will never be used unless weights are on cpu, or there are no gpu ops between cpu ops - - - // pass 2.2 expand gpu down + // ops unsupported by the backend being expanded will be left unassigned so that they can be assigned later when the locations of its inputs are known + // expand gpu down { int cur_backend_id = -1; for (int i = 0; i < graph->n_nodes; i++) { @@ -1306,13 +1332,12 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg } else { cur_backend_id = *node_backend_id; } - } else { - *node_backend_id = cur_backend_id; - SET_CAUSE(node, "2.2"); + } else if (cur_backend_id != -1) { + ggml_backend_sched_set_if_supported(sched, node, cur_backend_id, node_backend_id); } } } - // pass 2.1 expand gpu up + // expand gpu up { int cur_backend_id = -1; for (int i = graph->n_nodes - 1; i >= 0; i--) { @@ -1328,13 +1353,12 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg } else { cur_backend_id = *node_backend_id; } - } else { - *node_backend_id = cur_backend_id; - SET_CAUSE(node, "2.1"); + } else if (cur_backend_id != -1) { + ggml_backend_sched_set_if_supported(sched, node, cur_backend_id, node_backend_id); } } } - // pass 2.4 expand rest down + // expand rest down { int cur_backend_id = -1; for (int i = 0; i < graph->n_nodes; i++) { @@ -1345,13 +1369,12 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg int * node_backend_id = &tensor_backend_id(node); if (*node_backend_id != -1) { cur_backend_id = *node_backend_id; - } else { - *node_backend_id = cur_backend_id; - SET_CAUSE(node, "2.4"); + } else if (cur_backend_id != -1) { + ggml_backend_sched_set_if_supported(sched, node, cur_backend_id, node_backend_id); } } } - // pass 2.3 expand rest up + // expand rest up { int cur_backend_id = -1; for (int i = graph->n_nodes - 1; i >= 0; i--) { @@ -1362,24 +1385,80 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg int * node_backend_id = &tensor_backend_id(node); if (*node_backend_id != -1) { cur_backend_id = *node_backend_id; - } else { - *node_backend_id = cur_backend_id; - SET_CAUSE(node, "2.3"); + } else if (cur_backend_id != -1) { + ggml_backend_sched_set_if_supported(sched, node, cur_backend_id, node_backend_id); } } } -#ifdef DEBUG_PASS2 - fprintf(stderr, "PASS 2 ASSIGNMENTS\n"); ggml_backend_sched_print_assignments(sched, graph); -#endif + // pass 3: upgrade nodes to higher prio backends with compatible buffer types + // if the tensor is already in the same buffer type (*) as another higher priority backend, we should move it there + // however, we also need to verify that the sources are in compatible buffer types + // (*) the actual requirement is more relaxed, the buffer type of the backend should be supported by all the users of this tensor further down the graph + // however, this is slow to verify, so we have a more strict requirement that the buffer type is the same + // this is not uncommon since multiple backends can use host memory, with the same buffer type (eg. BLAS and CPU) + // additionally, set remaining unassigned nodes to the backend with the most supported inputs + // only nodes that could not be assigned during expansion due to the backend not supporting the op should be unassigned at this point + for (int i = 0; i < graph->n_nodes; i++) { + struct ggml_tensor * node = graph->nodes[i]; + if (ggml_is_view_op(node->op)) { + continue; + } + int * node_backend_id = &tensor_backend_id(node); + if (*node_backend_id == -1) { + // unassigned node: find the backend with the most supported inputs + int n_supported_best = -1; + for (int b = 0; b < sched->n_backends; b++) { + if (ggml_backend_supports_op(sched->backends[b], node)) { + int n_supported = 0; + for (int j = 0; j < GGML_MAX_SRC; j++) { + struct ggml_tensor * src = node->src[j]; + if (src == NULL) { + continue; + } + if ((tensor_backend_id(src) != -1 || tensor_backend_id(src->view_src) != -1) && ggml_backend_sched_buffer_supported(sched, src, b)) { + n_supported++; + } + } + if (n_supported > n_supported_best) { + n_supported_best = n_supported; + *node_backend_id = b; + SET_CAUSE(node, "3.best"); + } + } + } + } else { + // assigned node: upgrade to higher prio backend if possible + for (int b = 0; b < *node_backend_id; b++) { + if (sched->bufts[b] == sched->bufts[*node_backend_id] && ggml_backend_supports_op(sched->backends[b], node)) { + bool supported = true; + for (int j = 0; j < GGML_MAX_SRC; j++) { + struct ggml_tensor * src = node->src[j]; + if (src == NULL) { + continue; + } + if (!ggml_backend_sched_buffer_supported(sched, src, b)) { + supported = false; + break; + } + } + if (supported) { + *node_backend_id = b; + SET_CAUSE(node, "3.upg"); + break; + } + } + } + } + } - // pass 3: assign backends to remaining src from dst and view_src + // pass 4: assign backends to remaining src from dst and view_src for (int i = 0; i < graph->n_nodes; i++) { struct ggml_tensor * node = graph->nodes[i]; int * cur_backend_id = &tensor_backend_id(node); if (node->view_src != NULL && *cur_backend_id == -1) { *cur_backend_id = tensor_backend_id(node->view_src); - SET_CAUSE(node, "3.vsrc"); + SET_CAUSE(node, "4.vsrc"); } for (int j = 0; j < GGML_MAX_SRC; j++) { struct ggml_tensor * src = node->src[j]; @@ -1391,17 +1470,14 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg if (src->view_src != NULL) { // views are always on the same backend as the source *src_backend_id = tensor_backend_id(src->view_src); - SET_CAUSE(src, "3.vsrc"); + SET_CAUSE(src, "4.vsrc"); } else { *src_backend_id = *cur_backend_id; - SET_CAUSE(src, "3.cur"); + SET_CAUSE(src, "4.cur"); } } } } -#ifdef DEBUG_PASS3 - fprintf(stderr, "PASS 3 ASSIGNMENTS\n"); ggml_backend_sched_print_assignments(sched, graph); -#endif // pass 4: split graph, find tensors that need to be copied { @@ -1448,10 +1524,12 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg } } // check if the split has too many inputs + // FIXME: count the number of inputs instead of only checking when full if (split->n_inputs == GGML_SCHED_MAX_SPLIT_INPUTS) { const size_t id = hash_id(src); int src_backend_id = sched->tensor_backend_id[id]; - if (src_backend_id != cur_backend_id && sched->tensor_copies[hash_id(src)][cur_backend_id][0] == NULL) { + bool supported = ggml_backend_sched_buffer_supported(sched, src, cur_backend_id); + if (src_backend_id != cur_backend_id && sched->tensor_copies[hash_id(src)][cur_backend_id][0] == NULL && !supported) { //printf("starting new split because of too many inputs: node %s, input %s\n", node->name, src->name); need_new_split = true; break; @@ -1486,7 +1564,7 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg const int src_backend_id = tensor_backend_id(src); assert(src_backend_id != -1); // all inputs should be assigned by now - if (src->flags & GGML_TENSOR_FLAG_INPUT && sched->n_copies > 1) { + if (src->flags & GGML_TENSOR_FLAG_INPUT && sched->n_copies > 1) { size_t id = hash_id(src); if (sched->tensor_copies[id][src_backend_id][0] == NULL) { ggml_backend_t backend = sched->backends[src_backend_id]; @@ -1511,7 +1589,8 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg } } - if (src_backend_id != node_backend_id) { + bool supported = ggml_backend_sched_buffer_supported(sched, src, cur_backend_id); + if (src_backend_id != cur_backend_id && !supported) { // create a copy of the input in the split's backend const size_t id = hash_id(src); if (sched->tensor_copies[id][cur_backend_id][0] == NULL) { @@ -1537,9 +1616,21 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg split->i_end = graph->n_nodes; sched->n_splits = i_split + 1; } -#ifdef DEBUG_PASS4 - fprintf(stderr, "PASS 4 ASSIGNMENTS\n"); ggml_backend_sched_print_assignments(sched, graph); -#endif + + if (sched->debug) { + ggml_backend_sched_print_assignments(sched, graph); + } + + // swap node_backend_ids and leaf_backend_ids and prevs + { + int * tmp = sched->node_backend_ids; + sched->node_backend_ids = sched->prev_node_backend_ids; + sched->prev_node_backend_ids = tmp; + + tmp = sched->leaf_backend_ids; + sched->leaf_backend_ids = sched->prev_leaf_backend_ids; + sched->prev_leaf_backend_ids = tmp; + } // create copies of the graph for each split // TODO: avoid this copy @@ -1613,8 +1704,24 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg } static bool ggml_backend_sched_alloc_splits(ggml_backend_sched_t sched) { + bool backend_ids_changed = false; + for (int i = 0; i < sched->graph->n_nodes; i++) { + if (sched->node_backend_ids[i] != sched->prev_node_backend_ids[i]) { + backend_ids_changed = true; + break; + } + } + if (!backend_ids_changed) { + for (int i = 0; i < sched->graph->n_leafs; i++) { + if (sched->leaf_backend_ids[i] != sched->prev_leaf_backend_ids[i]) { + backend_ids_changed = true; + break; + } + } + } + // allocate graph - if (!ggml_gallocr_alloc_graph(sched->galloc, sched->graph)) { + if (backend_ids_changed || !ggml_gallocr_alloc_graph(sched->galloc, sched->graph)) { // the re-allocation may cause the split inputs to be moved to a different address ggml_backend_sched_synchronize(sched); #ifndef NDEBUG @@ -1727,6 +1834,8 @@ ggml_backend_sched_t ggml_backend_sched_new( struct ggml_backend_sched * sched = calloc(1, sizeof(struct ggml_backend_sched)); + sched->debug = getenv("GGML_SCHED_DEBUG") != NULL; + // initialize hash table sched->hash_set = ggml_hash_set_new(graph_size); sched->tensor_backend_id = calloc(sched->hash_set.size, sizeof(sched->tensor_backend_id[0])); @@ -1735,6 +1844,8 @@ ggml_backend_sched_t ggml_backend_sched_new( const size_t nodes_size = graph_size + GGML_SCHED_MAX_SPLITS*GGML_SCHED_MAX_SPLIT_INPUTS*2; sched->node_backend_ids = calloc(nodes_size, sizeof(sched->node_backend_ids[0])); sched->leaf_backend_ids = calloc(nodes_size, sizeof(sched->leaf_backend_ids[0])); + sched->prev_node_backend_ids = calloc(nodes_size, sizeof(sched->prev_node_backend_ids[0])); + sched->prev_leaf_backend_ids = calloc(nodes_size, sizeof(sched->prev_leaf_backend_ids[0])); sched->n_backends = n_backends; @@ -1747,7 +1858,7 @@ ggml_backend_sched_t ggml_backend_sched_new( for (int b = 0; b < n_backends; b++) { sched->backends[b] = backends[b]; sched->bufts[b] = bufts ? bufts[b] : ggml_backend_get_default_buffer_type(backends[b]); - GGML_ASSERT(ggml_backend_buft_supports_backend(sched->bufts[b], backends[b])); + GGML_ASSERT(ggml_backend_supports_buft(backends[b], sched->bufts[b])); if (sched->n_copies > 1) { for (int c = 0; c < sched->n_copies; c++) { sched->events[b][c] = ggml_backend_event_new(backends[b]); @@ -1779,6 +1890,8 @@ void ggml_backend_sched_free(ggml_backend_sched_t sched) { free(sched->tensor_copies); free(sched->node_backend_ids); free(sched->leaf_backend_ids); + free(sched->prev_node_backend_ids); + free(sched->prev_leaf_backend_ids); free(sched); } @@ -1875,6 +1988,7 @@ void ggml_backend_sched_set_tensor_backend(ggml_backend_sched_t sched, struct gg int backend_index = ggml_backend_sched_backend_id(sched, backend); GGML_ASSERT(backend_index >= 0 && backend_index < sched->n_backends); tensor_backend_id(node) = backend_index; + SET_CAUSE(node, "usr"); } ggml_backend_t ggml_backend_sched_get_tensor_backend(ggml_backend_sched_t sched, struct ggml_tensor * node) { diff --git a/ggml-backend.h b/ggml-backend.h index c582b0685..47fd81475 100644 --- a/ggml-backend.h +++ b/ggml-backend.h @@ -23,7 +23,6 @@ extern "C" { GGML_API size_t ggml_backend_buft_get_alignment (ggml_backend_buffer_type_t buft); GGML_API size_t ggml_backend_buft_get_max_size (ggml_backend_buffer_type_t buft); GGML_API GGML_CALL size_t ggml_backend_buft_get_alloc_size (ggml_backend_buffer_type_t buft, struct ggml_tensor * tensor); - GGML_API bool ggml_backend_buft_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend); GGML_API bool ggml_backend_buft_is_host (ggml_backend_buffer_type_t buft); // buffer @@ -74,6 +73,7 @@ extern "C" { GGML_API enum ggml_status ggml_backend_graph_compute (ggml_backend_t backend, struct ggml_cgraph * cgraph); GGML_API enum ggml_status ggml_backend_graph_compute_async(ggml_backend_t backend, struct ggml_cgraph * cgraph); GGML_API bool ggml_backend_supports_op(ggml_backend_t backend, const struct ggml_tensor * op); + GGML_API bool ggml_backend_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft); GGML_API bool ggml_backend_offload_op(ggml_backend_t backend, const struct ggml_tensor * op); // tensor copy between different backends @@ -90,7 +90,7 @@ extern "C" { GGML_API void ggml_backend_event_free (ggml_backend_event_t event); GGML_API void ggml_backend_event_record (ggml_backend_event_t event); GGML_API void ggml_backend_event_synchronize(ggml_backend_event_t event); - GGML_API void ggml_backend_event_wait (ggml_backend_t backend, ggml_backend_event_t event); // wait async on event + GGML_API void ggml_backend_event_wait (ggml_backend_t backend, ggml_backend_event_t event); // // CPU backend @@ -119,7 +119,7 @@ extern "C" { GGML_API size_t ggml_backend_reg_get_count(void); GGML_API size_t ggml_backend_reg_find_by_name(const char * name); - GGML_API ggml_backend_t ggml_backend_reg_init_backend_from_str(const char * backend_str); // str is name[:params] + GGML_API ggml_backend_t ggml_backend_reg_init_backend_from_str(const char * backend_str); // str is backend_name:params (params is optional) GGML_API const char * ggml_backend_reg_get_name(size_t i); GGML_API ggml_backend_t ggml_backend_reg_init_backend(size_t i, const char * params); // params is backend-specific GGML_API ggml_backend_buffer_type_t ggml_backend_reg_get_default_buffer_type(size_t i); diff --git a/ggml-blas.cpp b/ggml-blas.cpp new file mode 100644 index 000000000..d709a357b --- /dev/null +++ b/ggml-blas.cpp @@ -0,0 +1,363 @@ +#include "ggml-blas.h" +#include "ggml-backend-impl.h" + +#include +#include + +#if defined(GGML_USE_ACCELERATE) +# include +#elif defined(GGML_BLAS_USE_MKL) +# include +#else +# include +# ifdef BLIS_ENABLE_CBLAS +# include +# endif +#endif + +struct ggml_backend_blas_context { + int n_threads = GGML_DEFAULT_N_THREADS; + std::unique_ptr work_data; + size_t work_size = 0; +#ifndef GGML_USE_OPENMP + std::vector> tasks; +#endif +}; + +// helper function to determine if it is better to use BLAS or not +// for large matrices, BLAS is faster +static bool ggml_backend_blas_use_blas(const struct ggml_tensor * dst) { + const struct ggml_tensor * src0 = dst->src[0]; + const struct ggml_tensor * src1 = dst->src[1]; + + const int64_t ne10 = src1->ne[0]; + + const int64_t ne0 = dst->ne[0]; + const int64_t ne1 = dst->ne[1]; + + // TODO: find the optimal values for these + if (ggml_is_contiguous(src0) && + ggml_is_contiguous(src1) && + src1->type == GGML_TYPE_F32 && + (ne0 >= 32 && ne1 >= 32 && ne10 >= 32)) { + + /*printf("BLAS: %d %d %d %d %d\n", ne0, ne1, ne10, ne00, ne01);*/ + return true; + } + + return false; +} + +static void ggml_backend_blas_mul_mat(ggml_backend_blas_context * ctx, struct ggml_tensor * dst) { + const struct ggml_tensor * src0 = dst->src[0]; + const struct ggml_tensor * src1 = dst->src[1]; + + GGML_TENSOR_BINARY_OP_LOCALS + + const enum ggml_type type = src0->type; + + GGML_ASSERT(ne0 == ne01); + GGML_ASSERT(ne1 == ne11); + GGML_ASSERT(ne2 == ne12); + GGML_ASSERT(ne3 == ne13); + + // we don't support permuted src0 or src1 + GGML_ASSERT(nb00 == ggml_type_size(type)); + GGML_ASSERT(nb10 == ggml_type_size(src1->type)); + + // dst cannot be transposed or permuted + GGML_ASSERT(nb0 == sizeof(float)); + GGML_ASSERT(nb0 <= nb1); + GGML_ASSERT(nb1 <= nb2); + GGML_ASSERT(nb2 <= nb3); + + // broadcast factors + const int64_t r2 = ne12/ne02; + const int64_t r3 = ne13/ne03; + + const int64_t ne_plane = ne01*ne00; + const size_t desired_wsize = type == GGML_TYPE_F32 ? 0 : ne03*ne02*ne_plane*sizeof(float); + + if (ctx->work_size < desired_wsize) { + ctx->work_data.reset(new char[desired_wsize]); + ctx->work_size = desired_wsize; + } + void * wdata = ctx->work_data.get(); + + // convert src0 to float + if (type != GGML_TYPE_F32) { + ggml_type_traits_t type_traits = ggml_internal_get_type_traits(type); + ggml_to_float_t const to_float = type_traits.to_float; + + for (int64_t i03 = 0; i03 < ne03; i03++) { + for (int64_t i02 = 0; i02 < ne02; i02++) { + const void * x = (char *) src0->data + i02*nb02 + i03*nb03; + float * const wplane = (float *) wdata + i02*ne_plane + i03*ne02*ne_plane; + + const int min_cols_per_thread = 4096; + const int min_rows_per_thread = std::max((int)(min_cols_per_thread/ne00), 1); + const int n_threads = std::max(std::min(ctx->n_threads, (int)(ne01/min_rows_per_thread)), 1); + +#ifdef GGML_USE_OPENMP + #pragma omp parallel for num_threads(n_threads) + for (int64_t i01 = 0; i01 < ne01; i01++) { + to_float((const char *) x + i01*nb01, wplane + i01*ne00, ne00); + } +#else + for (int i = 1; i < n_threads; i++) { + const int64_t start = i*ne01/n_threads; + const int64_t end = (i + 1)*ne01/n_threads; + if (start < end) { + ctx->tasks.push_back(std::async(std::launch::async, [=]() { + for (int64_t i01 = start; i01 < end; i01++) { + to_float((const char *) x + i01*nb01, wplane + i01*ne00, ne00); + } + })); + } + } + { + // reuse the current thread for the first task + const int64_t start = 0; + const int64_t end = ne01/n_threads; + for (int64_t i01 = start; i01 < end; i01++) { + to_float((const char *) x + i01*nb01, wplane + i01*ne00, ne00); + } + } +#endif + } + } + +#ifndef GGML_USE_OPENMP + // wait for all tasks to finish + for (auto & task : ctx->tasks) { + task.get(); + } + ctx->tasks.clear(); +#endif + } + +#if defined(OPENBLAS_VERSION) + openblas_set_num_threads(ctx->n_threads); +#endif + +#if defined(BLIS_ENABLE_CBLAS) + bli_thread_set_num_threads(ctx->n_threads); +#endif + + for (int64_t i13 = 0; i13 < ne13; i13++) { + for (int64_t i12 = 0; i12 < ne12; i12++) { + const int64_t i03 = i13/r3; + const int64_t i02 = i12/r2; + + const float * x = (float *) ((char *) src0->data + i02*nb02 + i03*nb03); + const float * y = (float *) ((char *) src1->data + i12*nb12 + i13*nb13); + float * d = (float *) ((char *) dst->data + i12*nb2 + i13*nb3); + + if (type != GGML_TYPE_F32) { + x = (float *) wdata + i02*ne_plane + i03*ne02*ne_plane; + } + + cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, + ne1, ne01, ne10, + 1.0f, y, ne10, + x, ne00, + 0.0f, d, ne01); + } + } +} + +static void ggml_backend_blas_out_prod(ggml_backend_blas_context * ctx, struct ggml_tensor * dst) { + const struct ggml_tensor * src0 = dst->src[0]; + const struct ggml_tensor * src1 = dst->src[1]; + + GGML_TENSOR_BINARY_OP_LOCALS + + GGML_ASSERT(ne0 == ne00); + GGML_ASSERT(ne1 == ne10); + GGML_ASSERT(ne2 == ne02); + GGML_ASSERT(ne02 == ne12); + GGML_ASSERT(ne3 == ne13); + GGML_ASSERT(ne03 == ne13); + + // we don't support permuted src0 or src1 + GGML_ASSERT(nb00 == sizeof(float)); + + // dst cannot be transposed or permuted + GGML_ASSERT(nb0 == sizeof(float)); + // GGML_ASSERT(nb0 <= nb1); + // GGML_ASSERT(nb1 <= nb2); + // GGML_ASSERT(nb2 <= nb3); + + // Arguments to ggml_compute_forward_out_prod (expressed as major,minor) + // src0: (k,n) + // src1: (k,m) + // dst: (m,n) + // + // Arguments to sgemm (see https://github.com/Reference-LAPACK/lapack/blob/master/BLAS/SRC/sgemm.f) + // Also expressed as (major,minor) + // a: (m,k): so src1 transposed + // b: (k,n): so src0 + // c: (m,n) + // + // However, if ggml_is_transposed(src1) is true, then + // src1->data already contains a transposed version, so sgemm mustn't + // transpose it further. + + int n = src0->ne[0]; + int k = src0->ne[1]; + int m = src1->ne[0]; + + CBLAS_TRANSPOSE transposeA; + int lda; + + if (!ggml_is_transposed(src1)) { + transposeA = CblasTrans; + lda = m; + } else { + transposeA = CblasNoTrans; + lda = k; + } + + float * a = (float *) ((char *) src1->data); + float * b = (float *) ((char *) src0->data); + float * c = (float *) ((char *) dst->data); + + cblas_sgemm(CblasRowMajor, transposeA, CblasNoTrans, m, n, k, 1.0, a, lda, b, n, 0.0, c, n); + + GGML_UNUSED(ctx); +} + +// backend interface + +GGML_CALL static const char * ggml_backend_blas_name(ggml_backend_t backend) { + return "BLAS"; + + GGML_UNUSED(backend); +} + +GGML_CALL static void ggml_backend_blas_free(ggml_backend_t backend) { + ggml_backend_blas_context * ctx = (ggml_backend_blas_context *)backend->context; + delete ctx; + delete backend; +} + +GGML_CALL static ggml_backend_buffer_type_t ggml_backend_blas_get_default_buffer_type(ggml_backend_t backend) { + return ggml_backend_cpu_buffer_type(); + + GGML_UNUSED(backend); +} + +GGML_CALL static enum ggml_status ggml_backend_blas_graph_compute(ggml_backend_t backend, struct ggml_cgraph * cgraph) { + ggml_backend_blas_context * ctx = (ggml_backend_blas_context *)backend->context; + + for (int i = 0; i < cgraph->n_nodes; i++) { + struct ggml_tensor * node = cgraph->nodes[i]; + + switch (node->op) { + case GGML_OP_MUL_MAT: + ggml_backend_blas_mul_mat(ctx, node); + break; + + case GGML_OP_OUT_PROD: + ggml_backend_blas_out_prod(ctx, node); + break; + + case GGML_OP_NONE: + case GGML_OP_RESHAPE: + case GGML_OP_VIEW: + case GGML_OP_PERMUTE: + case GGML_OP_TRANSPOSE: + break; + + default: + fprintf(stderr, "%s: unsupported op %s\n", __func__, ggml_op_desc(node)); + GGML_ASSERT(false); + } + } + + return GGML_STATUS_SUCCESS; + + GGML_UNUSED(backend); +} + +GGML_CALL static bool ggml_backend_blas_supports_op(ggml_backend_t backend, const struct ggml_tensor * op) { + const struct ggml_tensor * src0 = op->src[0]; + const struct ggml_tensor * src1 = op->src[1]; + + return (op->op == GGML_OP_MUL_MAT && ggml_backend_blas_use_blas(op)) || + (op->op == GGML_OP_OUT_PROD && op->src[0]->type == GGML_TYPE_F32 && + op->src[1]->type == GGML_TYPE_F32 && + ggml_is_matrix(src0) && + ggml_is_matrix(src1) && + ggml_is_contiguous(src0) && + (ggml_is_contiguous(src1) || ggml_is_transposed(src1))); + + GGML_UNUSED(backend); +} + +GGML_CALL static bool ggml_backend_blas_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + return ggml_backend_buft_is_host(buft); + + GGML_UNUSED(backend); +} + +static struct ggml_backend_i blas_backend_i = { + /* .get_name = */ ggml_backend_blas_name, + /* .free = */ ggml_backend_blas_free, + /* .get_default_buffer_type = */ ggml_backend_blas_get_default_buffer_type, + /* .set_tensor_async = */ NULL, + /* .get_tensor_async = */ NULL, + /* .cpy_tensor_async = */ NULL, + /* .synchronize = */ NULL, + /* .graph_plan_create = */ NULL, + /* .graph_plan_free = */ NULL, + /* .graph_plan_update = */ NULL, + /* .graph_plan_compute = */ NULL, + /* .graph_compute = */ ggml_backend_blas_graph_compute, + /* .supports_op = */ ggml_backend_blas_supports_op, + /* .supports_buft = */ ggml_backend_blas_supports_buft, + /* .offload_op = */ NULL, + /* .event_new = */ NULL, + /* .event_free = */ NULL, + /* .event_record = */ NULL, + /* .event_wait = */ NULL, + /* .event_synchronize = */ NULL, +}; + +static ggml_guid_t ggml_backend_blas_guid(void) { + static ggml_guid guid = { 0x12, 0xa8, 0xae, 0xf4, 0xc0, 0x1e, 0x61, 0x97, 0x8f, 0xeb, 0x33, 0x04, 0xa1, 0x33, 0x51, 0x2d }; + return &guid; +} + +ggml_backend_t ggml_backend_blas_init(void) { + ggml_backend_blas_context * ctx = new ggml_backend_blas_context; + + ggml_backend_t backend = new ggml_backend { + /* .guid = */ ggml_backend_blas_guid(), + /* .interface = */ blas_backend_i, + /* .context = */ ctx, + }; + +#if !defined(NDEBUG) && defined(OPENBLAS_VERSION) && defined(GGML_USE_OPENMP) + if (openblas_get_parallel() != OPENBLAS_OPENMP) { + fprintf(stderr, "%s: warning: ggml is using OpenMP, but OpenBLAS was compiled without OpenMP support\n", __func__); + } +#endif + +#if !defined(NDEBUG) && defined(BLIS_ENABLE_CBLAS) && defined(GGML_USE_OPENMP) && !defined(BLIS_ENABLE_OPENMP) + fprintf(stderr, "%s: warning: ggml is using OpenMP, but BLIS was compiled without OpenMP support\n", __func__); +#endif + + return backend; +} + +GGML_CALL bool ggml_backend_is_blas(ggml_backend_t backend) { + return backend != NULL && ggml_guid_matches(backend->guid, ggml_backend_blas_guid()); +} + +void ggml_backend_blas_set_n_threads(ggml_backend_t backend_blas, int n_threads) { + GGML_ASSERT(ggml_backend_is_blas(backend_blas)); + + ggml_backend_blas_context * ctx = (ggml_backend_blas_context *)backend_blas->context; + ctx->n_threads = n_threads; +} diff --git a/ggml-blas.h b/ggml-blas.h new file mode 100644 index 000000000..f2e37de06 --- /dev/null +++ b/ggml-blas.h @@ -0,0 +1,23 @@ +#pragma once + +#include "ggml.h" +#include "ggml-backend.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +// backend API +GGML_API GGML_CALL ggml_backend_t ggml_backend_blas_init(void); + +GGML_API GGML_CALL bool ggml_backend_is_blas(ggml_backend_t backend); + +// number of threads used for conversion to float +// for openblas and blis, this will also set the number of threads used for blas operations +GGML_API GGML_CALL void ggml_backend_blas_set_n_threads(ggml_backend_t backend_blas, int n_threads); + + +#ifdef __cplusplus +} +#endif diff --git a/ggml-cuda.cu b/ggml-cuda.cu index c6bc3f64c..64d3b6747 100644 --- a/ggml-cuda.cu +++ b/ggml-cuda.cu @@ -543,6 +543,10 @@ GGML_CALL static const char * ggml_backend_cuda_buffer_type_name(ggml_backend_bu return ctx->name.c_str(); } +static bool ggml_backend_buft_is_cuda(ggml_backend_buffer_type_t buft) { + return buft->iface.get_name == ggml_backend_cuda_buffer_type_name; +} + GGML_CALL static ggml_backend_buffer_t ggml_backend_cuda_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) { ggml_backend_cuda_buffer_type_context * buft_ctx = (ggml_backend_cuda_buffer_type_context *)buft->context; @@ -585,24 +589,12 @@ GGML_CALL static size_t ggml_backend_cuda_buffer_type_get_alloc_size(ggml_backen GGML_UNUSED(buft); } -GGML_CALL static bool ggml_backend_cuda_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - if (!ggml_backend_is_cuda(backend)) { - return false; - } - - ggml_backend_cuda_buffer_type_context * buft_ctx = (ggml_backend_cuda_buffer_type_context *)buft->context; - ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *)backend->context; - - return buft_ctx->device == cuda_ctx->device; -} - static ggml_backend_buffer_type_i ggml_backend_cuda_buffer_type_interface = { /* .get_name = */ ggml_backend_cuda_buffer_type_name, /* .alloc_buffer = */ ggml_backend_cuda_buffer_type_alloc_buffer, /* .get_alignment = */ ggml_backend_cuda_buffer_type_get_alignment, /* .get_max_size = */ NULL, // defaults to SIZE_MAX /* .get_alloc_size = */ ggml_backend_cuda_buffer_type_get_alloc_size, - /* .supports_backend = */ ggml_backend_cuda_buffer_type_supports_backend, /* .is_host = */ NULL, }; @@ -863,6 +855,10 @@ GGML_CALL static const char * ggml_backend_cuda_split_buffer_type_name(ggml_back GGML_UNUSED(buft); } +static bool ggml_backend_buft_is_cuda_split(ggml_backend_buffer_type_t buft) { + return buft->iface.get_name == ggml_backend_cuda_split_buffer_type_name; +} + GGML_CALL static ggml_backend_buffer_t ggml_backend_cuda_split_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) { // since we don't know the exact split after rounding, we cannot allocate the device buffers at this point // instead, we allocate them for each tensor separately in init_tensor @@ -906,12 +902,6 @@ GGML_CALL static size_t ggml_backend_cuda_split_buffer_type_get_alloc_size(ggml_ return total_size; } -GGML_CALL static bool ggml_backend_cuda_split_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - return ggml_backend_is_cuda(backend); - - GGML_UNUSED(buft); -} - GGML_CALL static bool ggml_backend_cuda_split_buffer_type_is_host(ggml_backend_buffer_type_t buft) { return false; @@ -924,7 +914,6 @@ static ggml_backend_buffer_type_i ggml_backend_cuda_split_buffer_type_interface /* .get_alignment = */ ggml_backend_cuda_split_buffer_type_get_alignment, /* .get_max_size = */ NULL, // defaults to SIZE_MAX /* .get_alloc_size = */ ggml_backend_cuda_split_buffer_type_get_alloc_size, - /* .supports_backend = */ ggml_backend_cuda_split_buffer_type_supports_backend, /* .is_host = */ ggml_backend_cuda_split_buffer_type_is_host, }; @@ -1024,7 +1013,6 @@ GGML_CALL ggml_backend_buffer_type_t ggml_backend_cuda_host_buffer_type() { /* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment, /* .get_max_size = */ NULL, // defaults to SIZE_MAX /* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size, - /* .supports_backend = */ ggml_backend_cpu_buffer_type()->iface.supports_backend, /* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host, }, /* .context = */ nullptr, @@ -2879,6 +2867,20 @@ GGML_CALL static bool ggml_backend_cuda_supports_op(ggml_backend_t backend, cons GGML_UNUSED(backend); } +GGML_CALL static bool ggml_backend_cuda_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + if (ggml_backend_buft_is_cuda_split(buft)) { + return true; + } + + if (ggml_backend_buft_is_cuda(buft)) { + ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *)backend->context; + ggml_backend_cuda_buffer_type_context * buft_ctx = (ggml_backend_cuda_buffer_type_context *)buft->context; + return buft_ctx->device == cuda_ctx->device; + } + + return false; +} + GGML_CALL static bool ggml_backend_cuda_offload_op(ggml_backend_t backend, const ggml_tensor * op) { const int min_batch_size = 32; @@ -2951,9 +2953,11 @@ static ggml_backend_i ggml_backend_cuda_interface = { /* .synchronize = */ ggml_backend_cuda_synchronize, /* .graph_plan_create = */ NULL, /* .graph_plan_free = */ NULL, + /* .graph_plan_update = */ NULL, /* .graph_plan_compute = */ NULL, /* .graph_compute = */ ggml_backend_cuda_graph_compute, /* .supports_op = */ ggml_backend_cuda_supports_op, + /* .supports_buft = */ ggml_backend_cuda_supports_buft, /* .offload_op = */ ggml_backend_cuda_offload_op, /* .event_new = */ ggml_backend_cuda_event_new, /* .event_free = */ ggml_backend_cuda_event_free, diff --git a/ggml-kompute.cpp b/ggml-kompute.cpp index 18c6f4a10..ed5f2e349 100644 --- a/ggml-kompute.cpp +++ b/ggml-kompute.cpp @@ -1902,18 +1902,12 @@ static size_t ggml_backend_vk_buffer_type_get_max_size(ggml_backend_buffer_type_ return ctx->max_alloc; } -static bool ggml_backend_kompute_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - GGML_UNUSED(buft); - return ggml_backend_is_kompute(backend); -} - static ggml_backend_buffer_type_i ggml_backend_kompute_buffer_type_interface = { /* .get_name = */ ggml_backend_kompute_buffer_type_get_name, /* .alloc_buffer = */ ggml_backend_kompute_buffer_type_alloc_buffer, /* .get_alignment = */ ggml_backend_kompute_buffer_type_get_alignment, /* .get_max_size = */ ggml_backend_vk_buffer_type_get_max_size, /* .get_alloc_size = */ NULL, // defaults to ggml_nbytes - /* .supports_backend = */ ggml_backend_kompute_buffer_type_supports_backend, /* .is_host = */ NULL, }; @@ -1973,6 +1967,11 @@ static bool ggml_backend_kompute_supports_op(ggml_backend_t backend, const struc return ggml_vk_supports_op(op); } +static bool ggml_backend_kompute_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + GGML_UNUSED(backend); + return buft->iface.get_name == ggml_backend_kompute_buffer_type_get_name; +} + static struct ggml_backend_i kompute_backend_i = { /* .get_name = */ ggml_backend_kompute_name, /* .free = */ ggml_backend_kompute_free, @@ -1983,9 +1982,11 @@ static struct ggml_backend_i kompute_backend_i = { /* .synchronize = */ NULL, /* .graph_plan_create = */ NULL, /* .graph_plan_free = */ NULL, + /* .graph_plan_update = */ NULL, /* .graph_plan_compute = */ NULL, /* .graph_compute = */ ggml_backend_kompute_graph_compute, /* .supports_op = */ ggml_backend_kompute_supports_op, + /* .supports_buft = */ ggml_backend_kompute_supports_buft, /* .offload_op = */ NULL, /* .event_new = */ NULL, /* .event_free = */ NULL, diff --git a/ggml-metal.m b/ggml-metal.m index b5c287347..ec9e95302 100644 --- a/ggml-metal.m +++ b/ggml-metal.m @@ -3044,12 +3044,6 @@ GGML_CALL static size_t ggml_backend_metal_buffer_type_get_max_size(ggml_backend UNUSED(buft); } -GGML_CALL static bool ggml_backend_metal_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - return ggml_backend_is_metal(backend) || ggml_backend_is_cpu(backend); - - UNUSED(buft); -} - GGML_CALL static bool ggml_backend_metal_buffer_type_is_host(ggml_backend_buffer_type_t buft) { return true; @@ -3064,7 +3058,6 @@ GGML_CALL ggml_backend_buffer_type_t ggml_backend_metal_buffer_type(void) { /* .get_alignment = */ ggml_backend_metal_buffer_type_get_alignment, /* .get_max_size = */ ggml_backend_metal_buffer_type_get_max_size, /* .get_alloc_size = */ NULL, // defaults to ggml_nbytes - /* .supports_backend = */ ggml_backend_metal_buffer_type_supports_backend, /* .is_host = */ ggml_backend_metal_buffer_type_is_host, }, /* .context = */ NULL, @@ -3179,6 +3172,12 @@ GGML_CALL static bool ggml_backend_metal_supports_op(ggml_backend_t backend, con return ggml_metal_supports_op(metal_ctx, op); } +GGML_CALL static bool ggml_backend_metal_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + return buft->iface.get_name == ggml_backend_metal_buffer_type_get_name; + + UNUSED(backend); +} + static struct ggml_backend_i ggml_backend_metal_i = { /* .get_name = */ ggml_backend_metal_name, /* .free = */ ggml_backend_metal_free, @@ -3189,9 +3188,11 @@ static struct ggml_backend_i ggml_backend_metal_i = { /* .synchronize = */ NULL, /* .graph_plan_create = */ NULL, /* .graph_plan_free = */ NULL, + /* .graph_plan_update = */ NULL, /* .graph_plan_compute = */ NULL, /* .graph_compute = */ ggml_backend_metal_graph_compute, /* .supports_op = */ ggml_backend_metal_supports_op, + /* .supports_buft = */ ggml_backend_metal_supports_buft, /* .offload_op = */ NULL, /* .event_new = */ NULL, /* .event_free = */ NULL, diff --git a/ggml-rpc.cpp b/ggml-rpc.cpp index 679ce4f28..9b95193d3 100644 --- a/ggml-rpc.cpp +++ b/ggml-rpc.cpp @@ -540,22 +540,12 @@ GGML_CALL static size_t ggml_backend_rpc_buffer_type_get_alloc_size(ggml_backend return ggml_nbytes(tensor); } -GGML_CALL static bool ggml_backend_rpc_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - if (!ggml_backend_is_rpc(backend)) { - return false; - } - ggml_backend_rpc_buffer_type_context * buft_ctx = (ggml_backend_rpc_buffer_type_context *)buft->context; - ggml_backend_rpc_context * rpc_ctx = (ggml_backend_rpc_context *)backend->context; - return buft_ctx->endpoint == rpc_ctx->endpoint; -} - static ggml_backend_buffer_type_i ggml_backend_rpc_buffer_type_interface = { /* .get_name = */ ggml_backend_rpc_buffer_type_name, /* .alloc_buffer = */ ggml_backend_rpc_buffer_type_alloc_buffer, /* .get_alignment = */ ggml_backend_rpc_buffer_type_get_alignment, /* .get_max_size = */ ggml_backend_rpc_get_max_size, /* .get_alloc_size = */ ggml_backend_rpc_buffer_type_get_alloc_size, - /* .supports_backend = */ ggml_backend_rpc_buffer_type_supports_backend, /* .is_host = */ NULL, }; @@ -638,6 +628,15 @@ GGML_CALL static bool ggml_backend_rpc_supports_op(ggml_backend_t backend, const return false; } +GGML_CALL static bool ggml_backend_rpc_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + if (buft->iface.get_name == ggml_backend_rpc_buffer_type_name) { + return false; + } + ggml_backend_rpc_buffer_type_context * buft_ctx = (ggml_backend_rpc_buffer_type_context *)buft->context; + ggml_backend_rpc_context * rpc_ctx = (ggml_backend_rpc_context *)backend->context; + return buft_ctx->endpoint == rpc_ctx->endpoint; +} + static ggml_backend_i ggml_backend_rpc_interface = { /* .get_name = */ ggml_backend_rpc_name, /* .free = */ ggml_backend_rpc_free, @@ -648,9 +647,11 @@ static ggml_backend_i ggml_backend_rpc_interface = { /* .synchronize = */ ggml_backend_rpc_synchronize, /* .graph_plan_create = */ NULL, /* .graph_plan_free = */ NULL, + /* .graph_plan_update = */ NULL, /* .graph_plan_compute = */ NULL, /* .graph_compute = */ ggml_backend_rpc_graph_compute, /* .supports_op = */ ggml_backend_rpc_supports_op, + /* .supports_buft = */ ggml_backend_rpc_supports_buft, /* .offload_op = */ NULL, /* .event_new = */ NULL, /* .event_free = */ NULL, diff --git a/ggml-sycl.cpp b/ggml-sycl.cpp index e7d260bd4..6f41ed272 100644 --- a/ggml-sycl.cpp +++ b/ggml-sycl.cpp @@ -16575,22 +16575,12 @@ GGML_CALL static size_t ggml_backend_sycl_buffer_type_get_alloc_size(ggml_backen UNUSED(buft); } -GGML_CALL static bool ggml_backend_sycl_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - if (!ggml_backend_is_sycl(backend)) { - return false; - } - ggml_backend_sycl_buffer_type_context * buft_ctx = (ggml_backend_sycl_buffer_type_context *)buft->context; - ggml_backend_sycl_context * sycl_ctx = (ggml_backend_sycl_context *)backend->context; - return buft_ctx->device == sycl_ctx->device; -} - static ggml_backend_buffer_type_i ggml_backend_sycl_buffer_type_interface = { /* .get_name = */ ggml_backend_sycl_buffer_type_name, /* .alloc_buffer = */ ggml_backend_sycl_buffer_type_alloc_buffer, /* .get_alignment = */ ggml_backend_sycl_buffer_type_get_alignment, /* .get_max_size = */ ggml_backend_sycl_buffer_type_get_max_size, /* .get_alloc_size = */ ggml_backend_sycl_buffer_type_get_alloc_size, - /* .supports_backend = */ ggml_backend_sycl_buffer_type_supports_backend, /* .is_host = */ nullptr, }; @@ -16942,12 +16932,6 @@ GGML_CALL static size_t ggml_backend_sycl_split_buffer_type_get_alloc_size(ggml_ return total_size; } -GGML_CALL static bool ggml_backend_sycl_split_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - return ggml_backend_is_sycl(backend); - - UNUSED(buft); -} - GGML_CALL static bool ggml_backend_sycl_split_buffer_type_is_host(ggml_backend_buffer_type_t buft) { return false; @@ -16960,7 +16944,6 @@ static ggml_backend_buffer_type_i ggml_backend_sycl_split_buffer_type_interface /* .get_alignment = */ ggml_backend_sycl_split_buffer_type_get_alignment, /* .get_max_size = */ NULL, // defaults to SIZE_MAX /* .get_alloc_size = */ ggml_backend_sycl_split_buffer_type_get_alloc_size, - /* .supports_backend = */ ggml_backend_sycl_split_buffer_type_supports_backend, /* .is_host = */ ggml_backend_sycl_split_buffer_type_is_host, }; @@ -17046,7 +17029,6 @@ ggml_backend_buffer_type_t ggml_backend_sycl_host_buffer_type() { /* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment, /* .get_max_size = */ NULL, // TODO: return device.maxBufferLength /* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size, - /* .supports_backend = */ ggml_backend_cpu_buffer_type()->iface.supports_backend, /* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host, }, /* .context = */ nullptr, @@ -17311,6 +17293,14 @@ GGML_CALL static bool ggml_backend_sycl_offload_op(ggml_backend_t backend, const GGML_UNUSED(backend); } +GGML_CALL static bool ggml_backend_sycl_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + if (buft->iface.get_name != ggml_backend_sycl_buffer_type_name) { + return false; + } + ggml_backend_sycl_buffer_type_context * buft_ctx = (ggml_backend_sycl_buffer_type_context *)buft->context; + ggml_backend_sycl_context * sycl_ctx = (ggml_backend_sycl_context *)backend->context; + return buft_ctx->device == sycl_ctx->device; +} static ggml_backend_i ggml_backend_sycl_interface = { /* .get_name = */ ggml_backend_sycl_name, @@ -17322,9 +17312,11 @@ static ggml_backend_i ggml_backend_sycl_interface = { /* .synchronize = */ ggml_backend_sycl_synchronize, /* .graph_plan_create = */ NULL, /* .graph_plan_free = */ NULL, + /* .graph_plan_update = */ NULL, /* .graph_plan_compute = */ NULL, /* .graph_compute = */ ggml_backend_sycl_graph_compute, /* .supports_op = */ ggml_backend_sycl_supports_op, + /* .supports_buft = */ ggml_backend_sycl_supports_buft, /* .offload_op = */ ggml_backend_sycl_offload_op, /* .event_new = */ NULL, /* .event_free = */ NULL, diff --git a/ggml-vulkan.cpp b/ggml-vulkan.cpp index 5b9280491..e2d17a352 100644 --- a/ggml-vulkan.cpp +++ b/ggml-vulkan.cpp @@ -6142,24 +6142,12 @@ GGML_CALL static size_t ggml_backend_vk_buffer_type_get_alloc_size(ggml_backend_ UNUSED(buft); } -GGML_CALL static bool ggml_backend_vk_buffer_type_supports_backend(ggml_backend_buffer_type_t buft, ggml_backend_t backend) { - if (!ggml_backend_is_vk(backend)) { - return false; - } - - ggml_backend_vk_buffer_type_context * buft_ctx = (ggml_backend_vk_buffer_type_context *)buft->context; - ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context; - - return buft_ctx->ctx->idx == ctx->idx; -} - static ggml_backend_buffer_type_i ggml_backend_vk_buffer_type_interface = { /* .get_name = */ ggml_backend_vk_buffer_type_name, /* .alloc_buffer = */ ggml_backend_vk_buffer_type_alloc_buffer, /* .get_alignment = */ ggml_backend_vk_buffer_type_get_alignment, /* .get_max_size = */ ggml_backend_vk_buffer_type_get_max_size, /* .get_alloc_size = */ ggml_backend_vk_buffer_type_get_alloc_size, - /* .supports_backend = */ ggml_backend_vk_buffer_type_supports_backend, /* .is_host = */ NULL, }; @@ -6235,7 +6223,6 @@ GGML_CALL ggml_backend_buffer_type_t ggml_backend_vk_host_buffer_type() { /* .get_alignment = */ ggml_backend_vk_host_buffer_type_get_alignment, /* .get_max_size = */ NULL, // defaults to SIZE_MAX /* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size, - /* .supports_backend = */ ggml_backend_cpu_buffer_type()->iface.supports_backend, /* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host, }, /* .context = */ nullptr, @@ -6551,6 +6538,17 @@ GGML_CALL static bool ggml_backend_vk_offload_op(ggml_backend_t backend, const g UNUSED(backend); } +GGML_CALL static bool ggml_backend_vk_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { + if (buft->iface.get_name != ggml_backend_vk_buffer_type_name) { + return false; + } + + ggml_backend_vk_buffer_type_context * buft_ctx = (ggml_backend_vk_buffer_type_context *)buft->context; + ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context; + + return buft_ctx->ctx->idx == ctx->idx; +} + // TODO: enable async and synchronize static ggml_backend_i ggml_backend_vk_interface = { /* .get_name = */ ggml_backend_vk_name, @@ -6562,9 +6560,11 @@ static ggml_backend_i ggml_backend_vk_interface = { /* .synchronize = */ NULL, // ggml_backend_vk_synchronize, /* .graph_plan_create = */ NULL, /* .graph_plan_free = */ NULL, + /* .graph_plan_update = */ NULL, /* .graph_plan_compute = */ NULL, /* .graph_compute = */ ggml_backend_vk_graph_compute, /* .supports_op = */ ggml_backend_vk_supports_op, + /* .supports_buft = */ ggml_backend_vk_supports_buft, /* .offload_op = */ ggml_backend_vk_offload_op, /* .event_new = */ NULL, /* .event_free = */ NULL, diff --git a/ggml.c b/ggml.c index 2ea1d7677..d5d33c2ba 100644 --- a/ggml.c +++ b/ggml.c @@ -297,12 +297,6 @@ inline static void * ggml_calloc(size_t num, size_t size) { #if defined(GGML_USE_ACCELERATE) #include -#elif defined(GGML_USE_OPENBLAS) -#if defined(GGML_BLAS_USE_MKL) -#include -#else -#include -#endif #endif // floating point type used to accumulate sums @@ -12179,39 +12173,6 @@ static void ggml_compute_forward_group_norm( // ggml_compute_forward_mul_mat -#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) -// helper function to determine if it is better to use BLAS or not -// for large matrices, BLAS is faster -static bool ggml_compute_forward_mul_mat_use_blas(struct ggml_tensor * dst) { - const struct ggml_tensor * src0 = dst->src[0]; - const struct ggml_tensor * src1 = dst->src[1]; - - //const int64_t ne00 = src0->ne[0]; - //const int64_t ne01 = src0->ne[1]; - - const int64_t ne10 = src1->ne[0]; - - const int64_t ne0 = dst->ne[0]; - const int64_t ne1 = dst->ne[1]; - - // NOTE: with GGML_OP_MUL_MAT_ID we don't want to go through the BLAS branch because it will dequantize (to_float) - // all the experts for each batch element and the processing would become incredibly slow - // TODO: find the optimal values for these - if (dst->op != GGML_OP_MUL_MAT_ID && - ggml_is_contiguous(src0) && - ggml_is_contiguous(src1) && - //src0->type == GGML_TYPE_F32 && - src1->type == GGML_TYPE_F32 && - (ne0 >= 32 && ne1 >= 32 && ne10 >= 32)) { - - /*printf("BLAS: %d %d %d %d %d\n", ne0, ne1, ne10, ne00, ne01);*/ - return true; - } - - return false; -} -#endif - static void ggml_compute_forward_mul_mat_one_chunk( const struct ggml_compute_params * params, struct ggml_tensor * dst, @@ -12349,73 +12310,6 @@ static void ggml_compute_forward_mul_mat( // nb01 >= nb00 - src0 is not transposed // compute by src0 rows -#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) - if (ggml_compute_forward_mul_mat_use_blas(dst)) { - const int64_t ne_plane = ne01*ne00; - const size_t desired_wsize = ne13*ne12*ne_plane*sizeof(float); - UNUSED(desired_wsize); - - if (params->type == GGML_TASK_TYPE_INIT) { - if (type != GGML_TYPE_F32) { - assert(params->wsize >= desired_wsize); - // parallelize by src0 rows - for (int64_t i13 = 0; i13 < ne13; i13++) { - for (int64_t i12 = 0; i12 < ne12; i12++) { - // broadcast src0 into src1 across 2nd,3rd dimension - const int64_t i03 = i13/r3; - const int64_t i02 = i12/r2; - - const void * x = (char *) src0->data + i02*nb02 + i03*nb03; - float * const wdata = (float *) params->wdata + i13*ne12*ne_plane + i12*ne_plane; - ggml_to_float_t const to_float = type_traits[type].to_float; - - for (int64_t i01 = ith; i01 < ne01; i01 += nth) { - to_float((const char *) x + i01*nb01, wdata + i01*ne00, ne00); - } - } - } - } - return; - } - - if (params->type == GGML_TASK_TYPE_FINALIZE) { - return; - } - - // perform sgemm, parallelization controlled by blas lib - if (ith != 0) { - return; - } - - //const int64_t tgemm0 = ggml_perf_time_us(); - for (int64_t i13 = 0; i13 < ne13; i13++) { - for (int64_t i12 = 0; i12 < ne12; i12++) { - const int64_t i03 = i13/r3; - const int64_t i02 = i12/r2; - - const void * x = (char *) src0->data + i02*nb02 + i03*nb03; - const float * y = (float *) ((char *) src1->data + i12*nb12 + i13*nb13); - float * d = (float *) ((char *) dst->data + i12*nb2 + i13*nb3); - - if (type != GGML_TYPE_F32) { - x = (float *) params->wdata + i13*ne12*ne_plane + i12*ne_plane; - } - - cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, - ne1, ne01, ne10, - 1.0f, y, ne10, - x, ne00, - 0.0f, d, ne01); - } - } - //printf("cblas_sgemm = %.3f ms, %lld flops\n", (ggml_perf_time_us() - tgemm0)/1000.0, ne13*ne12*ne1*ne01*ne10*2); - - //printf("CBLAS = %f ms, %d x %d x %d x %d\n", (ggml_perf_time_us() - t0)/1000.0, ne0, ne1, ne2, ne3); - - return; - } -#endif - #if GGML_USE_LLAMAFILE const bool src1_cont = ggml_is_contiguous(src1); @@ -12796,19 +12690,7 @@ static void ggml_compute_forward_out_prod_f32( // nb01 >= nb00 - src0 is not transposed // compute by src0 rows -#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) - bool use_blas = ggml_is_matrix(src0) && - ggml_is_matrix(src1) && - ggml_is_contiguous(src0) && - (ggml_is_contiguous(src1) || ggml_is_transposed(src1)); -#endif - if (params->type == GGML_TASK_TYPE_INIT) { -#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) // gemm beta will zero dst - if (use_blas) { - return; - } -#endif if (ith != 0) { return; } @@ -12820,50 +12702,6 @@ static void ggml_compute_forward_out_prod_f32( return; } -#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) - if (use_blas) { - if (params->ith != 0) { // All threads other than the first do no work. - return; - } - // Arguments to ggml_compute_forward_out_prod (expressed as major,minor) - // src0: (k,n) - // src1: (k,m) - // dst: (m,n) - // - // Arguments to sgemm (see https://github.com/Reference-LAPACK/lapack/blob/master/BLAS/SRC/sgemm.f) - // Also expressed as (major,minor) - // a: (m,k): so src1 transposed - // b: (k,n): so src0 - // c: (m,n) - // - // However, if ggml_is_transposed(src1) is true, then - // src1->data already contains a transposed version, so sgemm mustn't - // transpose it further. - - int n = src0->ne[0]; - int k = src0->ne[1]; - int m = src1->ne[0]; - - int transposeA, lda; - - if (!ggml_is_transposed(src1)) { - transposeA = CblasTrans; - lda = m; - } else { - transposeA = CblasNoTrans; - lda = k; - } - - float * a = (float *) ((char *) src1->data); - float * b = (float *) ((char *) src0->data); - float * c = (float *) ((char *) dst->data); - - cblas_sgemm(CblasRowMajor, transposeA, CblasNoTrans, m, n, k, 1.0, a, lda, b, n, 0.0, c, n); - - return; - } -#endif - // dst[:,:,:,:] = 0 // for i2,i3: // for i1: @@ -12993,8 +12831,6 @@ static void ggml_compute_forward_out_prod_q_f32( // nb01 >= nb00 - src0 is not transposed // compute by src0 rows - // TODO: #if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) - if (params->type == GGML_TASK_TYPE_INIT) { if (ith != 0) { return; @@ -13391,6 +13227,8 @@ static void ggml_compute_forward_get_rows_q( const int64_t i10 = (i - i12*ne11*ne10 - i11*ne10); const int64_t i01 = *(int32_t *) ((char *) src1->data + i10*nb10 + i11*nb11 + i12*nb12); + assert(i01 >= 0 && i01 < ne01); + dequantize_row_q( (const void *) ((char *) src0->data + i01*nb01 + i11*nb02 + i12*nb03), (float *) ((char *) dst->data + i10*nb1 + i11*nb2 + i12*nb3), nc); @@ -13434,6 +13272,8 @@ static void ggml_compute_forward_get_rows_f16( const int64_t i10 = (i - i12*ne11*ne10 - i11*ne10); const int64_t i01 = *(int32_t *) ((char *) src1->data + i10*nb10 + i11*nb11 + i12*nb12); + assert(i01 >= 0 && i01 < ne01); + ggml_fp16_to_fp32_row( (const void *) ((char *) src0->data + i01*nb01 + i11*nb02 + i12*nb03), (float *) ((char *) dst->data + i10*nb1 + i11*nb2 + i12*nb3), nc); @@ -13477,7 +13317,9 @@ static void ggml_compute_forward_get_rows_bf16( const int64_t i10 = (i - i12*ne11*ne10 - i11*ne10); const int64_t i01 = *(int32_t *) ((char *) src1->data + i10*nb10 + i11*nb11 + i12*nb12); - ggml_bf16_to_fp32_row( + assert(i01 >= 0 && i01 < ne01); + + ggml_bf16_to_fp32_row( (const void *) ((char *) src0->data + i01*nb01 + i11*nb02 + i12*nb03), (float *) ((char *) dst->data + i10*nb1 + i11*nb2 + i12*nb3), nc); } @@ -13520,6 +13362,8 @@ static void ggml_compute_forward_get_rows_f32( const int64_t i10 = (i - i12*ne11*ne10 - i11*ne10); const int64_t i01 = *(int32_t *) ((char *) src1->data + i10*nb10 + i11*nb11 + i12*nb12); + assert(i01 >= 0 && i01 < ne01); + ggml_vec_cpy_f32(nc, (float *) ((char *) dst->data + i10*nb1 + i11*nb2 + i12*nb3), (float *) ((char *) src0->data + i01*nb01 + i11*nb02 + i12*nb03)); @@ -18893,6 +18737,7 @@ static int ggml_get_n_tasks(struct ggml_tensor * node, int n_threads, int n_cur_ switch (node->op) { case GGML_OP_CPY: case GGML_OP_DUP: + case GGML_OP_CONT: case GGML_OP_ADD: case GGML_OP_ADD1: case GGML_OP_ACC: @@ -18977,7 +18822,6 @@ static int ggml_get_n_tasks(struct ggml_tensor * node, int n_threads, int n_cur_ } break; case GGML_OP_SCALE: case GGML_OP_SET: - case GGML_OP_CONT: case GGML_OP_RESHAPE: case GGML_OP_VIEW: case GGML_OP_PERMUTE: @@ -19137,8 +18981,11 @@ static void ggml_graph_compute_thread_sync_node(int * node_n, struct ggml_comput sched_yield(); } - * node_n = atomic_load(&state->shared->node_n); - if (* node_n != last_node_n) break; + *node_n = atomic_load(&state->shared->node_n); + if (*node_n != last_node_n) { + break; + } + #if defined(__SSE3__) // Tell the processor we're spinning. It's a processor hint for spinlocks. _mm_pause(); @@ -19148,15 +18995,18 @@ static void ggml_graph_compute_thread_sync_node(int * node_n, struct ggml_comput static void ggml_graph_compute_thread_sync_task(int * task_phase, struct ggml_compute_state * state, const bool do_yield) { // wait for other threads to finish - const int last_task_phase = * task_phase; + const int last_task_phase = *task_phase; while (true) { if (do_yield) { sched_yield(); } - * task_phase = atomic_load(&state->shared->node_task); - if (* task_phase != last_task_phase) break; + *task_phase = atomic_load(&state->shared->node_task); + if (*task_phase != last_task_phase) { + break; + } + #if defined(__SSE3__) // Tell the processor we're spinning. It's a processor hint for spinlocks. _mm_pause(); @@ -19356,17 +19206,6 @@ struct ggml_cplan ggml_graph_plan(const struct ggml_cgraph * cgraph, int n_threa { const enum ggml_type vec_dot_type = type_traits[node->src[0]->type].vec_dot_type; -#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) - if (ggml_compute_forward_mul_mat_use_blas(node)) { - if (node->src[0]->type != GGML_TYPE_F32) { - // here we need memory for fully dequantized matrix from src0 - // take into account that src0 can be broadcasted into src1[2,3] - cur = ggml_type_size(GGML_TYPE_F32) - * node->src[0]->ne[0]*node->src[0]->ne[1] - * node->src[1]->ne[2]*node->src[1]->ne[3]; - } - } else -#endif if (node->src[1]->type != vec_dot_type) { cur = ggml_row_size(vec_dot_type, ggml_nelements(node->src[1])); } @@ -22664,7 +22503,7 @@ int ggml_cpu_has_wasm_simd(void) { } int ggml_cpu_has_blas(void) { -#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) || defined(GGML_USE_CUDA) || defined(GGML_USE_VULKAN) || defined(GGML_USE_SYCL) +#if defined(GGML_USE_BLAS) || defined(GGML_USE_CUDA) || defined(GGML_USE_VULKAN) || defined(GGML_USE_SYCL) return 1; #else return 0; diff --git a/llama.cpp b/llama.cpp index 8b675ea99..225ea977f 100644 --- a/llama.cpp +++ b/llama.cpp @@ -21,6 +21,10 @@ # include "ggml-kompute.h" #endif +#ifdef GGML_USE_BLAS +# include "ggml-blas.h" +#endif + #ifdef GGML_USE_METAL # include "ggml-metal.h" #endif @@ -2299,9 +2303,13 @@ struct llama_context { std::vector backends; #ifdef GGML_USE_METAL ggml_backend_t backend_metal = nullptr; +#endif +#ifdef GGML_USE_BLAS + ggml_backend_t backend_blas = nullptr; #endif ggml_backend_t backend_cpu = nullptr; + const llama_model & model; // key + value cache for the self attention @@ -11529,7 +11537,8 @@ static struct ggml_cgraph * llama_build_graph( if (batch.n_tokens < 32 || full_offload) { if (il != -1 && strcmp(name, "norm") == 0) { for (auto * backend : lctx.backends) { - if (ggml_backend_buft_supports_backend(lctx.model.buft_layer[il].buft, backend)) { + if (ggml_backend_supports_buft(backend, lctx.model.buft_layer[il].buft) && + (ggml_backend_supports_op(backend, cur) || ggml_backend_offload_op(backend, cur))) { ggml_backend_sched_set_tensor_backend(lctx.sched, cur, backend); break; } @@ -12026,6 +12035,11 @@ static void llama_graph_compute( ggml_backend_cpu_set_n_threads(lctx.backend_cpu, n_threads); ggml_backend_cpu_set_abort_callback(lctx.backend_cpu, lctx.abort_callback, lctx.abort_callback_data); } +#ifdef GGML_USE_BLAS + if (lctx.backend_blas != nullptr) { + ggml_backend_blas_set_n_threads(lctx.backend_blas, n_threads); + } +#endif ggml_backend_sched_graph_compute_async(lctx.sched, gf); @@ -12248,17 +12262,6 @@ static int llama_decode_internal( } // LLAMA_LOG_INFO("graph build time: %.3f ms (%d nodes, %d leafs)\n", (ggml_time_us() - t_start_us)/1000.0, gf->n_nodes, gf->n_leafs); - // for big prompts, if BLAS is enabled, it is better to use only one thread - // otherwise, the threads are spin-lock waiting for the BLAS calls and are degrading the performance - // TODO: this is mostly important for Apple Silicon where CBLAS is still performing very well - // we still need some threads to process all non-mul_mat ops, but not too much to avoid interfering - // with the BLAS calls. need a better solution - // MoE Special Case: This logic applies when hparams.n_expert == 0, i.e. the model is NOT an MoE model. When an MoE is - // being processed then Accelerate/BLAS will not be involved, so capping would limit performance. - if (n_tokens >= 32 && hparams.n_expert == 0 && ggml_cpu_has_blas() && !ggml_cpu_has_gpublas()) { - n_threads = std::min(4, n_threads); - } - ggml_backend_sched_alloc_graph(lctx.sched, gf); llama_set_inputs(lctx, u_batch); @@ -16251,6 +16254,16 @@ struct llama_context * llama_new_context_with_model( ctx->backends.push_back(backend); } #endif + +#ifdef GGML_USE_BLAS + ctx->backend_blas = ggml_backend_blas_init(); + if (ctx->backend_blas == nullptr) { + LLAMA_LOG_WARN("%s: failed to initialize BLAS backend\n", __func__); + } else { + ctx->backends.push_back(ctx->backend_blas); + } +#endif + #if defined(GGML_USE_RPC) if (model->n_gpu_layers > 0) { for (const auto & endpoint : model->rpc_servers) { From a55eb1bf0fa2fd84147bdfd384391e029d988253 Mon Sep 17 00:00:00 2001 From: Galunid Date: Thu, 13 Jun 2024 09:42:41 +0200 Subject: [PATCH 28/37] readme : Remove outdated instructions from README.md (#7914) [no ci] --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index d1c6190dd..6c24135d6 100644 --- a/README.md +++ b/README.md @@ -622,9 +622,6 @@ python3 -m pip install -r requirements.txt # convert the model to ggml FP16 format python3 convert-hf-to-gguf.py models/mymodel/ -# [Optional] for models using BPE tokenizers -python convert-hf-to-gguf.py models/mymodel/ --vocab-type bpe - # quantize the model to 4-bits (using Q4_K_M method) ./llama-quantize ./models/mymodel/ggml-model-f16.gguf ./models/mymodel/ggml-model-Q4_K_M.gguf Q4_K_M From 172c8256840ffd882ab9992ecedbb587d9b21f15 Mon Sep 17 00:00:00 2001 From: Radoslav Gerganov Date: Thu, 13 Jun 2024 15:18:44 +0300 Subject: [PATCH 29/37] rpc : fix ggml_backend_rpc_supports_buft() (#7918) --- ggml-rpc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ggml-rpc.cpp b/ggml-rpc.cpp index 9b95193d3..22d9524b8 100644 --- a/ggml-rpc.cpp +++ b/ggml-rpc.cpp @@ -624,12 +624,12 @@ GGML_CALL static enum ggml_status ggml_backend_rpc_graph_compute(ggml_backend_t GGML_CALL static bool ggml_backend_rpc_supports_op(ggml_backend_t backend, const ggml_tensor * op) { UNUSED(backend); UNUSED(op); - GGML_ASSERT(false && "not implemented"); - return false; + //TODO: call the remote backend and cache the results + return true; } GGML_CALL static bool ggml_backend_rpc_supports_buft(ggml_backend_t backend, ggml_backend_buffer_type_t buft) { - if (buft->iface.get_name == ggml_backend_rpc_buffer_type_name) { + if (buft->iface.get_name != ggml_backend_rpc_buffer_type_name) { return false; } ggml_backend_rpc_buffer_type_context * buft_ctx = (ggml_backend_rpc_buffer_type_context *)buft->context; From 41b9260f18eb7f325c952006ac46afc1d0d8ad2f Mon Sep 17 00:00:00 2001 From: Elaine Date: Fri, 14 Jun 2024 13:16:49 +0300 Subject: [PATCH 30/37] convert : add Poro-34B-chat tokenizer support (#7713) * support for Poro chat pre-tokenizer * add support for Poro pre-tokenizer * Update convert-hf-to-gguf-update.py Co-authored-by: Georgi Gerganov * Change Poro-34B-chat to poro-chat * Change Poro-34B-chat to poro-chat * Update convert-hf-to-gguf-update.py * Update llama.cpp --------- Co-authored-by: Georgi Gerganov --- convert-hf-to-gguf-update.py | 1 + convert-hf-to-gguf.py | 3 +++ llama.cpp | 8 ++++++++ llama.h | 1 + 4 files changed, 13 insertions(+) diff --git a/convert-hf-to-gguf-update.py b/convert-hf-to-gguf-update.py index f43b15760..fbf1e1ea3 100755 --- a/convert-hf-to-gguf-update.py +++ b/convert-hf-to-gguf-update.py @@ -83,6 +83,7 @@ models = [ {"name": "jina-v2-es", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-es", }, {"name": "jina-v2-de", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-de", }, {"name": "smaug-bpe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/abacusai/Smaug-Llama-3-70B-Instruct", }, + {"name": "poro-chat", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LumiOpen/Poro-34B-chat", }, {"name": "jina-v2-code", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-code", }, ] diff --git a/convert-hf-to-gguf.py b/convert-hf-to-gguf.py index 025405a2c..55ce502db 100755 --- a/convert-hf-to-gguf.py +++ b/convert-hf-to-gguf.py @@ -477,6 +477,9 @@ class Model: if chkhsh == "c136ed14d01c2745d4f60a9596ae66800e2b61fa45643e72436041855ad4089d": # ref: https://huggingface.co/abacusai/Smaug-Llama-3-70B-Instruct res = "smaug-bpe" + if chkhsh == "c7ea5862a53e4272c035c8238367063e2b270d51faa48c0f09e9d5b54746c360": + # ref: https://huggingface.co/LumiOpen/Poro-34B-chat + res = "poro-chat" if chkhsh == "7967bfa498ade6b757b064f31e964dddbb80f8f9a4d68d4ba7998fcf281c531a": # ref: https://huggingface.co/jinaai/jina-embeddings-v2-base-code res = "jina-v2-code" diff --git a/llama.cpp b/llama.cpp index 225ea977f..7f8c259a8 100644 --- a/llama.cpp +++ b/llama.cpp @@ -4713,6 +4713,9 @@ static void llm_load_vocab( } else if ( tokenizer_pre == "smaug-bpe") { vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_SMAUG; + } else if ( + tokenizer_pre == "poro-chat") { + vocab.type_pre = LLAMA_VOCAB_PRE_TYPE_PORO; } else { throw std::runtime_error(format("unknown pre-tokenizer type: '%s'", tokenizer_pre.c_str())); } @@ -13028,6 +13031,11 @@ struct llm_tokenizer_bpe { "(?:'[sS]|'[tT]|'[rR][eE]|'[vV][eE]|'[mM]|'[lL][lL]|'[dD])|[^\\r\\n\\p{L}\\p{N}]?\\p{L}+|\\p{N}| ?[^\\s\\p{L}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+", }); break; + case LLAMA_VOCAB_PRE_TYPE_PORO: + word_collection = unicode_regex_split(text, { + " ?[^(\\s|.,!?…。,、।۔،)]+", + }); + break; default: // default regex for BPE tokenization pre-processing word_collection = unicode_regex_split(text, { diff --git a/llama.h b/llama.h index 62908261f..da310ffaf 100644 --- a/llama.h +++ b/llama.h @@ -86,6 +86,7 @@ extern "C" { LLAMA_VOCAB_PRE_TYPE_OLMO = 12, LLAMA_VOCAB_PRE_TYPE_DBRX = 13, LLAMA_VOCAB_PRE_TYPE_SMAUG = 14, + LLAMA_VOCAB_PRE_TYPE_PORO = 15, }; // note: these values should be synchronized with ggml_rope From 6fcd1331efbfbb89c8c96eba2321bb7b4d0c40e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Fri, 14 Jun 2024 12:20:04 +0200 Subject: [PATCH 31/37] llama : more checks before assuming FIM tokens (#7644) * More checks before assuming FIM tokens for Llama arch * extensive token check --- llama.cpp | 68 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/llama.cpp b/llama.cpp index 7f8c259a8..05591aa43 100644 --- a/llama.cpp +++ b/llama.cpp @@ -4561,35 +4561,6 @@ static void llm_load_vocab( vocab.special_cls_id = -1; vocab.special_mask_id = -1; - // For Fill-In-the-Middle (FIM)/infill models which where converted - // prior to support of FIM special tokens in GGUF, the following - // will allow those models to continue to work. The general names - // of the known models are currently CodeLlama (LLM_ARCH_LLAMA) and - // CodeGemma (LLM_ARCH_GEMMA). This can potentially be removed once - // new versions of these models have been published. - std::string gen_name; - ml.get_key(LLM_KV_GENERAL_NAME, gen_name, false); - - std::transform(gen_name.begin(), gen_name.end(), gen_name.begin(), - [](unsigned char c){ return std::tolower(c); }); - - if (gen_name.find("code") != std::string::npos) { - if (model.arch == LLM_ARCH_LLAMA) { - vocab.special_prefix_id = 32007; - vocab.special_suffix_id = 32008; - vocab.special_middle_id = 32009; - vocab.special_eot_id = 32010; - } else if (model.arch == LLM_ARCH_GEMMA) { - vocab.special_prefix_id = 67; - vocab.special_suffix_id = 69; - vocab.special_middle_id = 68; - // TODO: this is not EOT, it is "file separator" token, needs fix - // https://huggingface.co/google/codegemma-7b-it/blob/9b1d9231388358c04d90bd003458f5070d97db44/tokenizer_config.json#L565-L572 - //vocab.special_eot_id = 70; - vocab.special_eot_id = 107; - } - } - const int add_space_prefix_keyidx = gguf_find_key(ctx, kv(LLM_KV_TOKENIZER_ADD_PREFIX).c_str()); if (add_space_prefix_keyidx != -1) { vocab.add_space_prefix = gguf_get_val_bool(ctx, add_space_prefix_keyidx); @@ -4773,6 +4744,45 @@ static void llm_load_vocab( // determine the newline token: LLaMA "<0x0A>" == 10 == '\n', Falcon 193 == '\n' if (vocab.type == LLAMA_VOCAB_TYPE_SPM) { + // For Fill-In-the-Middle (FIM)/infill models which where converted + // prior to support of FIM special tokens in GGUF, the following + // will allow those models to continue to work. The general names + // of the known models are currently CodeLlama (LLM_ARCH_LLAMA) and + // CodeGemma (LLM_ARCH_GEMMA). This can potentially be removed once + // new versions of these models have been published. + std::string gen_name; + ml.get_key(LLM_KV_GENERAL_NAME, gen_name, false); + + std::transform(gen_name.begin(), gen_name.end(), gen_name.begin(), + [](unsigned char c){ return std::tolower(c); }); + + if (gen_name.find("code") != std::string::npos) { + if (model.arch == LLM_ARCH_LLAMA + && 32010 < vocab.id_to_token.size() + && vocab.id_to_token[32007].text == "
    "
    +              && vocab.id_to_token[32008].text == ""
    +              && vocab.id_to_token[32009].text == ""
    +              && vocab.id_to_token[32010].text == "") {
    +                vocab.special_prefix_id = 32007;
    +                vocab.special_suffix_id = 32008;
    +                vocab.special_middle_id = 32009;
    +                vocab.special_eot_id    = 32010;
    +            } else if (model.arch == LLM_ARCH_GEMMA
    +              && 107 < vocab.id_to_token.size()
    +              && vocab.id_to_token[67].text == "<|fim_prefix|>"
    +              && vocab.id_to_token[69].text == "<|fim_suffix|>"
    +              && vocab.id_to_token[68].text == "<|fim_middle|>"
    +              && vocab.id_to_token[107].text == "") {
    +                vocab.special_prefix_id = 67;
    +                vocab.special_suffix_id = 69;
    +                vocab.special_middle_id = 68;
    +                // TODO: this is not EOT, it is "file separator" token, needs fix
    +                //       https://huggingface.co/google/codegemma-7b-it/blob/9b1d9231388358c04d90bd003458f5070d97db44/tokenizer_config.json#L565-L572
    +                //vocab.special_eot_id    = 70;
    +                vocab.special_eot_id    = 107;
    +            }
    +        }
    +
             try {
                 vocab.linefeed_id = llama_byte_to_token(vocab, '\n');
             } catch (const std::exception & e) {
    
    From e65bbf606c61f49dc06c7ac060cd5ba7ae446025 Mon Sep 17 00:00:00 2001
    From: Radoslav Gerganov 
    Date: Fri, 14 Jun 2024 16:47:41 +0300
    Subject: [PATCH 32/37] llama-bench : fix RPC indication (#7936)
    
    Show "+RPC" when RPC offloading is used
    ---
     examples/llama-bench/llama-bench.cpp | 12 ++++++------
     1 file changed, 6 insertions(+), 6 deletions(-)
    
    diff --git a/examples/llama-bench/llama-bench.cpp b/examples/llama-bench/llama-bench.cpp
    index 61dd1d71a..d641a9f12 100644
    --- a/examples/llama-bench/llama-bench.cpp
    +++ b/examples/llama-bench/llama-bench.cpp
    @@ -714,7 +714,6 @@ struct test {
         static const bool kompute;
         static const bool metal;
         static const bool sycl;
    -    static const bool rpc;
         static const bool gpu_blas;
         static const bool blas;
         static const std::string cpu_info;
    @@ -726,6 +725,7 @@ struct test {
         int n_batch;
         int n_ubatch;
         int n_threads;
    +    bool has_rpc;
         ggml_type type_k;
         ggml_type type_v;
         int n_gpu_layers;
    @@ -751,6 +751,7 @@ struct test {
             n_batch = inst.n_batch;
             n_ubatch = inst.n_ubatch;
             n_threads = inst.n_threads;
    +        has_rpc = !inst.rpc_servers.empty();
             type_k = inst.type_k;
             type_v = inst.type_v;
             n_gpu_layers = inst.n_gpu_layers;
    @@ -810,9 +811,6 @@ struct test {
             if (sycl) {
                 return GGML_SYCL_NAME;
             }
    -        if (rpc) {
    -            return "RPC";
    -        }
             if (gpu_blas) {
                 return "GPU BLAS";
             }
    @@ -882,7 +880,7 @@ struct test {
             std::vector values = {
                 build_commit, std::to_string(build_number),
                 std::to_string(cuda), std::to_string(vulkan), std::to_string(vulkan),
    -            std::to_string(metal), std::to_string(sycl), std::to_string(rpc), std::to_string(gpu_blas), std::to_string(blas),
    +            std::to_string(metal), std::to_string(sycl), std::to_string(has_rpc), std::to_string(gpu_blas), std::to_string(blas),
                 cpu_info, gpu_info,
                 model_filename, model_type, std::to_string(model_size), std::to_string(model_n_params),
                 std::to_string(n_batch), std::to_string(n_ubatch),
    @@ -916,7 +914,6 @@ const bool        test::metal        = !!ggml_cpu_has_metal();
     const bool        test::gpu_blas     = !!ggml_cpu_has_gpublas();
     const bool        test::blas         = !!ggml_cpu_has_blas();
     const bool        test::sycl         = !!ggml_cpu_has_sycl();
    -const bool        test::rpc          = !!ggml_cpu_has_rpc();
     const std::string test::cpu_info     = get_cpu_info();
     const std::string test::gpu_info     = get_gpu_info();
     
    @@ -1182,6 +1179,9 @@ struct markdown_printer : public printer {
                     value = buf;
                 } else if (field == "backend") {
                     value = test::get_backend();
    +                if (t.has_rpc) {
    +                    value += "+RPC";
    +                }
                 } else if (field == "test") {
                     if (t.n_prompt > 0 && t.n_gen == 0) {
                         snprintf(buf, sizeof(buf), "pp%d", t.n_prompt);
    
    From 66ef1ceedf983773c8ceb4d925285d41d4e50e2a Mon Sep 17 00:00:00 2001
    From: Georgi Gerganov 
    Date: Fri, 14 Jun 2024 17:14:09 +0300
    Subject: [PATCH 33/37] metal : utilize max shared memory for mul_mat_id
     (#7935)
    
    ---
     ggml-metal.m | 3 ++-
     1 file changed, 2 insertions(+), 1 deletion(-)
    
    diff --git a/ggml-metal.m b/ggml-metal.m
    index ec9e95302..f894274ca 100644
    --- a/ggml-metal.m
    +++ b/ggml-metal.m
    @@ -1862,9 +1862,10 @@ static enum ggml_status ggml_metal_graph_compute(
                             // ne21 = n_rows
                             const int dst_rows = ne20*ne21;
                             const int dst_rows_min = n_as;
    +                        const int dst_rows_max = (ctx->device.maxThreadgroupMemoryLength - 32 - 8192)/4;
     
                             // max size of the rowids array in the kernel shared buffer
    -                        GGML_ASSERT(dst_rows <= 2048);
    +                        GGML_ASSERT(dst_rows <= dst_rows_max);
     
                             // for now the matrix-matrix multiplication kernel only works on A14+/M1+ SoCs
                             // AMD GPU and older A-chips will reuse matrix-vector multiplication kernel
    
    From 76d66ee0be91e2bec93206e821ee1db8d023cff5 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= 
    Date: Fri, 14 Jun 2024 18:41:49 +0200
    Subject: [PATCH 34/37] CUDA: faster q2_K, q3_K MMQ + int8 tensor cores (#7921)
    
    * CUDA: faster q2_K, q3_K MMQ + int8 tensor cores
    
    * try CI fix
    
    * try CI fix
    
    * try CI fix
    
    * fix data race
    
    * rever q2_K precision related changes
    ---
     ggml-cuda.cu          |   6 +-
     ggml-cuda/argsort.cu  |   1 +
     ggml-cuda/common.cuh  |   5 +
     ggml-cuda/mmq.cuh     | 750 +++++++++++++++++++++++++-----------------
     ggml-cuda/softmax.cu  |   1 +
     ggml-cuda/vecdotq.cuh |  35 +-
     6 files changed, 468 insertions(+), 330 deletions(-)
    
    diff --git a/ggml-cuda.cu b/ggml-cuda.cu
    index 64d3b6747..593fa4cda 100644
    --- a/ggml-cuda.cu
    +++ b/ggml-cuda.cu
    @@ -188,13 +188,15 @@ static ggml_cuda_device_info ggml_cuda_init() {
             info.default_tensor_split[id] = total_vram;
             total_vram += prop.totalGlobalMem;
     
    +        info.devices[id].nsm   = prop.multiProcessorCount;
    +        info.devices[id].smpb  = prop.sharedMemPerBlock;
     #if defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)
    +        info.devices[id].smpbo = prop.sharedMemPerBlock;
             info.devices[id].cc = 100*prop.major + 10*prop.minor + CC_OFFSET_AMD;
     #else
    +        info.devices[id].smpbo = prop.sharedMemPerBlockOptin;
             info.devices[id].cc = 100*prop.major + 10*prop.minor;
     #endif // defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)
    -        info.devices[id].smpb = prop.sharedMemPerBlock;
    -        info.devices[id].nsm  = prop.multiProcessorCount;
         }
     
         for (int id = 0; id < info.device_count; ++id) {
    diff --git a/ggml-cuda/argsort.cu b/ggml-cuda/argsort.cu
    index 164144061..15757ca18 100644
    --- a/ggml-cuda/argsort.cu
    +++ b/ggml-cuda/argsort.cu
    @@ -73,6 +73,7 @@ static void argsort_f32_i32_cuda(const float * x, int * dst, const int ncols, co
         const dim3 block_nums(1, nrows, 1);
         const size_t shared_mem = ncols_pad * sizeof(int);
     
    +    // FIXME: this limit could be raised by ~2-4x on Ampere or newer
         GGML_ASSERT(shared_mem <= ggml_cuda_info().devices[ggml_cuda_get_device()].smpb);
     
         if (order == GGML_SORT_ORDER_ASC) {
    diff --git a/ggml-cuda/common.cuh b/ggml-cuda/common.cuh
    index 7f4764d60..de7c2e434 100644
    --- a/ggml-cuda/common.cuh
    +++ b/ggml-cuda/common.cuh
    @@ -331,6 +331,10 @@ static __device__ __forceinline__ half2 __shfl_xor(half2 var, int laneMask, int
     #define FP16_AVAILABLE
     #endif // (defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) || __CUDA_ARCH__ >= CC_PASCAL
     
    +#if defined(FP16_AVAILABLE) && __CUDA_ARCH__ != 610
    +#define FAST_FP16_AVAILABLE
    +#endif // defined(FP16_AVAILABLE) && __CUDA_ARCH__ != 610
    +
     #if !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && __CUDA_ARCH__ >= CC_VOLTA
     #define FP16_MMA_AVAILABLE
     #endif // !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)) && __CUDA_ARCH__ >= CC_VOLTA
    @@ -661,6 +665,7 @@ struct ggml_cuda_device_info {
             int     cc;                 // compute capability
             int     nsm;                // number of streaming multiprocessors
             size_t  smpb;               // max. shared memory per block
    +        size_t  smpbo;              // max. shared memory per block (with opt-in)
             bool    vmm;                // virtual memory support
             size_t  vmm_granularity;    // granularity of virtual memory
             size_t  total_vram;
    diff --git a/ggml-cuda/mmq.cuh b/ggml-cuda/mmq.cuh
    index 01e2086b4..6d57974fb 100644
    --- a/ggml-cuda/mmq.cuh
    +++ b/ggml-cuda/mmq.cuh
    @@ -10,10 +10,10 @@
     #define MMQ_TILE_Y_K (WARP_SIZE + WARP_SIZE/QI8_1)
     
     typedef void (*load_tiles_mmq_t)(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride);
     typedef void (*vec_dot_mmq_t)(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0);
     typedef void (*mmq_write_back_t)(const float * __restrict__ sum, float * __restrict__ dst, const int & ne0, const int & ne1);
     
    @@ -25,9 +25,8 @@ static_assert(sizeof(block_q8_1_mmq) == 4*QK8_1 + 4*sizeof(half2), "Unexpected b
     static_assert(sizeof(block_q8_1_mmq) == 4*sizeof(block_q8_1),      "Unexpected block_q8_1_mmq size");
     
     struct tile_x_sizes {
    -    int ql;
    +    int qs;
         int dm;
    -    int qh;
         int sc;
     };
     
    @@ -67,16 +66,16 @@ static constexpr __device__ int get_mmq_y_device(int /*mmq_x*/) {
     #endif // __CUDA_ARCH__ >= CC_VOLTA
     #endif // defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)
     
    -#define TILE_X_SIZES_Q4_0 tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI4_0 + mmq_y/QI4_0, 0,                           0}
    -#define TILE_X_SIZES_Q4_1 tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI4_1 + mmq_y/QI4_1, 0,                           0}
    -#define TILE_X_SIZES_Q5_0 tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI5_0 + mmq_y/QI5_0, 0,                           0}
    -#define TILE_X_SIZES_Q5_1 tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI5_1 + mmq_y/QI5_1, 0,                           0}
    -#define TILE_X_SIZES_Q8_0 tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI8_0 + mmq_y/QI8_0, 0,                           0}
    -#define TILE_X_SIZES_Q2_K tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI2_K + mmq_y/QI2_K, 0,                           mmq_y*WARP_SIZE/4 + mmq_y/4}
    -#define TILE_X_SIZES_Q3_K tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI3_K + mmq_y/QI3_K, mmq_y*WARP_SIZE/2 + mmq_y/2, mmq_y*WARP_SIZE/4 + mmq_y/4}
    -#define TILE_X_SIZES_Q4_K tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI4_K + mmq_y/QI4_K, 0,                           mmq_y*WARP_SIZE/8 + mmq_y/8}
    -#define TILE_X_SIZES_Q5_K tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI5_K + mmq_y/QI5_K, 0,                           mmq_y*WARP_SIZE/8 + mmq_y/8}
    -#define TILE_X_SIZES_Q6_K tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI6_K + mmq_y/QI6_K, 0,                           mmq_y*WARP_SIZE/8 + mmq_y/8}
    +#define TILE_X_SIZES_Q4_0 tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI4_0 + mmq_y/QI4_0, 0}
    +#define TILE_X_SIZES_Q4_1 tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI4_1 + mmq_y/QI4_1, 0}
    +#define TILE_X_SIZES_Q5_0 tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI5_0 + mmq_y/QI5_0, 0}
    +#define TILE_X_SIZES_Q5_1 tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI5_1 + mmq_y/QI5_1, 0}
    +#define TILE_X_SIZES_Q8_0 tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI8_0 + mmq_y/QI8_0, 0}
    +#define TILE_X_SIZES_Q2_K tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE       + mmq_y,       0}
    +#define TILE_X_SIZES_Q3_K tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI3_K + mmq_y/QI3_K, mmq_y*WARP_SIZE/4 + mmq_y/4}
    +#define TILE_X_SIZES_Q4_K tile_x_sizes{mmq_y*WARP_SIZE   + mmq_y, mmq_y*WARP_SIZE/QI4_K + mmq_y/QI4_K, mmq_y*WARP_SIZE/8 + mmq_y/8}
    +#define TILE_X_SIZES_Q5_K tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI5_K + mmq_y/QI5_K, mmq_y*WARP_SIZE/8 + mmq_y/8}
    +#define TILE_X_SIZES_Q6_K tile_x_sizes{mmq_y*WARP_SIZE*2 + mmq_y, mmq_y*WARP_SIZE/QI6_K + mmq_y/QI6_K, mmq_y*WARP_SIZE/8 + mmq_y/8}
     
     #define GET_TILE_X_SIZES_BODY                           \
         return type == GGML_TYPE_Q4_0 ? TILE_X_SIZES_Q4_0 : \
    @@ -89,7 +88,7 @@ static constexpr __device__ int get_mmq_y_device(int /*mmq_x*/) {
             type == GGML_TYPE_Q4_K ? TILE_X_SIZES_Q4_K :    \
             type == GGML_TYPE_Q5_K ? TILE_X_SIZES_Q5_K :    \
             type == GGML_TYPE_Q6_K ? TILE_X_SIZES_Q6_K :    \
    -        tile_x_sizes{0, 0, 0, 0}
    +        tile_x_sizes{0, 0, 0}
     
     static tile_x_sizes get_tile_x_sizes_host(const ggml_type type, const int mmq_y) {
         GET_TILE_X_SIZES_BODY;
    @@ -103,9 +102,9 @@ static constexpr __device__ tile_x_sizes get_tile_x_sizes_device(ggml_type type)
     // ------------------------------------------------------------
     
     template  static __device__ __forceinline__ void load_tiles_q4_0(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const int kbx  = threadIdx.x / QI4_0;
         const int kqsx = threadIdx.x % QI4_0;
    @@ -122,7 +121,7 @@ template  static __device__ __forceinlin
     
             const block_q4_0 * bxi = (const block_q4_0 *) x + kbx0 + i*stride + kbx;
     
    -        x_ql[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8(bxi->qs, kqsx);
    +        x_qs[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8(bxi->qs, kqsx);
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI4_0;
    @@ -144,10 +143,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q4_0_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const float * x_df = (const float *) x_dm;
         const int   * y_qs = (const int   *) y + 4;
    @@ -172,7 +170,7 @@ static __device__ __forceinline__ void vec_dot_q4_0_q8_1_dp4a(
                 }
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q4_0_q8_1_impl
    -                (&x_ql[i*(WARP_SIZE + 1) + k0], u, x_df[i*(WARP_SIZE/QI4_0) + i/QI4_0 + k0/QI4_0],
    +                (&x_qs[i*(WARP_SIZE + 1) + k0], u, x_df[i*(WARP_SIZE/QI4_0) + i/QI4_0 + k0/QI4_0],
                     y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]);
             }
         }
    @@ -180,10 +178,10 @@ static __device__ __forceinline__ void vec_dot_q4_0_q8_1_dp4a(
     
     template 
     static __device__ __forceinline__ void vec_dot_q4_0_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
    +    GGML_UNUSED(x_sc);
     
         typedef mma_int_A_I16K8 mma_A;
         typedef mma_int_B_J8K8  mma_B;
    @@ -205,7 +203,7 @@ static __device__ __forceinline__ void vec_dot_q4_0_q8_1_mma(
             const int k     = k0 + mma_A::get_k(l) % QI4_0;
             const int shift =   4*(mma_A::get_k(l) / QI4_0);
     
    -        A.x[l] = __vsubss4((x_ql[i*(WARP_SIZE + 1) + k] >> shift) & 0x0F0F0F0F, 0x08080808);
    +        A.x[l] = __vsubss4((x_qs[i*(WARP_SIZE + 1) + k] >> shift) & 0x0F0F0F0F, 0x08080808);
         }
     #pragma unroll
         for (int l = 0; l < mma_C::ne/2; ++l) {
    @@ -240,12 +238,16 @@ static __device__ __forceinline__ void vec_dot_q4_0_q8_1_mma(
                 sum[(j0/B.J)*C.ne + l] += dA[l/2]*__low2float(dsB[l%2])*C.x[l];
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template  static __device__ __forceinline__ void load_tiles_q4_1(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const int kbx  = threadIdx.x / QI4_1;
         const int kqsx = threadIdx.x % QI4_1;
    @@ -260,7 +262,7 @@ template  static __device__ __forceinlin
     
             const block_q4_1 * bxi = (const block_q4_1 *) x + kbx0 + i*stride + kbx;
     
    -        x_ql[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8_aligned(bxi->qs, kqsx);
    +        x_qs[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8_aligned(bxi->qs, kqsx);
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI4_1;
    @@ -282,10 +284,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q4_1_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const int   * y_qs = (const int   *) y + 4;
         const half2 * y_ds = (const half2 *) y;
    @@ -309,7 +310,7 @@ static __device__ __forceinline__ void vec_dot_q4_1_q8_1_dp4a(
                 }
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q4_1_q8_1_impl
    -                (&x_ql[i*(WARP_SIZE + 1) + k0], u, x_dm[i*(WARP_SIZE/QI4_1) + i/QI4_1 + k0/QI4_1],
    +                (&x_qs[i*(WARP_SIZE + 1) + k0], u, x_dm[i*(WARP_SIZE/QI4_1) + i/QI4_1 + k0/QI4_1],
                     y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]);
             }
         }
    @@ -317,10 +318,10 @@ static __device__ __forceinline__ void vec_dot_q4_1_q8_1_dp4a(
     
     template 
     static __device__ __forceinline__ void vec_dot_q4_1_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
    +    GGML_UNUSED(x_sc);
     
         typedef mma_int_A_I16K8 mma_A;
         typedef mma_int_B_J8K8  mma_B;
    @@ -341,7 +342,7 @@ static __device__ __forceinline__ void vec_dot_q4_1_q8_1_mma(
             const int k     = k0 + mma_A::get_k(l) % QI4_0;
             const int shift =   4*(mma_A::get_k(l) / QI4_0);
     
    -        A.x[l] = (x_ql[i*(WARP_SIZE + 1) + k] >> shift) & 0x0F0F0F0F;
    +        A.x[l] = (x_qs[i*(WARP_SIZE + 1) + k] >> shift) & 0x0F0F0F0F;
         }
     #pragma unroll
         for (int l = 0; l < mma_C::ne/2; ++l) {
    @@ -377,12 +378,16 @@ static __device__ __forceinline__ void vec_dot_q4_1_q8_1_mma(
                 sum[(j0/B.J)*C.ne + l] += __low2float(dmA_dsB)*C.x[l] + __high2float(dmA_dsB);
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template  static __device__ __forceinline__ void load_tiles_q5_0(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const int kbx  = threadIdx.x / QI5_0;
         const int kqsx = threadIdx.x % QI5_0;
    @@ -407,7 +412,7 @@ template  static __device__ __forceinlin
             qs0    |= (qh << 25)   & 0x10000000;  // 3 -> 28
             qs0     = __vsubss4(qs0, 0x10101010); // subtract 16
     
    -        x_ql[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+0] = qs0;
    +        x_qs[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+0] = qs0;
     
             int qs1 = (ql >>  4)   & 0x0F0F0F0F;
             qs1    |= (qh >> 12)   & 0x00000010;  // 16 ->  4
    @@ -416,7 +421,7 @@ template  static __device__ __forceinlin
             qs1    |= (qh <<  9)   & 0x10000000;  // 19 -> 28
             qs1     = __vsubss4(qs1, 0x10101010); // subtract 16
     
    -        x_ql[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+1] = qs1;
    +        x_qs[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+1] = qs1;
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI5_0;
    @@ -439,10 +444,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q5_0_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const float * x_dmf = (const float *) x_dm;
         const int   * y_qs  = (const int   *) y + 4;
    @@ -468,17 +472,17 @@ static __device__ __forceinline__ void vec_dot_q5_0_q8_1_dp4a(
                 }
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q8_0_q8_1_impl
    -                (&x_ql[i*(2*WARP_SIZE + 1) + 2*k0], u, x_dmf[index_bx], y_df[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]);
    +                (&x_qs[i*(2*WARP_SIZE + 1) + 2*k0], u, x_dmf[index_bx], y_df[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]);
             }
         }
     }
     
     template 
     static __device__ __forceinline__ void vec_dot_q5_0_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
    +    GGML_UNUSED(x_sc);
     
         typedef mma_int_A_I16K8 mma_A;
         typedef mma_int_B_J8K8  mma_B;
    @@ -499,7 +503,7 @@ static __device__ __forceinline__ void vec_dot_q5_0_q8_1_mma(
             const int i     =    i0 + mma_A::get_i(l);
             const int k     = 2*(k0 + mma_A::get_k(l) % QI5_0) + mma_A::get_k(l) / QI5_0;
     
    -        A.x[l] = x_ql[i*(2*WARP_SIZE + 1) + k];
    +        A.x[l] = x_qs[i*(2*WARP_SIZE + 1) + k];
         }
     #pragma unroll
         for (int l = 0; l < mma_C::ne/2; ++l) {
    @@ -534,12 +538,16 @@ static __device__ __forceinline__ void vec_dot_q5_0_q8_1_mma(
                 sum[(j0/B.J)*C.ne + l] += dA[l/2]*dB[l%2]*C.x[l];
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template  static __device__ __forceinline__ void load_tiles_q5_1(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const int kbx  = threadIdx.x / QI5_1;
         const int kqsx = threadIdx.x % QI5_1;
    @@ -563,7 +571,7 @@ template  static __device__ __forceinlin
             qs0    |= (qh << 18) & 0x00100000; // 2 -> 20
             qs0    |= (qh << 25) & 0x10000000; // 3 -> 28
     
    -        x_ql[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+0] = qs0;
    +        x_qs[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+0] = qs0;
     
             int qs1 = (ql >>  4) & 0x0F0F0F0F;
             qs1    |= (qh >> 12) & 0x00000010; // 16 ->  4
    @@ -571,7 +579,7 @@ template  static __device__ __forceinlin
             qs1    |= (qh <<  2) & 0x00100000; // 18 -> 20
             qs1    |= (qh <<  9) & 0x10000000; // 19 -> 28
     
    -        x_ql[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+1] = qs1;
    +        x_qs[i * (2*WARP_SIZE + 1) + 2*threadIdx.x+1] = qs1;
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI5_1;
    @@ -593,10 +601,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q5_1_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const int   * y_qs  = (const int   *) y + 4;
         const half2 * y_ds  = (const half2 *) y;
    @@ -621,17 +628,17 @@ static __device__ __forceinline__ void vec_dot_q5_1_q8_1_dp4a(
                 }
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q8_1_q8_1_impl
    -                (&x_ql[i*(2*WARP_SIZE + 1) + 2*k0], u, x_dm[index_bx], y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]);
    +                (&x_qs[i*(2*WARP_SIZE + 1) + 2*k0], u, x_dm[index_bx], y_ds[j*MMQ_TILE_Y_K + (2*k0/QI8_1) % (WARP_SIZE/QI8_1)]);
             }
         }
     }
     
     template 
     static __device__ __forceinline__ void vec_dot_q5_1_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
    +    GGML_UNUSED(x_sc);
     
         typedef mma_int_A_I16K8 mma_A;
         typedef mma_int_B_J8K8  mma_B;
    @@ -651,7 +658,7 @@ static __device__ __forceinline__ void vec_dot_q5_1_q8_1_mma(
             const int i     =    i0 + mma_A::get_i(l);
             const int k     = 2*(k0 + mma_A::get_k(l) % QI5_1) + mma_A::get_k(l) / QI5_1;
     
    -        A.x[l] = x_ql[i*(2*WARP_SIZE + 1) + k];
    +        A.x[l] = x_qs[i*(2*WARP_SIZE + 1) + k];
         }
     #pragma unroll
         for (int l = 0; l < mma_C::ne/2; ++l) {
    @@ -687,13 +694,16 @@ static __device__ __forceinline__ void vec_dot_q5_1_q8_1_mma(
                 sum[(j0/B.J)*C.ne + l] += __low2float(dmA_dsB)*C.x[l] + __high2float(dmA_dsB);
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template  static __device__ __forceinline__ void load_tiles_q8_0(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const int kbx  = threadIdx.x / QI8_0;
         const int kqsx = threadIdx.x % QI8_0;
    @@ -709,7 +719,7 @@ template  static __device__ __forceinlin
     
             const block_q8_0 * bxi = (const block_q8_0 *) x + kbx0 + i*stride + kbx;
     
    -        x_ql[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_int8(bxi->qs, kqsx);
    +        x_qs[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_int8(bxi->qs, kqsx);
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI8_0;
    @@ -731,10 +741,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q8_0_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +    GGML_UNUSED(x_sc);
     
         const float * x_dmf = (const float *) x_dm;
         const int   * y_qs  = (const int   *) y + 4;
    @@ -749,7 +758,7 @@ static __device__ __forceinline__ void vec_dot_q8_0_q8_1_dp4a(
                 const int i = i0 + threadIdx.x;
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q8_0_q8_1_impl
    -                (&x_ql[i*(WARP_SIZE + 1) + k0], &y_qs[j*MMQ_TILE_Y_K + k0], x_dmf[i*(WARP_SIZE/QI8_0) + i/QI8_0 + k0/QI8_0],
    +                (&x_qs[i*(WARP_SIZE + 1) + k0], &y_qs[j*MMQ_TILE_Y_K + k0], x_dmf[i*(WARP_SIZE/QI8_0) + i/QI8_0 + k0/QI8_0],
                     y_df[j*MMQ_TILE_Y_K + k0/QI8_1]);
             }
         }
    @@ -757,10 +766,10 @@ static __device__ __forceinline__ void vec_dot_q8_0_q8_1_dp4a(
     
     template 
     static __device__ __forceinline__ void vec_dot_q8_0_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
    +    GGML_UNUSED(x_sc);
     
         typedef mma_int_A_I16K8 mma_A;
         typedef mma_int_B_J8K8  mma_B;
    @@ -781,7 +790,7 @@ static __device__ __forceinline__ void vec_dot_q8_0_q8_1_mma(
             const int i = i0 + mma_A::get_i(l);
             const int k = k0 + mma_A::get_k(l);
     
    -        A.x[l] = x_ql[i*(WARP_SIZE + 1) + k];
    +        A.x[l] = x_qs[i*(WARP_SIZE + 1) + k];
         }
     #pragma unroll
         for (int l = 0; l < mma_C::ne/2; ++l) {
    @@ -816,12 +825,15 @@ static __device__ __forceinline__ void vec_dot_q8_0_q8_1_mma(
                 sum[(j0/B.J)*C.ne + l] += C.x[l]*dA[l/2]*dB[l%2];
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template  static __device__ __forceinline__ void load_tiles_q2_K(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh);
     
         const int kbx  = threadIdx.x / QI2_K;
         const int kqsx = threadIdx.x % QI2_K;
    @@ -836,48 +848,42 @@ template  static __device__ __forceinlin
     
             const block_q2_K * bxi = (const block_q2_K *) x + kbx0 + i*stride + kbx;
     
    -        x_ql[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8_aligned(bxi->qs, kqsx);
    -    }
    -
    -    const int blocks_per_tile_x_row = WARP_SIZE / QI2_K;
    -    const int kbxd = threadIdx.x % blocks_per_tile_x_row;
    +        const int x_ql_0 = get_int_from_uint8(bxi->qs, kqsx);
     
     #pragma unroll
    -    for (int i0 = 0; i0 < mmq_y; i0 += nwarps * QI2_K) {
    -        int i = (i0 + threadIdx.y * QI2_K + threadIdx.x / blocks_per_tile_x_row) % mmq_y;
    +        for (int l = 0; l < QR2_K; ++l) {
    +            const int k = kbx*QI2_K + (kqsx/8)*8 + l*2 + (kqsx % 8)/4;
     
    -        if (need_check) {
    -            i = min(i, i_max);
    +            int x_qs_k = ((x_ql_0 >> (2*l)) & 0x03030303) << (2*(kqsx % 4));
    +            x_qs_k |= __shfl_xor_sync(0xFFFFFFFF, x_qs_k, 1, WARP_SIZE);
    +            x_qs_k |= __shfl_xor_sync(0xFFFFFFFF, x_qs_k, 2, WARP_SIZE);
    +
    +            if (kqsx % QR2_K != 0) {
    +                continue;
    +            }
    +
    +            x_qs[i*(WARP_SIZE + 1) + k] = x_qs_k;
             }
     
    -        const block_q2_K * bxi = (const block_q2_K *) x + kbx0 + i*stride + kbxd;
    +        const int sc_m = bxi->scales[kqsx];
    +#ifdef FAST_FP16_AVAILABLE
    +        const half2 x_dm_ik = __hmul2(bxi->dm, make_half2(sc_m & 0x0F, sc_m >> 4));
    +#else
    +        const float2 bxi_dmf = __half22float2(bxi->dm);
    +        const half2 x_dm_ik = make_half2(bxi_dmf.x*(sc_m & 0x0F), bxi_dmf.y*(sc_m >> 4));
    +#endif // FAST_FP16_AVAILABLE
     
    -        x_dm[i * (WARP_SIZE/QI2_K) + i / QI2_K + kbxd] = bxi->dm;
    -    }
    -
    -#pragma unroll
    -    for (int i0 = 0; i0 < mmq_y; i0 += nwarps * 4) {
    -        int i = i0 + threadIdx.y * 4 + threadIdx.x / (WARP_SIZE/4);
    -
    -        if (need_check) {
    -            i = min(i, i_max);
    -        }
    -
    -        const block_q2_K * bxi = (const block_q2_K *) x + kbx0 + i*stride + (threadIdx.x % (WARP_SIZE/4)) / (QI2_K/4);
    -
    -        x_sc[i * (WARP_SIZE/4) + i / 4 + threadIdx.x % (WARP_SIZE/4)] = get_int_from_uint8_aligned(bxi->scales, threadIdx.x % (QI2_K/4));
    +        x_dm[i*(WARP_SIZE + 1) + threadIdx.x] = x_dm_ik;
         }
     }
     
     template 
    -static __device__ __forceinline__ void vec_dot_q2_K_q8_1_mul_mat(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +static __device__ __forceinline__ void vec_dot_q2_K_q8_1_dp4a(
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
     
    -    GGML_UNUSED(x_qh);
    -
    -    const int   * y_qs  = (const int   *) y + 4;
    -    const float * y_df  = (const float *) y;
    +    const int   * y_qs = (const int   *) y + 4;
    +    const float * y_df = (const float *) y;
     
     #pragma unroll
         for (int j0 = 0; j0 < mmq_x; j0 += nwarps) {
    @@ -887,30 +893,99 @@ static __device__ __forceinline__ void vec_dot_q2_K_q8_1_mul_mat(
             for (int i0 = 0; i0 < mmq_y; i0 += WARP_SIZE) {
                 const int i = i0 + threadIdx.x;
     
    -            const int kbx = k0 / QI2_K;
    -            const int ky  = (k0 % QI2_K) * QR2_K;
    -
    -            int v[QR2_K*VDR_Q2_K_Q8_1_MMQ];
    -
    -            const int kqsx = i*(WARP_SIZE + 1) + kbx*QI2_K + (QI2_K/2) * (ky/(2*QI2_K)) + ky % (QI2_K/2);
    -            const int shift = 2 * ((ky % (2*QI2_K)) / (QI2_K/2));
    -
    -#pragma unroll
    -            for (int l = 0; l < QR2_K*VDR_Q2_K_Q8_1_MMQ; ++l) {
    -                v[l] = (x_ql[kqsx + l] >> shift) & 0x03030303;
    -            }
    -
    -            const uint8_t * scales = ((const uint8_t *) &x_sc[i*(WARP_SIZE/4) + i/4 + kbx*4]) + ky/4;
    -
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q2_K_q8_1_impl_mmq(
    -                v, &y_qs[j*MMQ_TILE_Y_K + (QR2_K*k0) % WARP_SIZE], scales,
    -                x_dm[i*(WARP_SIZE/QI2_K) + i/QI2_K + kbx], y_df[j*MMQ_TILE_Y_K + ((QR2_K*k0) % WARP_SIZE)/QI8_1]);
    +                &x_qs[i*(WARP_SIZE + 1) + k0], &y_qs[j*MMQ_TILE_Y_K + (QR2_K*k0) % WARP_SIZE],
    +                &x_dm[i*(WARP_SIZE + 1) + k0], y_df[j*MMQ_TILE_Y_K + ((QR2_K*k0) % WARP_SIZE)/QI8_1]);
             }
         }
     }
     
    +template 
    +static __device__ __forceinline__ void vec_dot_q2_K_q8_1_mma(
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
    +    const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    +#ifdef INT8_MMA_AVAILABLE
    +
    +    typedef mma_int_A_I16K4 mma_A;
    +    typedef mma_int_B_J8K4  mma_B;
    +    typedef mma_int_C_I16J8 mma_C;
    +
    +    const int   * y_qs = (const int   *) y + 4;
    +    const float * y_df = (const float *) y;
    +
    +    const int i0 = threadIdx.y*mma_A::I;
    +    static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y");
    +
    +    mma_A   A[2];
    +    float  dA[mma_C::ne/2][2];
    +    float  mA[mma_C::ne/2][2];
    +
    +#pragma unroll
    +    for (int l = 0; l < mma_A::ne; ++l) {
    +        const int i = i0 + mma_A::get_i(l);
    +        const int shift = 2*mma_A::get_k(l);
    +
    +        A[0].x[l] = (x_qs[i*(WARP_SIZE + 1) + k0 + 0] >> shift) & 0x03030303;
    +        A[1].x[l] = (x_qs[i*(WARP_SIZE + 1) + k0 + 1] >> shift) & 0x03030303;
    +    }
    +
    +#pragma unroll
    +    for (int l = 0; l < mma_C::ne/2; ++l) {
    +        const int i = i0 + mma_C::get_i(2*l);
    +
    +#pragma unroll
    +        for (int kk = 0; kk < 2; ++kk) {
    +            const float2 dm = __half22float2(x_dm[i*(WARP_SIZE + 1) + k0 + kk]);
    +
    +            dA[l][kk] = dm.x;
    +            mA[l][kk] = dm.y;
    +        }
    +    }
    +
    +#pragma unroll
    +    for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) {
    +        mma_C Cd[2];
    +        mma_C Cm[2];
    +        mma_B B[2];
    +        float dB[mma_C::ne/2];
    +
    +#pragma unroll
    +        for (int l = 0; l < mma_B::ne; ++l) {
    +            const int j = j0 + mma_B::get_j(l);
    +            const int k = (4*k0 + mma_B::get_k(l)) % WARP_SIZE;
    +
    +            B[0].x[l] = y_qs[j*MMQ_TILE_Y_K + k + 0];
    +            B[1].x[l] = y_qs[j*MMQ_TILE_Y_K + k + mma_B::K];
    +        }
    +#pragma unroll
    +        for (int l = 0; l < mma_C::ne/2; ++l) {
    +            const int j = j0 + mma_C::get_j(l);
    +
    +            dB[l] = y_df[j*MMQ_TILE_Y_K + ((4*k0)/QI8_1) % (WARP_SIZE/QI8_1)];
    +        }
    +
    +        Cd[0].mma_K4(A[0], B[0]);
    +        Cd[1].mma_K4(A[1], B[1]);
    +
    +        mma_A A1;
    +        A1.x[0] = 0x01010101;
    +        A1.x[1] = 0x01010101;
    +        Cm[0].mma_K4(A1, B[0]);
    +        Cm[1].mma_K4(A1, B[1]);
    +
    +#pragma unroll
    +        for (int l = 0; l < mma_C::ne; ++l) {
    +            sum[(j0/mma_B::J)*mma_C::ne + l] += (Cd[0].x[l]*dA[l/2][0] + Cd[1].x[l]*dA[l/2][1] - Cm[0].x[l]*mA[l/2][0] - Cm[1].x[l]*mA[l/2][1])*dB[l%2];
    +        }
    +    }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
    +}
    +
     template  static __device__ __forceinline__ void load_tiles_q3_K(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
     
         const int kbx  = threadIdx.x / QI3_K;
    @@ -926,7 +1001,25 @@ template  static __device__ __forceinlin
     
             const block_q3_K * bxi = (const block_q3_K *) x + kbx0 + i*stride + kbx;
     
    -        x_ql[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8(bxi->qs, kqsx);
    +        const int x_ql_0 = get_int_from_uint8(bxi->qs,    kqsx);
    +        const int x_qh_0 = get_int_from_uint8(bxi->hmask, kqsx % (QI3_K/2)) >> (4 * (kqsx / (QI3_K/2)));
    +
    +#pragma unroll
    +        for (int l = 0; l < QR3_K; ++l) {
    +            const int k = kbx*(QR3_K*QI3_K) + (kqsx/8)*32 + l*8 + kqsx % 8;
    +
    +            const int x_ql_k =  (x_ql_0 >> (2*l))       & 0x03030303;
    +            const int x_qh_k = ((x_qh_0 >>    l)  << 2) & 0x04040404;
    +
    +            int x_qs_k = (x_ql_k | x_qh_k) << (4*(k%2));
    +            x_qs_k |= __shfl_xor_sync(0xFFFFFFFF, x_qs_k, 1, WARP_SIZE);
    +
    +            if (kqsx % 2 != 0) {
    +                continue;
    +            }
    +
    +            x_qs[i*(2*WARP_SIZE + 1) + k/2] = x_qs_k;
    +        }
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI3_K;
    @@ -946,20 +1039,6 @@ template  static __device__ __forceinlin
             x_dmf[i * (WARP_SIZE/QI3_K) + i / QI3_K + kbxd] = bxi->d;
         }
     
    -#pragma unroll
    -    for (int i0 = 0; i0 < mmq_y; i0 += nwarps * 2) {
    -        int i = i0 + threadIdx.y * 2 + threadIdx.x / (WARP_SIZE/2);
    -
    -        if (need_check) {
    -            i = min(i, i_max);
    -        }
    -
    -        const block_q3_K * bxi = (const block_q3_K *) x + kbx0 + i*stride + (threadIdx.x % (WARP_SIZE/2)) / (QI3_K/2);
    -
    -        // invert the mask with ~ so that a 0/1 results in 4/0 being subtracted
    -        x_qh[i * (WARP_SIZE/2) + i / 2 + threadIdx.x % (WARP_SIZE/2)] = ~get_int_from_uint8(bxi->hmask, threadIdx.x % (QI3_K/2));
    -    }
    -
     #pragma unroll
         for (int i0 = 0; i0 < mmq_y; i0 += nwarps * 4) {
             int i = i0 + threadIdx.y * 4 + threadIdx.x / (WARP_SIZE/4);
    @@ -987,13 +1066,13 @@ template  static __device__ __forceinlin
     }
     
     template 
    -static __device__ __forceinline__ void vec_dot_q3_K_q8_1_mul_mat(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +static __device__ __forceinline__ void vec_dot_q3_K_q8_1_dp4a(
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
     
    -    const float * x_dmf = (const float *) x_dm;
    -    const int   * y_qs  = (const int   *) y + 4;
    -    const float * y_df  = (const float *) y;
    +    const float * x_df = (const float *) x_dm;
    +    const int   * y_qs = (const int   *) y + 4;
    +    const float * y_df = (const float *) y;
     
     #pragma unroll
         for (int j0 = 0; j0 < mmq_x; j0 += nwarps) {
    @@ -1008,31 +1087,102 @@ static __device__ __forceinline__ void vec_dot_q3_K_q8_1_mul_mat(
     
                 const int8_t * scales = ((const int8_t *) (x_sc + i * (WARP_SIZE/4) + i/4 + kbx*4)) + ky/4;
     
    -            int v[QR3_K*VDR_Q3_K_Q8_1_MMQ];
    -
    -#pragma unroll
    -            for (int l = 0; l < QR3_K*VDR_Q3_K_Q8_1_MMQ; ++l) {
    -                const int kqsx = i*(WARP_SIZE + 1) + kbx*QI3_K + (QI3_K/2) * (ky/(2*QI3_K)) + ky % (QI3_K/2);
    -                const int shift = 2 * ((ky % 32) / 8);
    -                const int vll = (x_ql[kqsx + l] >> shift) & 0x03030303;
    -
    -                const int vh = x_qh[i*(WARP_SIZE/2) + i/2 + kbx * (QI3_K/2) + (ky+l)%8] >> ((ky+l) / 8);
    -                const int vlh = (vh << 2) & 0x04040404;
    -
    -                v[l] = __vsubss4(vll, vlh);
    -            }
    -
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q3_K_q8_1_impl_mmq(
    -                v, &y_qs[j*MMQ_TILE_Y_K + (k0*QR3_K) % WARP_SIZE], scales,
    -                x_dmf[i*(WARP_SIZE/QI3_K) + i/QI3_K + kbx], y_df[j*MMQ_TILE_Y_K + ((k0*QR3_K) % WARP_SIZE)/QI8_1]);
    +                &x_qs[i*(2*WARP_SIZE + 1) + 2*k0], &y_qs[j*MMQ_TILE_Y_K + (k0*QR3_K) % WARP_SIZE], scales,
    +                x_df[i*(WARP_SIZE/QI3_K) + i/QI3_K + kbx], y_df[j*MMQ_TILE_Y_K + ((k0*QR3_K) % WARP_SIZE)/QI8_1]);
             }
         }
     }
     
    +template 
    +static __device__ __forceinline__ void vec_dot_q3_K_q8_1_mma(
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
    +    const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    +#ifdef INT8_MMA_AVAILABLE
    +
    +    typedef mma_int_A_I16K4 mma_A;
    +    typedef mma_int_B_J8K4  mma_B;
    +    typedef mma_int_C_I16J8 mma_C;
    +
    +    const float * x_df = (const float *) x_dm;
    +    const int   * y_qs = (const int   *) y + 4;
    +    const float * y_df = (const float *) y;
    +
    +    const int i0 = threadIdx.y*mma_A::I;
    +    static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y");
    +
    +    mma_A   A[2];
    +    int   scA[mma_C::ne/2][2];
    +    float  dA[mma_C::ne/2];
    +
    +#pragma unroll
    +    for (int l = 0; l < mma_A::ne; ++l) {
    +        const int i = i0 + mma_A::get_i(l);
    +        const int k = QR3_K*k0 + mma_A::get_k(l);
    +
    +        A[0].x[l] = (x_qs[i*(2*WARP_SIZE + 1) + k/2 + 0]          >> (4*(k%2))) & 0x0F0F0F0F;
    +        A[1].x[l] = (x_qs[i*(2*WARP_SIZE + 1) + k/2 + mma_A::K/2] >> (4*(k%2))) & 0x0F0F0F0F;
    +        A[0].x[l] = __vsubss4(A[0].x[l], 0x04040404);
    +        A[1].x[l] = __vsubss4(A[1].x[l], 0x04040404);
    +    }
    +
    +#pragma unroll
    +    for (int l = 0; l < mma_C::ne/2; ++l) {
    +        const int i = i0 + mma_C::get_i(2*l);
    +
    +        const int kbx  = k0 / QI3_K;
    +        const int ky  = (k0 % QI3_K) * QR3_K;
    +        const int8_t * sc = ((const int8_t *) (x_sc + i * (WARP_SIZE/4) + i/4 + kbx*4)) + ky/4;
    +
    +        scA[l][0] = sc[0];
    +        scA[l][1] = sc[1];
    +    }
    +
    +#pragma unroll
    +    for (int l = 0; l < mma_C::ne/2; ++l) {
    +        const int i = i0 + mma_C::get_i(2*l);
    +
    +        dA[l] = x_df[i*(WARP_SIZE/QI3_K) + i/QI3_K + k0/QI3_K];
    +    }
    +
    +#pragma unroll
    +    for (int j0 = 0; j0 < mmq_x; j0 += mma_int_B_J8K8::J) {
    +        mma_C C[2];
    +        mma_B B[2];
    +        float dB[mma_C::ne/2];
    +
    +#pragma unroll
    +        for (int l = 0; l < mma_B::ne; ++l) {
    +            const int j = j0 + mma_B::get_j(l);
    +            const int k = (4*k0 + mma_B::get_k(l)) % WARP_SIZE;
    +
    +            B[0].x[l] = y_qs[j*MMQ_TILE_Y_K + k + 0];
    +            B[1].x[l] = y_qs[j*MMQ_TILE_Y_K + k + mma_B::K];
    +        }
    +#pragma unroll
    +        for (int l = 0; l < mma_C::ne/2; ++l) {
    +            const int j = j0 + mma_C::get_j(l);
    +
    +            dB[l] = y_df[j*MMQ_TILE_Y_K + ((4*k0)/QI8_1) % (WARP_SIZE/QI8_1)];
    +        }
    +
    +        C[0].mma_K4(A[0], B[0]);
    +        C[1].mma_K4(A[1], B[1]);
    +
    +#pragma unroll
    +        for (int l = 0; l < mma_C::ne; ++l) {
    +            sum[(j0/mma_B::J)*mma_C::ne + l] += (C[0].x[l]*scA[l/2][0] + C[1].x[l]*scA[l/2][1])*dA[l/2]*dB[l%2];
    +        }
    +    }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
    +}
    +
     template  static __device__ __forceinline__ void load_tiles_q4_K(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh);
     
         const int kbx  = 0;           // threadIdx.x / QI4_K
         const int kqsx = threadIdx.x; // threadIdx.x % QI4_K
    @@ -1047,7 +1197,7 @@ template  static __device__ __forceinlin
     
             const block_q4_K * bxi = (const block_q4_K *) x + kbx0 + i*stride + kbx;
     
    -        x_ql[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8_aligned(bxi->qs, kqsx);
    +        x_qs[i * (WARP_SIZE + 1) + threadIdx.x] = get_int_from_uint8_aligned(bxi->qs, kqsx);
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI4_K;  // == 1 if QK_K == 256
    @@ -1090,11 +1240,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q4_K_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
     
    -    GGML_UNUSED(x_qh);
    -
         const int   * y_qs = (const int   *) y + 4;
         const half2 * y_ds = (const half2 *) y;
     
    @@ -1109,7 +1257,7 @@ static __device__ __forceinline__ void vec_dot_q4_K_q8_1_dp4a(
                 const uint8_t * sc = ((const uint8_t *) &x_sc[i * (WARP_SIZE/8) + i/8 + k0/16]) + 2*((k0 % 16) / 8);
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q4_K_q8_1_impl_mmq(
    -                &x_ql[i*(WARP_SIZE + 1) + k0], &y_qs[j*MMQ_TILE_Y_K + (QR4_K*k0) % WARP_SIZE], sc, sc+8,
    +                &x_qs[i*(WARP_SIZE + 1) + k0], &y_qs[j*MMQ_TILE_Y_K + (QR4_K*k0) % WARP_SIZE], sc, sc+8,
                     x_dm[i*(WARP_SIZE/QI4_K) + i/QI4_K], &y_ds[j*MMQ_TILE_Y_K + ((QR4_K*k0) % WARP_SIZE)/QI8_1]);
             }
         }
    @@ -1117,10 +1265,9 @@ static __device__ __forceinline__ void vec_dot_q4_K_q8_1_dp4a(
     
     template 
     static __device__ __forceinline__ void vec_dot_q4_K_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
     
         typedef mma_int_A_I16K8 mma_A;
         typedef mma_int_B_J8K8  mma_B;
    @@ -1143,7 +1290,7 @@ static __device__ __forceinline__ void vec_dot_q4_K_q8_1_mma(
                 const int i = i0 + mma_A::get_i(l);
                 const int k = k0 + mma_A::get_k(l);
     
    -            A[kvdr/4].x[l] = (x_ql[i*(WARP_SIZE + 1) + k] >> kvdr) & 0x0F0F0F0F;
    +            A[kvdr/4].x[l] = (x_qs[i*(WARP_SIZE + 1) + k] >> kvdr) & 0x0F0F0F0F;
             }
     
     #pragma unroll
    @@ -1204,12 +1351,15 @@ static __device__ __forceinline__ void vec_dot_q4_K_q8_1_mma(
                 sum[(j0/mma_B::J)*mma_C::ne + l] += __low2float(dmA[l/2])*tmpd[l] - __high2float(dmA[l/2])*tmpm[l];
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template  static __device__ __forceinline__ void load_tiles_q5_K(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh);
     
         const int kbx  = 0;           // threadIdx.x / QI5_K
         const int kqsx = threadIdx.x; // threadIdx.x % QI5_K
    @@ -1236,8 +1386,8 @@ template  static __device__ __forceinlin
             const int kq0 = ky - ky % (QI5_K/2) + threadIdx.x % (QI5_K/4) + 0;
             const int kq1 = ky - ky % (QI5_K/2) + threadIdx.x % (QI5_K/4) + (QI5_K/4);
     
    -        x_ql[i * (2*WARP_SIZE + 1) + kq0] = ql0 | qh0;
    -        x_ql[i * (2*WARP_SIZE + 1) + kq1] = ql1 | qh1;
    +        x_qs[i * (2*WARP_SIZE + 1) + kq0] = ql0 | qh0;
    +        x_qs[i * (2*WARP_SIZE + 1) + kq1] = ql1 | qh1;
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI5_K;  // == 1 if QK_K == 256
    @@ -1280,11 +1430,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q5_K_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
     
    -    GGML_UNUSED(x_qh);
    -
         const int   * y_qs  = (const int   *) y + 4;
         const half2 * y_ds  = (const half2 *) y;
     
    @@ -1299,7 +1447,7 @@ static __device__ __forceinline__ void vec_dot_q5_K_q8_1_dp4a(
                 const uint8_t * sc = ((const uint8_t *) &x_sc[i * (WARP_SIZE/8) + i/8 + k0/16]) + 2 * ((k0 % 16) / 8);
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q5_K_q8_1_impl_mmq(
    -                &x_ql[i*(QR5_K*WARP_SIZE + 1) + QR5_K*k0], &y_qs[j*MMQ_TILE_Y_K + (QR5_K*k0) % WARP_SIZE], sc, sc+8,
    +                &x_qs[i*(QR5_K*WARP_SIZE + 1) + QR5_K*k0], &y_qs[j*MMQ_TILE_Y_K + (QR5_K*k0) % WARP_SIZE], sc, sc+8,
                     x_dm[i*(WARP_SIZE/QI5_K) + i/QI5_K], &y_ds[j*MMQ_TILE_Y_K + ((QR5_K*k0) % WARP_SIZE)/QI8_1]);
             }
         }
    @@ -1307,10 +1455,9 @@ static __device__ __forceinline__ void vec_dot_q5_K_q8_1_dp4a(
     
     template 
     static __device__ __forceinline__ void vec_dot_q5_K_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
     
         typedef mma_int_A_I16K8 mma_A;
         typedef mma_int_B_J8K8  mma_B;
    @@ -1333,7 +1480,7 @@ static __device__ __forceinline__ void vec_dot_q5_K_q8_1_mma(
                 const int i = i0 + mma_A::get_i(l);
                 const int k = QR5_K*k0 + QR5_K*kvdr + mma_A::get_k(l);
     
    -            A[kvdr/4].x[l] = x_ql[i*(QR5_K*WARP_SIZE + 1) + k];
    +            A[kvdr/4].x[l] = x_qs[i*(QR5_K*WARP_SIZE + 1) + k];
             }
     
     #pragma unroll
    @@ -1394,12 +1541,15 @@ static __device__ __forceinline__ void vec_dot_q5_K_q8_1_mma(
                 sum[(j0/mma_B::J)*mma_C::ne + l] += __low2float(dmA[l/2])*tmpd[l] - __high2float(dmA[l/2])*tmpm[l];
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template  static __device__ __forceinline__ void load_tiles_q6_K(
    -    const char * __restrict__ x, int * __restrict__ x_ql, half2 * __restrict__ x_dm, int * __restrict__ x_qh,
    +    const char * __restrict__ x, int * __restrict__ x_qs, half2 * __restrict__ x_dm,
         int * __restrict__ x_sc, const int & kbx0, const int & i_max, const int & stride) {
    -    GGML_UNUSED(x_qh);
     
         const int kbx  = 0;           // threadIdx.x / QI6_K
         const int kqsx = threadIdx.x; // threadIdx.x % QI6_K
    @@ -1426,8 +1576,8 @@ template  static __device__ __forceinlin
             const int kq0 = ky - ky % QI6_K + threadIdx.x % (QI6_K/2) + 0;
             const int kq1 = ky - ky % QI6_K + threadIdx.x % (QI6_K/2) + (QI6_K/2);
     
    -        x_ql[i * (2*WARP_SIZE + 1) + kq0] = __vsubss4(ql0 | qh0, 0x20202020);
    -        x_ql[i * (2*WARP_SIZE + 1) + kq1] = __vsubss4(ql1 | qh1, 0x20202020);
    +        x_qs[i * (2*WARP_SIZE + 1) + kq0] = __vsubss4(ql0 | qh0, 0x20202020);
    +        x_qs[i * (2*WARP_SIZE + 1) + kq1] = __vsubss4(ql1 | qh1, 0x20202020);
         }
     
         const int blocks_per_tile_x_row = WARP_SIZE / QI6_K;  // == 1 if QK_K == 256
    @@ -1463,11 +1613,9 @@ template  static __device__ __forceinlin
     
     template 
     static __device__ __forceinline__ void vec_dot_q6_K_q8_1_dp4a(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
     
    -    GGML_UNUSED(x_qh);
    -
         const float * x_dmf = (const float *) x_dm;
         const int   * y_qs  = (const int   *) y + 4;
         const float * y_df  = (const float *) y;
    @@ -1483,7 +1631,7 @@ static __device__ __forceinline__ void vec_dot_q6_K_q8_1_dp4a(
                 const int8_t * sc = ((const int8_t *) &x_sc[i * (WARP_SIZE/8) + i/8 + k0/8]);
     
                 sum[j0/nwarps*mmq_y/WARP_SIZE + i0/WARP_SIZE] += vec_dot_q6_K_q8_1_impl_mmq(
    -                &x_ql[i*(QR6_K*WARP_SIZE + 1) + QR6_K*k0], &y_qs[j*MMQ_TILE_Y_K + (QR6_K*k0) % WARP_SIZE], sc,
    +                &x_qs[i*(QR6_K*WARP_SIZE + 1) + QR6_K*k0], &y_qs[j*MMQ_TILE_Y_K + (QR6_K*k0) % WARP_SIZE], sc,
                     x_dmf[i*(WARP_SIZE/QI6_K) + i/QI6_K], &y_df[j*MMQ_TILE_Y_K + ((QR6_K*k0) % WARP_SIZE)/QI8_1]);
             }
         }
    @@ -1491,10 +1639,9 @@ static __device__ __forceinline__ void vec_dot_q6_K_q8_1_dp4a(
     
     template 
     static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mma(
    -    const int * __restrict__ x_ql, const half2 * __restrict__ x_dm, const int * __restrict__ x_qh, const int * __restrict__ x_sc,
    +    const int * __restrict__ x_qs, const half2 * __restrict__ x_dm, const int * __restrict__ x_sc,
         const int * __restrict__ y, float * __restrict__ sum, const int & k0) {
    -
    -    GGML_UNUSED(x_qh); GGML_UNUSED(x_sc);
    +#ifdef INT8_MMA_AVAILABLE
     
         typedef mma_int_A_I16K4 mma_A;
         typedef mma_int_B_J8K4  mma_B;
    @@ -1505,7 +1652,9 @@ static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mma(
         const float * y_df = (const float *) y;
     
         const int i0 = threadIdx.y*mma_A::I;
    +#ifdef INT8_MMA_AVAILABLE
         static_assert(nwarps*mma_A::I == mmq_y, "nwarps*mma_A::I != mmq_y");
    +#endif // INT8_MMA_AVAILABLE
     
         mma_A   A[4];
         int   scA[mma_C::ne/2][4];
    @@ -1517,8 +1666,8 @@ static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mma(
                 const int i = i0 + mma_A::get_i(l);
                 const int k = QR6_K*k0 + QR6_K*kvdr + mma_A::get_k(l);
     
    -            A[kvdr/2 + 0].x[l] = x_ql[i*(QR6_K*WARP_SIZE + 1) + k + 0];
    -            A[kvdr/2 + 1].x[l] = x_ql[i*(QR6_K*WARP_SIZE + 1) + k + mma_A::K];
    +            A[kvdr/2 + 0].x[l] = x_qs[i*(QR6_K*WARP_SIZE + 1) + k + 0];
    +            A[kvdr/2 + 1].x[l] = x_qs[i*(QR6_K*WARP_SIZE + 1) + k + mma_A::K];
             }
     
     #pragma unroll
    @@ -1578,6 +1727,10 @@ static __device__ __forceinline__ void vec_dot_q6_K_q8_1_mma(
                 sum[(j0/mma_B::J)*mma_C::ne + l] += tmp[l]*dA[l/2];
             }
         }
    +#else
    +    GGML_UNUSED(x_qs); GGML_UNUSED(x_dm); GGML_UNUSED(x_sc); GGML_UNUSED(y); GGML_UNUSED(sum); GGML_UNUSED(k0);
    +    NO_DEVICE_CODE;
    +#endif // INT8_MMA_AVAILABLE
     }
     
     template
    @@ -1608,7 +1761,9 @@ static __device__ __forceinline__ void mmq_write_back_mma(const float * __restri
         typedef mma_int_C_I16J8 mma_C;
     
         const int i0 = threadIdx.y*mma_C::I;
    +#ifdef INT8_MMA_AVAILABLE
         static_assert(nwarps*mma_C::I == mmq_y, "nwarps*mma_C::I != mmq_y");
    +#endif // INT8_MMA_AVAILABLE
     
     #pragma unroll
         for (int j0 = 0; j0 < mmq_x; j0 += mma_C::J) {
    @@ -1638,125 +1793,85 @@ struct mmq_type_traits;
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q4_0_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q4_0;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q4_0_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q4_0_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q4_0_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q4_0;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q4_0_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q4_0_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q4_1_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q4_1;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q4_1_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q4_1_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q4_1_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q4_1;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q4_1_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q4_1_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q5_0_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q5_0;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q5_0_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q5_0_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q5_0_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q5_0;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q5_0_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q5_0_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q5_1_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q5_1;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q5_1_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q5_1_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q5_1_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q5_1;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q5_1_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q5_1_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q8_0_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q8_0;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q8_0_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q8_0_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q8_0_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q8_0;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q8_0_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q8_0_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q2_K_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q2_K;
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q2_K_q8_1_mul_mat;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    +    static constexpr int              vdr          = VDR_Q2_K_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q2_K;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q2_K_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q2_K_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q3_K_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q3_K;
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q3_K_q8_1_mul_mat;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    +    static constexpr int              vdr          = VDR_Q3_K_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q3_K;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q3_K_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q3_K_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q4_K_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q4_K;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q4_K_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q4_K_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q4_K_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q4_K;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q4_K_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q4_K_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q5_K_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q5_K;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q5_K_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q5_K_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q5_K_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q5_K;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q5_K_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q5_K_q8_1_dp4a;
     };
     
     template 
     struct mmq_type_traits {
    -    static constexpr int              vdr        = VDR_Q6_K_Q8_1_MMQ;
    -    static constexpr load_tiles_mmq_t load_tiles = load_tiles_q6_K;
    -#ifdef INT8_MMA_AVAILABLE
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q6_K_q8_1_mma;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    -#else
    -    static constexpr vec_dot_mmq_t    vec_dot    = vec_dot_q6_K_q8_1_dp4a;
    -    static constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    -#endif // INT8_MMA_AVAILABLE
    +    static constexpr int              vdr          = VDR_Q6_K_Q8_1_MMQ;
    +    static constexpr load_tiles_mmq_t load_tiles   = load_tiles_q6_K;
    +    static constexpr vec_dot_mmq_t    vec_dot_mma  = vec_dot_q6_K_q8_1_mma;
    +    static constexpr vec_dot_mmq_t    vec_dot_dp4a = vec_dot_q6_K_q8_1_dp4a;
     };
     
    -static int mmq_need_sum(const ggml_type type_x) {
    +static bool mmq_need_sum(const ggml_type type_x) {
         switch (type_x) {
             case GGML_TYPE_Q4_0:
             case GGML_TYPE_Q4_1:
    @@ -1790,7 +1905,7 @@ template 
     #if __CUDA_ARCH__ >= CC_VOLTA
         __launch_bounds__(WARP_SIZE*nwarps, 1)
     #else
    -    __launch_bounds__(WARP_SIZE*nwarps, type == GGML_TYPE_Q2_K ? 1 : 2)
    +    __launch_bounds__(WARP_SIZE*nwarps, 2)
     #endif // __CUDA_ARCH__ >= CC_VOLTA
     #endif // defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__)
     static __global__ void mul_mat_q(
    @@ -1809,16 +1924,21 @@ static __global__ void mul_mat_q(
         constexpr int              mmq_y      = get_mmq_y_device(mmq_x);
         constexpr int              vdr        = mmq_type_traits::vdr;
         constexpr load_tiles_mmq_t load_tiles = mmq_type_traits::load_tiles;
    -    constexpr vec_dot_mmq_t    vec_dot    = mmq_type_traits::vec_dot;
    -    constexpr mmq_write_back_t write_back = mmq_type_traits::write_back;
    +
    +#ifdef INT8_MMA_AVAILABLE
    +    constexpr vec_dot_mmq_t    vec_dot    = mmq_type_traits::vec_dot_mma;
    +    constexpr mmq_write_back_t write_back = mmq_write_back_mma;
    +#else
    +    constexpr vec_dot_mmq_t    vec_dot    = mmq_type_traits::vec_dot_dp4a;
    +    constexpr mmq_write_back_t write_back = mmq_write_back_dp4a;
    +#endif // INT8_MMA_AVAILABLE
     
         constexpr tile_x_sizes txs = get_tile_x_sizes_device(type);
     
         extern __shared__ char data_mul_mat_q[];
    -    int   * tile_x_ql = (int   *)  data_mul_mat_q;
    -    half2 * tile_x_dm = (half2 *) (tile_x_ql + txs.ql);
    -    int   * tile_x_qh = (int   *) (tile_x_dm + txs.dm);
    -    int   * tile_x_sc = (int   *) (tile_x_qh + txs.qh);
    +    int   * tile_x_qs = (int   *)  data_mul_mat_q;
    +    half2 * tile_x_dm = (half2 *) (tile_x_qs + txs.qs);
    +    int   * tile_x_sc = (int   *) (tile_x_dm + txs.dm);
         int   * tile_y    = (int   *) (tile_x_sc + txs.sc); // [mmq_x * (WARP_SIZE + WARP_SIZE/QI8_1)]
     
         const int blocks_per_row_x = ne00 / qk;
    @@ -1834,7 +1954,7 @@ static __global__ void mul_mat_q(
     
         for (int kb0 = 0; kb0 < blocks_per_row_x; kb0 += blocks_per_warp) {
     
    -        load_tiles(x, tile_x_ql, tile_x_dm, tile_x_qh, tile_x_sc, stride01*blockIdx.x*mmq_y + kb0, tile_x_max_i, stride01);
    +        load_tiles(x, tile_x_qs, tile_x_dm, tile_x_sc, stride01*blockIdx.x*mmq_y + kb0, tile_x_max_i, stride01);
     
     #pragma unroll
             for (int kr = 0; kr < qr; ++kr) {
    @@ -1850,7 +1970,7 @@ static __global__ void mul_mat_q(
     
     // #pragma unroll // unrolling this loop causes too much register pressure
                 for (int k0 = kr*WARP_SIZE/qr; k0 < (kr+1)*WARP_SIZE/qr; k0 += vdr) {
    -                vec_dot(tile_x_ql, tile_x_dm, tile_x_qh, tile_x_sc, tile_y, sum, k0);
    +                vec_dot(tile_x_qs, tile_x_dm, tile_x_sc, tile_y, sum, k0);
                 }
     
                 __syncthreads();
    @@ -1867,6 +1987,19 @@ struct mmq_args {
         int64_t ne0;
     };
     
    +constexpr int mmq_get_nwarps(int mmq_x) {
    +    return mmq_x >= 32 ? 8 : 4;
    +}
    +
    +static int mmq_get_shmem(const ggml_type type, const int mmq_x, const int mmq_y) {
    +    const tile_x_sizes txs = get_tile_x_sizes_host(type, mmq_y);
    +    const int nwarps = mmq_get_nwarps(mmq_x);
    +
    +    const int shmem_x = txs.qs*sizeof(int) + txs.dm*sizeof(half2) + txs.sc*sizeof(int);
    +    const int shmem_y = mmq_x*WARP_SIZE*sizeof(int) + mmq_x*(WARP_SIZE/QI8_1)*sizeof(half2);
    +    return shmem_x + GGML_PAD(shmem_y, nwarps*WARP_SIZE*sizeof(int));
    +}
    +
     template 
     static void launch_mul_mat_q(const mmq_args & args, cudaStream_t stream) {
         const int id = ggml_cuda_get_device();
    @@ -1878,10 +2011,7 @@ static void launch_mul_mat_q(const mmq_args & args, cudaStream_t stream) {
         const dim3 block_nums(block_num_x, block_num_y, 1);
         const dim3 block_dims(WARP_SIZE, nwarps, 1);
     
    -    const tile_x_sizes txs = get_tile_x_sizes_host(type, mmq_y);
    -    const int shmem_x = txs.ql*sizeof(int) + txs.dm*sizeof(half2) + txs.qh*sizeof(int) + txs.sc*sizeof(int);
    -    const int shmem_y = mmq_x*WARP_SIZE*sizeof(int) + mmq_x*(WARP_SIZE/QI8_1)*sizeof(half2);
    -    const int shmem = shmem_x + GGML_PAD(shmem_y, nwarps*WARP_SIZE*sizeof(int));
    +    const int shmem = mmq_get_shmem(type, mmq_x, mmq_y);
     
     #if !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__))
         static bool shmem_limit_raised[GGML_CUDA_MAX_DEVICES] = {false};
    @@ -1905,9 +2035,10 @@ static void launch_mul_mat_q(const mmq_args & args, cudaStream_t stream) {
     
     template 
     void mul_mat_q_case(const mmq_args & args, cudaStream_t stream) {
    -    const int id = ggml_cuda_get_device();
    -    const int nsm = ggml_cuda_info().devices[id].nsm;
    -    const int cc  = ggml_cuda_info().devices[id].cc;
    +    const int id    = ggml_cuda_get_device();
    +    const int nsm   = ggml_cuda_info().devices[id].nsm;
    +    const int cc    = ggml_cuda_info().devices[id].cc;
    +    const int smpbo = ggml_cuda_info().devices[id].smpbo;
     
         const int mmq_x_max = get_mmq_x_max_host(cc);
         const int mmq_y = get_mmq_y_host(cc, mmq_x_max);
    @@ -1920,7 +2051,7 @@ void mul_mat_q_case(const mmq_args & args, cudaStream_t stream) {
             const int block_num_x = (args.ne11 + mmq_x - 1) / mmq_x;
             const int nwaves = (block_num_x*block_num_y + nsm - 1) / nsm;
     
    -        if (nwaves < nwaves_best) {
    +        if (nwaves < nwaves_best && mmq_get_shmem(type, mmq_x, mmq_y) <= smpbo) {
                 mmq_x_best  = mmq_x;
                 nwaves_best = nwaves;
             }
    @@ -1928,54 +2059,55 @@ void mul_mat_q_case(const mmq_args & args, cudaStream_t stream) {
     
         switch (mmq_x_best) {
             case   8:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  16:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  24:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  32:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  40:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  48:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  56:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  64:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  72:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  80:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  88:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case  96:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case 104:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case 112:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case 120:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             case 128:
    -            launch_mul_mat_q(args, stream);
    +            launch_mul_mat_q(args, stream);
                 break;
             default:
    +            fprintf(stderr, "mmq_x_best=%d\n", mmq_x_best);
                 GGML_ASSERT(false);
                 break;
         }
    diff --git a/ggml-cuda/softmax.cu b/ggml-cuda/softmax.cu
    index ce64f2f2c..c24abae1f 100644
    --- a/ggml-cuda/softmax.cu
    +++ b/ggml-cuda/softmax.cu
    @@ -130,6 +130,7 @@ static void soft_max_f32_cuda(const float * x, const T * mask, float * dst, cons
         const float m0 = powf(2.0f, -(max_bias       ) / n_head_log2);
         const float m1 = powf(2.0f, -(max_bias / 2.0f) / n_head_log2);
     
    +    // FIXME: this limit could be raised by ~2-4x on Ampere or newer
         if (shmem < ggml_cuda_info().devices[ggml_cuda_get_device()].smpb) {
             switch (ncols_x) {
                 case 32:
    diff --git a/ggml-cuda/vecdotq.cuh b/ggml-cuda/vecdotq.cuh
    index b9573a7c7..3b12d6566 100644
    --- a/ggml-cuda/vecdotq.cuh
    +++ b/ggml-cuda/vecdotq.cuh
    @@ -265,36 +265,31 @@ static __device__ __forceinline__ float vec_dot_q2_K_q8_1_impl_mmvq(
     
     // contiguous u/y values
     static __device__ __forceinline__ float vec_dot_q2_K_q8_1_impl_mmq(
    -    const int * __restrict__ v, const int * __restrict__ u, const uint8_t * __restrict__ scales,
    -    const half2 & dm2, const float & d8) {
    +    const int * __restrict__ v, const int * __restrict__ u, const half2 * dm2, const float & d8) {
     
     #if __CUDA_ARCH__ >= MIN_CC_DP4A // lowest compute capability for integer intrinsics
    -    int sumi_d = 0;
    -    int sumi_m = 0;
    +    float sumf_d = 0.0f;
    +    float sumf_m = 0.0f;
     
     #pragma unroll
         for (int i0 = 0; i0 < QI8_1; i0 += QI8_1/2) {
    -        int sumi_d_sc = 0;
    -
    -        const int sc = scales[i0 / (QI8_1/2)];
    -
    -        // fill int with 4x m
    -        int m = sc >> 4;
    -        m |= m <<  8;
    -        m |= m << 16;
    +        const float2 dm2f = __half22float2(dm2[i0/(QI8_1/2)]);
    +        int sumi_d = 0;
    +        int sumi_m = 0;
     
    +        const int vi0 = v[i0/(QI8_1/2)];
     #pragma unroll
             for (int i = i0; i < i0 + QI8_1/2; ++i) {
    -            sumi_d_sc = __dp4a(v[i], u[i], sumi_d_sc); // SIMD dot product
    -            sumi_m    = __dp4a(m,    u[i], sumi_m); // multiply sum of q8_1 values with m
    +            const int vi = (vi0 >> (2*(i % (QI8_1/2)))) & 0x03030303;
    +            sumi_d = __dp4a(vi,         u[i], sumi_d); // SIMD dot product
    +            sumi_m = __dp4a(0x01010101, u[i], sumi_m);
             }
     
    -        sumi_d += sumi_d_sc * (sc & 0xF);
    +        sumf_d += dm2f.x * sumi_d;
    +        sumf_m += dm2f.y * sumi_m;
         }
     
    -    const float2 dm2f = __half22float2(dm2);
    -
    -    return d8 * (dm2f.x*sumi_d - dm2f.y*sumi_m);
    +    return d8*(sumf_d - sumf_m);
     #else
         NO_DEVICE_CODE;
     #endif // __CUDA_ARCH__ >= MIN_CC_DP4A
    @@ -352,8 +347,10 @@ static __device__ __forceinline__ float vec_dot_q3_K_q8_1_impl_mmq(
         for (int i0 = 0; i0 < QR3_K*VDR_Q3_K_Q8_1_MMQ; i0 += QI8_1/2) {
             int sumi_sc = 0;
     
    +#pragma unroll
             for (int i = i0; i < i0 + QI8_1/2; ++i) {
    -            sumi_sc = __dp4a(v[i], u[i], sumi_sc); // SIMD dot product
    +            const int vi = __vsubss4((v[i/2] >> (4*(i%2))) & 0x0F0F0F0F, 0x04040404);
    +            sumi_sc = __dp4a(vi, u[i], sumi_sc); // SIMD dot product
             }
     
             sumi += sumi_sc * scales[i0 / (QI8_1/2)];
    
    From f8ec8877b75774fc6c47559d529dac423877bcad Mon Sep 17 00:00:00 2001
    From: olexiyb 
    Date: Fri, 14 Jun 2024 20:28:34 +0300
    Subject: [PATCH 35/37] ci : fix macos x86 build (#7940)
    
    In order to use old `macos-latest` we should use `macos-12`
    
    Potentially will fix: https://github.com/ggerganov/llama.cpp/issues/6975
    ---
     .github/workflows/build.yml | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
    index 81ce770cc..a8fcae043 100644
    --- a/.github/workflows/build.yml
    +++ b/.github/workflows/build.yml
    @@ -84,7 +84,7 @@ jobs:
               name: llama-bin-macos-arm64.zip
     
       macOS-latest-cmake-x64:
    -    runs-on: macos-latest
    +    runs-on: macos-12
     
         steps:
           - name: Clone
    
    From 7b2f4a7d193ef2475259bbe7656fcccfab4b1217 Mon Sep 17 00:00:00 2001
    From: "Meng, Hengyu" 
    Date: Sat, 15 Jun 2024 14:05:10 +0800
    Subject: [PATCH 36/37] [SYCL] remove global variables (#7710)
    
    * separate DPCT helpers outside
    
    * replace global variables with context
    
    * remove useless extra
    
    * update mul_mat condition
    
    * remove duplicate buft initialization
    
    * remove duplicate extra and global work group size
    
    * remove useless backend check
    
    * remove duplicated extras
    
    * use macro for group_size and remove cuda-related
    ---
     CMakeLists.txt            |    3 +-
     ggml-sycl.cpp             | 5532 +++++--------------------------------
     ggml-sycl.h               |   11 +-
     ggml-sycl/backend.hpp     |   18 +
     ggml-sycl/common.cpp      |   53 +
     ggml-sycl/common.hpp      |  298 ++
     ggml-sycl/dpct/helper.hpp | 2980 ++++++++++++++++++++
     ggml-sycl/presets.hpp     |   69 +
     llama.cpp                 |   13 +-
     9 files changed, 4142 insertions(+), 4835 deletions(-)
     create mode 100644 ggml-sycl/backend.hpp
     create mode 100644 ggml-sycl/common.cpp
     create mode 100644 ggml-sycl/common.hpp
     create mode 100644 ggml-sycl/dpct/helper.hpp
     create mode 100644 ggml-sycl/presets.hpp
    
    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index 08481334f..d86107187 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -684,7 +684,8 @@ if (LLAMA_SYCL)
         endif()
     
         set(GGML_HEADERS_SYCL ggml-sycl.h)
    -    set(GGML_SOURCES_SYCL ggml-sycl.cpp)
    +    file(GLOB GGML_SOURCES_SYCL "ggml-sycl/*.cpp")
    +    list(APPEND GGML_SOURCES_SYCL "ggml-sycl.cpp")
     
         if (WIN32)
             set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} -fsycl sycl7 OpenCL mkl_sycl_blas_dll.lib mkl_intel_ilp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib)
    diff --git a/ggml-sycl.cpp b/ggml-sycl.cpp
    index 6f41ed272..6bd42b960 100644
    --- a/ggml-sycl.cpp
    +++ b/ggml-sycl.cpp
    @@ -36,6 +36,8 @@
     #include "ggml.h"
     #include "ggml-backend-impl.h"
     
    +#include "ggml-sycl/backend.hpp"
    +
     /*
     Following definition copied from DPCT head files, which are used by ggml-sycl.cpp
     */
    @@ -82,3020 +84,7 @@ Following definition copied from DPCT head files, which are used by ggml-sycl.cp
     #define __dpct_noinline__ __attribute__((noinline))
     #endif
     
    -
    -std::string get_device_type_name(const sycl::device &Device) {
    -    auto DeviceType = Device.get_info();
    -    switch (DeviceType) {
    -    case sycl::info::device_type::cpu:
    -        return "cpu";
    -    case sycl::info::device_type::gpu:
    -        return "gpu";
    -    case sycl::info::device_type::host:
    -        return "host";
    -    case sycl::info::device_type::accelerator:
    -        return "acc";
    -    default:
    -        return "unknown";
    -    }
    -}
    -
    -std::string get_device_backend_and_type(const sycl::device &device) {
    -    std::stringstream device_type;
    -    sycl::backend backend = device.get_backend();
    -    device_type <<  backend << ":" << get_device_type_name(device);
    -    return device_type.str();
    -}
    -
    -namespace dpct
    -{
    -    typedef sycl::queue *queue_ptr;
    -    typedef sycl::event *event_ptr;
    -    typedef char *device_ptr;
    -    typedef uint8_t byte_t;
    -    typedef sycl::buffer buffer_t;
    -
    -    /// SYCL default exception handler
    -    inline auto exception_handler = [](sycl::exception_list exceptions)
    -    {
    -        for (std::exception_ptr const &e : exceptions)
    -        {
    -            try
    -            {
    -                std::rethrow_exception(e);
    -            }
    -            catch (sycl::exception const &e)
    -            {
    -                std::cerr << "Caught asynchronous SYCL exception:" << std::endl
    -                          << e.what() << std::endl
    -                          << "Exception caught at file:" << __FILE__
    -                          << ", line:" << __LINE__ << std::endl;
    -            }
    -        }
    -    };
    -
    -    enum error_code
    -    {
    -        success = 0,
    -        default_error = 999
    -    };
    -
    -    enum memcpy_direction
    -    {
    -        host_to_host,
    -        host_to_device,
    -        device_to_host,
    -        device_to_device,
    -        automatic
    -    };
    -
    -    enum memory_region
    -    {
    -        global = 0, // device global memory
    -        constant,   // device constant memory
    -        local,      // device local memory
    -        shared,     // memory which can be accessed by host and device
    -    };
    -
    -    enum class library_data_t : unsigned char
    -    {
    -        real_float = 0,
    -        complex_float,
    -        real_double,
    -        complex_double,
    -        real_half,
    -        complex_half,
    -        real_bfloat16,
    -        complex_bfloat16,
    -        real_int4,
    -        complex_int4,
    -        real_uint4,
    -        complex_uint4,
    -        real_int8,
    -        complex_int8,
    -        real_uint8,
    -        complex_uint8,
    -        real_int16,
    -        complex_int16,
    -        real_uint16,
    -        complex_uint16,
    -        real_int32,
    -        complex_int32,
    -        real_uint32,
    -        complex_uint32,
    -        real_int64,
    -        complex_int64,
    -        real_uint64,
    -        complex_uint64,
    -        real_int8_4,
    -        real_int8_32,
    -        real_uint8_4,
    -        library_data_t_size
    -    };
    -
    -    template 
    -    struct DataType
    -    {
    -        using T2 = T;
    -    };
    -    template 
    -    struct DataType>
    -    {
    -        using T2 = std::complex;
    -    };
    -
    -    static void destroy_event(event_ptr event)
    -    {
    -        delete event;
    -    }
    -
    -    static inline unsigned int get_tid()
    -    {
    -#if defined(__linux__)
    -        return syscall(SYS_gettid);
    -#elif defined(_WIN64)
    -        return GetCurrentThreadId();
    -#else
    -#error "Only support Windows and Linux."
    -#endif
    -    }
    -
    -    namespace detail
    -    {
    -        static void get_version(const sycl::device &dev, int &major, int &minor)
    -        {
    -            // Version string has the following format:
    -            // a. OpenCL
    -            // b. 
    -            // c.  e.g gfx1030
    -            std::string ver;
    -            ver = dev.get_info();
    -            std::string::size_type i = 0;
    -            while (i < ver.size()) {
    -              if (isdigit(ver[i]))
    -                break;
    -              i++;
    -            }
    -            major = std::stoi(&(ver[i]));
    -            while (i < ver.size()) {
    -              if (ver[i] == '.')
    -                break;
    -              i++;
    -            }
    -            if (i < ver.size()) {
    -              // a. and b.
    -              i++;
    -              minor = std::stoi(&(ver[i]));
    -            } else {
    -              // c.
    -              minor = 0;
    -            }
    -        }
    -
    -        template 
    -        class generic_error_type
    -        {
    -        public:
    -            generic_error_type() = default;
    -            generic_error_type(T value) : value{value} {}
    -            operator T() const { return value; }
    -
    -        private:
    -            T value;
    -        };
    -
    -    } // namespace detail
    -
    -    /// Pitched 2D/3D memory data.
    -    class pitched_data
    -    {
    -    public:
    -        pitched_data() : pitched_data(nullptr, 0, 0, 0) {}
    -        pitched_data(void *data, size_t pitch, size_t x, size_t y)
    -            : _data(data), _pitch(pitch), _x(x), _y(y) {}
    -
    -        void *get_data_ptr() { return _data; }
    -        void set_data_ptr(void *data) { _data = data; }
    -
    -        size_t get_pitch() { return _pitch; }
    -        void set_pitch(size_t pitch) { _pitch = pitch; }
    -
    -        size_t get_x() { return _x; }
    -        void set_x(size_t x) { _x = x; };
    -
    -        size_t get_y() { return _y; }
    -        void set_y(size_t y) { _y = y; }
    -
    -    private:
    -        void *_data;
    -        size_t _pitch, _x, _y;
    -    };
    -
    -    class device_info
    -    {
    -    public:
    -        // get interface
    -        const char *get_name() const { return _name; }
    -        char *get_name() { return _name; }
    -        template ,
    -                  std::enable_if_t> ||
    -                                       std::is_same_v,
    -                                   int> = 0>
    -        auto get_max_work_item_sizes() const
    -        {
    -            if constexpr (std::is_same_v>)
    -                return sycl::range<3>(_max_work_item_sizes_i[0],
    -                                      _max_work_item_sizes_i[1],
    -                                      _max_work_item_sizes_i[2]);
    -            else
    -            {
    -                return _max_work_item_sizes_i;
    -            }
    -        }
    -        template ,
    -                  std::enable_if_t> ||
    -                                       std::is_same_v,
    -                                   int> = 0>
    -        auto get_max_work_item_sizes()
    -        {
    -            if constexpr (std::is_same_v>)
    -                return sycl::range<3>(_max_work_item_sizes_i[0],
    -                                      _max_work_item_sizes_i[1],
    -                                      _max_work_item_sizes_i[2]);
    -            else
    -            {
    -                return _max_work_item_sizes_i;
    -            }
    -        }
    -        bool get_host_unified_memory() const { return _host_unified_memory; }
    -        int get_major_version() const { return _major; }
    -        int get_minor_version() const { return _minor; }
    -        int get_integrated() const { return _integrated; }
    -        int get_max_clock_frequency() const { return _frequency; }
    -        int get_max_compute_units() const { return _max_compute_units; }
    -        int get_max_work_group_size() const { return _max_work_group_size; }
    -        int get_max_sub_group_size() const { return _max_sub_group_size; }
    -        int get_max_work_items_per_compute_unit() const
    -        {
    -            return _max_work_items_per_compute_unit;
    -        }
    -        int get_max_register_size_per_work_group() const
    -        {
    -            return _max_register_size_per_work_group;
    -        }
    -        template  ||
    -                                       std::is_same_v,
    -                                   int> = 0>
    -        auto get_max_nd_range_size() const
    -        {
    -            if constexpr (std::is_same_v)
    -                return _max_nd_range_size;
    -            else
    -                return _max_nd_range_size_i;
    -        }
    -        template  ||
    -                                       std::is_same_v,
    -                                   int> = 0>
    -        auto get_max_nd_range_size()
    -        {
    -            if constexpr (std::is_same_v)
    -                return _max_nd_range_size;
    -            else
    -                return _max_nd_range_size_i;
    -        }
    -        size_t get_global_mem_size() const { return _global_mem_size; }
    -        size_t get_local_mem_size() const { return _local_mem_size; }
    -        size_t get_max_mem_alloc_size() const { return _max_mem_alloc_size; }
    -        /// Returns the maximum clock rate of device's global memory in kHz. If
    -        /// compiler does not support this API then returns default value 3200000 kHz.
    -        unsigned int get_memory_clock_rate() const { return _memory_clock_rate; }
    -        /// Returns the maximum bus width between device and memory in bits. If
    -        /// compiler does not support this API then returns default value 64 bits.
    -        unsigned int get_memory_bus_width() const { return _memory_bus_width; }
    -        uint32_t get_device_id() const { return _device_id; }
    -        std::array get_uuid() const { return _uuid; }
    -        /// Returns global memory cache size in bytes.
    -        unsigned int get_global_mem_cache_size() const
    -        {
    -            return _global_mem_cache_size;
    -        }
    -
    -        // set interface
    -        void set_name(const char *name)
    -        {
    -            size_t length = strlen(name);
    -            if (length < 256)
    -            {
    -                std::memcpy(_name, name, length + 1);
    -            }
    -            else
    -            {
    -                std::memcpy(_name, name, 255);
    -                _name[255] = '\0';
    -            }
    -        }
    -        void set_max_work_item_sizes(const sycl::range<3> max_work_item_sizes)
    -        {
    -            for (int i = 0; i < 3; ++i)
    -                _max_work_item_sizes_i[i] = max_work_item_sizes[i];
    -        }
    -        [[deprecated]] void
    -        set_max_work_item_sizes(const sycl::id<3> max_work_item_sizes)
    -        {
    -            for (int i = 0; i < 3; ++i)
    -            {
    -                _max_work_item_sizes_i[i] = max_work_item_sizes[i];
    -            }
    -        }
    -        void set_host_unified_memory(bool host_unified_memory)
    -        {
    -            _host_unified_memory = host_unified_memory;
    -        }
    -        void set_major_version(int major) { _major = major; }
    -        void set_minor_version(int minor) { _minor = minor; }
    -        void set_integrated(int integrated) { _integrated = integrated; }
    -        void set_max_clock_frequency(int frequency) { _frequency = frequency; }
    -        void set_max_compute_units(int max_compute_units)
    -        {
    -            _max_compute_units = max_compute_units;
    -        }
    -        void set_global_mem_size(size_t global_mem_size)
    -        {
    -            _global_mem_size = global_mem_size;
    -        }
    -        void set_local_mem_size(size_t local_mem_size)
    -        {
    -            _local_mem_size = local_mem_size;
    -        }
    -        void set_max_mem_alloc_size(size_t max_mem_alloc_size)
    -        {
    -            _max_mem_alloc_size = max_mem_alloc_size;
    -        }
    -        void set_max_work_group_size(int max_work_group_size)
    -        {
    -            _max_work_group_size = max_work_group_size;
    -        }
    -        void set_max_sub_group_size(int max_sub_group_size)
    -        {
    -            _max_sub_group_size = max_sub_group_size;
    -        }
    -        void
    -        set_max_work_items_per_compute_unit(int max_work_items_per_compute_unit)
    -        {
    -            _max_work_items_per_compute_unit = max_work_items_per_compute_unit;
    -        }
    -        void set_max_nd_range_size(int max_nd_range_size[])
    -        {
    -            for (int i = 0; i < 3; i++)
    -            {
    -                _max_nd_range_size[i] = max_nd_range_size[i];
    -                _max_nd_range_size_i[i] = max_nd_range_size[i];
    -            }
    -        }
    -        void set_memory_clock_rate(unsigned int memory_clock_rate)
    -        {
    -            _memory_clock_rate = memory_clock_rate;
    -        }
    -        void set_memory_bus_width(unsigned int memory_bus_width)
    -        {
    -            _memory_bus_width = memory_bus_width;
    -        }
    -        void
    -        set_max_register_size_per_work_group(int max_register_size_per_work_group)
    -        {
    -            _max_register_size_per_work_group = max_register_size_per_work_group;
    -        }
    -        void set_device_id(uint32_t device_id)
    -        {
    -            _device_id = device_id;
    -        }
    -        void set_uuid(std::array uuid)
    -        {
    -            _uuid = std::move(uuid);
    -        }
    -        void set_global_mem_cache_size(unsigned int global_mem_cache_size)
    -        {
    -            _global_mem_cache_size = global_mem_cache_size;
    -        }
    -
    -    private:
    -        char _name[256];
    -        int _max_work_item_sizes_i[3];
    -        bool _host_unified_memory = false;
    -        int _major;
    -        int _minor;
    -        int _integrated = 0;
    -        int _frequency;
    -        // Set estimated value 3200000 kHz as default value.
    -        unsigned int _memory_clock_rate = 3200000;
    -        // Set estimated value 64 bits as default value.
    -        unsigned int _memory_bus_width = 64;
    -        unsigned int _global_mem_cache_size;
    -        int _max_compute_units;
    -        int _max_work_group_size;
    -        int _max_sub_group_size;
    -        int _max_work_items_per_compute_unit;
    -        int _max_register_size_per_work_group;
    -        size_t _global_mem_size;
    -        size_t _local_mem_size;
    -        size_t _max_mem_alloc_size;
    -        size_t _max_nd_range_size[3];
    -        int _max_nd_range_size_i[3];
    -        uint32_t _device_id;
    -        std::array _uuid;
    -    };
    -
    -    static int get_major_version(const sycl::device &dev)
    -    {
    -        int major, minor;
    -        detail::get_version(dev, major, minor);
    -        return major;
    -    }
    -
    -    static int get_minor_version(const sycl::device &dev)
    -    {
    -        int major, minor;
    -        detail::get_version(dev, major, minor);
    -        return minor;
    -    }
    -
    -    static void get_device_info(device_info &out, const sycl::device &dev)
    -    {
    -        device_info prop;
    -        prop.set_name(dev.get_info().c_str());
    -
    -        int major, minor;
    -        detail::get_version(dev, major, minor);
    -        prop.set_major_version(major);
    -        prop.set_minor_version(minor);
    -
    -        prop.set_max_work_item_sizes(
    -#if (__SYCL_COMPILER_VERSION && __SYCL_COMPILER_VERSION < 20220902)
    -            // oneAPI DPC++ compiler older than 2022/09/02, where max_work_item_sizes
    -            // is an enum class element
    -            dev.get_info());
    -#else
    -            // SYCL 2020-conformant code, max_work_item_sizes is a struct templated by
    -            // an int
    -            dev.get_info>());
    -#endif
    -        prop.set_host_unified_memory(dev.has(sycl::aspect::usm_host_allocations));
    -
    -        prop.set_max_clock_frequency(
    -            dev.get_info() * 1000);
    -
    -        prop.set_max_compute_units(
    -            dev.get_info());
    -        prop.set_max_work_group_size(
    -            dev.get_info());
    -        prop.set_global_mem_size(dev.get_info());
    -        prop.set_local_mem_size(dev.get_info());
    -        prop.set_max_mem_alloc_size(dev.get_info());
    -
    -#if (defined(SYCL_EXT_INTEL_DEVICE_INFO) && SYCL_EXT_INTEL_DEVICE_INFO >= 6)
    -        if (dev.has(sycl::aspect::ext_intel_memory_clock_rate))
    -        {
    -            unsigned int tmp =
    -                dev.get_info();
    -            if (tmp != 0)
    -                prop.set_memory_clock_rate(1000 * tmp);
    -        }
    -        if (dev.has(sycl::aspect::ext_intel_memory_bus_width))
    -        {
    -            prop.set_memory_bus_width(
    -                dev.get_info());
    -        }
    -        if (dev.has(sycl::aspect::ext_intel_device_id))
    -        {
    -            prop.set_device_id(
    -                dev.get_info());
    -        }
    -        if (dev.has(sycl::aspect::ext_intel_device_info_uuid))
    -        {
    -            prop.set_uuid(dev.get_info());
    -        }
    -#elif defined(_MSC_VER) && !defined(__clang__)
    -#pragma message("get_device_info: querying memory_clock_rate and \
    -        memory_bus_width are not supported by the compiler used. \
    -        Use 3200000 kHz as memory_clock_rate default value. \
    -        Use 64 bits as memory_bus_width default value.")
    -#else
    -#warning "get_device_info: querying memory_clock_rate and \
    -        memory_bus_width are not supported by the compiler used. \
    -        Use 3200000 kHz as memory_clock_rate default value. \
    -        Use 64 bits as memory_bus_width default value."
    -#endif
    -
    -        size_t max_sub_group_size = 1;
    -        std::vector sub_group_sizes =
    -            dev.get_info();
    -
    -        for (const auto &sub_group_size : sub_group_sizes)
    -        {
    -            if (max_sub_group_size < sub_group_size)
    -                max_sub_group_size = sub_group_size;
    -        }
    -
    -        prop.set_max_sub_group_size(max_sub_group_size);
    -
    -        prop.set_max_work_items_per_compute_unit(
    -            dev.get_info());
    -        int max_nd_range_size[] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
    -        prop.set_max_nd_range_size(max_nd_range_size);
    -
    -        // Estimates max register size per work group, feel free to update the value
    -        // according to device properties.
    -        prop.set_max_register_size_per_work_group(65536);
    -
    -        prop.set_global_mem_cache_size(
    -            dev.get_info());
    -        out = prop;
    -    }
    -
    -    /// dpct device extension
    -    class device_ext : public sycl::device
    -    {
    -        typedef std::mutex mutex_type;
    -
    -    public:
    -        device_ext() : sycl::device(), _ctx(*this) {}
    -        ~device_ext()
    -        {
    -            std::lock_guard lock(m_mutex);
    -            clear_queues();
    -        }
    -        device_ext(const sycl::device &base) : sycl::device(base), _ctx(*this)
    -        {
    -            std::lock_guard lock(m_mutex);
    -            init_queues();
    -        }
    -
    -        int is_native_atomic_supported() { return 0; }
    -        int get_major_version() const
    -        {
    -            return dpct::get_major_version(*this);
    -        }
    -
    -        int get_minor_version() const
    -        {
    -            return dpct::get_minor_version(*this);
    -        }
    -
    -        int get_max_compute_units() const
    -        {
    -            return get_device_info().get_max_compute_units();
    -        }
    -
    -        /// Return the maximum clock frequency of this device in KHz.
    -        int get_max_clock_frequency() const
    -        {
    -            return get_device_info().get_max_clock_frequency();
    -        }
    -
    -        int get_integrated() const { return get_device_info().get_integrated(); }
    -
    -        int get_max_sub_group_size() const
    -        {
    -            return get_device_info().get_max_sub_group_size();
    -        }
    -
    -        int get_max_register_size_per_work_group() const
    -        {
    -            return get_device_info().get_max_register_size_per_work_group();
    -        }
    -
    -        int get_max_work_group_size() const
    -        {
    -            return get_device_info().get_max_work_group_size();
    -        }
    -
    -        int get_mem_base_addr_align() const
    -        {
    -            return get_info();
    -        }
    -
    -        size_t get_global_mem_size() const
    -        {
    -            return get_device_info().get_global_mem_size();
    -        }
    -
    -        size_t get_max_mem_alloc_size() const
    -        {
    -            return get_device_info().get_max_mem_alloc_size();
    -        }
    -
    -        /// Get the number of bytes of free and total memory on the SYCL device.
    -        /// \param [out] free_memory The number of bytes of free memory on the SYCL device.
    -        /// \param [out] total_memory The number of bytes of total memory on the SYCL device.
    -        void get_memory_info(size_t &free_memory, size_t &total_memory)
    -        {
    -            total_memory = get_device_info().get_global_mem_size();
    -            const char *warning_info = "get_memory_info: [warning] ext_intel_free_memory is not "
    -                                 "supported (export/set ZES_ENABLE_SYSMAN=1 to support), "
    -                                 "use total memory as free memory";
    -#if (defined(__SYCL_COMPILER_VERSION) && __SYCL_COMPILER_VERSION >= 20221105)
    -            if (!has(sycl::aspect::ext_intel_free_memory))
    -            {
    -                std::cerr << warning_info << std::endl;
    -                free_memory = total_memory;
    -            }
    -            else
    -            {
    -                free_memory = get_info();
    -            }
    -#else
    -            std::cerr << warning_info << std::endl;
    -            free_memory = total_memory;
    -#if defined(_MSC_VER) && !defined(__clang__)
    -#pragma message("Querying the number of bytes of free memory is not supported")
    -#else
    -#warning "Querying the number of bytes of free memory is not supported"
    -#endif
    -#endif
    -        }
    -
    -        void get_device_info(device_info &out) const
    -        {
    -            dpct::get_device_info(out, *this);
    -        }
    -
    -        device_info get_device_info() const
    -        {
    -            device_info prop;
    -            dpct::get_device_info(prop, *this);
    -            return prop;
    -        }
    -
    -        void reset()
    -        {
    -            std::lock_guard lock(m_mutex);
    -            clear_queues();
    -            init_queues();
    -        }
    -
    -        sycl::queue &in_order_queue() { return *_q_in_order; }
    -
    -        sycl::queue &out_of_order_queue() { return *_q_out_of_order; }
    -
    -        sycl::queue &default_queue()
    -        {
    -            return in_order_queue();
    -        }
    -
    -        void queues_wait_and_throw()
    -        {
    -            std::unique_lock lock(m_mutex);
    -            std::vector> current_queues(
    -                _queues);
    -            lock.unlock();
    -            for (const auto &q : current_queues)
    -            {
    -                q->wait_and_throw();
    -            }
    -            // Guard the destruct of current_queues to make sure the ref count is safe.
    -            lock.lock();
    -        }
    -
    -        sycl::queue *create_queue(bool enable_exception_handler = false)
    -        {
    -            return create_in_order_queue(enable_exception_handler);
    -        }
    -
    -        sycl::queue *create_queue(sycl::context context, sycl::device device,
    -                                bool enable_exception_handler = false) {
    -            return create_in_order_queue(context, device, enable_exception_handler);
    -        }
    -
    -        sycl::queue *create_in_order_queue(bool enable_exception_handler = false) {
    -            std::lock_guard lock(m_mutex);
    -            return create_queue_impl(enable_exception_handler,
    -                                    sycl::property::queue::in_order());
    -        }
    -
    -        sycl::queue *create_in_order_queue(sycl::context context, sycl::device device,
    -                                        bool enable_exception_handler = false) {
    -            std::lock_guard lock(m_mutex);
    -            return create_queue_impl(context, device, enable_exception_handler,
    -                                    sycl::property::queue::in_order());
    -        }
    -
    -        sycl::queue *create_out_of_order_queue(bool enable_exception_handler = false) {
    -            std::lock_guard lock(m_mutex);
    -            return create_queue_impl(enable_exception_handler);
    -        }
    -
    -        void destroy_queue(sycl::queue *&queue)
    -        {
    -            std::lock_guard lock(m_mutex);
    -            _queues.erase(std::remove_if(_queues.begin(), _queues.end(),
    -                                         [=](const std::shared_ptr &q) -> bool
    -                                         {
    -                                             return q.get() == queue;
    -                                         }),
    -                          _queues.end());
    -            queue = nullptr;
    -        }
    -        void set_saved_queue(sycl::queue *q)
    -        {
    -            std::lock_guard lock(m_mutex);
    -            _saved_queue = q;
    -        }
    -        sycl::queue *get_saved_queue() const
    -        {
    -            std::lock_guard lock(m_mutex);
    -            return _saved_queue;
    -        }
    -        sycl::context get_context() const { return _ctx; }
    -
    -    private:
    -        void clear_queues()
    -        {
    -            _queues.clear();
    -            _q_in_order = _q_out_of_order = _saved_queue = nullptr;
    -        }
    -
    -        void init_queues()
    -        {
    -            _q_in_order = create_queue_impl(true, sycl::property::queue::in_order());
    -            _q_out_of_order = create_queue_impl(true);
    -            _saved_queue = &default_queue();
    -        }
    -
    -        /// Caller should acquire resource \p m_mutex before calling this function.
    -        template 
    -        sycl::queue *create_queue_impl(bool enable_exception_handler,
    -                                       Properties... properties)
    -        {
    -            sycl::async_handler eh = {};
    -            if (enable_exception_handler)
    -            {
    -                eh = exception_handler;
    -            }
    -            _queues.push_back(std::make_shared(
    -                _ctx, *this, eh,
    -                sycl::property_list(
    -#ifdef DPCT_PROFILING_ENABLED
    -                    sycl::property::queue::enable_profiling(),
    -#endif
    -                    properties...)));
    -
    -            return _queues.back().get();
    -        }
    -
    -        template 
    -        sycl::queue *create_queue_impl(sycl::context context, sycl::device device,
    -                                    bool enable_exception_handler,
    -                                    Properties... properties) {
    -            sycl::async_handler eh = {};
    -            if (enable_exception_handler) {
    -                eh = exception_handler;
    -            }
    -            _queues.push_back(std::make_shared(
    -                context, device, eh,
    -                sycl::property_list(
    -        #ifdef DPCT_PROFILING_ENABLED
    -                    sycl::property::queue::enable_profiling(),
    -        #endif
    -                    properties...)));
    -
    -            return _queues.back().get();
    -        }
    -
    -        void get_version(int &major, int &minor) const
    -        {
    -            detail::get_version(*this, major, minor);
    -        }
    -        sycl::queue *_q_in_order, *_q_out_of_order;
    -        sycl::queue *_saved_queue;
    -        sycl::context _ctx;
    -        std::vector> _queues;
    -        mutable mutex_type m_mutex;
    -    };
    -
    -    /// device manager
    -    class dev_mgr
    -    {
    -    public:
    -        device_ext ¤t_device()
    -        {
    -            unsigned int dev_id = current_device_id();
    -            check_id(dev_id);
    -            return *_devs[dev_id];
    -        }
    -        device_ext &cpu_device() const
    -        {
    -            std::lock_guard lock(m_mutex);
    -            if (_cpu_device == -1)
    -            {
    -                throw std::runtime_error("no valid cpu device");
    -            }
    -            else
    -            {
    -                return *_devs[_cpu_device];
    -            }
    -        }
    -        device_ext &get_device(unsigned int id) const
    -        {
    -            std::lock_guard lock(m_mutex);
    -            check_id(id);
    -            return *_devs[id];
    -        }
    -        unsigned int current_device_id() const
    -        {
    -            std::lock_guard lock(m_mutex);
    -            auto it = _thread2dev_map.find(get_tid());
    -            if (it != _thread2dev_map.end())
    -                return it->second;
    -            return DEFAULT_DEVICE_ID;
    -        }
    -
    -        /// Select device with a device ID.
    -        /// \param [in] id The id of the device which can
    -        /// be obtained through get_device_id(const sycl::device).
    -        void select_device(unsigned int id)
    -        {
    -            std::lock_guard lock(m_mutex);
    -            check_id(id);
    -            _thread2dev_map[get_tid()] = id;
    -        }
    -        unsigned int device_count() { return _devs.size(); }
    -
    -        unsigned int get_device_id(const sycl::device &dev)
    -        {
    -            unsigned int id = 0;
    -            for (auto dev_item : _devs)
    -            {
    -                if (*dev_item == dev)
    -                {
    -                    break;
    -                }
    -                id++;
    -            }
    -            return id;
    -        }
    -
    -        template 
    -        std::enable_if_t<
    -            std::is_invocable_r_v>
    -        select_device(const DeviceSelector &selector = sycl::gpu_selector_v)
    -        {
    -            sycl::device selected_device = sycl::device(selector);
    -            unsigned int selected_device_id = get_device_id(selected_device);
    -            select_device(selected_device_id);
    -        }
    -
    -        /// Returns the instance of device manager singleton.
    -        static dev_mgr &instance()
    -        {
    -            static dev_mgr d_m;
    -            return d_m;
    -        }
    -        dev_mgr(const dev_mgr &) = delete;
    -        dev_mgr &operator=(const dev_mgr &) = delete;
    -        dev_mgr(dev_mgr &&) = delete;
    -        dev_mgr &operator=(dev_mgr &&) = delete;
    -
    -    private:
    -        mutable std::recursive_mutex m_mutex;
    -        static bool compare_dev(sycl::device &device1, sycl::device &device2)
    -        {
    -            dpct::device_info prop1;
    -            dpct::get_device_info(prop1, device1);
    -            dpct::device_info prop2;
    -            dpct::get_device_info(prop2, device2);
    -            return prop1.get_max_compute_units() > prop2.get_max_compute_units();
    -        }
    -        static int convert_backend_index(std::string & backend) {
    -            if (backend == "ext_oneapi_level_zero:gpu") return 0;
    -            if (backend == "opencl:gpu") return 1;
    -            if (backend == "ext_oneapi_cuda:gpu") return 2;
    -            if (backend == "ext_oneapi_hip:gpu") return 3;
    -            if (backend == "opencl:cpu") return 4;
    -            if (backend == "opencl:acc") return 5;
    -            printf("convert_backend_index: can't handle backend=%s\n", backend.c_str());
    -            GGML_ASSERT(false);
    -        }
    -        static bool compare_backend(std::string &backend1, std::string &backend2) {
    -            return convert_backend_index(backend1) < convert_backend_index(backend2);
    -        }
    -        dev_mgr()
    -        {
    -            sycl::device default_device =
    -                sycl::device(sycl::default_selector_v);
    -            _devs.push_back(std::make_shared(default_device));
    -
    -            std::vector sycl_all_devs;
    -            // Collect other devices except for the default device.
    -            if (default_device.is_cpu())
    -                _cpu_device = 0;
    -
    -            auto Platforms = sycl::platform::get_platforms();
    -            // Keep track of the number of devices per backend
    -            std::map DeviceNums;
    -            std::map> backend_devices;
    -
    -            while (!Platforms.empty()) {
    -                auto Platform = Platforms.back();
    -                Platforms.pop_back();
    -                auto devices = Platform.get_devices();
    -                std::string backend_type = get_device_backend_and_type(devices[0]);
    -                for (const auto &device : devices) {
    -                    backend_devices[backend_type].push_back(device);
    -                }
    -            }
    -
    -            std::vector keys;
    -            for(auto it = backend_devices.begin(); it != backend_devices.end(); ++it) {
    -                keys.push_back(it->first);
    -            }
    -            std::sort(keys.begin(), keys.end(), compare_backend);
    -
    -            for (auto &key : keys) {
    -                std::vector devs = backend_devices[key];
    -                std::sort(devs.begin(), devs.end(), compare_dev);
    -                for (const auto &dev : devs) {
    -                    sycl_all_devs.push_back(dev);
    -                }
    -            }
    -
    -            for (auto &dev : sycl_all_devs)
    -            {
    -                if (dev == default_device)
    -                {
    -                    continue;
    -                }
    -                _devs.push_back(std::make_shared(dev));
    -                if (_cpu_device == -1 && dev.is_cpu())
    -                {
    -                    _cpu_device = _devs.size() - 1;
    -                }
    -            }
    -        }
    -        void check_id(unsigned int id) const
    -        {
    -            if (id >= _devs.size())
    -            {
    -                throw std::runtime_error("invalid device id");
    -            }
    -        }
    -        std::vector> _devs;
    -        /// DEFAULT_DEVICE_ID is used, if current_device_id() can not find current
    -        /// thread id in _thread2dev_map, which means default device should be used
    -        /// for the current thread.
    -        const unsigned int DEFAULT_DEVICE_ID = 0;
    -        /// thread-id to device-id map.
    -        std::map _thread2dev_map;
    -        int _cpu_device = -1;
    -    };
    -
    -    static inline sycl::queue &get_default_queue()
    -    {
    -        return dev_mgr::instance().current_device().default_queue();
    -    }
    -
    -    namespace detail
    -    {
    -        enum class pointer_access_attribute
    -        {
    -            host_only = 0,
    -            device_only,
    -            host_device,
    -            end
    -        };
    -
    -        static pointer_access_attribute get_pointer_attribute(sycl::queue &q,
    -                                                              const void *ptr)
    -        {
    -            switch (sycl::get_pointer_type(ptr, q.get_context()))
    -            {
    -            case sycl::usm::alloc::unknown:
    -                return pointer_access_attribute::host_only;
    -            case sycl::usm::alloc::device:
    -                return pointer_access_attribute::device_only;
    -            case sycl::usm::alloc::shared:
    -            case sycl::usm::alloc::host:
    -                return pointer_access_attribute::host_device;
    -            }
    -        }
    -
    -        template 
    -        inline constexpr std::uint64_t get_type_combination_id(ArgT Val)
    -        {
    -            static_assert((unsigned char)library_data_t::library_data_t_size <=
    -                              std::numeric_limits::max() &&
    -                          "library_data_t size exceeds limit.");
    -            static_assert(std::is_same_v, "Unsupported ArgT");
    -            return (std::uint64_t)Val;
    -        }
    -
    -        template 
    -        inline constexpr std::uint64_t get_type_combination_id(FirstT FirstVal,
    -                                                               RestT... RestVal)
    -        {
    -            static_assert((std::uint8_t)library_data_t::library_data_t_size <=
    -                              std::numeric_limits::max() &&
    -                          "library_data_t size exceeds limit.");
    -            static_assert(sizeof...(RestT) <= 8 && "Too many parameters");
    -            static_assert(std::is_same_v, "Unsupported FirstT");
    -            return get_type_combination_id(RestVal...) << 8 | ((std::uint64_t)FirstVal);
    -        }
    -
    -        class mem_mgr
    -        {
    -            mem_mgr()
    -            {
    -                // Reserved address space, no real memory allocation happens here.
    -#if defined(__linux__)
    -                mapped_address_space =
    -                    (byte_t *)mmap(nullptr, mapped_region_size, PROT_NONE,
    -                                   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    -#elif defined(_WIN64)
    -                mapped_address_space = (byte_t *)VirtualAlloc(
    -                    NULL,               // NULL specified as the base address parameter
    -                    mapped_region_size, // Size of allocation
    -                    MEM_RESERVE,        // Allocate reserved pages
    -                    PAGE_NOACCESS);     // Protection = no access
    -#else
    -#error "Only support Windows and Linux."
    -#endif
    -                next_free = mapped_address_space;
    -            };
    -
    -        public:
    -            using buffer_id_t = int;
    -
    -            struct allocation
    -            {
    -                buffer_t buffer;
    -                byte_t *alloc_ptr;
    -                size_t size;
    -            };
    -
    -            ~mem_mgr()
    -            {
    -#if defined(__linux__)
    -                munmap(mapped_address_space, mapped_region_size);
    -#elif defined(_WIN64)
    -                VirtualFree(mapped_address_space, 0, MEM_RELEASE);
    -#else
    -#error "Only support Windows and Linux."
    -#endif
    -            };
    -
    -            mem_mgr(const mem_mgr &) = delete;
    -            mem_mgr &operator=(const mem_mgr &) = delete;
    -            mem_mgr(mem_mgr &&) = delete;
    -            mem_mgr &operator=(mem_mgr &&) = delete;
    -
    -            /// Allocate
    -            void *mem_alloc(size_t size)
    -            {
    -                if (!size)
    -                    return nullptr;
    -                std::lock_guard lock(m_mutex);
    -                if (next_free + size > mapped_address_space + mapped_region_size)
    -                {
    -                    throw std::runtime_error("dpct_malloc: out of memory for virtual memory pool");
    -                }
    -                // Allocation
    -                sycl::range<1> r(size);
    -                buffer_t buf(r);
    -                allocation A{buf, next_free, size};
    -                // Map allocation to device pointer
    -                void *result = next_free;
    -                m_map.emplace(next_free + size, A);
    -                // Update pointer to the next free space.
    -                next_free += (size + extra_padding + alignment - 1) & ~(alignment - 1);
    -
    -                return result;
    -            }
    -
    -            /// Deallocate
    -            void mem_free(const void *ptr)
    -            {
    -                if (!ptr)
    -                    return;
    -                std::lock_guard lock(m_mutex);
    -                auto it = get_map_iterator(ptr);
    -                m_map.erase(it);
    -            }
    -
    -            /// map: device pointer -> allocation(buffer, alloc_ptr, size)
    -            allocation translate_ptr(const void *ptr)
    -            {
    -                std::lock_guard lock(m_mutex);
    -                auto it = get_map_iterator(ptr);
    -                return it->second;
    -            }
    -
    -            /// Check if the pointer represents device pointer or not.
    -            bool is_device_ptr(const void *ptr) const
    -            {
    -                std::lock_guard lock(m_mutex);
    -                return (mapped_address_space <= ptr) &&
    -                       (ptr < mapped_address_space + mapped_region_size);
    -            }
    -
    -            /// Returns the instance of memory manager singleton.
    -            static mem_mgr &instance()
    -            {
    -                static mem_mgr m;
    -                return m;
    -            }
    -
    -        private:
    -            std::map m_map;
    -            mutable std::mutex m_mutex;
    -            byte_t *mapped_address_space;
    -            byte_t *next_free;
    -            const size_t mapped_region_size = 128ull * 1024 * 1024 * 1024;
    -            const size_t alignment = 256;
    -            /// This padding may be defined to some positive value to debug
    -            /// out of bound accesses.
    -            const size_t extra_padding = 0;
    -
    -            std::map::iterator get_map_iterator(const void *ptr)
    -            {
    -                auto it = m_map.upper_bound((byte_t *)ptr);
    -                if (it == m_map.end())
    -                {
    -                    // Not a virtual pointer.
    -                    throw std::runtime_error("can not get buffer from non-virtual pointer");
    -                }
    -                const allocation &alloc = it->second;
    -                if (ptr < alloc.alloc_ptr)
    -                {
    -                    // Out of bound.
    -                    // This may happen if there's a gap between allocations due to alignment
    -                    // or extra padding and pointer points to this gap.
    -                    throw std::runtime_error("invalid virtual pointer");
    -                }
    -                return it;
    -            }
    -        };
    -
    -        template 
    -        class accessor;
    -        template 
    -        class memory_traits
    -        {
    -        public:
    -            static constexpr sycl::access::target target =
    -                sycl::access::target::device;
    -            static constexpr sycl::access_mode mode =
    -                (Memory == constant) ? sycl::access_mode::read
    -                                     : sycl::access_mode::read_write;
    -            static constexpr size_t type_size = sizeof(T);
    -            using element_t =
    -                typename std::conditional::type;
    -            using value_t = typename std::remove_cv::type;
    -            template 
    -            using accessor_t = typename std::conditional<
    -                Memory == local, sycl::local_accessor,
    -                sycl::accessor>::type;
    -            using pointer_t = T *;
    -        };
    -
    -        static inline void *dpct_malloc(size_t size, sycl::queue &q)
    -        {
    -            return sycl::malloc_device(size, q.get_device(), q.get_context());
    -        }
    -
    -#define PITCH_DEFAULT_ALIGN(x) (((x) + 31) & ~(0x1F))
    -        static inline void *dpct_malloc(size_t &pitch, size_t x, size_t y, size_t z,
    -                                        sycl::queue &q)
    -        {
    -            pitch = PITCH_DEFAULT_ALIGN(x);
    -            return dpct_malloc(pitch * y * z, q);
    -        }
    -
    -        /**
    -         * @brief Sets \p value to the first \p size elements starting from \p dev_ptr in \p q.
    -         * @tparam valueT The type of the element to be set.
    -         * @param [in] q The queue in which the operation is done.
    -         * @param [in] dev_ptr Pointer to the virtual device memory address.
    -         * @param [in] value The value to be set.
    -         * @param [in] size Number of elements to be set to the value.
    -         * @return An event representing the memset operation.
    -         */
    -        template 
    -        static inline sycl::event dpct_memset(sycl::queue &q, void *dev_ptr,
    -                                              valueT value, size_t size)
    -        {
    -            return q.fill(dev_ptr, value, size);
    -        }
    -
    -        /**
    -         * @brief Sets \p value to the 3D memory region pointed by \p data in \p q.
    -         * @tparam valueT The type of the element to be set.
    -         * @param [in] q The queue in which the operation is done.
    -         * @param [in] data Pointer to the pitched device memory region.
    -         * @param [in] value The value to be set.
    -         * @param [in] size 3D memory region by number of elements.
    -         * @return An event list representing the memset operations.
    -         */
    -        template 
    -        static inline std::vector
    -        dpct_memset(sycl::queue &q, pitched_data data, valueT value,
    -                    sycl::range<3> size)
    -        {
    -            std::vector event_list;
    -            size_t slice = data.get_pitch() * data.get_y();
    -            unsigned char *data_surface = (unsigned char *)data.get_data_ptr();
    -            for (size_t z = 0; z < size.get(2); ++z)
    -            {
    -                unsigned char *data_ptr = data_surface;
    -                for (size_t y = 0; y < size.get(1); ++y)
    -                {
    -                    event_list.push_back(dpct_memset(q, data_ptr, value, size.get(0)));
    -                    data_ptr += data.get_pitch();
    -                }
    -                data_surface += slice;
    -            }
    -            return event_list;
    -        }
    -
    -        /**
    -         * @brief Sets \p val to the pitched 2D memory region pointed by \p ptr in \p q.
    -         * @tparam valueT The type of the element to be set.
    -         * @param [in] q The queue in which the operation is done.
    -         * @param [in] ptr Pointer to the virtual device memory.
    -         * @param [in] pitch The pitch size by number of elements, including padding.
    -         * @param [in] val The value to be set.
    -         * @param [in] x The width of memory region by number of elements.
    -         * @param [in] y The height of memory region by number of elements.
    -         * @return An event list representing the memset operations.
    -         */
    -        template 
    -        static inline std::vector
    -        dpct_memset(sycl::queue &q, void *ptr, size_t pitch, valueT val, size_t x,
    -                    size_t y)
    -        {
    -            return dpct_memset(q, pitched_data(ptr, pitch, x, 1), val,
    -                               sycl::range<3>(x, y, 1));
    -        }
    -
    -        static memcpy_direction deduce_memcpy_direction(sycl::queue &q, void *to_ptr,
    -                                                        const void *from_ptr,
    -                                                        memcpy_direction dir)
    -        {
    -            switch (dir)
    -            {
    -            case memcpy_direction::host_to_host:
    -            case memcpy_direction::host_to_device:
    -            case memcpy_direction::device_to_host:
    -            case memcpy_direction::device_to_device:
    -                return dir;
    -            case memcpy_direction::automatic:
    -            {
    -                // table[to_attribute][from_attribute]
    -                static const memcpy_direction
    -                    direction_table[static_cast(pointer_access_attribute::end)]
    -                                   [static_cast(pointer_access_attribute::end)] =
    -                                       {{memcpy_direction::host_to_host,
    -                                         memcpy_direction::device_to_host,
    -                                         memcpy_direction::host_to_host},
    -                                        {memcpy_direction::host_to_device,
    -                                         memcpy_direction::device_to_device,
    -                                         memcpy_direction::device_to_device},
    -                                        {memcpy_direction::host_to_host,
    -                                         memcpy_direction::device_to_device,
    -                                         memcpy_direction::device_to_device}};
    -                return direction_table[static_cast(get_pointer_attribute(
    -                    q, to_ptr))][static_cast(get_pointer_attribute(q, from_ptr))];
    -            }
    -            default:
    -                throw std::runtime_error("dpct_memcpy: invalid direction value");
    -            }
    -        }
    -
    -        static sycl::event
    -        dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr, size_t size,
    -                    memcpy_direction direction,
    -                    const std::vector &dep_events = {})
    -        {
    -            if (!size)
    -                return sycl::event{};
    -            return q.memcpy(to_ptr, from_ptr, size, dep_events);
    -            GGML_UNUSED(direction);
    -        }
    -
    -        // Get actual copy range and make sure it will not exceed range.
    -        static inline size_t get_copy_range(sycl::range<3> size, size_t slice,
    -                                            size_t pitch)
    -        {
    -            return slice * (size.get(2) - 1) + pitch * (size.get(1) - 1) + size.get(0);
    -        }
    -
    -        static inline size_t get_offset(sycl::id<3> id, size_t slice,
    -                                        size_t pitch)
    -        {
    -            return slice * id.get(2) + pitch * id.get(1) + id.get(0);
    -        }
    -
    -        /// copy 3D matrix specified by \p size from 3D matrix specified by \p from_ptr
    -        /// and \p from_range to another specified by \p to_ptr and \p to_range.
    -        static inline std::vector
    -        dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    -                    sycl::range<3> to_range, sycl::range<3> from_range,
    -                    sycl::id<3> to_id, sycl::id<3> from_id,
    -                    sycl::range<3> size, memcpy_direction direction,
    -                    const std::vector &dep_events = {})
    -        {
    -            // RAII for host pointer
    -            class host_buffer
    -            {
    -                void *_buf;
    -                size_t _size;
    -                sycl::queue &_q;
    -                const std::vector &_deps; // free operation depends
    -
    -            public:
    -                host_buffer(size_t size, sycl::queue &q,
    -                            const std::vector &deps)
    -                    : _buf(std::malloc(size)), _size(size), _q(q), _deps(deps) {}
    -                void *get_ptr() const { return _buf; }
    -                size_t get_size() const { return _size; }
    -                ~host_buffer()
    -                {
    -                    if (_buf)
    -                    {
    -                        _q.submit([&](sycl::handler &cgh)
    -                                  {
    -        cgh.depends_on(_deps);
    -        cgh.host_task([buf = _buf] { std::free(buf); }); });
    -                    }
    -                }
    -            };
    -            std::vector event_list;
    -
    -            size_t to_slice = to_range.get(1) * to_range.get(0),
    -                   from_slice = from_range.get(1) * from_range.get(0);
    -            unsigned char *to_surface =
    -                (unsigned char *)to_ptr + get_offset(to_id, to_slice, to_range.get(0));
    -            const unsigned char *from_surface =
    -                (const unsigned char *)from_ptr +
    -                get_offset(from_id, from_slice, from_range.get(0));
    -
    -            if (to_slice == from_slice && to_slice == size.get(1) * size.get(0))
    -            {
    -                return {dpct_memcpy(q, to_surface, from_surface, to_slice * size.get(2),
    -                                    direction, dep_events)};
    -            }
    -            direction = deduce_memcpy_direction(q, to_ptr, from_ptr, direction);
    -            size_t size_slice = size.get(1) * size.get(0);
    -            switch (direction)
    -            {
    -            case host_to_host:
    -                for (size_t z = 0; z < size.get(2); ++z)
    -                {
    -                    unsigned char *to_ptr = to_surface;
    -                    const unsigned char *from_ptr = from_surface;
    -                    if (to_range.get(0) == from_range.get(0) &&
    -                        to_range.get(0) == size.get(0))
    -                    {
    -                        event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size_slice,
    -                                                         direction, dep_events));
    -                    }
    -                    else
    -                    {
    -                        for (size_t y = 0; y < size.get(1); ++y)
    -                        {
    -                            event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size.get(0),
    -                                                             direction, dep_events));
    -                            to_ptr += to_range.get(0);
    -                            from_ptr += from_range.get(0);
    -                        }
    -                    }
    -                    to_surface += to_slice;
    -                    from_surface += from_slice;
    -                }
    -                break;
    -            case host_to_device:
    -            {
    -                host_buffer buf(get_copy_range(size, to_slice, to_range.get(0)), q,
    -                                event_list);
    -                std::vector host_events;
    -                if (to_slice == size_slice)
    -                {
    -                    // Copy host data to a temp host buffer with the shape of target.
    -                    host_events =
    -                        dpct_memcpy(q, buf.get_ptr(), from_surface, to_range, from_range,
    -                                    sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size,
    -                                    host_to_host, dep_events);
    -                }
    -                else
    -                {
    -                    // Copy host data to a temp host buffer with the shape of target.
    -                    host_events = dpct_memcpy(
    -                        q, buf.get_ptr(), from_surface, to_range, from_range,
    -                        sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size, host_to_host,
    -                        // If has padding data, not sure whether it is useless. So fill temp
    -                        // buffer with it.
    -                        std::vector{
    -                            dpct_memcpy(q, buf.get_ptr(), to_surface, buf.get_size(),
    -                                        device_to_host, dep_events)});
    -                }
    -                // Copy from temp host buffer to device with only one submit.
    -                event_list.push_back(dpct_memcpy(q, to_surface, buf.get_ptr(),
    -                                                 buf.get_size(), host_to_device,
    -                                                 host_events));
    -                break;
    -            }
    -            case device_to_host:
    -            {
    -                host_buffer buf(get_copy_range(size, from_slice, from_range.get(0)), q,
    -                                event_list);
    -                // Copy from host temp buffer to host target with reshaping.
    -                event_list = dpct_memcpy(
    -                    q, to_surface, buf.get_ptr(), to_range, from_range, sycl::id<3>(0, 0, 0),
    -                    sycl::id<3>(0, 0, 0), size, host_to_host,
    -                    // Copy from device to temp host buffer with only one submit.
    -                    std::vector{dpct_memcpy(q, buf.get_ptr(), from_surface,
    -                                                         buf.get_size(),
    -                                                         device_to_host, dep_events)});
    -                break;
    -            }
    -            case device_to_device:
    -                event_list.push_back(q.submit([&](sycl::handler &cgh){
    -                cgh.depends_on(dep_events);
    -                cgh.parallel_for(
    -                    size,
    -                    [=](sycl::id<3> id) {
    -                        to_surface[get_offset(id, to_slice, to_range.get(0))] =
    -                            from_surface[get_offset(id, from_slice, from_range.get(0))];
    -                    }); }));
    -                break;
    -            default:
    -                throw std::runtime_error("dpct_memcpy: invalid direction value");
    -            }
    -            return event_list;
    -        }
    -
    -        /// memcpy 2D/3D matrix specified by pitched_data.
    -        static inline std::vector
    -        dpct_memcpy(sycl::queue &q, pitched_data to, sycl::id<3> to_id,
    -                    pitched_data from, sycl::id<3> from_id, sycl::range<3> size,
    -                    memcpy_direction direction = automatic)
    -        {
    -            return dpct_memcpy(q, to.get_data_ptr(), from.get_data_ptr(),
    -                               sycl::range<3>(to.get_pitch(), to.get_y(), 1),
    -                               sycl::range<3>(from.get_pitch(), from.get_y(), 1), to_id, from_id,
    -                               size, direction);
    -        }
    -
    -        /// memcpy 2D matrix with pitch.
    -        static inline std::vector
    -        dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    -                    size_t to_pitch, size_t from_pitch, size_t x, size_t y,
    -                    memcpy_direction direction = automatic)
    -        {
    -            return dpct_memcpy(q, to_ptr, from_ptr, sycl::range<3>(to_pitch, y, 1),
    -                               sycl::range<3>(from_pitch, y, 1),
    -                               sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0),
    -                               sycl::range<3>(x, y, 1), direction);
    -        }
    -
    -        namespace deprecated
    -        {
    -
    -            template 
    -            class usm_allocator
    -            {
    -            private:
    -                using Alloc = sycl::usm_allocator;
    -                Alloc _impl;
    -
    -            public:
    -                using value_type = typename std::allocator_traits::value_type;
    -                using pointer = typename std::allocator_traits::pointer;
    -                using const_pointer = typename std::allocator_traits::const_pointer;
    -                using void_pointer = typename std::allocator_traits::void_pointer;
    -                using const_void_pointer =
    -                    typename std::allocator_traits::const_void_pointer;
    -                using reference = typename std::allocator_traits::value_type &;
    -                using const_reference =
    -                    const typename std::allocator_traits::value_type &;
    -                using difference_type =
    -                    typename std::allocator_traits::difference_type;
    -                using size_type = typename std::allocator_traits::size_type;
    -                using propagate_on_container_copy_assignment = typename std::allocator_traits<
    -                    Alloc>::propagate_on_container_copy_assignment;
    -                using propagate_on_container_move_assignment = typename std::allocator_traits<
    -                    Alloc>::propagate_on_container_move_assignment;
    -                using propagate_on_container_swap =
    -                    typename std::allocator_traits::propagate_on_container_swap;
    -                using is_always_equal =
    -                    typename std::allocator_traits::is_always_equal;
    -
    -                template 
    -                struct rebind
    -                {
    -                    typedef usm_allocator other;
    -                };
    -
    -                usm_allocator() : _impl(dpct::get_default_queue()) {}
    -                ~usm_allocator() {}
    -                usm_allocator(const usm_allocator &other) : _impl(other._impl) {}
    -                usm_allocator(usm_allocator &&other) : _impl(std::move(other._impl)) {}
    -                pointer address(reference r) { return &r; }
    -                const_pointer address(const_reference r) { return &r; }
    -                pointer allocate(size_type cnt, const_void_pointer hint = nullptr)
    -                {
    -                    return std::allocator_traits::allocate(_impl, cnt, hint);
    -                }
    -                void deallocate(pointer p, size_type cnt)
    -                {
    -                    std::allocator_traits::deallocate(_impl, p, cnt);
    -                }
    -                size_type max_size() const
    -                {
    -                    return std::allocator_traits::max_size(_impl);
    -                }
    -                bool operator==(const usm_allocator &other) const { return _impl == other._impl; }
    -                bool operator!=(const usm_allocator &other) const { return _impl != other._impl; }
    -            };
    -
    -        } // namespace deprecated
    -
    -        inline void dpct_free(void *ptr,
    -                              const sycl::queue &q)
    -        {
    -            if (ptr)
    -            {
    -                sycl::free(ptr, q.get_context());
    -            }
    -        }
    -
    -        template 
    -        inline auto get_memory(const void *x)
    -        {
    -            T *new_x = reinterpret_cast(const_cast(x));
    -            return new_x;
    -        }
    -
    -        template 
    -        inline typename DataType::T2 get_value(const T *s, sycl::queue &q)
    -        {
    -            using Ty = typename DataType::T2;
    -            Ty s_h;
    -            if (get_pointer_attribute(q, s) == pointer_access_attribute::device_only)
    -                detail::dpct_memcpy(q, (void *)&s_h, (const void *)s, sizeof(T), device_to_host)
    -                    .wait();
    -            else
    -                s_h = *reinterpret_cast(s);
    -            return s_h;
    -        }
    -
    -    } // namespace detail
    -
    -    template 
    -    inline auto get_value(const T *s, sycl::queue &q)
    -    {
    -        return detail::get_value(s, q);
    -    }
    -
    -    namespace detail
    -    {
    -        template 
    -        inline void gemm_impl(sycl::queue &q, oneapi::mkl::transpose a_trans,
    -                              oneapi::mkl::transpose b_trans, int m, int n, int k,
    -                              const void *alpha, const void *a, int lda, const void *b,
    -                              int ldb, const void *beta, void *c, int ldc)
    -        {
    -            Ts alpha_value = dpct::get_value(reinterpret_cast(alpha), q);
    -            Ts beta_value = dpct::get_value(reinterpret_cast(beta), q);
    -            auto data_a = get_memory(a);
    -            auto data_b = get_memory(b);
    -            auto data_c = get_memory(c);
    -            oneapi::mkl::blas::column_major::gemm(
    -                q, a_trans, b_trans, m, n, k, alpha_value, data_a, lda,
    -                data_b, ldb, beta_value, data_c, ldc);
    -        }
    -
    -        template 
    -        class vectorized_binary
    -        {
    -        public:
    -            inline VecT operator()(VecT a, VecT b, const BinaryOperation binary_op)
    -            {
    -                VecT v4;
    -                for (size_t i = 0; i < v4.size(); ++i)
    -                {
    -                    v4[i] = binary_op(a[i], b[i]);
    -                }
    -                return v4;
    -            }
    -        };
    -
    -        template 
    -        class vectorized_binary<
    -            VecT, BinaryOperation,
    -            std::void_t>>
    -        {
    -        public:
    -            inline VecT operator()(VecT a, VecT b, const BinaryOperation binary_op)
    -            {
    -                return binary_op(a, b).template as();
    -            }
    -        };
    -
    -        template 
    -        inline void gemm_batch_impl(sycl::queue &q, oneapi::mkl::transpose a_trans,
    -                                    oneapi::mkl::transpose b_trans, int m, int n, int k,
    -                                    const void *alpha, const void **a, int lda,
    -                                    const void **b, int ldb, const void *beta, void **c,
    -                                    int ldc, int batch_size)
    -        {
    -            struct matrix_info_t
    -            {
    -                oneapi::mkl::transpose transpose_info[2];
    -                Ts value_info[2];
    -                std::int64_t size_info[3];
    -                std::int64_t ld_info[3];
    -                std::int64_t groupsize_info;
    -            };
    -
    -            Ts alpha_value = dpct::get_value(reinterpret_cast(alpha), q);
    -            Ts beta_value = dpct::get_value(reinterpret_cast(beta), q);
    -
    -            matrix_info_t *matrix_info =
    -                (matrix_info_t *)std::malloc(sizeof(matrix_info_t));
    -            matrix_info->transpose_info[0] = a_trans;
    -            matrix_info->transpose_info[1] = b_trans;
    -            matrix_info->value_info[0] = alpha_value;
    -            matrix_info->value_info[1] = beta_value;
    -            matrix_info->size_info[0] = m;
    -            matrix_info->size_info[1] = n;
    -            matrix_info->size_info[2] = k;
    -            matrix_info->ld_info[0] = lda;
    -            matrix_info->ld_info[1] = ldb;
    -            matrix_info->ld_info[2] = ldc;
    -            matrix_info->groupsize_info = batch_size;
    -
    -            sycl::event e = oneapi::mkl::blas::column_major::gemm_batch(
    -                q, matrix_info->transpose_info, matrix_info->transpose_info + 1,
    -                matrix_info->size_info, matrix_info->size_info + 1,
    -                matrix_info->size_info + 2, matrix_info->value_info,
    -                reinterpret_cast(a), matrix_info->ld_info,
    -                reinterpret_cast(b), matrix_info->ld_info + 1,
    -                matrix_info->value_info + 1, reinterpret_cast(c),
    -                matrix_info->ld_info + 2, 1, &(matrix_info->groupsize_info));
    -
    -            q.submit([&](sycl::handler &cgh)
    -                     {
    -    cgh.depends_on(e);
    -    cgh.host_task([=] { std::free(matrix_info); }); });
    -        }
    -
    -        template 
    -        inline void
    -        gemm_batch_impl(sycl::queue &q, oneapi::mkl::transpose a_trans,
    -                        oneapi::mkl::transpose b_trans, int m, int n,
    -                        int k, const void *alpha, const void *a, int lda,
    -                        long long int stride_a, const void *b, int ldb,
    -                        long long int stride_b, const void *beta, void *c,
    -                        int ldc, long long int stride_c, int batch_size)
    -        {
    -            Ts alpha_value = dpct::get_value(reinterpret_cast(alpha), q);
    -            Ts beta_value = dpct::get_value(reinterpret_cast(beta), q);
    -            auto data_a = get_memory(a);
    -            auto data_b = get_memory(b);
    -            auto data_c = get_memory(c);
    -            oneapi::mkl::blas::column_major::gemm_batch(
    -                q, a_trans, b_trans, m, n, k, alpha_value, data_a, lda,
    -                stride_a, data_b, ldb, stride_b, beta_value,
    -                data_c, ldc, stride_c, batch_size);
    -        }
    -
    -    } // namespace detail
    -
    -    template 
    -    inline unsigned vectorized_binary(unsigned a, unsigned b,
    -                                      const BinaryOperation binary_op)
    -    {
    -        sycl::vec v0{a}, v1{b};
    -        auto v2 = v0.as();
    -        auto v3 = v1.as();
    -        auto v4 =
    -            detail::vectorized_binary()(v2, v3, binary_op);
    -        v0 = v4.template as>();
    -        return v0;
    -    }
    -
    -    static void async_dpct_memcpy(void *to_ptr, const void *from_ptr, size_t size,
    -                                  memcpy_direction direction = automatic,
    -                                  sycl::queue &q = dpct::get_default_queue())
    -    {
    -        detail::dpct_memcpy(q, to_ptr, from_ptr, size, direction);
    -    }
    -
    -    static inline unsigned int select_device(unsigned int id)
    -    {
    -        dev_mgr::instance().select_device(id);
    -        return id;
    -    }
    -
    -    template 
    -    T permute_sub_group_by_xor(sycl::sub_group g, T x, unsigned int mask,
    -                               unsigned int logical_sub_group_size = 32)
    -    {
    -        unsigned int id = g.get_local_linear_id();
    -        unsigned int start_index =
    -            id / logical_sub_group_size * logical_sub_group_size;
    -        unsigned int target_offset = (id % logical_sub_group_size) ^ mask;
    -        return sycl::select_from_group(g, x,
    -                                       target_offset < logical_sub_group_size
    -                                           ? start_index + target_offset
    -                                           : id);
    -    }
    -
    -    template 
    -    sycl::vec extract_and_sign_or_zero_extend4(T val)
    -    {
    -        return sycl::vec(val)
    -            .template as, int8_t, uint8_t>, 4>>()
    -            .template convert();
    -    }
    -
    -    template 
    -    using dot_product_acc_t =
    -        std::conditional_t && std::is_unsigned_v,
    -                           uint32_t, int32_t>;
    -
    -    template 
    -    inline auto dp4a(T1 a, T2 b, T3 c)
    -    {
    -        dot_product_acc_t res = c;
    -        auto va = extract_and_sign_or_zero_extend4(a);
    -        auto vb = extract_and_sign_or_zero_extend4(b);
    -        res += va[0] * vb[0];
    -        res += va[1] * vb[1];
    -        res += va[2] * vb[2];
    -        res += va[3] * vb[3];
    -        return res;
    -    }
    -
    -    struct sub_sat
    -    {
    -        template 
    -        auto operator()(const T x, const T y) const
    -        {
    -            return sycl::sub_sat(x, y);
    -        }
    -    };
    -
    -    template 
    -    inline T vectorized_min(T a, T b)
    -    {
    -        sycl::vec v0{a}, v1{b};
    -        auto v2 = v0.template as();
    -        auto v3 = v1.template as();
    -        auto v4 = sycl::min(v2, v3);
    -        v0 = v4.template as>();
    -        return v0;
    -    }
    -
    -    inline float pow(const float a, const int b) { return sycl::pown(a, b); }
    -    inline double pow(const double a, const int b) { return sycl::pown(a, b); }
    -    inline float pow(const float a, const float b) { return sycl::pow(a, b); }
    -    inline double pow(const double a, const double b) { return sycl::pow(a, b); }
    -    template 
    -    inline typename std::enable_if_t, T>
    -    pow(const T a, const U b)
    -    {
    -        return sycl::pow(a, static_cast(b));
    -    }
    -    template 
    -    inline typename std::enable_if_t, double>
    -    pow(const T a, const U b)
    -    {
    -        return sycl::pow(static_cast(a), static_cast(b));
    -    }
    -
    -    inline double min(const double a, const float b)
    -    {
    -        return sycl::fmin(a, static_cast(b));
    -    }
    -    inline double min(const float a, const double b)
    -    {
    -        return sycl::fmin(static_cast(a), b);
    -    }
    -    inline float min(const float a, const float b) { return sycl::fmin(a, b); }
    -    inline double min(const double a, const double b) { return sycl::fmin(a, b); }
    -    inline std::uint32_t min(const std::uint32_t a, const std::int32_t b)
    -    {
    -        return sycl::min(a, static_cast(b));
    -    }
    -    inline std::uint32_t min(const std::int32_t a, const std::uint32_t b)
    -    {
    -        return sycl::min(static_cast(a), b);
    -    }
    -    inline std::int32_t min(const std::int32_t a, const std::int32_t b)
    -    {
    -        return sycl::min(a, b);
    -    }
    -    inline std::uint32_t min(const std::uint32_t a, const std::uint32_t b)
    -    {
    -        return sycl::min(a, b);
    -    }
    -    inline std::uint64_t min(const std::uint64_t a, const std::int64_t b)
    -    {
    -        return sycl::min(a, static_cast(b));
    -    }
    -    inline std::uint64_t min(const std::int64_t a, const std::uint64_t b)
    -    {
    -        return sycl::min(static_cast(a), b);
    -    }
    -    inline std::int64_t min(const std::int64_t a, const std::int64_t b)
    -    {
    -        return sycl::min(a, b);
    -    }
    -    inline std::uint64_t min(const std::uint64_t a, const std::uint64_t b)
    -    {
    -        return sycl::min(a, b);
    -    }
    -    inline std::uint64_t min(const std::uint64_t a, const std::int32_t b)
    -    {
    -        return sycl::min(a, static_cast(b));
    -    }
    -    inline std::uint64_t min(const std::int32_t a, const std::uint64_t b)
    -    {
    -        return sycl::min(static_cast(a), b);
    -    }
    -    inline std::uint64_t min(const std::uint64_t a, const std::uint32_t b)
    -    {
    -        return sycl::min(a, static_cast(b));
    -    }
    -    inline std::uint64_t min(const std::uint32_t a, const std::uint64_t b)
    -    {
    -        return sycl::min(static_cast(a), b);
    -    }
    -    // max function overloads.
    -    // For floating-point types, `float` or `double` arguments are acceptable.
    -    // For integer types, `std::uint32_t`, `std::int32_t`, `std::uint64_t` or
    -    // `std::int64_t` type arguments are acceptable.
    -    inline double max(const double a, const float b)
    -    {
    -        return sycl::fmax(a, static_cast(b));
    -    }
    -    inline double max(const float a, const double b)
    -    {
    -        return sycl::fmax(static_cast(a), b);
    -    }
    -    inline float max(const float a, const float b) { return sycl::fmax(a, b); }
    -    inline double max(const double a, const double b) { return sycl::fmax(a, b); }
    -    inline std::uint32_t max(const std::uint32_t a, const std::int32_t b)
    -    {
    -        return sycl::max(a, static_cast(b));
    -    }
    -    inline std::uint32_t max(const std::int32_t a, const std::uint32_t b)
    -    {
    -        return sycl::max(static_cast(a), b);
    -    }
    -    inline std::int32_t max(const std::int32_t a, const std::int32_t b)
    -    {
    -        return sycl::max(a, b);
    -    }
    -    inline std::uint32_t max(const std::uint32_t a, const std::uint32_t b)
    -    {
    -        return sycl::max(a, b);
    -    }
    -    inline std::uint64_t max(const std::uint64_t a, const std::int64_t b)
    -    {
    -        return sycl::max(a, static_cast(b));
    -    }
    -    inline std::uint64_t max(const std::int64_t a, const std::uint64_t b)
    -    {
    -        return sycl::max(static_cast(a), b);
    -    }
    -    inline std::int64_t max(const std::int64_t a, const std::int64_t b)
    -    {
    -        return sycl::max(a, b);
    -    }
    -    inline std::uint64_t max(const std::uint64_t a, const std::uint64_t b)
    -    {
    -        return sycl::max(a, b);
    -    }
    -    inline std::uint64_t max(const std::uint64_t a, const std::int32_t b)
    -    {
    -        return sycl::max(a, static_cast(b));
    -    }
    -    inline std::uint64_t max(const std::int32_t a, const std::uint64_t b)
    -    {
    -        return sycl::max(static_cast(a), b);
    -    }
    -    inline std::uint64_t max(const std::uint64_t a, const std::uint32_t b)
    -    {
    -        return sycl::max(a, static_cast(b));
    -    }
    -    inline std::uint64_t max(const std::uint32_t a, const std::uint64_t b)
    -    {
    -        return sycl::max(static_cast(a), b);
    -    }
    -
    -    inline void
    -    has_capability_or_fail(const sycl::device &dev,
    -                           const std::initializer_list &props)
    -    {
    -        for (const auto &it : props)
    -        {
    -            if (dev.has(it))
    -                continue;
    -            switch (it)
    -            {
    -            case sycl::aspect::fp64:
    -                throw std::runtime_error("'double' is not supported in '" +
    -                                         dev.get_info() +
    -                                         "' device");
    -                break;
    -            case sycl::aspect::fp16:
    -                throw std::runtime_error("'half' is not supported in '" +
    -                                         dev.get_info() +
    -                                         "' device");
    -                break;
    -            default:
    -#define __SYCL_ASPECT(ASPECT, ID) \
    -    case sycl::aspect::ASPECT:    \
    -        return #ASPECT;
    -#define __SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE) __SYCL_ASPECT(ASPECT, ID)
    -#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE)
    -                auto getAspectNameStr = [](sycl::aspect AspectNum) -> std::string
    -                {
    -                    switch (AspectNum)
    -                    {
    -#include 
    -#include 
    -                    default:
    -                        return "unknown aspect";
    -                    }
    -                };
    -#undef __SYCL_ASPECT_DEPRECATED_ALIAS
    -#undef __SYCL_ASPECT_DEPRECATED
    -#undef __SYCL_ASPECT
    -                throw std::runtime_error(
    -                    "'" + getAspectNameStr(it) + "' is not supported in '" +
    -                    dev.get_info() + "' device");
    -            }
    -            break;
    -        }
    -    }
    -
    -    static inline unsigned int get_current_device_id()
    -    {
    -        return dev_mgr::instance().current_device_id();
    -    }
    -
    -    static inline device_ext &get_current_device()
    -    {
    -        return dev_mgr::instance().current_device();
    -    }
    -
    -    static inline sycl::queue &get_in_order_queue()
    -    {
    -        return dev_mgr::instance().current_device().in_order_queue();
    -    }
    -
    -    static sycl::event
    -    dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr, size_t size,
    -                memcpy_direction direction,
    -                const std::vector &dep_events = {})
    -    {
    -        if (!size)
    -            return sycl::event{};
    -        return q.memcpy(to_ptr, from_ptr, size, dep_events);
    -        GGML_UNUSED(direction);
    -    }
    -
    -    // Get actual copy range and make sure it will not exceed range.
    -    static inline size_t get_copy_range(sycl::range<3> size, size_t slice,
    -                                        size_t pitch)
    -    {
    -        return slice * (size.get(2) - 1) + pitch * (size.get(1) - 1) + size.get(0);
    -    }
    -
    -    static inline size_t get_offset(sycl::id<3> id, size_t slice,
    -                                    size_t pitch)
    -    {
    -        return slice * id.get(2) + pitch * id.get(1) + id.get(0);
    -    }
    -
    -    /// copy 3D matrix specified by \p size from 3D matrix specified by \p from_ptr
    -    /// and \p from_range to another specified by \p to_ptr and \p to_range.
    -    static inline std::vector
    -    dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    -                sycl::range<3> to_range, sycl::range<3> from_range,
    -                sycl::id<3> to_id, sycl::id<3> from_id,
    -                sycl::range<3> size, memcpy_direction direction,
    -                const std::vector &dep_events = {})
    -    {
    -        // RAII for host pointer
    -        class host_buffer
    -        {
    -            void *_buf;
    -            size_t _size;
    -            sycl::queue &_q;
    -            const std::vector &_deps; // free operation depends
    -
    -        public:
    -            host_buffer(size_t size, sycl::queue &q,
    -                        const std::vector &deps)
    -                : _buf(std::malloc(size)), _size(size), _q(q), _deps(deps) {}
    -            void *get_ptr() const { return _buf; }
    -            size_t get_size() const { return _size; }
    -            ~host_buffer()
    -            {
    -                if (_buf)
    -                {
    -                    _q.submit([&](sycl::handler &cgh)
    -                              {
    -            cgh.depends_on(_deps);
    -            cgh.host_task([buf = _buf] { std::free(buf); }); });
    -                }
    -            }
    -        };
    -        std::vector event_list;
    -
    -        size_t to_slice = to_range.get(1) * to_range.get(0),
    -               from_slice = from_range.get(1) * from_range.get(0);
    -        unsigned char *to_surface =
    -            (unsigned char *)to_ptr + get_offset(to_id, to_slice, to_range.get(0));
    -        const unsigned char *from_surface =
    -            (const unsigned char *)from_ptr +
    -            get_offset(from_id, from_slice, from_range.get(0));
    -
    -        if (to_slice == from_slice && to_slice == size.get(1) * size.get(0))
    -        {
    -            return {dpct_memcpy(q, to_surface, from_surface, to_slice * size.get(2),
    -                                direction, dep_events)};
    -        }
    -        direction = detail::deduce_memcpy_direction(q, to_ptr, from_ptr, direction);
    -        size_t size_slice = size.get(1) * size.get(0);
    -        switch (direction)
    -        {
    -        case host_to_host:
    -            for (size_t z = 0; z < size.get(2); ++z)
    -            {
    -                unsigned char *to_ptr = to_surface;
    -                const unsigned char *from_ptr = from_surface;
    -                if (to_range.get(0) == from_range.get(0) &&
    -                    to_range.get(0) == size.get(0))
    -                {
    -                    event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size_slice,
    -                                                     direction, dep_events));
    -                }
    -                else
    -                {
    -                    for (size_t y = 0; y < size.get(1); ++y)
    -                    {
    -                        event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size.get(0),
    -                                                         direction, dep_events));
    -                        to_ptr += to_range.get(0);
    -                        from_ptr += from_range.get(0);
    -                    }
    -                }
    -                to_surface += to_slice;
    -                from_surface += from_slice;
    -            }
    -            break;
    -        case host_to_device:
    -        {
    -            host_buffer buf(get_copy_range(size, to_slice, to_range.get(0)), q,
    -                            event_list);
    -            std::vector host_events;
    -            if (to_slice == size_slice)
    -            {
    -                // Copy host data to a temp host buffer with the shape of target.
    -                host_events =
    -                    dpct_memcpy(q, buf.get_ptr(), from_surface, to_range, from_range,
    -                                sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size,
    -                                host_to_host, dep_events);
    -            }
    -            else
    -            {
    -                // Copy host data to a temp host buffer with the shape of target.
    -                host_events = dpct_memcpy(
    -                    q, buf.get_ptr(), from_surface, to_range, from_range,
    -                    sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size, host_to_host,
    -                    // If has padding data, not sure whether it is useless. So fill temp
    -                    // buffer with it.
    -                    std::vector{
    -                        dpct_memcpy(q, buf.get_ptr(), to_surface, buf.get_size(),
    -                                    device_to_host, dep_events)});
    -            }
    -            // Copy from temp host buffer to device with only one submit.
    -            event_list.push_back(dpct_memcpy(q, to_surface, buf.get_ptr(),
    -                                             buf.get_size(), host_to_device,
    -                                             host_events));
    -            break;
    -        }
    -        case device_to_host:
    -        {
    -            host_buffer buf(get_copy_range(size, from_slice, from_range.get(0)), q,
    -                            event_list);
    -            // Copy from host temp buffer to host target with reshaping.
    -            event_list = dpct_memcpy(
    -                q, to_surface, buf.get_ptr(), to_range, from_range, sycl::id<3>(0, 0, 0),
    -                sycl::id<3>(0, 0, 0), size, host_to_host,
    -                // Copy from device to temp host buffer with only one submit.
    -                std::vector{dpct_memcpy(q, buf.get_ptr(), from_surface,
    -                                                     buf.get_size(),
    -                                                     device_to_host, dep_events)});
    -            break;
    -        }
    -        case device_to_device:
    -            event_list.push_back(q.submit([&](sycl::handler &cgh)
    -                                          {
    -        cgh.depends_on(dep_events);
    -        cgh.parallel_for(
    -            size,
    -            [=](sycl::id<3> id) {
    -                to_surface[get_offset(id, to_slice, to_range.get(0))] =
    -                    from_surface[get_offset(id, from_slice, from_range.get(0))];
    -            }); }));
    -        break;
    -        default:
    -            throw std::runtime_error("dpct_memcpy: invalid direction value");
    -        }
    -        return event_list;
    -    }
    -
    -    /// memcpy 2D/3D matrix specified by pitched_data.
    -    static inline std::vector
    -    dpct_memcpy(sycl::queue &q, pitched_data to, sycl::id<3> to_id,
    -                pitched_data from, sycl::id<3> from_id, sycl::range<3> size,
    -                memcpy_direction direction = automatic)
    -    {
    -        return dpct_memcpy(q, to.get_data_ptr(), from.get_data_ptr(),
    -                           sycl::range<3>(to.get_pitch(), to.get_y(), 1),
    -                           sycl::range<3>(from.get_pitch(), from.get_y(), 1), to_id, from_id,
    -                           size, direction);
    -    }
    -
    -    /// memcpy 2D matrix with pitch.
    -    static inline std::vector
    -    dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    -                size_t to_pitch, size_t from_pitch, size_t x, size_t y,
    -                memcpy_direction direction = automatic)
    -    {
    -        return dpct_memcpy(q, to_ptr, from_ptr, sycl::range<3>(to_pitch, y, 1),
    -                           sycl::range<3>(from_pitch, y, 1),
    -                           sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0),
    -                           sycl::range<3>(x, y, 1), direction);
    -    }
    -
    -    inline void gemm(sycl::queue &q, oneapi::mkl::transpose a_trans,
    -                     oneapi::mkl::transpose b_trans, int m, int n, int k,
    -                     const void *alpha, const void *a, library_data_t a_type,
    -                     int lda, const void *b, library_data_t b_type, int ldb,
    -                     const void *beta, void *c, library_data_t c_type, int ldc,
    -                     library_data_t scaling_type)
    -    {
    -        if (scaling_type == library_data_t::real_float &&
    -            c_type == library_data_t::complex_float)
    -        {
    -            scaling_type = library_data_t::complex_float;
    -        }
    -        else if (scaling_type == library_data_t::real_double &&
    -                 c_type == library_data_t::complex_double)
    -        {
    -            scaling_type = library_data_t::complex_double;
    -        }
    -
    -        std::uint64_t key =
    -            detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
    -        switch (key)
    -        {
    -        case detail::get_type_combination_id(
    -            library_data_t::real_float, library_data_t::real_float,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_double, library_data_t::real_double,
    -            library_data_t::real_double, library_data_t::real_double):
    -        {
    -            detail::gemm_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::complex_float, library_data_t::complex_float,
    -            library_data_t::complex_float, library_data_t::complex_float):
    -        {
    -            detail::gemm_impl, std::complex,
    -                              std::complex, std::complex>(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::complex_double, library_data_t::complex_double,
    -            library_data_t::complex_double, library_data_t::complex_double):
    -        {
    -            detail::gemm_impl, std::complex,
    -                              std::complex, std::complex>(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_half, library_data_t::real_half):
    -        {
    -            detail::gemm_impl(q, a_trans, b_trans, m, n, k, alpha, a,
    -                                          lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -#ifdef __INTEL_MKL__
    -        case detail::get_type_combination_id(
    -            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_impl(q, a_trans, b_trans, m, n, k, alpha, a, lda, b,
    -                                     ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_half, library_data_t::real_float):
    -        {
    -            float alpha_value =
    -                dpct::get_value(reinterpret_cast(alpha), q);
    -            float beta_value =
    -                dpct::get_value(reinterpret_cast(beta), q);
    -            sycl::half alpha_half(alpha_value);
    -            sycl::half beta_half(beta_value);
    -            detail::gemm_impl(q, a_trans, b_trans, m, n, k, &alpha_half,
    -                                          a, lda, b, ldb, &beta_half, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_int8, library_data_t::real_int8,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    -            library_data_t::real_bfloat16, library_data_t::real_float):
    -        {
    -            detail::gemm_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_int8, library_data_t::real_int8,
    -            library_data_t::real_int32, library_data_t::real_int32):
    -        {
    -            float alpha_float =
    -                dpct::get_value(reinterpret_cast(alpha), q);
    -            float beta_float =
    -                dpct::get_value(reinterpret_cast(beta), q);
    -            detail::gemm_impl(
    -                q, a_trans, b_trans, m, n, k, &alpha_float, a, lda, b, ldb, &beta_float, c, ldc);
    -            break;
    -        }
    -#endif // __INTEL_MKL__
    -        default:
    -            throw std::runtime_error("the combination of data type is unsupported");
    -        }
    -    } // gemm()
    -
    -    /// Computes a batch of matrix-matrix product with general matrices.
    -    /// \param [in] q The queue where the routine should be executed.
    -    /// \param [in] a_trans Specifies the operation applied to A.
    -    /// \param [in] b_trans Specifies the operation applied to B.
    -    /// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C.
    -    /// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C.
    -    /// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B).
    -    /// \param [in] alpha Scaling factor for the matrix-matrix product.
    -    /// \param [in] a Input matrix A.
    -    /// \param [in] a_type Data type of the matrix A.
    -    /// \param [in] lda Leading dimension of A.
    -    /// \param [in] b Input matrix B.
    -    /// \param [in] b_type Data type of the matrix B.
    -    /// \param [in] ldb Leading dimension of B.
    -    /// \param [in] beta Scaling factor for matrix C.
    -    /// \param [in, out] c Input/Output matrix C.
    -    /// \param [in] c_type Data type of the matrix C.
    -    /// \param [in] ldc Leading dimension of C.
    -    /// \param [in] batch_size Specifies the number of matrix multiply operations to perform.
    -    /// \param [in] scaling_type Data type of the scaling factors.
    -    inline void gemm_batch(sycl::queue &q, oneapi::mkl::transpose a_trans,
    -                           oneapi::mkl::transpose b_trans, int m, int n, int k,
    -                           const void *alpha, const void *a[],
    -                           library_data_t a_type, int lda, const void *b[],
    -                           library_data_t b_type, int ldb, const void *beta,
    -                           void *c[], library_data_t c_type, int ldc,
    -                           int batch_size, library_data_t scaling_type)
    -    {
    -        if (scaling_type == library_data_t::real_float &&
    -            c_type == library_data_t::complex_float)
    -        {
    -            scaling_type = library_data_t::complex_float;
    -        }
    -        else if (scaling_type == library_data_t::real_double &&
    -                 c_type == library_data_t::complex_double)
    -        {
    -            scaling_type = library_data_t::complex_double;
    -        }
    -
    -        std::uint64_t key =
    -            detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
    -        switch (key)
    -        {
    -        case detail::get_type_combination_id(
    -            library_data_t::real_float, library_data_t::real_float,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_double, library_data_t::real_double,
    -            library_data_t::real_double, library_data_t::real_double):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::complex_float, library_data_t::complex_float,
    -            library_data_t::complex_float, library_data_t::complex_float):
    -        {
    -            detail::gemm_batch_impl, std::complex,
    -                                    std::complex, std::complex>(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::complex_double, library_data_t::complex_double,
    -            library_data_t::complex_double, library_data_t::complex_double):
    -        {
    -            detail::gemm_batch_impl, std::complex,
    -                                    std::complex, std::complex>(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_half, library_data_t::real_half):
    -        {
    -            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha,
    -                                                a, lda, b, ldb, beta, c, ldc,
    -                                                batch_size);
    -            break;
    -        }
    -#ifdef __INTEL_MKL__
    -        case detail::get_type_combination_id(
    -            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    -            library_data_t::real_bfloat16, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha, a, lda,
    -                                           b, ldb, beta, c, ldc, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_int8, library_data_t::real_int8,
    -            library_data_t::real_int32, library_data_t::real_int32):
    -        {
    -            float alpha_float =
    -                dpct::get_value(reinterpret_cast(alpha), q);
    -            float beta_float =
    -                dpct::get_value(reinterpret_cast(beta), q);
    -            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, &alpha_float,
    -                                           a, lda, b, ldb, &beta_float, c, ldc,
    -                                           batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_int8, library_data_t::real_int8,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -#endif
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_half, library_data_t::real_float):
    -        {
    -            float alpha_value =
    -                dpct::get_value(reinterpret_cast(alpha), q);
    -            float beta_value =
    -                dpct::get_value(reinterpret_cast(beta), q);
    -            sycl::half alpha_half(alpha_value);
    -            sycl::half beta_half(beta_value);
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, &alpha_half, a, lda, b, ldb, &beta_half, c, ldc,
    -                batch_size);
    -            break;
    -        }
    -        default:
    -            throw std::runtime_error("the combination of data type is unsupported");
    -        }
    -    }
    -
    -    /// Computes a batch of matrix-matrix product with general matrices.
    -    /// \param [in] q The queue where the routine should be executed.
    -    /// \param [in] a_trans Specifies the operation applied to A.
    -    /// \param [in] b_trans Specifies the operation applied to B.
    -    /// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C.
    -    /// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C.
    -    /// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B).
    -    /// \param [in] alpha Scaling factor for the matrix-matrix product.
    -    /// \param [in] a Input matrix A.
    -    /// \param [in] a_type Data type of the matrix A.
    -    /// \param [in] lda Leading dimension of A.
    -    /// \param [in] stride_a Stride between the different A matrices.
    -    /// \param [in] b Input matrix B.
    -    /// \param [in] b_type Data type of the matrix B.
    -    /// \param [in] ldb Leading dimension of B.
    -    /// \param [in] stride_b Stride between the different B matrices.
    -    /// \param [in] beta Scaling factor for matrix C.
    -    /// \param [in, out] c Input/Output matrix C.
    -    /// \param [in] c_type Data type of the matrix C.
    -    /// \param [in] ldc Leading dimension of C.
    -    /// \param [in] stride_c Stride between the different C matrices.
    -    /// \param [in] batch_size Specifies the number of matrix multiply operations to perform.
    -    /// \param [in] scaling_type Data type of the scaling factors.
    -    inline void gemm_batch(sycl::queue &q, oneapi::mkl::transpose a_trans,
    -                           oneapi::mkl::transpose b_trans, int m, int n, int k,
    -                           const void *alpha, const void *a, library_data_t a_type,
    -                           int lda, long long int stride_a, const void *b,
    -                           library_data_t b_type, int ldb, long long int stride_b,
    -                           const void *beta, void *c, library_data_t c_type,
    -                           int ldc, long long int stride_c, int batch_size,
    -                           library_data_t scaling_type)
    -    {
    -        if (scaling_type == library_data_t::real_float &&
    -            c_type == library_data_t::complex_float)
    -        {
    -            scaling_type = library_data_t::complex_float;
    -        }
    -        else if (scaling_type == library_data_t::real_double &&
    -                 c_type == library_data_t::complex_double)
    -        {
    -            scaling_type = library_data_t::complex_double;
    -        }
    -
    -        std::uint64_t key =
    -            detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
    -        switch (key)
    -        {
    -        case detail::get_type_combination_id(
    -            library_data_t::real_float, library_data_t::real_float,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    -                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_double, library_data_t::real_double,
    -            library_data_t::real_double, library_data_t::real_double):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    -                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::complex_float, library_data_t::complex_float,
    -            library_data_t::complex_float, library_data_t::complex_float):
    -        {
    -            detail::gemm_batch_impl, std::complex,
    -                                    std::complex, std::complex>(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    -                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::complex_double, library_data_t::complex_double,
    -            library_data_t::complex_double, library_data_t::complex_double):
    -        {
    -            detail::gemm_batch_impl, std::complex,
    -                                    std::complex, std::complex>(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    -                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_half, library_data_t::real_half):
    -        {
    -            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha,
    -                                                a, lda, stride_a, b, ldb, stride_b,
    -                                                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -#ifdef __INTEL_MKL__
    -        case detail::get_type_combination_id(
    -            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    -            library_data_t::real_bfloat16, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    -                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha, a, lda,
    -                                           stride_a, b, ldb, stride_b, beta, c, ldc,
    -                                           stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_int8, library_data_t::real_int8,
    -            library_data_t::real_int32, library_data_t::real_int32):
    -        {
    -            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha,
    -                                                  a, lda, stride_a, b, ldb, stride_b,
    -                                                  beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_int8, library_data_t::real_int8,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    -                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_float, library_data_t::real_float):
    -        {
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    -                beta, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -#endif
    -        case detail::get_type_combination_id(
    -            library_data_t::real_half, library_data_t::real_half,
    -            library_data_t::real_half, library_data_t::real_float):
    -        {
    -            float alpha_value =
    -                dpct::get_value(reinterpret_cast(alpha), q);
    -            float beta_value =
    -                dpct::get_value(reinterpret_cast(beta), q);
    -            sycl::half alpha_half(alpha_value);
    -            sycl::half beta_half(beta_value);
    -            detail::gemm_batch_impl(
    -                q, a_trans, b_trans, m, n, k, &alpha_half, a, lda, stride_a, b, ldb, stride_b,
    -                &beta_half, c, ldc, stride_c, batch_size);
    -            break;
    -        }
    -        default:
    -            throw std::runtime_error("the combination of data type is unsupported");
    -        }
    -    }
    -
    -    static inline void
    -    async_dpct_memcpy(void *to_ptr, size_t to_pitch, const void *from_ptr,
    -                      size_t from_pitch, size_t x, size_t y,
    -                      memcpy_direction direction = automatic,
    -                      sycl::queue &q = get_default_queue())
    -    {
    -        detail::dpct_memcpy(q, to_ptr, from_ptr, to_pitch, from_pitch, x, y,
    -                            direction);
    -    }
    -
    -    using err0 = detail::generic_error_type;
    -    using err1 = detail::generic_error_type;
    -
    -    static inline void dpct_free(void *ptr, sycl::queue &q = get_default_queue()) {
    -        detail::dpct_free(ptr, q);
    -    }
    -
    -    /// dpct accessor used as device function parameter.
    -    template  class accessor;
    -    template  class accessor {
    -    public:
    -        using memory_t = detail::memory_traits;
    -        using element_t = typename memory_t::element_t;
    -        using pointer_t = typename memory_t::pointer_t;
    -        using accessor_t = typename memory_t::template accessor_t<3>;
    -        accessor(pointer_t data, const sycl::range<3> &in_range)
    -            : _data(data), _range(in_range) {}
    -        template 
    -        accessor(typename std::enable_if::type &acc)
    -            : accessor(acc, acc.get_range()) {}
    -        accessor(const accessor_t &acc, const sycl::range<3> &in_range)
    -            : accessor(acc.get_pointer(), in_range) {}
    -        accessor operator[](size_t index) const {
    -            sycl::range<2> sub(_range.get(1), _range.get(2));
    -            return accessor(_data + index * sub.size(), sub);
    -        }
    -
    -        pointer_t get_ptr() const { return _data; }
    -
    -    private:
    -        pointer_t _data;
    -        sycl::range<3> _range;
    -    };
    -    template  class accessor {
    -    public:
    -        using memory_t = detail::memory_traits;
    -        using element_t = typename memory_t::element_t;
    -        using pointer_t = typename memory_t::pointer_t;
    -        using accessor_t = typename memory_t::template accessor_t<2>;
    -        accessor(pointer_t data, const sycl::range<2> &in_range)
    -            : _data(data), _range(in_range) {}
    -        template 
    -        accessor(typename std::enable_if::type &acc)
    -            : accessor(acc, acc.get_range()) {}
    -        accessor(const accessor_t &acc, const sycl::range<2> &in_range)
    -            : accessor(acc.get_pointer(), in_range) {}
    -
    -        pointer_t operator[](size_t index) const {
    -            return _data + _range.get(1) * index;
    -        }
    -
    -        pointer_t get_ptr() const { return _data; }
    -
    -    private:
    -        pointer_t _data;
    -        sycl::range<2> _range;
    -    };
    -
    -    namespace detail {
    -        /// Device variable with address space of shared, global or constant.
    -        template  class device_memory {
    -        public:
    -            using accessor_t =
    -                typename detail::memory_traits::template accessor_t;
    -            using value_t = typename detail::memory_traits::value_t;
    -            using dpct_accessor_t = dpct::accessor;
    -
    -            device_memory() : device_memory(sycl::range(1)) {}
    -
    -            /// Constructor of 1-D array with initializer list
    -            device_memory(const sycl::range &in_range,
    -                        std::initializer_list &&init_list)
    -                : device_memory(in_range) {
    -                assert(init_list.size() <= in_range.size());
    -                _host_ptr = (value_t *)std::malloc(_size);
    -                std::memset(_host_ptr, 0, _size);
    -                std::memcpy(_host_ptr, init_list.begin(), init_list.size() * sizeof(T));
    -            }
    -
    -            /// Constructor of 2-D array with initializer list
    -            template 
    -            device_memory(
    -                const typename std::enable_if>::type &in_range,
    -                std::initializer_list> &&init_list)
    -                : device_memory(in_range) {
    -                assert(init_list.size() <= in_range[0]);
    -                _host_ptr = (value_t *)std::malloc(_size);
    -                std::memset(_host_ptr, 0, _size);
    -                auto tmp_data = _host_ptr;
    -                for (auto sub_list : init_list) {
    -                    assert(sub_list.size() <= in_range[1]);
    -                    std::memcpy(tmp_data, sub_list.begin(),
    -                                sub_list.size() * sizeof(T));
    -                    tmp_data += in_range[1];
    -                }
    -            }
    -
    -            /// Constructor with range
    -            device_memory(const sycl::range &range_in)
    -                : _size(range_in.size() * sizeof(T)), _range(range_in),
    -                _reference(false), _host_ptr(nullptr), _device_ptr(nullptr) {
    -                static_assert(
    -                    (Memory == global) || (Memory == constant) || (Memory == shared),
    -                    "device memory region should be global, constant or shared");
    -                // Make sure that singleton class mem_mgr and dev_mgr will destruct
    -                // later than this.
    -                detail::mem_mgr::instance();
    -                dev_mgr::instance();
    -            }
    -
    -            /// Constructor with range
    -            template 
    -            device_memory(Args... Arguments)
    -                : device_memory(sycl::range(Arguments...)) {}
    -
    -            ~device_memory() {
    -                if (_device_ptr && !_reference)
    -                    dpct::dpct_free(_device_ptr);
    -                if (_host_ptr)
    -                    std::free(_host_ptr);
    -            }
    -
    -            /// Allocate memory with default queue, and init memory if has initial
    -            /// value.
    -            void init() { init(dpct::get_default_queue()); }
    -            /// Allocate memory with specified queue, and init memory if has initial
    -            /// value.
    -            void init(sycl::queue &q) {
    -                if (_device_ptr)
    -                    return;
    -                if (!_size)
    -                    return;
    -                allocate_device(q);
    -                if (_host_ptr)
    -                    detail::dpct_memcpy(q, _device_ptr, _host_ptr, _size,
    -                                        host_to_device);
    -            }
    -
    -            /// The variable is assigned to a device pointer.
    -            void assign(value_t *src, size_t size) {
    -                this->~device_memory();
    -                new (this) device_memory(src, size);
    -            }
    -
    -            /// Get memory pointer of the memory object, which is virtual pointer when
    -            /// usm is not used, and device pointer when usm is used.
    -            value_t *get_ptr() { return get_ptr(get_default_queue()); }
    -            /// Get memory pointer of the memory object, which is virtual pointer when
    -            /// usm is not used, and device pointer when usm is used.
    -            value_t *get_ptr(sycl::queue &q) {
    -                init(q);
    -                return _device_ptr;
    -            }
    -
    -            /// Get the device memory object size in bytes.
    -            size_t get_size() { return _size; }
    -
    -            template 
    -            typename std::enable_if::type &operator[](size_t index) {
    -                init();
    -                return _device_ptr[index];
    -            }
    -
    -            /// Get dpct::accessor with dimension info for the device memory object
    -            /// when usm is used and dimension is greater than 1.
    -            template 
    -            typename std::enable_if::type
    -            get_access(sycl::handler &cgh) {
    -                return dpct_accessor_t((T *)_device_ptr, _range);
    -            }
    -
    -        private:
    -            device_memory(value_t *memory_ptr, size_t size)
    -                : _size(size), _range(size / sizeof(T)), _reference(true),
    -                _device_ptr(memory_ptr) {}
    -
    -            void allocate_device(sycl::queue &q) {
    -        #ifndef DPCT_USM_LEVEL_NONE
    -                if (Memory == shared) {
    -                    _device_ptr = (value_t *)sycl::malloc_shared(_size, q.get_device(),
    -                                                                q.get_context());
    -                    return;
    -                }
    -        #ifdef SYCL_EXT_ONEAPI_USM_DEVICE_READ_ONLY
    -                if (Memory == constant) {
    -                    _device_ptr = (value_t *)sycl::malloc_device(
    -                        _size, q.get_device(), q.get_context(),
    -                        sycl::ext::oneapi::property::usm::device_read_only());
    -                    return;
    -                }
    -        #endif
    -        #endif
    -                _device_ptr = (value_t *)detail::dpct_malloc(_size, q);
    -            }
    -
    -            size_t _size;
    -            sycl::range _range;
    -            bool _reference;
    -            value_t *_host_ptr;
    -            value_t *_device_ptr;
    -        };
    -        template 
    -        class device_memory : public device_memory {
    -        public:
    -            using base = device_memory;
    -            using value_t = typename base::value_t;
    -            using accessor_t =
    -                typename detail::memory_traits::template accessor_t<0>;
    -
    -            /// Constructor with initial value.
    -            device_memory(const value_t &val) : base(sycl::range<1>(1), {val}) {}
    -
    -            /// Default constructor
    -            device_memory() : base(1) {}
    -        };
    -        } // namespace detail
    -
    -    template 
    -    using global_memory = detail::device_memory;
    -    template 
    -    using constant_memory = detail::device_memory;
    -    template 
    -    using shared_memory = detail::device_memory;
    -
    -
    -    template 
    -    inline T atomic_fetch_add(T *addr, T operand) {
    -    auto atm =
    -        sycl::atomic_ref(addr[0]);
    -    return atm.fetch_add(operand);
    -    }
    -
    -    template 
    -    inline T1 atomic_fetch_add(T1 *addr, T2 operand) {
    -    auto atm =
    -        sycl::atomic_ref(addr[0]);
    -    return atm.fetch_add(operand);
    -    }
    -
    -    template 
    -    inline T atomic_fetch_add(T *addr, T operand,
    -                            sycl::memory_order memoryOrder) {
    -    switch (memoryOrder) {
    -        case sycl::memory_order::relaxed:
    -            return atomic_fetch_add(addr, operand);
    -        case sycl::memory_order::acq_rel:
    -            return atomic_fetch_add(addr, operand);
    -        case sycl::memory_order::seq_cst:
    -            return atomic_fetch_add(addr, operand);
    -        default:
    -            assert(false && "Invalid memory_order for atomics. Valid memory_order for "
    -                            "atomics are: sycl::memory_order::relaxed, "
    -                            "sycl::memory_order::acq_rel, sycl::memory_order::seq_cst!");
    -        }
    -    }
    -
    -    template 
    -    inline T1 atomic_fetch_add(T1 *addr, T2 operand,
    -                            sycl::memory_order memoryOrder) {
    -    atomic_fetch_add(addr, operand, memoryOrder);
    -    }
    -
    -} // COPY from DPCT head files
    -
    -#define GGML_COMMON_DECL_SYCL
    -#define GGML_COMMON_IMPL_SYCL
    -#include "ggml-common.h"
    -
    -static int g_ggml_sycl_debug=0;
    -#define GGML_SYCL_DEBUG(...) do{if(g_ggml_sycl_debug) fprintf(stderr, __VA_ARGS__);}while(0)
    -
    -#define CHECK_TRY_ERROR(expr)                                                  \
    -  [&]() {                                                                      \
    -    try {                                                                      \
    -      expr;                                                                    \
    -      return dpct::success;                                                    \
    -    } catch (std::exception const &e) {                                        \
    -      std::cerr << e.what()<< "\nException caught at file:" << __FILE__        \
    -        << ", line:" << __LINE__ <<", func:"<<__func__<< std::endl;            \
    -      return dpct::default_error;                                              \
    -    }                                                                          \
    -  }()
    -
    -// #define DEBUG_SYCL_MALLOC
    -
    -static int g_work_group_size = 0;
    -// typedef sycl::half ggml_fp16_t;
    -
    -#define __SYCL_ARCH__ DPCT_COMPATIBILITY_TEMP
    -#define VER_4VEC   130          //todo for hardward optimize.
    -#define VER_GEN9      700       //todo for hardward optimize.
    -#define VER_GEN12 1000000       //todo for hardward optimize.
    -#define VER_GEN13      (VER_GEN12 + 1030)   //todo for hardward optimize.
    -
    -#define GGML_SYCL_MAX_NODES 8192 //TODO: adapt to hardwares
    -
    -#if !defined(GGML_SYCL_FORCE_MMQ)
    -    #define SYCL_USE_XMX
    -#endif
    -
    -// max batch size to use MMQ kernels when tensor cores are available
    -#define MMQ_MAX_BATCH_SIZE 32
    -
    -
    -#if defined(_MSC_VER)
    -#pragma warning(disable: 4244 4267) // possible loss of data
    -#endif
    -
    -// dmmv = dequantize_mul_mat_vec
    -#ifndef GGML_SYCL_DMMV_X
    -#define GGML_SYCL_DMMV_X 32
    -#endif
    -#ifndef GGML_SYCL_MMV_Y
    -#define GGML_SYCL_MMV_Y 1
    -#endif
    -
    -enum ggml_sycl_backend_gpu_mode {
    -    SYCL_UNSET_GPU_MODE = -1,
    -    SYCL_SINGLE_GPU_MODE = 0,
    -    SYCL_MUL_GPU_MODE
    -};
    -
    -static_assert(sizeof(sycl::half) == sizeof(ggml_fp16_t), "wrong fp16 size");
    -
    -static void crash(){
    -    int *ptr = NULL;
    -    *ptr = 0;
    -}
    -
    -static void ggml_sycl_error(const char * stmt, const char * func, const char * file, const int line, const char * msg) {
    -    fprintf(stderr, "SYCL error: %s: %s\n", stmt, msg);
    -    fprintf(stderr, "  in function %s at %s:%d\n", func, file, line);
    -    GGML_ASSERT(!"SYCL error");
    -}
    -
    -#define SYCL_CHECK(err) do {                                                   \
    -    auto err_ = (err); if (err_ != 0) ggml_sycl_error(                         \
    -        #err, __func__, __FILE__, __LINE__,                                    \
    -        "Meet error in this line code!");   \
    -} while (0)
    -
    -#if DPCT_COMPAT_RT_VERSION >= 11100
    -#define GGML_SYCL_ASSUME(x) __builtin_assume(x)
    -#else
    -#define GGML_SYCL_ASSUME(x)
    -#endif // DPCT_COMPAT_RT_VERSION >= 11100
    -
    -#ifdef GGML_SYCL_F16
    -typedef sycl::half dfloat; // dequantize float
    -typedef sycl::half2 dfloat2;
    -#else
    -typedef float dfloat; // dequantize float
    -typedef sycl::float2 dfloat2;
    -#endif //GGML_SYCL_F16
    -
    -#define MMVQ_MAX_BATCH_SIZE  8
    -
    -static const int8_t kvalues_iq4nl[16]={-127, -104, -83, -65, -49, -35, -22, -10, 1, 13, 25, 38, 53, 69, 89, 113};
    -
     bool   ggml_sycl_loaded(void);
    -void * ggml_sycl_host_malloc(size_t size);
    -void   ggml_sycl_host_free(void * ptr);
    -bool   ggml_sycl_can_mul_mat(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst);
     void   ggml_sycl_free_data(struct ggml_tensor * tensor);
     void   ggml_sycl_assign_buffers(struct ggml_tensor * tensor);
     void   ggml_sycl_assign_buffers_no_scratch(struct ggml_tensor * tensor);
    @@ -3109,10 +98,7 @@ void   ggml_sycl_free_scratch(void);
     void   ggml_sycl_get_device_description(int device, char * description, size_t description_size);
     bool   ggml_backend_is_sycl(ggml_backend_t backend);
     int    ggml_backend_sycl_get_device(ggml_backend_t backend);
    -int    get_main_device();
     static bool ggml_backend_buffer_is_sycl_split(ggml_backend_buffer_t buffer);
    -void   print_ggml_tensor(const char*name, struct ggml_tensor *src);
    -void   log_tensor_with_cnt(const char* name, struct ggml_tensor * src, int stop_cnt);
     
     void dev2dev_memcpy(sycl::queue &q_dst, sycl::queue &q_src, void *ptr_dst,
                         const void *ptr_src, size_t size) {
    @@ -3155,25 +141,26 @@ static __dpct_inline__ int get_int_from_uint8_aligned(const uint8_t *x8,
     
     template 
     using to_t_sycl_t = void (*)(const void *__restrict__ x, T *__restrict__ y,
    -                             int k, dpct::queue_ptr stream);
    +                             int k, queue_ptr stream);
     typedef to_t_sycl_t to_fp32_sycl_t;
     typedef to_t_sycl_t to_fp16_sycl_t;
     
     typedef void (*dequantize_kernel_t)(const void * vx, const int ib, const int iqs, dfloat2 & v);
     typedef void (*dot_kernel_k_t)(const void * __restrict__ vx, const int ib, const int iqs, const float * __restrict__ y, float & v);
     typedef void (*cpy_kernel_t)(const char * cx, char * cdst);
    -typedef void (*ggml_sycl_func_t)(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst);
    +typedef void (*ggml_sycl_func_t)(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst);
     typedef void (*ggml_sycl_op_mul_mat_t)(
    +    ggml_backend_sycl_context & ctx,
         const ggml_tensor *src0, const ggml_tensor *src1, ggml_tensor *dst,
         const char *src0_dd_i, const float *src1_ddf_i, const char *src1_ddq_i,
         float *dst_dd_i, const int64_t row_low, const int64_t row_high,
         const int64_t src1_ncols, const int64_t src1_padded_row_size,
    -    const dpct::queue_ptr &stream);
    -typedef void (*ggml_sycl_op_flatten_t)(const ggml_tensor *src0,
    +    const queue_ptr &stream);
    +typedef void (*ggml_sycl_op_flatten_t)(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                            const ggml_tensor *src1,
                                            ggml_tensor *dst, const float *src0_dd,
                                            const float *src1_dd, float *dst_dd,
    -                                       const dpct::queue_ptr &main_stream);
    +                                       const queue_ptr &main_stream);
     
     typedef float (*vec_dot_q_sycl_t)(const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & iqs);
     typedef void (*allocate_tiles_sycl_t)(int **x_ql, sycl::half2 **x_dm,
    @@ -3191,387 +178,6 @@ typedef float (*vec_dot_q_mul_mat_sycl_t)(
         const int *__restrict__ y_qs, const sycl::half2 *__restrict__ y_ms,
         const int &i, const int &j, const int &k);
     
    -#define WARP_SIZE 32
    -#define MATRIX_ROW_PADDING 512 // last row of quant. matrices is a multiple of this to avoid out-of-bounds memory accesses
    -
    -#define SYCL_GELU_BLOCK_SIZE 256
    -#define SYCL_SILU_BLOCK_SIZE 256
    -#define SYCL_TANH_BLOCK_SIZE 256
    -#define SYCL_RELU_BLOCK_SIZE 256
    -#define SYCL_HARDSIGMOID_BLOCK_SIZE 256
    -#define SYCL_HARDSWISH_BLOCK_SIZE 256
    -#define SYCL_SQR_BLOCK_SIZE 256
    -#define SYCL_CPY_BLOCK_SIZE 32
    -#define SYCL_SCALE_BLOCK_SIZE 256
    -#define SYCL_CLAMP_BLOCK_SIZE 256
    -#define SYCL_ROPE_BLOCK_SIZE 256
    -#define SYCL_DIAG_MASK_INF_BLOCK_SIZE 32
    -#define SYCL_QUANTIZE_BLOCK_SIZE 256
    -#define SYCL_DEQUANTIZE_BLOCK_SIZE 256
    -#define SYCL_GET_ROWS_BLOCK_SIZE 256
    -#define SYCL_UPSCALE_BLOCK_SIZE 256
    -#define SYCL_CONCAT_BLOCK_SIZE 256
    -#define SYCL_PAD_BLOCK_SIZE 256
    -#define SYCL_ACC_BLOCK_SIZE 256
    -#define SYCL_IM2COL_BLOCK_SIZE 256
    -#define SYCL_POOL2D_BLOCK_SIZE 256
    -
    -// dmmv = dequantize_mul_mat_vec
    -#ifndef GGML_SYCL_DMMV_X
    -#define GGML_SYCL_DMMV_X 32
    -#endif
    -#ifndef GGML_SYCL_MMV_Y
    -#define GGML_SYCL_MMV_Y 1
    -#endif
    -
    -#ifndef K_QUANTS_PER_ITERATION
    -#define K_QUANTS_PER_ITERATION 2
    -#else
    -static_assert(K_QUANTS_PER_ITERATION == 1 || K_QUANTS_PER_ITERATION == 2, "K_QUANTS_PER_ITERATION must be 1 or 2");
    -#endif
    -
    -#ifndef GGML_SYCL_PEER_MAX_BATCH_SIZE
    -#define GGML_SYCL_PEER_MAX_BATCH_SIZE 128
    -#endif // GGML_SYCL_PEER_MAX_BATCH_SIZE
    -
    -#define MUL_MAT_SRC1_COL_STRIDE 128
    -
    -#define MAX_STREAMS 8
    -static dpct::queue_ptr g_syclStreams[GGML_SYCL_MAX_DEVICES][MAX_STREAMS] = {{0}};
    -
    -struct ggml_tensor_extra_gpu {
    -    void * data_device[GGML_SYCL_MAX_DEVICES]; // 1 pointer for each device for split tensors
    -    dpct::event_ptr
    -        events[GGML_SYCL_MAX_DEVICES]
    -              [MAX_STREAMS]; // events for synchronizing multiple GPUs
    -};
    -
    -class sycl_gpu_mgr {
    -    public:
    -        std::vector gpus;
    -        std::vector devices;
    -        sycl::queue *first_queue;
    -        sycl::context co_ctx;
    -        int max_compute_units = 0;
    -        int work_group_size = 0;
    -        std::string gpus_list = "";
    -
    -        /*
    -        Use all GPUs with same top max compute units
    -        */
    -        sycl_gpu_mgr() {
    -            detect_sycl_gpu_list_with_max_cu();
    -            get_allow_gpus();
    -            create_context_with_gpus();
    -        }
    -
    -        /*
    -        Only use the assigned GPU
    -        */
    -        sycl_gpu_mgr(int main_gpu_id) {
    -            sycl::device device = dpct::dev_mgr::instance().get_device(main_gpu_id);
    -            dpct::device_info prop;
    -            dpct::get_device_info(prop, device);
    -            gpus.push_back(main_gpu_id);
    -            devices.push_back(device);
    -            work_group_size = prop.get_max_work_group_size();
    -            max_compute_units = prop.get_max_compute_units();
    -
    -            get_allow_gpus();
    -            create_context_with_gpus();
    -        }
    -
    -        void create_context_with_gpus() {
    -            sycl::context ctx = sycl::context(devices);
    -            assert(gpus.size() > 0);
    -            first_queue = dpct::get_current_device().create_queue(ctx, devices[0]);
    -            co_ctx = first_queue->get_context();
    -        }
    -
    -        sycl::context &get_co_ctx() { return co_ctx; }
    -
    -        void get_allow_gpus() {
    -            gpus_list = "";
    -            for (size_t i = 0; i < gpus.size(); ++i) {
    -                gpus_list += std::to_string(gpus[i]);
    -                gpus_list += ",";
    -            }
    -            if (gpus_list.length() > 1) {
    -                gpus_list.pop_back();
    -            }
    -        }
    -
    -        bool is_allowed_gpu(int device_id) {
    -            return std::find(gpus.begin(), gpus.end(), device_id) != gpus.end();
    -        }
    -
    -        void detect_sycl_gpu_list_with_max_cu() try {
    -            int device_count = dpct::dev_mgr::instance().device_count();
    -
    -            for (int id = 0; id < device_count; id++) {
    -                sycl::device device = dpct::dev_mgr::instance().get_device(id);
    -                if (!device.is_gpu())
    -                    continue;
    -                dpct::device_info prop;
    -                dpct::get_device_info(prop, device);
    -                if (max_compute_units < prop.get_max_compute_units())
    -                    max_compute_units = prop.get_max_compute_units();
    -            }
    -
    -            for (int id = 0; id < device_count; id++) {
    -                sycl::device device = dpct::dev_mgr::instance().get_device(id);
    -                if (!device.is_gpu())
    -                    continue;
    -                dpct::device_info prop;
    -                dpct::get_device_info(prop, device);
    -                if (max_compute_units == prop.get_max_compute_units() &&
    -                    is_ext_oneapi_device(device)) {
    -                    gpus.push_back(id);
    -                    devices.push_back(device);
    -                    work_group_size = prop.get_max_work_group_size();
    -                }
    -            }
    -            return;
    -        } catch (sycl::exception const &exc) {
    -            std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -                    << ", line:" << __LINE__ << std::endl;
    -            std::exit(1);
    -        }
    -
    -        int get_gpu_count() { return (int)gpus.size(); }
    -
    -        int get_index(int id) {
    -            for (int i = 0; i < (int)gpus.size(); i++) {
    -                if (gpus[i] == id)
    -                    return i;
    -            }
    -            printf("miss to get device index by id=%d\n", id);
    -            GGML_ASSERT(false);
    -        }
    -
    -        int get_next_index(int id) {
    -            int cur_index = get_index(id);
    -            for (int i = cur_index + 1; i < (int)gpus.size(); i++) {
    -                if (gpus[i] == id)
    -                    return i;
    -            }
    -            GGML_ASSERT(false);
    -        }
    -
    -        bool is_ext_oneapi_device(const sycl::device &dev) {
    -            sycl::backend dev_backend = dev.get_backend();
    -            if (dev_backend == sycl::backend::ext_oneapi_level_zero ||
    -                dev_backend == sycl::backend::ext_oneapi_cuda ||
    -                dev_backend == sycl::backend::ext_oneapi_hip)
    -                return true;
    -            return false;
    -        }
    -};
    -
    -static sycl_gpu_mgr *g_sycl_gpu_mgr = NULL;
    -static int g_device_count = -1;
    -static int g_all_sycl_device_count = -1;
    -static int g_main_device = -1;
    -static int g_main_device_id = -1;
    -static bool g_ggml_backend_sycl_buffer_type_initialized = false;
    -
    -static std::array g_default_tensor_split = {};
    -
    -static float g_tensor_split[GGML_SYCL_MAX_DEVICES] = {0};
    -
    -static ggml_sycl_backend_gpu_mode g_ggml_sycl_backend_gpu_mode = SYCL_UNSET_GPU_MODE;
    -
    -struct sycl_device_capabilities {
    -    int     cc;                 // compute capability
    -    bool    vmm;                // virtual memory support
    -    size_t  vmm_granularity;    // granularity of virtual memory
    -    int device_id;
    -};
    -
    -static sycl_device_capabilities g_device_caps[GGML_SYCL_MAX_DEVICES] = { {0, false, 0, -1} };
    -
    -struct sycl_device_id2index {
    -    int index;
    -};
    -
    -static void * g_scratch_buffer = nullptr;
    -static size_t g_scratch_size = 0; // disabled by default
    -static size_t g_scratch_offset = 0;
    -
    -static dpct::queue_ptr g_sycl_handles[GGML_SYCL_MAX_DEVICES] = {nullptr};
    -
    -int get_main_device(){
    -    return g_main_device;
    -}
    -
    -[[noreturn]]
    -static void bad_arch(const sycl::stream &stream_ct1) {
    -    stream_ct1 << "ERROR: ggml-sycl was compiled without support for the "
    -                  "current GPU architecture.\n";
    -    // __trap();
    -    std::exit(1);
    -
    -    (void) bad_arch; // suppress unused function warning
    -}
    -
    -/*
    -device_index: device index from 0 to n (continue numbers).
    -    It is used for device select/set in SYCL backend internal data structure.
    -*/
    -void check_allow_gpu_index(const int device_index) {
    -    if (device_index >= g_device_count) {
    -        char error_buf[256];
    -        snprintf(error_buf, sizeof(error_buf),
    -                 "%s error: device_index:%d is out of range: [0-%d]", __func__,
    -                 device_index, g_device_count - 1);
    -        fprintf(stderr, "%s\n", error_buf);
    -        assert(false);
    -    }
    -}
    -
    -/*
    -device_id: device ID is shown by ggml_backend_sycl_print_sycl_devices().
    -    It is only used to set current working device.
    -*/
    -void check_allow_gpu_id(const int device_id) {
    -    if (!g_sycl_gpu_mgr->is_allowed_gpu(device_id)) {
    -        char error_buf[256];
    -        snprintf(error_buf, sizeof(error_buf),
    -                 "error: cannot set device=%d, which is not allowed. Please "
    -                 "set GPU ID in: [%s]",
    -                 device_id, g_sycl_gpu_mgr->gpus_list.c_str());
    -        fprintf(stderr, "%s\n", error_buf);
    -        throw std::invalid_argument(error_buf);
    -    }
    -}
    -
    -int get_current_device_id() {
    -    return dpct::dev_mgr::instance().current_device_id();
    -}
    -
    -inline dpct::err0 ggml_sycl_set_device(const int device) try {
    -
    -    int device_id = g_sycl_gpu_mgr->gpus[device];
    -    check_allow_gpu_id(device_id);
    -
    -    int current_device_id;
    -    SYCL_CHECK(CHECK_TRY_ERROR(current_device_id = get_current_device_id()));
    -
    -    // GGML_SYCL_DEBUG("ggml_sycl_set_device device_id=%d,
    -    // current_device_id=%d\n", device, current_device);
    -    if (device_id == current_device_id) {
    -        return 0;
    -    }
    -
    -    return CHECK_TRY_ERROR(dpct::select_device(device_id));
    -} catch (sycl::exception const &exc) {
    -    std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -              << ", line:" << __LINE__ << std::endl;
    -    crash();
    -    std::exit(1);
    -}
    -
    -void log_ggml_var_device(const char*name, float *src, size_t total_elements, bool src_on_device){
    -    if(!g_ggml_sycl_debug) return;
    -    if(!src){
    -        printf("GGML Tensor:%s skip to save for NULL pointer\n", name);
    -        return;
    -    }
    -    char filename[1024];
    -    sprintf(filename, "%s.txt", name);
    -    printf("GGML Tensor:%s save to %s\n", name, filename);
    -
    -    size_t total_size = total_elements*sizeof(float);
    -    float *local_buf = NULL;
    -    if(src_on_device) {
    -        local_buf = (float *) ggml_sycl_host_malloc(total_size);
    -        ggml_sycl_set_device(g_main_device);
    -        dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    -        main_stream->memcpy(local_buf, src, total_size).wait();
    -    }
    -    else {
    -        local_buf = (float *)src;
    -    }
    -
    -    std::ofstream logfile;
    -    logfile.open(filename);
    -    for(size_t i=0; imemcpy(local_buf, src, total_size).wait();
    -    }
    -    else {
    -        local_buf = (sycl::half *)src;
    -    }
    -
    -    std::ofstream logfile;
    -    logfile.open(filename);
    -    for(size_t i=0; ibackend == GGML_BACKEND_TYPE_GPU || src->backend == GGML_BACKEND_TYPE_GPU_SPLIT;
    -    float *src_data =NULL;
    -    if(src_on_device) {
    -        ggml_tensor_extra_gpu * src_extra = (ggml_tensor_extra_gpu *)  src->extra;
    -        src_data = (float*)src_extra->data_device[g_main_device];
    -    }
    -    else {
    -        src_data = (float *)src->data;
    -    }
    -
    -    log_ggml_var_device(name, src_data, total_elements, src_on_device);
    -}
    -
    -static int log_file_name_idx=0;
    -void log_tensor_with_cnt(const char* name, struct ggml_tensor * src, int stop_cnt) {
    -    stop_cnt = 4;
    -    if(log_file_name_idx>=stop_cnt) return;
    -    char filename[1280];
    -    sprintf(filename, "%s_%07d", name, log_file_name_idx);
    -    log_file_name_idx++;
    -    print_ggml_tensor(filename, src);
    -}
    -
     static __dpct_inline__ float warp_reduce_sum(float x,
                                                  const sycl::nd_item<3> &item_ct1) {
     #pragma unroll
    @@ -9256,10 +5862,10 @@ static  void pool2d_nchw_kernel(
     }
     
     template 
    -static void get_rows_sycl(const ggml_tensor *src0, const ggml_tensor *src1,
    +static void get_rows_sycl(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                               ggml_tensor *dst, const void *src0_dd,
                               const int32_t *src1_dd, float *dst_dd,
    -                          dpct::queue_ptr stream) {
    +                          queue_ptr stream) {
     
         GGML_TENSOR_BINARY_OP_LOCALS
     
    @@ -9291,10 +5897,10 @@ static void get_rows_sycl(const ggml_tensor *src0, const ggml_tensor *src1,
     }
     
     template 
    -static void get_rows_sycl_float(const ggml_tensor *src0,
    +static void get_rows_sycl_float(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                     const ggml_tensor *src1, ggml_tensor *dst,
                                     const src0_t *src0_dd, const int32_t *src1_dd,
    -                                float *dst_dd, dpct::queue_ptr stream) {
    +                                float *dst_dd, queue_ptr stream) {
     
         GGML_TENSOR_BINARY_OP_LOCALS
     
    @@ -9331,10 +5937,11 @@ static void get_rows_sycl_float(const ggml_tensor *src0,
     template
     struct bin_bcast_sycl {
         template 
    -    void operator()(const struct ggml_tensor *src0,
    +    void operator()(ggml_backend_sycl_context & ctx,
    +                    const struct ggml_tensor *src0,
                         const struct ggml_tensor *src1, struct ggml_tensor *dst,
                         const src0_t *src0_dd, const src1_t *src1_dd, dst_t *dst_dd,
    -                    dpct::queue_ptr stream) {
    +                    queue_ptr stream) {
     
             GGML_TENSOR_BINARY_OP_LOCALS
     
    @@ -9471,7 +6078,7 @@ struct bin_bcast_sycl {
     static void acc_f32_sycl(const float *x, const float *y, float *dst,
                              const int n_elements, const int ne10, const int ne11,
                              const int ne12, const int nb1, const int nb2,
    -                         const int offset, dpct::queue_ptr stream) {
    +                         const int offset, queue_ptr stream) {
         int num_blocks = (n_elements + SYCL_ACC_BLOCK_SIZE - 1) / SYCL_ACC_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9484,7 +6091,7 @@ static void acc_f32_sycl(const float *x, const float *y, float *dst,
     }
     
     static void gelu_f32_sycl(const float *x, float *dst, const int k,
    -                          dpct::queue_ptr stream) {
    +                          queue_ptr stream) {
         const int num_blocks = (k + SYCL_GELU_BLOCK_SIZE - 1) / SYCL_GELU_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9496,7 +6103,7 @@ static void gelu_f32_sycl(const float *x, float *dst, const int k,
     }
     
     static void silu_f32_sycl(const float *x, float *dst, const int k,
    -                          dpct::queue_ptr stream) {
    +                          queue_ptr stream) {
         const int num_blocks = (k + SYCL_SILU_BLOCK_SIZE - 1) / SYCL_SILU_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9508,7 +6115,7 @@ static void silu_f32_sycl(const float *x, float *dst, const int k,
     }
     
     static void gelu_quick_f32_sycl(const float *x, float *dst, const int k,
    -                                dpct::queue_ptr stream) {
    +                                queue_ptr stream) {
         const int num_blocks = (k + SYCL_GELU_BLOCK_SIZE - 1) / SYCL_GELU_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9520,7 +6127,7 @@ static void gelu_quick_f32_sycl(const float *x, float *dst, const int k,
     }
     
     static void tanh_f32_sycl(const float *x, float *dst, const int k,
    -                          dpct::queue_ptr stream) {
    +                          queue_ptr stream) {
         const int num_blocks = (k + SYCL_TANH_BLOCK_SIZE - 1) / SYCL_TANH_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9532,7 +6139,7 @@ static void tanh_f32_sycl(const float *x, float *dst, const int k,
     }
     
     static void relu_f32_sycl(const float *x, float *dst, const int k,
    -                          dpct::queue_ptr stream) {
    +                          queue_ptr stream) {
         const int num_blocks = (k + SYCL_RELU_BLOCK_SIZE - 1) / SYCL_RELU_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9544,7 +6151,7 @@ static void relu_f32_sycl(const float *x, float *dst, const int k,
     }
     
     static void hardsigmoid_f32_sycl(const float *x, float *dst, const int k,
    -                                 dpct::queue_ptr stream) {
    +                                 queue_ptr stream) {
         const int num_blocks = (k + SYCL_HARDSIGMOID_BLOCK_SIZE - 1) / SYCL_HARDSIGMOID_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9556,7 +6163,7 @@ static void hardsigmoid_f32_sycl(const float *x, float *dst, const int k,
     }
     
     static void hardswish_f32_sycl(const float *x, float *dst, const int k,
    -                               dpct::queue_ptr stream) {
    +                               queue_ptr stream) {
         const int num_blocks = (k + SYCL_HARDSWISH_BLOCK_SIZE - 1) / SYCL_HARDSWISH_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9569,7 +6176,7 @@ static void hardswish_f32_sycl(const float *x, float *dst, const int k,
     
     static void leaky_relu_f32_sycl(const float *x, float *dst, const int k,
                                     const float negative_slope,
    -                                dpct::queue_ptr stream) {
    +                                queue_ptr stream) {
         const int num_blocks = (k + SYCL_RELU_BLOCK_SIZE - 1) / SYCL_RELU_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9581,7 +6188,7 @@ static void leaky_relu_f32_sycl(const float *x, float *dst, const int k,
     }
     
     static void sqr_f32_sycl(const float *x, float *dst, const int k,
    -                         dpct::queue_ptr stream) {
    +                         queue_ptr stream) {
         const int num_blocks = (k + SYCL_SQR_BLOCK_SIZE - 1) / SYCL_SQR_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -9594,7 +6201,7 @@ static void sqr_f32_sycl(const float *x, float *dst, const int k,
     
     static void norm_f32_sycl(const float *x, float *dst, const int ncols,
                               const int nrows, const float eps,
    -                          dpct::queue_ptr stream) {
    +                          queue_ptr stream) {
         GGML_ASSERT(ncols % WARP_SIZE == 0);
         if (ncols < 1024) {
             const sycl::range<3> block_dims(1, 1, WARP_SIZE);
    @@ -9612,7 +6219,8 @@ static void norm_f32_sycl(const float *x, float *dst, const int ncols,
                         });
             });
         } else {
    -        const int work_group_size = g_work_group_size;
    +        // FIXME: 1024 from cuda
    +        const int work_group_size = GROUP_SIZE;
             const sycl::range<3> block_dims(1, 1, work_group_size);
             /*
             DPCT1049:17: The work-group size passed to the SYCL kernel may exceed
    @@ -9637,7 +6245,7 @@ static void norm_f32_sycl(const float *x, float *dst, const int ncols,
     
     static void group_norm_f32_sycl(const float *x, float *dst,
                                     const int num_groups, const int group_size,
    -                                const int ne_elements, dpct::queue_ptr stream) {
    +                                const int ne_elements, queue_ptr stream) {
         static const float eps = 1e-6f;
         if (group_size < 1024) {
             const sycl::range<3> block_dims(1, 1, WARP_SIZE);
    @@ -9658,7 +6266,7 @@ static void group_norm_f32_sycl(const float *x, float *dst,
                         });
             });
         } else {
    -        const int work_group_size = g_work_group_size;
    +        const int work_group_size = GROUP_SIZE;
             const sycl::range<3> block_dims(1, 1, work_group_size);
             /*
             DPCT1049:18: The work-group size passed to the SYCL kernel may exceed
    @@ -9687,7 +6295,7 @@ static void group_norm_f32_sycl(const float *x, float *dst,
     
     static void concat_f32_sycl(const float *x, const float *y, float *dst,
                                 const int ne0, int ne1, int ne2, int ne02,
    -                            dpct::queue_ptr stream) {
    +                            queue_ptr stream) {
         int num_blocks = (ne0 + SYCL_CONCAT_BLOCK_SIZE - 1) / SYCL_CONCAT_BLOCK_SIZE;
         sycl::range<3> gridDim(ne2, ne1, num_blocks);
         stream->parallel_for(
    @@ -9702,7 +6310,7 @@ static void concat_f32_sycl(const float *x, const float *y, float *dst,
     static void upscale_f32_sycl(const float *x, float *dst, const int nb00, const int nb01,
                                  const int nb02, const int nb03, const int ne10, const int ne11,
                                  const int ne12, const int ne13, const float sf0, const float sf1,
    -                             const float sf2, const float sf3, dpct::queue_ptr stream) {
    +                             const float sf2, const float sf3, queue_ptr stream) {
         int dst_size = ne10 * ne11 * ne12 * ne13;
         int num_blocks = (dst_size + SYCL_UPSCALE_BLOCK_SIZE - 1) / SYCL_UPSCALE_BLOCK_SIZE;
         sycl::range<1> gridDim(num_blocks * SYCL_UPSCALE_BLOCK_SIZE);
    @@ -9715,7 +6323,7 @@ static void upscale_f32_sycl(const float *x, float *dst, const int nb00, const i
     
     static void pad_f32_sycl(const float *x, float *dst, const int ne00,
                              const int ne01, const int ne02, const int ne0,
    -                         const int ne1, const int ne2, dpct::queue_ptr stream) {
    +                         const int ne1, const int ne2, queue_ptr stream) {
         int num_blocks = (ne0 + SYCL_PAD_BLOCK_SIZE - 1) / SYCL_PAD_BLOCK_SIZE;
         sycl::range<3> gridDim(ne2, ne1, num_blocks);
         stream->parallel_for(
    @@ -9728,7 +6336,7 @@ static void pad_f32_sycl(const float *x, float *dst, const int ne00,
     
     static void rms_norm_f32_sycl(const float *x, float *dst, const int ncols,
                                   const int nrows, const float eps,
    -                              dpct::queue_ptr stream) {
    +                              queue_ptr stream) {
         GGML_ASSERT(ncols % WARP_SIZE == 0);
         // printf("%s ncols=%d, nrows=%d, WARP_SIZE=%d\n", __func__, ncols, nrows, WARP_SIZE);
         if (ncols < 1024) {
    @@ -9747,7 +6355,7 @@ static void rms_norm_f32_sycl(const float *x, float *dst, const int ncols,
                         });
             });
         } else {
    -        const int work_group_size = g_work_group_size;
    +        const int work_group_size = GROUP_SIZE;
             const sycl::range<3> block_dims(1, 1, work_group_size);
             /*
             DPCT1049:19: The work-group size passed to the SYCL kernel may exceed
    @@ -9772,7 +6380,7 @@ static void rms_norm_f32_sycl(const float *x, float *dst, const int ncols,
     
     static void quantize_row_q8_1_sycl(const float *x, void *vy, const int kx,
                                        const int ky, const int kx_padded,
    -                                   dpct::queue_ptr stream) {
    +                                   queue_ptr stream) {
         const int block_num_x = (kx_padded + SYCL_QUANTIZE_BLOCK_SIZE - 1) / SYCL_QUANTIZE_BLOCK_SIZE;
         const sycl::range<3> num_blocks(1, ky, block_num_x);
         const sycl::range<3> block_size(1, 1, SYCL_DEQUANTIZE_BLOCK_SIZE);
    @@ -9791,7 +6399,7 @@ static void quantize_row_q8_1_sycl(const float *x, void *vy, const int kx,
     template 
     static void dequantize_block_sycl(const void *__restrict__ vx,
                                       dst_t *__restrict__ y, const int k,
    -                                  dpct::queue_ptr stream) {
    +                                  queue_ptr stream) {
         const int num_blocks = (k + 2*SYCL_DEQUANTIZE_BLOCK_SIZE - 1) / (2*SYCL_DEQUANTIZE_BLOCK_SIZE);
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9809,7 +6417,7 @@ static void dequantize_block_sycl(const void *__restrict__ vx,
     
     template 
     static void dequantize_row_q2_K_sycl(const void *vx, dst_t *y, const int k,
    -                                     dpct::queue_ptr stream) {
    +                                     queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9826,7 +6434,7 @@ static void dequantize_row_q2_K_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_q3_K_sycl(const void *vx, dst_t *y, const int k,
    -                                     dpct::queue_ptr stream) {
    +                                     queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9843,7 +6451,7 @@ static void dequantize_row_q3_K_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_q4_0_sycl(const void *vx, dst_t *y, const int k,
    -                                     dpct::queue_ptr stream) {
    +                                     queue_ptr stream) {
         const int nb32 = k / 32;
         const int nb = (k + 255) / 256;
         {
    @@ -9861,7 +6469,7 @@ static void dequantize_row_q4_0_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_q4_1_sycl(const void *vx, dst_t *y, const int k,
    -                                     dpct::queue_ptr stream) {
    +                                     queue_ptr stream) {
         const int nb32 = k / 32;
         const int nb = (k + 255) / 256;
         {
    @@ -9880,7 +6488,7 @@ static void dequantize_row_q4_1_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_q4_K_sycl(const void *vx, dst_t *y, const int k,
    -                                     dpct::queue_ptr stream) {
    +                                     queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9897,7 +6505,7 @@ static void dequantize_row_q4_K_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_q5_K_sycl(const void *vx, dst_t *y, const int k,
    -                                     dpct::queue_ptr stream) {
    +                                     queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9914,7 +6522,7 @@ static void dequantize_row_q5_K_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_q6_K_sycl(const void *vx, dst_t *y, const int k,
    -                                     dpct::queue_ptr stream) {
    +                                     queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9931,7 +6539,7 @@ static void dequantize_row_q6_K_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq1_s_sycl(const void *vx, dst_t *y, const int k,
    -                                        dpct::queue_ptr stream) {
    +                                        queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9952,7 +6560,7 @@ static void dequantize_row_iq1_s_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq1_m_sycl(const void *vx, dst_t *y, const int k,
    -                                        dpct::queue_ptr stream) {
    +                                        queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9973,7 +6581,7 @@ static void dequantize_row_iq1_m_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq2_xxs_sycl(const void *vx, dst_t *y, const int k,
    -                                        dpct::queue_ptr stream) {
    +                                        queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -9994,7 +6602,7 @@ static void dequantize_row_iq2_xxs_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq2_xs_sycl(const void *vx, dst_t *y, const int k,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -10015,7 +6623,7 @@ static void dequantize_row_iq2_xs_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq2_s_sycl(const void *vx, dst_t *y, const int k,
    -                                      dpct::queue_ptr stream) {
    +                                      queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -10035,7 +6643,7 @@ static void dequantize_row_iq2_s_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq3_xxs_sycl(const void *vx, dst_t *y, const int k,
    -                                        dpct::queue_ptr stream) {
    +                                        queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -10056,7 +6664,7 @@ static void dequantize_row_iq3_xxs_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq3_s_sycl(const void *vx, dst_t *y, const int k,
    -                                        dpct::queue_ptr stream) {
    +                                        queue_ptr stream) {
         const int nb = k / QK_K;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -10076,7 +6684,7 @@ static void dequantize_row_iq3_s_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq4_xs_sycl(const void *vx, dst_t *y, const int k,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         const int nb = (k + QK_K - 1) / QK_K;
           {
                 dpct::has_capability_or_fail(stream->get_device(),
    @@ -10097,7 +6705,7 @@ static void dequantize_row_iq4_xs_sycl(const void *vx, dst_t *y, const int k,
     
     template 
     static void dequantize_row_iq4_nl_sycl(const void *vx, dst_t *y, const int k,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         const int nb = (k + QK_K - 1) / QK_K;
           {
                 dpct::has_capability_or_fail(stream->get_device(),
    @@ -10120,7 +6728,7 @@ static void dequantize_row_iq4_nl_sycl(const void *vx, dst_t *y, const int k,
     template 
     static void convert_unary_sycl(const void *__restrict__ vx,
                                    dst_t *__restrict__ y, const int k,
    -                               dpct::queue_ptr stream) {
    +                               queue_ptr stream) {
         const int num_blocks = (k + SYCL_DEQUANTIZE_BLOCK_SIZE - 1) / SYCL_DEQUANTIZE_BLOCK_SIZE;
         {
             dpct::has_capability_or_fail(stream->get_device(),
    @@ -10241,7 +6849,7 @@ static to_fp32_sycl_t ggml_get_to_fp32_sycl(ggml_type type) {
     static void dequantize_mul_mat_vec_q4_0_sycl(const void *vx, const dfloat *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % GGML_SYCL_DMMV_X == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         // the number of rows may exceed maximum grid size in the y or z dimensions, use the x dimension instead
    @@ -10263,7 +6871,7 @@ static void dequantize_mul_mat_vec_q4_0_sycl(const void *vx, const dfloat *y,
     static void dequantize_mul_mat_vec_q4_1_sycl(const void *vx, const dfloat *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % GGML_SYCL_DMMV_X == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10284,7 +6892,7 @@ static void dequantize_mul_mat_vec_q4_1_sycl(const void *vx, const dfloat *y,
     static void dequantize_mul_mat_vec_q5_0_sycl(const void *vx, const dfloat *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % GGML_SYCL_DMMV_X == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10305,7 +6913,7 @@ static void dequantize_mul_mat_vec_q5_0_sycl(const void *vx, const dfloat *y,
     static void dequantize_mul_mat_vec_q5_1_sycl(const void *vx, const dfloat *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % GGML_SYCL_DMMV_X == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10326,7 +6934,7 @@ static void dequantize_mul_mat_vec_q5_1_sycl(const void *vx, const dfloat *y,
     static void dequantize_mul_mat_vec_q8_0_sycl(const void *vx, const dfloat *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % GGML_SYCL_DMMV_X == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10347,7 +6955,7 @@ static void dequantize_mul_mat_vec_q8_0_sycl(const void *vx, const dfloat *y,
     static void dequantize_mul_mat_vec_q2_K_sycl(const void *vx, const float *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int ny = 2; // very slightly faster than 1 even when K_QUANTS_PER_ITERATION = 2
         const int block_num_y = (nrows + ny - 1) / ny;
    @@ -10363,7 +6971,7 @@ static void dequantize_mul_mat_vec_q2_K_sycl(const void *vx, const float *y,
     static void dequantize_mul_mat_vec_q3_K_sycl(const void *vx, const float *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int ny = 2 / K_QUANTS_PER_ITERATION;
         const int block_num_y = (nrows + ny - 1) / ny;
    @@ -10379,7 +6987,7 @@ static void dequantize_mul_mat_vec_q3_K_sycl(const void *vx, const float *y,
     static void dequantize_mul_mat_vec_q4_K_sycl(const void *vx, const float *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int ny = 2 / K_QUANTS_PER_ITERATION;
         const int block_num_y = (nrows + ny - 1) / ny;
    @@ -10395,7 +7003,7 @@ static void dequantize_mul_mat_vec_q4_K_sycl(const void *vx, const float *y,
     static void dequantize_mul_mat_vec_q5_K_sycl(const void *vx, const float *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const sycl::range<3> block_dims(1, 1, 32);
         stream->parallel_for(
    @@ -10408,7 +7016,7 @@ static void dequantize_mul_mat_vec_q5_K_sycl(const void *vx, const float *y,
     static void dequantize_mul_mat_vec_q6_K_sycl(const void *vx, const float *y,
                                                  float *dst, const int ncols,
                                                  const int nrows,
    -                                             dpct::queue_ptr stream) {
    +                                             queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int ny = 2 / K_QUANTS_PER_ITERATION;
         const int block_num_y = (nrows + ny - 1) / ny;
    @@ -10424,7 +7032,7 @@ static void dequantize_mul_mat_vec_q6_K_sycl(const void *vx, const float *y,
     static void convert_mul_mat_vec_f16_sycl(const void *vx, const dfloat *y,
                                              float *dst, const int ncols,
                                              const int nrows,
    -                                         dpct::queue_ptr stream) {
    +                                         queue_ptr stream) {
         GGML_ASSERT(ncols % GGML_SYCL_DMMV_X == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10446,7 +7054,7 @@ static void convert_mul_mat_vec_f16_sycl(const void *vx, const dfloat *y,
     static void mul_mat_vec_q4_0_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK4_0 == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10470,7 +7078,7 @@ static void mul_mat_vec_q4_0_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q4_1_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK4_1 == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10494,7 +7102,7 @@ static void mul_mat_vec_q4_1_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q5_0_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK5_0 == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10518,7 +7126,7 @@ static void mul_mat_vec_q5_0_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q5_1_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK5_1 == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10542,7 +7150,7 @@ static void mul_mat_vec_q5_1_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q8_0_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK8_0 == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10566,7 +7174,7 @@ static void mul_mat_vec_q8_0_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q2_K_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10590,7 +7198,7 @@ static void mul_mat_vec_q2_K_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q3_K_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10614,7 +7222,7 @@ static void mul_mat_vec_q3_K_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q4_K_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10638,7 +7246,7 @@ static void mul_mat_vec_q4_K_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q5_K_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10662,7 +7270,7 @@ static void mul_mat_vec_q5_K_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_q6_K_q8_1_sycl(const void *vx, const void *vy,
                                            float *dst, const int ncols,
                                            const int nrows,
    -                                       dpct::queue_ptr stream) {
    +                                       queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10687,7 +7295,7 @@ static void mul_mat_vec_q6_K_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq2_xxs_q8_1_sycl(const void *vx, const void *vy,
                                               float *dst, const int ncols,
                                               const int nrows,
    -                                          dpct::queue_ptr stream) {
    +                                          queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10708,7 +7316,7 @@ static void mul_mat_vec_iq2_xxs_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq2_xs_q8_1_sycl(const void *vx, const void *vy,
                                              float *dst, const int ncols,
                                              const int nrows,
    -                                         dpct::queue_ptr stream) {
    +                                         queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10733,7 +7341,7 @@ static void mul_mat_vec_iq2_xs_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq2_s_q8_1_sycl(const void *vx, const void *vy,
                                              float *dst, const int ncols,
                                              const int nrows,
    -                                         dpct::queue_ptr stream) {
    +                                         queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10758,7 +7366,7 @@ static void mul_mat_vec_iq2_s_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq3_xxs_q8_1_sycl(const void *vx, const void *vy,
                                               float *dst, const int ncols,
                                               const int nrows,
    -                                          dpct::queue_ptr stream) {
    +                                          queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10783,7 +7391,7 @@ static void mul_mat_vec_iq3_xxs_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq3_s_q8_1_sycl(const void *vx, const void *vy,
                                               float *dst, const int ncols,
                                               const int nrows,
    -                                          dpct::queue_ptr stream) {
    +                                          queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10807,7 +7415,7 @@ static void mul_mat_vec_iq3_s_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq1_s_q8_1_sycl(const void *vx, const void *vy,
                                               float *dst, const int ncols,
                                               const int nrows,
    -                                          dpct::queue_ptr stream) {
    +                                          queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10832,7 +7440,7 @@ static void mul_mat_vec_iq1_s_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq1_m_q8_1_sycl(const void *vx, const void *vy,
                                               float *dst, const int ncols,
                                               const int nrows,
    -                                          dpct::queue_ptr stream) {
    +                                          queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10853,7 +7461,7 @@ static void mul_mat_vec_iq1_m_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq4_nl_q8_1_sycl(const void *vx, const void *vy,
                                               float *dst, const int ncols,
                                               const int nrows,
    -                                          dpct::queue_ptr stream) {
    +                                          queue_ptr stream) {
         GGML_ASSERT(ncols % QK4_NL == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10875,7 +7483,7 @@ static void mul_mat_vec_iq4_nl_q8_1_sycl(const void *vx, const void *vy,
     static void mul_mat_vec_iq4_xs_q8_1_sycl(const void *vx, const void *vy,
                                               float *dst, const int ncols,
                                               const int nrows,
    -                                          dpct::queue_ptr stream) {
    +                                          queue_ptr stream) {
         GGML_ASSERT(ncols % QK_K == 0);
         const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y;
         const sycl::range<3> block_nums(1, 1, block_num_y);
    @@ -10898,12 +7506,12 @@ static void ggml_mul_mat_q4_0_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11013,12 +7621,12 @@ static void ggml_mul_mat_q4_1_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11128,12 +7736,12 @@ static void ggml_mul_mat_q5_0_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11243,12 +7851,12 @@ static void ggml_mul_mat_q5_1_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11358,12 +7966,12 @@ static void ggml_mul_mat_q8_0_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11473,12 +8081,12 @@ static void ggml_mul_mat_q2_K_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11594,12 +8202,12 @@ static void ggml_mul_mat_q3_K_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11721,12 +8329,12 @@ static void ggml_mul_mat_q4_K_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11842,12 +8450,12 @@ static void ggml_mul_mat_q5_K_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -11963,12 +8571,12 @@ static void ggml_mul_mat_q6_K_q8_1_sycl(const void *vx, const void *vy,
                                             float *dst, const int ncols_x,
                                             const int nrows_x, const int ncols_y,
                                             const int nrows_y, const int nrows_dst,
    -                                        dpct::queue_ptr stream) try {
    +                                        queue_ptr stream) try {
     
         int id;
         SYCL_CHECK(
             CHECK_TRY_ERROR(id = get_current_device_id()));
    -    const int compute_capability = g_device_caps[id].cc;
    +    const int compute_capability = ggml_sycl_info().devices[id].cc;
     
         int mmq_x, mmq_y, nwarps;
         if (compute_capability >= VER_GEN13) {
    @@ -12085,7 +8693,7 @@ static void ggml_mul_mat_p021_f16_f32_sycl(const void *vx, const float *y,
                                                const int nrows_x,
                                                const int nchannels_x,
                                                const int nchannels_y,
    -                                           dpct::queue_ptr stream) {
    +                                           queue_ptr stream) {
     
         const sycl::range<3> block_nums(nchannels_y, nrows_x, 1);
         const sycl::range<3> block_dims(1, 1, WARP_SIZE);
    @@ -12105,7 +8713,7 @@ static void ggml_mul_mat_p021_f16_f32_sycl(const void *vx, const float *y,
     static void ggml_mul_mat_vec_nc_f16_f32_sycl(
         const void *vx, const float *y, float *dst, const int ncols_x,
         const int nrows_x, const int row_stride_x, const int nchannels_x,
    -    const int nchannels_y, const int channel_stride_x, dpct::queue_ptr stream) {
    +    const int nchannels_y, const int channel_stride_x, queue_ptr stream) {
     
         const sycl::range<3> block_nums(nchannels_y, nrows_x, 1);
         const sycl::range<3> block_dims(1, 1, WARP_SIZE);
    @@ -12129,7 +8737,7 @@ ggml_cpy_f16_f32_sycl(const char *cx, char *cdst, const int ne, const int ne00,
                           const int nb01, const int nb02, const int nb03,
                           const int ne10, const int ne11, const int ne12,
                           const int nb10, const int nb11, const int nb12,
    -                      const int nb13, dpct::queue_ptr stream) {
    +                      const int nb13, queue_ptr stream) {
     
         const int num_blocks = (ne + SYCL_CPY_BLOCK_SIZE - 1) / SYCL_CPY_BLOCK_SIZE;
         {
    @@ -12156,7 +8764,7 @@ static void ggml_cpy_f32_f32_sycl(const char *cx, char *cdst, const int ne,
                                       const int ne11, const int ne12,
                                       const int nb10, const int nb11,
                                       const int nb12, const int nb13,
    -                                  dpct::queue_ptr stream) {
    +                                  queue_ptr stream) {
     
         const int num_blocks = (ne + SYCL_CPY_BLOCK_SIZE - 1) / SYCL_CPY_BLOCK_SIZE;
         {
    @@ -12183,7 +8791,7 @@ static void ggml_cpy_f32_f16_sycl(const char *cx, char *cdst, const int ne,
                                       const int ne11, const int ne12,
                                       const int nb10, const int nb11,
                                       const int nb12, const int nb13,
    -                                  dpct::queue_ptr stream) {
    +                                  queue_ptr stream) {
     
         const int num_blocks = (ne + SYCL_CPY_BLOCK_SIZE - 1) / SYCL_CPY_BLOCK_SIZE;
         {
    @@ -12210,7 +8818,7 @@ static void ggml_cpy_f32_q8_0_sycl(const char *cx, char *cdst, const int ne,
                                        const int ne11, const int ne12,
                                        const int nb10, const int nb11,
                                        const int nb12, const int nb13,
    -                                   dpct::queue_ptr stream) {
    +                                   queue_ptr stream) {
     
         GGML_ASSERT(ne % QK8_0 == 0);
         const int num_blocks = ne / QK8_0;
    @@ -12232,7 +8840,7 @@ static void ggml_cpy_f32_q4_0_sycl(const char *cx, char *cdst, const int ne,
                                        const int ne11, const int ne12,
                                        const int nb10, const int nb11,
                                        const int nb12, const int nb13,
    -                                   dpct::queue_ptr stream) {
    +                                   queue_ptr stream) {
     
         GGML_ASSERT(ne % QK4_0 == 0);
         const int num_blocks = ne / QK4_0;
    @@ -12254,7 +8862,7 @@ static void ggml_cpy_f32_q4_1_sycl(const char *cx, char *cdst, const int ne,
                                        const int ne11, const int ne12,
                                        const int nb10, const int nb11,
                                        const int nb12, const int nb13,
    -                                   dpct::queue_ptr stream) {
    +                                   queue_ptr stream) {
     
         GGML_ASSERT(ne % QK4_1 == 0);
         const int num_blocks = ne / QK4_1;
    @@ -12276,7 +8884,7 @@ static void ggml_cpy_f16_f16_sycl(const char *cx, char *cdst, const int ne,
                                       const int ne11, const int ne12,
                                       const int nb10, const int nb11,
                                       const int nb12, const int nb13,
    -                                  dpct::queue_ptr stream) {
    +                                  queue_ptr stream) {
     
         const int num_blocks = (ne + SYCL_CPY_BLOCK_SIZE - 1) / SYCL_CPY_BLOCK_SIZE;
         {
    @@ -12303,7 +8911,7 @@ static void ggml_cpy_i16_i16_sycl(const char *cx, char *cdst, const int ne,
                                       const int ne11, const int ne12,
                                       const int nb10, const int nb11,
                                       const int nb12, const int nb13,
    -                                  dpct::queue_ptr stream) {
    +                                  queue_ptr stream) {
     
         const int num_blocks = (ne + SYCL_CPY_BLOCK_SIZE - 1) / SYCL_CPY_BLOCK_SIZE;
         {
    @@ -12330,7 +8938,7 @@ static void ggml_cpy_i32_i32_sycl(const char *cx, char *cdst, const int ne,
                                       const int ne11, const int ne12,
                                       const int nb10, const int nb11,
                                       const int nb12, const int nb13,
    -                                  dpct::queue_ptr stream) {
    +                                  queue_ptr stream) {
     
         const int num_blocks = (ne + SYCL_CPY_BLOCK_SIZE - 1) / SYCL_CPY_BLOCK_SIZE;
         {
    @@ -12350,7 +8958,7 @@ static void ggml_cpy_i32_i32_sycl(const char *cx, char *cdst, const int ne,
     }
     
     static void scale_f32_sycl(const float *x, float *dst, const float scale,
    -                           const int k, dpct::queue_ptr stream) {
    +                           const int k, queue_ptr stream) {
         const int num_blocks = (k + SYCL_SCALE_BLOCK_SIZE - 1) / SYCL_SCALE_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -12363,7 +8971,7 @@ static void scale_f32_sycl(const float *x, float *dst, const float scale,
     
     static void clamp_f32_sycl(const float *x, float *dst, const float min,
                                const float max, const int k,
    -                           dpct::queue_ptr stream) {
    +                           queue_ptr stream) {
         const int num_blocks = (k + SYCL_CLAMP_BLOCK_SIZE - 1) / SYCL_CLAMP_BLOCK_SIZE;
         stream->parallel_for(
             sycl::nd_range<3>(sycl::range<3>(1, 1, num_blocks) *
    @@ -12378,7 +8986,7 @@ template 
     static void rope_sycl(const T *x, T *dst, int ncols, int nrows,
                           const int32_t *pos, float freq_scale, int p_delta_rows,
                           float freq_base, float ext_factor, float attn_factor,
    -                      rope_corr_dims corr_dims, dpct::queue_ptr stream) {
    +                      rope_corr_dims corr_dims, queue_ptr stream) {
         GGML_ASSERT(ncols % 2 == 0);
         const sycl::range<3> block_dims(1, SYCL_ROPE_BLOCK_SIZE, 1);
         const int num_blocks_x = (ncols + 2*SYCL_ROPE_BLOCK_SIZE - 1) / (2*SYCL_ROPE_BLOCK_SIZE);
    @@ -12423,7 +9031,7 @@ static void rope_neox_sycl(const T *x, T *dst, int ncols, int n_dims, int nrows,
                                const int32_t *pos, float freq_scale,
                                int p_delta_rows, float freq_base, float ext_factor,
                                float attn_factor, rope_corr_dims corr_dims,
    -                           const float * freq_factors, dpct::queue_ptr stream) {
    +                           const float * freq_factors, queue_ptr stream) {
         GGML_ASSERT(ncols % 2 == 0);
         const sycl::range<3> block_dims(1, SYCL_ROPE_BLOCK_SIZE, 1);
         const int num_blocks_x = (ncols + 2*SYCL_ROPE_BLOCK_SIZE - 1) / (2*SYCL_ROPE_BLOCK_SIZE);
    @@ -12479,7 +9087,7 @@ static void rope_neox_sycl(const T *x, T *dst, int ncols, int n_dims, int nrows,
     }
     
     static void sum_rows_f32_sycl(const float *x, float *dst, const int ncols,
    -                              const int nrows, dpct::queue_ptr stream) {
    +                              const int nrows, queue_ptr stream) {
         const sycl::range<3> block_dims(1, 1, WARP_SIZE);
         const sycl::range<3> block_nums(1, nrows, 1);
         stream->parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims),
    @@ -12499,7 +9107,7 @@ static int next_power_of_2(int x) {
     
     static void argsort_f32_i32_sycl(const float *x, int *dst, const int ncols,
                                      const int nrows, ggml_sort_order order,
    -                                 dpct::queue_ptr stream) {
    +                                 queue_ptr stream) {
         // bitonic sort requires ncols to be power of 2
         const int ncols_pad = next_power_of_2(ncols);
     
    @@ -12507,8 +9115,6 @@ static void argsort_f32_i32_sycl(const float *x, int *dst, const int ncols,
         const sycl::range<3> block_nums(1, nrows, 1);
         const size_t shared_mem = ncols_pad * sizeof(int);
     
    -    // GGML_ASSERT(shared_mem <= ggml_cuda_info().devices[ggml_cuda_get_device()].smpb);
    -
         if (order == GGML_SORT_ORDER_ASC) {
             stream->submit([&](sycl::handler &cgh) {
                 sycl::local_accessor dpct_local_acc_ct1(
    @@ -12545,7 +9151,7 @@ static void argsort_f32_i32_sycl(const float *x, int *dst, const int ncols,
     static void diag_mask_inf_f32_sycl(const float *x, float *dst,
                                        const int ncols_x, const int nrows_x,
                                        const int rows_per_channel, const int n_past,
    -                                   dpct::queue_ptr stream) {
    +                                   queue_ptr stream) {
         const sycl::range<3> block_dims(1, SYCL_DIAG_MASK_INF_BLOCK_SIZE, 1);
         const int block_num_x = (ncols_x + SYCL_DIAG_MASK_INF_BLOCK_SIZE - 1) / SYCL_DIAG_MASK_INF_BLOCK_SIZE;
         const sycl::range<3> block_nums(1, block_num_x, nrows_x);
    @@ -12561,7 +9167,7 @@ template 
     static void soft_max_f32_submitter(const float * x, const float * mask, float * dst, const int ncols_par,
                                        const int nrows_y, const float scale, const float max_bias, const float m0,
                                        const float m1, uint32_t n_head_log2, sycl::range<3> block_nums, sycl::range<3> block_dims,
    -                                   const size_t n_local_scratch, dpct::queue_ptr stream) {
    +                                   const size_t n_local_scratch, queue_ptr stream) {
         stream->submit([&](sycl::handler &cgh) {
             sycl::local_accessor local_buf_acc(n_local_scratch, cgh);
     
    @@ -12579,9 +9185,9 @@ static void soft_max_f32_submitter(const float * x, const float * mask, float *
     static void soft_max_f32_sycl(const float * x, const float * mask,
                                   float * dst, const int ncols_x, const int nrows_x,
                                   const int nrows_y, const float scale, const float max_bias,
    -                              dpct::queue_ptr stream) {
    +                              queue_ptr stream) {
         int nth = WARP_SIZE;
    -    int max_block_size = g_work_group_size;
    +    int max_block_size = GROUP_SIZE;
         while (nth < ncols_x && nth < max_block_size) nth *= 2;
         if (nth>max_block_size) nth = max_block_size;
     
    @@ -12662,7 +9268,7 @@ static void im2col_sycl(const float *x, T *dst, int IW, int IH,
                                     int OW, int OH, int KW, int KH, int IC,
                                     int offset_delta, int s0, int s1, int p0,
                                     int p1, int d0, int d1,
    -                                dpct::queue_ptr stream) {
    +                                queue_ptr stream) {
         const int parallel_elements = OW * KW * KH;
         const int num_blocks = (parallel_elements + SYCL_IM2COL_BLOCK_SIZE - 1) / SYCL_IM2COL_BLOCK_SIZE;
         sycl::range<3> block_nums(IC, OH, num_blocks);
    @@ -12682,223 +9288,6 @@ static void im2col_sycl(const float *x, T *dst, int IW, int IH,
         }
     }
     
    -// buffer pool for sycl
    -#define MAX_SYCL_BUFFERS 256
    -
    -struct scoped_spin_lock {
    -    std::atomic_flag& lock;
    -    scoped_spin_lock(std::atomic_flag& lock) : lock(lock) {
    -        while (lock.test_and_set(std::memory_order_acquire)) {
    -            ; // spin
    -        }
    -    }
    -    ~scoped_spin_lock() {
    -        lock.clear(std::memory_order_release);
    -    }
    -    scoped_spin_lock(const scoped_spin_lock&) = delete;
    -    scoped_spin_lock& operator=(const scoped_spin_lock&) = delete;
    -};
    -
    -static std::atomic_flag g_sycl_pool_lock = ATOMIC_FLAG_INIT;
    -
    -// #define DEBUG_SYCL_MALLOC
    -struct sycl_buffer {
    -    void * ptr = nullptr;
    -    size_t size = 0;
    -};
    -
    -static sycl_buffer g_sycl_buffer_pool[GGML_SYCL_MAX_DEVICES][MAX_SYCL_BUFFERS];
    -static size_t g_sycl_pool_size[GGML_SYCL_MAX_DEVICES] = {0};
    -
    -static void *ggml_sycl_pool_malloc_leg(int device_index, size_t size, size_t *actual_size) try {
    -    scoped_spin_lock lock(g_sycl_pool_lock);
    -    // GGML_SYCL_DEBUG("ggml_sycl_pool_malloc_leg device_index %d size=%lu\n", device_index, size);
    -#ifdef DEBUG_SYCL_MALLOC
    -    int nnz = 0;
    -    size_t max_size = 0;
    -#endif
    -    size_t best_diff = 1ull << 36;
    -    int ibest = -1;
    -    for (int i = 0; i < MAX_SYCL_BUFFERS; ++i) {
    -        sycl_buffer& b = g_sycl_buffer_pool[device_index][i];
    -        if (b.ptr != nullptr) {
    -#ifdef DEBUG_SYCL_MALLOC
    -            ++nnz;
    -            if (b.size > max_size) max_size = b.size;
    -#endif
    -            if (b.size >= size) {
    -                size_t diff = b.size - size;
    -                if (diff < best_diff) {
    -                    best_diff = diff;
    -                    ibest = i;
    -                    if (!best_diff) {
    -                        void * ptr = b.ptr;
    -                        *actual_size = b.size;
    -                        b.ptr = nullptr;
    -                        b.size = 0;
    -                        // GGML_SYCL_DEBUG("ggml_sycl_pool_malloc_leg return 1 %p and rm in pool\n", ptr);
    -                        return ptr;
    -                    }
    -                }
    -            }
    -        }
    -    }
    -    if (ibest >= 0) {
    -        sycl_buffer& b = g_sycl_buffer_pool[device_index][ibest];
    -        void * ptr = b.ptr;
    -        *actual_size = b.size;
    -        b.ptr = nullptr;
    -        b.size = 0;
    -        // GGML_SYCL_DEBUG("ggml_sycl_pool_malloc_leg return 2 %p and rm in pool\n", ptr);
    -        return ptr;
    -    }
    -    void * ptr;
    -    size_t look_ahead_size = (size_t) (1.05 * size);
    -    look_ahead_size = 256 * ((look_ahead_size + 255)/256);
    -
    -    const dpct::queue_ptr stream = g_syclStreams[device_index][0];
    -    SYCL_CHECK(
    -        CHECK_TRY_ERROR(ptr = (void *)sycl::malloc_device(
    -                             look_ahead_size, *stream)));
    -    *actual_size = look_ahead_size;
    -    g_sycl_pool_size[device_index] += look_ahead_size;
    -
    -#ifdef DEBUG_SYCL_MALLOC
    -    fprintf(stderr, "%s[%d]: %d buffers, max_size = %u MB, pool_size = %u MB, requested %u MB\n", __func__, id, nnz,
    -            (uint32_t)(max_size/1024/1024), (uint32_t)(g_sycl_pool_size[id]/1024/1024), (uint32_t)(size/1024/1024));
    -#endif
    -    // GGML_SYCL_DEBUG("ggml_sycl_pool_malloc_leg look_ahead_size=%lu, return %p\n", look_ahead_size, ptr);
    -    return ptr;
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -static void ggml_sycl_pool_free_leg(int device_index, void *ptr, size_t size) try {
    -    scoped_spin_lock lock(g_sycl_pool_lock);
    -    const dpct::queue_ptr stream = g_syclStreams[device_index][0];
    -    for (int i = 0; i < MAX_SYCL_BUFFERS; ++i) {
    -        sycl_buffer& b = g_sycl_buffer_pool[device_index][i];
    -        if (b.ptr == nullptr) {
    -            b.ptr = ptr;
    -            b.size = size;
    -            return;
    -        }
    -    }
    -    fprintf(stderr, "WARNING: sycl buffer pool full, increase MAX_SYCL_BUFFERS\n");
    -    SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(ptr, *stream)));
    -    g_sycl_pool_size[device_index] -= size;
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -// pool with virtual memory
    -/*
    -DPCT1082:64: Migration of CUmemGenericAllocationHandle type is not supported.
    -*/
    -// static std::vector
    -//     g_sycl_pool_handles[GGML_SYCL_MAX_DEVICES];
    -static dpct::device_ptr g_sycl_pool_addr[GGML_SYCL_MAX_DEVICES] = {0};
    -static size_t g_sycl_pool_used[GGML_SYCL_MAX_DEVICES] = {0};
    -
    -static void *ggml_sycl_pool_malloc_vmm(int device_index, size_t size, size_t *actual_size) try {
    -    GGML_UNUSED(device_index);
    -    GGML_UNUSED(size);
    -    GGML_UNUSED(actual_size);
    -    return NULL;
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -static void ggml_sycl_pool_free_vmm(int device_index, void *ptr, size_t size) try {
    -    scoped_spin_lock lock(g_sycl_pool_lock);
    -#ifdef DEBUG_SYCL_MALLOC
    -    printf("sycl pool[%d]: freed %llu bytes at %llx\n", device_index, (unsigned long long) size, ptr);
    -#endif
    -
    -    g_sycl_pool_used[device_index] -= size;
    -
    -    // all deallocations must be in reverse order of the allocations
    -    GGML_ASSERT(ptr == (void *) (g_sycl_pool_addr[device_index] + g_sycl_pool_used[device_index]));
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -static void *ggml_sycl_pool_malloc(int device_index, size_t size, size_t *actual_size) try {
    -    if (g_device_caps[device_index].vmm) {
    -        return ggml_sycl_pool_malloc_vmm(device_index, size, actual_size);
    -    } else {
    -        return ggml_sycl_pool_malloc_leg(device_index, size, actual_size);
    -    }
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -static void ggml_sycl_pool_free(int device_index, void *ptr, size_t size) try {
    -    if (g_device_caps[device_index].vmm) {
    -        ggml_sycl_pool_free_vmm(device_index, ptr, size);
    -    } else {
    -        ggml_sycl_pool_free_leg(device_index, ptr, size);
    -    }
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -
    -template
    -struct sycl_pool_alloc {
    -    int device_index = -1;
    -    int device_id = -1;
    -    T * ptr = nullptr;
    -    size_t actual_size = 0;
    -
    -    // size is in number of elements
    -    T * alloc(size_t size) {
    -        GGML_ASSERT(ptr == nullptr);
    -        device_id = get_current_device_id();
    -        device_index = g_sycl_gpu_mgr->get_index(device_id);
    -        ptr = (T *) ggml_sycl_pool_malloc(device_index, size * sizeof(T), &this->actual_size);
    -        // GGML_SYCL_DEBUG("sycl_pool_alloc %lu return %p actual size=%lu\n", size * sizeof(T), ptr, this->actual_size);
    -        return ptr;
    -    }
    -
    -    sycl_pool_alloc(size_t size) {
    -        alloc(size);
    -    }
    -
    -    ~sycl_pool_alloc() {
    -        if (ptr != nullptr) {
    -            ggml_sycl_pool_free(device_index, ptr, actual_size);
    -        }
    -    }
    -
    -    T * get() {
    -        return ptr;
    -    }
    -
    -    sycl_pool_alloc() = default;
    -    sycl_pool_alloc(const sycl_pool_alloc &) = delete;
    -    sycl_pool_alloc(sycl_pool_alloc &&) = delete;
    -    sycl_pool_alloc& operator=(const sycl_pool_alloc &) = delete;
    -    sycl_pool_alloc& operator=(sycl_pool_alloc &&) = delete;
    -};
     
     static bool g_sycl_loaded = false;
     
    @@ -12950,21 +9339,6 @@ void ggml_backend_sycl_print_sycl_devices() {
         }
     }
     
    -void print_gpu_device_list() {
    -    GGML_ASSERT(g_sycl_gpu_mgr);
    -
    -    char* hint=NULL;
    -    if (g_ggml_sycl_backend_gpu_mode == SYCL_SINGLE_GPU_MODE) {
    -        hint = "use %d SYCL GPUs: [%s] with Max compute units:%d\n";
    -    } else {
    -        hint = "detect %d SYCL GPUs: [%s] with top Max compute units:%d\n";
    -    }
    -    fprintf(stderr, hint,
    -        g_sycl_gpu_mgr->get_gpu_count(),
    -        g_sycl_gpu_mgr->gpus_list.c_str(),
    -        g_sycl_gpu_mgr->max_compute_units);
    -}
    -
     int get_sycl_env(const char *env_name, int default_val) {
         char *user_device_string = getenv(env_name);
         int user_number = default_val;
    @@ -12986,11 +9360,11 @@ int get_work_group_size(int user_device_id) {
         return prop.get_max_work_group_size();
     }
     
    -static void ggml_init_sycl() try {
    +static void ggml_check_sycl() try {
         static bool initialized = false;
     
         if (!initialized) {
    -        fprintf(stderr, "[SYCL] call ggml_init_sycl\n");
    +        fprintf(stderr, "[SYCL] call ggml_check_sycl\n");
             g_ggml_sycl_debug = get_sycl_env("GGML_SYCL_DEBUG", 0);
     
             fprintf(stderr, "%s: GGML_SYCL_DEBUG: %d\n", __func__, g_ggml_sycl_debug);
    @@ -13027,109 +9401,189 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -void ggml_init_by_gpus(int device_count) try {
    -    g_device_count = device_count;
    -    g_work_group_size = g_sycl_gpu_mgr->work_group_size;
    +static ggml_sycl_device_info ggml_sycl_init() {
    +    ggml_sycl_device_info info = {};
     
    -    int64_t total_vram = 0;
    -
    -    print_gpu_device_list();
    -
    -    for (int id = 0; id < GGML_SYCL_MAX_DEVICES; ++id) {
    -        g_device_caps[id].vmm = 0;
    -        g_device_caps[id].device_id = -1;
    -        g_device_caps[id].cc = 0;
    -        g_tensor_split[id] = 0;
    -        g_default_tensor_split[id] = 0;
    +    info.device_count = dpct::dev_mgr::instance().device_count();
    +    if (info.device_count == 0) {
    +        fprintf(stderr, "%s: failed to initialize " GGML_SYCL_NAME ": %s\n", __func__);
    +        return info;
         }
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        int device_id = g_sycl_gpu_mgr->gpus[i];
    -        g_device_caps[i].vmm = 0;
    +    GGML_ASSERT(info.device_count <= GGML_SYCL_MAX_DEVICES);
     
    +    int64_t total_vram = 0;
    +#if defined(GGML_SYCL_FORCE_MMQ)
    +    fprintf(stderr, "%s: GGML_SYCL_FORCE_MMQ:   yes\n", __func__);
    +#else
    +    fprintf(stderr, "%s: GGML_SYCL_FORCE_MMQ:   no\n", __func__);
    +#endif
    +#if defined(SYCL_USE_XMX)
    +    fprintf(stderr, "%s: SYCL_USE_XMX: yes\n", __func__);
    +#else
    +    fprintf(stderr, "%s: SYCL_USE_XMX: no\n", __func__);
    +#endif
    +    fprintf(stderr, "%s: found %d " GGML_SYCL_NAME " devices:\n", __func__, info.device_count);
    +
    +    for (int i = 0; i < info.device_count; ++i) {
    +        info.devices[i].vmm = 0;
             dpct::device_info prop;
             SYCL_CHECK(CHECK_TRY_ERROR(dpct::get_device_info(
    -            prop, dpct::dev_mgr::instance().get_device(device_id))));
    +            prop, dpct::dev_mgr::instance().get_device(i))));
     
    -        g_default_tensor_split[i] = total_vram;
    +        info.default_tensor_split[i] = total_vram;
             total_vram += prop.get_global_mem_size();
     
    -        g_device_caps[i].cc =
    +        info.devices[i].cc =
                 100 * prop.get_major_version() + 10 * prop.get_minor_version();
         }
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        g_default_tensor_split[i] /= total_vram;
    +    for (int id = 0; id < info.device_count; ++id) {
    +        info.default_tensor_split[id] /= total_vram;
    +    }
    +    return info;
    +}
    +
    +const ggml_sycl_device_info & ggml_sycl_info() {
    +    static ggml_sycl_device_info info = ggml_sycl_init();
    +    return info;
    +}
    +
    +/*
    +device_index: device index from 0 to n (continue numbers).
    +    It is used for device select/set in SYCL backend internal data structure.
    +*/
    +inline void check_allow_gpu_index(const int device_index) {
    +  if (device_index >= ggml_sycl_info().device_count) {
    +    char error_buf[256];
    +    snprintf(
    +        error_buf,
    +        sizeof(error_buf),
    +        "%s error: device_index:%d is out of range: [0-%d]",
    +        __func__,
    +        device_index,
    +        ggml_sycl_info().device_count - 1);
    +    fprintf(stderr, "%s\n", error_buf);
    +    assert(false);
    +  }
    +}
    +
    +// buffer pool for sycl (legacy)
    +struct ggml_sycl_pool_leg : public ggml_sycl_pool {
    +    static const int MAX_SYCL_BUFFERS = 256;
    +
    +    int device;
    +    queue_ptr qptr;
    +    struct ggml_sycl_buffer {
    +        void * ptr = nullptr;
    +        size_t size = 0;
    +    };
    +
    +    ggml_sycl_buffer buffer_pool[MAX_SYCL_BUFFERS] = {};
    +    size_t pool_size = 0;
    +
    +    explicit ggml_sycl_pool_leg(queue_ptr qptr_, int device_) :
    +        qptr(qptr_),
    +        device(device_) {
         }
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        SYCL_CHECK(ggml_sycl_set_device(i));
    -
    -        // create sycl streams
    -        for (int is = 0; is < MAX_STREAMS; ++is) {
    -            SYCL_CHECK(CHECK_TRY_ERROR(
    -                g_syclStreams[i][is] =
    -                    dpct::get_current_device().create_queue(
    -                        g_sycl_gpu_mgr->get_co_ctx(), dpct::get_current_device())));
    +    ~ggml_sycl_pool_leg() {
    +        for (int i = 0; i < MAX_SYCL_BUFFERS; ++i) {
    +            ggml_sycl_buffer & b = buffer_pool[i];
    +            if (b.ptr != nullptr) {
    +                SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(b.ptr, *qptr)));
    +                pool_size -= b.size;
    +            }
             }
    -
    -        const dpct::queue_ptr stream = g_syclStreams[i][0];
    -        // create sycl handle
    -        SYCL_CHECK(CHECK_TRY_ERROR(g_sycl_handles[i] = stream));
    -    }
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -void *ggml_sycl_host_malloc(size_t size) try {
    -    if (getenv("GGML_SYCL_NO_PINNED") != nullptr) {
    -        return nullptr;
    +        GGML_ASSERT(pool_size == 0);
         }
     
    -    ggml_sycl_set_device(g_main_device);
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    +    void * alloc(size_t size, size_t * actual_size) override {
    +#ifdef DEBUG_sycl_MALLOC
    +        int nnz = 0;
    +        size_t max_size = 0;
    +#endif
    +        size_t best_diff = 1ull << 36;
    +        int ibest = -1;
    +        for (int i = 0; i < MAX_SYCL_BUFFERS; ++i) {
    +            ggml_sycl_buffer& b = buffer_pool[i];
    +            if (b.ptr != nullptr) {
    +#ifdef DEBUG_sycl_MALLOC
    +                ++nnz;
    +                if (b.size > max_size) max_size = b.size;
    +#endif
    +                if (b.size >= size) {
    +                    size_t diff = b.size - size;
    +                    if (diff < best_diff) {
    +                        best_diff = diff;
    +                        ibest = i;
    +                        if (!best_diff) {
    +                            void * ptr = b.ptr;
    +                            *actual_size = b.size;
    +                            b.ptr = nullptr;
    +                            b.size = 0;
    +                            return ptr;
    +                        }
    +                    }
    +                }
    +            }
    +        }
    +        if (ibest >= 0) {
    +            ggml_sycl_buffer& b = buffer_pool[ibest];
    +            void * ptr = b.ptr;
    +            *actual_size = b.size;
    +            b.ptr = nullptr;
    +            b.size = 0;
    +            return ptr;
    +        }
    +        void * ptr;
    +        size_t look_ahead_size = (size_t) (1.05 * size);
     
    -    void * ptr = nullptr;
    -    dpct::err0 err = CHECK_TRY_ERROR(
    -        ptr = (void *)sycl::malloc_host(size, *main_stream));
    +        SYCL_CHECK(
    +            CHECK_TRY_ERROR(ptr = (void *)sycl::malloc_device(
    +                                look_ahead_size, *qptr)));
    +        *actual_size = look_ahead_size;
    +        pool_size += look_ahead_size;
     
    -    if (err != 0) {
    -        // clear the error
    -        fprintf(
    -            stderr,
    -            "WARNING: failed to allocate %.2f MB of pinned memory: %s\n",
    -            size / 1024.0 / 1024.0,
    -            "syclGetErrorString is not supported");
    -        return nullptr;
    +    #ifdef DEBUG_SYCL_MALLOC
    +        fprintf(stderr, "%s[%d]: %d buffers, max_size = %u MB, pool_size = %u MB, requested %u MB\n", __func__, id, nnz,
    +                (uint32_t)(max_size/1024/1024), (uint32_t)(g_sycl_pool_size[id]/1024/1024), (uint32_t)(size/1024/1024));
    +    #endif
    +        // GGML_SYCL_DEBUG("ggml_sycl_pool_malloc_leg look_ahead_size=%lu, return %p\n", look_ahead_size, ptr);
    +        return ptr;
         }
     
    -    return ptr;
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    +    void free(void * ptr, size_t size) override {
    +        for (int i = 0; i < MAX_SYCL_BUFFERS; ++i) {
    +            ggml_sycl_buffer& b = buffer_pool[i];
    +            if (b.ptr == nullptr) {
    +                b.ptr = ptr;
    +                b.size = size;
    +                return;
    +            }
    +        }
    +        fprintf(stderr, "WARNING: sycl buffer pool full, increase MAX_sycl_BUFFERS\n");
    +        SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(ptr, *qptr)));
    +        pool_size -= size;
    +    }
    +};
    +
    +std::unique_ptr ggml_backend_sycl_context::new_pool_for_device(queue_ptr qptr, int device) {
    +    // TBD: NO VMM support
    +    // if (ggml_sycl_info().devices[device].vmm) {
    +    //     return std::unique_ptr(new ggml_sycl_pool_vmm(device));
    +    // }
    +   return std::unique_ptr(new ggml_sycl_pool_leg(qptr, device));
     }
     
    -void ggml_sycl_host_free(void *ptr) try {
    -    ggml_sycl_set_device(g_main_device);
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    -    SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(ptr, *main_stream)));
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    +// TBD pool with virtual memory management
    +// struct ggml_sycl_pool_vmm : public ggml_sycl_pool
     
     static dpct::err0 ggml_sycl_cpy_tensor_2d(void *dst,
                                               const struct ggml_tensor *src,
                                               int64_t i3, int64_t i2,
                                               int64_t i1_low, int64_t i1_high,
    -                                          dpct::queue_ptr stream) try {
    +                                          queue_ptr stream) try {
     
         dpct::memcpy_direction kind;
         char * src_ptr;
    @@ -13195,10 +9649,10 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -static void ggml_sycl_op_get_rows(const ggml_tensor *src0,
    +static void ggml_sycl_op_get_rows(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                       const ggml_tensor *src1, ggml_tensor *dst,
                                       const float *src0_d, const float *src1_d,
    -                                  float *dst_d, const dpct::queue_ptr &stream) {
    +                                  float *dst_d, const queue_ptr &stream) {
     
         GGML_ASSERT(src1->type == GGML_TYPE_I32);
         GGML_ASSERT(dst->type == GGML_TYPE_F32);
    @@ -13211,26 +9665,26 @@ static void ggml_sycl_op_get_rows(const ggml_tensor *src0,
     
         switch (src0->type) {
             case GGML_TYPE_F16:
    -            get_rows_sycl_float(src0, src1, dst, (const sycl::half *)src0_d,
    +            get_rows_sycl_float(ctx, src0, src1, dst, (const sycl::half *)src0_d,
                                     src1_i32, dst_d, stream);
                 break;
             case GGML_TYPE_F32:
    -            get_rows_sycl_float(src0, src1, dst, src0_d, src1_i32, dst_d, stream);
    +            get_rows_sycl_float(ctx, src0, src1, dst, src0_d, src1_i32, dst_d, stream);
                 break;
             case GGML_TYPE_Q4_0:
    -            get_rows_sycl(src0, src1, dst, src0_d, src1_i32, dst_d, stream);
    +            get_rows_sycl(ctx, src0, src1, dst, src0_d, src1_i32, dst_d, stream);
                 break;
             case GGML_TYPE_Q4_1:
    -            get_rows_sycl(src0, src1, dst, src0_d, src1_i32, dst_d, stream);
    +            get_rows_sycl(ctx, src0, src1, dst, src0_d, src1_i32, dst_d, stream);
                 break;
             case GGML_TYPE_Q5_0:
    -            get_rows_sycl(src0, src1, dst, src0_d, src1_i32, dst_d, stream);
    +            get_rows_sycl(ctx, src0, src1, dst, src0_d, src1_i32, dst_d, stream);
                 break;
             case GGML_TYPE_Q5_1:
    -            get_rows_sycl(src0, src1, dst, src0_d, src1_i32, dst_d, stream);
    +            get_rows_sycl(ctx, src0, src1, dst, src0_d, src1_i32, dst_d, stream);
                 break;
             case GGML_TYPE_Q8_0:
    -            get_rows_sycl(src0, src1, dst, src0_d, src1_i32, dst_d, stream);
    +            get_rows_sycl(ctx, src0, src1, dst, src0_d, src1_i32, dst_d, stream);
                 break;
             default:
                 // TODO: k-quants
    @@ -13241,25 +9695,25 @@ static void ggml_sycl_op_get_rows(const ggml_tensor *src0,
     }
     
     template 
    -inline void ggml_sycl_op_bin_bcast(const ggml_tensor *src0,
    +inline void ggml_sycl_op_bin_bcast(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                        const ggml_tensor *src1, ggml_tensor *dst,
                                        const float *src0_dd, const float *src1_dd,
                                        float *dst_dd,
    -                                   const dpct::queue_ptr &main_stream) {
    +                                   const queue_ptr &main_stream) {
     
         if (src0->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32) {
    -        op()(src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
    +        op()(ctx, src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
         } else if (src0->type == GGML_TYPE_F16 && dst->type == GGML_TYPE_F16) {
    -        op()(src0, src1, dst, (const sycl::half *)src0_dd, src1_dd,
    +        op()(ctx, src0, src1, dst, (const sycl::half *)src0_dd, src1_dd,
                  (sycl::half *)dst_dd, main_stream);
         } else if (src0->type == GGML_TYPE_F16 && dst->type == GGML_TYPE_F32) {
    -        op()(src0, src1, dst, (const sycl::half *)src0_dd, src1_dd, dst_dd,
    +        op()(ctx, src0, src1, dst, (const sycl::half *)src0_dd, src1_dd, dst_dd,
                  main_stream);
         } else if (src0->type == GGML_TYPE_I32 && dst->type == GGML_TYPE_I32) {
    -        op()(src0, src1, dst, (const int32_t *)src0_dd, (const int32_t *)src1_dd, (int32_t *)dst_dd,
    +        op()(ctx, src0, src1, dst, (const int32_t *)src0_dd, (const int32_t *)src1_dd, (int32_t *)dst_dd,
                  main_stream);
         } else if (src0->type == GGML_TYPE_I16 && dst->type == GGML_TYPE_I16) {
    -        op()(src0, src1, dst, (const int16_t *)src0_dd, (const int16_t *)src1_dd, (int16_t *)dst_dd,
    +        op()(ctx, src0, src1, dst, (const int16_t *)src0_dd, (const int16_t *)src1_dd, (int16_t *)dst_dd,
                  main_stream);
         } else {
             fprintf(stderr, "%s: unsupported types: dst: %s, src0: %s, src1: %s\n", __func__,
    @@ -13268,30 +9722,30 @@ inline void ggml_sycl_op_bin_bcast(const ggml_tensor *src0,
         }
     }
     
    -static void ggml_sycl_op_repeat(const ggml_tensor *src0,
    +static void ggml_sycl_op_repeat(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                     const ggml_tensor *src1, ggml_tensor *dst,
                                     const float *src0_d, const float *src1_d,
                                     float *dst_d,
    -                                const dpct::queue_ptr &main_stream) {
    +                                const queue_ptr &main_stream) {
     
    -    ggml_sycl_op_bin_bcast>(dst, src0, dst, nullptr, src0_d, dst_d, main_stream);
    +    ggml_sycl_op_bin_bcast>(ctx, dst, src0, dst, nullptr, src0_d, dst_d, main_stream);
     
         (void) src1;
         (void) src1_d;
     }
     
    -inline void ggml_sycl_op_add(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_add(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                  ggml_tensor *dst, const float *src0_dd,
                                  const float *src1_dd, float *dst_dd,
    -                             const dpct::queue_ptr &main_stream) {
    +                             const queue_ptr &main_stream) {
     
    -    ggml_sycl_op_bin_bcast>(src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
    +    ggml_sycl_op_bin_bcast>(ctx, src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
     }
     
    -inline void ggml_sycl_op_acc(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_acc(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                  ggml_tensor *dst, const float *src0_dd,
                                  const float *src1_dd, float *dst_dd,
    -                             const dpct::queue_ptr &main_stream) {
    +                             const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT(src1->type == GGML_TYPE_F32);
    @@ -13308,26 +9762,26 @@ inline void ggml_sycl_op_acc(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) dst;
     }
     
    -inline void ggml_sycl_op_mul(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_mul(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                  ggml_tensor *dst, const float *src0_dd,
                                  const float *src1_dd, float *dst_dd,
    -                             const dpct::queue_ptr &main_stream) {
    +                             const queue_ptr &main_stream) {
     
    -    ggml_sycl_op_bin_bcast>(src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
    +    ggml_sycl_op_bin_bcast>(ctx, src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
     }
     
    -inline void ggml_sycl_op_div(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_div(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                  ggml_tensor *dst, const float *src0_dd,
                                  const float *src1_dd, float *dst_dd,
    -                             const dpct::queue_ptr &main_stream) {
    +                             const queue_ptr &main_stream) {
     
    -    ggml_sycl_op_bin_bcast>(src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
    +    ggml_sycl_op_bin_bcast>(ctx, src0, src1, dst, src0_dd, src1_dd, dst_dd, main_stream);
     }
     
    -inline void ggml_sycl_op_gelu(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_gelu(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                   ggml_tensor *dst, const float *src0_dd,
                                   const float *src1_dd, float *dst_dd,
    -                              const dpct::queue_ptr &main_stream) {
    +                              const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13339,10 +9793,10 @@ inline void ggml_sycl_op_gelu(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_silu(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_silu(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                   ggml_tensor *dst, const float *src0_dd,
                                   const float *src1_dd, float *dst_dd,
    -                              const dpct::queue_ptr &main_stream) {
    +                              const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13354,11 +9808,11 @@ inline void ggml_sycl_op_silu(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_gelu_quick(const ggml_tensor *src0,
    +inline void ggml_sycl_op_gelu_quick(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                         const ggml_tensor *src1, ggml_tensor *dst,
                                         const float *src0_dd, const float *src1_dd,
                                         float *dst_dd,
    -                                    const dpct::queue_ptr &main_stream) {
    +                                    const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13370,10 +9824,10 @@ inline void ggml_sycl_op_gelu_quick(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_tanh(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_tanh(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                   ggml_tensor *dst, const float *src0_dd,
                                   const float *src1_dd, float *dst_dd,
    -                              const dpct::queue_ptr &main_stream) {
    +                              const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13384,10 +9838,10 @@ inline void ggml_sycl_op_tanh(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_relu(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_relu(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                   ggml_tensor *dst, const float *src0_dd,
                                   const float *src1_dd, float *dst_dd,
    -                              const dpct::queue_ptr &main_stream) {
    +                              const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13399,11 +9853,11 @@ inline void ggml_sycl_op_relu(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -static void ggml_sycl_op_hardsigmoid(const ggml_tensor *src0,
    +static void ggml_sycl_op_hardsigmoid(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                          const ggml_tensor *src1, ggml_tensor *dst,
                                          const float *src0_dd, const float *src1_dd,
                                          float *dst_dd,
    -                                     const dpct::queue_ptr &main_stream) {
    +                                     const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13415,10 +9869,10 @@ static void ggml_sycl_op_hardsigmoid(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -static void ggml_sycl_op_hardswish(const ggml_tensor *src0,
    +static void ggml_sycl_op_hardswish(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                        const ggml_tensor *src1, ggml_tensor *dst,
                                        const float *src0_dd, const float *src1_dd,
    -                                   float *dst_dd, const dpct::queue_ptr &main_stream) {
    +                                   float *dst_dd, const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13430,11 +9884,11 @@ static void ggml_sycl_op_hardswish(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_leaky_relu(const ggml_tensor *src0,
    +inline void ggml_sycl_op_leaky_relu(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                         const ggml_tensor *src1, ggml_tensor *dst,
                                         const float *src0_dd, const float *src1_dd,
                                         float *dst_dd,
    -                                    const dpct::queue_ptr &main_stream) {
    +                                    const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13449,10 +9903,10 @@ inline void ggml_sycl_op_leaky_relu(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_sqr(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_sqr(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                  ggml_tensor *dst, const float *src0_dd,
                                  const float *src1_dd, float *dst_dd,
    -                             const dpct::queue_ptr &main_stream) {
    +                             const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13464,10 +9918,10 @@ inline void ggml_sycl_op_sqr(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_norm(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_norm(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                   ggml_tensor *dst, const float *src0_dd,
                                   const float *src1_dd, float *dst_dd,
    -                              const dpct::queue_ptr &main_stream) {
    +                              const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13485,11 +9939,11 @@ inline void ggml_sycl_op_norm(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_group_norm(const ggml_tensor *src0,
    +inline void ggml_sycl_op_group_norm(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                         const ggml_tensor *src1, ggml_tensor *dst,
                                         const float *src0_dd, const float *src1_dd,
                                         float *dst_dd,
    -                                    const dpct::queue_ptr &main_stream) {
    +                                    const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13503,11 +9957,11 @@ inline void ggml_sycl_op_group_norm(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_concat(const ggml_tensor *src0,
    +inline void ggml_sycl_op_concat(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                     const ggml_tensor *src1, ggml_tensor *dst,
                                     const float *src0_dd, const float *src1_dd,
                                     float *dst_dd,
    -                                const dpct::queue_ptr &main_stream) {
    +                                const queue_ptr &main_stream) {
     #pragma message("TODO: generalize concat kernel for dim != 2")
     #pragma message("      https://github.com/ggerganov/llama.cpp/pull/7563")
         int dim = dst->op_params[0];
    @@ -13525,11 +9979,11 @@ inline void ggml_sycl_op_concat(const ggml_tensor *src0,
         (void) dst;
     }
     
    -inline void ggml_sycl_op_upscale(const ggml_tensor *src0,
    +inline void ggml_sycl_op_upscale(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                      const ggml_tensor *src1, ggml_tensor *dst,
                                      const float *src0_dd, const float *src1_dd,
                                      float *dst_dd,
    -                                 const dpct::queue_ptr &main_stream) {
    +                                 const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT(dst->type == GGML_TYPE_F32);
    @@ -13548,10 +10002,10 @@ inline void ggml_sycl_op_upscale(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_pad(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_pad(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                  ggml_tensor *dst, const float *src0_dd,
                                  const float *src1_dd, float *dst_dd,
    -                             const dpct::queue_ptr &main_stream) {
    +                             const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT(dst->type == GGML_TYPE_F32);
    @@ -13566,11 +10020,11 @@ inline void ggml_sycl_op_pad(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_rms_norm(const ggml_tensor *src0,
    +inline void ggml_sycl_op_rms_norm(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                       const ggml_tensor *src1, ggml_tensor *dst,
                                       const float *src0_dd, const float *src1_dd,
                                       float *dst_dd,
    -                                  const dpct::queue_ptr &main_stream) {
    +                                  const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -13589,11 +10043,11 @@ inline void ggml_sycl_op_rms_norm(const ggml_tensor *src0,
     }
     
     inline void ggml_sycl_op_mul_mat_q(
    -    const ggml_tensor *src0, const ggml_tensor *src1, ggml_tensor *dst,
    +    ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1, ggml_tensor *dst,
         const char *src0_dd_i, const float *src1_ddf_i, const char *src1_ddq_i,
         float *dst_dd_i, const int64_t row_low, const int64_t row_high,
         const int64_t src1_ncols, const int64_t src1_padded_row_size,
    -    const dpct::queue_ptr &stream) try {
    +    const queue_ptr &stream) try {
     
         const int64_t ne00 = src0->ne[0];
     
    @@ -13610,7 +10064,7 @@ inline void ggml_sycl_op_mul_mat_q(
     
         // the main device has a larger memory buffer to hold the results from all GPUs
         // nrows_dst == nrows of the matrix that the dequantize_mul_mat kernel writes into
    -    const int64_t nrows_dst = dst->backend == GGML_BACKEND_TYPE_GPU && device_id == g_main_device ? ne0 : row_diff;
    +    const int64_t nrows_dst = device_id == ctx.device ? ne0 : row_diff;
     
         switch (src0->type) {
             case GGML_TYPE_Q4_0:
    @@ -13661,13 +10115,13 @@ catch (sycl::exception const &exc) {
     static int64_t get_row_rounding(ggml_type type, const std::array & tensor_split) {
         int64_t min_compute_capability = INT_MAX;
         int64_t max_compute_capability = INT_MIN;
    -    for (int i = 0; i < g_device_count; ++i) {
    -        if (tensor_split[i] < (i + 1 < g_device_count ? tensor_split[i + 1] : 1.0f)) {
    -            if (min_compute_capability > g_device_caps[i].cc) {
    -                min_compute_capability = g_device_caps[i].cc;
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
    +        if (tensor_split[i] < (i + 1 < ggml_sycl_info().device_count ? tensor_split[i + 1] : 1.0f)) {
    +            if (min_compute_capability > ggml_sycl_info().devices[i].cc) {
    +                min_compute_capability = ggml_sycl_info().devices[i].cc;
                 }
    -            if (max_compute_capability < g_device_caps[i].cc) {
    -                max_compute_capability = g_device_caps[i].cc;
    +            if (max_compute_capability < ggml_sycl_info().devices[i].cc) {
    +                max_compute_capability = ggml_sycl_info().devices[i].cc;
                 }
             }
         }
    @@ -13707,11 +10161,12 @@ static int64_t get_row_rounding(ggml_type type, const std::arrayne[0];
         GGML_ASSERT(ne10 % QK8_1 == 0);
    @@ -13725,7 +10180,7 @@ inline void ggml_sycl_op_mul_mat_vec_q(
     
         // the main device has a larger memory buffer to hold the results from all GPUs
         // nrows_dst == nrows of the matrix that the kernel writes into
    -    const int64_t nrows_dst = dst->backend == GGML_BACKEND_TYPE_GPU && id == g_main_device ? ne00 : row_diff;
    +    const int64_t nrows_dst = id == ctx.device ? ne00 : row_diff;
     
         switch (src0->type) {
             case GGML_TYPE_Q4_0:
    @@ -13799,11 +10254,12 @@ inline void ggml_sycl_op_mul_mat_vec_q(
     
     
     inline void ggml_sycl_op_dequantize_mul_mat_vec(
    +    ggml_backend_sycl_context & ctx,
         const ggml_tensor *src0, const ggml_tensor *src1, ggml_tensor *dst,
         const char *src0_dd_i, const float *src1_ddf_i, const char *src1_ddq_i,
         float *dst_dd_i, const int64_t row_low, const int64_t row_high,
         const int64_t src1_ncols, const int64_t src1_padded_row_size,
    -    const dpct::queue_ptr &stream) {
    +    const queue_ptr &stream) {
     
         const int64_t ne00 = src0->ne[0];
         const int64_t row_diff = row_high - row_low;
    @@ -13812,7 +10268,7 @@ inline void ggml_sycl_op_dequantize_mul_mat_vec(
     
         // on some GPUs it is faster to convert src1 to half and to use half precision intrinsics
     #ifdef GGML_SYCL_F16
    -    sycl_pool_alloc src1_dfloat_a;
    +    ggml_sycl_pool_alloc src1_dfloat_a(ctx.pool());
         sycl::half *src1_dfloat = nullptr; // dfloat == half
     
         bool src1_convert_f16 =
    @@ -13878,11 +10334,12 @@ inline void ggml_sycl_op_dequantize_mul_mat_vec(
     }
     
     inline void ggml_sycl_op_mul_mat_sycl(
    +    ggml_backend_sycl_context & ctx,
         const ggml_tensor *src0, const ggml_tensor *src1, ggml_tensor *dst,
         const char *src0_dd_i, const float *src1_ddf_i, const char *src1_ddq_i,
         float *dst_dd_i, const int64_t row_low, const int64_t row_high,
         const int64_t src1_ncols, const int64_t src1_padded_row_size,
    -    const dpct::queue_ptr &stream) try {
    +    const queue_ptr &stream) try {
     
         GGML_ASSERT(src0_dd_i  != nullptr);
         GGML_ASSERT(src1_ddf_i != nullptr);
    @@ -13901,7 +10358,7 @@ inline void ggml_sycl_op_mul_mat_sycl(
     
         // the main device has a larger memory buffer to hold the results from all GPUs
         // ldc == nrows of the matrix that cuBLAS writes into
    -    int ldc = dst->backend == GGML_BACKEND_TYPE_GPU && id == g_main_device ? ne0 : row_diff;
    +    int ldc = id == ctx.device ? ne0 : row_diff;
     
     #ifdef GGML_SYCL_F16
         bool use_fp16 = true;  // TODO(Yu) SYCL capability check
    @@ -13913,7 +10370,7 @@ inline void ggml_sycl_op_mul_mat_sycl(
             dst->op_params[0] == GGML_PREC_DEFAULT) {
     
             // GGML_SYCL_DEBUG("ggml_sycl_op_mul_mat_sycl - fp16 path\n");
    -        sycl_pool_alloc src0_as_f16;
    +        ggml_sycl_pool_alloc src0_as_f16(ctx.pool());
             if (src0->type != GGML_TYPE_F16) {
                 const to_fp16_sycl_t to_fp16_sycl = ggml_get_to_fp16_sycl(src0->type);
                 GGML_ASSERT(to_fp16_sycl != nullptr);
    @@ -13925,7 +10382,7 @@ inline void ggml_sycl_op_mul_mat_sycl(
                                              ? (const sycl::half *)src0_dd_i
                                              : src0_as_f16.get();
     
    -        sycl_pool_alloc src1_as_f16;
    +        ggml_sycl_pool_alloc src1_as_f16(ctx.pool());
             if (src1->type != GGML_TYPE_F16) {
                 const to_fp16_sycl_t to_fp16_sycl = ggml_get_to_fp16_sycl(src1->type);
                 GGML_ASSERT(to_fp16_sycl != nullptr);
    @@ -13936,26 +10393,24 @@ inline void ggml_sycl_op_mul_mat_sycl(
             const sycl::half *src1_ptr = src1->type == GGML_TYPE_F16
                     ? (const sycl::half *)src1->data + src1_padded_row_size
                                              : src1_as_f16.get();
    -        sycl_pool_alloc dst_f16(row_diff * src1_ncols);
    +        ggml_sycl_pool_alloc dst_f16(ctx.pool(), row_diff * src1_ncols);
     
             const sycl::half alpha_f16 = 1.0f;
             const sycl::half beta_f16 = 0.0f;
    -        SYCL_CHECK(CHECK_TRY_ERROR(g_sycl_handles[id] = stream));
             SYCL_CHECK(CHECK_TRY_ERROR(dpct::gemm(
    -            *g_sycl_handles[id], oneapi::mkl::transpose::trans,
    +            *stream, oneapi::mkl::transpose::trans,
                 oneapi::mkl::transpose::nontrans, row_diff, src1_ncols, ne10,
                 &alpha_f16, src0_ptr, dpct::library_data_t::real_half, ne00,
                 src1_ptr, dpct::library_data_t::real_half, ne10, &beta_f16,
                 dst_f16.get(), dpct::library_data_t::real_half, ldc,
                 dpct::library_data_t::real_half)));
    -        g_sycl_handles[id]->wait();
             const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(GGML_TYPE_F16);
             to_fp32_sycl(dst_f16.get(), dst_dd_i, row_diff*src1_ncols, stream);
         }
         else {
             // GGML_SYCL_DEBUG("ggml_sycl_op_mul_mat_sycl - fp32 path\n");
    -        sycl_pool_alloc src0_ddq_as_f32;
    -        sycl_pool_alloc src1_ddq_as_f32;
    +        ggml_sycl_pool_alloc src0_ddq_as_f32(ctx.pool());
    +        ggml_sycl_pool_alloc src1_ddq_as_f32(ctx.pool());
             if (src0->type != GGML_TYPE_F32) {
                 const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(src0->type);
                 GGML_ASSERT(to_fp32_sycl != nullptr);
    @@ -13974,14 +10429,12 @@ inline void ggml_sycl_op_mul_mat_sycl(
             const float alpha = 1.0f;
             const float beta = 0.0f;
     
    -        SYCL_CHECK(CHECK_TRY_ERROR(g_sycl_handles[id] = stream));
             SYCL_CHECK(CHECK_TRY_ERROR(oneapi::mkl::blas::column_major::gemm(
    -            *g_sycl_handles[id], oneapi::mkl::transpose::trans,
    +            *stream, oneapi::mkl::transpose::trans,
                 oneapi::mkl::transpose::nontrans, row_diff, src1_ncols, ne10,
    -            dpct::get_value(&alpha, *g_sycl_handles[id]), src0_ddf_i, ne00,
    -            src1_ddf1_i, ne10, dpct::get_value(&beta, *g_sycl_handles[id]),
    +            dpct::get_value(&alpha, *stream), src0_ddf_i, ne00,
    +            src1_ddf1_i, ne10, dpct::get_value(&beta, *stream),
                 dst_dd_i, ldc)));
    -        g_sycl_handles[id]->wait();
         }
         (void) dst;
         (void) src1_ddq_i;
    @@ -13993,10 +10446,10 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -inline void ggml_sycl_op_rope(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_rope(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                   ggml_tensor *dst, const float *src0_dd,
                                   const float *src1_dd, float *dst_dd,
    -                              const dpct::queue_ptr &main_stream) {
    +                              const queue_ptr &main_stream) {
         const ggml_tensor * src2 = dst->src[2];
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_F16);
    @@ -14084,10 +10537,10 @@ inline void ggml_sycl_op_rope(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -static void ggml_sycl_op_pool2d(const ggml_tensor *src0,
    +static void ggml_sycl_op_pool2d(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                     const ggml_tensor *src1, ggml_tensor *dst,
                                     const float *src0_dd, const float *src1_dd,
    -                                float *dst_dd, const dpct::queue_ptr &main_stream) {
    +                                float *dst_dd, const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -14126,11 +10579,11 @@ static void ggml_sycl_op_pool2d(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_im2col(const ggml_tensor *src0,
    +inline void ggml_sycl_op_im2col(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                     const ggml_tensor *src1, ggml_tensor *dst,
                                     const float *src0_dd, const float *src1_dd,
                                     float *dst_dd,
    -                                const dpct::queue_ptr &main_stream) {
    +                                const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F16);
         GGML_ASSERT(src1->type == GGML_TYPE_F32);
    @@ -14167,11 +10620,11 @@ inline void ggml_sycl_op_im2col(const ggml_tensor *src0,
         (void) src0_dd;
     }
     
    -inline void ggml_sycl_op_sum_rows(const ggml_tensor *src0,
    +inline void ggml_sycl_op_sum_rows(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                       const ggml_tensor *src1, ggml_tensor *dst,
                                       const float *src0_dd, const float *src1_dd,
                                       float *dst_dd,
    -                                  const dpct::queue_ptr &main_stream) {
    +                                  const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -14186,11 +10639,11 @@ inline void ggml_sycl_op_sum_rows(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_argsort(const ggml_tensor *src0,
    +inline void ggml_sycl_op_argsort(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                      const ggml_tensor *src1, ggml_tensor *dst,
                                      const float *src0_dd, const float *src1_dd,
                                      float *dst_dd,
    -                                 const dpct::queue_ptr &main_stream) {
    +                                 const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_I32);
    @@ -14207,11 +10660,11 @@ inline void ggml_sycl_op_argsort(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_diag_mask_inf(const ggml_tensor *src0,
    +inline void ggml_sycl_op_diag_mask_inf(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                            const ggml_tensor *src1,
                                            ggml_tensor *dst, const float *src0_dd,
                                            const float *src1_dd, float *dst_dd,
    -                                       const dpct::queue_ptr &main_stream) {
    +                                       const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -14229,11 +10682,11 @@ inline void ggml_sycl_op_diag_mask_inf(const ggml_tensor *src0,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_soft_max(const ggml_tensor *src0,
    +inline void ggml_sycl_op_soft_max(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                       const ggml_tensor *src1, ggml_tensor *dst,
                                       const float *src0_dd, const float *src1_dd,
                                       float *dst_dd,
    -                                  const dpct::queue_ptr &main_stream) {
    +                                  const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -14256,10 +10709,10 @@ inline void ggml_sycl_op_soft_max(const ggml_tensor *src0,
                           nrows_x, nrows_y, scale, max_bias, main_stream);
     }
     
    -inline void ggml_sycl_op_scale(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_scale(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                    ggml_tensor *dst, const float *src0_dd,
                                    const float *src1_dd, float *dst_dd,
    -                               const dpct::queue_ptr &main_stream) {
    +                               const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -14279,10 +10732,10 @@ inline void ggml_sycl_op_scale(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -inline void ggml_sycl_op_clamp(const ggml_tensor *src0, const ggml_tensor *src1,
    +inline void ggml_sycl_op_clamp(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                                    ggml_tensor *dst, const float *src0_dd,
                                    const float *src1_dd, float *dst_dd,
    -                               const dpct::queue_ptr &main_stream) {
    +                               const queue_ptr &main_stream) {
     
         GGML_ASSERT(src0->type == GGML_TYPE_F32);
         GGML_ASSERT( dst->type == GGML_TYPE_F32);
    @@ -14304,7 +10757,7 @@ inline void ggml_sycl_op_clamp(const ggml_tensor *src0, const ggml_tensor *src1,
         (void) src1_dd;
     }
     
    -static void ggml_sycl_op_flatten(const ggml_tensor *src0,
    +static void ggml_sycl_op_flatten(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                      const ggml_tensor *src1, ggml_tensor *dst,
                                      const ggml_sycl_op_flatten_t op) try {
         const int64_t nrows0 = ggml_nrows(src0);
    @@ -14319,66 +10772,22 @@ static void ggml_sycl_op_flatten(const ggml_tensor *src0,
         ggml_tensor_extra_gpu * src1_extra = use_src1 ? (ggml_tensor_extra_gpu *) src1->extra : nullptr;
         ggml_tensor_extra_gpu * dst_extra  =            (ggml_tensor_extra_gpu *)  dst->extra;
     
    -    const bool src0_on_device =             src0->backend == GGML_BACKEND_TYPE_GPU || src0->backend == GGML_BACKEND_TYPE_GPU_SPLIT;
    -    const bool src1_on_device = use_src1 && src1->backend == GGML_BACKEND_TYPE_GPU;
    -    const bool  dst_on_device =              dst->backend == GGML_BACKEND_TYPE_GPU;
    -
         // dd = data device
    -    float * src0_ddf = nullptr;
    -    float * src1_ddf = nullptr;
    -    float *  dst_ddf = nullptr;
    +    float * src0_ddf = (float *) src0->data;
    +    float * src1_ddf = use_src1 ? (float *) src1->data : nullptr;
    +    float *  dst_ddf = (float *) dst->data;
     
    -    sycl_pool_alloc src0_f;
    -    sycl_pool_alloc src1_f;
    -    sycl_pool_alloc  dst_f;
    +    ggml_sycl_pool_alloc src0_f(ctx.pool());
    +    ggml_sycl_pool_alloc src1_f(ctx.pool());
    +    ggml_sycl_pool_alloc  dst_f(ctx.pool());
     
    -    ggml_sycl_set_device(g_main_device);
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    -    // GGML_SYCL_DEBUG("g_main_device=%d, main_stream=%p src0_on_device=%d, src1_on_device=%d, dst_on_device=%d\n",
    -        // g_main_device, main_stream, src0_on_device, src1_on_device, dst_on_device);
    +    ggml_sycl_set_device(ctx.device);
    +    queue_ptr main_stream = ctx.stream();
    +    // GGML_SYCL_DEBUG("ctx.device=%d, main_stream=%p src0_on_device=%d, src1_on_device=%d, dst_on_device=%d\n",
    +        // ctx.device, main_stream, src0_on_device, src1_on_device, dst_on_device);
     
    -    if (src0_on_device) {
    -        src0_ddf = (float *) src0_extra->data_device[g_main_device];
    -    } else {
    -        src0_ddf = src0_f.alloc(ggml_nelements(src0));
    -        // GGML_SYCL_DEBUG("before ggml_sycl_cpy_tensor_2d src0_ddf=%p, src0=%p\n", src0_ddf, src0);
    -        SYCL_CHECK(ggml_sycl_cpy_tensor_2d(src0_ddf, src0, 0, 0, 0, nrows0, main_stream));
    -    }
    -
    -    if (use_src1) {
    -        if (src1_on_device) {
    -            src1_ddf = (float *) src1_extra->data_device[g_main_device];
    -        } else {
    -            src1_ddf = src1_f.alloc(ggml_nelements(src1));
    -            SYCL_CHECK(ggml_sycl_cpy_tensor_2d(src1_ddf, src1, 0, 0, 0, nrows1, main_stream));
    -        }
    -    }
    -    if (dst_on_device) {
    -        dst_ddf = (float *) dst_extra->data_device[g_main_device];
    -    } else {
    -        dst_ddf = dst_f.alloc(ggml_nelements(dst));
    -    }
    -
    -    // GGML_SYCL_DEBUG("op src0=%p, src1=%p, dst=%p, src0_ddf=%p, src1_ddf=%p, dst_ddf=%p, main_stream=%p\n",
    -        // src0, src1, dst, src0_ddf, src1_ddf, dst_ddf, main_stream);
         // do the computation
    -    op(src0, src1, dst, src0_ddf, src1_ddf, dst_ddf, main_stream);
    -    /*
    -    DPCT1010:89: SYCL uses exceptions to report errors and does not use the
    -    error codes. The call was replaced with 0. You need to rewrite this code.
    -    */
    -    SYCL_CHECK(0);
    -
    -    // copy dst to host if necessary
    -    if (!dst_on_device) {
    -        SYCL_CHECK(CHECK_TRY_ERROR(
    -            main_stream->memcpy(dst->data, dst_ddf, ggml_nbytes(dst)).wait()));
    -    }
    -
    -    if (dst->backend == GGML_BACKEND_TYPE_CPU) {
    -        SYCL_CHECK(CHECK_TRY_ERROR(
    -            dpct::get_current_device().queues_wait_and_throw()));
    -    }
    +    op(ctx, src0, src1, dst, src0_ddf, src1_ddf, dst_ddf, main_stream);
         // print_ggml_tensor("tensor", dst);
     }
     catch (sycl::exception const &exc) {
    @@ -14388,7 +10797,7 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -static void ggml_sycl_set_peer_access(const int n_tokens) {
    +static void ggml_sycl_set_peer_access(const int n_tokens, int main_device) {
         static bool peer_access_enabled = false;
     
         const bool enable_peer_access = n_tokens <= GGML_SYCL_PEER_MAX_BATCH_SIZE;
    @@ -14398,19 +10807,18 @@ static void ggml_sycl_set_peer_access(const int n_tokens) {
         }
     
     #ifdef NDEBUG
    -    for (int i = 0; i < g_device_count; ++i) {
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
             SYCL_CHECK(ggml_sycl_set_device(i));
    -        // SYCL_CHECK(syclDeviceSynchronize());
         }
     
    -    for (int i = 0; i < g_device_count; ++i) {
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
             SYCL_CHECK(ggml_sycl_set_device(i));
     
    -        for (int id_other = 0; id_other < g_device_count; ++id_other) {
    +        for (int id_other = 0; id_other < ggml_sycl_info().device_count; ++id_other) {
                 if (i == id_other) {
                     continue;
                 }
    -            if (i != g_main_device && id_other != g_main_device) {
    +            if (i != main_device && id_other != main_device) {
                     continue;
                 }
     
    @@ -14434,7 +10842,7 @@ struct ggml_backend_sycl_split_buffer_type_context {
         std::array tensor_split;
     };
     
    -static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
    +static void ggml_sycl_op_mul_mat(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                      const ggml_tensor *src1, ggml_tensor *dst,
                                      ggml_sycl_op_mul_mat_t op,
                                      const bool convert_src1_to_q8_1) try {
    @@ -14469,7 +10877,6 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
         ggml_tensor_extra_gpu * src1_extra = (ggml_tensor_extra_gpu *) src1->extra;
         ggml_tensor_extra_gpu *  dst_extra = (ggml_tensor_extra_gpu *)  dst->extra;
     
    -    const bool src0_on_device = src0->backend == GGML_BACKEND_TYPE_GPU || src0->backend == GGML_BACKEND_TYPE_GPU_SPLIT;
         const bool src0_is_contiguous = ggml_is_contiguous(src0);
         const bool src1_is_contiguous = ggml_is_contiguous(src1);
     
    @@ -14489,10 +10896,10 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
         }
     
         struct dev_data {
    -        sycl_pool_alloc src0_dd_alloc;
    -        sycl_pool_alloc src1_ddf_alloc;
    -        sycl_pool_alloc src1_ddq_alloc;
    -        sycl_pool_alloc dst_dd_alloc;
    +        ggml_sycl_pool_alloc src0_dd_alloc;
    +        ggml_sycl_pool_alloc src1_ddf_alloc;
    +        ggml_sycl_pool_alloc src1_ddq_alloc;
    +        ggml_sycl_pool_alloc dst_dd_alloc;
     
             char *src0_dd = nullptr;
             float *src1_ddf = nullptr; // float
    @@ -14506,9 +10913,9 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
         dev_data dev[GGML_SYCL_MAX_DEVICES];
     
         int used_devices = 0;
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    +    queue_ptr main_stream = ctx.stream();
     
    -    for (int i = 0; i < g_device_count; ++i) {
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
             // by default, use all rows
             dev[i].row_low  = 0;
             dev[i].row_high = ne01;
    @@ -14525,7 +10932,7 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
                     }
                 }
     
    -            if (i != g_device_count - 1) {
    +            if (i != ggml_sycl_info().device_count - 1) {
                     dev[i].row_high  = ne01*tensor_split[i + 1];
                     if (dev[i].row_high < ne01) {
                         dev[i].row_high -= dev[i].row_high % rounding;
    @@ -14534,33 +10941,33 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
             }
         }
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        if ((!split && i != g_main_device) || dev[i].row_low == dev[i].row_high) {
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
    +        if ((!split && i != ctx.device) || dev[i].row_low == dev[i].row_high) {
                 continue;
             }
     
             used_devices++;
     
    -        const bool src1_on_device = src1->backend == GGML_BACKEND_TYPE_GPU && i == g_main_device;
    -        const bool  dst_on_device =  dst->backend == GGML_BACKEND_TYPE_GPU && i == g_main_device;
    +        const bool src1_on_device = i == ctx.device;
    +        const bool  dst_on_device = i == ctx.device;
     
             ggml_sycl_set_device(i);
    -        dpct::queue_ptr stream = g_syclStreams[i][0];
    +        queue_ptr stream = ctx.stream(i, 0);
     
    -        if (src0_on_device && src0_is_contiguous) {
    -            dev[i].src0_dd = (char *) src0_extra->data_device[i];
    +        if (src0_is_contiguous) {
    +            dev[i].src0_dd = (char *) src0->data;
             } else {
    -            dev[i].src0_dd = dev[i].src0_dd_alloc.alloc(ggml_nbytes(src0));
    +            dev[i].src0_dd = dev[i].src0_dd_alloc.alloc(ctx.pool(i), ggml_nbytes(src0));
             }
     
             if (src1_on_device && src1_is_contiguous) {
    -            dev[i].src1_ddf = (float *) src1_extra->data_device[i];
    +            dev[i].src1_ddf = (float *) src1->data;
             } else {
    -            dev[i].src1_ddf = dev[i].src1_ddf_alloc.alloc(ggml_nelements(src1));
    +            dev[i].src1_ddf = dev[i].src1_ddf_alloc.alloc(ctx.pool(i), ggml_nelements(src1));
             }
     
             if (convert_src1_to_q8_1) {
    -            dev[i].src1_ddq = dev[i].src1_ddq_alloc.alloc(nrows1*src1_padded_col_size*q8_1_ts/q8_1_bs);
    +            dev[i].src1_ddq = dev[i].src1_ddq_alloc.alloc(ctx.pool(i), nrows1*src1_padded_col_size*q8_1_ts/q8_1_bs);
     
                 if (src1_on_device && src1_is_contiguous) {
                     quantize_row_q8_1_sycl(dev[i].src1_ddf, dev[i].src1_ddq, ne10, nrows1, src1_padded_col_size, stream);
    @@ -14574,53 +10981,53 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
             }
     
             if (dst_on_device) {
    -            dev[i].dst_dd = (float *) dst_extra->data_device[i];
    +            dev[i].dst_dd = (float *) dst->data;
             } else {
                 const size_t size_dst_ddf = split ? (dev[i].row_high - dev[i].row_low)*ne1 : ggml_nelements(dst);
    -            dev[i].dst_dd = dev[i].dst_dd_alloc.alloc(size_dst_ddf);
    +            dev[i].dst_dd = dev[i].dst_dd_alloc.alloc(ctx.pool(i), size_dst_ddf);
             }
         }
     
         // if multiple devices are used they need to wait for the main device
         // here an event is recorded that signals that the main device has finished calculating the input data
         if (split && used_devices > 1) {
    -        ggml_sycl_set_device(g_main_device);
    +        ggml_sycl_set_device(ctx.device);
             /*
             DPCT1024:91: The original code returned the error code that was further
             consumed by the program logic. This original code was replaced with 0.
             You may need to rewrite the program logic consuming the error code.
             */
             SYCL_CHECK(CHECK_TRY_ERROR(
    -            *src0_extra->events[g_main_device][0] =
    -                g_syclStreams[g_main_device][0]->ext_oneapi_submit_barrier()));
    +            *src0_extra->events[ctx.device][0] =
    +                ctx.stream()->ext_oneapi_submit_barrier()));
         }
     
         const int64_t src1_col_stride = split && used_devices > 1 ? MUL_MAT_SRC1_COL_STRIDE : ne11;
         for (int64_t src1_col_0 = 0; src1_col_0 < ne11; src1_col_0 += src1_col_stride) {
    -        const int64_t is = split ? (src1_col_0/src1_col_stride) % MAX_STREAMS : 0;
    +        const int64_t is = split ? (src1_col_0/src1_col_stride) % GGML_SYCL_MAX_STREAMS : 0;
             const int64_t src1_ncols = src1_col_0 + src1_col_stride > ne11 ? ne11 - src1_col_0 : src1_col_stride;
     
    -        for (int i = 0; i < g_device_count; ++i) {
    -            if ((!split && i != g_main_device) || dev[i].row_low == dev[i].row_high) {
    +        for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
    +            if ((!split && i != ctx.device) || dev[i].row_low == dev[i].row_high) {
                     continue;
                 }
     
    -            const bool src1_on_device = src1->backend == GGML_BACKEND_TYPE_GPU && i == g_main_device;
    -            const bool  dst_on_device =  dst->backend == GGML_BACKEND_TYPE_GPU && i == g_main_device;
    +            const bool src1_on_device = i == ctx.device;
    +            const bool  dst_on_device = i == ctx.device;
                 const int64_t row_diff = dev[i].row_high - dev[i].row_low;
     
                 ggml_sycl_set_device(i);
    -            dpct::queue_ptr stream = g_syclStreams[i][is];
    +            queue_ptr stream = ctx.stream(i, is);
     
                 // wait for main GPU data if necessary
    -            if (split && (i != g_main_device || is != 0)) {
    +            if (split && (i != ctx.device || is != 0)) {
                     /*
                     DPCT1009:163: SYCL uses exceptions to report errors and does not
                     use the error codes. The original code was commented out and a
                     warning string was inserted. You need to rewrite this code.
                     */
                     SYCL_CHECK(CHECK_TRY_ERROR(stream->ext_oneapi_submit_barrier(
    -                    {*src0_extra->events[g_main_device][0]})));
    +                    {*src0_extra->events[ctx.device][0]})));
                 }
     
                 for (int64_t i0 = 0; i0 < ne13*ne12; ++i0) {
    @@ -14637,22 +11044,22 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
     
                     // the main device memory buffer can be on VRAM scratch, with space for all partial results
                     // in that case an offset on dst_ddf_i is needed
    -                if (dst->backend == GGML_BACKEND_TYPE_GPU && i == g_main_device) {
    +                if (i == ctx.device) {
                         dst_dd_i += dev[i].row_low; // offset is 0 if no tensor split
                     }
     
                     // copy src0, src1 to device if necessary
    -                if (src1->backend == GGML_BACKEND_TYPE_GPU && src1_is_contiguous) {
    -                    if (i != g_main_device) {
    +                if (src1_is_contiguous) {
    +                    if (i != ctx.device) {
                             if (convert_src1_to_q8_1) {
    -                            char * src1_ddq_i_source = dev[g_main_device].src1_ddq + src1_ddq_i_offset;
    +                            char * src1_ddq_i_source = dev[ctx.device].src1_ddq + src1_ddq_i_offset;
                               SYCL_CHECK(CHECK_TRY_ERROR(stream->memcpy(
                                     src1_ddq_i, src1_ddq_i_source,
                                     src1_ncols * src1_padded_col_size * q8_1_ts /
                                         q8_1_bs).wait()));
                             } else {
     
    -                            float * src1_ddf_i_source = (float *) src1_extra->data_device[g_main_device];
    +                            float * src1_ddf_i_source = (float *) src1_extra->data_device[ctx.device];
                                 src1_ddf_i_source += (i0*ne11 + src1_col_0) * ne10;
     
                                 SYCL_CHECK(CHECK_TRY_ERROR(dev2dev_memcpy(*stream, *main_stream,
    @@ -14660,14 +11067,14 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
                                     src1_ncols * ne10 * sizeof(float))));
                             }
                         }
    -                } else if (src1->backend == GGML_BACKEND_TYPE_CPU || (src1_on_device && !src1_is_contiguous)) {
    +                } else if (src1_on_device && !src1_is_contiguous) {
                         SYCL_CHECK(ggml_sycl_cpy_tensor_2d(
                                        src1_ddf_i, src1, i03, i02, src1_col_0, src1_col_0+src1_ncols, stream));
                     } else {
                         GGML_ASSERT(false);
                     }
     
    -                if (convert_src1_to_q8_1 && (src1->backend == GGML_BACKEND_TYPE_CPU || !src1_is_contiguous)) {
    +                if (convert_src1_to_q8_1 && !src1_is_contiguous) {
                         quantize_row_q8_1_sycl(src1_ddf_i, src1_ddq_i, ne10, src1_ncols, src1_padded_col_size, stream);
                         /*
                         DPCT1010:92: SYCL uses exceptions to report errors and does
    @@ -14677,14 +11084,14 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
                         SYCL_CHECK(0);
                     }
     
    -                if (src1_col_0 == 0 && (!src0_on_device || !src0_is_contiguous) && i02 % i02_divisor == 0) {
    +                if (src1_col_0 == 0 && !src0_is_contiguous && i02 % i02_divisor == 0) {
                         SYCL_CHECK(ggml_sycl_cpy_tensor_2d(src0_dd_i, src0, i03, i02/i02_divisor, dev[i].row_low, dev[i].row_high, stream));
                     }
                     if (src1->type == GGML_TYPE_F16) {
                         src1_padded_col_size = (i0 * ne11 + src1_col_0) * ne10;
                     }
                     // do the computation
    -                SYCL_CHECK(CHECK_TRY_ERROR(op(src0, src1, dst, src0_dd_i, src1_ddf_i, src1_ddq_i, dst_dd_i,
    +                SYCL_CHECK(CHECK_TRY_ERROR(op(ctx, src0, src1, dst, src0_dd_i, src1_ddf_i, src1_ddq_i, dst_dd_i,
                         dev[i].row_low, dev[i].row_high, src1_ncols, src1_padded_col_size, stream)));
                     /*
                     DPCT1010:93: SYCL uses exceptions to report errors and does not
    @@ -14695,17 +11102,7 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
     
                     // copy dst to host or other device if necessary
                     if (!dst_on_device) {
    -                    void * dst_off_device;
    -                    dpct::memcpy_direction kind;
    -                    if (dst->backend == GGML_BACKEND_TYPE_CPU) {
    -                        dst_off_device = dst->data;
    -                        kind = dpct::device_to_host;
    -                    } else if (dst->backend == GGML_BACKEND_TYPE_GPU) {
    -                        dst_off_device = dst_extra->data_device[g_main_device];
    -                        kind = dpct::device_to_device;
    -                    } else {
    -                        GGML_ASSERT(false);
    -                    }
    +                    void * dst_off_device = dst->data;
                         if (split) {
                             // src0 = weight matrix is saved as a transposed matrix for better memory layout.
                             // dst is NOT transposed.
    @@ -14716,27 +11113,10 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
                             GGML_ASSERT(dst->nb[1] == ne0*sizeof(float));
                             dhf_dst_i += src1_col_0*ne0 + dev[i].row_low;
     
    -                        //todo, dirty solution. Need be updated when device2device memcpy() is supported.
    -                        if (kind == dpct::device_to_device) {
    -                            size_t dst_size = ggml_nbytes_pad(dst);
    -                            float *host_buf = (float *)malloc(dst_size);
    -                            SYCL_CHECK(CHECK_TRY_ERROR(dpct::async_dpct_memcpy(
    -                                host_buf, ne0 * sizeof(float), dst_dd_i,
    -                                row_diff * sizeof(float), row_diff * sizeof(float),
    -                                src1_ncols, dpct::device_to_host, *stream)));
    -                            dpct::dev_mgr::instance().get_device(g_sycl_gpu_mgr->gpus[i]).queues_wait_and_throw();
    -                            SYCL_CHECK(CHECK_TRY_ERROR(dpct::async_dpct_memcpy(
    -                                dhf_dst_i, ne0 * sizeof(float), host_buf,
    -                                row_diff * sizeof(float), row_diff * sizeof(float),
    -                                src1_ncols, dpct::host_to_device, *main_stream)));
    -                            dpct::dev_mgr::instance().get_device(g_sycl_gpu_mgr->gpus[g_main_device]).queues_wait_and_throw();
    -                            free(host_buf);
    -                        } else {
    -                            SYCL_CHECK(CHECK_TRY_ERROR(dpct::async_dpct_memcpy(
    -                                dhf_dst_i, ne0 * sizeof(float), dst_dd_i,
    -                                row_diff * sizeof(float), row_diff * sizeof(float),
    -                                src1_ncols, kind, *stream)));
    -                        }
    +                        SYCL_CHECK(CHECK_TRY_ERROR(dpct::async_dpct_memcpy(
    +                            dhf_dst_i, ne0 * sizeof(float), dst_dd_i,
    +                            row_diff * sizeof(float), row_diff * sizeof(float),
    +                            src1_ncols, dpct::device_to_device, *stream)));
                         } else {
                             float * dhf_dst_i = (float *) ((char *) dst_off_device + i02*nb2 + i03*nb3);
                             GGML_ASSERT(dst->nb[1] == ne0*sizeof(float));
    @@ -14748,7 +11128,7 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
                     }
     
                     // add event for the main device to wait on until other device is done
    -                if (split && (i != g_main_device || is != 0)) {
    +                if (split && (i != ctx.device || is != 0)) {
                         /*
                         DPCT1024:94: The original code returned the error code that
                         was further consumed by the program logic. This original
    @@ -14764,28 +11144,22 @@ static void ggml_sycl_op_mul_mat(const ggml_tensor *src0,
         }
     
         // main device waits for all other devices to be finished
    -    if (split && g_device_count > 1) {
    +    if (split && ggml_sycl_info().device_count > 1) {
             int64_t is_max = (ne11 + MUL_MAT_SRC1_COL_STRIDE - 1) / MUL_MAT_SRC1_COL_STRIDE;
    -        is_max = is_max <= MAX_STREAMS ? is_max : MAX_STREAMS;
    +        is_max = is_max <= GGML_SYCL_MAX_STREAMS ? is_max : GGML_SYCL_MAX_STREAMS;
     
    -        ggml_sycl_set_device(g_main_device);
    -        for (int i = 0; i < g_device_count; ++i) {
    +        ggml_sycl_set_device(ctx.device);
    +        for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
                 if (dev[i].row_low == dev[i].row_high) {
                     continue;
                 }
                 for (int64_t is = 0; is < is_max; ++is) {
                     SYCL_CHECK(CHECK_TRY_ERROR(
    -                    g_syclStreams[g_main_device][0]->ext_oneapi_submit_barrier(
    +                    ctx.stream()->ext_oneapi_submit_barrier(
                             {*src0_extra->events[i][is]})));
                 }
             }
         }
    -
    -    if (dst->backend == GGML_BACKEND_TYPE_CPU) {
    -        SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -        SYCL_CHECK(CHECK_TRY_ERROR(
    -            dpct::get_current_device().queues_wait_and_throw()));
    -    }
     }
     catch (sycl::exception const &exc) {
       std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    @@ -14794,149 +11168,134 @@ catch (sycl::exception const &exc) {
     }
     
     
    -static void ggml_sycl_repeat(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_repeat(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_repeat);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_repeat);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_get_rows(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_get_rows(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_get_rows);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_get_rows);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_add(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_add(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_add);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_add);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_acc(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_acc(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_acc);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_acc);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_mul(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_mul(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_mul);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_mul);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_div(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_div(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_div);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_div);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_gelu(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_gelu(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_gelu);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_gelu);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_silu(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_silu(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_silu);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_silu);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_gelu_quick(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_gelu_quick(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_gelu_quick);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_gelu_quick);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_tanh(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_tanh(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_tanh);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_tanh);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_relu(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_relu(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_relu);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_relu);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_hardsigmoid(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_hardsigmoid(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_hardsigmoid);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_hardsigmoid);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_hardswish(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_hardswish(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_hardswish);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_hardswish);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_leaky_relu(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_leaky_relu(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_leaky_relu);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_leaky_relu);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_sqr(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_sqr(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_sqr);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_sqr);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_norm(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_norm(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_norm);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_norm);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_group_norm(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_group_norm(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_group_norm);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_group_norm);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_concat(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_concat(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_concat);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_concat);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_upscale(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_upscale(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_upscale);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_upscale);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -static void ggml_sycl_pad(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_pad(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_pad);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_pad);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
     
    -static void ggml_sycl_rms_norm(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_rms_norm(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_SYCL_DEBUG("call %s\n", __func__);
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_rms_norm);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_rms_norm);
         GGML_SYCL_DEBUG("call %s done\n", __func__);
     }
     
    -bool ggml_sycl_can_mul_mat(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst) {
    -    if (!g_sycl_loaded) return false;
    -
    -    const int64_t ne10 = src1->ne[0];
    -
    -    const int64_t ne0 = dst->ne[0];
    -    const int64_t ne1 = dst->ne[1];
    -
    -    // TODO: find the optimal values for these
    -    return (src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_F16 || ggml_is_quantized(src0->type)) &&
    -            src1->type == GGML_TYPE_F32 &&
    -             dst->type == GGML_TYPE_F32 &&
    -            (ne0 >= 32 && ne1 >= 32 && ne10 >= 32);
    -}
    -
    -static void ggml_sycl_mul_mat_vec_p021(const ggml_tensor *src0,
    +static void ggml_sycl_mul_mat_vec_p021(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                            const ggml_tensor *src1,
                                            ggml_tensor *dst) try {
         GGML_ASSERT(ggml_is_permuted(src0) && ggml_is_permuted(src1));
    @@ -14952,17 +11311,12 @@ static void ggml_sycl_mul_mat_vec_p021(const ggml_tensor *src0,
     
         const int64_t ne12 = src1->ne[2];
     
    -    SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    +    SYCL_CHECK(ggml_sycl_set_device(ctx.device));
    +    queue_ptr main_stream = ctx.stream();
     
    -    ggml_tensor_extra_gpu * src0_extra = (ggml_tensor_extra_gpu *) src0->extra;
    -    void * src0_ddq = src0_extra->data_device[g_main_device];
    -
    -    ggml_tensor_extra_gpu * src1_extra = (ggml_tensor_extra_gpu *) src1->extra;
    -    float * src1_ddf = (float *) src1_extra->data_device[g_main_device];
    -
    -    ggml_tensor_extra_gpu * dst_extra = (ggml_tensor_extra_gpu *) dst->extra;
    -    float * dst_ddf = (float *) dst_extra->data_device[g_main_device];
    +    void  * src0_ddq = src0->data;
    +    float * src1_ddf = (float *) src1->data;
    +    float * dst_ddf  = (float *) dst->data;
     
         ggml_mul_mat_p021_f16_f32_sycl(src0_ddq, src1_ddf, dst_ddf, ne00, ne01, ne02, ne12, main_stream);
     }
    @@ -14972,7 +11326,7 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -static void ggml_sycl_mul_mat_vec_nc(const ggml_tensor *src0,
    +static void ggml_sycl_mul_mat_vec_nc(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                          const ggml_tensor *src1,
                                          ggml_tensor *dst) try {
         GGML_ASSERT(!ggml_is_transposed(src0));
    @@ -14991,17 +11345,12 @@ static void ggml_sycl_mul_mat_vec_nc(const ggml_tensor *src0,
     
         const int64_t ne12 = src1->ne[2];
     
    -    SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    +    SYCL_CHECK(ggml_sycl_set_device(ctx.device));
    +    queue_ptr main_stream = ctx.stream();
     
    -    ggml_tensor_extra_gpu * src0_extra = (ggml_tensor_extra_gpu *) src0->extra;
    -    void * src0_ddq = src0_extra->data_device[g_main_device];
    -
    -    ggml_tensor_extra_gpu * src1_extra = (ggml_tensor_extra_gpu *) src1->extra;
    -    float * src1_ddf = (float *) src1_extra->data_device[g_main_device];
    -
    -    ggml_tensor_extra_gpu * dst_extra = (ggml_tensor_extra_gpu *) dst->extra;
    -    float * dst_ddf = (float *) dst_extra->data_device[g_main_device];
    +    void  * src0_ddq = src0->data;
    +    float * src1_ddf = (float *) src1->data;
    +    float * dst_ddf  = (float *) dst->data;
     
         const int64_t row_stride_x = nb01 / sizeof(sycl::half);
         const int64_t channel_stride_x = nb02 / sizeof(sycl::half);
    @@ -15039,7 +11388,8 @@ static void k_compute_batched_ptrs(const sycl::half *src0_as_f16,
         ptrs_dst[0*ne23 + i12 + i13*ne12] = (      char *)         dst + i12*nbd2 + i13*nbd3;
     }
     
    -static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
    +static void ggml_sycl_mul_mat_batched_sycl(ggml_backend_sycl_context & ctx,
    +                                             const ggml_tensor *src0,
                                                  const ggml_tensor *src1,
                                                  ggml_tensor *dst) try {
         GGML_ASSERT(!ggml_is_transposed(src0));
    @@ -15051,27 +11401,20 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
     
         const int64_t ne_dst = ggml_nelements(dst);
     
    -    SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    +    SYCL_CHECK(ggml_sycl_set_device(ctx.device));
    +    queue_ptr main_stream = ctx.stream();;
     
         bool no_mixed_dtypes = main_stream->get_backend() == sycl::backend::ext_oneapi_cuda ||
                                main_stream->get_backend() == sycl::backend::ext_oneapi_hip;
     
    -    SYCL_CHECK(
    -        CHECK_TRY_ERROR(g_sycl_handles[g_main_device] = main_stream));
     
    -    ggml_tensor_extra_gpu * src0_extra = (ggml_tensor_extra_gpu *) src0->extra;
    -    void * src0_ddq = src0_extra->data_device[g_main_device];
    +    void * src0_ddq = src0->data;
         sycl::half *src0_as_f16 = (sycl::half *)src0_ddq;
    -
    -    ggml_tensor_extra_gpu * src1_extra = (ggml_tensor_extra_gpu *) src1->extra;
    -    float * src1_ddf = (float *) src1_extra->data_device[g_main_device];
    -
    -    ggml_tensor_extra_gpu * dst_extra = (ggml_tensor_extra_gpu *) dst->extra;
    -    float * dst_ddf = (float *) dst_extra->data_device[g_main_device];
    +    float * src1_ddf = (float *) src1->data;
    +    float * dst_ddf = (float *) dst->data;
     
         // convert src1 to fp16
    -    sycl_pool_alloc src1_f16_alloc;
    +    ggml_sycl_pool_alloc src1_f16_alloc(ctx.pool());
         if (src1->type != GGML_TYPE_F16) {
             const to_fp16_sycl_t to_fp16_sycl = ggml_get_to_fp16_sycl(src1->type);
             const int64_t ne_src1 = ggml_nelements(src1);
    @@ -15082,7 +11425,7 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
         sycl::half *src1_f16 = src1->type == GGML_TYPE_F16 ? (sycl::half *)src1_ddf
                                                            : src1_f16_alloc.get();
     
    -    sycl_pool_alloc dst_f16;
    +    ggml_sycl_pool_alloc dst_f16(ctx.pool());
         char * dst_t;
     
         dpct::library_data_t cu_compute_type = dpct::library_data_t::real_float;
    @@ -15130,7 +11473,7 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
         if (r2 == 1 && r3 == 1 && ggml_is_contiguous_2(src0) && ggml_is_contiguous_2(src1)) {
             // there is no broadcast and src0, src1 are contiguous across dims 2, 3
             SYCL_CHECK(CHECK_TRY_ERROR(dpct::gemm_batch(
    -            *g_sycl_handles[g_main_device], oneapi::mkl::transpose::trans,
    +            *main_stream, oneapi::mkl::transpose::trans,
                 oneapi::mkl::transpose::nontrans, ne01, ne11, ne10, alpha,
                 (const char *)src0_as_f16, dpct::library_data_t::real_half,
                 nb01 / nb00, nb02 / nb00,
    @@ -15141,8 +11484,8 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
         } else {
             const int ne23 = ne12*ne13;
     
    -        sycl_pool_alloc ptrs_src(2*ne23);
    -        sycl_pool_alloc<      void *> ptrs_dst(1*ne23);
    +        ggml_sycl_pool_alloc ptrs_src(ctx.pool(), 2*ne23);
    +        ggml_sycl_pool_alloc<      void *> ptrs_dst(ctx.pool(), 1*ne23);
     
             sycl::range<3> block_dims(1, ne12, ne13);
             /*
    @@ -15171,7 +11514,7 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
                 });
             }
             SYCL_CHECK(CHECK_TRY_ERROR(dpct::gemm_batch(
    -            *g_sycl_handles[g_main_device], oneapi::mkl::transpose::trans,
    +            *main_stream, oneapi::mkl::transpose::trans,
                 oneapi::mkl::transpose::nontrans, ne01, ne11, ne10, alpha,
                 (const void **)(ptrs_src.get() + 0 * ne23),
                 dpct::library_data_t::real_half, nb01 / nb00,
    @@ -15216,19 +11559,26 @@ bool ggml_sycl_supports_dmmv(enum ggml_type type) {
         }
     }
     
    -static void ggml_sycl_mul_mat(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    -    const bool all_on_device =
    -        (src0->backend == GGML_BACKEND_TYPE_GPU || src0->backend == GGML_BACKEND_TYPE_GPU_SPLIT) &&
    -        (src1->backend == GGML_BACKEND_TYPE_GPU) &&
    -        ( dst->backend == GGML_BACKEND_TYPE_GPU);
    -
    -    const bool split = src0->backend == GGML_BACKEND_TYPE_GPU_SPLIT;
    +static void ggml_sycl_mul_mat(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +    const bool split = ggml_backend_buffer_is_sycl_split(src0->buffer);
     
         int64_t min_compute_capability = INT_MAX;
    -    for (int i = 0; i < g_device_count; ++i) {
    -        if (min_compute_capability > g_device_caps[i].cc && g_tensor_split[i] < (i + 1 < g_device_count ? g_tensor_split[i + 1] : 1.0f)) {
    -            min_compute_capability = g_device_caps[i].cc;
    +
    +    if (split) {
    +        ggml_backend_sycl_split_buffer_type_context * buft_ctx = (ggml_backend_sycl_split_buffer_type_context *) src0->buffer->buft->context;
    +        auto & tensor_split = buft_ctx->tensor_split;
    +        for (int id = 0; id < ggml_sycl_info().device_count; ++id) {
    +            // skip devices that are not going to do any work:
    +            if (tensor_split[id] >= (id + 1 < ggml_sycl_info().device_count ? tensor_split[id + 1] : 1.0f)) {
    +                continue;
    +            }
    +
    +            if (min_compute_capability > ggml_sycl_info().devices[id].cc) {
    +                min_compute_capability = ggml_sycl_info().devices[id].cc;
    +            }
             }
    +    } else {
    +        min_compute_capability    = ggml_sycl_info().devices[ctx.device].cc;
         }
     
         // check data types and tensor shapes for custom matrix multiplication kernels:
    @@ -15252,196 +11602,24 @@ static void ggml_sycl_mul_mat(const ggml_tensor * src0, const ggml_tensor * src1
     
         if (!split && src0->type == GGML_TYPE_F16 && ggml_is_permuted(src0) && ggml_is_permuted(src1) && src1->ne[1] == 1) {
             // KQ single-batch
    -        ggml_sycl_mul_mat_vec_p021(src0, src1, dst);
    +        ggml_sycl_mul_mat_vec_p021(ctx, src0, src1, dst);
         } else if (!split && src0->type == GGML_TYPE_F16 && !ggml_is_contiguous(src0) && !ggml_is_transposed(src1) && src1->ne[1] == 1) {
             // KQV single-batch
    -        ggml_sycl_mul_mat_vec_nc(src0, src1, dst);
    +        ggml_sycl_mul_mat_vec_nc(ctx, src0, src1, dst);
         } else if (!split && src0->type == GGML_TYPE_F16 && (src1->type == GGML_TYPE_F16) && !ggml_is_transposed(src0) && !ggml_is_transposed(src1) && src1->ne[2]*src1->ne[3] > 1) {
             // KQ + KQV multi-batch
    -        ggml_sycl_mul_mat_batched_sycl(src0, src1, dst);
    +        ggml_sycl_mul_mat_batched_sycl(ctx, src0, src1, dst);
         } else if (use_dequantize_mul_mat_vec) {
    -        ggml_sycl_op_mul_mat(src0, src1, dst, ggml_sycl_op_dequantize_mul_mat_vec, false);
    +        ggml_sycl_op_mul_mat(ctx, src0, src1, dst, ggml_sycl_op_dequantize_mul_mat_vec, false);
         } else if (use_mul_mat_vec_q) {
    -        ggml_sycl_op_mul_mat(src0, src1, dst, ggml_sycl_op_mul_mat_vec_q, true);
    +        ggml_sycl_op_mul_mat(ctx, src0, src1, dst, ggml_sycl_op_mul_mat_vec_q, true);
         } else if (use_mul_mat_q) {
    -        ggml_sycl_op_mul_mat(src0, src1, dst, ggml_sycl_op_mul_mat_q, true);
    +        ggml_sycl_op_mul_mat(ctx, src0, src1, dst, ggml_sycl_op_mul_mat_q, true);
         } else {
    -        ggml_sycl_op_mul_mat(src0, src1, dst, ggml_sycl_op_mul_mat_sycl, false);
    +        ggml_sycl_op_mul_mat(ctx, src0, src1, dst, ggml_sycl_op_mul_mat_sycl, false);
         }
     }
     
    -#if 0
    -template
    -static __global__ void k_compute_batched_ptrs_id(
    -        const void ** ptrs_src, void ** ptrs_dst,
    -        int ne12, int ne13,
    -        int ne23,
    -        int nb02, int nb03,
    -        int nb12, int nb13,
    -        int nb2, int nb3,
    -        int r2, int r3,
    -        ggml_type src0_type, half * src0_as_f16, int64_t src0_ne,
    -        const half * src1_f16, half * dst_f16,
    -        const int32_t * ids, const int id,
    -        Srcs... src0s) {
    -
    -    int i = ids[id];
    -
    -    half * src0_f16;
    -    const void * srcs_ar[] = { (const half *) src0s... };
    -    if (src0_type == GGML_TYPE_F16) {
    -        src0_f16 = (half *) srcs_ar[i];
    -    } else {
    -        src0_f16 = src0_as_f16;
    -        if (item_ct1.get_local_id(2) == 0 && threadIdx.y == 0) {
    -            const to_fp16_sycl_t to_fp16 = ggml_get_to_fp16_sycl(src0_type);
    -            to_fp16(srcs_ar[i], src0_f16, src0_ne, syclStreamFireAndForget);
    -        }
    -    }
    -
    -    int i13 = blockIdx.x * blockDim.x + item_ct1.get_local_id(2);
    -    int i12 = blockIdx.y * blockDim.y + threadIdx.y;
    -
    -    if (i13 >= ne13 || i12 >= ne12) {
    -        return;
    -    }
    -
    -    int i03 = i13 / r3;
    -    int i02 = i12 / r2;
    -
    -    ptrs_src[0*ne23 + i12 + i13*ne12] = (const char *) src0_f16 + i02*nb02   + i03*nb03;
    -    ptrs_src[1*ne23 + i12 + i13*ne12] = (const char *) src1_f16 + i12*nb12/2 + i13*nb13/2;
    -    ptrs_dst[0*ne23 + i12 + i13*ne12] = (      char *)  dst_f16 + i12* nb2/2 + i13* nb3/2;
    -}
    -
    -static void ggml_sycl_mul_mat_id_sycl(ggml_tensor * dst) {
    -    const struct ggml_tensor * ids = dst->src[0];
    -    const struct ggml_tensor * src1 = dst->src[1];
    -    const struct ggml_tensor * src00 = dst->src[2];
    -
    -    const int id = dst->op_params[0];
    -
    -    GGML_ASSERT(!ggml_is_transposed(src00));
    -    GGML_ASSERT(!ggml_is_transposed(src1));
    -
    -    GGML_ASSERT(src00->backend != GGML_BACKEND_TYPE_GPU_SPLIT);
    -    GGML_ASSERT(src1->type == GGML_TYPE_F32);
    -
    -    GGML_TENSOR_LOCALS(int64_t, ne0, src00, ne);
    -
    -    //const int64_t nb01 = src00->nb[1];
    -    GGML_TENSOR_LOCALS(int64_t, nb0, src00, nb);
    -
    -    GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne);
    -
    -    GGML_TENSOR_LOCALS(int64_t, nb1, src1, nb);
    -    //const int64_t nb11 = src1->nb[1];
    -
    -    const int64_t ne1 = ggml_nelements(src1);
    -    const int64_t ne  = ggml_nelements(dst);
    -
    -    SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -    syclStream_t main_stream = g_syclStreams[g_main_device][0];
    -
    -    SYCL_CHECK(syclSetStream(g_sycl_handles[g_main_device], main_stream));
    -
    -    //ggml_tensor_extra_gpu * src0_extra = (ggml_tensor_extra_gpu *) src0->extra;
    -    //void * src0_ddq = src0_extra->data_device[g_main_device];
    -    //half * src0_as_f16 = (half *) src0_ddq;
    -
    -    ggml_tensor_extra_gpu * src1_extra = (ggml_tensor_extra_gpu *) src1->extra;
    -    float * src1_ddf = (float *) src1_extra->data_device[g_main_device];
    -
    -    ggml_tensor_extra_gpu * dst_extra = (ggml_tensor_extra_gpu *) dst->extra;
    -    float * dst_ddf = (float *) dst_extra->data_device[g_main_device];
    -
    -    // convert src1 to fp16
    -    const to_fp16_sycl_t to_fp16_sycl = ggml_get_to_fp16_sycl(src1->type);
    -    GGML_ASSERT(to_fp16_sycl != nullptr);
    -
    -    size_t src1_as = 0;
    -    half * src1_as_f16 = (half *) ggml_sycl_pool_malloc(g_main_device, ne1 * sizeof(half), &src1_as);
    -    to_fp16_sycl(src1_ddf, src1_as_f16, ne1, main_stream);
    -
    -    size_t dst_as = 0;
    -    half * dst_f16 = (half *) ggml_sycl_pool_malloc(g_main_device, ne * sizeof(half), &dst_as);
    -
    -    GGML_ASSERT(ne12 % ne02 == 0);
    -    GGML_ASSERT(ne13 % ne03 == 0);
    -
    -    // broadcast factors
    -    const int64_t r2 = ne12/ne02;
    -    const int64_t r3 = ne13/ne03;
    -
    -    const half alpha_f16 = 1.0f;
    -    const half beta_f16  = 0.0f;
    -
    -    // use syclGemmBatchedEx
    -    const int ne23 = ne12*ne13;
    -
    -    const void ** ptrs_src = nullptr;
    -          void ** ptrs_dst = nullptr;
    -
    -    size_t ptrs_src_s = 0;
    -    size_t ptrs_dst_s = 0;
    -
    -    ptrs_src = (const void **) ggml_sycl_pool_malloc(g_main_device, 2*ne23*sizeof(void *), &ptrs_src_s);
    -    ptrs_dst = (      void **) ggml_sycl_pool_malloc(g_main_device, 1*ne23*sizeof(void *), &ptrs_dst_s);
    -
    -    int64_t src0_ne = ggml_nelements(src00);
    -    half * src0_as_f16 = nullptr;
    -    size_t src0_as = 0;
    -    if (src00->type != GGML_TYPE_F16) {
    -        src0_as_f16 = (half *) ggml_sycl_pool_malloc(g_main_device, src0_ne * sizeof(half), &src0_as);
    -    }
    -
    -    static_assert(GGML_MAX_SRC == 6, "GGML_MAX_SRC == 6");
    -    dim3 block_dims(ne13, ne12);
    -    k_compute_batched_ptrs_id<<<1, block_dims, 0, main_stream>>>(
    -            ptrs_src, ptrs_dst,
    -            ne12, ne13,
    -            ne23,
    -            ne00*ne01*sizeof(half), ne00*ne01*ne02*sizeof(half),
    -            nb12, nb13,
    -            dst->nb[2], dst->nb[3],
    -            r2, r3,
    -            src00->type, src0_as_f16, src0_ne,
    -            src1_as_f16, dst_f16,
    -            (const int *)((ggml_tensor_extra_gpu *)ids->extra)->data_device[g_main_device], id,
    -            dst->src[2] ? (const half *)((ggml_tensor_extra_gpu *)dst->src[2]->extra)->data_device[g_main_device] : nullptr,
    -            dst->src[3] ? (const half *)((ggml_tensor_extra_gpu *)dst->src[3]->extra)->data_device[g_main_device] : nullptr,
    -            dst->src[4] ? (const half *)((ggml_tensor_extra_gpu *)dst->src[4]->extra)->data_device[g_main_device] : nullptr,
    -            dst->src[5] ? (const half *)((ggml_tensor_extra_gpu *)dst->src[5]->extra)->data_device[g_main_device] : nullptr
    -    );
    -    SYCL_CHECK(syclGetLastError());
    -
    -    SYCL_CHECK(
    -    syclGemmBatchedEx(g_sycl_handles[g_main_device], CUBLAS_OP_T, CUBLAS_OP_N,
    -            ne01, ne11, ne10,
    -            &alpha_f16, (const void **) (ptrs_src + 0*ne23), SYCL_R_16F, ne00,
    -                        (const void **) (ptrs_src + 1*ne23), SYCL_R_16F, ne10,
    -            &beta_f16,  (      void **) (ptrs_dst + 0*ne23), SYCL_R_16F, ne01,
    -            ne23,
    -            CUBLAS_COMPUTE_16F,
    -            CUBLAS_GEMM_DEFAULT_TENSOR_OP));
    -
    -    if (src0_as != 0) {
    -        ggml_sycl_pool_free(g_main_device, src0_as_f16, src0_as);
    -    }
    -    if (ptrs_src_s != 0) {
    -        ggml_sycl_pool_free(g_main_device, ptrs_src, ptrs_src_s);
    -    }
    -    if (ptrs_dst_s != 0) {
    -        ggml_sycl_pool_free(g_main_device, ptrs_dst, ptrs_dst_s);
    -    }
    -
    -    const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(GGML_TYPE_F16);
    -    to_fp32_sycl(dst_f16, dst_ddf, ne, main_stream);
    -
    -    ggml_sycl_pool_free(g_main_device, src1_as_f16, src1_as);
    -    ggml_sycl_pool_free(g_main_device, dst_f16, dst_as);
    -}
    -#endif
     
     struct mmid_row_mapping {
         int32_t i1;
    @@ -15508,7 +11686,7 @@ __dpct_inline__ static void k_copy_dst_from_contiguous(
         }
     }
     
    -static void ggml_sycl_mul_mat_id(const ggml_tensor *src0,
    +static void ggml_sycl_mul_mat_id(ggml_backend_sycl_context & ctx, const ggml_tensor *src0,
                                      const ggml_tensor *src1,
                                      ggml_tensor *dst) try {
         GGML_ASSERT(!ggml_backend_buffer_is_sycl_split(src0->buffer) && "mul_mat_id does not support split buffers");
    @@ -15516,7 +11694,7 @@ static void ggml_sycl_mul_mat_id(const ggml_tensor *src0,
         const ggml_tensor *ids = dst->src[2];
         GGML_TENSOR_BINARY_OP_LOCALS
     
    -    const dpct::queue_ptr stream = g_syclStreams[g_main_device][0];
    +    const queue_ptr stream = ctx.stream();
     
         const int64_t n_as = ne02;
         const int64_t n_ids = ids->ne[0];
    @@ -15552,13 +11730,13 @@ static void ggml_sycl_mul_mat_id(const ggml_tensor *src0,
     
         char *src0_original = src1->backend == GGML_BACKEND_TYPE_CPU
                                   ? (char *)src0->data
    -                              : (char *)src0_extra->data_device[g_main_device];
    +                              : (char *)src0_extra->data_device[ctx.device];
         char *src1_original = src1->backend == GGML_BACKEND_TYPE_CPU
                                   ? (char *)src1->data
    -                              : (char *)src1_extra->data_device[g_main_device];
    +                              : (char *)src1_extra->data_device[ctx.device];
         char *dst_original = dst->backend == GGML_BACKEND_TYPE_CPU
                                  ? (char *)dst->data
    -                             : (char *)dst_extra->data_device[g_main_device];
    +                             : (char *)dst_extra->data_device[ctx.device];
     
         src0_row.ne[2] = 1;
         src0_row.ne[3] = 1;
    @@ -15587,22 +11765,22 @@ static void ggml_sycl_mul_mat_id(const ggml_tensor *src0,
                     const int64_t i1 = id;
                     const int64_t i2 = i12;
     
    -            src0_row_extra.data_device[g_main_device] =
    +            src0_row_extra.data_device[ctx.device] =
                     src0_original + i02*nb02;
    -            src1_row_extra.data_device[g_main_device] =
    +            src1_row_extra.data_device[ctx.device] =
                     src1_original + + i11*nb11 + i12*nb12;
    -            dst_row_extra.data_device[g_main_device] =
    +            dst_row_extra.data_device[ctx.device] =
                     dst_original + i1*nb1   + i2*nb2;
     
    -            ggml_sycl_mul_mat(&src0_row, &src1_row, &dst_row);
    +            ggml_sycl_mul_mat(ctx, &src0_row, &src1_row, &dst_row);
                 }
             }
         } else {
    -        sycl_pool_alloc src1_contiguous(sizeof(float)*ggml_nelements(src1));
    -        sycl_pool_alloc  dst_contiguous(sizeof(float)*ggml_nelements(dst));
    +        ggml_sycl_pool_alloc src1_contiguous(ctx.pool(), sizeof(float)*ggml_nelements(src1));
    +        ggml_sycl_pool_alloc  dst_contiguous(ctx.pool(), sizeof(float)*ggml_nelements(dst));
     
    -        src1_row_extra.data_device[g_main_device] = src1_contiguous.get();
    -        dst_row_extra.data_device[g_main_device]  =  dst_contiguous.get();
    +        src1_row_extra.data_device[ctx.device] = src1_contiguous.get();
    +        dst_row_extra.data_device[ctx.device]  =  dst_contiguous.get();
     
             for (int64_t i02 = 0; i02 < n_as; i02++) {
                 int64_t num_src1_rows = 0;
    @@ -15625,8 +11803,8 @@ static void ggml_sycl_mul_mat_id(const ggml_tensor *src0,
                 }
     
     
    -            sycl_pool_alloc dev_cur_src1_row(1);
    -            sycl_pool_alloc dev_row_mapping(num_src1_rows);
    +            ggml_sycl_pool_alloc dev_cur_src1_row(ctx.pool(), 1);
    +            ggml_sycl_pool_alloc dev_row_mapping(ctx.pool(), num_src1_rows);
                 SYCL_CHECK(CHECK_TRY_ERROR(
                     stream->memset(dev_cur_src1_row.get(), 0, sizeof(int))));
     
    @@ -15658,7 +11836,7 @@ static void ggml_sycl_mul_mat_id(const ggml_tensor *src0,
                     });
                 }
     
    -            src0_row_extra.data_device[g_main_device] = src0_original + i02*nb02;
    +            src0_row_extra.data_device[ctx.device] = src0_original + i02*nb02;
     
                 GGML_ASSERT(nb11 == sizeof(float)*ne10);
                 GGML_ASSERT(nb1 == sizeof(float)*ne0);
    @@ -15673,7 +11851,7 @@ static void ggml_sycl_mul_mat_id(const ggml_tensor *src0,
                 dst_row.nb[2] = num_src1_rows*nb1;
                 dst_row.nb[3] = num_src1_rows*nb1;
     
    -            ggml_sycl_mul_mat(&src0_row, &src1_row, &dst_row);
    +            ggml_sycl_mul_mat(ctx, &src0_row, &src1_row, &dst_row);
     
                 {
                     sycl::range<3> block_dims(1, 1, std::min((unsigned int)ne0, 768u));
    @@ -15703,35 +11881,29 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -static void ggml_sycl_scale(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_scale);
    +static void ggml_sycl_scale(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_scale);
     }
     
    -static void ggml_sycl_clamp(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_clamp);
    +static void ggml_sycl_clamp(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_clamp);
     }
     
    -static void ggml_sycl_cpy(const ggml_tensor *src0, const ggml_tensor *src1,
    +static void ggml_sycl_cpy(ggml_backend_sycl_context & ctx, const ggml_tensor *src0, const ggml_tensor *src1,
                               ggml_tensor *dst) try {
         const int64_t ne = ggml_nelements(src0);
         GGML_ASSERT(ne == ggml_nelements(src1));
     
    -    GGML_ASSERT(src0->backend == GGML_BACKEND_TYPE_GPU);
    -    GGML_ASSERT(src1->backend == GGML_BACKEND_TYPE_GPU);
    -
         GGML_ASSERT(ggml_nbytes(src0) <= INT_MAX);
         GGML_ASSERT(ggml_nbytes(src1) <= INT_MAX);
     
         GGML_TENSOR_BINARY_OP_LOCALS;
     
    -    SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -    dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
    +    SYCL_CHECK(ggml_sycl_set_device(ctx.device));
    +    queue_ptr main_stream = ctx.stream();
     
    -    const ggml_tensor_extra_gpu * src0_extra = (ggml_tensor_extra_gpu *) src0->extra;
    -    const ggml_tensor_extra_gpu * src1_extra = (ggml_tensor_extra_gpu *) src1->extra;
    -
    -    char * src0_ddc = (char *) src0_extra->data_device[g_main_device];
    -    char * src1_ddc = (char *) src1_extra->data_device[g_main_device];
    +    char * src0_ddc = (char *) src0->data;
    +    char * src1_ddc = (char *) src1->data;
     
         if (src0->type == GGML_TYPE_F32 && src1->type == GGML_TYPE_F32) {
             ggml_cpy_f32_f32_sycl (src0_ddc, src1_ddc, ne, ne00, ne01, ne02, nb00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb13, main_stream);
    @@ -15765,44 +11937,44 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -static void ggml_sycl_dup(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_dup(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         // TODO: why do we pass dst as src1 here?
    -    ggml_sycl_cpy(src0, dst, nullptr);
    +    ggml_sycl_cpy(ctx, src0, dst, nullptr);
         (void) src1;
     }
     
    -static void ggml_sycl_diag_mask_inf(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_diag_mask_inf);
    +static void ggml_sycl_diag_mask_inf(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_diag_mask_inf);
     }
     
    -static void ggml_sycl_soft_max(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_soft_max);
    +static void ggml_sycl_soft_max(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_soft_max);
     }
     
    -static void ggml_sycl_rope(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_rope(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_ASSERT(ggml_is_contiguous(src0)); // TODO: this restriction is temporary until non-cont support is implemented
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_rope);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_rope);
     }
     
    -static void ggml_sycl_pool2d(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_pool2d);
    +static void ggml_sycl_pool2d(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_pool2d);
     }
     
    -static void ggml_sycl_im2col(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_im2col);
    +static void ggml_sycl_im2col(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_im2col);
     }
     
    -static void ggml_sycl_sum_rows(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_sum_rows(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_ASSERT(ggml_is_contiguous(src0));
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_sum_rows);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_sum_rows);
     }
     
    -static void ggml_sycl_argsort(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_argsort(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         GGML_ASSERT(ggml_is_contiguous(src0));
    -    ggml_sycl_op_flatten(src0, src1, dst, ggml_sycl_op_argsort);
    +    ggml_sycl_op_flatten(ctx, src0, src1, dst, ggml_sycl_op_argsort);
     }
     
    -static void ggml_sycl_nop(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
    +static void ggml_sycl_nop(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
         (void) src0;
         (void) src1;
         (void) dst;
    @@ -15814,184 +11986,17 @@ static size_t ggml_nbytes_split(const struct ggml_tensor * tensor, int nrows_spl
         return nrows_split*ggml_row_size(tensor->type, tensor->ne[0]);
     }
     
    -void ggml_sycl_free_data(struct ggml_tensor *tensor) try {
    -    if (!tensor || !tensor->extra || (tensor->backend != GGML_BACKEND_TYPE_GPU && tensor->backend != GGML_BACKEND_TYPE_GPU_SPLIT) ) {
    -        return;
    -    }
    -
    -    ggml_tensor_extra_gpu * extra = (ggml_tensor_extra_gpu *) tensor->extra;
    -
    -    for (int i = 0; i < g_device_count; ++i) {
    -        const dpct::queue_ptr stream = g_syclStreams[i][0];
    -        if (extra->data_device[i] != nullptr) {
    -            SYCL_CHECK(ggml_sycl_set_device(i));
    -            SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(extra->data_device[i], *stream)));
    -        }
    -
    -        for (int64_t is = 0; is < MAX_STREAMS; ++is) {
    -            if (extra->events[i][is] != nullptr) {
    -                SYCL_CHECK(ggml_sycl_set_device(i));
    -                SYCL_CHECK(CHECK_TRY_ERROR(
    -                    dpct::destroy_event(extra->events[i][is])));
    -            }
    -        }
    -    }
    -
    -    delete extra;
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -static ggml_tensor_extra_gpu * g_temp_tensor_extras = nullptr;
    -static size_t g_temp_tensor_extra_index = 0;
    -
    -static ggml_tensor_extra_gpu * ggml_sycl_alloc_temp_tensor_extra() {
    -    if (g_temp_tensor_extras == nullptr) {
    -        g_temp_tensor_extras = new ggml_tensor_extra_gpu[GGML_SYCL_MAX_NODES];
    -    }
    -
    -    size_t alloc_index = g_temp_tensor_extra_index;
    -    g_temp_tensor_extra_index = (g_temp_tensor_extra_index + 1) % GGML_SYCL_MAX_NODES;
    -    ggml_tensor_extra_gpu * extra = &g_temp_tensor_extras[alloc_index];
    -    memset(extra, 0, sizeof(*extra));
    -
    -    return extra;
    -}
    -
    -static void ggml_sycl_assign_buffers_impl(struct ggml_tensor *tensor,
    -                                          bool scratch, bool force_inplace,
    -                                          bool no_alloc) try {
    -    if (scratch && g_scratch_size == 0) {
    -        return;
    -    }
    -
    -    tensor->backend = GGML_BACKEND_TYPE_GPU;
    -
    -    if (tensor->src[0] != nullptr && tensor->src[0]->backend == GGML_BACKEND_TYPE_CPU) {
    -        const ggml_op src0_op = tensor->src[0]->op;
    -        if (src0_op == GGML_OP_RESHAPE || src0_op == GGML_OP_TRANSPOSE || src0_op == GGML_OP_VIEW || src0_op == GGML_OP_PERMUTE) {
    -            ggml_sycl_assign_buffers_impl(tensor->src[0], scratch, force_inplace, no_alloc);
    -        }
    -    }
    -    if (tensor->op == GGML_OP_CPY && tensor->src[1]->backend == GGML_BACKEND_TYPE_CPU) {
    -        ggml_sycl_assign_buffers_impl(tensor->src[1], scratch, force_inplace, no_alloc);
    -    }
    -
    -    if (scratch && no_alloc) {
    -        return;
    -    }
    -
    -    ggml_tensor_extra_gpu * extra;
    -
    -    const bool inplace = (tensor->src[0] != nullptr && tensor->src[0]->data == tensor->data) ||
    -        tensor->op == GGML_OP_VIEW ||
    -        force_inplace;
    -    const size_t size = ggml_nbytes(tensor);
    -
    -    SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -    const dpct::queue_ptr stream = g_syclStreams[g_main_device][0];
    -
    -    if (inplace && (tensor->src[0]->backend == GGML_BACKEND_TYPE_GPU || tensor->src[0]->backend == GGML_BACKEND_TYPE_GPU_SPLIT)) {
    -        ggml_tensor_extra_gpu * src0_extra = (ggml_tensor_extra_gpu * ) tensor->src[0]->extra;
    -        char * src0_ddc = (char *) src0_extra->data_device[g_main_device];
    -        size_t offset = 0;
    -        if (tensor->op == GGML_OP_VIEW) {
    -            memcpy(&offset, tensor->op_params, sizeof(size_t));
    -        }
    -        extra = ggml_sycl_alloc_temp_tensor_extra();
    -        extra->data_device[g_main_device] = src0_ddc + offset;
    -    } else if (tensor->op == GGML_OP_CPY) {
    -        ggml_tensor_extra_gpu * src1_extra = (ggml_tensor_extra_gpu * ) tensor->src[1]->extra;
    -        void * src1_ddv = src1_extra->data_device[g_main_device];
    -        extra = ggml_sycl_alloc_temp_tensor_extra();
    -        extra->data_device[g_main_device] = src1_ddv;
    -    } else if (scratch) {
    -        GGML_ASSERT(size <= g_scratch_size);
    -        if (g_scratch_offset + size > g_scratch_size) {
    -            g_scratch_offset = 0;
    -        }
    -
    -        char * data = (char *) g_scratch_buffer;
    -        if (data == nullptr) {
    -            SYCL_CHECK(CHECK_TRY_ERROR(
    -                data = (char *)sycl::malloc_device(
    -                    g_scratch_size, *stream)));
    -            g_scratch_buffer = data;
    -        }
    -        extra = ggml_sycl_alloc_temp_tensor_extra();
    -        extra->data_device[g_main_device] = data + g_scratch_offset;
    -
    -        g_scratch_offset += size;
    -
    -        GGML_ASSERT(g_scratch_offset <= g_scratch_size);
    -    } else { // allocate new buffers outside of scratch
    -        void * data;
    -        SYCL_CHECK(CHECK_TRY_ERROR(data = (void *)sycl::malloc_device(
    -                                        size, *stream)));
    -        SYCL_CHECK(CHECK_TRY_ERROR(
    -            (*stream).memset(data, 0, size).wait()));
    -        extra = new ggml_tensor_extra_gpu;
    -        memset(extra, 0, sizeof(*extra));
    -        extra->data_device[g_main_device] = data;
    -    }
    -
    -    tensor->extra = extra;
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -void ggml_sycl_copy_to_device(struct ggml_tensor *tensor) try {
    -    GGML_ASSERT(tensor->backend == GGML_BACKEND_TYPE_GPU);
    -    GGML_ASSERT(ggml_is_contiguous(tensor));
    -
    -    ggml_tensor_extra_gpu * extra = (ggml_tensor_extra_gpu *) tensor->extra;
    -    SYCL_CHECK(ggml_sycl_set_device(g_main_device));
    -    const dpct::queue_ptr stream = g_syclStreams[g_main_device][0];
    -    SYCL_CHECK(CHECK_TRY_ERROR((*stream)
    -                                    .memcpy(extra->data_device[g_main_device],
    -                                            tensor->data, ggml_nbytes(tensor))
    -                                    .wait()));
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -void ggml_sycl_assign_buffers(struct ggml_tensor * tensor) {
    -    ggml_sycl_assign_buffers_impl(tensor, true, false, false);
    -}
    -
    -void ggml_sycl_assign_buffers_no_alloc(struct ggml_tensor * tensor) {
    -    ggml_sycl_assign_buffers_impl(tensor, true, false, true);
    -}
    -
    -void ggml_sycl_assign_buffers_no_scratch(struct ggml_tensor * tensor) {
    -    ggml_sycl_assign_buffers_impl(tensor, false, false, false);
    -}
    -
    -void ggml_sycl_assign_buffers_force_inplace(struct ggml_tensor * tensor) {
    -    ggml_sycl_assign_buffers_impl(tensor, false, true, false);
    -}
    -
     void ggml_sycl_set_main_device(const int main_device) try {
    -    if (g_main_device == main_device) return;
    +    if (dpct::get_current_device_id() == main_device) return;
         check_allow_gpu_index(main_device);
    -    g_main_device = main_device;
    -    g_main_device_id = g_sycl_gpu_mgr->gpus[main_device];
    +    dpct::select_device(main_device);
     
         if (g_ggml_sycl_debug) {
             dpct::device_info prop;
             SYCL_CHECK(CHECK_TRY_ERROR(dpct::get_device_info(
    -            prop, dpct::dev_mgr::instance().get_device(g_main_device_id))));
    +            prop, dpct::dev_mgr::instance().get_device(main_device))));
             fprintf(stderr, "Using device %d (%s) as main device\n",
    -                g_main_device_id, prop.get_name());
    +                main_device, prop.get_name());
         }
     }
     catch (sycl::exception const &exc) {
    @@ -16000,52 +12005,10 @@ catch (sycl::exception const &exc) {
       std::exit(1);
     }
     
    -void ggml_sycl_set_scratch_size(const size_t scratch_size) {
    -    // this is a hack to not completely break llama.cpp when using multiple models or contexts simultaneously
    -    // it still won't always work as expected, but it's better than nothing
    -    if (scratch_size > g_scratch_size) {
    -        ggml_sycl_free_scratch();
    -    }
    -    g_scratch_size = std::max(g_scratch_size, scratch_size);
    -}
    -
    -void ggml_sycl_free_scratch() try {
    -    if (g_scratch_buffer == nullptr) {
    -        return;
    -    }
    -    ggml_sycl_set_device(g_main_device);
    -    const dpct::queue_ptr stream = g_syclStreams[g_main_device][0];
    -
    -    SYCL_CHECK(CHECK_TRY_ERROR(
    -        sycl::free(g_scratch_buffer, *stream)));
    -    g_scratch_buffer = nullptr;
    -}
    -catch (sycl::exception const &exc) {
    -  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    -            << ", line:" << __LINE__ << std::endl;
    -  std::exit(1);
    -}
    -
    -bool ggml_sycl_compute_forward(struct ggml_compute_params * params, struct ggml_tensor * tensor) {
    +bool ggml_sycl_compute_forward(ggml_backend_sycl_context & ctx, struct ggml_tensor * tensor) {
         if (!g_sycl_loaded) return false;
     
         ggml_sycl_func_t func;
    -    const bool any_on_device = tensor->backend == GGML_BACKEND_TYPE_GPU
    -        || (tensor->src[0] != nullptr && (tensor->src[0]->backend == GGML_BACKEND_TYPE_GPU || tensor->src[0]->backend == GGML_BACKEND_TYPE_GPU_SPLIT))
    -        || (tensor->src[1] != nullptr && tensor->src[1]->backend == GGML_BACKEND_TYPE_GPU);
    -
    -    if (!any_on_device && tensor->op != GGML_OP_MUL_MAT && tensor->op != GGML_OP_MUL_MAT_ID) {
    -        return false;
    -    }
    -
    -    if (tensor->op == GGML_OP_MUL_MAT) {
    -        if (tensor->src[0]->ne[3] != tensor->src[1]->ne[3]) {
    -#ifndef NDEBUG
    -            fprintf(stderr, "%s: cannot compute %s: src0->ne[3] = %" PRId64 ", src1->ne[3] = %" PRId64 " - fallback to CPU\n", __func__, tensor->name, tensor->src[0]->ne[3], tensor->src[1]->ne[3]);
    -#endif
    -            return false;
    -        }
    -    }
     
         switch (tensor->op) {
             case GGML_OP_REPEAT:
    @@ -16118,13 +12081,13 @@ bool ggml_sycl_compute_forward(struct ggml_compute_params * params, struct ggml_
                 func = ggml_sycl_rms_norm;
                 break;
             case GGML_OP_MUL_MAT:
    -            if (!any_on_device && !ggml_sycl_can_mul_mat(tensor->src[0], tensor->src[1], tensor)) {
    +            if (tensor->src[0]->ne[3] != tensor->src[1]->ne[3]) {
                     return false;
                 }
                 func = ggml_sycl_mul_mat;
                 break;
             case GGML_OP_MUL_MAT_ID:
    -            if (!any_on_device && !ggml_sycl_can_mul_mat(tensor->src[2], tensor->src[1], tensor)) {
    +            if (tensor->src[0]->ne[3] != tensor->src[1]->ne[3]) {
                     return false;
                 }
                 func = ggml_sycl_mul_mat_id;
    @@ -16176,17 +12139,11 @@ bool ggml_sycl_compute_forward(struct ggml_compute_params * params, struct ggml_
                 return false;
         }
     
    -    if (tensor->src[0] != nullptr && tensor->src[0]->backend == GGML_BACKEND_TYPE_GPU_SPLIT) {
    -        ggml_sycl_set_peer_access(tensor->src[1]->ne[1]);
    +    if (tensor->src[0] != nullptr && ggml_backend_buffer_is_sycl_split(tensor->src[0]->buffer)) {
    +        ggml_sycl_set_peer_access(tensor->src[1]->ne[1], ctx.device);
         }
     
    -    if (params->ith != 0) {
    -        return true;
    -    }
    -    if (params->type == GGML_TASK_TYPE_INIT || params->type == GGML_TASK_TYPE_FINALIZE) {
    -        return true;
    -    }
    -    func(tensor->src[0], tensor->src[1], tensor);
    +    func(ctx, tensor->src[0], tensor->src[1], tensor);
         return true;
     }
     
    @@ -16194,13 +12151,9 @@ GGML_API GGML_CALL void   ggml_sycl_get_gpu_list(int *id_list, int max_len) try
         GGML_SYCL_DEBUG("[SYCL] call ggml_sycl_get_gpu_list\n");
         for(int i=0;igpus.size();i++){
    +    for (int i=0;i< ggml_sycl_info().device_count;i++){
             if (i>=max_len) break;
    -        id_list[i] = g_sycl_gpu_mgr->gpus[i];
    +        id_list[i] = i;
         }
         return;
     }
    @@ -16228,9 +12181,8 @@ GGML_API GGML_CALL void ggml_sycl_get_device_description(int device, char *descr
                                           size_t description_size) try {
         GGML_SYCL_DEBUG("[SYCL] call ggml_sycl_get_device_description\n");
         dpct::device_info prop;
    -    int device_id = g_sycl_gpu_mgr->gpus[device];
         SYCL_CHECK(CHECK_TRY_ERROR(dpct::get_device_info(
    -        prop, dpct::dev_mgr::instance().get_device(device_id))));
    +        prop, dpct::dev_mgr::instance().get_device(device))));
         snprintf(description, description_size, "%s", prop.get_name());
     }
     catch (sycl::exception const &exc) {
    @@ -16254,9 +12206,8 @@ GGML_CALL void ggml_backend_sycl_get_device_memory(int device, size_t *free,
         device information which may not be supported by all compilers or runtimes.
         You may need to adjust the code.
         */
    -   int device_id = g_sycl_gpu_mgr->gpus[device];
         SYCL_CHECK(CHECK_TRY_ERROR(
    -        dpct::dev_mgr::instance().get_device(device_id).get_memory_info(*free, *total)));
    +        dpct::dev_mgr::instance().get_device(device).get_memory_info(*free, *total)));
     }
     catch (sycl::exception const &exc) {
       std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    @@ -16275,32 +12226,21 @@ catch (sycl::exception const &exc) {
     struct ggml_backend_sycl_buffer_context {
         int device;
         void * dev_ptr = nullptr;
    -    ggml_tensor_extra_gpu * temp_tensor_extras = nullptr;
    -    size_t temp_tensor_extra_index = 0;
    +    queue_ptr stream;
         std::string name;
     
    -     ggml_backend_sycl_buffer_context(int device, void * dev_ptr) :
    -        device(device), dev_ptr(dev_ptr) {
    +     ggml_backend_sycl_buffer_context(int device, void * dev_ptr, queue_ptr stream) :
    +        device(device), dev_ptr(dev_ptr), stream(stream) {
                 check_allow_gpu_index(device);
    -            int id = g_sycl_gpu_mgr->gpus[device];
    -            name = (GGML_SYCL_NAME + std::to_string(id));
    +            name = (GGML_SYCL_NAME + std::to_string(device));
             }
     
    -    ~ ggml_backend_sycl_buffer_context() {
    -        delete[] temp_tensor_extras;
    -    }
     
    -    ggml_tensor_extra_gpu * ggml_sycl_alloc_temp_tensor_extra() {
    -        if (temp_tensor_extras == nullptr) {
    -            temp_tensor_extras = new ggml_tensor_extra_gpu[GGML_SYCL_MAX_NODES];
    +    ~ggml_backend_sycl_buffer_context() {
    +        if (dev_ptr != nullptr) {
    +            ggml_sycl_set_device(device);
    +            SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(dev_ptr, *stream)));
             }
    -
    -        size_t alloc_index = temp_tensor_extra_index;
    -        temp_tensor_extra_index = (temp_tensor_extra_index + 1) % GGML_SYCL_MAX_NODES;
    -        ggml_tensor_extra_gpu * extra = &temp_tensor_extras[alloc_index];
    -        memset(extra, 0, sizeof(*extra));
    -
    -        return extra;
         }
     };
     
    @@ -16317,10 +12257,7 @@ static void
     ggml_backend_sycl_buffer_free_buffer(ggml_backend_buffer_t buffer) try {
         ggml_backend_sycl_buffer_context * ctx = ( ggml_backend_sycl_buffer_context *)buffer->context;
         ggml_sycl_set_device(ctx->device);
    -    const dpct::queue_ptr stream = g_syclStreams[ctx->device][0];
     
    -    SYCL_CHECK(
    -        CHECK_TRY_ERROR(sycl::free(ctx->dev_ptr, *stream)));
         delete ctx;
     }
     catch (sycl::exception const &exc) {
    @@ -16346,11 +12283,6 @@ ggml_backend_sycl_buffer_init_tensor(ggml_backend_buffer_t buffer,
             return;
         }
     
    -    ggml_tensor_extra_gpu * extra = ctx->ggml_sycl_alloc_temp_tensor_extra();
    -
    -    extra->data_device[ctx->device] = tensor->data;
    -    tensor->backend = GGML_BACKEND_TYPE_GPU;
    -    tensor->extra = extra;
     
         if (ggml_is_quantized(tensor->type)) {
             // initialize padding to 0 to avoid possible NaN values
    @@ -16358,7 +12290,7 @@ ggml_backend_sycl_buffer_init_tensor(ggml_backend_buffer_t buffer,
             size_t padded_size = ggml_backend_buft_get_alloc_size(buffer->buft, tensor);
     
             if (padded_size > original_size && tensor->view_src == nullptr) {
    -            SYCL_CHECK(CHECK_TRY_ERROR(g_syclStreams[ctx->device][0]->memset(
    +            SYCL_CHECK(CHECK_TRY_ERROR(ctx->stream->memset(
                     (char *)tensor->data + original_size, 0,
                     padded_size - original_size).wait()));
             }
    @@ -16374,19 +12306,17 @@ static void ggml_backend_sycl_buffer_set_tensor(ggml_backend_buffer_t buffer,
                                                     ggml_tensor *tensor,
                                                     const void *data, size_t offset,
                                                     size_t size) try {
    -    GGML_ASSERT(tensor->backend == GGML_BACKEND_TYPE_GPU);
     
         ggml_backend_sycl_buffer_context * ctx = ( ggml_backend_sycl_buffer_context *)buffer->context;
     
         ggml_sycl_set_device(ctx->device);
    -    const dpct::queue_ptr stream = g_syclStreams[ctx->device][0];
    +    auto stream = &(dpct::dev_mgr::instance().get_device(ctx->device).default_queue());
         SYCL_CHECK(
             CHECK_TRY_ERROR(dpct::dev_mgr::instance().get_device(ctx->device).queues_wait_and_throw()));
         char* host_buf = (char*)malloc(size);
         memcpy(host_buf, data, size);
         SYCL_CHECK(
    -        CHECK_TRY_ERROR((*stream)
    -                             .memcpy((char *)tensor->data + offset, host_buf, size)
    +        CHECK_TRY_ERROR((*stream).memcpy((char *)tensor->data + offset, host_buf, size)
                                  .wait()));
         free(host_buf);
     }
    @@ -16400,19 +12330,14 @@ static void ggml_backend_sycl_buffer_get_tensor(ggml_backend_buffer_t buffer,
                                                     const ggml_tensor *tensor,
                                                     void *data, size_t offset,
                                                     size_t size) try {
    -    GGML_ASSERT(tensor->backend == GGML_BACKEND_TYPE_GPU);
     
         ggml_backend_sycl_buffer_context * ctx = ( ggml_backend_sycl_buffer_context *)buffer->context;
     
         ggml_sycl_set_device(ctx->device);
    -    const dpct::queue_ptr stream = g_syclStreams[ctx->device][0];
    -
    -    SYCL_CHECK(
    -        CHECK_TRY_ERROR(dpct::dev_mgr::instance().get_device(ctx->device).queues_wait_and_throw()));
    +    auto stream = dpct::dev_mgr::instance().get_device(ctx->device).default_queue();
     
         SYCL_CHECK(CHECK_TRY_ERROR(
    -        (*stream)
    -            .memcpy(data, (const char *)tensor->data + offset, size)
    +        stream.memcpy(data, (const char *)tensor->data + offset, size)
                 .wait()));
     }
     catch (sycl::exception const &exc) {
    @@ -16427,7 +12352,7 @@ ggml_backend_sycl_buffer_cpy_tensor(ggml_backend_buffer_t buffer,
                                         ggml_tensor *dst) try {
         if (ggml_backend_buffer_is_sycl(src->buffer)) {
             ggml_backend_sycl_buffer_context * src_ctx = (ggml_backend_sycl_buffer_context *)src->buffer->context;
    -        ggml_backend_sycl_buffer_context * dst_ctx = (ggml_backend_sycl_buffer_context *)buffer->context;
    +        ggml_backend_sycl_buffer_context * dst_ctx = (ggml_backend_sycl_buffer_context *)dst->buffer->context;
     
             ggml_sycl_set_device(src_ctx->device);
             /*
    @@ -16451,8 +12376,8 @@ ggml_backend_sycl_buffer_cpy_tensor(ggml_backend_buffer_t buffer,
             was inserted. You need to rewrite this code.
             */
     
    -        dpct::queue_ptr stream_dst = g_syclStreams[dst_ctx->device][0];
    -        dpct::queue_ptr stream_src = g_syclStreams[src_ctx->device][0];
    +        queue_ptr stream_dst = dst_ctx->stream;
    +        queue_ptr stream_src = src_ctx->stream;
             size_t size = ggml_nbytes(src);
     
             //todo. it's dirty solutino to walkaroud known issue:device2device cross GPUs.
    @@ -16487,7 +12412,7 @@ static void ggml_backend_sycl_buffer_clear(ggml_backend_buffer_t buffer,
          ggml_backend_sycl_buffer_context * ctx = ( ggml_backend_sycl_buffer_context *)buffer->context;
     
         ggml_sycl_set_device(ctx->device);
    -    const dpct::queue_ptr stream = g_syclStreams[ctx->device][0];
    +    queue_ptr stream = ctx->stream;
         SYCL_CHECK(
             CHECK_TRY_ERROR(dpct::get_current_device().queues_wait_and_throw()));
     
    @@ -16517,11 +12442,9 @@ static struct ggml_backend_buffer_i ggml_backend_sycl_buffer_interface = {
     struct ggml_backend_sycl_buffer_type_context {
         int device;
         std::string name;
    -};
     
    -struct ggml_backend_sycl_context {
    -    int device;
    -    std::string name;
    +    // each buffer type has its own stream
    +    queue_ptr stream = nullptr;
     };
     
     GGML_CALL static const char * ggml_backend_sycl_buffer_type_name(ggml_backend_buffer_type_t buft) {
    @@ -16534,13 +12457,13 @@ ggml_backend_sycl_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft,
                                                size_t size) try {
         ggml_backend_sycl_buffer_type_context * buft_ctx = (ggml_backend_sycl_buffer_type_context *)buft->context;
         ggml_sycl_set_device(buft_ctx->device);
    -    const dpct::queue_ptr stream = g_syclStreams[buft_ctx->device][0];
    +    const queue_ptr stream = buft_ctx->stream;
         size = std::max(size, (size_t)1); // syclMalloc returns null for size 0
     
         void * dev_ptr;
         SYCL_CHECK(CHECK_TRY_ERROR(dev_ptr = (void *)sycl::malloc_device(
                                         size, *stream)));
    -    ggml_backend_sycl_buffer_context * ctx = new  ggml_backend_sycl_buffer_context(buft_ctx->device, dev_ptr);
    +    ggml_backend_sycl_buffer_context * ctx = new  ggml_backend_sycl_buffer_context(buft_ctx->device, dev_ptr, buft_ctx->stream);
         return ggml_backend_buffer_init(buft, ggml_backend_sycl_buffer_interface, ctx, size);
     }
     catch (sycl::exception const &exc) {
    @@ -16584,26 +12507,58 @@ static ggml_backend_buffer_type_i ggml_backend_sycl_buffer_type_interface = {
         /* .is_host          = */ nullptr,
     };
     
    -ggml_backend_buffer_type_t ggml_backend_sycl_buffer_type(int device_index) {
    +ggml_backend_buffer_type_t ggml_backend_sycl_buffer_type(int device) {
    +    static std::mutex mutex;
    +    std::lock_guard lock(mutex);
    +
         GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_buffer_type\n");
     
    -    if (device_index>=g_device_count or device_index<0) {
    +    if (device>=ggml_sycl_info().device_count or device<0) {
             printf("ggml_backend_sycl_buffer_type error: device_index:%d is out of range [0, %d], miss to call ggml_backend_sycl_set_single_device()\n",
    -            device_index, g_device_count-1);
    -        GGML_ASSERT(device_indexgpus[i])},
    +                /* .context  = */ new ggml_backend_sycl_buffer_type_context{i, GGML_SYCL_NAME + std::to_string(i), stream},
                 };
             }
    -        g_ggml_backend_sycl_buffer_type_initialized = true;
    +        ggml_backend_sycl_buffer_type_initialized = true;
         }
    -    return &ggml_backend_sycl_buffer_types[device_index];
    +    return &ggml_backend_sycl_buffer_types[device];
    +}
    +
    +ggml_backend_buffer_type_t ggml_backend_sycl_buffer_type(ggml_backend_sycl_context * ctx) {
    +    GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_buffer_type\n");
    +
    +    int device = ctx->device;
    +    if (device>=ggml_sycl_info().device_count or device<0) {
    +        printf("ggml_backend_sycl_buffer_type error: device_index:%d is out of range [0, %d], miss to call ggml_backend_sycl_set_single_device()\n",
    +            device, ggml_sycl_info().device_count-1);
    +        GGML_ASSERT(devicestream(i, 0)},
    +            };
    +        }
    +        ggml_backend_sycl_buffer_type_initialized = true;
    +    }
    +    return &ggml_backend_sycl_buffer_types[device];
     }
     
     // sycl split buffer type
    @@ -16613,7 +12568,7 @@ static void get_row_split(int64_t * row_low, int64_t * row_high, const ggml_tens
     
         *row_low = id == 0 ? 0 : nrows*tensor_split[id];
         *row_low -= *row_low % rounding;
    -    if (id == g_device_count - 1) {
    +    if (id == ggml_sycl_info().device_count - 1) {
             *row_high = nrows;
         } else {
             *row_high = nrows*tensor_split[id + 1];
    @@ -16624,9 +12579,8 @@ static void get_row_split(int64_t * row_low, int64_t * row_high, const ggml_tens
     struct ggml_backend_sycl_split_buffer_context {
         ~ggml_backend_sycl_split_buffer_context() try {
             for (ggml_tensor_extra_gpu * extra : tensor_extras) {
    -            for (int i = 0; i < g_device_count; ++i) {
    -                // int id = g_sycl_gpu_mgr->gpus[i];
    -                for (int64_t is = 0; is < MAX_STREAMS; ++is) {
    +            for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
    +                for (int64_t is = 0; is < GGML_SYCL_MAX_STREAMS; ++is) {
                         if (extra->events[i][is] != nullptr) {
                             /*
                             DPCT1009:206: SYCL uses exceptions to report errors and
    @@ -16647,7 +12601,7 @@ struct ggml_backend_sycl_split_buffer_context {
                         */
                         ggml_sycl_set_device(i);
                         SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(
    -                        extra->data_device[i], *g_syclStreams[i][0])));
    +                        extra->data_device[i], *(streams[i]))));
                     }
                 }
                 delete extra;
    @@ -16660,6 +12614,7 @@ struct ggml_backend_sycl_split_buffer_context {
         }
     
         std::vector tensor_extras;
    +    std::vector streams;
     };
     
     GGML_CALL static const char * ggml_backend_sycl_split_buffer_get_name(ggml_backend_buffer_t buffer) {
    @@ -16697,9 +12652,9 @@ ggml_backend_sycl_split_buffer_init_tensor(ggml_backend_buffer_t buffer,
         ggml_tensor_extra_gpu * extra = new ggml_tensor_extra_gpu{};
     
         ctx->tensor_extras.push_back(extra);
    +        ctx->streams.push_back(&(dpct::get_current_device().default_queue()));
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        // int id = g_sycl_gpu_mgr->gpus[i];
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
             int64_t row_low, row_high;
             get_row_split(&row_low, &row_high, tensor, buft_ctx->tensor_split, i);
     
    @@ -16719,6 +12674,7 @@ ggml_backend_sycl_split_buffer_init_tensor(ggml_backend_buffer_t buffer,
             // FIXME: do not crash if cudaMalloc fails
             // currently, init_tensor cannot fail, it needs to be fixed in ggml-backend first
             ggml_sycl_set_device(i);
    +        const queue_ptr stream = ctx->streams[i];
             char * buf;
             /*
             DPCT1009:208: SYCL uses exceptions to report errors and does not use the
    @@ -16726,7 +12682,7 @@ ggml_backend_sycl_split_buffer_init_tensor(ggml_backend_buffer_t buffer,
             was inserted. You need to rewrite this code.
             */
             SYCL_CHECK(CHECK_TRY_ERROR(buf = (char *)sycl::malloc_device(
    -                                        size, *g_syclStreams[i][0])));
    +                                        size, *stream)));
     
             // set padding to 0 to avoid possible NaN values
             if (size > original_size) {
    @@ -16736,14 +12692,14 @@ ggml_backend_sycl_split_buffer_init_tensor(ggml_backend_buffer_t buffer,
                 string was inserted. You need to rewrite this code.
                 */
                 SYCL_CHECK(CHECK_TRY_ERROR(
    -                (*g_syclStreams[i][0])
    +                (*stream)
                         .memset(buf + original_size, 0, size - original_size)
                         .wait()));
             }
     
             extra->data_device[i] = buf;
     
    -        for (int64_t is = 0; is < MAX_STREAMS; ++is) {
    +        for (int64_t is = 0; is < GGML_SYCL_MAX_STREAMS; ++is) {
                 /*
                 DPCT1009:210: SYCL uses exceptions to report errors and does not use
                 the error codes. The original code was commented out and a warning
    @@ -16770,14 +12726,14 @@ ggml_backend_sycl_split_buffer_set_tensor(ggml_backend_buffer_t buffer,
         GGML_ASSERT(offset == 0);
         GGML_ASSERT(size == ggml_nbytes(tensor));
     
    +    ggml_backend_sycl_split_buffer_context * ctx = (ggml_backend_sycl_split_buffer_context *)buffer->context;
         ggml_backend_sycl_split_buffer_type_context * buft_ctx = (ggml_backend_sycl_split_buffer_type_context *)buffer->buft->context;
     
         const int64_t ne0 = tensor->ne[0];
         const size_t nb1 = tensor->nb[1];
         ggml_tensor_extra_gpu * extra = (ggml_tensor_extra_gpu *)tensor->extra;
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        // int id = g_sycl_gpu_mgr->gpus[i];
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
             int64_t row_low, row_high;
             get_row_split(&row_low, &row_high, tensor, buft_ctx->tensor_split, i);
     
    @@ -16802,8 +12758,9 @@ ggml_backend_sycl_split_buffer_set_tensor(ggml_backend_buffer_t buffer,
             was inserted. You need to rewrite this code.
             */
             ggml_sycl_set_device(i);
    +        const queue_ptr stream = ctx->streams[i];
             SYCL_CHECK(CHECK_TRY_ERROR(
    -            (*g_syclStreams[i][0])
    +            (*stream)
                     .memcpy(extra->data_device[i], buf_host, original_size)
                     .wait()));
         }
    @@ -16822,14 +12779,14 @@ ggml_backend_sycl_split_buffer_get_tensor(ggml_backend_buffer_t buffer,
         GGML_ASSERT(offset == 0);
         GGML_ASSERT(size == ggml_nbytes(tensor));
     
    +    ggml_backend_sycl_split_buffer_context * ctx = (ggml_backend_sycl_split_buffer_context *)buffer->context;
         ggml_backend_sycl_split_buffer_type_context * buft_ctx = (ggml_backend_sycl_split_buffer_type_context *)buffer->buft->context;
     
         const int64_t ne0 = tensor->ne[0];
         const size_t nb1 = tensor->nb[1];
         ggml_tensor_extra_gpu * extra = (ggml_tensor_extra_gpu *)tensor->extra;
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        // int id = g_sycl_gpu_mgr->gpus[i];
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
             int64_t row_low, row_high;
             get_row_split(&row_low, &row_high, tensor, buft_ctx->tensor_split, i);
     
    @@ -16854,8 +12811,9 @@ ggml_backend_sycl_split_buffer_get_tensor(ggml_backend_buffer_t buffer,
             was inserted. You need to rewrite this code.
             */
             ggml_sycl_set_device(i);
    +        const queue_ptr stream = ctx->streams[i];
             SYCL_CHECK(CHECK_TRY_ERROR(
    -            (*g_syclStreams[i][0])
    +            (*stream)
                     .memcpy(buf_host, extra->data_device[i], original_size)
                     .wait()));
         }
    @@ -16911,8 +12869,7 @@ GGML_CALL static size_t ggml_backend_sycl_split_buffer_type_get_alloc_size(ggml_
     
         const int64_t ne0 = tensor->ne[0];
     
    -    for (int i = 0; i < g_device_count; ++i) {
    -        // int id = g_sycl_gpu_mgr->gpus[i];
    +    for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
             int64_t row_low, row_high;
             get_row_split(&row_low, &row_high, tensor, ctx->tensor_split, i);
     
    @@ -16948,8 +12905,11 @@ static ggml_backend_buffer_type_i ggml_backend_sycl_split_buffer_type_interface
     };
     
     GGML_CALL ggml_backend_buffer_type_t ggml_backend_sycl_split_buffer_type(const float * tensor_split) {
    +    static std::mutex mutex;
    +    std::lock_guard lock(mutex);
    +
         GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_split_buffer_type\n");
    -    ggml_init_sycl();
    +    ggml_check_sycl();
         // FIXME: this is not thread safe
         static std::map, struct ggml_backend_buffer_type> buft_map;
     
    @@ -16957,16 +12917,14 @@ GGML_CALL ggml_backend_buffer_type_t ggml_backend_sycl_split_buffer_type(const f
     
         bool all_zero = tensor_split == nullptr || std::all_of(tensor_split, tensor_split + GGML_SYCL_MAX_DEVICES, [](float x) { return x == 0.0f; });
         if (all_zero) {
    -        tensor_split_arr = g_default_tensor_split;
    +        tensor_split_arr = ggml_sycl_info().default_tensor_split;
         } else {
             float split_sum = 0.0f;
    -        for (int i = 0; i < g_device_count; ++i) {
    -            // int id = g_sycl_gpu_mgr->gpus[i];
    +        for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
                 tensor_split_arr[i] = split_sum;
                 split_sum += tensor_split[i];
             }
    -        for (int i = 0; i < g_device_count; ++i) {
    -            // int id = g_sycl_gpu_mgr->gpus[i];
    +        for (int i = 0; i < ggml_sycl_info().device_count; ++i) {
                 tensor_split_arr[i] /= split_sum;
             }
         }
    @@ -17064,9 +13022,11 @@ GGML_CALL static void ggml_backend_sycl_set_tensor_async(ggml_backend_t backend,
                                                    const void *data, size_t offset,
                                                    size_t size) try {
         ggml_backend_sycl_context * sycl_ctx = (ggml_backend_sycl_context *)backend->context;
    -    GGML_ASSERT(tensor->buffer->buft == ggml_backend_sycl_buffer_type(sycl_ctx->device) && "unsupported buffer type");
    -    GGML_ASSERT(tensor->backend == GGML_BACKEND_TYPE_GPU);
    -    SYCL_CHECK(CHECK_TRY_ERROR(g_syclStreams[sycl_ctx->device][0]->memcpy(
    +    ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;
    +
    +    GGML_ASSERT(buf->buft == ggml_backend_sycl_buffer_type(sycl_ctx->device) && "unsupported buffer type");
    +    const queue_ptr stream = sycl_ctx->stream(sycl_ctx->device, 0);
    +    SYCL_CHECK(CHECK_TRY_ERROR((stream)->memcpy(
             (char *)tensor->data + offset, data, size).wait()));
     }
     catch (sycl::exception const &exc) {
    @@ -17080,9 +13040,11 @@ GGML_CALL static void ggml_backend_sycl_get_tensor_async(ggml_backend_t backend,
                                                    void *data, size_t offset,
                                                    size_t size) try {
         ggml_backend_sycl_context * sycl_ctx = (ggml_backend_sycl_context *)backend->context;
    -    GGML_ASSERT(tensor->buffer->buft == ggml_backend_sycl_buffer_type(sycl_ctx->device) && "unsupported buffer type");
    -    GGML_ASSERT(tensor->backend == GGML_BACKEND_TYPE_GPU);
    -    SYCL_CHECK(CHECK_TRY_ERROR(g_syclStreams[sycl_ctx->device][0]->memcpy(
    +    ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;
    +
    +    GGML_ASSERT(buf->buft == ggml_backend_sycl_buffer_type(sycl_ctx->device) && "unsupported buffer type");
    +    const queue_ptr stream = sycl_ctx->stream(sycl_ctx->device, 0);
    +    SYCL_CHECK(CHECK_TRY_ERROR((stream)->memcpy(
             data, (const char *)tensor->data + offset, size).wait()));
     }
     catch (sycl::exception const &exc) {
    @@ -17101,7 +13063,8 @@ GGML_CALL static bool ggml_backend_sycl_cpy_tensor_async(ggml_backend_t backend,
             error codes. The original code was commented out and a warning string
             was inserted. You need to rewrite this code.
             */
    -        SYCL_CHECK(CHECK_TRY_ERROR(g_syclStreams[sycl_ctx->device][0]->memcpy(
    +        const queue_ptr stream = sycl_ctx->stream(sycl_ctx->device, 0);
    +        SYCL_CHECK(CHECK_TRY_ERROR((stream)->memcpy(
                 dst->data, src->data, ggml_nbytes(dst)).wait()));
             return true;
         }
    @@ -17116,7 +13079,8 @@ catch (sycl::exception const &exc) {
     
     static void ggml_backend_sycl_synchronize(ggml_backend_t backend) try {
         ggml_backend_sycl_context * sycl_ctx = (ggml_backend_sycl_context *)backend->context;
    -    SYCL_CHECK(CHECK_TRY_ERROR(g_syclStreams[sycl_ctx->device][0]->wait()));
    +    const queue_ptr stream = sycl_ctx->stream(sycl_ctx->device, 0);
    +    SYCL_CHECK(CHECK_TRY_ERROR((stream)->wait()));
     
         UNUSED(backend);
     }
    @@ -17130,28 +13094,21 @@ GGML_CALL static ggml_status ggml_backend_sycl_graph_compute(ggml_backend_t back
         ggml_backend_sycl_context * sycl_ctx = (ggml_backend_sycl_context *)backend->context;
         ggml_sycl_set_main_device(sycl_ctx->device);
     
    -    ggml_compute_params params = {};
    -    params.type = GGML_TASK_TYPE_COMPUTE;
    -    params.ith = 0;
    +
         for (int i = 0; i < cgraph->n_nodes; i++) {
             ggml_tensor * node = cgraph->nodes[i];
             if (ggml_is_empty(node) || node->op == GGML_OP_RESHAPE || node->op == GGML_OP_TRANSPOSE || node->op == GGML_OP_VIEW || node->op == GGML_OP_PERMUTE || node->op == GGML_OP_NONE) {
                 continue;
             }
     #ifndef NDEBUG
    -        assert(node->backend == GGML_BACKEND_TYPE_GPU || node->backend == GGML_BACKEND_TYPE_GPU_SPLIT);
             assert(node->buffer->buft == ggml_backend_sycl_buffer_type(sycl_ctx->device));
    -        assert(node->extra != nullptr);
    -
             for (int j = 0; j < GGML_MAX_SRC; j++) {
                 if (node->src[j] != nullptr) {
    -                assert(node->src[j]->backend == GGML_BACKEND_TYPE_GPU || node->src[j]->backend == GGML_BACKEND_TYPE_GPU_SPLIT);
                     assert(node->src[j]->buffer->buft == ggml_backend_sycl_buffer_type(sycl_ctx->device));
    -                assert(node->src[j]->extra != nullptr);
                 }
             }
     #endif
    -        bool ok = ggml_sycl_compute_forward(¶ms, node);
    +        bool ok = ggml_sycl_compute_forward(*sycl_ctx, node);
             if (!ok) {
                 fprintf(stderr, "%s: error: op not supported %s (%s)\n", __func__, node->name, ggml_op_name(node->op));
             }
    @@ -17332,16 +13289,14 @@ static ggml_guid_t ggml_backend_sycl_guid() {
     
     GGML_CALL ggml_backend_t ggml_backend_sycl_init(int device) {
         GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_init\n");
    -    ggml_init_sycl();
    +    ggml_check_sycl();
     
         check_allow_gpu_index(device);
     
    -    // not strictly necessary, but it may reduce the overhead of the first graph_compute
    -    ggml_sycl_set_main_device(device);
    -    int id = g_sycl_gpu_mgr->gpus[device];
    -    ggml_backend_sycl_context * ctx = new ggml_backend_sycl_context {
    -        /* .device = */ device,
    -        /* .name   = */ GGML_SYCL_NAME + std::to_string(id),
    +    ggml_backend_sycl_context * ctx = new ggml_backend_sycl_context(device);
    +    if (ctx == nullptr) {
    +        fprintf(stderr, "%s: error: failed to allocate context\n", __func__);
    +        return nullptr;
         };
     
         ggml_backend_t sycl_backend = new ggml_backend {
    @@ -17359,8 +13314,7 @@ bool ggml_backend_is_sycl(ggml_backend_t backend) {
     
     GGML_CALL int ggml_backend_sycl_get_device_count() {
         GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_get_device_count\n");
    -    if (!g_sycl_gpu_mgr) g_sycl_gpu_mgr = new sycl_gpu_mgr();
    -    return g_sycl_gpu_mgr->get_gpu_count();
    +    return ggml_sycl_info().device_count;
     }
     
     GGML_CALL static ggml_backend_t ggml_backend_reg_sycl_init(const char * params, void * user_data) {
    @@ -17370,60 +13324,14 @@ GGML_CALL static ggml_backend_t ggml_backend_reg_sycl_init(const char * params,
         UNUSED(params);
     }
     
    -GGML_API GGML_CALL int ggml_backend_sycl_get_device_index(int device_id) {
    -    GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_get_device_index\n");
    -    return g_sycl_gpu_mgr->get_index(device_id);
    -}
    -
    -GGML_API GGML_CALL int ggml_backend_sycl_get_device_id(int device_index) {
    -    GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_get_device_id\n");
    -    return g_sycl_gpu_mgr->gpus[device_index];
    -}
    -
    -GGML_API GGML_CALL void ggml_backend_sycl_set_single_device_mode(int main_gpu_id) {
    -    ggml_init_sycl();
    -    GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_set_single_device_mode\n");
    -    fprintf(stderr, "ggml_backend_sycl_set_single_device: use single device: [%d]\n", main_gpu_id);
    -    GGML_ASSERT(main_gpu_idget_gpu_count());
    -    g_ggml_backend_sycl_buffer_type_initialized = false;
    -}
    -
    -GGML_API GGML_CALL void ggml_backend_sycl_set_mul_device_mode() {
    -    ggml_init_sycl();
    -    GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_set_mul_device_mode\n");
    -
    -    if (g_ggml_sycl_backend_gpu_mode == SYCL_MUL_GPU_MODE) {
    -        return;
    -    }
    -
    -    fprintf(stderr, "ggml_backend_sycl_set_mul_device_mode: true\n");
    -
    -    if (g_sycl_gpu_mgr) {
    -        delete g_sycl_gpu_mgr;
    -    }
    -    g_sycl_gpu_mgr = new sycl_gpu_mgr();
    -    g_ggml_sycl_backend_gpu_mode = SYCL_MUL_GPU_MODE;
    -    ggml_init_by_gpus(g_sycl_gpu_mgr->get_gpu_count());
    -    g_ggml_backend_sycl_buffer_type_initialized = false;
    -}
    -
     extern "C" int ggml_backend_sycl_reg_devices();
     
     int ggml_backend_sycl_reg_devices() {
    -    ggml_backend_sycl_set_mul_device_mode();
    -    assert(g_device_count>0);
    -    for (int i = 0; i < g_device_count; i++) {
    -        int id = g_sycl_gpu_mgr->gpus[i];
    +    assert(ggml_sycl_info().device_count>0);
    +    for (int i = 0; i < ggml_sycl_info().device_count; i++) {
             char name[128];
    -        snprintf(name, sizeof(name), "%s%d", GGML_SYCL_NAME, id);
    +        snprintf(name, sizeof(name), "%s%d", GGML_SYCL_NAME, i);
             ggml_backend_register(name, ggml_backend_reg_sycl_init, ggml_backend_sycl_buffer_type(i), (void *) (intptr_t) i);
         }
    -    return g_device_count;
    +    return ggml_sycl_info().device_count;
     }
    diff --git a/ggml-sycl.h b/ggml-sycl.h
    index a9f776fc1..451938fc4 100644
    --- a/ggml-sycl.h
    +++ b/ggml-sycl.h
    @@ -8,14 +8,12 @@
     
     #include "ggml.h"
     #include "ggml-backend.h"
    +#include "ggml-sycl/presets.hpp"
     
     #ifdef  __cplusplus
     extern "C" {
     #endif
     
    -#define GGML_SYCL_MAX_DEVICES       48
    -#define GGML_SYCL_NAME "SYCL"
    -
     // backend API
     GGML_API ggml_backend_t ggml_backend_sycl_init(int device);
     
    @@ -33,13 +31,6 @@ GGML_API GGML_CALL void   ggml_sycl_get_gpu_list(int *id_list, int max_len);
     GGML_API GGML_CALL void   ggml_sycl_get_device_description(int device, char *description, size_t description_size);
     GGML_API GGML_CALL int   ggml_backend_sycl_get_device_count();
     GGML_API GGML_CALL void ggml_backend_sycl_get_device_memory(int device, size_t *free, size_t *total);
    -GGML_API GGML_CALL int ggml_backend_sycl_get_device_index(int device_id);
    -
    -// TODO: these are temporary
    -//       ref: https://github.com/ggerganov/llama.cpp/pull/6022#issuecomment-1992615670
    -GGML_API GGML_CALL int ggml_backend_sycl_get_device_id(int device_index);
    -GGML_API GGML_CALL void ggml_backend_sycl_set_single_device_mode(int main_gpu_id);
    -GGML_API GGML_CALL void ggml_backend_sycl_set_mul_device_mode();
     
     // SYCL doesn't support registering host memory, keep here for reference
     // GGML_API GGML_CALL bool ggml_backend_sycl_register_host_buffer(void * buffer, size_t size);
    diff --git a/ggml-sycl/backend.hpp b/ggml-sycl/backend.hpp
    new file mode 100644
    index 000000000..88bae5967
    --- /dev/null
    +++ b/ggml-sycl/backend.hpp
    @@ -0,0 +1,18 @@
    +//
    +// MIT license
    +// Copyright (C) 2024 Intel Corporation
    +// SPDX-License-Identifier: MIT
    +//
    +
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +
    +#ifndef GGML_SYCL_BACKEND_HPP
    +#define GGML_SYCL_BACKEND_HPP
    +
    +#include "common.hpp"
    +
    +#endif // GGML_SYCL_BACKEND_HPP
    diff --git a/ggml-sycl/common.cpp b/ggml-sycl/common.cpp
    new file mode 100644
    index 000000000..e878f4f50
    --- /dev/null
    +++ b/ggml-sycl/common.cpp
    @@ -0,0 +1,53 @@
    +//
    +// MIT license
    +// Copyright (C) 2024 Intel Corporation
    +// SPDX-License-Identifier: MIT
    +//
    +
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +
    +#include "common.hpp"
    +
    +int get_current_device_id() {
    +  return dpct::dev_mgr::instance().current_device_id();
    +}
    +
    +void* ggml_sycl_host_malloc(size_t size) try {
    +  if (getenv("GGML_SYCL_NO_PINNED") != nullptr) {
    +    return nullptr;
    +  }
    +
    +  void* ptr = nullptr;
    +  // allow to use dpct::get_in_order_queue() for host malloc
    +  dpct::err0 err = CHECK_TRY_ERROR(
    +      ptr = (void*)sycl::malloc_host(size, dpct::get_in_order_queue()));
    +
    +  if (err != 0) {
    +    // clear the error
    +    fprintf(
    +        stderr,
    +        "WARNING: failed to allocate %.2f MB of pinned memory: %s\n",
    +        size / 1024.0 / 1024.0,
    +        "syclGetErrorString is not supported");
    +    return nullptr;
    +  }
    +
    +  return ptr;
    +} catch (sycl::exception const& exc) {
    +  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    +            << ", line:" << __LINE__ << std::endl;
    +  std::exit(1);
    +}
    +
    +void ggml_sycl_host_free(void* ptr) try {
    +  // allow to use dpct::get_in_order_queue() for host malloc
    +  SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(ptr, dpct::get_in_order_queue())));
    +} catch (sycl::exception const& exc) {
    +  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    +            << ", line:" << __LINE__ << std::endl;
    +  std::exit(1);
    +}
    diff --git a/ggml-sycl/common.hpp b/ggml-sycl/common.hpp
    new file mode 100644
    index 000000000..414c37eed
    --- /dev/null
    +++ b/ggml-sycl/common.hpp
    @@ -0,0 +1,298 @@
    +//
    +// MIT license
    +// Copyright (C) 2024 Intel Corporation
    +// SPDX-License-Identifier: MIT
    +//
    +
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +
    +#ifndef GGML_SYCL_COMMON_HPP
    +#define GGML_SYCL_COMMON_HPP
    +
    +#include 
    +#include 
    +
    +#include "dpct/helper.hpp"
    +#include "presets.hpp"
    +
    +#define GGML_COMMON_DECL_SYCL
    +#define GGML_COMMON_IMPL_SYCL
    +#include "ggml-common.h"
    +
    +void* ggml_sycl_host_malloc(size_t size);
    +void ggml_sycl_host_free(void* ptr);
    +
    +static int g_ggml_sycl_debug = 0;
    +#define GGML_SYCL_DEBUG(...)        \
    +  do {                              \
    +    if (g_ggml_sycl_debug)          \
    +      fprintf(stderr, __VA_ARGS__); \
    +  } while (0)
    +
    +#define CHECK_TRY_ERROR(expr)                                            \
    +  [&]() {                                                                \
    +    try {                                                                \
    +      expr;                                                              \
    +      return dpct::success;                                              \
    +    } catch (std::exception const& e) {                                  \
    +      std::cerr << e.what() << "\nException caught at file:" << __FILE__ \
    +                << ", line:" << __LINE__ << ", func:" << __func__        \
    +                << std::endl;                                            \
    +      return dpct::default_error;                                        \
    +    }                                                                    \
    +  }()
    +
    +// #define DEBUG_SYCL_MALLOC
    +
    +static int g_work_group_size = 0;
    +// typedef sycl::half ggml_fp16_t;
    +
    +#define __SYCL_ARCH__ DPCT_COMPATIBILITY_TEMP
    +#define VER_4VEC 610 // todo for hardward optimize.
    +#define VER_GEN9 700 // todo for hardward optimize.
    +#define VER_GEN12 1000000 // todo for hardward optimize.
    +#define VER_GEN13 (VER_GEN12 + 1030) // todo for hardward optimize.
    +
    +#define GGML_SYCL_MAX_NODES 8192 // TODO: adapt to hardwares
    +
    +// define for XMX in Intel GPU
    +// TODO: currently, it's not used for XMX really.
    +#if !defined(GGML_SYCL_FORCE_MMQ)
    +    #define SYCL_USE_XMX
    +#endif
    +
    +// max batch size to use MMQ kernels when tensor cores are available
    +#define MMQ_MAX_BATCH_SIZE 32
    +
    +#if defined(_MSC_VER)
    +#pragma warning(disable : 4244 4267) // possible loss of data
    +#endif
    +
    +// dmmv = dequantize_mul_mat_vec
    +#ifndef GGML_SYCL_DMMV_X
    +#define GGML_SYCL_DMMV_X 32
    +#endif
    +#ifndef GGML_SYCL_MMV_Y
    +#define GGML_SYCL_MMV_Y 1
    +#endif
    +
    +typedef sycl::queue *queue_ptr;
    +
    +enum ggml_sycl_backend_gpu_mode {
    +  SYCL_UNSET_GPU_MODE = -1,
    +  SYCL_SINGLE_GPU_MODE = 0,
    +  SYCL_MUL_GPU_MODE
    +};
    +
    +static_assert(sizeof(sycl::half) == sizeof(ggml_fp16_t), "wrong fp16 size");
    +
    +static void crash() {
    +  int* ptr = NULL;
    +  *ptr = 0;
    +}
    +
    +[[noreturn]] static void ggml_sycl_error(
    +    const char* stmt,
    +    const char* func,
    +    const char* file,
    +    const int line,
    +    const char* msg) {
    +  fprintf(stderr, "SYCL error: %s: %s\n", stmt, msg);
    +  fprintf(stderr, "  in function %s at %s:%d\n", func, file, line);
    +  GGML_ASSERT(!"SYCL error");
    +}
    +
    +#define SYCL_CHECK(err)                     \
    +  do {                                      \
    +    auto err_ = (err);                      \
    +    if (err_ != 0)                          \
    +      ggml_sycl_error(                      \
    +          #err,                             \
    +          __func__,                         \
    +          __FILE__,                         \
    +          __LINE__,                         \
    +          "Meet error in this line code!"); \
    +  } while (0)
    +
    +#if DPCT_COMPAT_RT_VERSION >= 11100
    +#define GGML_SYCL_ASSUME(x) __builtin_assume(x)
    +#else
    +#define GGML_SYCL_ASSUME(x)
    +#endif // DPCT_COMPAT_RT_VERSION >= 11100
    +
    +#ifdef GGML_SYCL_F16
    +typedef sycl::half dfloat; // dequantize float
    +typedef sycl::half2 dfloat2;
    +#else
    +typedef float dfloat; // dequantize float
    +typedef sycl::float2 dfloat2;
    +#endif // GGML_SYCL_F16
    +
    +#define MMVQ_MAX_BATCH_SIZE  8
    +
    +static const int8_t kvalues_iq4nl[16]={-127, -104, -83, -65, -49, -35, -22, -10, 1, 13, 25, 38, 53, 69, 89, 113};
    +
    +static int g_all_sycl_device_count = -1;
    +static bool g_ggml_backend_sycl_buffer_type_initialized = false;
    +
    +static ggml_sycl_backend_gpu_mode g_ggml_sycl_backend_gpu_mode =
    +    SYCL_UNSET_GPU_MODE;
    +
    +static void* g_scratch_buffer = nullptr;
    +static size_t g_scratch_size = 0; // disabled by default
    +static size_t g_scratch_offset = 0;
    +
    +[[noreturn]] static inline void bad_arch(const sycl::stream& stream_ct1) {
    +  stream_ct1 << "ERROR: ggml-sycl was compiled without support for the "
    +                "current GPU architecture.\n";
    +  // __trap();
    +  std::exit(1);
    +
    +  (void)bad_arch; // suppress unused function warning
    +}
    +
    +int get_current_device_id();
    +
    +inline dpct::err0 ggml_sycl_set_device(const int device) try {
    +
    +  int current_device_id;
    +  SYCL_CHECK(CHECK_TRY_ERROR(current_device_id = get_current_device_id()));
    +
    +  // GGML_SYCL_DEBUG("ggml_sycl_set_device device_id=%d,
    +  // current_device_id=%d\n", device, current_device);
    +  if (device == current_device_id) {
    +    return 0;
    +  }
    +
    +  return CHECK_TRY_ERROR(dpct::select_device(device));
    +} catch (sycl::exception const& exc) {
    +  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
    +            << ", line:" << __LINE__ << std::endl;
    +  crash();
    +  std::exit(1);
    +}
    +
    +//////////////////////
    +
    +struct ggml_sycl_device_info {
    +    int device_count;
    +
    +    struct sycl_device_info {
    +        int     cc;                 // compute capability
    +        // int     nsm;                // number of streaming multiprocessors
    +        // size_t  smpb;               // max. shared memory per block
    +        bool    vmm;                // virtual memory support
    +        size_t  total_vram;
    +    };
    +
    +    sycl_device_info devices[GGML_SYCL_MAX_DEVICES] = {};
    +
    +    std::array default_tensor_split = {};
    +};
    +
    +const ggml_sycl_device_info & ggml_sycl_info();
    +
    +struct ggml_sycl_pool {
    +    virtual ~ggml_sycl_pool() = default;
    +
    +    virtual void * alloc(size_t size, size_t * actual_size) = 0;
    +    virtual void free(void * ptr, size_t size) = 0;
    +};
    +
    +template
    +struct ggml_sycl_pool_alloc {
    +    ggml_sycl_pool * pool = nullptr;
    +    T * ptr = nullptr;
    +    size_t actual_size = 0;
    +
    +    explicit ggml_sycl_pool_alloc(ggml_sycl_pool & pool) : pool(&pool) {
    +    }
    +
    +    ggml_sycl_pool_alloc(ggml_sycl_pool & pool, size_t size) : pool(&pool) {
    +        alloc(size);
    +    }
    +
    +    ~ggml_sycl_pool_alloc() {
    +        if (ptr != nullptr) {
    +            pool->free(ptr, actual_size);
    +        }
    +    }
    +
    +    // size is in number of elements
    +    T * alloc(size_t size) {
    +        GGML_ASSERT(pool != nullptr);
    +        GGML_ASSERT(ptr == nullptr);
    +        ptr = (T *) pool->alloc(size * sizeof(T), &this->actual_size);
    +        return ptr;
    +    }
    +
    +    T * alloc(ggml_sycl_pool & pool, size_t size) {
    +        this->pool = &pool;
    +        return alloc(size);
    +    }
    +
    +    T * get() {
    +        return ptr;
    +    }
    +
    +    ggml_sycl_pool_alloc() = default;
    +    ggml_sycl_pool_alloc(const ggml_sycl_pool_alloc &) = delete;
    +    ggml_sycl_pool_alloc(ggml_sycl_pool_alloc &&) = delete;
    +    ggml_sycl_pool_alloc& operator=(const ggml_sycl_pool_alloc &) = delete;
    +    ggml_sycl_pool_alloc& operator=(ggml_sycl_pool_alloc &&) = delete;
    +};
    +
    +// backend interface
    +
    +struct ggml_tensor_extra_gpu {
    +  void* data_device[GGML_SYCL_MAX_DEVICES]; // 1 pointer for each device for split
    +                                       // tensors
    +  dpct::event_ptr events[GGML_SYCL_MAX_DEVICES]
    +                        [GGML_SYCL_MAX_STREAMS]; // events for synchronizing multiple GPUs
    +};
    +
    +struct ggml_backend_sycl_context {
    +    int device;
    +    std::string name;
    +
    +    queue_ptr qptrs[GGML_SYCL_MAX_DEVICES][GGML_SYCL_MAX_STREAMS] = { { nullptr } };
    +
    +    explicit ggml_backend_sycl_context(int device) :
    +        device(device),
    +        name(GGML_SYCL_NAME + std::to_string(device)) {
    +    }
    +
    +    queue_ptr stream(int device, int stream) {
    +        if (qptrs[device][stream] == nullptr) {
    +            qptrs[device][stream] = &(dpct::get_current_device().default_queue());
    +        }
    +        return qptrs[device][stream];
    +    }
    +
    +    queue_ptr stream() {
    +        return stream(device, 0);
    +    }
    +
    +    // pool
    +    std::unique_ptr pools[GGML_SYCL_MAX_DEVICES];
    +
    +    static std::unique_ptr new_pool_for_device(queue_ptr qptr, int device);
    +
    +    ggml_sycl_pool & pool(int device) {
    +        if (pools[device] == nullptr) {
    +            pools[device] = new_pool_for_device(stream(device,0), device);
    +        }
    +        return *pools[device];
    +    }
    +
    +    ggml_sycl_pool & pool() {
    +        return pool(device);
    +    }
    +};
    +
    +
    +#endif // GGML_SYCL_COMMON_HPP
    diff --git a/ggml-sycl/dpct/helper.hpp b/ggml-sycl/dpct/helper.hpp
    new file mode 100644
    index 000000000..017fd6ee1
    --- /dev/null
    +++ b/ggml-sycl/dpct/helper.hpp
    @@ -0,0 +1,2980 @@
    +//
    +// MIT license
    +// Copyright (C) 2024 Intel Corporation
    +// SPDX-License-Identifier: MIT
    +//
    +
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +
    +#ifndef GGML_SYCL_DPCT_HELPER_HPP
    +#define GGML_SYCL_DPCT_HELPER_HPP
    +
    +#include 
    +#include 
    +#include 
    +#include 
    +
    +#include "ggml.h"
    +
    +#if defined(__linux__)
    +#include 
    +#elif defined(_WIN64)
    +#ifndef NOMINMAX
    +#define NOMINMAX
    +#endif
    +#include 
    +#else
    +#error "Only support Windows and Linux."
    +#endif
    +
    +#if defined(__linux__)
    +#include 
    +#include 
    +#endif
    +#if defined(_WIN64)
    +#ifndef NOMINMAX
    +#define NOMINMAX
    +#endif
    +#include 
    +#endif
    +
    +#define DPCT_COMPATIBILITY_TEMP (900)
    +
    +#if defined(_MSC_VER)
    +#define __dpct_align__(n) __declspec(align(n))
    +#define __dpct_inline__ __forceinline
    +#else
    +#define __dpct_align__(n) __attribute__((aligned(n)))
    +#define __dpct_inline__ __inline__ __attribute__((always_inline))
    +#endif
    +
    +#if defined(_MSC_VER)
    +#define __dpct_noinline__ __declspec(noinline)
    +#else
    +#define __dpct_noinline__ __attribute__((noinline))
    +#endif
    +
    +inline std::string get_device_type_name(const sycl::device &Device) {
    +    auto DeviceType = Device.get_info();
    +    switch (DeviceType) {
    +    case sycl::info::device_type::cpu:
    +        return "cpu";
    +    case sycl::info::device_type::gpu:
    +        return "gpu";
    +    case sycl::info::device_type::host:
    +        return "host";
    +    case sycl::info::device_type::accelerator:
    +        return "acc";
    +    default:
    +        return "unknown";
    +    }
    +}
    +
    +inline std::string get_device_backend_and_type(const sycl::device &device) {
    +    std::stringstream device_type;
    +    sycl::backend backend = device.get_backend();
    +    device_type <<  backend << ":" << get_device_type_name(device);
    +    return device_type.str();
    +}
    +
    +namespace dpct
    +{
    +    typedef sycl::queue *queue_ptr;
    +    typedef sycl::event *event_ptr;
    +    typedef char *device_ptr;
    +    typedef uint8_t byte_t;
    +    typedef sycl::buffer buffer_t;
    +
    +    /// SYCL default exception handler
    +    inline auto exception_handler = [](sycl::exception_list exceptions)
    +    {
    +        for (std::exception_ptr const &e : exceptions)
    +        {
    +            try
    +            {
    +                std::rethrow_exception(e);
    +            }
    +            catch (sycl::exception const &e)
    +            {
    +                std::cerr << "Caught asynchronous SYCL exception:" << std::endl
    +                          << e.what() << std::endl
    +                          << "Exception caught at file:" << __FILE__
    +                          << ", line:" << __LINE__ << std::endl;
    +            }
    +        }
    +    };
    +
    +    enum error_code
    +    {
    +        success = 0,
    +        default_error = 999
    +    };
    +
    +    enum memcpy_direction
    +    {
    +        host_to_host,
    +        host_to_device,
    +        device_to_host,
    +        device_to_device,
    +        automatic
    +    };
    +
    +    enum memory_region
    +    {
    +        global = 0, // device global memory
    +        constant,   // device constant memory
    +        local,      // device local memory
    +        shared,     // memory which can be accessed by host and device
    +    };
    +
    +    enum class library_data_t : unsigned char
    +    {
    +        real_float = 0,
    +        complex_float,
    +        real_double,
    +        complex_double,
    +        real_half,
    +        complex_half,
    +        real_bfloat16,
    +        complex_bfloat16,
    +        real_int4,
    +        complex_int4,
    +        real_uint4,
    +        complex_uint4,
    +        real_int8,
    +        complex_int8,
    +        real_uint8,
    +        complex_uint8,
    +        real_int16,
    +        complex_int16,
    +        real_uint16,
    +        complex_uint16,
    +        real_int32,
    +        complex_int32,
    +        real_uint32,
    +        complex_uint32,
    +        real_int64,
    +        complex_int64,
    +        real_uint64,
    +        complex_uint64,
    +        real_int8_4,
    +        real_int8_32,
    +        real_uint8_4,
    +        library_data_t_size
    +    };
    +
    +    template 
    +    struct DataType
    +    {
    +        using T2 = T;
    +    };
    +    template 
    +    struct DataType>
    +    {
    +        using T2 = std::complex;
    +    };
    +
    +    static void destroy_event(event_ptr event)
    +    {
    +        delete event;
    +    }
    +
    +    static inline unsigned int get_tid()
    +    {
    +#if defined(__linux__)
    +        return syscall(SYS_gettid);
    +#elif defined(_WIN64)
    +        return GetCurrentThreadId();
    +#else
    +#error "Only support Windows and Linux."
    +#endif
    +    }
    +
    +    namespace detail
    +    {
    +        static void get_version(const sycl::device &dev, int &major, int &minor)
    +        {
    +            // Version string has the following format:
    +            // a. OpenCL
    +            // b. 
    +            // c.  e.g gfx1030
    +            std::string ver;
    +            ver = dev.get_info();
    +            std::string::size_type i = 0;
    +            while (i < ver.size()) {
    +              if (isdigit(ver[i]))
    +                break;
    +              i++;
    +            }
    +            major = std::stoi(&(ver[i]));
    +            while (i < ver.size()) {
    +              if (ver[i] == '.')
    +                break;
    +              i++;
    +            }
    +            if (i < ver.size()) {
    +              // a. and b.
    +              i++;
    +              minor = std::stoi(&(ver[i]));
    +            } else {
    +              // c.
    +              minor = 0;
    +            }
    +        }
    +
    +        template 
    +        class generic_error_type
    +        {
    +        public:
    +            generic_error_type() = default;
    +            generic_error_type(T value) : value{value} {}
    +            operator T() const { return value; }
    +
    +        private:
    +            T value;
    +        };
    +
    +    } // namespace detail
    +
    +    /// Pitched 2D/3D memory data.
    +    class pitched_data
    +    {
    +    public:
    +        pitched_data() : pitched_data(nullptr, 0, 0, 0) {}
    +        pitched_data(void *data, size_t pitch, size_t x, size_t y)
    +            : _data(data), _pitch(pitch), _x(x), _y(y) {}
    +
    +        void *get_data_ptr() { return _data; }
    +        void set_data_ptr(void *data) { _data = data; }
    +
    +        size_t get_pitch() { return _pitch; }
    +        void set_pitch(size_t pitch) { _pitch = pitch; }
    +
    +        size_t get_x() { return _x; }
    +        void set_x(size_t x) { _x = x; };
    +
    +        size_t get_y() { return _y; }
    +        void set_y(size_t y) { _y = y; }
    +
    +    private:
    +        void *_data;
    +        size_t _pitch, _x, _y;
    +    };
    +
    +    class device_info
    +    {
    +    public:
    +        // get interface
    +        const char *get_name() const { return _name; }
    +        char *get_name() { return _name; }
    +        template ,
    +                  std::enable_if_t> ||
    +                                       std::is_same_v,
    +                                   int> = 0>
    +        auto get_max_work_item_sizes() const
    +        {
    +            if constexpr (std::is_same_v>)
    +                return sycl::range<3>(_max_work_item_sizes_i[0],
    +                                      _max_work_item_sizes_i[1],
    +                                      _max_work_item_sizes_i[2]);
    +            else
    +            {
    +                return _max_work_item_sizes_i;
    +            }
    +        }
    +        template ,
    +                  std::enable_if_t> ||
    +                                       std::is_same_v,
    +                                   int> = 0>
    +        auto get_max_work_item_sizes()
    +        {
    +            if constexpr (std::is_same_v>)
    +                return sycl::range<3>(_max_work_item_sizes_i[0],
    +                                      _max_work_item_sizes_i[1],
    +                                      _max_work_item_sizes_i[2]);
    +            else
    +            {
    +                return _max_work_item_sizes_i;
    +            }
    +        }
    +        bool get_host_unified_memory() const { return _host_unified_memory; }
    +        int get_major_version() const { return _major; }
    +        int get_minor_version() const { return _minor; }
    +        int get_integrated() const { return _integrated; }
    +        int get_max_clock_frequency() const { return _frequency; }
    +        int get_max_compute_units() const { return _max_compute_units; }
    +        int get_max_work_group_size() const { return _max_work_group_size; }
    +        int get_max_sub_group_size() const { return _max_sub_group_size; }
    +        int get_max_work_items_per_compute_unit() const
    +        {
    +            return _max_work_items_per_compute_unit;
    +        }
    +        int get_max_register_size_per_work_group() const
    +        {
    +            return _max_register_size_per_work_group;
    +        }
    +        template  ||
    +                                       std::is_same_v,
    +                                   int> = 0>
    +        auto get_max_nd_range_size() const
    +        {
    +            if constexpr (std::is_same_v)
    +                return _max_nd_range_size;
    +            else
    +                return _max_nd_range_size_i;
    +        }
    +        template  ||
    +                                       std::is_same_v,
    +                                   int> = 0>
    +        auto get_max_nd_range_size()
    +        {
    +            if constexpr (std::is_same_v)
    +                return _max_nd_range_size;
    +            else
    +                return _max_nd_range_size_i;
    +        }
    +        size_t get_global_mem_size() const { return _global_mem_size; }
    +        size_t get_local_mem_size() const { return _local_mem_size; }
    +        size_t get_max_mem_alloc_size() const { return _max_mem_alloc_size; }
    +        /// Returns the maximum clock rate of device's global memory in kHz. If
    +        /// compiler does not support this API then returns default value 3200000 kHz.
    +        unsigned int get_memory_clock_rate() const { return _memory_clock_rate; }
    +        /// Returns the maximum bus width between device and memory in bits. If
    +        /// compiler does not support this API then returns default value 64 bits.
    +        unsigned int get_memory_bus_width() const { return _memory_bus_width; }
    +        uint32_t get_device_id() const { return _device_id; }
    +        std::array get_uuid() const { return _uuid; }
    +        /// Returns global memory cache size in bytes.
    +        unsigned int get_global_mem_cache_size() const
    +        {
    +            return _global_mem_cache_size;
    +        }
    +
    +        // set interface
    +        void set_name(const char *name)
    +        {
    +            size_t length = strlen(name);
    +            if (length < 256)
    +            {
    +                std::memcpy(_name, name, length + 1);
    +            }
    +            else
    +            {
    +                std::memcpy(_name, name, 255);
    +                _name[255] = '\0';
    +            }
    +        }
    +        void set_max_work_item_sizes(const sycl::range<3> max_work_item_sizes)
    +        {
    +            for (int i = 0; i < 3; ++i)
    +                _max_work_item_sizes_i[i] = max_work_item_sizes[i];
    +        }
    +        [[deprecated]] void
    +        set_max_work_item_sizes(const sycl::id<3> max_work_item_sizes)
    +        {
    +            for (int i = 0; i < 3; ++i)
    +            {
    +                _max_work_item_sizes_i[i] = max_work_item_sizes[i];
    +            }
    +        }
    +        void set_host_unified_memory(bool host_unified_memory)
    +        {
    +            _host_unified_memory = host_unified_memory;
    +        }
    +        void set_major_version(int major) { _major = major; }
    +        void set_minor_version(int minor) { _minor = minor; }
    +        void set_integrated(int integrated) { _integrated = integrated; }
    +        void set_max_clock_frequency(int frequency) { _frequency = frequency; }
    +        void set_max_compute_units(int max_compute_units)
    +        {
    +            _max_compute_units = max_compute_units;
    +        }
    +        void set_global_mem_size(size_t global_mem_size)
    +        {
    +            _global_mem_size = global_mem_size;
    +        }
    +        void set_local_mem_size(size_t local_mem_size)
    +        {
    +            _local_mem_size = local_mem_size;
    +        }
    +        void set_max_mem_alloc_size(size_t max_mem_alloc_size)
    +        {
    +            _max_mem_alloc_size = max_mem_alloc_size;
    +        }
    +        void set_max_work_group_size(int max_work_group_size)
    +        {
    +            _max_work_group_size = max_work_group_size;
    +        }
    +        void set_max_sub_group_size(int max_sub_group_size)
    +        {
    +            _max_sub_group_size = max_sub_group_size;
    +        }
    +        void
    +        set_max_work_items_per_compute_unit(int max_work_items_per_compute_unit)
    +        {
    +            _max_work_items_per_compute_unit = max_work_items_per_compute_unit;
    +        }
    +        void set_max_nd_range_size(int max_nd_range_size[])
    +        {
    +            for (int i = 0; i < 3; i++)
    +            {
    +                _max_nd_range_size[i] = max_nd_range_size[i];
    +                _max_nd_range_size_i[i] = max_nd_range_size[i];
    +            }
    +        }
    +        void set_memory_clock_rate(unsigned int memory_clock_rate)
    +        {
    +            _memory_clock_rate = memory_clock_rate;
    +        }
    +        void set_memory_bus_width(unsigned int memory_bus_width)
    +        {
    +            _memory_bus_width = memory_bus_width;
    +        }
    +        void
    +        set_max_register_size_per_work_group(int max_register_size_per_work_group)
    +        {
    +            _max_register_size_per_work_group = max_register_size_per_work_group;
    +        }
    +        void set_device_id(uint32_t device_id)
    +        {
    +            _device_id = device_id;
    +        }
    +        void set_uuid(std::array uuid)
    +        {
    +            _uuid = std::move(uuid);
    +        }
    +        void set_global_mem_cache_size(unsigned int global_mem_cache_size)
    +        {
    +            _global_mem_cache_size = global_mem_cache_size;
    +        }
    +
    +    private:
    +        char _name[256];
    +        int _max_work_item_sizes_i[3];
    +        bool _host_unified_memory = false;
    +        int _major;
    +        int _minor;
    +        int _integrated = 0;
    +        int _frequency;
    +        // Set estimated value 3200000 kHz as default value.
    +        unsigned int _memory_clock_rate = 3200000;
    +        // Set estimated value 64 bits as default value.
    +        unsigned int _memory_bus_width = 64;
    +        unsigned int _global_mem_cache_size;
    +        int _max_compute_units;
    +        int _max_work_group_size;
    +        int _max_sub_group_size;
    +        int _max_work_items_per_compute_unit;
    +        int _max_register_size_per_work_group;
    +        size_t _global_mem_size;
    +        size_t _local_mem_size;
    +        size_t _max_mem_alloc_size;
    +        size_t _max_nd_range_size[3];
    +        int _max_nd_range_size_i[3];
    +        uint32_t _device_id;
    +        std::array _uuid;
    +    };
    +
    +    static int get_major_version(const sycl::device &dev)
    +    {
    +        int major, minor;
    +        detail::get_version(dev, major, minor);
    +        return major;
    +    }
    +
    +    static int get_minor_version(const sycl::device &dev)
    +    {
    +        int major, minor;
    +        detail::get_version(dev, major, minor);
    +        return minor;
    +    }
    +
    +    static void get_device_info(device_info &out, const sycl::device &dev)
    +    {
    +        device_info prop;
    +        prop.set_name(dev.get_info().c_str());
    +
    +        int major, minor;
    +        detail::get_version(dev, major, minor);
    +        prop.set_major_version(major);
    +        prop.set_minor_version(minor);
    +
    +        prop.set_max_work_item_sizes(
    +#if (__SYCL_COMPILER_VERSION && __SYCL_COMPILER_VERSION < 20220902)
    +            // oneAPI DPC++ compiler older than 2022/09/02, where max_work_item_sizes
    +            // is an enum class element
    +            dev.get_info());
    +#else
    +            // SYCL 2020-conformant code, max_work_item_sizes is a struct templated by
    +            // an int
    +            dev.get_info>());
    +#endif
    +        prop.set_host_unified_memory(dev.has(sycl::aspect::usm_host_allocations));
    +
    +        prop.set_max_clock_frequency(
    +            dev.get_info() * 1000);
    +
    +        prop.set_max_compute_units(
    +            dev.get_info());
    +        prop.set_max_work_group_size(
    +            dev.get_info());
    +        prop.set_global_mem_size(dev.get_info());
    +        prop.set_local_mem_size(dev.get_info());
    +        prop.set_max_mem_alloc_size(dev.get_info());
    +
    +#if (defined(SYCL_EXT_INTEL_DEVICE_INFO) && SYCL_EXT_INTEL_DEVICE_INFO >= 6)
    +        if (dev.has(sycl::aspect::ext_intel_memory_clock_rate))
    +        {
    +            unsigned int tmp =
    +                dev.get_info();
    +            if (tmp != 0)
    +                prop.set_memory_clock_rate(1000 * tmp);
    +        }
    +        if (dev.has(sycl::aspect::ext_intel_memory_bus_width))
    +        {
    +            prop.set_memory_bus_width(
    +                dev.get_info());
    +        }
    +        if (dev.has(sycl::aspect::ext_intel_device_id))
    +        {
    +            prop.set_device_id(
    +                dev.get_info());
    +        }
    +        if (dev.has(sycl::aspect::ext_intel_device_info_uuid))
    +        {
    +            prop.set_uuid(dev.get_info());
    +        }
    +#elif defined(_MSC_VER) && !defined(__clang__)
    +#pragma message("get_device_info: querying memory_clock_rate and \
    +        memory_bus_width are not supported by the compiler used. \
    +        Use 3200000 kHz as memory_clock_rate default value. \
    +        Use 64 bits as memory_bus_width default value.")
    +#else
    +#warning "get_device_info: querying memory_clock_rate and \
    +        memory_bus_width are not supported by the compiler used. \
    +        Use 3200000 kHz as memory_clock_rate default value. \
    +        Use 64 bits as memory_bus_width default value."
    +#endif
    +
    +        size_t max_sub_group_size = 1;
    +        std::vector sub_group_sizes =
    +            dev.get_info();
    +
    +        for (const auto &sub_group_size : sub_group_sizes)
    +        {
    +            if (max_sub_group_size < sub_group_size)
    +                max_sub_group_size = sub_group_size;
    +        }
    +
    +        prop.set_max_sub_group_size(max_sub_group_size);
    +
    +        prop.set_max_work_items_per_compute_unit(
    +            dev.get_info());
    +        int max_nd_range_size[] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
    +        prop.set_max_nd_range_size(max_nd_range_size);
    +
    +        // Estimates max register size per work group, feel free to update the value
    +        // according to device properties.
    +        prop.set_max_register_size_per_work_group(65536);
    +
    +        prop.set_global_mem_cache_size(
    +            dev.get_info());
    +        out = prop;
    +    }
    +
    +    /// dpct device extension
    +    class device_ext : public sycl::device
    +    {
    +        typedef std::mutex mutex_type;
    +
    +    public:
    +        device_ext() : sycl::device(), _ctx(*this) {}
    +        ~device_ext()
    +        {
    +            std::lock_guard lock(m_mutex);
    +            clear_queues();
    +        }
    +        device_ext(const sycl::device &base) : sycl::device(base), _ctx(*this)
    +        {
    +            std::lock_guard lock(m_mutex);
    +            init_queues();
    +        }
    +
    +        int is_native_atomic_supported() { return 0; }
    +        int get_major_version() const
    +        {
    +            return dpct::get_major_version(*this);
    +        }
    +
    +        int get_minor_version() const
    +        {
    +            return dpct::get_minor_version(*this);
    +        }
    +
    +        int get_max_compute_units() const
    +        {
    +            return get_device_info().get_max_compute_units();
    +        }
    +
    +        /// Return the maximum clock frequency of this device in KHz.
    +        int get_max_clock_frequency() const
    +        {
    +            return get_device_info().get_max_clock_frequency();
    +        }
    +
    +        int get_integrated() const { return get_device_info().get_integrated(); }
    +
    +        int get_max_sub_group_size() const
    +        {
    +            return get_device_info().get_max_sub_group_size();
    +        }
    +
    +        int get_max_register_size_per_work_group() const
    +        {
    +            return get_device_info().get_max_register_size_per_work_group();
    +        }
    +
    +        int get_max_work_group_size() const
    +        {
    +            return get_device_info().get_max_work_group_size();
    +        }
    +
    +        int get_mem_base_addr_align() const
    +        {
    +            return get_info();
    +        }
    +
    +        size_t get_global_mem_size() const
    +        {
    +            return get_device_info().get_global_mem_size();
    +        }
    +
    +        size_t get_max_mem_alloc_size() const
    +        {
    +            return get_device_info().get_max_mem_alloc_size();
    +        }
    +
    +        /// Get the number of bytes of free and total memory on the SYCL device.
    +        /// \param [out] free_memory The number of bytes of free memory on the SYCL device.
    +        /// \param [out] total_memory The number of bytes of total memory on the SYCL device.
    +        void get_memory_info(size_t &free_memory, size_t &total_memory)
    +        {
    +            total_memory = get_device_info().get_global_mem_size();
    +            const char *warning_info = "get_memory_info: [warning] ext_intel_free_memory is not "
    +                                 "supported (export/set ZES_ENABLE_SYSMAN=1 to support), "
    +                                 "use total memory as free memory";
    +#if (defined(__SYCL_COMPILER_VERSION) && __SYCL_COMPILER_VERSION >= 20221105)
    +            if (!has(sycl::aspect::ext_intel_free_memory))
    +            {
    +                std::cerr << warning_info << std::endl;
    +                free_memory = total_memory;
    +            }
    +            else
    +            {
    +                free_memory = get_info();
    +            }
    +#else
    +            std::cerr << warning_info << std::endl;
    +            free_memory = total_memory;
    +#if defined(_MSC_VER) && !defined(__clang__)
    +#pragma message("Querying the number of bytes of free memory is not supported")
    +#else
    +#warning "Querying the number of bytes of free memory is not supported"
    +#endif
    +#endif
    +        }
    +
    +        void get_device_info(device_info &out) const
    +        {
    +            dpct::get_device_info(out, *this);
    +        }
    +
    +        device_info get_device_info() const
    +        {
    +            device_info prop;
    +            dpct::get_device_info(prop, *this);
    +            return prop;
    +        }
    +
    +        void reset()
    +        {
    +            std::lock_guard lock(m_mutex);
    +            clear_queues();
    +            init_queues();
    +        }
    +
    +        sycl::queue &in_order_queue() { return *_q_in_order; }
    +
    +        sycl::queue &out_of_order_queue() { return *_q_out_of_order; }
    +
    +        sycl::queue &default_queue()
    +        {
    +            return in_order_queue();
    +        }
    +
    +        void queues_wait_and_throw()
    +        {
    +            std::unique_lock lock(m_mutex);
    +            std::vector> current_queues(
    +                _queues);
    +            lock.unlock();
    +            for (const auto &q : current_queues)
    +            {
    +                q->wait_and_throw();
    +            }
    +            // Guard the destruct of current_queues to make sure the ref count is safe.
    +            lock.lock();
    +        }
    +
    +        sycl::queue *create_queue(bool enable_exception_handler = false)
    +        {
    +            return create_in_order_queue(enable_exception_handler);
    +        }
    +
    +        sycl::queue *create_queue(sycl::context context, sycl::device device,
    +                                bool enable_exception_handler = false) {
    +            return create_in_order_queue(context, device, enable_exception_handler);
    +        }
    +
    +        sycl::queue *create_in_order_queue(bool enable_exception_handler = false) {
    +            std::lock_guard lock(m_mutex);
    +            return create_queue_impl(enable_exception_handler,
    +                                    sycl::property::queue::in_order());
    +        }
    +
    +        sycl::queue *create_in_order_queue(sycl::context context, sycl::device device,
    +                                        bool enable_exception_handler = false) {
    +            std::lock_guard lock(m_mutex);
    +            return create_queue_impl(context, device, enable_exception_handler,
    +                                    sycl::property::queue::in_order());
    +        }
    +
    +        sycl::queue *create_out_of_order_queue(bool enable_exception_handler = false) {
    +            std::lock_guard lock(m_mutex);
    +            return create_queue_impl(enable_exception_handler);
    +        }
    +
    +        void destroy_queue(sycl::queue *&queue)
    +        {
    +            std::lock_guard lock(m_mutex);
    +            _queues.erase(std::remove_if(_queues.begin(), _queues.end(),
    +                                         [=](const std::shared_ptr &q) -> bool
    +                                         {
    +                                             return q.get() == queue;
    +                                         }),
    +                          _queues.end());
    +            queue = nullptr;
    +        }
    +        void set_saved_queue(sycl::queue *q)
    +        {
    +            std::lock_guard lock(m_mutex);
    +            _saved_queue = q;
    +        }
    +        sycl::queue *get_saved_queue() const
    +        {
    +            std::lock_guard lock(m_mutex);
    +            return _saved_queue;
    +        }
    +        sycl::context get_context() const { return _ctx; }
    +
    +    private:
    +        void clear_queues()
    +        {
    +            _queues.clear();
    +            _q_in_order = _q_out_of_order = _saved_queue = nullptr;
    +        }
    +
    +        void init_queues()
    +        {
    +            _q_in_order = create_queue_impl(true, sycl::property::queue::in_order());
    +            _q_out_of_order = create_queue_impl(true);
    +            _saved_queue = &default_queue();
    +        }
    +
    +        /// Caller should acquire resource \p m_mutex before calling this function.
    +        template 
    +        sycl::queue *create_queue_impl(bool enable_exception_handler,
    +                                       Properties... properties)
    +        {
    +            sycl::async_handler eh = {};
    +            if (enable_exception_handler)
    +            {
    +                eh = exception_handler;
    +            }
    +            _queues.push_back(std::make_shared(
    +                _ctx, *this, eh,
    +                sycl::property_list(
    +#ifdef DPCT_PROFILING_ENABLED
    +                    sycl::property::queue::enable_profiling(),
    +#endif
    +                    properties...)));
    +
    +            return _queues.back().get();
    +        }
    +
    +        template 
    +        sycl::queue *create_queue_impl(sycl::context context, sycl::device device,
    +                                    bool enable_exception_handler,
    +                                    Properties... properties) {
    +            sycl::async_handler eh = {};
    +            if (enable_exception_handler) {
    +                eh = exception_handler;
    +            }
    +            _queues.push_back(std::make_shared(
    +                context, device, eh,
    +                sycl::property_list(
    +        #ifdef DPCT_PROFILING_ENABLED
    +                    sycl::property::queue::enable_profiling(),
    +        #endif
    +                    properties...)));
    +
    +            return _queues.back().get();
    +        }
    +
    +        void get_version(int &major, int &minor) const
    +        {
    +            detail::get_version(*this, major, minor);
    +        }
    +        sycl::queue *_q_in_order, *_q_out_of_order;
    +        sycl::queue *_saved_queue;
    +        sycl::context _ctx;
    +        std::vector> _queues;
    +        mutable mutex_type m_mutex;
    +    };
    +
    +    /// device manager
    +    class dev_mgr
    +    {
    +    public:
    +        device_ext ¤t_device()
    +        {
    +            unsigned int dev_id = current_device_id();
    +            check_id(dev_id);
    +            return *_devs[dev_id];
    +        }
    +        device_ext &cpu_device() const
    +        {
    +            std::lock_guard lock(m_mutex);
    +            if (_cpu_device == -1)
    +            {
    +                throw std::runtime_error("no valid cpu device");
    +            }
    +            else
    +            {
    +                return *_devs[_cpu_device];
    +            }
    +        }
    +        device_ext &get_device(unsigned int id) const
    +        {
    +            std::lock_guard lock(m_mutex);
    +            check_id(id);
    +            return *_devs[id];
    +        }
    +        unsigned int current_device_id() const
    +        {
    +            std::lock_guard lock(m_mutex);
    +            auto it = _thread2dev_map.find(get_tid());
    +            if (it != _thread2dev_map.end())
    +                return it->second;
    +            return DEFAULT_DEVICE_ID;
    +        }
    +
    +        /// Select device with a device ID.
    +        /// \param [in] id The id of the device which can
    +        /// be obtained through get_device_id(const sycl::device).
    +        void select_device(unsigned int id)
    +        {
    +            std::lock_guard lock(m_mutex);
    +            check_id(id);
    +            _thread2dev_map[get_tid()] = id;
    +        }
    +        unsigned int device_count() { return _devs.size(); }
    +
    +        unsigned int get_device_id(const sycl::device &dev)
    +        {
    +            unsigned int id = 0;
    +            for (auto dev_item : _devs)
    +            {
    +                if (*dev_item == dev)
    +                {
    +                    break;
    +                }
    +                id++;
    +            }
    +            return id;
    +        }
    +
    +        template 
    +        std::enable_if_t<
    +            std::is_invocable_r_v>
    +        select_device(const DeviceSelector &selector = sycl::gpu_selector_v)
    +        {
    +            sycl::device selected_device = sycl::device(selector);
    +            unsigned int selected_device_id = get_device_id(selected_device);
    +            select_device(selected_device_id);
    +        }
    +
    +        /// Returns the instance of device manager singleton.
    +        static dev_mgr &instance()
    +        {
    +            static dev_mgr d_m;
    +            return d_m;
    +        }
    +        dev_mgr(const dev_mgr &) = delete;
    +        dev_mgr &operator=(const dev_mgr &) = delete;
    +        dev_mgr(dev_mgr &&) = delete;
    +        dev_mgr &operator=(dev_mgr &&) = delete;
    +
    +    private:
    +        mutable std::recursive_mutex m_mutex;
    +        static bool compare_dev(sycl::device &device1, sycl::device &device2)
    +        {
    +            sycl::backend backend1 = device1.get_backend();
    +            sycl::backend backend2 = device2.get_backend();
    +            // levelzero backends always come first
    +            if(backend1 == sycl::backend::ext_oneapi_level_zero && backend2 != sycl::backend::ext_oneapi_level_zero) return true;
    +            if(backend1 != sycl::backend::ext_oneapi_level_zero && backend2 == sycl::backend::ext_oneapi_level_zero) return false;
    +            dpct::device_info prop1;
    +            dpct::get_device_info(prop1, device1);
    +            dpct::device_info prop2;
    +            dpct::get_device_info(prop2, device2);
    +            return prop1.get_max_compute_units() > prop2.get_max_compute_units();
    +        }
    +        static int convert_backend_index(std::string & backend) {
    +            if (backend == "ext_oneapi_level_zero:gpu") return 0;
    +            if (backend == "opencl:gpu") return 1;
    +            if (backend == "ext_oneapi_cuda:gpu") return 2;
    +            if (backend == "ext_oneapi_hip:gpu") return 3;
    +            if (backend == "opencl:cpu") return 4;
    +            if (backend == "opencl:acc") return 5;
    +            printf("convert_backend_index: can't handle backend=%s\n", backend.c_str());
    +            GGML_ASSERT(false);
    +        }
    +        static bool compare_backend(std::string &backend1, std::string &backend2) {
    +            return convert_backend_index(backend1) < convert_backend_index(backend2);
    +        }
    +        dev_mgr()
    +        {
    +            sycl::device default_device =
    +                sycl::device(sycl::default_selector_v);
    +            _devs.push_back(std::make_shared(default_device));
    +
    +            std::vector sycl_all_devs;
    +            // Collect other devices except for the default device.
    +            if (default_device.is_cpu())
    +                _cpu_device = 0;
    +
    +            auto Platforms = sycl::platform::get_platforms();
    +            // Keep track of the number of devices per backend
    +            std::map DeviceNums;
    +            std::map> backend_devices;
    +
    +            while (!Platforms.empty()) {
    +                auto Platform = Platforms.back();
    +                Platforms.pop_back();
    +                auto devices = Platform.get_devices();
    +                std::string backend_type = get_device_backend_and_type(devices[0]);
    +                for (const auto &device : devices) {
    +                    backend_devices[backend_type].push_back(device);
    +                }
    +            }
    +
    +            std::vector keys;
    +            for(auto it = backend_devices.begin(); it != backend_devices.end(); ++it) {
    +                keys.push_back(it->first);
    +            }
    +            std::sort(keys.begin(), keys.end(), compare_backend);
    +
    +            for (auto &key : keys) {
    +                std::vector devs = backend_devices[key];
    +                std::sort(devs.begin(), devs.end(), compare_dev);
    +                for (const auto &dev : devs) {
    +                    sycl_all_devs.push_back(dev);
    +                }
    +            }
    +
    +            for (auto &dev : sycl_all_devs)
    +            {
    +                if (dev == default_device)
    +                {
    +                    continue;
    +                }
    +                _devs.push_back(std::make_shared(dev));
    +                if (_cpu_device == -1 && dev.is_cpu())
    +                {
    +                    _cpu_device = _devs.size() - 1;
    +                }
    +            }
    +        }
    +        void check_id(unsigned int id) const
    +        {
    +            if (id >= _devs.size())
    +            {
    +                throw std::runtime_error("invalid device id");
    +            }
    +        }
    +        std::vector> _devs;
    +        /// DEFAULT_DEVICE_ID is used, if current_device_id() can not find current
    +        /// thread id in _thread2dev_map, which means default device should be used
    +        /// for the current thread.
    +        const unsigned int DEFAULT_DEVICE_ID = 0;
    +        /// thread-id to device-id map.
    +        std::map _thread2dev_map;
    +        int _cpu_device = -1;
    +    };
    +
    +    static inline sycl::queue &get_default_queue()
    +    {
    +        return dev_mgr::instance().current_device().default_queue();
    +    }
    +
    +    namespace detail
    +    {
    +        enum class pointer_access_attribute
    +        {
    +            host_only = 0,
    +            device_only,
    +            host_device,
    +            end
    +        };
    +
    +        static pointer_access_attribute get_pointer_attribute(sycl::queue &q,
    +                                                              const void *ptr)
    +        {
    +            switch (sycl::get_pointer_type(ptr, q.get_context()))
    +            {
    +            case sycl::usm::alloc::unknown:
    +                return pointer_access_attribute::host_only;
    +            case sycl::usm::alloc::device:
    +                return pointer_access_attribute::device_only;
    +            case sycl::usm::alloc::shared:
    +            case sycl::usm::alloc::host:
    +                return pointer_access_attribute::host_device;
    +            }
    +        }
    +
    +        template 
    +        inline constexpr std::uint64_t get_type_combination_id(ArgT Val)
    +        {
    +            static_assert((unsigned char)library_data_t::library_data_t_size <=
    +                              std::numeric_limits::max() &&
    +                          "library_data_t size exceeds limit.");
    +            static_assert(std::is_same_v, "Unsupported ArgT");
    +            return (std::uint64_t)Val;
    +        }
    +
    +        template 
    +        inline constexpr std::uint64_t get_type_combination_id(FirstT FirstVal,
    +                                                               RestT... RestVal)
    +        {
    +            static_assert((std::uint8_t)library_data_t::library_data_t_size <=
    +                              std::numeric_limits::max() &&
    +                          "library_data_t size exceeds limit.");
    +            static_assert(sizeof...(RestT) <= 8 && "Too many parameters");
    +            static_assert(std::is_same_v, "Unsupported FirstT");
    +            return get_type_combination_id(RestVal...) << 8 | ((std::uint64_t)FirstVal);
    +        }
    +
    +        class mem_mgr
    +        {
    +            mem_mgr()
    +            {
    +                // Reserved address space, no real memory allocation happens here.
    +#if defined(__linux__)
    +                mapped_address_space =
    +                    (byte_t *)mmap(nullptr, mapped_region_size, PROT_NONE,
    +                                   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    +#elif defined(_WIN64)
    +                mapped_address_space = (byte_t *)VirtualAlloc(
    +                    NULL,               // NULL specified as the base address parameter
    +                    mapped_region_size, // Size of allocation
    +                    MEM_RESERVE,        // Allocate reserved pages
    +                    PAGE_NOACCESS);     // Protection = no access
    +#else
    +#error "Only support Windows and Linux."
    +#endif
    +                next_free = mapped_address_space;
    +            };
    +
    +        public:
    +            using buffer_id_t = int;
    +
    +            struct allocation
    +            {
    +                buffer_t buffer;
    +                byte_t *alloc_ptr;
    +                size_t size;
    +            };
    +
    +            ~mem_mgr()
    +            {
    +#if defined(__linux__)
    +                munmap(mapped_address_space, mapped_region_size);
    +#elif defined(_WIN64)
    +                VirtualFree(mapped_address_space, 0, MEM_RELEASE);
    +#else
    +#error "Only support Windows and Linux."
    +#endif
    +            };
    +
    +            mem_mgr(const mem_mgr &) = delete;
    +            mem_mgr &operator=(const mem_mgr &) = delete;
    +            mem_mgr(mem_mgr &&) = delete;
    +            mem_mgr &operator=(mem_mgr &&) = delete;
    +
    +            /// Allocate
    +            void *mem_alloc(size_t size)
    +            {
    +                if (!size)
    +                    return nullptr;
    +                std::lock_guard lock(m_mutex);
    +                if (next_free + size > mapped_address_space + mapped_region_size)
    +                {
    +                    throw std::runtime_error("dpct_malloc: out of memory for virtual memory pool");
    +                }
    +                // Allocation
    +                sycl::range<1> r(size);
    +                buffer_t buf(r);
    +                allocation A{buf, next_free, size};
    +                // Map allocation to device pointer
    +                void *result = next_free;
    +                m_map.emplace(next_free + size, A);
    +                // Update pointer to the next free space.
    +                next_free += (size + extra_padding + alignment - 1) & ~(alignment - 1);
    +
    +                return result;
    +            }
    +
    +            /// Deallocate
    +            void mem_free(const void *ptr)
    +            {
    +                if (!ptr)
    +                    return;
    +                std::lock_guard lock(m_mutex);
    +                auto it = get_map_iterator(ptr);
    +                m_map.erase(it);
    +            }
    +
    +            /// map: device pointer -> allocation(buffer, alloc_ptr, size)
    +            allocation translate_ptr(const void *ptr)
    +            {
    +                std::lock_guard lock(m_mutex);
    +                auto it = get_map_iterator(ptr);
    +                return it->second;
    +            }
    +
    +            /// Check if the pointer represents device pointer or not.
    +            bool is_device_ptr(const void *ptr) const
    +            {
    +                std::lock_guard lock(m_mutex);
    +                return (mapped_address_space <= ptr) &&
    +                       (ptr < mapped_address_space + mapped_region_size);
    +            }
    +
    +            /// Returns the instance of memory manager singleton.
    +            static mem_mgr &instance()
    +            {
    +                static mem_mgr m;
    +                return m;
    +            }
    +
    +        private:
    +            std::map m_map;
    +            mutable std::mutex m_mutex;
    +            byte_t *mapped_address_space;
    +            byte_t *next_free;
    +            const size_t mapped_region_size = 128ull * 1024 * 1024 * 1024;
    +            const size_t alignment = 256;
    +            /// This padding may be defined to some positive value to debug
    +            /// out of bound accesses.
    +            const size_t extra_padding = 0;
    +
    +            std::map::iterator get_map_iterator(const void *ptr)
    +            {
    +                auto it = m_map.upper_bound((byte_t *)ptr);
    +                if (it == m_map.end())
    +                {
    +                    // Not a virtual pointer.
    +                    throw std::runtime_error("can not get buffer from non-virtual pointer");
    +                }
    +                const allocation &alloc = it->second;
    +                if (ptr < alloc.alloc_ptr)
    +                {
    +                    // Out of bound.
    +                    // This may happen if there's a gap between allocations due to alignment
    +                    // or extra padding and pointer points to this gap.
    +                    throw std::runtime_error("invalid virtual pointer");
    +                }
    +                return it;
    +            }
    +        };
    +
    +        template 
    +        class accessor;
    +        template 
    +        class memory_traits
    +        {
    +        public:
    +            static constexpr sycl::access::target target =
    +                sycl::access::target::device;
    +            static constexpr sycl::access_mode mode =
    +                (Memory == constant) ? sycl::access_mode::read
    +                                     : sycl::access_mode::read_write;
    +            static constexpr size_t type_size = sizeof(T);
    +            using element_t =
    +                typename std::conditional::type;
    +            using value_t = typename std::remove_cv::type;
    +            template 
    +            using accessor_t = typename std::conditional<
    +                Memory == local, sycl::local_accessor,
    +                sycl::accessor>::type;
    +            using pointer_t = T *;
    +        };
    +
    +        static inline void *dpct_malloc(size_t size, sycl::queue &q)
    +        {
    +            return sycl::malloc_device(size, q.get_device(), q.get_context());
    +        }
    +
    +#define PITCH_DEFAULT_ALIGN(x) (((x) + 31) & ~(0x1F))
    +        static inline void *dpct_malloc(size_t &pitch, size_t x, size_t y, size_t z,
    +                                        sycl::queue &q)
    +        {
    +            pitch = PITCH_DEFAULT_ALIGN(x);
    +            return dpct_malloc(pitch * y * z, q);
    +        }
    +
    +        /**
    +         * @brief Sets \p value to the first \p size elements starting from \p dev_ptr in \p q.
    +         * @tparam valueT The type of the element to be set.
    +         * @param [in] q The queue in which the operation is done.
    +         * @param [in] dev_ptr Pointer to the virtual device memory address.
    +         * @param [in] value The value to be set.
    +         * @param [in] size Number of elements to be set to the value.
    +         * @return An event representing the memset operation.
    +         */
    +        template 
    +        static inline sycl::event dpct_memset(sycl::queue &q, void *dev_ptr,
    +                                              valueT value, size_t size)
    +        {
    +            return q.fill(dev_ptr, value, size);
    +        }
    +
    +        /**
    +         * @brief Sets \p value to the 3D memory region pointed by \p data in \p q.
    +         * @tparam valueT The type of the element to be set.
    +         * @param [in] q The queue in which the operation is done.
    +         * @param [in] data Pointer to the pitched device memory region.
    +         * @param [in] value The value to be set.
    +         * @param [in] size 3D memory region by number of elements.
    +         * @return An event list representing the memset operations.
    +         */
    +        template 
    +        static inline std::vector
    +        dpct_memset(sycl::queue &q, pitched_data data, valueT value,
    +                    sycl::range<3> size)
    +        {
    +            std::vector event_list;
    +            size_t slice = data.get_pitch() * data.get_y();
    +            unsigned char *data_surface = (unsigned char *)data.get_data_ptr();
    +            for (size_t z = 0; z < size.get(2); ++z)
    +            {
    +                unsigned char *data_ptr = data_surface;
    +                for (size_t y = 0; y < size.get(1); ++y)
    +                {
    +                    event_list.push_back(dpct_memset(q, data_ptr, value, size.get(0)));
    +                    data_ptr += data.get_pitch();
    +                }
    +                data_surface += slice;
    +            }
    +            return event_list;
    +        }
    +
    +        /**
    +         * @brief Sets \p val to the pitched 2D memory region pointed by \p ptr in \p q.
    +         * @tparam valueT The type of the element to be set.
    +         * @param [in] q The queue in which the operation is done.
    +         * @param [in] ptr Pointer to the virtual device memory.
    +         * @param [in] pitch The pitch size by number of elements, including padding.
    +         * @param [in] val The value to be set.
    +         * @param [in] x The width of memory region by number of elements.
    +         * @param [in] y The height of memory region by number of elements.
    +         * @return An event list representing the memset operations.
    +         */
    +        template 
    +        static inline std::vector
    +        dpct_memset(sycl::queue &q, void *ptr, size_t pitch, valueT val, size_t x,
    +                    size_t y)
    +        {
    +            return dpct_memset(q, pitched_data(ptr, pitch, x, 1), val,
    +                               sycl::range<3>(x, y, 1));
    +        }
    +
    +        static memcpy_direction deduce_memcpy_direction(sycl::queue &q, void *to_ptr,
    +                                                        const void *from_ptr,
    +                                                        memcpy_direction dir)
    +        {
    +            switch (dir)
    +            {
    +            case memcpy_direction::host_to_host:
    +            case memcpy_direction::host_to_device:
    +            case memcpy_direction::device_to_host:
    +            case memcpy_direction::device_to_device:
    +                return dir;
    +            case memcpy_direction::automatic:
    +            {
    +                // table[to_attribute][from_attribute]
    +                static const memcpy_direction
    +                    direction_table[static_cast(pointer_access_attribute::end)]
    +                                   [static_cast(pointer_access_attribute::end)] =
    +                                       {{memcpy_direction::host_to_host,
    +                                         memcpy_direction::device_to_host,
    +                                         memcpy_direction::host_to_host},
    +                                        {memcpy_direction::host_to_device,
    +                                         memcpy_direction::device_to_device,
    +                                         memcpy_direction::device_to_device},
    +                                        {memcpy_direction::host_to_host,
    +                                         memcpy_direction::device_to_device,
    +                                         memcpy_direction::device_to_device}};
    +                return direction_table[static_cast(get_pointer_attribute(
    +                    q, to_ptr))][static_cast(get_pointer_attribute(q, from_ptr))];
    +            }
    +            default:
    +                throw std::runtime_error("dpct_memcpy: invalid direction value");
    +            }
    +        }
    +
    +        static sycl::event
    +        dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr, size_t size,
    +                    memcpy_direction direction,
    +                    const std::vector &dep_events = {})
    +        {
    +            if (!size)
    +                return sycl::event{};
    +            return q.memcpy(to_ptr, from_ptr, size, dep_events);
    +            GGML_UNUSED(direction);
    +        }
    +
    +        // Get actual copy range and make sure it will not exceed range.
    +        static inline size_t get_copy_range(sycl::range<3> size, size_t slice,
    +                                            size_t pitch)
    +        {
    +            return slice * (size.get(2) - 1) + pitch * (size.get(1) - 1) + size.get(0);
    +        }
    +
    +        static inline size_t get_offset(sycl::id<3> id, size_t slice,
    +                                        size_t pitch)
    +        {
    +            return slice * id.get(2) + pitch * id.get(1) + id.get(0);
    +        }
    +
    +        /// copy 3D matrix specified by \p size from 3D matrix specified by \p from_ptr
    +        /// and \p from_range to another specified by \p to_ptr and \p to_range.
    +        static inline std::vector
    +        dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    +                    sycl::range<3> to_range, sycl::range<3> from_range,
    +                    sycl::id<3> to_id, sycl::id<3> from_id,
    +                    sycl::range<3> size, memcpy_direction direction,
    +                    const std::vector &dep_events = {})
    +        {
    +            // RAII for host pointer
    +            class host_buffer
    +            {
    +                void *_buf;
    +                size_t _size;
    +                sycl::queue &_q;
    +                const std::vector &_deps; // free operation depends
    +
    +            public:
    +                host_buffer(size_t size, sycl::queue &q,
    +                            const std::vector &deps)
    +                    : _buf(std::malloc(size)), _size(size), _q(q), _deps(deps) {}
    +                void *get_ptr() const { return _buf; }
    +                size_t get_size() const { return _size; }
    +                ~host_buffer()
    +                {
    +                    if (_buf)
    +                    {
    +                        _q.submit([&](sycl::handler &cgh)
    +                                  {
    +        cgh.depends_on(_deps);
    +        cgh.host_task([buf = _buf] { std::free(buf); }); });
    +                    }
    +                }
    +            };
    +            std::vector event_list;
    +
    +            size_t to_slice = to_range.get(1) * to_range.get(0),
    +                   from_slice = from_range.get(1) * from_range.get(0);
    +            unsigned char *to_surface =
    +                (unsigned char *)to_ptr + get_offset(to_id, to_slice, to_range.get(0));
    +            const unsigned char *from_surface =
    +                (const unsigned char *)from_ptr +
    +                get_offset(from_id, from_slice, from_range.get(0));
    +
    +            if (to_slice == from_slice && to_slice == size.get(1) * size.get(0))
    +            {
    +                return {dpct_memcpy(q, to_surface, from_surface, to_slice * size.get(2),
    +                                    direction, dep_events)};
    +            }
    +            direction = deduce_memcpy_direction(q, to_ptr, from_ptr, direction);
    +            size_t size_slice = size.get(1) * size.get(0);
    +            switch (direction)
    +            {
    +            case host_to_host:
    +                for (size_t z = 0; z < size.get(2); ++z)
    +                {
    +                    unsigned char *to_ptr = to_surface;
    +                    const unsigned char *from_ptr = from_surface;
    +                    if (to_range.get(0) == from_range.get(0) &&
    +                        to_range.get(0) == size.get(0))
    +                    {
    +                        event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size_slice,
    +                                                         direction, dep_events));
    +                    }
    +                    else
    +                    {
    +                        for (size_t y = 0; y < size.get(1); ++y)
    +                        {
    +                            event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size.get(0),
    +                                                             direction, dep_events));
    +                            to_ptr += to_range.get(0);
    +                            from_ptr += from_range.get(0);
    +                        }
    +                    }
    +                    to_surface += to_slice;
    +                    from_surface += from_slice;
    +                }
    +                break;
    +            case host_to_device:
    +            {
    +                host_buffer buf(get_copy_range(size, to_slice, to_range.get(0)), q,
    +                                event_list);
    +                std::vector host_events;
    +                if (to_slice == size_slice)
    +                {
    +                    // Copy host data to a temp host buffer with the shape of target.
    +                    host_events =
    +                        dpct_memcpy(q, buf.get_ptr(), from_surface, to_range, from_range,
    +                                    sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size,
    +                                    host_to_host, dep_events);
    +                }
    +                else
    +                {
    +                    // Copy host data to a temp host buffer with the shape of target.
    +                    host_events = dpct_memcpy(
    +                        q, buf.get_ptr(), from_surface, to_range, from_range,
    +                        sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size, host_to_host,
    +                        // If has padding data, not sure whether it is useless. So fill temp
    +                        // buffer with it.
    +                        std::vector{
    +                            dpct_memcpy(q, buf.get_ptr(), to_surface, buf.get_size(),
    +                                        device_to_host, dep_events)});
    +                }
    +                // Copy from temp host buffer to device with only one submit.
    +                event_list.push_back(dpct_memcpy(q, to_surface, buf.get_ptr(),
    +                                                 buf.get_size(), host_to_device,
    +                                                 host_events));
    +                break;
    +            }
    +            case device_to_host:
    +            {
    +                host_buffer buf(get_copy_range(size, from_slice, from_range.get(0)), q,
    +                                event_list);
    +                // Copy from host temp buffer to host target with reshaping.
    +                event_list = dpct_memcpy(
    +                    q, to_surface, buf.get_ptr(), to_range, from_range, sycl::id<3>(0, 0, 0),
    +                    sycl::id<3>(0, 0, 0), size, host_to_host,
    +                    // Copy from device to temp host buffer with only one submit.
    +                    std::vector{dpct_memcpy(q, buf.get_ptr(), from_surface,
    +                                                         buf.get_size(),
    +                                                         device_to_host, dep_events)});
    +                break;
    +            }
    +            case device_to_device:
    +                event_list.push_back(q.submit([&](sycl::handler &cgh){
    +                cgh.depends_on(dep_events);
    +                cgh.parallel_for(
    +                    size,
    +                    [=](sycl::id<3> id) {
    +                        to_surface[get_offset(id, to_slice, to_range.get(0))] =
    +                            from_surface[get_offset(id, from_slice, from_range.get(0))];
    +                    }); }));
    +                break;
    +            default:
    +                throw std::runtime_error("dpct_memcpy: invalid direction value");
    +            }
    +            return event_list;
    +        }
    +
    +        /// memcpy 2D/3D matrix specified by pitched_data.
    +        static inline std::vector
    +        dpct_memcpy(sycl::queue &q, pitched_data to, sycl::id<3> to_id,
    +                    pitched_data from, sycl::id<3> from_id, sycl::range<3> size,
    +                    memcpy_direction direction = automatic)
    +        {
    +            return dpct_memcpy(q, to.get_data_ptr(), from.get_data_ptr(),
    +                               sycl::range<3>(to.get_pitch(), to.get_y(), 1),
    +                               sycl::range<3>(from.get_pitch(), from.get_y(), 1), to_id, from_id,
    +                               size, direction);
    +        }
    +
    +        /// memcpy 2D matrix with pitch.
    +        static inline std::vector
    +        dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    +                    size_t to_pitch, size_t from_pitch, size_t x, size_t y,
    +                    memcpy_direction direction = automatic)
    +        {
    +            return dpct_memcpy(q, to_ptr, from_ptr, sycl::range<3>(to_pitch, y, 1),
    +                               sycl::range<3>(from_pitch, y, 1),
    +                               sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0),
    +                               sycl::range<3>(x, y, 1), direction);
    +        }
    +
    +        namespace deprecated
    +        {
    +
    +            template 
    +            class usm_allocator
    +            {
    +            private:
    +                using Alloc = sycl::usm_allocator;
    +                Alloc _impl;
    +
    +            public:
    +                using value_type = typename std::allocator_traits::value_type;
    +                using pointer = typename std::allocator_traits::pointer;
    +                using const_pointer = typename std::allocator_traits::const_pointer;
    +                using void_pointer = typename std::allocator_traits::void_pointer;
    +                using const_void_pointer =
    +                    typename std::allocator_traits::const_void_pointer;
    +                using reference = typename std::allocator_traits::value_type &;
    +                using const_reference =
    +                    const typename std::allocator_traits::value_type &;
    +                using difference_type =
    +                    typename std::allocator_traits::difference_type;
    +                using size_type = typename std::allocator_traits::size_type;
    +                using propagate_on_container_copy_assignment = typename std::allocator_traits<
    +                    Alloc>::propagate_on_container_copy_assignment;
    +                using propagate_on_container_move_assignment = typename std::allocator_traits<
    +                    Alloc>::propagate_on_container_move_assignment;
    +                using propagate_on_container_swap =
    +                    typename std::allocator_traits::propagate_on_container_swap;
    +                using is_always_equal =
    +                    typename std::allocator_traits::is_always_equal;
    +
    +                template 
    +                struct rebind
    +                {
    +                    typedef usm_allocator other;
    +                };
    +
    +                usm_allocator() : _impl(dpct::get_default_queue()) {}
    +                ~usm_allocator() {}
    +                usm_allocator(const usm_allocator &other) : _impl(other._impl) {}
    +                usm_allocator(usm_allocator &&other) : _impl(std::move(other._impl)) {}
    +                pointer address(reference r) { return &r; }
    +                const_pointer address(const_reference r) { return &r; }
    +                pointer allocate(size_type cnt, const_void_pointer hint = nullptr)
    +                {
    +                    return std::allocator_traits::allocate(_impl, cnt, hint);
    +                }
    +                void deallocate(pointer p, size_type cnt)
    +                {
    +                    std::allocator_traits::deallocate(_impl, p, cnt);
    +                }
    +                size_type max_size() const
    +                {
    +                    return std::allocator_traits::max_size(_impl);
    +                }
    +                bool operator==(const usm_allocator &other) const { return _impl == other._impl; }
    +                bool operator!=(const usm_allocator &other) const { return _impl != other._impl; }
    +            };
    +
    +        } // namespace deprecated
    +
    +        inline void dpct_free(void *ptr,
    +                              const sycl::queue &q)
    +        {
    +            if (ptr)
    +            {
    +                sycl::free(ptr, q.get_context());
    +            }
    +        }
    +
    +        template 
    +        inline auto get_memory(const void *x)
    +        {
    +            T *new_x = reinterpret_cast(const_cast(x));
    +            return new_x;
    +        }
    +
    +        template 
    +        inline typename DataType::T2 get_value(const T *s, sycl::queue &q)
    +        {
    +            using Ty = typename DataType::T2;
    +            Ty s_h;
    +            if (get_pointer_attribute(q, s) == pointer_access_attribute::device_only)
    +                detail::dpct_memcpy(q, (void *)&s_h, (const void *)s, sizeof(T), device_to_host)
    +                    .wait();
    +            else
    +                s_h = *reinterpret_cast(s);
    +            return s_h;
    +        }
    +
    +    } // namespace detail
    +
    +    template 
    +    inline auto get_value(const T *s, sycl::queue &q)
    +    {
    +        return detail::get_value(s, q);
    +    }
    +
    +    namespace detail
    +    {
    +        template 
    +        inline void gemm_impl(sycl::queue &q, oneapi::mkl::transpose a_trans,
    +                              oneapi::mkl::transpose b_trans, int m, int n, int k,
    +                              const void *alpha, const void *a, int lda, const void *b,
    +                              int ldb, const void *beta, void *c, int ldc)
    +        {
    +            Ts alpha_value = dpct::get_value(reinterpret_cast(alpha), q);
    +            Ts beta_value = dpct::get_value(reinterpret_cast(beta), q);
    +            auto data_a = get_memory(a);
    +            auto data_b = get_memory(b);
    +            auto data_c = get_memory(c);
    +            oneapi::mkl::blas::column_major::gemm(
    +                q, a_trans, b_trans, m, n, k, alpha_value, data_a, lda,
    +                data_b, ldb, beta_value, data_c, ldc);
    +        }
    +
    +        template 
    +        class vectorized_binary
    +        {
    +        public:
    +            inline VecT operator()(VecT a, VecT b, const BinaryOperation binary_op)
    +            {
    +                VecT v4;
    +                for (size_t i = 0; i < v4.size(); ++i)
    +                {
    +                    v4[i] = binary_op(a[i], b[i]);
    +                }
    +                return v4;
    +            }
    +        };
    +
    +        template 
    +        class vectorized_binary<
    +            VecT, BinaryOperation,
    +            std::void_t>>
    +        {
    +        public:
    +            inline VecT operator()(VecT a, VecT b, const BinaryOperation binary_op)
    +            {
    +                return binary_op(a, b).template as();
    +            }
    +        };
    +
    +        template 
    +        inline void gemm_batch_impl(sycl::queue &q, oneapi::mkl::transpose a_trans,
    +                                    oneapi::mkl::transpose b_trans, int m, int n, int k,
    +                                    const void *alpha, const void **a, int lda,
    +                                    const void **b, int ldb, const void *beta, void **c,
    +                                    int ldc, int batch_size)
    +        {
    +            struct matrix_info_t
    +            {
    +                oneapi::mkl::transpose transpose_info[2];
    +                Ts value_info[2];
    +                std::int64_t size_info[3];
    +                std::int64_t ld_info[3];
    +                std::int64_t groupsize_info;
    +            };
    +
    +            Ts alpha_value = dpct::get_value(reinterpret_cast(alpha), q);
    +            Ts beta_value = dpct::get_value(reinterpret_cast(beta), q);
    +
    +            matrix_info_t *matrix_info =
    +                (matrix_info_t *)std::malloc(sizeof(matrix_info_t));
    +            matrix_info->transpose_info[0] = a_trans;
    +            matrix_info->transpose_info[1] = b_trans;
    +            matrix_info->value_info[0] = alpha_value;
    +            matrix_info->value_info[1] = beta_value;
    +            matrix_info->size_info[0] = m;
    +            matrix_info->size_info[1] = n;
    +            matrix_info->size_info[2] = k;
    +            matrix_info->ld_info[0] = lda;
    +            matrix_info->ld_info[1] = ldb;
    +            matrix_info->ld_info[2] = ldc;
    +            matrix_info->groupsize_info = batch_size;
    +
    +            sycl::event e = oneapi::mkl::blas::column_major::gemm_batch(
    +                q, matrix_info->transpose_info, matrix_info->transpose_info + 1,
    +                matrix_info->size_info, matrix_info->size_info + 1,
    +                matrix_info->size_info + 2, matrix_info->value_info,
    +                reinterpret_cast(a), matrix_info->ld_info,
    +                reinterpret_cast(b), matrix_info->ld_info + 1,
    +                matrix_info->value_info + 1, reinterpret_cast(c),
    +                matrix_info->ld_info + 2, 1, &(matrix_info->groupsize_info));
    +
    +            q.submit([&](sycl::handler &cgh)
    +                     {
    +    cgh.depends_on(e);
    +    cgh.host_task([=] { std::free(matrix_info); }); });
    +        }
    +
    +        template 
    +        inline void
    +        gemm_batch_impl(sycl::queue &q, oneapi::mkl::transpose a_trans,
    +                        oneapi::mkl::transpose b_trans, int m, int n,
    +                        int k, const void *alpha, const void *a, int lda,
    +                        long long int stride_a, const void *b, int ldb,
    +                        long long int stride_b, const void *beta, void *c,
    +                        int ldc, long long int stride_c, int batch_size)
    +        {
    +            Ts alpha_value = dpct::get_value(reinterpret_cast(alpha), q);
    +            Ts beta_value = dpct::get_value(reinterpret_cast(beta), q);
    +            auto data_a = get_memory(a);
    +            auto data_b = get_memory(b);
    +            auto data_c = get_memory(c);
    +            oneapi::mkl::blas::column_major::gemm_batch(
    +                q, a_trans, b_trans, m, n, k, alpha_value, data_a, lda,
    +                stride_a, data_b, ldb, stride_b, beta_value,
    +                data_c, ldc, stride_c, batch_size);
    +        }
    +
    +    } // namespace detail
    +
    +    template 
    +    inline unsigned vectorized_binary(unsigned a, unsigned b,
    +                                      const BinaryOperation binary_op)
    +    {
    +        sycl::vec v0{a}, v1{b};
    +        auto v2 = v0.as();
    +        auto v3 = v1.as();
    +        auto v4 =
    +            detail::vectorized_binary()(v2, v3, binary_op);
    +        v0 = v4.template as>();
    +        return v0;
    +    }
    +
    +    static void async_dpct_memcpy(void *to_ptr, const void *from_ptr, size_t size,
    +                                  memcpy_direction direction = automatic,
    +                                  sycl::queue &q = dpct::get_default_queue())
    +    {
    +        detail::dpct_memcpy(q, to_ptr, from_ptr, size, direction);
    +    }
    +
    +    static inline unsigned int select_device(unsigned int id)
    +    {
    +        dev_mgr::instance().select_device(id);
    +        return id;
    +    }
    +
    +    template 
    +    T permute_sub_group_by_xor(sycl::sub_group g, T x, unsigned int mask,
    +                               unsigned int logical_sub_group_size = 32)
    +    {
    +        unsigned int id = g.get_local_linear_id();
    +        unsigned int start_index =
    +            id / logical_sub_group_size * logical_sub_group_size;
    +        unsigned int target_offset = (id % logical_sub_group_size) ^ mask;
    +        return sycl::select_from_group(g, x,
    +                                       target_offset < logical_sub_group_size
    +                                           ? start_index + target_offset
    +                                           : id);
    +    }
    +
    +    template 
    +    sycl::vec extract_and_sign_or_zero_extend4(T val)
    +    {
    +        return sycl::vec(val)
    +            .template as, int8_t, uint8_t>, 4>>()
    +            .template convert();
    +    }
    +
    +    template 
    +    using dot_product_acc_t =
    +        std::conditional_t && std::is_unsigned_v,
    +                           uint32_t, int32_t>;
    +
    +    template 
    +    inline auto dp4a(T1 a, T2 b, T3 c)
    +    {
    +        dot_product_acc_t res = c;
    +        auto va = extract_and_sign_or_zero_extend4(a);
    +        auto vb = extract_and_sign_or_zero_extend4(b);
    +        res += va[0] * vb[0];
    +        res += va[1] * vb[1];
    +        res += va[2] * vb[2];
    +        res += va[3] * vb[3];
    +        return res;
    +    }
    +
    +    struct sub_sat
    +    {
    +        template 
    +        auto operator()(const T x, const T y) const
    +        {
    +            return sycl::sub_sat(x, y);
    +        }
    +    };
    +
    +    template 
    +    inline T vectorized_min(T a, T b)
    +    {
    +        sycl::vec v0{a}, v1{b};
    +        auto v2 = v0.template as();
    +        auto v3 = v1.template as();
    +        auto v4 = sycl::min(v2, v3);
    +        v0 = v4.template as>();
    +        return v0;
    +    }
    +
    +    inline float pow(const float a, const int b) { return sycl::pown(a, b); }
    +    inline double pow(const double a, const int b) { return sycl::pown(a, b); }
    +    inline float pow(const float a, const float b) { return sycl::pow(a, b); }
    +    inline double pow(const double a, const double b) { return sycl::pow(a, b); }
    +    template 
    +    inline typename std::enable_if_t, T>
    +    pow(const T a, const U b)
    +    {
    +        return sycl::pow(a, static_cast(b));
    +    }
    +    template 
    +    inline typename std::enable_if_t, double>
    +    pow(const T a, const U b)
    +    {
    +        return sycl::pow(static_cast(a), static_cast(b));
    +    }
    +
    +    inline double min(const double a, const float b)
    +    {
    +        return sycl::fmin(a, static_cast(b));
    +    }
    +    inline double min(const float a, const double b)
    +    {
    +        return sycl::fmin(static_cast(a), b);
    +    }
    +    inline float min(const float a, const float b) { return sycl::fmin(a, b); }
    +    inline double min(const double a, const double b) { return sycl::fmin(a, b); }
    +    inline std::uint32_t min(const std::uint32_t a, const std::int32_t b)
    +    {
    +        return sycl::min(a, static_cast(b));
    +    }
    +    inline std::uint32_t min(const std::int32_t a, const std::uint32_t b)
    +    {
    +        return sycl::min(static_cast(a), b);
    +    }
    +    inline std::int32_t min(const std::int32_t a, const std::int32_t b)
    +    {
    +        return sycl::min(a, b);
    +    }
    +    inline std::uint32_t min(const std::uint32_t a, const std::uint32_t b)
    +    {
    +        return sycl::min(a, b);
    +    }
    +    inline std::uint64_t min(const std::uint64_t a, const std::int64_t b)
    +    {
    +        return sycl::min(a, static_cast(b));
    +    }
    +    inline std::uint64_t min(const std::int64_t a, const std::uint64_t b)
    +    {
    +        return sycl::min(static_cast(a), b);
    +    }
    +    inline std::int64_t min(const std::int64_t a, const std::int64_t b)
    +    {
    +        return sycl::min(a, b);
    +    }
    +    inline std::uint64_t min(const std::uint64_t a, const std::uint64_t b)
    +    {
    +        return sycl::min(a, b);
    +    }
    +    inline std::uint64_t min(const std::uint64_t a, const std::int32_t b)
    +    {
    +        return sycl::min(a, static_cast(b));
    +    }
    +    inline std::uint64_t min(const std::int32_t a, const std::uint64_t b)
    +    {
    +        return sycl::min(static_cast(a), b);
    +    }
    +    inline std::uint64_t min(const std::uint64_t a, const std::uint32_t b)
    +    {
    +        return sycl::min(a, static_cast(b));
    +    }
    +    inline std::uint64_t min(const std::uint32_t a, const std::uint64_t b)
    +    {
    +        return sycl::min(static_cast(a), b);
    +    }
    +    // max function overloads.
    +    // For floating-point types, `float` or `double` arguments are acceptable.
    +    // For integer types, `std::uint32_t`, `std::int32_t`, `std::uint64_t` or
    +    // `std::int64_t` type arguments are acceptable.
    +    inline double max(const double a, const float b)
    +    {
    +        return sycl::fmax(a, static_cast(b));
    +    }
    +    inline double max(const float a, const double b)
    +    {
    +        return sycl::fmax(static_cast(a), b);
    +    }
    +    inline float max(const float a, const float b) { return sycl::fmax(a, b); }
    +    inline double max(const double a, const double b) { return sycl::fmax(a, b); }
    +    inline std::uint32_t max(const std::uint32_t a, const std::int32_t b)
    +    {
    +        return sycl::max(a, static_cast(b));
    +    }
    +    inline std::uint32_t max(const std::int32_t a, const std::uint32_t b)
    +    {
    +        return sycl::max(static_cast(a), b);
    +    }
    +    inline std::int32_t max(const std::int32_t a, const std::int32_t b)
    +    {
    +        return sycl::max(a, b);
    +    }
    +    inline std::uint32_t max(const std::uint32_t a, const std::uint32_t b)
    +    {
    +        return sycl::max(a, b);
    +    }
    +    inline std::uint64_t max(const std::uint64_t a, const std::int64_t b)
    +    {
    +        return sycl::max(a, static_cast(b));
    +    }
    +    inline std::uint64_t max(const std::int64_t a, const std::uint64_t b)
    +    {
    +        return sycl::max(static_cast(a), b);
    +    }
    +    inline std::int64_t max(const std::int64_t a, const std::int64_t b)
    +    {
    +        return sycl::max(a, b);
    +    }
    +    inline std::uint64_t max(const std::uint64_t a, const std::uint64_t b)
    +    {
    +        return sycl::max(a, b);
    +    }
    +    inline std::uint64_t max(const std::uint64_t a, const std::int32_t b)
    +    {
    +        return sycl::max(a, static_cast(b));
    +    }
    +    inline std::uint64_t max(const std::int32_t a, const std::uint64_t b)
    +    {
    +        return sycl::max(static_cast(a), b);
    +    }
    +    inline std::uint64_t max(const std::uint64_t a, const std::uint32_t b)
    +    {
    +        return sycl::max(a, static_cast(b));
    +    }
    +    inline std::uint64_t max(const std::uint32_t a, const std::uint64_t b)
    +    {
    +        return sycl::max(static_cast(a), b);
    +    }
    +
    +    inline void
    +    has_capability_or_fail(const sycl::device &dev,
    +                           const std::initializer_list &props)
    +    {
    +        for (const auto &it : props)
    +        {
    +            if (dev.has(it))
    +                continue;
    +            switch (it)
    +            {
    +            case sycl::aspect::fp64:
    +                throw std::runtime_error("'double' is not supported in '" +
    +                                         dev.get_info() +
    +                                         "' device");
    +                break;
    +            case sycl::aspect::fp16:
    +                throw std::runtime_error("'half' is not supported in '" +
    +                                         dev.get_info() +
    +                                         "' device");
    +                break;
    +            default:
    +#define __SYCL_ASPECT(ASPECT, ID) \
    +    case sycl::aspect::ASPECT:    \
    +        return #ASPECT;
    +#define __SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE) __SYCL_ASPECT(ASPECT, ID)
    +#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE)
    +                auto getAspectNameStr = [](sycl::aspect AspectNum) -> std::string
    +                {
    +                    switch (AspectNum)
    +                    {
    +#include 
    +#include 
    +                    default:
    +                        return "unknown aspect";
    +                    }
    +                };
    +#undef __SYCL_ASPECT_DEPRECATED_ALIAS
    +#undef __SYCL_ASPECT_DEPRECATED
    +#undef __SYCL_ASPECT
    +                throw std::runtime_error(
    +                    "'" + getAspectNameStr(it) + "' is not supported in '" +
    +                    dev.get_info() + "' device");
    +            }
    +            break;
    +        }
    +    }
    +
    +    static inline unsigned int get_current_device_id()
    +    {
    +        return dev_mgr::instance().current_device_id();
    +    }
    +
    +    static inline device_ext &get_current_device()
    +    {
    +        return dev_mgr::instance().current_device();
    +    }
    +
    +    static inline sycl::queue &get_in_order_queue()
    +    {
    +        return dev_mgr::instance().current_device().in_order_queue();
    +    }
    +
    +    static sycl::event
    +    dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr, size_t size,
    +                memcpy_direction direction,
    +                const std::vector &dep_events = {})
    +    {
    +        if (!size)
    +            return sycl::event{};
    +        return q.memcpy(to_ptr, from_ptr, size, dep_events);
    +        GGML_UNUSED(direction);
    +    }
    +
    +    // Get actual copy range and make sure it will not exceed range.
    +    static inline size_t get_copy_range(sycl::range<3> size, size_t slice,
    +                                        size_t pitch)
    +    {
    +        return slice * (size.get(2) - 1) + pitch * (size.get(1) - 1) + size.get(0);
    +    }
    +
    +    static inline size_t get_offset(sycl::id<3> id, size_t slice,
    +                                    size_t pitch)
    +    {
    +        return slice * id.get(2) + pitch * id.get(1) + id.get(0);
    +    }
    +
    +    /// copy 3D matrix specified by \p size from 3D matrix specified by \p from_ptr
    +    /// and \p from_range to another specified by \p to_ptr and \p to_range.
    +    static inline std::vector
    +    dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    +                sycl::range<3> to_range, sycl::range<3> from_range,
    +                sycl::id<3> to_id, sycl::id<3> from_id,
    +                sycl::range<3> size, memcpy_direction direction,
    +                const std::vector &dep_events = {})
    +    {
    +        // RAII for host pointer
    +        class host_buffer
    +        {
    +            void *_buf;
    +            size_t _size;
    +            sycl::queue &_q;
    +            const std::vector &_deps; // free operation depends
    +
    +        public:
    +            host_buffer(size_t size, sycl::queue &q,
    +                        const std::vector &deps)
    +                : _buf(std::malloc(size)), _size(size), _q(q), _deps(deps) {}
    +            void *get_ptr() const { return _buf; }
    +            size_t get_size() const { return _size; }
    +            ~host_buffer()
    +            {
    +                if (_buf)
    +                {
    +                    _q.submit([&](sycl::handler &cgh)
    +                              {
    +            cgh.depends_on(_deps);
    +            cgh.host_task([buf = _buf] { std::free(buf); }); });
    +                }
    +            }
    +        };
    +        std::vector event_list;
    +
    +        size_t to_slice = to_range.get(1) * to_range.get(0),
    +               from_slice = from_range.get(1) * from_range.get(0);
    +        unsigned char *to_surface =
    +            (unsigned char *)to_ptr + get_offset(to_id, to_slice, to_range.get(0));
    +        const unsigned char *from_surface =
    +            (const unsigned char *)from_ptr +
    +            get_offset(from_id, from_slice, from_range.get(0));
    +
    +        if (to_slice == from_slice && to_slice == size.get(1) * size.get(0))
    +        {
    +            return {dpct_memcpy(q, to_surface, from_surface, to_slice * size.get(2),
    +                                direction, dep_events)};
    +        }
    +        direction = detail::deduce_memcpy_direction(q, to_ptr, from_ptr, direction);
    +        size_t size_slice = size.get(1) * size.get(0);
    +        switch (direction)
    +        {
    +        case host_to_host:
    +            for (size_t z = 0; z < size.get(2); ++z)
    +            {
    +                unsigned char *to_ptr = to_surface;
    +                const unsigned char *from_ptr = from_surface;
    +                if (to_range.get(0) == from_range.get(0) &&
    +                    to_range.get(0) == size.get(0))
    +                {
    +                    event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size_slice,
    +                                                     direction, dep_events));
    +                }
    +                else
    +                {
    +                    for (size_t y = 0; y < size.get(1); ++y)
    +                    {
    +                        event_list.push_back(dpct_memcpy(q, to_ptr, from_ptr, size.get(0),
    +                                                         direction, dep_events));
    +                        to_ptr += to_range.get(0);
    +                        from_ptr += from_range.get(0);
    +                    }
    +                }
    +                to_surface += to_slice;
    +                from_surface += from_slice;
    +            }
    +            break;
    +        case host_to_device:
    +        {
    +            host_buffer buf(get_copy_range(size, to_slice, to_range.get(0)), q,
    +                            event_list);
    +            std::vector host_events;
    +            if (to_slice == size_slice)
    +            {
    +                // Copy host data to a temp host buffer with the shape of target.
    +                host_events =
    +                    dpct_memcpy(q, buf.get_ptr(), from_surface, to_range, from_range,
    +                                sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size,
    +                                host_to_host, dep_events);
    +            }
    +            else
    +            {
    +                // Copy host data to a temp host buffer with the shape of target.
    +                host_events = dpct_memcpy(
    +                    q, buf.get_ptr(), from_surface, to_range, from_range,
    +                    sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0), size, host_to_host,
    +                    // If has padding data, not sure whether it is useless. So fill temp
    +                    // buffer with it.
    +                    std::vector{
    +                        dpct_memcpy(q, buf.get_ptr(), to_surface, buf.get_size(),
    +                                    device_to_host, dep_events)});
    +            }
    +            // Copy from temp host buffer to device with only one submit.
    +            event_list.push_back(dpct_memcpy(q, to_surface, buf.get_ptr(),
    +                                             buf.get_size(), host_to_device,
    +                                             host_events));
    +            break;
    +        }
    +        case device_to_host:
    +        {
    +            host_buffer buf(get_copy_range(size, from_slice, from_range.get(0)), q,
    +                            event_list);
    +            // Copy from host temp buffer to host target with reshaping.
    +            event_list = dpct_memcpy(
    +                q, to_surface, buf.get_ptr(), to_range, from_range, sycl::id<3>(0, 0, 0),
    +                sycl::id<3>(0, 0, 0), size, host_to_host,
    +                // Copy from device to temp host buffer with only one submit.
    +                std::vector{dpct_memcpy(q, buf.get_ptr(), from_surface,
    +                                                     buf.get_size(),
    +                                                     device_to_host, dep_events)});
    +            break;
    +        }
    +        case device_to_device:
    +            event_list.push_back(q.submit([&](sycl::handler &cgh)
    +                                          {
    +        cgh.depends_on(dep_events);
    +        cgh.parallel_for(
    +            size,
    +            [=](sycl::id<3> id) {
    +                to_surface[get_offset(id, to_slice, to_range.get(0))] =
    +                    from_surface[get_offset(id, from_slice, from_range.get(0))];
    +            }); }));
    +        break;
    +        default:
    +            throw std::runtime_error("dpct_memcpy: invalid direction value");
    +        }
    +        return event_list;
    +    }
    +
    +    /// memcpy 2D/3D matrix specified by pitched_data.
    +    static inline std::vector
    +    dpct_memcpy(sycl::queue &q, pitched_data to, sycl::id<3> to_id,
    +                pitched_data from, sycl::id<3> from_id, sycl::range<3> size,
    +                memcpy_direction direction = automatic)
    +    {
    +        return dpct_memcpy(q, to.get_data_ptr(), from.get_data_ptr(),
    +                           sycl::range<3>(to.get_pitch(), to.get_y(), 1),
    +                           sycl::range<3>(from.get_pitch(), from.get_y(), 1), to_id, from_id,
    +                           size, direction);
    +    }
    +
    +    /// memcpy 2D matrix with pitch.
    +    static inline std::vector
    +    dpct_memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr,
    +                size_t to_pitch, size_t from_pitch, size_t x, size_t y,
    +                memcpy_direction direction = automatic)
    +    {
    +        return dpct_memcpy(q, to_ptr, from_ptr, sycl::range<3>(to_pitch, y, 1),
    +                           sycl::range<3>(from_pitch, y, 1),
    +                           sycl::id<3>(0, 0, 0), sycl::id<3>(0, 0, 0),
    +                           sycl::range<3>(x, y, 1), direction);
    +    }
    +
    +    inline void gemm(sycl::queue &q, oneapi::mkl::transpose a_trans,
    +                     oneapi::mkl::transpose b_trans, int m, int n, int k,
    +                     const void *alpha, const void *a, library_data_t a_type,
    +                     int lda, const void *b, library_data_t b_type, int ldb,
    +                     const void *beta, void *c, library_data_t c_type, int ldc,
    +                     library_data_t scaling_type)
    +    {
    +        if (scaling_type == library_data_t::real_float &&
    +            c_type == library_data_t::complex_float)
    +        {
    +            scaling_type = library_data_t::complex_float;
    +        }
    +        else if (scaling_type == library_data_t::real_double &&
    +                 c_type == library_data_t::complex_double)
    +        {
    +            scaling_type = library_data_t::complex_double;
    +        }
    +
    +        std::uint64_t key =
    +            detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
    +        switch (key)
    +        {
    +        case detail::get_type_combination_id(
    +            library_data_t::real_float, library_data_t::real_float,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_double, library_data_t::real_double,
    +            library_data_t::real_double, library_data_t::real_double):
    +        {
    +            detail::gemm_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::complex_float, library_data_t::complex_float,
    +            library_data_t::complex_float, library_data_t::complex_float):
    +        {
    +            detail::gemm_impl, std::complex,
    +                              std::complex, std::complex>(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::complex_double, library_data_t::complex_double,
    +            library_data_t::complex_double, library_data_t::complex_double):
    +        {
    +            detail::gemm_impl, std::complex,
    +                              std::complex, std::complex>(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_half, library_data_t::real_half):
    +        {
    +            detail::gemm_impl(q, a_trans, b_trans, m, n, k, alpha, a,
    +                                          lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +#ifdef __INTEL_MKL__
    +        case detail::get_type_combination_id(
    +            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_impl(q, a_trans, b_trans, m, n, k, alpha, a, lda, b,
    +                                     ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_half, library_data_t::real_float):
    +        {
    +            float alpha_value =
    +                dpct::get_value(reinterpret_cast(alpha), q);
    +            float beta_value =
    +                dpct::get_value(reinterpret_cast(beta), q);
    +            sycl::half alpha_half(alpha_value);
    +            sycl::half beta_half(beta_value);
    +            detail::gemm_impl(q, a_trans, b_trans, m, n, k, &alpha_half,
    +                                          a, lda, b, ldb, &beta_half, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_int8, library_data_t::real_int8,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    +            library_data_t::real_bfloat16, library_data_t::real_float):
    +        {
    +            detail::gemm_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_int8, library_data_t::real_int8,
    +            library_data_t::real_int32, library_data_t::real_int32):
    +        {
    +            float alpha_float =
    +                dpct::get_value(reinterpret_cast(alpha), q);
    +            float beta_float =
    +                dpct::get_value(reinterpret_cast(beta), q);
    +            detail::gemm_impl(
    +                q, a_trans, b_trans, m, n, k, &alpha_float, a, lda, b, ldb, &beta_float, c, ldc);
    +            break;
    +        }
    +#endif // __INTEL_MKL__
    +        default:
    +            throw std::runtime_error("the combination of data type is unsupported");
    +        }
    +    } // gemm()
    +
    +    /// Computes a batch of matrix-matrix product with general matrices.
    +    /// \param [in] q The queue where the routine should be executed.
    +    /// \param [in] a_trans Specifies the operation applied to A.
    +    /// \param [in] b_trans Specifies the operation applied to B.
    +    /// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C.
    +    /// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C.
    +    /// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B).
    +    /// \param [in] alpha Scaling factor for the matrix-matrix product.
    +    /// \param [in] a Input matrix A.
    +    /// \param [in] a_type Data type of the matrix A.
    +    /// \param [in] lda Leading dimension of A.
    +    /// \param [in] b Input matrix B.
    +    /// \param [in] b_type Data type of the matrix B.
    +    /// \param [in] ldb Leading dimension of B.
    +    /// \param [in] beta Scaling factor for matrix C.
    +    /// \param [in, out] c Input/Output matrix C.
    +    /// \param [in] c_type Data type of the matrix C.
    +    /// \param [in] ldc Leading dimension of C.
    +    /// \param [in] batch_size Specifies the number of matrix multiply operations to perform.
    +    /// \param [in] scaling_type Data type of the scaling factors.
    +    inline void gemm_batch(sycl::queue &q, oneapi::mkl::transpose a_trans,
    +                           oneapi::mkl::transpose b_trans, int m, int n, int k,
    +                           const void *alpha, const void *a[],
    +                           library_data_t a_type, int lda, const void *b[],
    +                           library_data_t b_type, int ldb, const void *beta,
    +                           void *c[], library_data_t c_type, int ldc,
    +                           int batch_size, library_data_t scaling_type)
    +    {
    +        if (scaling_type == library_data_t::real_float &&
    +            c_type == library_data_t::complex_float)
    +        {
    +            scaling_type = library_data_t::complex_float;
    +        }
    +        else if (scaling_type == library_data_t::real_double &&
    +                 c_type == library_data_t::complex_double)
    +        {
    +            scaling_type = library_data_t::complex_double;
    +        }
    +
    +        std::uint64_t key =
    +            detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
    +        switch (key)
    +        {
    +        case detail::get_type_combination_id(
    +            library_data_t::real_float, library_data_t::real_float,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_double, library_data_t::real_double,
    +            library_data_t::real_double, library_data_t::real_double):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::complex_float, library_data_t::complex_float,
    +            library_data_t::complex_float, library_data_t::complex_float):
    +        {
    +            detail::gemm_batch_impl, std::complex,
    +                                    std::complex, std::complex>(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::complex_double, library_data_t::complex_double,
    +            library_data_t::complex_double, library_data_t::complex_double):
    +        {
    +            detail::gemm_batch_impl, std::complex,
    +                                    std::complex, std::complex>(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_half, library_data_t::real_half):
    +        {
    +            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha,
    +                                                a, lda, b, ldb, beta, c, ldc,
    +                                                batch_size);
    +            break;
    +        }
    +#ifdef __INTEL_MKL__
    +        case detail::get_type_combination_id(
    +            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    +            library_data_t::real_bfloat16, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha, a, lda,
    +                                           b, ldb, beta, c, ldc, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_int8, library_data_t::real_int8,
    +            library_data_t::real_int32, library_data_t::real_int32):
    +        {
    +            float alpha_float =
    +                dpct::get_value(reinterpret_cast(alpha), q);
    +            float beta_float =
    +                dpct::get_value(reinterpret_cast(beta), q);
    +            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, &alpha_float,
    +                                           a, lda, b, ldb, &beta_float, c, ldc,
    +                                           batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_int8, library_data_t::real_int8,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +#endif
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_half, library_data_t::real_float):
    +        {
    +            float alpha_value =
    +                dpct::get_value(reinterpret_cast(alpha), q);
    +            float beta_value =
    +                dpct::get_value(reinterpret_cast(beta), q);
    +            sycl::half alpha_half(alpha_value);
    +            sycl::half beta_half(beta_value);
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, &alpha_half, a, lda, b, ldb, &beta_half, c, ldc,
    +                batch_size);
    +            break;
    +        }
    +        default:
    +            throw std::runtime_error("the combination of data type is unsupported");
    +        }
    +    }
    +
    +    /// Computes a batch of matrix-matrix product with general matrices.
    +    /// \param [in] q The queue where the routine should be executed.
    +    /// \param [in] a_trans Specifies the operation applied to A.
    +    /// \param [in] b_trans Specifies the operation applied to B.
    +    /// \param [in] m Specifies the number of rows of the matrix op(A) and of the matrix C.
    +    /// \param [in] n Specifies the number of columns of the matrix op(B) and of the matrix C.
    +    /// \param [in] k Specifies the number of columns of the matrix op(A) and the number of rows of the matrix op(B).
    +    /// \param [in] alpha Scaling factor for the matrix-matrix product.
    +    /// \param [in] a Input matrix A.
    +    /// \param [in] a_type Data type of the matrix A.
    +    /// \param [in] lda Leading dimension of A.
    +    /// \param [in] stride_a Stride between the different A matrices.
    +    /// \param [in] b Input matrix B.
    +    /// \param [in] b_type Data type of the matrix B.
    +    /// \param [in] ldb Leading dimension of B.
    +    /// \param [in] stride_b Stride between the different B matrices.
    +    /// \param [in] beta Scaling factor for matrix C.
    +    /// \param [in, out] c Input/Output matrix C.
    +    /// \param [in] c_type Data type of the matrix C.
    +    /// \param [in] ldc Leading dimension of C.
    +    /// \param [in] stride_c Stride between the different C matrices.
    +    /// \param [in] batch_size Specifies the number of matrix multiply operations to perform.
    +    /// \param [in] scaling_type Data type of the scaling factors.
    +    inline void gemm_batch(sycl::queue &q, oneapi::mkl::transpose a_trans,
    +                           oneapi::mkl::transpose b_trans, int m, int n, int k,
    +                           const void *alpha, const void *a, library_data_t a_type,
    +                           int lda, long long int stride_a, const void *b,
    +                           library_data_t b_type, int ldb, long long int stride_b,
    +                           const void *beta, void *c, library_data_t c_type,
    +                           int ldc, long long int stride_c, int batch_size,
    +                           library_data_t scaling_type)
    +    {
    +        if (scaling_type == library_data_t::real_float &&
    +            c_type == library_data_t::complex_float)
    +        {
    +            scaling_type = library_data_t::complex_float;
    +        }
    +        else if (scaling_type == library_data_t::real_double &&
    +                 c_type == library_data_t::complex_double)
    +        {
    +            scaling_type = library_data_t::complex_double;
    +        }
    +
    +        std::uint64_t key =
    +            detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
    +        switch (key)
    +        {
    +        case detail::get_type_combination_id(
    +            library_data_t::real_float, library_data_t::real_float,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    +                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_double, library_data_t::real_double,
    +            library_data_t::real_double, library_data_t::real_double):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    +                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::complex_float, library_data_t::complex_float,
    +            library_data_t::complex_float, library_data_t::complex_float):
    +        {
    +            detail::gemm_batch_impl, std::complex,
    +                                    std::complex, std::complex>(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    +                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::complex_double, library_data_t::complex_double,
    +            library_data_t::complex_double, library_data_t::complex_double):
    +        {
    +            detail::gemm_batch_impl, std::complex,
    +                                    std::complex, std::complex>(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    +                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_half, library_data_t::real_half):
    +        {
    +            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha,
    +                                                a, lda, stride_a, b, ldb, stride_b,
    +                                                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +#ifdef __INTEL_MKL__
    +        case detail::get_type_combination_id(
    +            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    +            library_data_t::real_bfloat16, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    +                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_bfloat16, library_data_t::real_bfloat16,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha, a, lda,
    +                                           stride_a, b, ldb, stride_b, beta, c, ldc,
    +                                           stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_int8, library_data_t::real_int8,
    +            library_data_t::real_int32, library_data_t::real_int32):
    +        {
    +            detail::gemm_batch_impl(q, a_trans, b_trans, m, n, k, alpha,
    +                                                  a, lda, stride_a, b, ldb, stride_b,
    +                                                  beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_int8, library_data_t::real_int8,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    +                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_float, library_data_t::real_float):
    +        {
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, alpha, a, lda, stride_a, b, ldb, stride_b,
    +                beta, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +#endif
    +        case detail::get_type_combination_id(
    +            library_data_t::real_half, library_data_t::real_half,
    +            library_data_t::real_half, library_data_t::real_float):
    +        {
    +            float alpha_value =
    +                dpct::get_value(reinterpret_cast(alpha), q);
    +            float beta_value =
    +                dpct::get_value(reinterpret_cast(beta), q);
    +            sycl::half alpha_half(alpha_value);
    +            sycl::half beta_half(beta_value);
    +            detail::gemm_batch_impl(
    +                q, a_trans, b_trans, m, n, k, &alpha_half, a, lda, stride_a, b, ldb, stride_b,
    +                &beta_half, c, ldc, stride_c, batch_size);
    +            break;
    +        }
    +        default:
    +            throw std::runtime_error("the combination of data type is unsupported");
    +        }
    +    }
    +
    +    static inline void
    +    async_dpct_memcpy(void *to_ptr, size_t to_pitch, const void *from_ptr,
    +                      size_t from_pitch, size_t x, size_t y,
    +                      memcpy_direction direction = automatic,
    +                      sycl::queue &q = get_default_queue())
    +    {
    +        detail::dpct_memcpy(q, to_ptr, from_ptr, to_pitch, from_pitch, x, y,
    +                            direction);
    +    }
    +
    +    using err0 = detail::generic_error_type;
    +    using err1 = detail::generic_error_type;
    +
    +    static inline void dpct_free(void *ptr, sycl::queue &q = get_default_queue()) {
    +        detail::dpct_free(ptr, q);
    +    }
    +
    +    /// dpct accessor used as device function parameter.
    +    template  class accessor;
    +    template  class accessor {
    +    public:
    +        using memory_t = detail::memory_traits;
    +        using element_t = typename memory_t::element_t;
    +        using pointer_t = typename memory_t::pointer_t;
    +        using accessor_t = typename memory_t::template accessor_t<3>;
    +        accessor(pointer_t data, const sycl::range<3> &in_range)
    +            : _data(data), _range(in_range) {}
    +        template 
    +        accessor(typename std::enable_if::type &acc)
    +            : accessor(acc, acc.get_range()) {}
    +        accessor(const accessor_t &acc, const sycl::range<3> &in_range)
    +            : accessor(acc.get_pointer(), in_range) {}
    +        accessor operator[](size_t index) const {
    +            sycl::range<2> sub(_range.get(1), _range.get(2));
    +            return accessor(_data + index * sub.size(), sub);
    +        }
    +
    +        pointer_t get_ptr() const { return _data; }
    +
    +    private:
    +        pointer_t _data;
    +        sycl::range<3> _range;
    +    };
    +    template  class accessor {
    +    public:
    +        using memory_t = detail::memory_traits;
    +        using element_t = typename memory_t::element_t;
    +        using pointer_t = typename memory_t::pointer_t;
    +        using accessor_t = typename memory_t::template accessor_t<2>;
    +        accessor(pointer_t data, const sycl::range<2> &in_range)
    +            : _data(data), _range(in_range) {}
    +        template 
    +        accessor(typename std::enable_if::type &acc)
    +            : accessor(acc, acc.get_range()) {}
    +        accessor(const accessor_t &acc, const sycl::range<2> &in_range)
    +            : accessor(acc.get_pointer(), in_range) {}
    +
    +        pointer_t operator[](size_t index) const {
    +            return _data + _range.get(1) * index;
    +        }
    +
    +        pointer_t get_ptr() const { return _data; }
    +
    +    private:
    +        pointer_t _data;
    +        sycl::range<2> _range;
    +    };
    +
    +    namespace detail {
    +        /// Device variable with address space of shared, global or constant.
    +        template  class device_memory {
    +        public:
    +            using accessor_t =
    +                typename detail::memory_traits::template accessor_t;
    +            using value_t = typename detail::memory_traits::value_t;
    +            using dpct_accessor_t = dpct::accessor;
    +
    +            device_memory() : device_memory(sycl::range(1)) {}
    +
    +            /// Constructor of 1-D array with initializer list
    +            device_memory(const sycl::range &in_range,
    +                        std::initializer_list &&init_list)
    +                : device_memory(in_range) {
    +                assert(init_list.size() <= in_range.size());
    +                _host_ptr = (value_t *)std::malloc(_size);
    +                std::memset(_host_ptr, 0, _size);
    +                std::memcpy(_host_ptr, init_list.begin(), init_list.size() * sizeof(T));
    +            }
    +
    +            /// Constructor of 2-D array with initializer list
    +            template 
    +            device_memory(
    +                const typename std::enable_if>::type &in_range,
    +                std::initializer_list> &&init_list)
    +                : device_memory(in_range) {
    +                assert(init_list.size() <= in_range[0]);
    +                _host_ptr = (value_t *)std::malloc(_size);
    +                std::memset(_host_ptr, 0, _size);
    +                auto tmp_data = _host_ptr;
    +                for (auto sub_list : init_list) {
    +                    assert(sub_list.size() <= in_range[1]);
    +                    std::memcpy(tmp_data, sub_list.begin(),
    +                                sub_list.size() * sizeof(T));
    +                    tmp_data += in_range[1];
    +                }
    +            }
    +
    +            /// Constructor with range
    +            device_memory(const sycl::range &range_in)
    +                : _size(range_in.size() * sizeof(T)), _range(range_in),
    +                _reference(false), _host_ptr(nullptr), _device_ptr(nullptr) {
    +                static_assert(
    +                    (Memory == global) || (Memory == constant) || (Memory == shared),
    +                    "device memory region should be global, constant or shared");
    +                // Make sure that singleton class mem_mgr and dev_mgr will destruct
    +                // later than this.
    +                detail::mem_mgr::instance();
    +                dev_mgr::instance();
    +            }
    +
    +            /// Constructor with range
    +            template 
    +            device_memory(Args... Arguments)
    +                : device_memory(sycl::range(Arguments...)) {}
    +
    +            ~device_memory() {
    +                if (_device_ptr && !_reference)
    +                    dpct::dpct_free(_device_ptr);
    +                if (_host_ptr)
    +                    std::free(_host_ptr);
    +            }
    +
    +            /// Allocate memory with default queue, and init memory if has initial
    +            /// value.
    +            void init() { init(dpct::get_default_queue()); }
    +            /// Allocate memory with specified queue, and init memory if has initial
    +            /// value.
    +            void init(sycl::queue &q) {
    +                if (_device_ptr)
    +                    return;
    +                if (!_size)
    +                    return;
    +                allocate_device(q);
    +                if (_host_ptr)
    +                    detail::dpct_memcpy(q, _device_ptr, _host_ptr, _size,
    +                                        host_to_device);
    +            }
    +
    +            /// The variable is assigned to a device pointer.
    +            void assign(value_t *src, size_t size) {
    +                this->~device_memory();
    +                new (this) device_memory(src, size);
    +            }
    +
    +            /// Get memory pointer of the memory object, which is virtual pointer when
    +            /// usm is not used, and device pointer when usm is used.
    +            value_t *get_ptr() { return get_ptr(get_default_queue()); }
    +            /// Get memory pointer of the memory object, which is virtual pointer when
    +            /// usm is not used, and device pointer when usm is used.
    +            value_t *get_ptr(sycl::queue &q) {
    +                init(q);
    +                return _device_ptr;
    +            }
    +
    +            /// Get the device memory object size in bytes.
    +            size_t get_size() { return _size; }
    +
    +            template 
    +            typename std::enable_if::type &operator[](size_t index) {
    +                init();
    +                return _device_ptr[index];
    +            }
    +
    +            /// Get dpct::accessor with dimension info for the device memory object
    +            /// when usm is used and dimension is greater than 1.
    +            template 
    +            typename std::enable_if::type
    +            get_access([[maybe_unused]] sycl::handler &cgh) {
    +                return dpct_accessor_t((T *)_device_ptr, _range);
    +            }
    +
    +        private:
    +            device_memory(value_t *memory_ptr, size_t size)
    +                : _size(size), _range(size / sizeof(T)), _reference(true),
    +                _device_ptr(memory_ptr) {}
    +
    +            void allocate_device(sycl::queue &q) {
    +        #ifndef DPCT_USM_LEVEL_NONE
    +                if (Memory == shared) {
    +                    _device_ptr = (value_t *)sycl::malloc_shared(_size, q.get_device(),
    +                                                                q.get_context());
    +                    return;
    +                }
    +        #ifdef SYCL_EXT_ONEAPI_USM_DEVICE_READ_ONLY
    +                if (Memory == constant) {
    +                    _device_ptr = (value_t *)sycl::malloc_device(
    +                        _size, q.get_device(), q.get_context(),
    +                        sycl::ext::oneapi::property::usm::device_read_only());
    +                    return;
    +                }
    +        #endif
    +        #endif
    +                _device_ptr = (value_t *)detail::dpct_malloc(_size, q);
    +            }
    +
    +            size_t _size;
    +            sycl::range _range;
    +            bool _reference;
    +            value_t *_host_ptr;
    +            value_t *_device_ptr;
    +        };
    +        template 
    +        class device_memory : public device_memory {
    +        public:
    +            using base = device_memory;
    +            using value_t = typename base::value_t;
    +            using accessor_t =
    +                typename detail::memory_traits::template accessor_t<0>;
    +
    +            /// Constructor with initial value.
    +            device_memory(const value_t &val) : base(sycl::range<1>(1), {val}) {}
    +
    +            /// Default constructor
    +            device_memory() : base(1) {}
    +        };
    +        } // namespace detail
    +
    +    template 
    +    using global_memory = detail::device_memory;
    +    template 
    +    using constant_memory = detail::device_memory;
    +    template 
    +    using shared_memory = detail::device_memory;
    +
    +
    +    template 
    +    inline T atomic_fetch_add(T *addr, T operand) {
    +    auto atm =
    +        sycl::atomic_ref(addr[0]);
    +    return atm.fetch_add(operand);
    +    }
    +
    +    template 
    +    inline T1 atomic_fetch_add(T1 *addr, T2 operand) {
    +    auto atm =
    +        sycl::atomic_ref(addr[0]);
    +    return atm.fetch_add(operand);
    +    }
    +
    +    template 
    +    inline T atomic_fetch_add(T *addr, T operand,
    +                            sycl::memory_order memoryOrder) {
    +    switch (memoryOrder) {
    +        case sycl::memory_order::relaxed:
    +            return atomic_fetch_add(addr, operand);
    +        case sycl::memory_order::acq_rel:
    +            return atomic_fetch_add(addr, operand);
    +        case sycl::memory_order::seq_cst:
    +            return atomic_fetch_add(addr, operand);
    +        default:
    +            assert(false && "Invalid memory_order for atomics. Valid memory_order for "
    +                            "atomics are: sycl::memory_order::relaxed, "
    +                            "sycl::memory_order::acq_rel, sycl::memory_order::seq_cst!");
    +        }
    +    }
    +
    +    template 
    +    inline T1 atomic_fetch_add(T1 *addr, T2 operand,
    +                            sycl::memory_order memoryOrder) {
    +    atomic_fetch_add(addr, operand, memoryOrder);
    +    }
    +
    +} // COPY from DPCT head files
    +
    +#endif // GGML_SYCL_DPCT_HELPER_HPP
    diff --git a/ggml-sycl/presets.hpp b/ggml-sycl/presets.hpp
    new file mode 100644
    index 000000000..dcf026110
    --- /dev/null
    +++ b/ggml-sycl/presets.hpp
    @@ -0,0 +1,69 @@
    +//
    +// MIT license
    +// Copyright (C) 2024 Intel Corporation
    +// SPDX-License-Identifier: MIT
    +//
    +
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +
    +#ifndef GGML_SYCL_PRESETS_HPP
    +#define GGML_SYCL_PRESETS_HPP
    +
    +#define GGML_SYCL_MAX_STREAMS       8
    +#define GGML_SYCL_MAX_BUFFERS       256
    +#define GGML_SYCL_MAX_DEVICES       48
    +#define GGML_SYCL_NAME "SYCL"
    +
    +// FIXME: 1024 from cuda
    +#define GROUP_SIZE 1024
    +#define WARP_SIZE 32
    +#define MATRIX_ROW_PADDING 512 // last row of quant. matrices is a multiple of this to avoid out-of-bounds memory accesses
    +
    +#define SYCL_GELU_BLOCK_SIZE 256
    +#define SYCL_SILU_BLOCK_SIZE 256
    +#define SYCL_TANH_BLOCK_SIZE 256
    +#define SYCL_RELU_BLOCK_SIZE 256
    +#define SYCL_HARDSIGMOID_BLOCK_SIZE 256
    +#define SYCL_HARDSWISH_BLOCK_SIZE 256
    +#define SYCL_SQR_BLOCK_SIZE 256
    +#define SYCL_CPY_BLOCK_SIZE 32
    +#define SYCL_SCALE_BLOCK_SIZE 256
    +#define SYCL_CLAMP_BLOCK_SIZE 256
    +#define SYCL_ROPE_BLOCK_SIZE 256
    +#define SYCL_ALIBI_BLOCK_SIZE 32
    +#define SYCL_DIAG_MASK_INF_BLOCK_SIZE 32
    +#define SYCL_QUANTIZE_BLOCK_SIZE 256
    +#define SYCL_DEQUANTIZE_BLOCK_SIZE 256
    +#define SYCL_GET_ROWS_BLOCK_SIZE 256
    +#define SYCL_UPSCALE_BLOCK_SIZE 256
    +#define SYCL_CONCAT_BLOCK_SIZE 256
    +#define SYCL_PAD_BLOCK_SIZE 256
    +#define SYCL_ACC_BLOCK_SIZE 256
    +#define SYCL_IM2COL_BLOCK_SIZE 256
    +#define SYCL_POOL2D_BLOCK_SIZE 256
    +
    +// dmmv = dequantize_mul_mat_vec
    +#ifndef GGML_SYCL_DMMV_X
    +#define GGML_SYCL_DMMV_X 32
    +#endif
    +#ifndef GGML_SYCL_MMV_Y
    +#define GGML_SYCL_MMV_Y 1
    +#endif
    +
    +#ifndef K_QUANTS_PER_ITERATION
    +#define K_QUANTS_PER_ITERATION 2
    +#else
    +static_assert(K_QUANTS_PER_ITERATION == 1 || K_QUANTS_PER_ITERATION == 2, "K_QUANTS_PER_ITERATION must be 1 or 2");
    +#endif
    +
    +#ifndef GGML_SYCL_PEER_MAX_BATCH_SIZE
    +#define GGML_SYCL_PEER_MAX_BATCH_SIZE 128
    +#endif // GGML_SYCL_PEER_MAX_BATCH_SIZE
    +
    +#define MUL_MAT_SRC1_COL_STRIDE 128
    +
    +#endif // GGML_SYCL_PRESETS_HPP
    diff --git a/llama.cpp b/llama.cpp
    index 05591aa43..3bf9b6685 100644
    --- a/llama.cpp
    +++ b/llama.cpp
    @@ -6625,16 +6625,6 @@ static int llama_model_load(const std::string & fname, llama_model & model, llam
             }
     #endif
     
    -#ifdef GGML_USE_SYCL
    -        if (params.split_mode == LLAMA_SPLIT_MODE_NONE) {
    -            ggml_backend_sycl_set_single_device_mode(params.main_gpu);
    -            //SYCL use device index (0, 1, 2) directly, uer input device id, then convert to device index.
    -            params.main_gpu = ggml_backend_sycl_get_device_index(params.main_gpu);
    -        } else {
    -            ggml_backend_sycl_set_mul_device_mode();
    -        }
    -#endif
    -
             if (!llm_load_tensors(
                 ml, model, params.n_gpu_layers, params.split_mode,  params.main_gpu, params.tensor_split, params.use_mlock,
                 params.progress_callback, params.progress_callback_user_data
    @@ -16241,8 +16231,7 @@ struct llama_context * llama_new_context_with_model(
             if (model->split_mode == LLAMA_SPLIT_MODE_NONE || model->split_mode == LLAMA_SPLIT_MODE_ROW) {
                 ggml_backend_t backend = ggml_backend_sycl_init(model->main_gpu);
                 if (backend == nullptr) {
    -                int main_gpu_id = ggml_backend_sycl_get_device_id(model->main_gpu);
    -                LLAMA_LOG_ERROR("%s: failed to initialize SYCL%d (index %d) backend\n", __func__, main_gpu_id, model->main_gpu);
    +                LLAMA_LOG_ERROR("%s: failed to initialize SYCL%d backend\n", __func__, model->main_gpu);
                     llama_free(ctx);
                     return nullptr;
                 }
    
    From 0c7b3595b9e5ad2355818e259f06b0dc3f0065b3 Mon Sep 17 00:00:00 2001
    From: Xuan Son Nguyen 
    Date: Sat, 15 Jun 2024 18:53:40 +0200
    Subject: [PATCH 37/37] Add `cvector-generator` example (#7514)
    
    * add control-vector-generator
    
    * calc diff
    
    * add comments
    
    * proof-of-concept stdlib implementation
    
    Implements PCA and file writing using mostly standard libraries. The output is recognized as a functional control vector, but outputs gibberish.
    
    * param parsing, refactor, comments
    
    Added basic command-line parameters for outfile and one each positive/negative prompt.
    
    Refactored some messy code in PCA computation and GGUF exporting.
    
    Left a bunch of comments regarding further work needed.
    
    * example template completions
    
    Implements an example template set built from the positive/negative prompts like the control vector Python implementation.
    
    * add multi prompts, multi-thread for PCA
    
    * fix mem error
    
    * add debugs
    
    * fix matrix transpose multiplication
    
    you have got to be kidding me
    
    * preliminary template/multiprompt support
    
    model is running out of context and that ought to be fixed (segfaulting) but other than that it looks goodish
    
    * fix zero output & param parsing, functional templating
    
    fixed a bug where the output file had no tensor data/was all zero
    
    fixed a bug where single hyphen flags were not being correctly parsed
    
    implements creation of templated prompts from input (still need to adapt based on model)
    
    * fix square_diff matmul index range and CRLF->LF line endings
    
    fixed a logic error where square_diff would not multiply all rows
    
    fixed a formatting error where the provided completions.txt had CRLF line endings
    
    * add command-line args for num threads, num completions file lines, always reload model
    
    refactored a few things and did what the commit message says on the tin
    
    * code aestheticization
    
    * fix compiler warnings
    
    * in-series multithreading for prompt embedding?
    
    added commented-out code to attempt to start implementing mutlithreading for embedding in main
    
    * remove unnecessary multithreading
    
    * interim fix memory leak
    
    * translated everything but PCA (I think)
    
    * tentatively translate the rest
    
    * fix ggml errors and make new ones
    
    at least it compiles and runs
    
    * fix cb_eval
    
    * temporary commit while I move dev environments
    
    it finally outputs a functioning control vector - "functioning" in the sense that it can be loaded and it clearly has the right idea, but makes the model incoherent
    
    * update debug statements
    
    * pre-tokenize so we can allocate correct memory to ctx_diffs_wrapped
    
    * update comments
    
    * (wip) refactor
    
    * clean up PCA ggml implementation
    
    * fix shape of v_diff_original
    
    * add n_batch for pca
    
    * working version
    
    * remember to copy back the last_eigenvector
    
    * fix n_completions
    
    * bring back n_completions
    
    * default n_pca_batch to 20
    
    * fix macos build
    
    * add to makefile all targets
    
    * use ggml_format_name
    
    * add readme
    
    * fix .editorconfig
    
    * use ggml_backend_tensor_copy
    
    * attemp to fix compile problem on mac
    
    * fix compile warn
    
    * reuse allocr
    
    * move param parser to common
    
    * better error handling
    
    * clean up a bit
    
    * add print_usage
    
    * shorten help msg
    
    * beautify help msg
    
    * escape prompt by default
    
    * change compile target to llama-cvector-generator
    
    * typo
    
    * disable GPU for PCA
    
    * code style
    
    ---------
    
    Co-authored-by: Christian Zhou-Zheng 
    ---
     .editorconfig                                 |   3 +
     Makefile                                      |   5 +
     common/common.cpp                             |  60 ++
     common/common.h                               |   9 +
     examples/CMakeLists.txt                       |   1 +
     examples/cvector-generator/CMakeLists.txt     |   5 +
     examples/cvector-generator/README.md          |  34 +
     examples/cvector-generator/completions.txt    | 582 ++++++++++++++++++
     .../cvector-generator/cvector-generator.cpp   | 499 +++++++++++++++
     examples/cvector-generator/negative.txt       |   1 +
     examples/cvector-generator/pca.hpp            | 322 ++++++++++
     examples/cvector-generator/positive.txt       |   1 +
     12 files changed, 1522 insertions(+)
     create mode 100644 examples/cvector-generator/CMakeLists.txt
     create mode 100644 examples/cvector-generator/README.md
     create mode 100644 examples/cvector-generator/completions.txt
     create mode 100644 examples/cvector-generator/cvector-generator.cpp
     create mode 100644 examples/cvector-generator/negative.txt
     create mode 100644 examples/cvector-generator/pca.hpp
     create mode 100644 examples/cvector-generator/positive.txt
    
    diff --git a/.editorconfig b/.editorconfig
    index 16d16b3b5..bd525e13f 100644
    --- a/.editorconfig
    +++ b/.editorconfig
    @@ -26,3 +26,6 @@ indent_size = 2
     
     [examples/llama.swiftui/llama.swiftui.xcodeproj/*]
     indent_style = tab
    +
    +[examples/cvector-generator/*.txt]
    +insert_final_newline = unset
    diff --git a/Makefile b/Makefile
    index 744fe5739..5ab3481fb 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -38,6 +38,7 @@ BUILD_TARGETS = \
     	llama-tokenize \
     	llama-train-text-from-scratch \
     	llama-vdot \
    +	llama-cvector-generator \
     	tests/test-c.o
     
     # Binaries only useful for tests
    @@ -922,6 +923,10 @@ llama-eval-callback: examples/eval-callback/eval-callback.cpp ggml.o llama.o $(C
     	$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
     	$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
     
    +llama-cvector-generator: examples/cvector-generator/cvector-generator.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
    +	$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
    +	$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
    +
     llama-train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp ggml.o llama.o $(COMMON_DEPS) train.o $(OBJS)
     	$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
     	$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
    diff --git a/common/common.cpp b/common/common.cpp
    index 1591790e6..73ff0e85b 100644
    --- a/common/common.cpp
    +++ b/common/common.cpp
    @@ -1576,6 +1576,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
                 return true;
             }
             params.out_file = argv[i];
    +        params.cvector_outfile = argv[i];
             return true;
         }
         if (arg == "-ofreq" || arg == "--output-frequency") {
    @@ -1610,6 +1611,55 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
             params.i_chunk = std::stoi(argv[i]);
             return true;
         }
    +    // cvector params
    +    if (arg == "--completions-file") {
    +        if (++i >= argc) {
    +            invalid_param = true;
    +            return true;
    +        }
    +        params.cvector_completions_file = argv[i];
    +        return true;
    +    }
    +    if (arg == "--positive-file") {
    +        if (++i >= argc) {
    +            invalid_param = true;
    +            return true;
    +        }
    +        params.cvector_positive_file = argv[i];
    +        return true;
    +    }
    +    if (arg == "--negative-file") {
    +        if (++i >= argc) {
    +            invalid_param = true;
    +            return true;
    +        }
    +        params.cvector_negative_file = argv[i];
    +        return true;
    +    }
    +    if (arg == "--completions") {
    +        if (++i >= argc) {
    +            invalid_param = true;
    +            return true;
    +        }
    +        params.n_completions = std::stoi(argv[i]);
    +        return true;
    +    }
    +    if (arg == "--pca-batch") {
    +        if (++i >= argc) {
    +            invalid_param = true;
    +            return true;
    +        }
    +        params.n_pca_batch = std::stoi(argv[i]);
    +        return true;
    +    }
    +    if (arg == "--pca-iter") {
    +        if (++i >= argc) {
    +            invalid_param = true;
    +            return true;
    +        }
    +        params.n_pca_iterations = std::stoi(argv[i]);
    +        return true;
    +    }
     #ifndef LOG_DISABLE_LOGS
         // Parse args for logging parameters
         if (log_param_single_parse(argv[i])) {
    @@ -1931,6 +1981,16 @@ void gpt_params_print_usage(int /*argc*/, char ** argv, const gpt_params & param
         options.push_back({ "logging",     "       --log-append",           "Don't truncate the old log file." });
     #endif // LOG_DISABLE_LOGS
     
    +    options.push_back({ "cvector" });
    +    options.push_back({ "cvector",     "-o,    --output FNAME",         "output file (default: '%s')", params.cvector_outfile.c_str() });
    +    options.push_back({ "cvector",     "       --positive-file FNAME",  "positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str() });
    +    options.push_back({ "cvector",     "       --negative-file FNAME",  "negative prompts file, one prompt per line (default: '%s')", params.cvector_negative_file.c_str() });
    +    options.push_back({ "cvector",     "       --completions-file FNAME",
    +                                                                        "completions file (default: '%s')", params.cvector_completions_file.c_str() });
    +    options.push_back({ "cvector",     "       --completions N",        "number of lines of completions file to use (default: %d)", params.n_completions });
    +    options.push_back({ "cvector",     "       --batch-pca N",          "batch size used for PCA. Larger batch runs faster, but uses more memory (default: %d)", params.n_pca_batch });
    +    options.push_back({ "cvector",     "       --iter-pca N",           "number of iterations used for PCA (default: %d)", params.n_pca_iterations });
    +
         printf("usage: %s [options]\n", argv[0]);
     
         for (const auto & o : options) {
    diff --git a/common/common.h b/common/common.h
    index 2345d855e..58ed72f43 100644
    --- a/common/common.h
    +++ b/common/common.h
    @@ -232,6 +232,15 @@ struct gpt_params {
     
         bool process_output = false; // collect data for the output tensor
         bool compute_ppl    = true;  // whether to compute perplexity
    +
    +    // cvector-generator params
    +    int n_completions = 64;
    +    int n_pca_batch = 20;
    +    int n_pca_iterations = 1000;
    +    std::string cvector_outfile          = "control_vector.gguf";
    +    std::string cvector_completions_file = "examples/cvector-generator/completions.txt";
    +    std::string cvector_positive_file    = "examples/cvector-generator/positive.txt";
    +    std::string cvector_negative_file    = "examples/cvector-generator/negative.txt";
     };
     
     void gpt_params_handle_model_default(gpt_params & params);
    diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
    index d6ce35f4c..0b51c44c0 100644
    --- a/examples/CMakeLists.txt
    +++ b/examples/CMakeLists.txt
    @@ -12,6 +12,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
     
     if (EMSCRIPTEN)
     else()
    +    add_subdirectory(cvector-generator)
         add_subdirectory(baby-llama)
         add_subdirectory(batched-bench)
         add_subdirectory(batched)
    diff --git a/examples/cvector-generator/CMakeLists.txt b/examples/cvector-generator/CMakeLists.txt
    new file mode 100644
    index 000000000..0a559d60c
    --- /dev/null
    +++ b/examples/cvector-generator/CMakeLists.txt
    @@ -0,0 +1,5 @@
    +set(TARGET llama-cvector-generator)
    +add_executable(${TARGET} cvector-generator.cpp pca.hpp)
    +install(TARGETS ${TARGET} RUNTIME)
    +target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
    +target_compile_features(${TARGET} PRIVATE cxx_std_11)
    diff --git a/examples/cvector-generator/README.md b/examples/cvector-generator/README.md
    new file mode 100644
    index 000000000..7b0e79c1f
    --- /dev/null
    +++ b/examples/cvector-generator/README.md
    @@ -0,0 +1,34 @@
    +# cvector-generator
    +
    +This example demonstrates how to generate a control vector using gguf models.
    +
    +Related PRs:
    +- [Add support for control vectors](https://github.com/ggerganov/llama.cpp/pull/5970)
    +- (Issue) [Generate control vector using llama.cpp](https://github.com/ggerganov/llama.cpp/issues/6880)
    +- [Add cvector-generator example](https://github.com/ggerganov/llama.cpp/pull/7514)
    +
    +## Examples
    +
    +```sh
    +# CPU only
    +./cvector-generator -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf
    +
    +# With GPU
    +./cvector-generator -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99
    +
    +# With advanced options
    +./cvector-generator -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99 --completions 128 --pca-iter 2000 --batch-pca 100
    +
    +# To see help message
    +./cvector-generator -h
    +# Then, have a look at "cvector" section
    +```
    +
    +## Tips and tricks
    +
    +If you have multiple lines per prompt, you can escape the newline character (change it to `\n`). For example:
    +
    +```
    +<|im_start|>system\nAct like a person who is extremely happy.<|im_end|>
    +<|im_start|>system\nYou are in a very good mood today<|im_end|>
    +```
    diff --git a/examples/cvector-generator/completions.txt b/examples/cvector-generator/completions.txt
    new file mode 100644
    index 000000000..abc45ffd8
    --- /dev/null
    +++ b/examples/cvector-generator/completions.txt
    @@ -0,0 +1,582 @@
    +
    +That game
    +I can see
    +Hmm, this
    +I can relate to
    +Who is
    +I understand the
    +Ugh,
    +What the hell was
    +Hey, did anyone
    +Although
    +Thank you for choosing
    +What are you
    +Oh w
    +How dare you open
    +It was my pleasure
    +I'm hon
    +I appreciate that you
    +Are you k
    +Whoever left this
    +It's always
    +Ew,
    +Hey, I l
    +Hello? Is someone
    +I understand that
    +That poem
    +Aww, poor
    +Hey, it
    +Alright, who
    +I didn't
    +Well, life
    +The document
    +Oh no, this
    +I'm concerned
    +Hello, this is
    +This art
    +Hmm, this drink
    +Hi there!
    +It seems
    +Is
    +Good
    +I can't
    +Ex
    +Who are
    +I can see that
    +Wow,
    +Today is a
    +Hey friend
    +Sometimes friends
    +Oh, this old
    +The weather outside
    +This place is sur
    +I appreciate your input
    +Thank you for the
    +Look at
    +I'm disappoint
    +To my
    +How dare you
    +That's an
    +This piece of art
    +Eww
    +This park is
    +This is incredible
    +Oh no, someone
    +Exc
    +Well, it'
    +I warned
    +Hey, I understand
    +Hey, I saw
    +How dare you go
    +What the he
    +Hey
    +It's
    +Hello? Hello?
    +It
    +Oh no!
    +This is the perfect
    +Good morning,
    +Oh no, there
    +It's so
    +Yeah
    +Uh,
    +Hello everyone
    +Who turned off
    +The weather
    +Who'
    +Hey, this
    +Wait,
    +Eww, gross
    +Excuse
    +It seems like you
    +Thank you so
    +What happened?
    +Oh my g
    +I am deeply sad
    +I war
    +Okay, let'
    +Hey, that
    +That was a beautiful
    +Oh no! That
    +What happened
    +Hey there
    +The artist'
    +What?!
    +Hey, it'
    +I am disappoint
    +It seems like
    +Oh no! The
    +This park is a
    +If you
    +Yes! I did
    +It sounds
    +What
    +Who is it
    +Hmm, that
    +That's strange
    +Yeah, that was
    +That's interesting
    +This park
    +What the hell
    +Who is that
    +I feel like my
    +Oh well
    +What the hell is
    +Hello? Hello
    +To my dearest
    +Bless you!\"
    +Thank you for
    +Oh, looks like
    +Can you please
    +This place is
    +Eww, what
    +Bless you
    +Is everything
    +Hey, I just
    +Whoever left these
    +Well, that'
    +I feel
    +Hey, do you
    +It's sad
    +Oh no, it
    +Hey, that'
    +Oh my god,
    +Thank you,
    +Hello little one,
    +I apolog
    +Hey team, I
    +How dare you read
    +Who is this and
    +Whoever left
    +Hi there! W
    +A
    +If you have
    +I was
    +U
    +Bless
    +Well, this
    +Oh, I'
    +It's a
    +Eww,
    +Is everything okay?
    +Oh, I
    +Hello, can you
    +Al
    +That was a great
    +What are
    +I understand that not
    +Oh no, not
    +Who is it?\"
    +Hey, can we
    +Whoever is taking
    +I would love to
    +Hey, I noticed
    +Hey, could
    +I understand that there
    +Hello?
    +D
    +Oh man, I
    +Thank you so much
    +Oh no, my
    +Dear [Name
    +Uh
    +I remember
    +Hey, who
    +Well, it
    +Are you
    +I understand that it
    +Hey, is
    +I would
    +Who is this
    +Excuse me
    +Alright
    +I am thrilled
    +Sometimes friends have
    +Who the
    +It's interesting
    +I would love
    +E
    +Hello? Is anyone
    +Well, this is
    +This place
    +Well,
    +I warned you
    +Hey, watch where
    +Oh my
    +That'
    +Sometimes friends have different
    +I understand that everyone
    +What?
    +What do these notes
    +I can relate
    +I'm not
    +I understand
    +To my dear
    +Guys
    +Well
    +Hey, I appreciate
    +Wow, what
    +Dear
    +That melody
    +Who the hell
    +Today is
    +Hello little
    +Wow, look
    +That's great
    +Love is never wrong
    +I'm having
    +Whoa, did
    +Ugh
    +Can you please provide
    +I miss you,
    +I feel uncom
    +I know
    +Ugh, this
    +Hey, watch
    +Oh great, a
    +I didn
    +Okay
    +That game of char
    +Oh
    +I appreciate
    +Who's there
    +I am so
    +Oh great, someone
    +Hey, could you
    +I remember wondering
    +Wait, what?
    +What do
    +Hello? Can
    +Hey there,
    +That game of
    +This is incred
    +Oh my gosh
    +Oh great, f
    +I appreciate your
    +It sounds like
    +What the heck
    +Okay, I understand
    +Ew
    +I understand that this
    +Uh, hi
    +Hi everyone!
    +What the hell?
    +Thank you for your
    +Oh no, the
    +Wow, I
    +Who turned
    +Dear [
    +Whoever
    +This is a
    +Whoa, he
    +What in the world
    +Although the physical
    +Hello, who is
    +That's amaz
    +Hey, I know
    +Okay, that
    +Hi everyone
    +Hey, is everything
    +I understand your fr
    +Oh no, poor
    +Oh, look
    +Good morning
    +Ew, gross
    +Oh no, did
    +Look at the family
    +Hey team
    +Yes!
    +Hey, can I
    +Okay, that'
    +It's great
    +Love is
    +Hey, what
    +Good morning, world
    +Who is it?
    +That poem really reson
    +I
    +That's
    +I understand the task
    +Gu
    +Hello? Who'
    +This postcard is
    +Whoa,
    +Oh, that
    +I understand that I
    +Whoever is
    +Hello? Who is
    +I'm really
    +Wow, this
    +Can
    +This artwork really
    +This is a shame
    +I miss you too
    +Who are you?
    +Today is a difficult
    +Hey, just
    +Are you okay
    +I am
    +Hi,
    +Wow, that
    +Hey there! Can
    +Okay, stay
    +Oh great, just
    +Yeah,
    +Hello? Can you
    +Oh, looks
    +Thank you for sharing
    +I'm glad
    +Hey, is that
    +Hmm
    +It was my
    +It sounds like you
    +Wow, your
    +I was promised certain
    +That was such a
    +Thank
    +Excuse you
    +That was
    +Hey team,
    +I feel un
    +It was
    +What'
    +Hey friend, I
    +How
    +Saying goodbye
    +That
    +It's heart
    +How dare
    +Oh,
    +Hello, may
    +What's this
    +Thank you for recogn
    +Aww, that
    +Oh, I remember
    +Hmm, that'
    +I miss
    +I know this
    +Wait
    +Is everything okay
    +Who is that person
    +Wow, you
    +Oh great
    +I'm sad
    +Wow, the
    +I am very disappoint
    +Who turned off the
    +I understand that things
    +I'm very
    +Hi
    +That's very
    +Okay, I
    +Oh no,
    +Wow, there
    +What's wrong
    +I apologize for
    +Hey, I
    +Can I help you
    +Oh, I didn
    +Alright,
    +Oh wow,
    +Oh my goodness
    +I know this event
    +What in the
    +Saying
    +Yeah, that
    +Guys, I
    +Hey, this v
    +This post
    +Are
    +Hey, can
    +Hello? Is
    +I can only imagine
    +Oh, that sounds
    +Hey, is anyone
    +I am disappointed
    +Hello,
    +Hey everyone, I
    +That was such
    +It's okay
    +The artist
    +Whoa
    +I understand that mistakes
    +Can I help
    +Who
    +Hi everyone! I
    +Hey, can you
    +Wow, how
    +Today
    +Oh no, I
    +Oh well, I
    +Well, that
    +This is the
    +Yes! I finally
    +Hey there little
    +Hello everyone!
    +Love is never
    +Look at the
    +This postcard
    +Oh great,
    +Can I
    +Hmm, this is
    +I understand your
    +Oh, look at
    +B
    +I'm so
    +Whoa, this
    +W
    +Oh, this
    +Sometimes
    +This piece of
    +What the
    +That was a
    +Hey, do
    +Oh no
    +Whoa, what
    +I feel like I
    +The documentary
    +Hello
    +Hello little one
    +I understand that my
    +Eww, that
    +Wow, an
    +Yes! Finally,
    +Although the physical location
    +Whoever is watching
    +That movie
    +I remember wondering about
    +Hey there, little
    +Who's
    +Hello, who
    +Hello everyone! Thank
    +Hello, can
    +That's too
    +Hey, just wanted
    +Hey there, I
    +Saying good
    +Hey there!
    +Who is there?
    +Oh my good
    +I am very
    +Oh no, what
    +Wow, thank
    +I was promised
    +Hi, is
    +Hey, I'
    +Guys, the
    +Oh no, that
    +Who is there
    +Hello, this
    +That movie really touched
    +If you have something
    +The documentary was
    +I'm starting
    +Are you kidd
    +That movie really
    +Hey everyone,
    +Thank you for considering
    +I didn'
    +Yes! I
    +Can you
    +Oh my god
    +Hey, whoever
    +That melody really
    +Thank you, little
    +Hello, may I
    +Look
    +Wow, we
    +It looks
    +What do these
    +Oh wow
    +I apologize
    +What are you all
    +It's such
    +It's clear
    +Hey, I was
    +Hey friend,
    +I can only
    +The weather outside is
    +Eww, this
    +I miss you
    +Wow
    +Aww,
    +Hi, is there
    +This artwork
    +Okay,
    +Oh well,
    +This
    +I'
    +Say
    +Hey there little gu
    +Hmm,
    +Whoa, who
    +I am thr
    +Oh man
    +Okay, stay calm
    +I'm happy
    +Oh, this cur
    +Oh man,
    +I'm sorry
    +Hello? Who
    +What?! That
    +This piece
    +Hey everyone
    +That's so
    +Are you okay?
    +What happened? Where
    +Hi there
    +The
    +Who the hell entered
    +I can
    +Guys,
    +What's
    +What in
    +It's important
    +I'm
    +I'm coming
    +It'
    +Yes! Finally
    +Wait, what
    +Wow, reading
    +I'm surprised
    +Hey, did
    +Hey,
    +Okay, let
    +I understand that you
    +Who the hell threw
    +Eww, who
    +Thank you for thinking
    +Who is this?\"
    +I am deeply
    +Thank you for including
    +Oh no, an
    +It looks like you
    +Aww
    +I'm confused
    +Wow, it
    +That poem really
    +Yes
    +Hey there, is
    +Hey, what'
    +Thank you for remember
    +To
    +This is
    +Thank you for making
    +I can'
    +That mel
    +Wow, they
    +I feel like
    +Although the
    +Who are you
    +Love
    +If
    +What the hell are
    +I am so sad
    +Oh, I found
    +Thank you
    +It looks like
    +Well, life is
    +I appreciate that
    +The artist's
    +Whoa, that
    +It's never
    \ No newline at end of file
    diff --git a/examples/cvector-generator/cvector-generator.cpp b/examples/cvector-generator/cvector-generator.cpp
    new file mode 100644
    index 000000000..9941683db
    --- /dev/null
    +++ b/examples/cvector-generator/cvector-generator.cpp
    @@ -0,0 +1,499 @@
    +#include "common.h"
    +#include "llama.h"
    +#include "ggml.h"
    +#include "pca.hpp"
    +
    +#ifdef GGML_USE_CUDA
    +#include "ggml-cuda.h"
    +#endif
    +
    +#ifdef GGML_USE_METAL
    +#include "ggml-metal.h"
    +#endif
    +
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +
    +
    +//////////////////////////////////////////////////
    +// utils
    +
    +template 
    +static std::string tokens_to_str(llama_context * ctx, Iter begin, Iter end) {
    +    std::string ret;
    +    for (; begin != end; ++begin) {
    +        ret += llama_token_to_piece(ctx, *begin);
    +    }
    +
    +    return ret;
    +}
    +
    +static void print_usage(int argc, char ** argv, const gpt_params & params) {
    +    gpt_params_print_usage(argc, argv, params);
    +
    +    printf("\nexample usage:\n");
    +    printf("\n    CPU only:   %s -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf\n", argv[0]);
    +    printf("\n    with GPU:   %s -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99\n", argv[0]);
    +    printf("\n    advanced:   %s -m ./dolphin-2.0-mistral-7b.Q4_K_M.gguf -ngl 99 --completions 128 --pca-iter 2000 --batch-pca 100\n", argv[0]);
    +    printf("\n");
    +}
    +
    +//////////////////////////////////////////////////
    +
    +
    +// cb_eval is reused for each pair of positive - negative prompt
    +struct callback_data {
    +    ggml_context * ctx_ggml = nullptr;   // holds v_pos, v_neg, v_diff_filtered
    +
    +    int n_layers = 0;
    +    int n_tokens = 0;
    +    bool is_eval_pos = true;
    +
    +    // each element of the vector correspond to one layer
    +    std::vector v_pos; // vector of matrices of size [n_embd, n_tokens]
    +    std::vector v_neg; // vector of matrices of size [n_embd, n_tokens]
    +    std::vector v_diff_filtered;   // vector of matrices of size [n_embd, n_nonzero_rows]. NOTE: n_nonzero_rows maybe different for each layer
    +
    +    // save a tensor into either v_pos or v_neg (decided by is_eval_pos)
    +    void save_tensor_for_layer(struct ggml_tensor * t) {
    +        GGML_ASSERT(t->type == GGML_TYPE_F32);
    +
    +        if (ctx_ggml == nullptr) {
    +            // alloc a new ctx_ggml if needed
    +            struct ggml_init_params params_ggml = {
    +                /*.mem_size   =*/ ggml_tensor_overhead() * n_layers * 3u,
    +                /*.mem_buffer =*/ NULL,
    +                /*.no_alloc   =*/ true,
    +            };
    +            ctx_ggml = ggml_init(params_ggml);
    +        }
    +
    +        // copy tensor data
    +        auto n_bytes = ggml_nbytes(t);
    +        struct ggml_tensor * t_layer = ggml_new_tensor_2d(ctx_ggml, t->type, t->ne[0], t->ne[1]);
    +        t_layer->data = malloc(n_bytes); // TODO @ngxson : get rid of this malloc somehow
    +        ggml_backend_tensor_get(t, t_layer->data, 0, n_bytes);
    +        ggml_set_name(t_layer, ggml_get_name(t));
    +        //print_debug_tensor(t_layer);
    +
    +        if (is_eval_pos) {
    +            v_pos.push_back(t_layer);
    +        } else {
    +            v_neg.push_back(t_layer);
    +        }
    +    }
    +
    +    // calculate diff (v_pos - v_neg) and place the result back to v_pos
    +    // all zero rows in the diff tensor will also be removed
    +    // NOTE: final layer is ignored. we only have (n_layers - 1) to process
    +    std::vector calc_diff() {
    +        for (float il = 0; il < v_pos.size(); il++) {
    +            float * a = (float *) v_pos[il]->data;
    +            float * b = (float *) v_neg[il]->data;
    +            size_t n_elem = ggml_nelements(v_pos[il]);
    +            for (size_t j = 0; j < n_elem; j++) {
    +                a[j] -= b[j];
    +            }
    +            //print_debug_tensor(v_pos[i]);
    +            auto diff_filtered = filter_nonzero_rows(v_pos[il]);
    +            v_diff_filtered.push_back(diff_filtered);
    +        }
    +        return v_diff_filtered; // for convinient, we return the result std::vector
    +    }
    +
    +    // delete zero rows from a given 2D tensor
    +    struct ggml_tensor * filter_nonzero_rows(struct ggml_tensor * a) {
    +        //printf("filter_nonzero_rows\n");
    +        auto is_row_all_zeros = [](struct ggml_tensor * t, int row, float eps) -> bool {
    +            // check if given row containing all zero elements
    +            int n_cols = t->ne[0]; // hint: should be equal to n_embd
    +            for (int col = 0; col < n_cols; ++col) {
    +                if (ggml_get_f32_nd(t, col, row, 0, 0) > eps) {
    +                    return false;
    +                }
    +            }
    +            return true;
    +        };
    +        std::vector rows_to_copy; // the idx of non-zero cols (to be copied to row of diff_filtered)
    +        for (int i_row = 0; i_row < a->ne[1]; i_row++) {
    +            if (!is_row_all_zeros(a, i_row, 1e-6)) {
    +                rows_to_copy.push_back(i_row);
    +            }
    +        }
    +
    +        // get "n_nonzero_rows" for the output "diff_filtered"
    +        int n_nonzero_rows = rows_to_copy.size();
    +        //printf("n_nonzero_rows: %d\n", n_nonzero_rows);
    +        int n_embd = a->ne[0];
    +        GGML_ASSERT(n_nonzero_rows > 0);
    +
    +        // diff_filtered: [n_embd, n_nonzero_rows]
    +        struct ggml_tensor * diff_filtered = ggml_new_tensor_2d(
    +            ctx_ggml, GGML_TYPE_F32, n_embd, n_nonzero_rows);
    +        ggml_format_name(diff_filtered, "diff_filtered_%s", a->name);
    +        diff_filtered->data = malloc(ggml_nbytes(diff_filtered));
    +
    +        // copy non-zero rows
    +        for (int dest_row = 0; dest_row < n_nonzero_rows; dest_row++) {
    +            int src_row = rows_to_copy[dest_row];
    +            for (int i = 0; i < n_embd; i++) {
    +                float src_elem = ggml_get_f32_nd(a, i, src_row, 0, 0);
    +                ggml_set_f32_nd(diff_filtered, i, dest_row, 0, 0, src_elem);
    +            }
    +        }
    +
    +        //print_debug_tensor(diff_filtered);
    +
    +        return diff_filtered;
    +    }
    +
    +    // we don't implement destructor, because we want to reuse callback_data. we just want to free the tensors
    +    void reset() {
    +        for (auto ptr : v_pos) free(ptr->data);
    +        for (auto ptr : v_neg) free(ptr->data);
    +        for (auto ptr : v_diff_filtered) free(ptr->data);
    +        v_pos.clear();
    +        v_neg.clear();
    +        v_diff_filtered.clear();
    +        if (ctx_ggml) {
    +            ggml_free(ctx_ggml);
    +        }
    +        ctx_ggml = nullptr;
    +    }
    +};
    +
    +/**
    + * process_ctx is used to store the ggml context for pre-post processing the diff vectors
    + * in short, input => v_diff and output => v_final
    + */
    +struct train_context {
    +    ggml_context * ctx_ggml;
    +    int n_embd;
    +    int n_layers;
    +
    +    /* pair of prompts to be used for generating final vector */
    +    std::vector positive_entries;
    +    std::vector negative_entries;
    +
    +    // each element of the vector correspond to one layer
    +    // NOTE: the last layer is discard. therefore, we will have (n_layers - 1) elements here
    +    // NOTE (2): v_diff is transposed from v_diff_tmp
    +    std::vector v_diff;  // vector of matrices of size [m, n_embd] where m ~ n_tokens * n_completions (v_diff contains no zero-rows)
    +    std::vector v_final; // vector of vectors of size [n_embd] to be written to file
    +
    +    // to easily re-alloc when concat v_diff, we temporary store v_diff in a vector instead of a tensor
    +    // v_diff_tmp will get converted unto v_diff later on
    +    std::vector> v_diff_tmp;
    +
    +    train_context(int n_embd_, int n_layers_) {
    +        n_embd = n_embd_;
    +        n_layers = n_layers_;
    +        struct ggml_init_params params_ggml = {
    +            /*.mem_size   =*/ ggml_tensor_overhead() * (n_layers - 1) * 2u,
    +            /*.mem_buffer =*/ NULL,
    +            /*.no_alloc   =*/ true,
    +        };
    +        ctx_ggml = ggml_init(params_ggml);
    +        for (int il = 0; il < n_layers - 1; il++) {
    +            std::vector empty;
    +            v_diff_tmp.push_back(empty);
    +            auto t = ggml_new_tensor_1d(ctx_ggml, GGML_TYPE_F32, n_embd);
    +            t->data = malloc(ggml_nbytes(t)); // TODO: get rid of malloc if possible
    +            v_final.push_back(t);
    +        }
    +    }
    +
    +    // add new rows into existing tensor in v_diff_tmp
    +    void concat_diff_tmp(const std::vector & diff_filtered) {
    +        GGML_ASSERT((int) diff_filtered.size() == n_layers - 1);
    +        for (int il = 0; il < n_layers - 1; il++) {
    +            auto t = diff_filtered[il];
    +            auto & diff_tmp = v_diff_tmp[il];
    +            size_t curr_size = diff_tmp.size();
    +            diff_tmp.resize(curr_size + ggml_nbytes(t));
    +            memcpy(diff_tmp.data() + curr_size, t->data, ggml_nbytes(t));
    +        }
    +    }
    +
    +    // build the v_diff tensors from v_diff_tmp (v_diff need to be transposed)
    +    // TODO @ngxson : maybe add option NOT to transpose v_diff; will be useful for "mean" method
    +    void build_v_diff() {
    +        printf("build_v_diff\n");
    +        for (int il = 0; il < n_layers - 1; il++) {
    +            auto & diff_tmp = v_diff_tmp[il];
    +            int n_elem = diff_tmp.size() / sizeof(float);
    +            GGML_ASSERT(n_elem % n_embd == 0);
    +            int n_rows = n_elem / n_embd;
    +            struct ggml_tensor * diff = ggml_new_tensor_2d(ctx_ggml, GGML_TYPE_F32, n_rows, n_embd);
    +            ggml_set_name(diff, (std::string("diff_") + std::to_string(il)).c_str());
    +            // copy data & transpose
    +            diff->data = malloc(ggml_nbytes(diff)); // TODO: get rid of this malloc if possible
    +            float * arr = (float *) diff_tmp.data();
    +            for (int ir = 0; ir < n_rows; ++ir) {
    +                for (int ic = 0; ic < n_embd; ++ic) {
    +                    float f = arr[ir*n_embd + ic];
    +                    ggml_set_f32_nd(diff, ir, ic, 0, 0, f);
    +                }
    +            }
    +            v_diff.push_back(diff);
    +            print_debug_tensor(diff);
    +            // free memory of diff_tmp
    +            diff_tmp.resize(0);
    +        }
    +    }
    +
    +    ~train_context() {
    +        for (auto ptr : v_final) free(ptr->data);
    +        for (auto ptr : v_diff) free(ptr->data);
    +        // no need to free v_diff_tmp, since we didn't use malloc
    +        ggml_free(ctx_ggml);
    +    }
    +};
    +
    +struct tokenized_prompt {
    +    std::vector tokens_pos;
    +    std::vector tokens_neg;
    +    size_t max_seq_len;
    +
    +    tokenized_prompt(llama_context * ctx, std::string pos, std::string neg) {
    +        const bool add_bos = llama_should_add_bos_token(llama_get_model(ctx));
    +        tokens_pos = ::llama_tokenize(ctx, pos, add_bos);
    +        tokens_neg = ::llama_tokenize(ctx, neg, add_bos);
    +        max_seq_len = std::max(tokens_pos.size(), tokens_neg.size());
    +        padding_seq(ctx, tokens_pos, max_seq_len);
    +        padding_seq(ctx, tokens_neg, max_seq_len);
    +    }
    +
    +    void padding_seq(llama_context * ctx, std::vector & tokens, size_t len) {
    +        // TODO: customize padding token
    +        std::vector pad_tokens = ::llama_tokenize(ctx, " ", false);
    +        llama_token pad_tok = pad_tokens.back();
    +        while (tokens.size() < len) {
    +            tokens.push_back(pad_tok);
    +        }
    +    }
    +};
    +
    +//////////////////////////////////////////////////
    +
    +template 
    +static std::string to_string(const T & val) {
    +    std::stringstream ss;
    +    ss << val;
    +    return ss.str();
    +}
    +
    +static std::vector ctrlvec_load_prompt_file(std::string path, bool skip_empty_lines) {
    +    std::vector output;
    +    std::ifstream file(path);
    +    if (!file.is_open()) {
    +        fprintf(stderr, "error: unable to open file: %s\n", path.c_str());
    +        exit(1);
    +    }
    +    std::string line;
    +    while (std::getline(file, line)) {
    +        bool is_skip = skip_empty_lines && line.empty();
    +        if (!is_skip) {
    +            string_process_escapes(line);
    +            output.push_back(line);
    +        }
    +    }
    +    file.close();
    +    return output;
    +}
    +
    +//////////////////////////////////////////////////
    +
    +static bool cb_eval(struct ggml_tensor * t, bool ask, void * user_data) {
    +    auto * cb_data = (callback_data *) user_data;
    +    static const char * l_out_name = "l_out";
    +    const bool is_l_out = strncmp(t->name, l_out_name, strlen(l_out_name)) == 0;
    +
    +    if (ask) {
    +        return is_l_out;
    +    }
    +
    +    if (!is_l_out || t->ne[1] != cb_data->n_tokens) {
    +        return true;
    +    }
    +
    +    // save the tensor to current context
    +    cb_data->save_tensor_for_layer(t);
    +    return true;
    +}
    +
    +static bool get_hidden_layers(llama_context * ctx, std::vector & tokens) {
    +    llama_kv_cache_clear(ctx);
    +    if (llama_decode(ctx, llama_batch_get_one(tokens.data(), tokens.size(), 0, 0))) {
    +        fprintf(stderr, "%s : failed to eval\n", __func__);
    +        return false;
    +    }
    +    return true;
    +}
    +
    +static void export_gguf(const std::vector & v_ctrl, const std::string fname, const std::string model_hint) {
    +    struct gguf_context * ctx = gguf_init_empty();
    +
    +    const std::string arch = "controlvector";
    +    gguf_set_val_str(ctx, "general.architecture", arch.c_str());
    +    gguf_set_val_str(ctx, (arch + ".model_hint").c_str(), model_hint.c_str());
    +    gguf_set_val_i32(ctx, (arch + ".layer_count").c_str(), v_ctrl.size());
    +
    +    for (size_t i = 0; i < v_ctrl.size(); ++i) {
    +        gguf_add_tensor(ctx, v_ctrl[i]);
    +        print_debug_tensor(v_ctrl[i]);
    +        printf("Added tensor: %s\n", v_ctrl[i]->name);
    +    }
    +
    +    printf("%s: writing file...\n", __func__);
    +    gguf_write_to_file(ctx, fname.c_str(), false);
    +    printf("%s: wrote file '%s'\n", __func__, fname.c_str());
    +    gguf_free(ctx);
    +}
    +
    +/**
    + * Load prompt files and completion file.
    + * Then format each pair of prompt + completion to make an entry.
    + */
    +static int prepare_entries(gpt_params & params, train_context & ctx_train) {
    +    // load prompts
    +    std::vector positive_prompts = ctrlvec_load_prompt_file(params.cvector_positive_file, true);
    +    std::vector negative_prompts = ctrlvec_load_prompt_file(params.cvector_negative_file, true);
    +    if (positive_prompts.size() != negative_prompts.size()) {
    +        fprintf(stderr, "number of positive and negative prompts must be equal\n");
    +        return 1;
    +    }
    +    if (positive_prompts.empty()) {
    +        fprintf(stderr, "must provide at least one prompt pair\n");
    +        return 1;
    +    }
    +
    +    // create templated prompts
    +    std::vector completions = ctrlvec_load_prompt_file(params.cvector_completions_file, false);
    +    auto format_template = [](std::string persona, std::string suffix) {
    +        // entry in positive/negative.txt must already be formatted i.e. "[INST] Act as if you're extremely happy. [/INST]"
    +        return persona + " " + suffix;
    +    };
    +    for (size_t i = 0; i < positive_prompts.size(); ++i) {
    +        for (int j = 0; j < std::min((int) completions.size(), params.n_completions); ++j) {
    +            // TODO replicate the truncations done by the python implementation
    +            ctx_train.positive_entries.push_back(format_template(positive_prompts[i], completions[j]));
    +            ctx_train.negative_entries.push_back(format_template(negative_prompts[i], completions[j]));
    +        }
    +    }
    +    return 0;
    +}
    +
    +int main(int argc, char ** argv) {
    +    gpt_params params;
    +
    +    if (!gpt_params_parse(argc, argv, params)) {
    +        print_usage(argc, argv, params);
    +        return 1;
    +    }
    +
    +    if (params.n_pca_iterations % params.n_pca_batch != 0) {
    +        fprintf(stderr, "PCA iterations must by multiply of PCA batch size\n");
    +        return 1;
    +    }
    +
    +
    +    callback_data cb_data;
    +
    +    // pass the callback to the backend scheduler
    +    // it will be executed for each node during the graph computation
    +    params.cb_eval = cb_eval;
    +    params.cb_eval_user_data = &cb_data;
    +    params.warmup = false;
    +
    +    print_build_info();
    +    llama_backend_init();
    +    llama_numa_init(params.numa);
    +
    +    // load the model to get hparams
    +    llama_model * model;
    +    llama_context * ctx;
    +    std::tie(model, ctx) = llama_init_from_gpt_params(params);
    +
    +    // int n_ctx = llama_n_ctx(ctx);
    +    int n_layers = llama_n_layer(model);
    +    int n_embd = llama_n_embd(model);
    +    // get model hint param (a.k.a model arch name)
    +    char model_hint[128];
    +    llama_model_meta_val_str(model, "general.architecture", model_hint, 128);
    +
    +    // init train_context
    +    train_context ctx_train(n_embd, n_layers);
    +
    +    // load and prepare entries for training
    +    prepare_entries(params, ctx_train);
    +
    +    // we have to pretokenize everything because otherwise we don't know how much overhead to allocate ctx_diffs_wrapped
    +    std::vector tokenized_prompts;
    +    size_t n_total_tokens = 0;
    +    for (size_t i = 0; i < ctx_train.positive_entries.size(); ++i) {
    +        tokenized_prompt t(ctx, ctx_train.positive_entries[i], ctx_train.negative_entries[i]);
    +        n_total_tokens += 2 * t.max_seq_len;
    +        tokenized_prompts.push_back(std::move(t));
    +    }
    +
    +    std::cout << "n_total_tokens: " << n_total_tokens << std::endl;
    +
    +    for(size_t i = 0; i < ctx_train.positive_entries.size(); ++i) {
    +        bool success = false;
    +        tokenized_prompt t = tokenized_prompts[i];
    +        cb_data.n_layers = n_layers;
    +        cb_data.n_tokens = t.max_seq_len;
    +
    +        printf("Evaluating prompt[%d/%d]: \"%s\" - \"%s\" (%d tokens)\n",
    +            (int) i+1, (int) ctx_train.positive_entries.size(),
    +            tokens_to_str(ctx, t.tokens_pos.cbegin(), t.tokens_pos.cend()).c_str(),
    +            tokens_to_str(ctx, t.tokens_neg.cbegin(), t.tokens_neg.cend()).c_str(),
    +            (int) t.max_seq_len);
    +
    +        cb_data.is_eval_pos = true;
    +        success = get_hidden_layers(ctx, t.tokens_pos);
    +        if (!success) break;
    +
    +        cb_data.is_eval_pos = false;
    +        success = get_hidden_layers(ctx, t.tokens_neg);
    +        if (!success) break;
    +
    +        // calculate diff and remove all zero rows
    +        auto v_diff_filtered = cb_data.calc_diff();
    +
    +        // save & concat the filtered v_diff to ctx_train
    +        ctx_train.concat_diff_tmp(v_diff_filtered);
    +
    +        // reset for next iteration
    +        cb_data.reset();
    +    }
    +
    +    // done with the model, we can now free it to make gain some memory
    +    printf("Done evaluate prompts, unload model...\n");
    +    llama_free(ctx);
    +    llama_free_model(model);
    +
    +    // prepare ctx_train for PCA
    +    ctx_train.build_v_diff();
    +
    +    // run PCA
    +    PCA::pca_params pca_params;
    +    pca_params.n_threads = params.n_threads;
    +    pca_params.n_batch = params.n_pca_batch;
    +    pca_params.n_iterations = params.n_pca_iterations;
    +    PCA::run_pca(pca_params, ctx_train.v_diff, ctx_train.v_final);
    +
    +    // write output vectors to gguf
    +    export_gguf(ctx_train.v_final, params.cvector_outfile, model_hint);
    +
    +    llama_backend_free();
    +
    +    return 0;
    +}
    diff --git a/examples/cvector-generator/negative.txt b/examples/cvector-generator/negative.txt
    new file mode 100644
    index 000000000..2ac3387f1
    --- /dev/null
    +++ b/examples/cvector-generator/negative.txt
    @@ -0,0 +1 @@
    +[INST] Act like a person who is extremely sad. [/INST]
    \ No newline at end of file
    diff --git a/examples/cvector-generator/pca.hpp b/examples/cvector-generator/pca.hpp
    new file mode 100644
    index 000000000..8b95cec37
    --- /dev/null
    +++ b/examples/cvector-generator/pca.hpp
    @@ -0,0 +1,322 @@
    +#include "common.h"
    +#include "llama.h"
    +#include "ggml.h"
    +
    +#ifdef GGML_USE_CUDA
    +#include "ggml-cuda.h"
    +#endif
    +
    +#ifdef GGML_USE_METAL
    +#include "ggml-metal.h"
    +#endif
    +
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +#include 
    +
    +#define DEBUG_POS 5
    +
    +static void print_debug_tensor(struct ggml_tensor * t, bool with_data = true) {
    +    printf("%s: %s (%s): [%d, %d]\n", __func__, t->name, ggml_type_name(t->type), (int) t->ne[0], (int) t->ne[1]);
    +    if (!with_data) return;
    +    printf("%s: %s[0] = [", __func__, t->name);
    +    for (size_t i = 0; i <= DEBUG_POS; i++) {
    +        printf(" %f,", ggml_get_f32_nd(t, i, 0, 0, 0));
    +    }
    +    printf(" ... ]\n");
    +}
    +
    +namespace PCA {
    +
    +// input params for PCA computations
    +struct pca_params {
    +    int n_threads = 1;
    +    int n_batch = 20; // number of iterations do to in one batch. larger the batch, more memory is used
    +    int n_iterations = 1000;
    +    float tolerance = 1e-7;
    +
    +    // for debugging
    +    int i_layer = 0;
    +    int n_layers = 0;
    +};
    +
    +// result from each iteration
    +struct pca_result {
    +    struct ggml_tensor * calculated_square = NULL;
    +    std::vector eigenvectors;
    +    std::vector distances;
    +};
    +
    +struct pca_model {
    +    ggml_backend_t backend = NULL;
    +    ggml_backend_buffer_t buffer;
    +    struct ggml_context * ctx;      // context to compute graph on target device
    +    struct ggml_context * ctx_host; // host context to store results
    +
    +    // tensors on target device
    +    struct ggml_tensor * dev_input;
    +    struct ggml_tensor * dev_square;
    +    struct ggml_tensor * dev_eigenvector;
    +
    +    pca_model(struct ggml_tensor * t_input) {
    +// TODO: enable GPU support when support for GGML_OP_SQRT is added
    +// #ifdef GGML_USE_CUDA
    +//         fprintf(stderr, "%s: using CUDA backend\n", __func__);
    +//         backend = ggml_backend_cuda_init(0); // init device 0
    +//         if (!backend) {
    +//             fprintf(stderr, "%s: ggml_backend_cuda_init() failed\n", __func__);
    +//         }
    +// #endif
    +
    +// #ifdef GGML_USE_METAL
    +//         fprintf(stderr, "%s: using Metal backend\n", __func__);
    +//         backend = ggml_backend_metal_init();
    +//         if (!backend) {
    +//             fprintf(stderr, "%s: ggml_backend_metal_init() failed\n", __func__);
    +//         }
    +// #endif
    +
    +        // if there aren't GPU Backends fallback to CPU backend
    +        if (!backend) {
    +            backend = ggml_backend_cpu_init();
    +        }
    +
    +        const int num_tensors = 4;
    +        struct ggml_init_params params {
    +            /*.mem_size   =*/ ggml_tensor_overhead() * num_tensors,
    +            /*.mem_buffer =*/ NULL,
    +            /*.no_alloc   =*/ true,
    +        };
    +        ctx = ggml_init(params);
    +
    +        auto n_samples = t_input->ne[0];
    +        auto n_embd    = t_input->ne[1];
    +
    +        dev_input       = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n_samples, n_embd);
    +        dev_square      = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n_embd,    n_embd);
    +        dev_eigenvector = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, n_embd);
    +
    +        ggml_set_name(dev_input,       "dev_input");
    +        ggml_set_name(dev_square,      "dev_square");
    +        ggml_set_name(dev_eigenvector, "dev_eigenvector");
    +        buffer = ggml_backend_alloc_ctx_tensors(ctx, backend);
    +        ggml_backend_tensor_set(dev_input, t_input->data, 0, ggml_nbytes(t_input));
    +
    +        // initialize eigenvector to random normalized vector
    +        {
    +            std::vector random_vec(ggml_nelements(dev_eigenvector), 0.0);
    +            std::default_random_engine generator(static_cast(std::time(0)));
    +            std::uniform_real_distribution distribution(0.0, 1.0);
    +            float sum_sqr = 0.0; // for normalizing random_vec
    +            for (size_t i = 0; i < random_vec.size(); ++i) {
    +                float f = distribution(generator);
    +                sum_sqr += f * f;
    +                random_vec[i] = f;
    +            }
    +            // normalize it
    +            float random_vec_norm = std::sqrt(sum_sqr);
    +            for (size_t i = 0; i < random_vec.size(); ++i) {
    +                random_vec[i] /= random_vec_norm;
    +            }
    +            ggml_backend_tensor_set(dev_eigenvector, random_vec.data(), 0, ggml_nbytes(dev_eigenvector));
    +        }
    +    }
    +
    +    ~pca_model() {
    +        ggml_free(ctx);
    +        ggml_backend_buffer_free(buffer);
    +        ggml_backend_free(backend);
    +    }
    +};
    +
    +static struct ggml_cgraph * build_graph_piter(
    +        const struct pca_params & params,
    +        const pca_model & model,
    +        bool calc_square = false) {
    +    GGML_ASSERT(params.n_batch > 0);
    +    // TODO: buf_size must be able to scale with params.n_batch
    +    static size_t buf_size = ggml_tensor_overhead()*GGML_DEFAULT_GRAPH_SIZE + ggml_graph_overhead();
    +    static std::vector buf(buf_size);
    +
    +    struct ggml_init_params params0 = {
    +        /*.mem_size   =*/ buf_size,
    +        /*.mem_buffer =*/ buf.data(),
    +        /*.no_alloc   =*/ true, // the tensors will be allocated later by ggml_allocr_alloc_graph()
    +    };
    +    // create a temporally context to build the graph
    +    struct ggml_context * ctx0 = ggml_init(params0);
    +    struct ggml_cgraph * gf = ggml_new_graph(ctx0);
    +
    +    // turn v_diff_original into square matrix if needed
    +    struct ggml_tensor * tmp_square;
    +    if (calc_square) {
    +        tmp_square = ggml_mul_mat(ctx0, model.dev_input, model.dev_input);
    +        ggml_set_name(tmp_square, "tmp_square");
    +    }
    +
    +    struct ggml_tensor * b_tensor;
    +    struct ggml_tensor * distance;
    +    struct ggml_tensor * old_eigen    = model.dev_eigenvector;
    +    struct ggml_tensor * input_square = calc_square ? tmp_square : model.dev_square;
    +
    +    for (int i = 0; i < params.n_batch; ++i) {
    +        // b_tensor = square * eigenvector^T
    +        b_tensor = ggml_mul_mat(ctx0, input_square, old_eigen);
    +        ggml_set_name(b_tensor, "b_tensor");
    +
    +        // normalize
    +        b_tensor = ggml_div_inplace(ctx0,
    +            b_tensor,
    +            ggml_sqrt_inplace(ctx0, ggml_sum_rows(ctx0, ggml_sqr(ctx0, b_tensor)))
    +        );
    +        ggml_format_name(b_tensor, "b_tensor_norm_%d", i);
    +
    +        // calculate distance(new eigenvector - old eigenvector)
    +        // we don't use ggml_sub because it may not be implemented on GPU backend
    +        struct ggml_tensor * new_sub_old = ggml_add(ctx0, old_eigen, ggml_scale(ctx0, b_tensor, -1));
    +        distance = ggml_sqrt_inplace(ctx0,
    +            ggml_sum_rows(ctx0, ggml_sqr_inplace(ctx0, new_sub_old)));
    +        ggml_format_name(distance, "distance_%d", i);
    +
    +        old_eigen = b_tensor;
    +
    +        // build operations nodes
    +        ggml_build_forward_expand(gf, distance);
    +    }
    +
    +    // delete the temporally context used to build the graph
    +    ggml_free(ctx0);
    +    return gf;
    +}
    +
    +static ggml_status compute_piter(
    +        const struct pca_params & params,
    +        const pca_model & model,
    +        struct ggml_cgraph * gf,
    +        ggml_gallocr_t allocr,
    +        struct pca_result & result) {
    +    // allocate tensors
    +    ggml_gallocr_alloc_graph(allocr, gf);
    +
    +    if (ggml_backend_is_cpu(model.backend)) {
    +        ggml_backend_cpu_set_n_threads(model.backend, params.n_threads);
    +    }
    +
    +// TODO: enable GPU support when support for GGML_OP_SQRT is added
    +//#ifdef GGML_USE_METAL
    +//    if (ggml_backend_is_metal(model.backend)) {
    +//        ggml_backend_metal_set_n_cb(model.backend, params.n_threads);
    +//    }
    +//#endif
    +
    +    ggml_status res = ggml_backend_graph_compute(model.backend, gf);
    +    if (res == GGML_STATUS_SUCCESS) {
    +        auto extract_i = [](std::string prefix, std::string str) -> int {
    +            int i = -1;
    +            if (str.rfind(prefix, 0) == 0) {
    +                sscanf(str.c_str(), (prefix + "%d").c_str(), &i);
    +            }
    +            return i;
    +        };
    +        result.calculated_square = NULL;
    +        result.eigenvectors.clear();
    +        result.distances.clear();
    +        result.eigenvectors.resize(params.n_batch);
    +        result.distances.resize(params.n_batch);
    +        // get output nodes
    +        for (int i = 0; i < gf->n_nodes; ++i) {
    +            auto node = gf->nodes[i];
    +            int iter = -1;
    +            // find b_tensor (without copying data from device)
    +            if ((iter = extract_i("b_tensor_norm_", node->name)) > -1) {
    +                result.eigenvectors[iter] = node;
    +            }
    +            // find distances, then copy data from device
    +            if ((iter = extract_i("distance_", node->name)) > -1) {
    +                float d;
    +                ggml_backend_tensor_get(node, &d, 0, sizeof(float));
    +                result.distances[iter] = d;
    +                // std::cout << node->name << " = " << d << "\n";
    +            }
    +            // find tmp_square if it exists (without copying data from device)
    +            if (std::string(node->name) == "tmp_square") {
    +                result.calculated_square = node;
    +            }
    +        }
    +    }
    +    return res;
    +}
    +
    +static void power_iteration(
    +        const struct pca_params & params,
    +        struct ggml_tensor * input, // shape of input: [n_samples, n_embd]
    +        struct ggml_tensor * output) {
    +    //printf("in power iteration\n");
    +    struct pca_model model(input);
    +
    +    ggml_gallocr_t allocr = ggml_gallocr_new(ggml_backend_get_default_buffer_type(model.backend));
    +    struct pca_result result;
    +    struct ggml_tensor * last_eigenvector = NULL;
    +
    +    int n_iters = params.n_iterations / params.n_batch; // more batch, fewer iterations
    +    for (int iter = 0; iter < n_iters; ++iter) {
    +        bool calc_square = (iter == 0); // only need to calculate square for first iteration
    +        struct ggml_cgraph * gf = build_graph_piter(params, model, calc_square);
    +        // ggml_graph_dump_dot(gf, nullptr, "/tmp/_cgraph.dot");
    +        compute_piter(params, model, gf, allocr, result);
    +
    +        for (size_t k = 0; k < result.distances.size(); ++k) {
    +            last_eigenvector = result.eigenvectors[k];
    +            if (result.distances[k] < params.tolerance) {
    +                break; // done
    +            }
    +        }
    +
    +        if (calc_square) {
    +            // copy and store the square matrix if needed
    +            GGML_ASSERT(result.calculated_square != NULL);
    +            ggml_backend_tensor_copy(result.calculated_square, model.dev_square);
    +        }
    +
    +        {
    +            // copy last eigen vector and store as input for next iteration
    +            GGML_ASSERT(last_eigenvector != NULL);
    +            ggml_backend_tensor_copy(last_eigenvector, model.dev_eigenvector);
    +        }
    +
    +        printf("%s: layer %d/%d, iteration: %d / total: %d (batch = %d) ...\n",
    +            __func__, params.i_layer+1, params.n_layers, iter, n_iters, params.n_batch);
    +    }
    +
    +    // get output tensor
    +    GGML_ASSERT(last_eigenvector);
    +    ggml_backend_tensor_get(last_eigenvector, output->data, 0, ggml_nbytes(last_eigenvector));
    +    //print_debug_tensor(output);
    +    ggml_gallocr_free(allocr);
    +}
    +
    +static void run_pca(
    +        struct pca_params & params,
    +        const std::vector & v_input, // shape of v_input[0]: [n_samples, n_embd]
    +        const std::vector & v_output) {
    +    printf("%s: Running PCA...\n", __func__);
    +    for (size_t il = 0; il < v_input.size(); ++il) {
    +
    +        // prepare output vector
    +        struct ggml_tensor * ctrl_out = v_output[il];
    +        ggml_format_name(ctrl_out, "direction.%ld", il+1);
    +
    +        // run power_iteration
    +        params.i_layer = il;
    +        params.n_layers = v_input.size();
    +        power_iteration(params, v_input[il], ctrl_out);
    +        printf("%s: Done layer %d / %d\n", __func__, (int) il+1, (int) v_input.size());
    +    }
    +}
    +
    +}
    diff --git a/examples/cvector-generator/positive.txt b/examples/cvector-generator/positive.txt
    new file mode 100644
    index 000000000..f28e9aa1a
    --- /dev/null
    +++ b/examples/cvector-generator/positive.txt
    @@ -0,0 +1 @@
    +[INST] Act like a person who is extremely happy. [/INST]
    \ No newline at end of file