Compare commits

..

1 Commits

Author SHA1 Message Date
Eric Curtin d3d06debe3 server : add pidfile option
So we can track the pid of this process

Signed-off-by: Eric Curtin <ecurtin@redhat.com>
2025-06-17 21:47:53 +01:00
7 changed files with 115 additions and 65 deletions
+4
View File
@@ -3373,5 +3373,9 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
}
).set_examples({LLAMA_EXAMPLE_SERVER}));
add_opt(common_arg({ "--pidfile" }, "FILE", "path to PID file for server process",
[](common_params & params, const std::string & value) { params.pidfile = value; })
.set_examples({ LLAMA_EXAMPLE_SERVER }));
return ctx_arg;
}
+1
View File
@@ -366,6 +366,7 @@ struct common_params {
std::string hostname = "127.0.0.1";
std::string public_path = ""; // NOLINT
std::string chat_template = ""; // NOLINT
std::string pidfile = ""; // path to PID file for server process // NOLINT
bool use_jinja = false; // NOLINT
bool enable_chat_template = true;
common_reasoning_format reasoning_format = COMMON_REASONING_FORMAT_DEEPSEEK;
-44
View File
@@ -368,8 +368,6 @@ if (MSVC)
/wd4005 # Macro redefinition
/wd4244 # Conversion from one type to another type, possible loss of data
/wd4267 # Conversion from 'size_t' to a smaller type, possible loss of data
/wd4305 # Conversion from 'type1' to 'type2', possible loss of data
/wd4566 # Conversion from 'char' to 'wchar_t', possible loss of data
/wd4996 # Disable POSIX deprecation warnings
/wd4702 # Unreachable code warnings
)
@@ -389,46 +387,4 @@ if (MSVC)
disable_msvc_warnings(ggml-cpu-skylakex)
disable_msvc_warnings(ggml-cpu-icelake)
disable_msvc_warnings(ggml-cpu-alderlake)
if (GGML_BUILD_EXAMPLES)
disable_msvc_warnings(common-ggml)
disable_msvc_warnings(common)
disable_msvc_warnings(mnist-common)
disable_msvc_warnings(mnist-eval)
disable_msvc_warnings(mnist-train)
disable_msvc_warnings(gpt-2-ctx)
disable_msvc_warnings(gpt-2-alloc)
disable_msvc_warnings(gpt-2-backend)
disable_msvc_warnings(gpt-2-sched)
disable_msvc_warnings(gpt-2-quantize)
disable_msvc_warnings(gpt-2-batched)
disable_msvc_warnings(gpt-j)
disable_msvc_warnings(gpt-j-quantize)
disable_msvc_warnings(magika)
disable_msvc_warnings(yolov3-tiny)
disable_msvc_warnings(sam)
disable_msvc_warnings(simple-ctx)
disable_msvc_warnings(simple-backend)
endif()
if (GGML_BUILD_TESTS)
disable_msvc_warnings(test-mul-mat)
disable_msvc_warnings(test-arange)
disable_msvc_warnings(test-backend-ops)
disable_msvc_warnings(test-cont)
disable_msvc_warnings(test-conv-transpose)
disable_msvc_warnings(test-conv-transpose-1d)
disable_msvc_warnings(test-conv1d)
disable_msvc_warnings(test-conv2d)
disable_msvc_warnings(test-conv2d-dw)
disable_msvc_warnings(test-customop)
disable_msvc_warnings(test-dup)
disable_msvc_warnings(test-opt)
disable_msvc_warnings(test-pool)
endif ()
endif()
+4 -8
View File
@@ -144,15 +144,9 @@ if (Vulkan_FOUND)
${VULKAN_SHADER_GEN_CMAKE_ARGS}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
# NOTE: When DESTDIR is set using Makefile generators and
# "make install" triggers the build step, vulkan-shaders-gen
# would be installed into the DESTDIR prefix, so it is unset
# to ensure that does not happen.
INSTALL_COMMAND ${CMAKE_COMMAND} -E env --unset=DESTDIR
${CMAKE_COMMAND} --install . --config $<CONFIG>
INSTALL_COMMAND ${CMAKE_COMMAND} --install . --config $<CONFIG>
)
ExternalProject_Add_StepTargets(vulkan-shaders-gen build install)
set (_ggml_vk_host_suffix $<IF:$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>,.exe,>)
set (_ggml_vk_genshaders_dir "${CMAKE_BINARY_DIR}/$<CONFIG>")
@@ -178,6 +172,8 @@ if (Vulkan_FOUND)
DEPENDS ${_ggml_vk_shader_files}
vulkan-shaders-gen
vulkan-shaders-gen-build
vulkan-shaders-gen-install
COMMENT "Generate vulkan shaders"
)
+6
View File
@@ -888,6 +888,12 @@ struct ggml_context {
struct ggml_object * objects_end;
};
struct ggml_context_container {
bool used;
struct ggml_context context;
};
//
// data types
//
+1 -1
View File
@@ -1 +1 @@
8cda0a3c19f2c7dc493887353c42f6956bc268b1
6a7d170c04789f6ebcf320ed03c1b16973f93bd7
+99 -12
View File
@@ -14,22 +14,31 @@
// mime type for sending response
#define MIMETYPE_JSON "application/json; charset=utf-8"
#include <signal.h>
#include <atomic>
#include <chrono>
#include <cinttypes>
#include <condition_variable>
#include <cstddef>
#include <deque>
#include <memory>
#include <mutex>
#include <thread>
#include <unordered_map>
#include <unordered_set>
// auto generated files (see README.md for details)
#include "index.html.gz.hpp"
#include "loading.html.hpp"
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstddef>
#include <cinttypes>
#include <deque>
#include <memory>
#include <mutex>
#include <signal.h>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#ifdef _WIN32
#include <process.h>
#define getpid _getpid
#define pid_t int;
#else
#include <unistd.h>
#endif
using json = nlohmann::ordered_json;
@@ -3691,6 +3700,77 @@ inline void signal_handler(int signal) {
shutdown_handler(signal);
}
static bool check_pid_alive(const pid_t pid) {
if (pid <= 0) {
return false;
}
// Process is alive or exists but is inaccessible
if (kill(pid, 0) == 0 || errno == EPERM) {
return true; // Process is alive
}
return false; // Process does not exist or other error
}
class PidFile {
public:
FILE * file = nullptr;
std::string fname;
bool rm = false;
FILE * open(const std::string & filename, const char * mode, const bool r = false) {
file = ggml_fopen(filename.c_str(), mode);
fname = filename;
rm = r;
return file;
}
void close() {
fclose(file);
file = nullptr;
if (rm) {
// Remove stale pidfile
unlink(fname.c_str());
}
}
~PidFile() {
if (file) {
close();
}
}
};
static bool is_old_pid_alive(const std::string & filename) {
pid_t oldpid = 0;
PidFile f;
if (f.open(filename, "r")) {
if (fscanf(f.file, "%d", &oldpid) == 1) {
if (check_pid_alive(oldpid)) {
LOG_ERR("Process already running with PID %d\n", oldpid);
return true;
}
}
}
return false;
}
static int create_pidfile(const std::string & pidfile, PidFile & f) {
if (!f.open(pidfile.c_str(), "w", true)) {
LOG_ERR("Unable to open pidfile %s: %s\n", pidfile.c_str(), strerror(errno));
return -1;
}
fprintf(f.file, "%d\n", getpid());
fflush(f.file);
return 0;
}
int main(int argc, char ** argv) {
// own arguments required by this example
common_params params;
@@ -3699,6 +3779,13 @@ int main(int argc, char ** argv) {
return 1;
}
PidFile f;
if (!params.pidfile.empty()) {
if (is_old_pid_alive(params.pidfile) || create_pidfile(params.pidfile, f)) {
return 1;
}
}
common_init();
// struct that contains llama context and inference