Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit de53fce

Browse files
authored
Add doc cherry-pick (#631)
* Add doc (#623) * Refine load_paddle_model doc (#626) * refine doc and close LOG (#632)
1 parent fcde5e8 commit de53fce

32 files changed

+413
-168
lines changed

build.sh

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ function gpu_on {
4242
cudnn_config=ON
4343
}
4444

45+
function test_doc {
46+
mkdir -p $build_dir
47+
cd $build_dir
48+
export runtime_include_dir=$workspace/cinn/runtime/cuda
49+
50+
prepare_ci
51+
cmake_
52+
build
53+
make_doc
54+
}
55+
4556
function cudnn_off {
4657
cudnn_config=OFF
4758
}
@@ -94,36 +105,46 @@ function prepare_ci {
94105
pip install pre-commit
95106
pip install clang-format==9.0
96107
pip install wheel
97-
pip install sphinx==3.3.1 sphinx_gallery==0.8.1 recommonmark==0.6.0 exhale scipy breathe==4.24.0 matplotlib
108+
pip install sphinx==3.3.1 sphinx_gallery==0.8.1 recommonmark==0.6.0 exhale scipy breathe==4.24.0 matplotlib sphinx_rtd_theme
98109
pip install paddlepaddle-gpu==2.1.2.post101 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html
99110
}
100111

101-
function make_doc {
112+
function prepare_doc_model_file {
102113
proxy_off
103-
cd $workspace/tutorials
104-
if [[ -f "ResNet18.tar.gz" ]]; then
105-
echo "model file for tutorials already downloaded."
106-
elif [[ -f "$build_dir/thirds/ResNet18.tar.gz" ]]; then
107-
rm -rf $workspace/tutorials/ResNet18
108-
ln -s $build_dir/thirds/ResNet18 $workspace/tutorials/ResNet18
114+
local tar_file=$1
115+
if [[ -f "$tar_file.tar.gz" ]]; then
116+
echo "model file $tar_file.tar.gz for tutorials already downloaded."
117+
elif [[ -f "$build_dir/thirds/$tar_file.tar.gz" ]]; then
118+
rm -rf $workspace/tutorials/$tar_file
119+
ln -s $build_dir/thirds/$tar_file $workspace/tutorials/$tar_file
109120
else
110-
wget http://paddle-inference-dist.bj.bcebos.com/CINN/ResNet18.tar.gz
111-
tar -zxvf ResNet18.tar.gz
121+
wget https://paddle-inference-dist.bj.bcebos.com/CINN/$tar_file.tar.gz
122+
tar -zxvf $tar_file.tar.gz
112123
fi
124+
}
125+
126+
function make_doc {
127+
proxy_off
128+
cd $workspace/tutorials
129+
prepare_doc_model_file ResNet50
130+
prepare_doc_model_file MobileNetV2
131+
prepare_doc_model_file EfficientNet
132+
prepare_doc_model_file FaceDet
133+
113134
if [[ $cuda_config == "ON" && ! -d "./is_cuda" ]]; then
114135
mkdir is_cuda
115136
fi
116-
137+
if [[ $cuda_config == "OFF" && -d "./is_cuda" ]]; then
138+
rm -rf ./is_cuda
139+
fi
117140
cd $build_dir
118141
rm -f $workspace/python/cinn/core_api.so
119142
ln -s $build_dir/cinn/pybind/core_api.so $workspace/python/cinn/
120143
cd $workspace/docs
121144
mkdir -p docs/source/cpp
122-
cat $workspace/tutorials/matmul.cc | python${py_version} $workspace/tools/gen_c++_tutorial.py > $workspace/docs/source/matmul.md
145+
cat $workspace/tutorials/matmul.cc | python${py_version} $workspace/tools/gen_c++_tutorial.py > $workspace/docs/source/matmul.md
146+
cat $workspace/tutorials/load_paddle_model.cc | python${py_version} $workspace/tools/gen_c++_tutorial.py > $workspace/docs/source/load_paddle_model.md
123147
make html
124-
if [[ $cuda_config == "ON" && -d "./is_cuda" ]]; then
125-
rm -rf $workspace/tutorials/is_cuda
126-
fi
127148
}
128149

129150
function cmake_ {
@@ -308,6 +329,10 @@ function main {
308329
run_test
309330
shift
310331
;;
332+
test_doc)
333+
test_doc
334+
shift
335+
;;
311336
ci)
312337
CI
313338
shift
@@ -320,10 +345,6 @@ function main {
320345
prepare_model
321346
shift
322347
;;
323-
make_doc)
324-
make_doc
325-
shift
326-
;;
327348
esac
328349
done
329350
}

cinn/backends/codegen_cuda_dev_test.cc

100644100755
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ TEST(CodeGenCUDA, basic) {
8989

9090
CodeGenCUDA_Dev codegen(target);
9191

92-
auto func = Lower("elementwise_add", stages, {A, B, C});
92+
auto func = Lower("elementwise_mul", stages, {A, B, C});
9393

9494
auto compiled = codegen.Compile(func);
9595

@@ -115,7 +115,7 @@ TEST(CodeGenCUDA, Module_output) {
115115

116116
CodeGenCUDA_Dev codegen(target);
117117

118-
auto func = Lower("elementwise_add", stages, {A, B, C});
118+
auto func = Lower("elementwise_mul", stages, {A, B, C});
119119

120120
Module::Builder builder("module", target);
121121
builder.AddFunction(func);
@@ -149,7 +149,7 @@ TEST(CodeGenCUDA2, test_of_cacheread) {
149149
stages[B_cache]->ComputeAt(stages[C], 1);
150150
CodeGenCUDA_Dev codegen(target);
151151

152-
auto func = Lower("elementwise_add", stages, {A, B, C});
152+
auto func = Lower("elementwise_mul", stages, {A, B, C});
153153

154154
Module::Builder builder("module", target);
155155
builder.AddFunction(func);
@@ -181,7 +181,7 @@ TEST(CodeGenCUDA2, test_of_cacheread) {
181181

182182
dim3 grid(10, 1, 1);
183183
dim3 block(10, 1, 1);
184-
cuda_module.LaunchKernel(0, "elementwise_add", grid, block, args);
184+
cuda_module.LaunchKernel(0, "elementwise_mul", grid, block, args);
185185

186186
CUDA_CALL(cudaMemcpy(host_data3.data(),
187187
reinterpret_cast<void*>(Cd),
@@ -221,7 +221,7 @@ TEST(CodeGenCUDA2, test_of_splitcudakernel) {
221221

222222
CodeGenCUDA_Dev codegen(target);
223223

224-
auto func = lang::LowerVec("elementwise_add", stages, {A, B, C, D}, {}, {}, nullptr, target);
224+
auto func = lang::LowerVec("elementwise_mul_and_add", stages, {A, B, C, D}, {}, {}, nullptr, target);
225225

226226
Module::Builder builder("module", target);
227227
for (auto& i : func) {
@@ -251,15 +251,15 @@ typedef char int8_t;
251251
252252
253253
__global__
254-
void __launch_bounds__(200) elementwise_add(const float* __restrict__ X, const float* __restrict__ Y, float* __restrict__ C)
254+
void __launch_bounds__(200) elementwise_mul_and_add(const float* __restrict__ X, const float* __restrict__ Y, float* __restrict__ C)
255255
{
256256
if (((int)blockIdx.x < 100)) {
257257
if (((int)threadIdx.x < 200)) {
258258
C[((200 * (int)blockIdx.x) + (int)threadIdx.x)] = (X[((200 * (int)blockIdx.x) + (int)threadIdx.x)] * Y[((200 * (int)blockIdx.x) + (int)threadIdx.x)]);
259259
};
260260
};
261261
}__global__
262-
void __launch_bounds__(200) elementwise_add_1(const float* __restrict__ X, const float* __restrict__ Y, const float* __restrict__ C, float* __restrict__ D)
262+
void __launch_bounds__(200) elementwise_mul_and_add_1(const float* __restrict__ X, const float* __restrict__ Y, const float* __restrict__ C, float* __restrict__ D)
263263
{
264264
if (((int)blockIdx.x < 100)) {
265265
if (((int)threadIdx.x < 200)) {

cinn/backends/compiler.cc

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ void Compiler::CompileCudaModule(const Module& module, const std::string& code,
7070
auto _host_module_device_module_ = SplitCudaAndHostModule(module); // NOLINT
7171
auto& host_module = std::get<0>(_host_module_device_module_);
7272
auto& device_module = std::get<1>(_host_module_device_module_);
73-
LOG(INFO) << "[CUDA] host module:\n" << host_module;
73+
VLOG(3) << "[CUDA] host module:\n" << host_module;
7474

7575
{ // compile cuda device
76-
LOG(INFO) << "[CUDA] device module:\n" << device_module;
76+
VLOG(3) << "[CUDA] device module:\n" << device_module;
7777
CodeGenCUDA_Dev codegen(target_);
7878
auto source_code = codegen.Compile(device_module);
7979
if (!code.empty()) source_code = code;
80-
LOG(INFO) << "[CUDA] source code:\n" << source_code;
80+
VLOG(3) << "[CUDA] source code:\n" << source_code;
8181
using runtime::cuda::CUDAModule;
8282

8383
backends::NVRTC_Compiler compiler;

cinn/backends/llvm/execution_engine.cc

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ std::unique_ptr<llvm::MemoryBuffer> NaiveObjectCache::getObject(const llvm::Modu
9898
return nullptr;
9999
}
100100

101-
LOG(INFO) << "Object for " << m->getModuleIdentifier() << " loaded from cache.";
101+
VLOG(3) << "Object for " << m->getModuleIdentifier() << " loaded from cache.";
102102
return llvm::MemoryBuffer::getMemBuffer(it->second->getMemBufferRef());
103103
}
104104

@@ -178,25 +178,25 @@ void ExecutionEngine::Link(const ir::Module &module) {
178178

179179
decltype(auto) es = jit_->getExecutionSession();
180180
if (false) {
181-
LOG(INFO) << "======= dump jit execution session ======";
181+
VLOG(3) << "======= dump jit execution session ======";
182182
std::string buffer;
183183
llvm::raw_string_ostream os(buffer);
184184
es.dump(os);
185185
os.flush();
186-
LOG(INFO) << buffer;
186+
VLOG(3) << buffer;
187187
}
188188
}
189189

190190
bool ExecutionEngine::AddModule(std::unique_ptr<llvm::Module> module, std::unique_ptr<llvm::LLVMContext> context) {
191191
module->setDataLayout(jit_->getDataLayout());
192192
if (false) {
193-
LOG(INFO) << "======= dump jit lib ==========";
193+
VLOG(3) << "======= dump jit lib ==========";
194194
std::string buffer;
195195
llvm::raw_string_ostream os(buffer);
196196
module->print(os, {});
197197
// main_jd_->dump(os);
198198
os.flush();
199-
LOG(INFO) << buffer;
199+
VLOG(3) << buffer;
200200
}
201201
llvm::orc::ThreadSafeContext tsc(std::move(context));
202202
llvm::orc::ThreadSafeModule tsm(std::move(module), std::move(tsc));

cinn/backends/llvm/simple_jit.cc

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ void SimpleJIT::AddModule(std::unique_ptr<llvm::Module> module, bool optimize) {
7171
module_pass_manager.run(*module, module_analysis_manager);
7272
}
7373

74-
LOG(INFO) << "jit target: " << jit_->getDataLayout().getStringRepresentation();
75-
LOG(INFO) << "module target: " << module->getDataLayout().getStringRepresentation();
74+
VLOG(3) << "jit target: " << jit_->getDataLayout().getStringRepresentation();
75+
VLOG(3) << "module target: " << module->getDataLayout().getStringRepresentation();
7676

7777
llvm::orc::ThreadSafeModule tsm(std::move(module), context_);
7878
llvm::cantFail(jit_->addIRModule(std::move(tsm)));
@@ -82,7 +82,7 @@ void SimpleJIT::AddModule(std::unique_ptr<llvm::Module> module, bool optimize) {
8282
llvm::raw_string_ostream os(buffer);
8383
jit_->getExecutionSession().dump(os);
8484
os.flush();
85-
LOG(INFO) << "compiled jit:\n" << buffer;
85+
VLOG(3) << "compiled jit:\n" << buffer;
8686
}
8787
}
8888

cinn/backends/llvm/simple_jit.h

100644100755
File mode changed.

cinn/backends/nvrtc_util.cc

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ std::string NVRTC_Compiler::CompilePTX(const std::string& code, bool include_hea
9191
for (const auto& option : compile_options) {
9292
param_cstrings.push_back(option.c_str());
9393
}
94-
LOG(INFO) << "compile options: " << utils::Join(compile_options, " ");
94+
VLOG(3) << "compile options: " << utils::Join(compile_options, " ");
9595
NVRTC_CALL(nvrtcCreateProgram(&prog, code.c_str(), nullptr, 0, nullptr, nullptr));
9696
nvrtcResult compile_res = nvrtcCompileProgram(prog, param_cstrings.size(), param_cstrings.data());
9797

cinn/common/cas.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,8 +2005,8 @@ Expr CasSimplifyMutator::FurtherSimplifyFracWithInterval(
20052005
auto it = var_intervals.find(bv->name);
20062006
auto ai_abs = std::abs(ai->value);
20072007
if (it != var_intervals.end()) {
2008-
LOG(INFO) << "found " << bv->name << " " << it->second << " "
2009-
<< " ai " << ai_abs;
2008+
VLOG(3) << "found " << bv->name << " " << it->second << " "
2009+
<< " ai " << ai_abs;
20102010
}
20112011
if (it != var_intervals.end() && std::abs(it->second.r) > ai_abs && std::abs(it->second.l) > ai_abs) {
20122012
return make_const(a.type(), 0);

cinn/common/ir_util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Expr RampRelatedMul(Expr a, Expr b) {
125125
CHECK_EQ(a_broadcast->lanes, b_broadcast->lanes);
126126
return ir::Broadcast::Make(a_broadcast->value * b_broadcast->value, a_broadcast->lanes);
127127
} else {
128-
LOG(INFO) << "a,b: " << a << " " << b;
128+
VLOG(3) << "a,b: " << a << " " << b;
129129
CINN_NOT_IMPLEMENTED
130130
}
131131
}

cinn/frontend/computation.cc

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ std::shared_ptr<CinnComputation> CinnComputation::CompilePaddleModel(
127127
}
128128
program->SetInputs({input_vars});
129129
program->Validate();
130-
LOG(INFO) << "program:\n" << *program;
130+
VLOG(3) << "program:\n" << *program;
131131

132132
for (auto &name : fetch_names) {
133133
output_vars.push_back(varmap.at(name));

0 commit comments

Comments
 (0)