Patch 2: Added threading for non posix systems

This commit is contained in:
CoderRC 2023-04-03 14:21:46 -04:00 committed by GitHub
parent 68623ee175
commit 8a7dd2c682
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2703 additions and 2695 deletions

11
ggml.h
View file

@ -776,13 +776,20 @@ int ggml_cpu_has_vsx(void);
// //
// threading for non posix systems // threading for non posix systems
// //
#if defined(_WIN32) && !defined(_POSIX_THREADS)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#else
#include <unistd.h>
#endif
#ifndef _POSIX_THREADS #ifndef _POSIX_THREADS
#if defined(_WIN32) #if defined(_WIN32)
#include <windows.h> #include <windows.h>
#endif #endif
typedef HANDLE pthread_t; typedef HANDLE pthread_t;
typedef DWORD thread_ret_t; static int pthread_create(pthread_t* out, void* unused, void*(*func)(void*), void* arg);
static int pthread_create(pthread_t* out, void* unused, thread_ret_t(*func)(void*), void* arg);
static int pthread_join(pthread_t thread, void* unused); static int pthread_join(pthread_t thread, void* unused);
#endif #endif

View file

@ -325,6 +325,7 @@ static void *mmap_file(const char *fname, uint64_t *mm_length) {
the_load_file_to_standby_struct * the_load_file_to_standby_struct1 = 0; the_load_file_to_standby_struct * the_load_file_to_standby_struct1 = 0;
const size_t readstridelen = 1 << 20; const size_t readstridelen = 1 << 20;
size_t fnamelen = strlen(fname); size_t fnamelen = strlen(fname);
pthread_t threadId;
#if defined(_WIN32) && !defined(_POSIX_MAPPED_FILES) #if defined(_WIN32) && !defined(_POSIX_MAPPED_FILES)
HANDLE hFile = CreateFileA(fname, HANDLE hFile = CreateFileA(fname,
GENERIC_READ, GENERIC_READ,
@ -382,7 +383,7 @@ the_load_file_to_standby_struct * the_load_file_to_standby_struct1 = 0;
if(the_load_file_to_standby_struct1->fname){ if(the_load_file_to_standby_struct1->fname){
memcpy(the_load_file_to_standby_struct1->fname, fname, fnamelen); memcpy(the_load_file_to_standby_struct1->fname, fname, fnamelen);
} }
pthread_create(0, 0, (void *(*)(void*))(&load_file_to_standby), the_load_file_to_standby_struct1); pthread_create(&threadId, 0, (void*(*)(void*))(&load_file_to_standby), the_load_file_to_standby_struct1);
} }
return addr; return addr;
} }