Skip to content

Commit

Permalink
[feat:init] first version of stable diffusion.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhaode committed Nov 17, 2022
0 parents commit 143e001
Show file tree
Hide file tree
Showing 44 changed files with 28,641 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0)
project(stable-diffusion-mnn)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# include dir
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/)

# libs dir
link_directories(${CMAKE_CURRENT_LIST_DIR}/libs)

# source files
FILE(GLOB SRCS ${CMAKE_CURRENT_LIST_DIR}/src/*)

# target
add_executable(main ${SRCS})

target_link_libraries(main MNN MNN_Express MNNOpenCV)
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Stable Diffusion MNN

## Usage

### 1. Compile MNN library
```bash
git clone https://github.com/alibaba/MNN.git
cd MNN
mkdir build
cmake -DMNN_BUILD_OPENCV=ON MNN_IMGCODECS=ON ..
make -j8
cp libMNN.so express/libMNN_Express.so tools/cv/libMNNOpenCV.so /path/to/stable-diffusion-mnn/libs
```

### 2. Build and Run
```bash
mkdir build
cd build
cmake ..
make -j4
./main "飞流直下三千尺,油画" f.jpg
```

# Ref
https://huggingface.co/IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1
62 changes: 62 additions & 0 deletions include/MNN/AutoTime.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// AutoTime.hpp
// MNN
//
// Created by MNN on 2018/07/27.
// Copyright © 2018, Alibaba Group Holding Limited
//

#ifndef MNN_AutoTime_hpp
#define MNN_AutoTime_hpp

#include <stdint.h>
#include <stdio.h>
#include <MNN/MNNDefine.h>

namespace MNN {

class MNN_PUBLIC Timer {
public:
Timer();
~Timer();
Timer(const Timer&) = delete;
Timer(const Timer&&) = delete;
Timer& operator=(const Timer&) = delete;
Timer& operator=(const Timer&&) = delete;

// reset timer
void reset();
// get duration (us) from init or latest reset.
uint64_t durationInUs();

// Get Current Time
uint64_t current() const {
return mLastResetTime;
}
protected:
uint64_t mLastResetTime;
};

/** time tracing util. prints duration between init and deinit. */
class MNN_PUBLIC AutoTime : Timer {
public:
AutoTime(int line, const char* func);
~AutoTime();
AutoTime(const AutoTime&) = delete;
AutoTime(const AutoTime&&) = delete;
AutoTime& operator=(const AutoTime&) = delete;
AutoTime& operator=(const AutoTime&&) = delete;

private:
int mLine;
char* mName;
};
} // namespace MNN

#ifdef MNN_OPEN_TIME_TRACE
#define AUTOTIME MNN::AutoTime ___t(__LINE__, __func__)
#else
#define AUTOTIME
#endif

#endif /* AutoTime_hpp */
34 changes: 34 additions & 0 deletions include/MNN/ErrorCode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ErrorCode.hpp
// MNN
//
// Created by MNN on 2018/09/18.
// Copyright © 2018, Alibaba Group Holding Limited
//

#ifndef MNN_ErrorCode_h
#define MNN_ErrorCode_h

namespace MNN {
enum ErrorCode {
#ifdef NO_ERROR
#undef NO_ERROR
#endif // NO_ERROR
NO_ERROR = 0,
OUT_OF_MEMORY = 1,
NOT_SUPPORT = 2,
COMPUTE_SIZE_ERROR = 3,
NO_EXECUTION = 4,
INVALID_VALUE = 5,

// User error
INPUT_DATA_ERROR = 10,
CALL_BACK_STOP = 11,

// Op Resize Error
TENSOR_NOT_SUPPORT = 20,
TENSOR_NEED_DIVIDE = 21,
};
} // namespace MNN

#endif /* ErrorCode_h */
Loading

0 comments on commit 143e001

Please sign in to comment.