KBaba7/llama.cpp
0
1#ifndef CLIP_H2#define CLIP_H3 4#include <stddef.h>5#include <stdint.h>6 7#ifdef LLAMA_SHARED8# if defined(_WIN32) && !defined(__MINGW32__)9# ifdef LLAMA_BUILD10# define CLIP_API __declspec(dllexport)11# else12# define CLIP_API __declspec(dllimport)13# endif14# else15# define CLIP_API __attribute__ ((visibility ("default")))16# endif17#else18# define CLIP_API19#endif20 21#ifdef __cplusplus22extern "C" {23#endif24 25struct clip_ctx;26 27struct clip_image_size {28 int width;29 int height;30};31 32struct clip_image_u8_batch {33 struct clip_image_u8 * data;34 size_t size;35};36 37struct clip_image_f32_batch {38 struct clip_image_f32 * data;39 size_t size;40};41 42CLIP_API struct clip_ctx * clip_model_load (const char * fname, int verbosity);43CLIP_API struct clip_ctx * clip_model_load_cpu(const char * fname, int verbosity);44 45CLIP_API void clip_free(struct clip_ctx * ctx);46 47CLIP_API size_t clip_embd_nbytes(const struct clip_ctx * ctx);48CLIP_API size_t clip_embd_nbytes_by_img(const struct clip_ctx * ctx, int img_h, int img_w);49 50CLIP_API int32_t clip_image_size (const struct clip_ctx * ctx);51CLIP_API int32_t clip_patch_size (const struct clip_ctx * ctx);52CLIP_API int32_t clip_hidden_size(const struct clip_ctx * ctx);53 54// TODO: should be enum, not string55CLIP_API const char * clip_patch_merge_type(const struct clip_ctx * ctx);56 57CLIP_API const int32_t * clip_image_grid(const struct clip_ctx * ctx);58 59CLIP_API int clip_n_patches (const struct clip_ctx * ctx);60CLIP_API int clip_n_patches_by_img (const struct clip_ctx * ctx, struct clip_image_f32 * img);61CLIP_API int clip_n_mmproj_embd (const struct clip_ctx * ctx);62 63CLIP_API int clip_uhd_num_image_embeds_col(struct clip_ctx * ctx_clip);64CLIP_API void clip_add_load_image_size(struct clip_ctx * ctx_clip, struct clip_image_size * load_image_size);65CLIP_API struct clip_image_size * clip_get_load_image_size(struct clip_ctx * ctx_clip);66 67CLIP_API struct clip_image_size * clip_image_size_init();68CLIP_API struct clip_image_u8 * clip_image_u8_init ();69CLIP_API struct clip_image_f32 * clip_image_f32_init();70 71CLIP_API void clip_image_u8_free (struct clip_image_u8 * img);72CLIP_API void clip_image_f32_free(struct clip_image_f32 * img);73CLIP_API void clip_image_u8_batch_free (struct clip_image_u8_batch * batch);74CLIP_API void clip_image_f32_batch_free(struct clip_image_f32_batch * batch);75 76CLIP_API bool clip_image_load_from_file(const char * fname, struct clip_image_u8 * img);77 78/** interpret bytes as an image file with length bytes_length, and use the result to populate img */79CLIP_API bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length, struct clip_image_u8 * img);80 81/** preprocess img and store the result in res_imgs, pad_to_square may be overridden to false depending on model configuration */82CLIP_API bool clip_image_preprocess(struct clip_ctx * ctx, const struct clip_image_u8 * img, struct clip_image_f32_batch * res_imgs );83 84CLIP_API struct ggml_tensor * clip_get_newline_tensor(const struct clip_ctx * ctx);85 86CLIP_API bool clip_image_encode (struct clip_ctx * ctx, int n_threads, struct clip_image_f32 * img, float * vec);87CLIP_API bool clip_image_batch_encode(struct clip_ctx * ctx, int n_threads, const struct clip_image_f32_batch * imgs, float * vec);88 89CLIP_API bool clip_model_quantize(const char * fname_inp, const char * fname_out, int itype);90 91CLIP_API int clip_is_minicpmv(const struct clip_ctx * ctx);92CLIP_API bool clip_is_qwen2vl(const struct clip_ctx * ctx);93 94CLIP_API bool clip_encode_float_image (struct clip_ctx * ctx, int n_threads, float * img, int h, int w, float * vec);95 96CLIP_API bool clip_is_glm(const struct clip_ctx * ctx);97 98#ifdef __cplusplus99}100#endif101 102#endif // CLIP_H103 