perf: parallelize host tensor elementwise and broadcast ops (#1998)

This commit is contained in:
leejet authored and GitHub committed 2026-09-19 21:46:16 +08:00
1 parent 275ab58e01
commit 17860c0e45
10 files changed
+361 -95

No files matched your search

+4 -2
View File
@@ -863,8 +863,10 @@ bool StableDiffusionGGML::init(const sd_ctx_params_t* sd_ctx_params) {
return false;
}
}
auto configuration = std::make_unique<ModelConfig>(*sd_ctx_params);
n_threads = sd_ctx_params->n_threads;
auto configuration = std::make_unique<ModelConfig>(*sd_ctx_params);
n_threads = sd_ctx_params->n_threads;
tensor_executor = std::make_unique<sd::ParallelExecutor>(n_threads > 0 ? n_threads : sd_get_num_physical_cores());
sd::ParallelScope tensor_scope(tensor_executor.get());
enable_mmap = sd_ctx_params->enable_mmap;
disable_prefetch = sd_ctx_params->disable_prefetch;
disable_segmented_compute = sd_ctx_params->disable_segmented_compute;
+6 -2
View File
@@ -8,6 +8,7 @@
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <set>
#include <string>
#include <vector>
@@ -56,8 +57,9 @@ public:
std::shared_ptr<RNG> rng;
std::shared_ptr<RNG> sampler_rng = nullptr;
int n_threads = -1;
float default_flow_shift = INFINITY;
float active_flow_shift = INFINITY;
std::unique_ptr<sd::ParallelExecutor> tensor_executor;
float default_flow_shift = INFINITY;
float active_flow_shift = INFINITY;
std::shared_ptr<Conditioner> cond_stage_model;
std::shared_ptr<FrozenCLIPVisionEmbedder> clip_vision; // for svd or wan2.1 i2v
@@ -206,6 +208,7 @@ public:
StableDiffusionGGML& sd;
std::unique_lock<std::recursive_mutex> lock;
bool acquired = false;
std::optional<sd::ParallelScope> tensor_scope;
explicit ContextOperation(StableDiffusionGGML& sd)
: sd(sd), lock(sd.execution_mutex, std::try_to_lock) {
@@ -215,6 +218,7 @@ public:
}
sd.executing_ = true;
acquired = true;
tensor_scope.emplace(sd.tensor_executor.get());
}
~ContextOperation() {