Skip to content

Commit

Permalink
fix build and update abi interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberhan123 committed Nov 23, 2023
1 parent 1303869 commit 81b0240
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,22 @@ endif()
include(sd)
include_directories(${sd_SOURCE_DIR})

if (APPLE AND NOT GGML_NO_ACCELERATE)
find_library(ACCELERATE_FRAMEWORK Accelerate)
if (ACCELERATE_FRAMEWORK)
message(STATUS "Accelerate framework found")

set(SD_EXTRA_LIBS ${SD_EXTRA_LIBS} ${ACCELERATE_FRAMEWORK})
set(SD_EXTRA_LIBS ${SD_EXTRA_LIBS} -DGGML_USE_ACCELERATE)
else()
message(WARNING "Accelerate framework not found")
endif()
endif()

set(SD_ABI sd-abi)
set(SD_EXTRA_LIBS "")
add_library(${SD_ABI} SHARED stable-diffusion-abi.cpp stable-diffusion-abi.h)
set_target_properties(${SD_ABI} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(${SD_ABI} PRIVATE STABLE_DIFFUSION_SHARED STABLE_DIFFUSION_BUILD)
target_link_libraries(${SD_ABI} PRIVATE $<TARGET_OBJECTS:ggml> $<TARGET_OBJECTS:stable-diffusion> ${SD_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${SD_ABI} PUBLIC $<TARGET_OBJECTS:ggml> $<TARGET_OBJECTS:stable-diffusion> ${SD_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(${SD_ABI} PUBLIC .)

11 changes: 6 additions & 5 deletions stable-diffusion-abi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stable-diffusion-abi.h"

#include "stable-diffusion.h"
#include <string>
#include <cstring>
#include <map>
Expand Down Expand Up @@ -149,13 +150,13 @@ void set_img2img_seed(sd_img2img_options* opt, int64_t seed) {
opt->seed = seed;
}

void* create_stable_diffusion(int n_threads, bool vae_decode_only, bool free_params_immediately, const char* rng_type) {
void* create_stable_diffusion(int n_threads, bool vae_decode_only, bool free_params_immediately,const char* lora_model_dir, const char* rng_type) {
auto s = std::string(rng_type);
auto it = RNGTypeMap.find(s);
if (it != RNGTypeMap.end()) {
return new StableDiffusion(n_threads, vae_decode_only, free_params_immediately, it->second);
return new StableDiffusion(n_threads, vae_decode_only, free_params_immediately,std::string(lora_model_dir), it->second);
}
return NULL;
return nullptr;
};

void destroy_stable_diffusion(void* sd) {
Expand Down Expand Up @@ -192,7 +193,7 @@ uint8_t* txt2img(void* sd, sd_txt2img_options* opt, int64_t* output_size) {
delete opt;
return result.data();
}
return NULL;
return nullptr;
};

uint8_t* img2img(void* sd, sd_img2img_options* opt, int64_t* output_size) {
Expand All @@ -218,7 +219,7 @@ uint8_t* img2img(void* sd, sd_img2img_options* opt, int64_t* output_size) {
delete opt;
return result.data();
}
return NULL;
return nullptr;
};

void set_stable_diffusion_log_level(const char* level) {
Expand Down
6 changes: 3 additions & 3 deletions stable-diffusion-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <stdint.h>
#include <string.h>

#include "stable-diffusion.h"

#ifdef STABLE_DIFFUSION_SHARED
#if defined(_WIN32) && !defined(__MINGW32__)
#ifdef STABLE_DIFFUSION_BUILD
Expand Down Expand Up @@ -72,9 +70,11 @@ extern "C"
STABLE_DIFFUSION_API void set_img2img_seed(sd_img2img_options* opt, int64_t seed);
//================================================================================

STABLE_DIFFUSION_API void* create_stable_diffusion(int n_threads,
STABLE_DIFFUSION_API void* create_stable_diffusion(
int n_threads,
bool vae_decode_only,
bool free_params_immediately,
const char* lora_model_dir,
const char* rng_type);

STABLE_DIFFUSION_API void destroy_stable_diffusion(void* sd);
Expand Down

0 comments on commit 81b0240

Please sign in to comment.