Skip to content

Commit 9f2920d

Browse files
committed
clip : use smart pointers
1 parent d3bd719 commit 9f2920d

File tree

5 files changed

+266
-249
lines changed

5 files changed

+266
-249
lines changed

examples/llava/clip-impl.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "ggml.h"
22
#include "gguf.h"
3+
#include "clip.h"
34

45
#include <climits>
56
#include <cstdarg>
@@ -178,6 +179,42 @@ static void clip_log_internal(enum ggml_log_level level, const char * format, ..
178179
#define LOG_DBG(...) LOG_TMPL(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__)
179180
#define LOG_CNT(...) LOG_TMPL(GGML_LOG_LEVEL_CONT, __VA_ARGS__)
180181

182+
//
183+
// cpp wrappers
184+
//
185+
186+
struct clip_image_u8_deleter {
187+
void operator()(clip_image_u8 * val) { clip_image_u8_free(val); }
188+
};
189+
190+
struct clip_image_f32_deleter {
191+
void operator()(clip_image_f32 * val) { clip_image_f32_free(val); }
192+
};
193+
194+
struct clip_image_size_deleter {
195+
void operator()(clip_image_size * val) { clip_image_size_free(val); }
196+
};
197+
198+
struct clip_image_u8_ptr : std::unique_ptr<clip_image_u8, clip_image_u8_deleter> {
199+
clip_image_u8_ptr() : std::unique_ptr<clip_image_u8, clip_image_u8_deleter>(clip_image_u8_init()) {}
200+
};
201+
202+
struct clip_image_f32_ptr : std::unique_ptr<clip_image_f32, clip_image_f32_deleter> {
203+
clip_image_f32_ptr() : std::unique_ptr<clip_image_f32, clip_image_f32_deleter>(clip_image_f32_init()) {}
204+
};
205+
206+
typedef std::unique_ptr<clip_image_size, clip_image_size_deleter> clip_image_size_ptr;
207+
208+
// these need to be struct to maintain compatibility with C interface
209+
struct clip_image_u8_batch : std::vector<clip_image_u8_ptr> {
210+
clip_image_u8_batch() : std::vector<clip_image_u8_ptr>() {}
211+
};
212+
struct clip_image_f32_batch : std::vector<clip_image_f32_ptr> {
213+
clip_image_f32_batch() : std::vector<clip_image_f32_ptr>() {}
214+
~clip_image_f32_batch() {}
215+
};
216+
217+
181218
//
182219
// common utils
183220
//

0 commit comments

Comments
 (0)