clip.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef CLIP_H
  2. #define CLIP_H
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #ifdef LLAMA_SHARED
  6. # if defined(_WIN32) && !defined(__MINGW32__)
  7. # ifdef LLAMA_BUILD
  8. # define CLIP_API __declspec(dllexport)
  9. # else
  10. # define CLIP_API __declspec(dllimport)
  11. # endif
  12. # else
  13. # define CLIP_API __attribute__ ((visibility ("default")))
  14. # endif
  15. #else
  16. # define CLIP_API
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. struct clip_ctx;
  22. struct clip_image_size {
  23. int width;
  24. int height;
  25. };
  26. struct clip_image_u8_batch {
  27. struct clip_image_u8 * data;
  28. size_t size;
  29. };
  30. struct clip_image_f32_batch {
  31. struct clip_image_f32 * data;
  32. size_t size;
  33. };
  34. CLIP_API struct clip_ctx * clip_model_load (const char * fname, int verbosity);
  35. CLIP_API struct clip_ctx * clip_model_load_cpu(const char * fname, int verbosity);
  36. CLIP_API void clip_free(struct clip_ctx * ctx);
  37. CLIP_API size_t clip_embd_nbytes(const struct clip_ctx * ctx);
  38. CLIP_API size_t clip_embd_nbytes_by_img(const struct clip_ctx * ctx, int img_h, int img_w);
  39. CLIP_API int32_t clip_image_size (const struct clip_ctx * ctx);
  40. CLIP_API int32_t clip_patch_size (const struct clip_ctx * ctx);
  41. CLIP_API int32_t clip_hidden_size(const struct clip_ctx * ctx);
  42. // TODO: should be enum, not string
  43. CLIP_API const char * clip_patch_merge_type(const struct clip_ctx * ctx);
  44. CLIP_API const int32_t * clip_image_grid(const struct clip_ctx * ctx);
  45. CLIP_API int clip_n_patches (const struct clip_ctx * ctx);
  46. CLIP_API int clip_n_patches_by_img (const struct clip_ctx * ctx, struct clip_image_f32 * img);
  47. CLIP_API int clip_n_mmproj_embd (const struct clip_ctx * ctx);
  48. CLIP_API int clip_uhd_num_image_embeds_col(struct clip_ctx * ctx_clip);
  49. CLIP_API void clip_add_load_image_size(struct clip_ctx * ctx_clip, struct clip_image_size * load_image_size);
  50. CLIP_API struct clip_image_size * clip_get_load_image_size(struct clip_ctx * ctx_clip);
  51. CLIP_API struct clip_image_size * clip_image_size_init();
  52. CLIP_API struct clip_image_u8 * clip_image_u8_init ();
  53. CLIP_API struct clip_image_f32 * clip_image_f32_init();
  54. CLIP_API void clip_image_u8_free (struct clip_image_u8 * img);
  55. CLIP_API void clip_image_f32_free(struct clip_image_f32 * img);
  56. CLIP_API void clip_image_u8_batch_free (struct clip_image_u8_batch * batch);
  57. CLIP_API void clip_image_f32_batch_free(struct clip_image_f32_batch * batch);
  58. CLIP_API bool clip_image_load_from_file(const char * fname, struct clip_image_u8 * img);
  59. /** interpret bytes as an image file with length bytes_length, and use the result to populate img */
  60. CLIP_API bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length, struct clip_image_u8 * img);
  61. /** preprocess img and store the result in res_imgs, pad_to_square may be overridden to false depending on model configuration */
  62. CLIP_API bool clip_image_preprocess(struct clip_ctx * ctx, const struct clip_image_u8 * img, struct clip_image_f32_batch * res_imgs );
  63. CLIP_API struct ggml_tensor * clip_get_newline_tensor(const struct clip_ctx * ctx);
  64. CLIP_API bool clip_image_encode (struct clip_ctx * ctx, int n_threads, struct clip_image_f32 * img, float * vec);
  65. CLIP_API bool clip_image_batch_encode(struct clip_ctx * ctx, int n_threads, const struct clip_image_f32_batch * imgs, float * vec);
  66. CLIP_API bool clip_model_quantize(const char * fname_inp, const char * fname_out, int itype);
  67. CLIP_API int clip_is_minicpmv(const struct clip_ctx * ctx);
  68. CLIP_API bool clip_is_qwen2vl(const struct clip_ctx * ctx);
  69. CLIP_API bool clip_encode_float_image (struct clip_ctx * ctx, int n_threads, float * img, int h, int w, float * vec);
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif // CLIP_H