char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
d2a818231
char/aliceai-t5-moe
1#pragma once 2 3#include <atomic> 4#include <cstdio> 5#include <string> 6#include <vector> 7 8#ifdef LLAMA_SUBPROCESS 9#include <sheredom/subprocess.h> 10#else 11// dummy values to allow compilation when subprocess is disabled 12struct subprocess_s {}; 13static constexprint subprocess_option_no_window = 0 ; 14static constexprint subprocess_option_combined_stdout_stderr = 0 ; 15static constexprint subprocess_option_inherit_environment = 0 ; 16static constexprint subprocess_option_search_user_path = 0 ; 17#endif 18 19// RAII-style wrapper around https://github.com/sheredom/subprocess.h, 20// exposing method calls instead of free functions operating on subprocess_s. 21struct common_subproc { 22common_subproc ()= default ; 23 ~common_subproc (); 24 25common_subproc (const common_subproc & )= delete ; 26common_subproc & operator = (const common_subproc & )= delete ; 27 28// spawn a child process; if env is non-empty it replaces the child's environment 29// (do not combine with subprocess_option_inherit_environment) 30bool create ( 31const std ::vector < std ::string > & args , 32int options , 33const std ::vector < std ::string > & env = {}, 34const char * cwd = nullptr); 35 36bool alive (); 37 38// true if LLAMA_SUBPROCESS was enabled at build time; when false, create() always fails 39static bool is_supported (); 40 41FILE * stdin_file (); 42FILE * stdout_file (); 43FILE * stderr_file (); 44 45// close stdin and detach it from the process, so a later join()/destroy() won't double-close it; 46// use this after writing all input to signal EOF to the child while it's still running 47void close_stdin (); 48 49void terminate (); 50 51// wait for the process to exit, release the underlying handle and return its exit code 52int join (); 53 54private : 55subprocess_s proc {}; 56std ::atomic < bool > is_created {false}; 57 58bool has_handle ()const ; 59};