Skip to content

Commit

Permalink
Merge pull request #30 from fszontagh/tcpsrv
Browse files Browse the repository at this point in the history
Tcpsrv
  • Loading branch information
fszontagh authored Jan 8, 2025
2 parents 2f0c5e5 + b50f03f commit d6577c8
Show file tree
Hide file tree
Showing 31 changed files with 2,272 additions and 571 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ set(SOURCES
src/ui/QueueManager.cpp
src/ui/ModelInfo.cpp
src/libs/SharedMemoryManager.cpp
src/libs/TcpClient.cpp

)

Expand Down Expand Up @@ -165,14 +166,15 @@ endif()

include(cmake/intl.cmake)

add_dependencies(${PROJECT_BINARY_NAME} ${APPDEPENDS} po-compile)
add_dependencies(${PROJECT_BINARY_NAME} ${APPDEPENDS} po-compile sockets_cpp)

# Include directories
target_include_directories(${PROJECT_BINARY_NAME} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${stable_diffusion_SOURCE_DIR}
${CpuFeatures_SOURCE_DIR}
${wxWidgets_SOURCE_DIR}/include
${sockets_cpp_SOURCE}
)
message(STATUS "APPDEPS: ${APPDEPENDS}")

Expand Down
1 change: 1 addition & 0 deletions extprocess/src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <wx/string.h>
#include <wx/translation.h>
#include <wx/filename.h>
#include "network/packets.h"
#include "helpers/sd.hpp"
#include "helpers/sslUtils.hpp"
#include "libs/SharedLibrary.h"
Expand Down
14 changes: 2 additions & 12 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
set(SERVER_BINARY_NAME "${PROJECT_BINARY_NAME}_server")
set(SERVER_EXPTORCESS_BINARY_NAME "${PROJECT_BINARY_NAME}_server_diffuser")

math(EXPR SHARED_MEMORY_SIZE "1024*1024*16")
math(EXPR STACK_SIZE "${SHARED_MEMORY_SIZE} + ((1024*1024)*4)")
message(STATUS "SHARED_MEMORY_SIZE: ${SHARED_MEMORY_SIZE}")
message(STATUS "STACK_SIZE: ${STACK_SIZE}")

configure_file(src/config.hpp.in config.hpp)



set(SOURCES src/main.cpp src/TerminalApp.cpp src/SocketApp.cpp)

Expand All @@ -17,8 +7,8 @@ if (MSVC)
endif()

add_executable(${SERVER_BINARY_NAME} ${SOURCES} ${CMAKE_SOURCE_DIR}/src/libs/SharedLibrary.cpp ${CMAKE_SOURCE_DIR}/src/libs/SharedMemoryManager.cpp)

target_precompile_headers(${SERVER_BINARY_NAME} PRIVATE src/pch.h)
add_dependencies(${SERVER_BINARY_NAME} sockets_cpp)
#target_precompile_headers(${SERVER_BINARY_NAME} PRIVATE src/pch.h)

if (MSVC)
target_link_options(${SERVER_BINARY_NAME} PRIVATE /STACK:${STACK_SIZE})
Expand Down
3 changes: 2 additions & 1 deletion server/server-config-example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"port": 8191,
"host": "127.0.0.1",
"logfile": "/var/log/stable-diffusion-server.log"
"logfile": "/var/log/stable-diffusion-server.log",
"backend": "avx"
}
133 changes: 128 additions & 5 deletions server/src/ServerConfig.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,136 @@
#ifndef __SERVER_CONFIG_H
#define __SERVER_CONFIG_H

#include <cstddef>
#include <cstdint>

#include "libs/json.hpp"

enum class backend_type {
AVX,
AVX2,
AVX512,
CUDA,
HIPBLAS,
VULKAN
};

inline const std::map<std::string, backend_type> backend_str_to_type = {
{"avx", backend_type::AVX},
{"avx2", backend_type::AVX2},
{"avx512", backend_type::AVX512},
{"cuda", backend_type::CUDA},
{"hipblas", backend_type::HIPBLAS},
{"vulkan", backend_type::VULKAN}};

inline const std::map<backend_type, std::string> backend_type_to_str = {
{backend_type::AVX, "avx"},
{backend_type::AVX2, "avx2"},
{backend_type::AVX512, "avx512"},
{backend_type::CUDA, "cuda"},
{backend_type::HIPBLAS, "hipblas"},
{backend_type::VULKAN, "vulkan"}};

struct ServerConfig {
std::string host = "127.0.0.1";
uint16_t port = 8191;
int max_clients = 10;
size_t max_request_size = 1024 * 1024 * 1024;
std::string host = "127.0.0.1";
uint16_t port = 8191;
int max_clients = 10;
size_t max_request_size = 1024 * 1024 * 1024;
unsigned int tcp_keepalive = 60; // kep alive period
std::string logfile;
backend_type backend = backend_type::AVX;
std::string authkey;
std::string server_name = ""; // optional server name to display in the gui
unsigned int unauthorized_timeout = 4; // disconnect clients after this many seconds if not authenticated
std::string exprocess_binary_path; // force to use this exprocess binary
std::string model_path;
std::string lora_path;
std::string vae_path;
std::string embedding_path;
std::string taesd_path;
std::string controlnet_path;
std::string esrgan_path;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ServerConfig, host, port, max_clients, max_request_size, logfile)
inline void to_json(nlohmann ::json& nlohmann_json_j, const ServerConfig& nlohmann_json_t) {
nlohmann_json_j["host"] = nlohmann_json_t.host;
nlohmann_json_j["port"] = nlohmann_json_t.port;
nlohmann_json_j["max_clients"] = nlohmann_json_t.max_clients;
nlohmann_json_j["max_request_size"] = nlohmann_json_t.max_request_size;
nlohmann_json_j["logfile"] = nlohmann_json_t.logfile;
nlohmann_json_j["backend"] = backend_type_to_str.at(nlohmann_json_t.backend);
nlohmann_json_j["authkey"] = nlohmann_json_t.authkey;
nlohmann_json_j["unauthorized_timeout"] = nlohmann_json_t.unauthorized_timeout;
if (nlohmann_json_t.server_name.empty() == false) {
nlohmann_json_j["server_name"] = nlohmann_json_t.server_name;
}
if (nlohmann_json_t.exprocess_binary_path.empty() == false) {
nlohmann_json_j["exprocess_binary_path"] = nlohmann_json_t.exprocess_binary_path;
}
if (nlohmann_json_t.model_path.empty() == false) {
nlohmann_json_j["model_path"] = nlohmann_json_t.model_path;
}
if (nlohmann_json_t.lora_path.empty() == false) {
nlohmann_json_j["lora_path"] = nlohmann_json_t.lora_path;
}
if (nlohmann_json_t.vae_path.empty() == false) {
nlohmann_json_j["vae_path"] = nlohmann_json_t.vae_path;
}
if (nlohmann_json_t.embedding_path.empty() == false) {
nlohmann_json_j["embedding_path"] = nlohmann_json_t.embedding_path;
}
if (nlohmann_json_t.taesd_path.empty() == false) {
nlohmann_json_j["taesd_path"] = nlohmann_json_t.taesd_path;
}
if (nlohmann_json_t.controlnet_path.empty() == false) {
nlohmann_json_j["controlnet_path"] = nlohmann_json_t.controlnet_path;
}
if (nlohmann_json_t.esrgan_path.empty() == false) {
nlohmann_json_j["esrgan_path"] = nlohmann_json_t.esrgan_path;
}
}
inline void from_json(const nlohmann ::json& nlohmann_json_j, ServerConfig& nlohmann_json_t) {
const ServerConfig nlohmann_json_default_obj{};
nlohmann_json_t.host = nlohmann_json_j.value("host", nlohmann_json_default_obj.host);
nlohmann_json_t.port = nlohmann_json_j.value("port", nlohmann_json_default_obj.port);
nlohmann_json_t.max_clients = nlohmann_json_j.value("max_clients", nlohmann_json_default_obj.max_clients);
nlohmann_json_t.max_request_size = nlohmann_json_j.value("max_request_size", nlohmann_json_default_obj.max_request_size);
nlohmann_json_t.logfile = nlohmann_json_j.value("logfile", nlohmann_json_default_obj.logfile);

std::string backend = nlohmann_json_j.value("backend", "avx");
if (backend_str_to_type.find(backend) == backend_str_to_type.end()) {
backend = "avx";
}
nlohmann_json_t.backend = backend_str_to_type.at(backend);
nlohmann_json_t.authkey = nlohmann_json_j.value("authkey", nlohmann_json_default_obj.authkey);
if (nlohmann_json_j.contains("server_name") && !nlohmann_json_j["server_name"].is_null()) {
nlohmann_json_t.server_name = nlohmann_json_j.value("server_name", nlohmann_json_default_obj.server_name);
}
if (nlohmann_json_j.contains("exprocess_binary_path") && !nlohmann_json_j["exprocess_binary_path"].is_null()) {
nlohmann_json_t.exprocess_binary_path = nlohmann_json_j.value("exprocess_binary_path", nlohmann_json_default_obj.exprocess_binary_path);
}
nlohmann_json_t.unauthorized_timeout = nlohmann_json_j.value("unauthorized_timeout", nlohmann_json_default_obj.unauthorized_timeout);

if (nlohmann_json_j.contains("model_path") && !nlohmann_json_j["model_path"].is_null()) {
nlohmann_json_t.model_path = nlohmann_json_j.value("model_path", nlohmann_json_default_obj.model_path);
}
if (nlohmann_json_j.contains("lora_path") && !nlohmann_json_j["lora_path"].is_null()) {
nlohmann_json_t.lora_path = nlohmann_json_j.value("lora_path", nlohmann_json_default_obj.lora_path);
}
if (nlohmann_json_j.contains("vae_path") && !nlohmann_json_j["vae_path"].is_null()) {
nlohmann_json_t.vae_path = nlohmann_json_j.value("vae_path", nlohmann_json_default_obj.vae_path);
}
if (nlohmann_json_j.contains("embedding_path") && !nlohmann_json_j["embedding_path"].is_null()) {
nlohmann_json_t.embedding_path = nlohmann_json_j.value("embedding_path", nlohmann_json_default_obj.embedding_path);
}
if (nlohmann_json_j.contains("taesd_path") && !nlohmann_json_j["taesd_path"].is_null()) {
nlohmann_json_t.taesd_path = nlohmann_json_j.value("taesd_path", nlohmann_json_default_obj.taesd_path);
}
if (nlohmann_json_j.contains("controlnet_path") && !nlohmann_json_j["controlnet_path"].is_null()) {
nlohmann_json_t.controlnet_path = nlohmann_json_j.value("controlnet_path", nlohmann_json_default_obj.controlnet_path);
}
if (nlohmann_json_j.contains("esrgan_path") && !nlohmann_json_j["esrgan_path"].is_null()) {
nlohmann_json_t.esrgan_path = nlohmann_json_j.value("esrgan_path", nlohmann_json_default_obj.esrgan_path);
}
}
#endif // __SERVER_CONFIG_H
Loading

0 comments on commit d6577c8

Please sign in to comment.