Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ file(GLOB SD_LIB_SOURCES CONFIGURE_DEPENDS
"src/*.h"
"src/*.cpp"
"src/*.hpp"
"src/conditioning/*.h"
"src/conditioning/*.cpp"
"src/conditioning/*.hpp"
"src/core/*.h"
"src/core/*.cpp"
"src/core/*.hpp"
"src/model/*/*.h"
"src/model/*/*.cpp"
"src/model/*/*.hpp"
"src/runtime/*.h"
"src/runtime/*.cpp"
"src/runtime/*.hpp"
"src/runtime/*.inl"
"src/model_io/*.h"
"src/model_io/*.cpp"
"src/tokenizers/*.h"
Expand Down Expand Up @@ -312,6 +325,7 @@ add_subdirectory(thirdparty)

target_link_libraries(${SD_LIB} PUBLIC ggml zip)
target_include_directories(${SD_LIB} PUBLIC . src include)
target_include_directories(${SD_LIB} PRIVATE src/core)
target_include_directories(${SD_LIB} PUBLIC . thirdparty)
target_compile_features(${SD_LIB} PUBLIC c_std_11 cxx_std_17)

Expand Down
10 changes: 8 additions & 2 deletions format-code.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
for f in src/*.cpp src/*.h src/*.hpp src/tokenizers/*.h src/tokenizers/*.cpp src/tokenizers/vocab/*.h src/tokenizers/vocab/*.cpp \
for f in src/*.cpp src/*.h src/*.hpp \
src/conditioning/*.cpp src/conditioning/*.h src/conditioning/*.hpp \
src/core/*.cpp src/core/*.h src/core/*.hpp \
src/runtime/*.cpp src/runtime/*.h src/runtime/*.hpp \
src/model/*/*.cpp src/model/*/*.h src/model/*/*.hpp \
src/tokenizers/*.h src/tokenizers/*.cpp src/tokenizers/vocab/*.h src/tokenizers/vocab/*.cpp \
src/model_io/*.h src/model_io/*.cpp examples/cli/*.cpp examples/cli/*.h examples/server/*.cpp \
examples/common/*.hpp examples/common/*.h examples/common/*.cpp; do
[[ -e "$f" ]] || continue
[[ "$f" == vocab* ]] && continue
echo "formatting '$f'"
# if [ "$f" != "stable-diffusion.h" ]; then
# clang-tidy -fix -p build_linux/ "$f"
# fi
clang-format -style=file -i "$f"
done
done
14 changes: 7 additions & 7 deletions src/conditioner.hpp → src/conditioning/conditioner.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef __CONDITIONER_HPP__
#define __CONDITIONER_HPP__
#ifndef __SD_CONDITIONING_CONDITIONER_HPP__
#define __SD_CONDITIONING_CONDITIONER_HPP__

#include <cmath>
#include <limits>
#include <optional>

#include "clip.hpp"
#include "llm.hpp"
#include "t5.hpp"
#include "tensor_ggml.hpp"
#include "core/tensor_ggml.hpp"
#include "model/te/clip.hpp"
#include "model/te/llm.hpp"
#include "model/te/t5.hpp"

struct SDCondition {
sd::Tensor<float> c_crossattn;
Expand Down Expand Up @@ -2554,4 +2554,4 @@ struct LTXAVEmbedder : public Conditioner {
}
};

#endif
#endif // __SD_CONDITIONING_CONDITIONER_HPP__
20 changes: 10 additions & 10 deletions src/ggml_extend.hpp → src/core/ggml_extend.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __GGML_EXTEND_HPP__
#define __GGML_EXTEND_HPP__
#ifndef __SD_CORE_GGML_EXTEND_HPP__
#define __SD_CORE_GGML_EXTEND_HPP__

#include <assert.h>
#include <inttypes.h>
Expand All @@ -23,19 +23,19 @@
#include <unordered_map>
#include <vector>

#include "core/ggml_extend_backend.h"
#include "core/ggml_graph_cut.h"
#include "core/layer_registry.h"
#include "ggml-alloc.h"
#include "ggml-backend.h"
#include "ggml.h"
#include "ggml_extend_backend.h"
#include "ggml_graph_cut.h"
#include "layer_registry.h"

#include "core/tensor.hpp"
#include "model.h"
#include "tensor.hpp"

#include "rng.hpp"
#include "tensor_ggml.hpp"
#include "util.h"
#include "core/rng.hpp"
#include "core/tensor_ggml.hpp"
#include "core/util.h"

#define EPS 1e-05f

Expand Down Expand Up @@ -4145,4 +4145,4 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_lokr_forward(
}
}

#endif // __GGML_EXTEND__HPP__
#endif // __SD_CORE_GGML_EXTEND_HPP__
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ggml_extend_backend.h"
#include "core/ggml_extend_backend.h"

#include <algorithm>
#include <cctype>
Expand All @@ -8,8 +8,8 @@
#include <stdexcept>
#include <vector>

#include "core/util.h"
#include "stable-diffusion.h"
#include "util.h"

static std::string trim_copy(const std::string& value) {
size_t begin = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/ggml_extend_backend.h → src/core/ggml_extend_backend.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __SD_GGML_EXTEND_BACKEND_H__
#define __SD_GGML_EXTEND_BACKEND_H__
#ifndef __SD_CORE_GGML_EXTEND_BACKEND_H__
#define __SD_CORE_GGML_EXTEND_BACKEND_H__

#include <cstdint>
#include <cstring>
Expand Down Expand Up @@ -76,4 +76,4 @@ ggml_backend_t sd_backend_cpu_init();
bool sd_backend_cpu_set_n_threads(ggml_backend_t backend_cpu, int n_threads);
const char* sd_backend_module_name(SDBackendModule module);
void ggml_ext_im_set_f32_1d(const struct ggml_tensor* tensor, int i, float value);
#endif
#endif // __SD_CORE_GGML_EXTEND_BACKEND_H__
6 changes: 3 additions & 3 deletions src/ggml_graph_cut.cpp → src/core/ggml_graph_cut.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ggml_graph_cut.h"
#include "core/ggml_graph_cut.h"

#include <algorithm>
#include <cstring>
Expand All @@ -8,11 +8,11 @@
#include <stack>
#include <unordered_map>

#include "core/util.h"
#include "ggml-alloc.h"
#include "ggml-backend.h"
#include "util.h"

#include "../ggml/src/ggml-impl.h"
#include "ggml/src/ggml-impl.h"

namespace sd::ggml_graph_cut {

Expand Down
6 changes: 3 additions & 3 deletions src/ggml_graph_cut.h → src/core/ggml_graph_cut.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __SD_GGML_GRAPH_CUT_H__
#define __SD_GGML_GRAPH_CUT_H__
#ifndef __SD_CORE_GGML_GRAPH_CUT_H__
#define __SD_CORE_GGML_GRAPH_CUT_H__

#include <array>
#include <cstdint>
Expand Down Expand Up @@ -114,4 +114,4 @@ namespace sd::ggml_graph_cut {
void annotate_residency(Plan& plan, size_t max_graph_vram_bytes);
} // namespace sd::ggml_graph_cut

#endif
#endif // __SD_CORE_GGML_GRAPH_CUT_H__
4 changes: 2 additions & 2 deletions src/layer_registry.cpp → src/core/layer_registry.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "layer_registry.h"
#include "core/layer_registry.h"

#include <utility>

#include "util.h"
#include "core/util.h"

namespace sd::layer_registry {

Expand Down
6 changes: 3 additions & 3 deletions src/layer_registry.h → src/core/layer_registry.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __LAYER_REGISTRY_H__
#define __LAYER_REGISTRY_H__
#ifndef __SD_CORE_LAYER_REGISTRY_H__
#define __SD_CORE_LAYER_REGISTRY_H__

#include <map>
#include <set>
Expand Down Expand Up @@ -47,4 +47,4 @@ namespace sd::layer_registry {

} // namespace sd::layer_registry

#endif
#endif // __SD_CORE_LAYER_REGISTRY_H__
6 changes: 3 additions & 3 deletions src/ordered_map.hpp → src/core/ordered_map.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __ORDERED_MAP_HPP__
#define __ORDERED_MAP_HPP__
#ifndef __SD_CORE_ORDERED_MAP_HPP__
#define __SD_CORE_ORDERED_MAP_HPP__

#include <iostream>
#include <list>
Expand Down Expand Up @@ -174,4 +174,4 @@ class OrderedMap {
}
};

#endif // __ORDERED_MAP_HPP__
#endif // __SD_CORE_ORDERED_MAP_HPP__
6 changes: 3 additions & 3 deletions src/rng.hpp → src/core/rng.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __RNG_H__
#define __RNG_H__
#ifndef __SD_CORE_RNG_HPP__
#define __SD_CORE_RNG_HPP__

#include <random>
#include <vector>
Expand Down Expand Up @@ -32,4 +32,4 @@ class STDDefaultRNG : public RNG {
}
};

#endif // __RNG_H__
#endif // __SD_CORE_RNG_HPP__
8 changes: 4 additions & 4 deletions src/rng_mt19937.hpp → src/core/rng_mt19937.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef __RNG_MT19937_HPP__
#define __RNG_MT19937_HPP__
#ifndef __SD_CORE_RNG_MT19937_HPP__
#define __SD_CORE_RNG_MT19937_HPP__

#include <cmath>
#include <vector>

#include "rng.hpp"
#include "core/rng.hpp"

// RNG imitiating torch cpu randn on CPU.
// Port from pytorch, original license: https://github.com/pytorch/pytorch/blob/d01a7b0241ed1c4cded7e7ca097249feb343f072/LICENSE
Expand Down Expand Up @@ -144,4 +144,4 @@ class MT19937RNG : public RNG {
}
};

#endif // __RNG_MT19937_HPP__
#endif // __SD_CORE_RNG_MT19937_HPP__
8 changes: 4 additions & 4 deletions src/rng_philox.hpp → src/core/rng_philox.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef __RNG_PHILOX_H__
#define __RNG_PHILOX_H__
#ifndef __SD_CORE_RNG_PHILOX_HPP__
#define __SD_CORE_RNG_PHILOX_HPP__

#include <cmath>
#include <vector>

#include "rng.hpp"
#include "core/rng.hpp"

// RNG imitiating torch cuda randn on CPU.
// Port from: https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/5ef669de080814067961f28357256e8fe27544f4/modules/rng_philox.py
Expand Down Expand Up @@ -122,4 +122,4 @@ class PhiloxRNG : public RNG {
}
};

#endif // __RNG_PHILOX_H__
#endif // __SD_CORE_RNG_PHILOX_HPP__
8 changes: 4 additions & 4 deletions src/tensor.hpp → src/core/tensor.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __SD_TENSOR_HPP__
#define __SD_TENSOR_HPP__
#ifndef __SD_CORE_TENSOR_HPP__
#define __SD_CORE_TENSOR_HPP__

#include <algorithm>
#include <cmath>
Expand All @@ -16,7 +16,7 @@
#include <utility>
#include <vector>

#include "rng.hpp"
#include "core/rng.hpp"

namespace sd {

Expand Down Expand Up @@ -1661,4 +1661,4 @@ namespace sd {

} // namespace sd

#endif
#endif // __SD_CORE_TENSOR_HPP__
8 changes: 4 additions & 4 deletions src/tensor_ggml.hpp → src/core/tensor_ggml.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __SD_TENSOR_GGML_HPP__
#define __SD_TENSOR_GGML_HPP__
#ifndef __SD_CORE_TENSOR_GGML_HPP__
#define __SD_CORE_TENSOR_GGML_HPP__

#include <array>
#include <cstring>
Expand All @@ -8,8 +8,8 @@
#include <string>
#include <type_traits>

#include "core/tensor.hpp"
#include "ggml.h"
#include "tensor.hpp"

namespace sd {

Expand Down Expand Up @@ -124,4 +124,4 @@ namespace sd {

} // namespace sd

#endif
#endif // __SD_CORE_TENSOR_GGML_HPP__
4 changes: 2 additions & 2 deletions src/util.cpp → src/core/util.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "util.h"
#include "core/util.h"
#include <algorithm>
#include <cctype>
#include <cmath>
Expand All @@ -13,7 +13,7 @@
#include <thread>
#include <unordered_set>
#include <vector>
#include "preprocessing.hpp"
#include "runtime/preprocessing.hpp"

#if defined(__APPLE__) && defined(__MACH__)
#include <sys/sysctl.h>
Expand Down
8 changes: 4 additions & 4 deletions src/util.h → src/core/util.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef __UTIL_H__
#define __UTIL_H__
#ifndef __SD_CORE_UTIL_H__
#define __SD_CORE_UTIL_H__

#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "core/tensor.hpp"
#include "ggml-backend.h"
#include "stable-diffusion.h"
#include "tensor.hpp"

#define SAFE_STR(s) ((s) ? (s) : "")
#define BOOL_STR(b) ((b) ? "true" : "false")
Expand Down Expand Up @@ -103,4 +103,4 @@ bool sd_backend_is(ggml_backend_t backend, const std::string& name);
#define LOG_INFO(format, ...) log_printf(SD_LOG_INFO, __FILE__, __LINE__, format, ##__VA_ARGS__)
#define LOG_WARN(format, ...) log_printf(SD_LOG_WARN, __FILE__, __LINE__, format, ##__VA_ARGS__)
#define LOG_ERROR(format, ...) log_printf(SD_LOG_ERROR, __FILE__, __LINE__, format, ##__VA_ARGS__)
#endif // __UTIL_H__
#endif // __SD_CORE_UTIL_H__
4 changes: 2 additions & 2 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
#include <unordered_map>
#include <vector>

#include "core/util.h"
#include "model.h"
#include "model_io/gguf_io.h"
#include "model_io/safetensors_io.h"
#include "model_io/torch_legacy_io.h"
#include "model_io/torch_zip_io.h"
#include "stable-diffusion.h"
#include "util.h"

#include "core/ggml_extend_backend.h"
#include "ggml-alloc.h"
#include "ggml-backend.h"
#include "ggml.h"
#include "ggml_extend_backend.h"
#include "zip.h"

#include "name_conversion.h"
Expand Down
Loading
Loading