|
14 | 14 | #include"ggml/ggml-backend.h" |
15 | 15 | #include"ggml/ggml.h" |
16 | 16 |
|
| 17 | + |
| 18 | + |
| 19 | +#if defined(_MSC_VER) |
| 20 | +#include<Windows.h> |
| 21 | +// windows.h, naming conflict with micros: std::min, sdt::max, SDLogLevel::ERROR |
| 22 | + |
| 23 | +#undef ERROR |
| 24 | +staticwchar_t*str2wstr(constchar* str) { |
| 25 | +size_t len =strlen(str) +1; |
| 26 | +wchar_t* wstr = (wchar_t*)malloc(len *sizeof(wchar_t)); |
| 27 | +MultiByteToWideChar(CP_UTF8,0, str, (int)(len *sizeof(char)), wstr, |
| 28 | + (int)len); |
| 29 | +return wstr; |
| 30 | +}; |
| 31 | + |
| 32 | +//#include <stringapiset.h> |
| 33 | +// donot only include stringapiset.h, C1189 #error: "No Target Architecture" |
| 34 | + |
| 35 | +#else// defined(_MSC_VER) |
| 36 | + |
| 37 | +#endif// defined(_MSC_VER) |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
17 | 44 | #defineST_HEADER_SIZE_LEN8 |
18 | 45 |
|
19 | 46 | uint64_tread_u64(uint8_t* buffer) { |
@@ -1203,7 +1230,17 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb) { |
1203 | 1230 | std::string file_path = file_paths_[file_index]; |
1204 | 1231 | LOG_DEBUG("loading tensors from %s", file_path.c_str()); |
1205 | 1232 |
|
| 1233 | + |
| 1234 | +#if defined(_MSC_VER) |
| 1235 | +constchar * c_file_path = file_path.c_str(); |
| 1236 | +constwchar_t * c_w_file_path =str2wstr(c_file_path); |
| 1237 | + std::ifstreamfile(c_w_file_path, std::ios::binary); |
| 1238 | +delete c_w_file_path; |
| 1239 | + |
| 1240 | +#else// defined(_MSC_VER) |
1206 | 1241 | std::ifstreamfile(file_path, std::ios::binary); |
| 1242 | +#endif// defined(_MSC_VER) |
| 1243 | + |
1207 | 1244 | if (!file.is_open()) { |
1208 | 1245 | LOG_ERROR("failed to open '%s'", file_path.c_str()); |
1209 | 1246 | returnfalse; |
|