clip.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 int32_t clip_image_size (const struct clip_ctx * ctx);
  39. CLIP_API int32_t clip_patch_size (const struct clip_ctx * ctx);
  40. CLIP_API int32_t clip_hidden_size(const struct clip_ctx * ctx);
  41. // TODO: should be enum, not string
  42. CLIP_API const char * clip_patch_merge_type(const struct clip_ctx * ctx);
  43. CLIP_API const int32_t * clip_image_grid(const struct clip_ctx * ctx);
  44. CLIP_API int clip_n_patches (const struct clip_ctx * ctx);
  45. CLIP_API int clip_n_mmproj_embd(const struct clip_ctx * ctx);
  46. CLIP_API int clip_uhd_num_image_embeds_col(struct clip_ctx * ctx_clip);
  47. CLIP_API void clip_add_load_image_size(struct clip_ctx * ctx_clip, struct clip_image_size * load_image_size);
  48. CLIP_API struct clip_image_size * clip_image_size_init();
  49. CLIP_API struct clip_image_u8 * clip_image_u8_init ();
  50. CLIP_API struct clip_image_f32 * clip_image_f32_init();
  51. CLIP_API void clip_image_u8_free (struct clip_image_u8 * img);
  52. CLIP_API void clip_image_f32_free(struct clip_image_f32 * img);
  53. CLIP_API void clip_image_u8_batch_free (struct clip_image_u8_batch * batch);
  54. CLIP_API void clip_image_f32_batch_free(struct clip_image_f32_batch * batch);
  55. CLIP_API bool clip_image_load_from_file(const char * fname, struct clip_image_u8 * img);
  56. /** interpret bytes as an image file with length bytes_length, and use the result to populate img */
  57. CLIP_API bool clip_image_load_from_bytes(const unsigned char * bytes, size_t bytes_length, struct clip_image_u8 * img);
  58. /** preprocess img and store the result in res_imgs, pad_to_square may be overridden to false depending on model configuration */
  59. CLIP_API bool clip_image_preprocess(struct clip_ctx * ctx, const struct clip_image_u8 * img, struct clip_image_f32_batch * res_imgs );
  60. CLIP_API struct ggml_tensor * clip_get_newline_tensor(const struct clip_ctx * ctx);
  61. CLIP_API bool clip_image_encode (struct clip_ctx * ctx, int n_threads, struct clip_image_f32 * img, float * vec);
  62. CLIP_API bool clip_image_batch_encode(struct clip_ctx * ctx, int n_threads, const struct clip_image_f32_batch * imgs, float * vec);
  63. CLIP_API bool clip_model_quantize(const char * fname_inp, const char * fname_out, int itype);
  64. CLIP_API int clip_is_minicpmv(const struct clip_ctx * ctx);
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif // CLIP_H