mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-26 23:29:53 +00:00
Some checks are pending
CI / ubuntu-latest-cmake (push) Waiting to run
CI / ubuntu-latest-cmake-vulkan (push) Waiting to run
CI / Build and push container images (push) Waiting to run
CI / macOS-latest-cmake (push) Waiting to run
CI / windows-latest-cmake (cpu, -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_LIBS=ON -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON) (push) Waiting to run
CI / windows-latest-cmake (cuda12, -DSD_CUDA=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_ARCHITECTURES='61;70;75;80;86;89;90;100;120' -DCMAKE_CUDA_FL… (push) Waiting to run
CI / windows-latest-cmake (vulkan, -DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON) (push) Waiting to run
CI / windows-latest-rocm (push) Waiting to run
CI / ubuntu-latest-rocm (10.1.0, x64, gfx900;gfx906;gfx908;gfx90a;gfx90c;gfx942;gfx950;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201) (push) Waiting to run
CI / release (push) Blocked by required conditions
115 lines
3.9 KiB
C++
115 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <condition_variable>
|
|
#include <cstdint>
|
|
#include <deque>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
|
|
#include "model_catalog.h"
|
|
|
|
enum class AsyncJobKind {
|
|
ImgGen,
|
|
VidGen,
|
|
Dgl,
|
|
};
|
|
|
|
enum class AsyncJobStatus {
|
|
Queued,
|
|
Generating,
|
|
Completed,
|
|
Failed,
|
|
Cancelled,
|
|
};
|
|
|
|
const char* async_job_kind_name(AsyncJobKind kind);
|
|
const char* async_job_status_name(AsyncJobStatus status);
|
|
|
|
struct AsyncJobProgress {
|
|
std::string stage = "queued";
|
|
std::string detail;
|
|
std::string unit;
|
|
int sample_pass = 0;
|
|
int64_t completed = 0;
|
|
int64_t total = 0;
|
|
std::chrono::steady_clock::time_point stage_started = std::chrono::steady_clock::now();
|
|
std::chrono::steady_clock::time_point finished{};
|
|
};
|
|
|
|
struct AsyncGenerationJob {
|
|
std::string id;
|
|
AsyncJobKind kind = AsyncJobKind::ImgGen;
|
|
AsyncJobStatus status = AsyncJobStatus::Queued;
|
|
std::atomic<bool> cancel_requested{false};
|
|
int64_t created_at = unix_timestamp_now_ms();
|
|
int64_t started_at = 0;
|
|
int64_t completed_at = 0;
|
|
std::unique_ptr<ServerModelSelection> model;
|
|
json request_body;
|
|
uint64_t model_revision = 0;
|
|
ImgGenJobRequest img_gen;
|
|
VidGenJobRequest vid_gen;
|
|
std::string dgl_source;
|
|
json dgl_result_info;
|
|
std::vector<std::string> result_images_b64;
|
|
json result_generation_info;
|
|
std::string result_media_b64;
|
|
std::string result_media_mime_type;
|
|
int result_frame_count = 0;
|
|
int result_fps = 0;
|
|
std::string error_code;
|
|
std::string error_message;
|
|
mutable std::mutex progress_mutex;
|
|
AsyncJobProgress progress;
|
|
mutable std::mutex preview_mutex;
|
|
std::string preview_b64;
|
|
int preview_pass = 0;
|
|
int preview_step = 0;
|
|
int preview_total_steps = 0;
|
|
};
|
|
|
|
struct AsyncJobManager {
|
|
std::mutex mutex;
|
|
std::condition_variable cv;
|
|
std::unordered_map<std::string, std::shared_ptr<AsyncGenerationJob>> jobs;
|
|
std::unordered_map<std::string, int64_t> expired_jobs;
|
|
std::deque<std::string> queue;
|
|
uint64_t next_id = 0;
|
|
bool stop = false;
|
|
size_t max_pending_jobs = 64;
|
|
int64_t completed_ttl_seconds = 600;
|
|
int64_t failed_ttl_seconds = 600;
|
|
|
|
size_t synchronous_jobs = 0;
|
|
std::chrono::steady_clock::time_point staging_deadline = std::chrono::steady_clock::time_point::max();
|
|
std::chrono::steady_clock::time_point residency_deadline = std::chrono::steady_clock::time_point::max();
|
|
|
|
void record_context_job_completion(const SDSvrParams& params);
|
|
};
|
|
|
|
void purge_expired_jobs(AsyncJobManager& manager);
|
|
size_t count_pending_jobs(const AsyncJobManager& manager);
|
|
std::string make_async_job_id(AsyncJobManager& manager);
|
|
bool cancel_queued_job(AsyncJobManager& manager, AsyncGenerationJob& job);
|
|
json make_async_job_json(const AsyncJobManager& manager, const AsyncGenerationJob& job);
|
|
bool parse_native_job_request(const json& body, ServerRuntime& runtime, AsyncGenerationJob& job, std::string& error_message);
|
|
bool execute_img_gen_job(ServerRuntime& runtime,
|
|
AsyncGenerationJob& job,
|
|
std::vector<std::string>& output_images,
|
|
json& output_info,
|
|
std::string& error_message);
|
|
bool execute_vid_gen_job(ServerRuntime& runtime,
|
|
AsyncGenerationJob& job,
|
|
std::string& output_media_b64,
|
|
std::string& output_media_mime_type,
|
|
int& output_frame_count,
|
|
int& output_fps,
|
|
json& output_info,
|
|
std::string& error_message);
|
|
void async_job_worker(ServerRuntime& runtime);
|