Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03k
1/*!2 Copyright 2013 Lovell Fuller and others.3 SPDX-License-Identifier: Apache-2.04*/5 6#include <cmath>7#include <cstdio>8#include <string>9 10#include <napi.h>11#include <vips/vips8>12#include <vips/vector.h>13 14#include "./common.h"15#include "./operations.h"16#include "./utilities.h"17 18/*19 Get and set cache limits20*/21Napi::Value cache(const Napi::CallbackInfo& info) {22 Napi::Env env = info.Env();23 24 // Set memory limit25 if (info[size_t(0)].IsNumber()) {26 vips_cache_set_max_mem(static_cast<size_t>(info[size_t(0)].As<Napi::Number>().Uint32Value()) * 1048576);27 }28 // Set file limit29 if (info[size_t(1)].IsNumber()) {30 vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Uint32Value());31 }32 // Set items limit33 if (info[size_t(2)].IsNumber()) {34 vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Uint32Value());35 }36 37 // Get memory stats38 Napi::Object memory = Napi::Object::New(env);39 memory.Set("current", round(vips_tracked_get_mem() / 1048576));40 memory.Set("high", round(vips_tracked_get_mem_highwater() / 1048576));41 memory.Set("max", round(vips_cache_get_max_mem() / 1048576));42 // Get file stats43 Napi::Object files = Napi::Object::New(env);44 files.Set("current", vips_tracked_get_files());45 files.Set("max", vips_cache_get_max_files());46 47 // Get item stats48 Napi::Object items = Napi::Object::New(env);49 items.Set("current", vips_cache_get_size());50 items.Set("max", vips_cache_get_max());51 52 Napi::Object cache = Napi::Object::New(env);53 cache.Set("memory", memory);54 cache.Set("files", files);55 cache.Set("items", items);56 return cache;57}58 59/*60 Get and set size of thread pool61*/62Napi::Value concurrency(const Napi::CallbackInfo& info) {63 // Set concurrency64 if (info[size_t(0)].IsNumber()) {65 vips_concurrency_set(info[size_t(0)].As<Napi::Number>().Int32Value());66 }67 // Get concurrency68 return Napi::Number::New(info.Env(), vips_concurrency_get());69}70 71/*72 Get internal counters (queued tasks, processing tasks)73*/74Napi::Value counters(const Napi::CallbackInfo& info) {75 Napi::Object counters = Napi::Object::New(info.Env());76 counters.Set("queue", static_cast<int>(sharp::counterQueue));77 counters.Set("process", static_cast<int>(sharp::counterProcess));78 return counters;79}80 81/*82 Get and set use of SIMD vector unit instructions83*/84Napi::Value simd(const Napi::CallbackInfo& info) {85 // Set state86 if (info[size_t(0)].IsBoolean()) {87 vips_vector_set_enabled(info[size_t(0)].As<Napi::Boolean>().Value());88 }89 // Get state90 return Napi::Boolean::New(info.Env(), vips_vector_isenabled());91}92 93/*94 Get libvips version95*/96Napi::Value libvipsVersion(const Napi::CallbackInfo& info) {97 Napi::Env env = info.Env();98 Napi::Object version = Napi::Object::New(env);99 100 char semver[9];101 std::snprintf(semver, sizeof(semver), "%d.%d.%d", vips_version(0), vips_version(1), vips_version(2));102 version.Set("semver", Napi::String::New(env, semver));103#ifdef SHARP_USE_GLOBAL_LIBVIPS104 version.Set("isGlobal", Napi::Boolean::New(env, true));105#else106 version.Set("isGlobal", Napi::Boolean::New(env, false));107#endif108#ifdef __EMSCRIPTEN__109 version.Set("isWasm", Napi::Boolean::New(env, true));110#else111 version.Set("isWasm", Napi::Boolean::New(env, false));112#endif113 return version;114}115 116/*117 Get available input/output file/buffer/stream formats118*/119Napi::Value format(const Napi::CallbackInfo& info) {120 Napi::Env env = info.Env();121 Napi::Object format = Napi::Object::New(env);122 for (std::string const f : {123 "jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",124 "ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad", "dcraw"125 }) {126 std::string id = f == "jp2k" ? "jp2" : f;127 // Input128 const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str());129 Napi::Boolean hasInputFile = Napi::Boolean::New(env, oc);130 Napi::Boolean hasInputBuffer =131 Napi::Boolean::New(env, vips_type_find("VipsOperation", (f + "load_buffer").c_str()));132 Napi::Object input = Napi::Object::New(env);133 input.Set("file", hasInputFile);134 input.Set("buffer", hasInputBuffer);135 input.Set("stream", hasInputBuffer);136 if (hasInputFile) {137 const VipsForeignClass *fc = VIPS_FOREIGN_CLASS(oc);138 if (fc->suffs) {139 Napi::Array fileSuffix = Napi::Array::New(env);140 const char **suffix = fc->suffs;141 for (int i = 0; *suffix; i++, suffix++) {142 fileSuffix.Set(i, Napi::String::New(env, *suffix));143 }144 input.Set("fileSuffix", fileSuffix);145 }146 }147 // Output148 Napi::Boolean hasOutputFile =149 Napi::Boolean::New(env, vips_type_find("VipsOperation", (f + "save").c_str()));150 Napi::Boolean hasOutputBuffer =151 Napi::Boolean::New(env, vips_type_find("VipsOperation", (f + "save_buffer").c_str()));152 Napi::Object output = Napi::Object::New(env);153 output.Set("file", hasOutputFile);154 output.Set("buffer", hasOutputBuffer);155 output.Set("stream", hasOutputBuffer);156 // Other attributes157 Napi::Object container = Napi::Object::New(env);158 container.Set("id", id);159 container.Set("input", input);160 container.Set("output", output);161 // Add to set of formats162 format.Set(id, container);163 }164 165 // Raw, uncompressed data166 Napi::Boolean supported = Napi::Boolean::New(env, true);167 Napi::Boolean unsupported = Napi::Boolean::New(env, false);168 Napi::Object rawInput = Napi::Object::New(env);169 rawInput.Set("file", unsupported);170 rawInput.Set("buffer", supported);171 rawInput.Set("stream", supported);172 Napi::Object rawOutput = Napi::Object::New(env);173 rawOutput.Set("file", unsupported);174 rawOutput.Set("buffer", supported);175 rawOutput.Set("stream", supported);176 Napi::Object raw = Napi::Object::New(env);177 raw.Set("id", "raw");178 raw.Set("input", rawInput);179 raw.Set("output", rawOutput);180 format.Set("raw", raw);181 182 return format;183}184 185/*186 (Un)block libvips operations at runtime.187*/188void block(const Napi::CallbackInfo& info) {189 Napi::Array ops = info[size_t(0)].As<Napi::Array>();190 bool const state = info[size_t(1)].As<Napi::Boolean>().Value();191 for (unsigned int i = 0; i < ops.Length(); i++) {192 vips_operation_block_set(ops.Get(i).As<Napi::String>().Utf8Value().c_str(), state);193 }194}195 196/*197 Synchronous, internal-only method used by some of the functional tests.198 Calculates the maximum colour distance using the DE2000 algorithm199 between two images of the same dimensions and number of channels.200*/201Napi::Value _maxColourDistance(const Napi::CallbackInfo& info) {202 Napi::Env env = info.Env();203 204 // Open input files205 VImage image1;206 sharp::ImageType imageType1 = sharp::DetermineImageType(info[size_t(0)].As<Napi::String>().Utf8Value().data());207 if (imageType1 != sharp::ImageType::UNKNOWN) {208 try {209 image1 = VImage::new_from_file(info[size_t(0)].As<Napi::String>().Utf8Value().c_str());210 } catch (...) {211 throw Napi::Error::New(env, "Input file 1 has corrupt header");212 }213 } else {214 throw Napi::Error::New(env, "Input file 1 is of an unsupported image format");215 }216 VImage image2;217 sharp::ImageType imageType2 = sharp::DetermineImageType(info[size_t(1)].As<Napi::String>().Utf8Value().data());218 if (imageType2 != sharp::ImageType::UNKNOWN) {219 try {220 image2 = VImage::new_from_file(info[size_t(1)].As<Napi::String>().Utf8Value().c_str());221 } catch (...) {222 throw Napi::Error::New(env, "Input file 2 has corrupt header");223 }224 } else {225 throw Napi::Error::New(env, "Input file 2 is of an unsupported image format");226 }227 // Ensure same number of channels228 if (image1.bands() != image2.bands()) {229 throw Napi::Error::New(env, "mismatchedBands");230 }231 // Ensure same dimensions232 if (image1.width() != image2.width() || image1.height() != image2.height()) {233 throw Napi::Error::New(env, "mismatchedDimensions");234 }235 236 double maxColourDistance;237 try {238 // Premultiply and remove alpha239 if (image1.has_alpha()) {240 image1 = image1.premultiply().extract_band(1, VImage::option()->set("n", image1.bands() - 1));241 }242 if (image2.has_alpha()) {243 image2 = image2.premultiply().extract_band(1, VImage::option()->set("n", image2.bands() - 1));244 }245 // Calculate colour distance246 maxColourDistance = image1.dE00(image2).max();247 } catch (std::runtime_error const &err) {248 throw Napi::Error::New(env, err.what());249 }250 251 // Clean up libvips' per-request data and threads252 vips_error_clear();253 vips_thread_shutdown();254 255 return Napi::Number::New(env, maxColourDistance);256}257 258#if defined(__GNUC__)259// mallctl will be resolved by the runtime linker when jemalloc is being used260extern "C" {261 int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) __attribute__((weak));262}263Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info) {264 Napi::Env env = info.Env();265 return Napi::Boolean::New(env, mallctl != nullptr);266}267#else268Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info) {269 Napi::Env env = info.Env();270 return Napi::Boolean::New(env, false);271}272#endif273 274#if defined(__GNUC__) && defined(__x86_64__)275// Are SSE 4.2 intrinsics available at runtime?276Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {277 Napi::Env env = info.Env();278 unsigned int eax, ebx, ecx, edx;279 __asm__ __volatile__("cpuid"280 : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)281 : "a"(1));282 return Napi::Boolean::New(env, (ecx & 1U << 20) != 0);283}284#else285Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {286 Napi::Env env = info.Env();287 return Napi::Boolean::New(env, false);288}289#endif290 