提交 72f97cae 编写于 作者: S silingtong123 提交者: GitHub

add the document of compileing lite on windows (#3471)

* test=develop, support WITH_TESTING=ON on windows

test=develop, modify the path of test_file in build_windows.bat

test=develop, modify the docment of windows compilation

test=develop, modify the document

* test=develop, modify the build_windows.bat
上级 2cc5baed
# PaddleLite使用X86预测部署
## 一、Docker或者Linux环境
Paddle-Lite 支持在Docker或Linux环境编译x86预测库。环境搭建参考[环境准备](../user_guides/source_compile)
## 编译
(注意:非docker Linux环境需要是Ubuntu16.04)
### 编译
1、 下载代码
```bash
......@@ -22,7 +26,7 @@ cd Paddle-Lite
# --with_log=OFF 关闭LOG信息输出
```
## 编译结果说明
### 编译结果说明
x86编译结果位于 `build.lite.x86/inference_lite_lib`
**具体内容**说明:
......@@ -52,7 +56,7 @@ x86编译结果位于 `build.lite.x86/inference_lite_lib`
## x86预测API使用示例
### x86预测API使用示例
1、`mobilenetv1_full`目录结构
......@@ -156,3 +160,83 @@ int main(int argc, char** argv) {
}
```
## 二、Windows环境
### 环境准备
#### 编译环境需求
- Windows 10 专业版
- 目前Windows暂不支持GPU模式
- *Python 版本 2.7/3.5.1+/3.6/3.7 (64 bit)*
- *pip 或 pip3 版本 9.0.1+ (64 bit)*
- *Visual Studio 2015 Update3*
#### 安装步骤
1. cmake 需要3.15版本, 可在官网[下载](https://cmake.org/download/),并添加到环境变量中。
2. python 需要2.7 及以上版本, 可在官网[下载](https://www.python.org/download/releases/2.7/)
3. git可以在官网[下载](https://gitforwindows.org/),并添加到环境变量中
### 编译
1、 下载代码
```bash
git clone https://github.com/PaddlePaddle/Paddle-Lite.git
# 切换到release分支
git checkout release/v2.3
```
2、 源码编译
```bash
cd Paddle-Lite
lite/tools/build_windows.bat with_extra with_python with_profile
```
编译脚本`lite/tools/build.bat`,追加参数说明:
| 参数 | 介绍 | 值 |
|-----------|-------------|-------------|
| with_extra | 可选,是否编译全量预测库(默认为OFF)。详情可参考[预测库说明](./library.html)。 | `ON``OFF` |
| with_python | 可选,是否编译python预测库(默认为OFF) 。 | `ON``OFF` |
| with_profile | 可选,是否支持分析器模式(默认为OFF) 。 | `ON``OFF` |
### 编译结果
x86编译结果位于 `build.lite.x86/inference_lite_lib`
**具体内容**说明:
1、 `bin`文件夹:可执行工具文件 `test_model_bin`
2、 `cxx`文件夹:包含c++的库文件与相应的头文件
- `include` : 头文件
- `lib` : 库文件
- 打包的静态库文件:
- `libpaddle_api_full_bundled.lib` :full_api 静态库
- `libpaddle_api_light_bundled.lib` :light_api 静态库
3、 `third_party` 文件夹:第三方库文件
### x86预测API使用示例
1、我们提供Windows环境下x86 API运行mobilenet_v1的示例:[mobilenet_full_x86demo](https://paddlelite-data.bj.bcebos.com/x86/mobilenet_full_x86demo.zip)。下载解压后内容如下>:
![](https://paddlelite-data.bj.bcebos.com/x86/x86-doc/demo.png)
`mobilenet_v1`为模型文件、`lib``include`分别是Paddle-Lite的预测库和头文件、`third_party`下是编译时依赖的第三方库`mklml``mobilenet_full_api.cc`是x86示例的源代码、`build.bat`为编译的脚本。
2、demo内容与使用方法
``` bash
# 1、编译(需在vs2015的命令窗口执行该脚本)
build.bat
```
编译结果为当前目录下的 `Release\\mobilenet_full_api.exe`
``` bash
# 2、执行预测
Release\\mobilenet_full_api.exe ..\mobilenet_v1
```
`mobilenet_v1`为模型路径,`mobilenet_full_api.exe`为第一步编译出的可执行文件。
......@@ -206,6 +206,7 @@ if (LITE_WITH_X86)
add_custom_target(publish_inference_x86_cxx_lib ${TARGET}
COMMAND ${CMAKE_COMMAND} -E make_directory "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
COMMAND ${CMAKE_COMMAND} -E make_directory "${INFER_LITE_PUBLISH_ROOT}/bin"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lite/api//${CMAKE_BUILD_TYPE}/test_model_bin.exe" "${INFER_LITE_PUBLISH_ROOT}/bin"
COMMAND ${CMAKE_COMMAND} -E make_directory "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/lite/api/paddle_api.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/lite/api/paddle_place.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
......@@ -216,7 +217,8 @@ if (LITE_WITH_X86)
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lite/api/${CMAKE_BUILD_TYPE}/libpaddle_api_full_bundled.lib" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lite/api/${CMAKE_BUILD_TYPE}/libpaddle_api_light_bundled.lib" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
)
add_dependencies(publish_inference_x86_cxx_lib test_model_bin)
add_dependencies(publish_inference_x86_cxx_lib bundle_full_api)
add_dependencies(publish_inference_x86_cxx_lib bundle_light_api)
add_dependencies(publish_inference publish_inference_x86_cxx_lib)
......@@ -226,6 +228,7 @@ if (LITE_WITH_X86)
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_BINARY_DIR}/third_party/install" "${INFER_LITE_PUBLISH_ROOT}/third_party"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_BINARY_DIR}/third_party/eigen3" "${INFER_LITE_PUBLISH_ROOT}/third_party"
COMMAND ${CMAKE_COMMAND} -E make_directory "${INFER_LITE_PUBLISH_ROOT}/demo/cxx"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/lite/demo/cxx" "${INFER_LITE_PUBLISH_ROOT}/demo/cxx"
)
add_dependencies(publish_inference_x86_cxx_lib publish_inference_x86_cxx_demos)
add_dependencies(publish_inference_x86_cxx_demos paddle_api_full_bundled eigen3)
......
......@@ -42,6 +42,9 @@ if ((NOT LITE_ON_TINY_PUBLISH) AND (LITE_WITH_CUDA OR LITE_WITH_X86 OR LITE_WITH
)
add_dependencies(paddle_light_api_shared op_list_h kernel_list_h)
if(WIN32)
target_link_libraries(paddle_light_api_shared shlwapi.lib)
endif()
target_link_libraries(paddle_light_api_shared ${light_lib_DEPS} ${arm_kernels} ${npu_kernels} ${rknpu_kernels} ${apu_kernels})
if(NOT APPLE AND NOT WIN32)
set(LINK_MAP_FILE "${PADDLE_SOURCE_DIR}/lite/core/lite.map")
......@@ -246,8 +249,10 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING)
ARGS --cl_path=${CMAKE_SOURCE_DIR}/lite/backends/opencl
--model_dir=${LITE_MODEL_DIR}/mobilenet_v1 SERIAL)
add_dependencies(test_mobilenetv1 extern_lite_download_mobilenet_v1_tar_gz)
set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set_target_properties(test_mobilenetv1 PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
if(NOT WIN32)
set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set_target_properties(test_mobilenetv1 PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
endif()
lite_cc_test(test_mobilenetv2 SRCS mobilenetv2_test.cc
DEPS ${lite_model_test_DEPS}
......@@ -255,7 +260,9 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING)
ARGS --cl_path=${CMAKE_SOURCE_DIR}/lite/backends/opencl
--model_dir=${LITE_MODEL_DIR}/mobilenet_v2_relu SERIAL)
add_dependencies(test_mobilenetv2 extern_lite_download_mobilenet_v2_relu_tar_gz)
set_target_properties(test_mobilenetv2 PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
if(NOT WIN32)
set_target_properties(test_mobilenetv2 PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
endif()
lite_cc_test(test_resnet50 SRCS resnet50_test.cc
DEPS ${lite_model_test_DEPS} paddle_api_light
......
......@@ -16,6 +16,7 @@
#if !defined(_WIN32)
#include <sys/time.h>
#else
#define NOMINMAX // msvc max/min macro conflict with std::min/max
#include <windows.h>
#include "lite/backends/x86/port.h"
#endif
......
......@@ -61,11 +61,11 @@ TEST(CXXApi, test_lite_googlenet) {
<< " ms in average.";
auto out = predictor->GetOutput(0);
std::vector<float> results(
{0.00034298553, 0.0008200012, 0.0005046297, 0.000839279,
0.00052616704, 0.0003447803, 0.0010877076, 0.00081762316,
0.0003941339, 0.0011430943, 0.0008892841, 0.00080191303,
0.0004442384, 0.000658702, 0.0026721435, 0.0013686896,
0.0005618166, 0.0006556497, 0.0006984528, 0.0014619455});
{0.00034298553f, 0.0008200012f, 0.0005046297f, 0.000839279f,
0.00052616704f, 0.0003447803f, 0.0010877076f, 0.00081762316f,
0.0003941339f, 0.0011430943f, 0.0008892841f, 0.00080191303f,
0.0004442384f, 0.000658702f, 0.0026721435f, 0.0013686896f,
0.0005618166f, 0.0006556497f, 0.0006984528f, 0.0014619455f});
for (size_t i = 0; i < results.size(); ++i) {
EXPECT_NEAR(out->data<float>()[i * 51], results[i], 1e-5);
}
......
......@@ -18,6 +18,7 @@
#if !defined(_WIN32)
#include <sys/time.h>
#else
#define NOMINMAX // msvc max/min macro conflict with std::min/max
#include <windows.h>
#include "lite/backends/x86/port.h"
#endif
......
......@@ -62,11 +62,11 @@ TEST(InceptionV4, test_inceptionv4_lite_x86) {
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.0011684548, 0.0010390386, 0.0011301535, 0.0010133048,
0.0010259597, 0.0010982729, 0.00093195855, 0.0009141837,
0.00096620916, 0.00089982944, 0.0010064574, 0.0010474789,
0.0009782845, 0.0009230255, 0.0010548076, 0.0010974824,
0.0010612885, 0.00089107914, 0.0010112736, 0.00097655767}));
{0.0011684548f, 0.0010390386f, 0.0011301535f, 0.0010133048f,
0.0010259597f, 0.0010982729f, 0.00093195855f, 0.0009141837f,
0.00096620916f, 0.00089982944f, 0.0010064574f, 0.0010474789f,
0.0009782845f, 0.0009230255f, 0.0010548076f, 0.0010974824f,
0.0010612885f, 0.00089107914f, 0.0010112736f, 0.00097655767f}));
auto out = predictor->GetOutput(0);
ASSERT_EQ(out->shape().size(), 2u);
......
......@@ -62,11 +62,11 @@ TEST(Mobilenet_v1, test_mobilenetv1_lite_x86) {
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.00019130898, 9.467885e-05, 0.00015971427, 0.0003650665,
0.00026431272, 0.00060884043, 0.0002107942, 0.0015819625,
0.0010323516, 0.00010079765, 0.00011006987, 0.0017364529,
0.0048292773, 0.0013995157, 0.0018453331, 0.0002428986,
0.00020211363, 0.00013668182, 0.0005855956, 0.00025901722}));
{0.00019130898f, 9.467885e-05f, 0.00015971427f, 0.0003650665f,
0.00026431272f, 0.00060884043f, 0.0002107942f, 0.0015819625f,
0.0010323516f, 0.00010079765f, 0.00011006987f, 0.0017364529f,
0.0048292773f, 0.0013995157f, 0.0018453331f, 0.0002428986f,
0.00020211363f, 0.00013668182f, 0.0005855956f, 0.00025901722f}));
auto out = predictor->GetOutput(0);
ASSERT_EQ(out->shape().size(), 2u);
ASSERT_EQ(out->shape()[0], 1);
......
......@@ -63,11 +63,11 @@ TEST(Mobilenet_v2, test_mobilenetv2_lite_x86) {
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.00017082224, 5.699624e-05, 0.000260885, 0.00016412718,
0.00034818667, 0.00015230637, 0.00032959113, 0.0014772735,
0.0009059976, 9.5378724e-05, 5.386537e-05, 0.0006427285,
0.0070957416, 0.0016094646, 0.0018807327, 0.00010506048,
6.823785e-05, 0.00012269315, 0.0007806194, 0.00022354358}));
{0.00017082224f, 5.699624e-05f, 0.000260885f, 0.00016412718f,
0.00034818667f, 0.00015230637f, 0.00032959113f, 0.0014772735f,
0.0009059976f, 9.5378724e-05f, 5.386537e-05f, 0.0006427285f,
0.0070957416f, 0.0016094646f, 0.0018807327f, 0.00010506048f,
6.823785e-05f, 0.00012269315f, 0.0007806194f, 0.00022354358f}));
auto out = predictor->GetOutput(0);
ASSERT_EQ(out->shape().size(), 2u);
ASSERT_EQ(out->shape()[0], 1);
......
......@@ -63,11 +63,11 @@ TEST(Resnet50, test_resnet50_lite_x86) {
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>(
{0.00024139918, 0.00020566184, 0.00022418296, 0.00041731037,
0.0005366107, 0.00016948722, 0.00028638865, 0.0009257241,
0.00072681636, 8.531815e-05, 0.0002129998, 0.0021168243,
0.006387163, 0.0037145028, 0.0012812682, 0.00045948103,
0.00013535398, 0.0002483765, 0.00076759676, 0.0002773295}));
{0.00024139918f, 0.00020566184f, 0.00022418296f, 0.00041731037f,
0.0005366107f, 0.00016948722f, 0.00028638865f, 0.0009257241f,
0.00072681636f, 8.531815e-05f, 0.0002129998f, 0.0021168243f,
0.006387163f, 0.0037145028f, 0.0012812682f, 0.00045948103f,
0.00013535398f, 0.0002483765f, 0.00076759676f, 0.0002773295f}));
auto out = predictor->GetOutput(0);
ASSERT_EQ(out->shape().size(), 2u);
ASSERT_EQ(out->shape()[0], 1);
......
......@@ -82,7 +82,7 @@ TEST(Step_rnn, test_step_rnn_lite_x86) {
std::vector<std::vector<float>> results;
// i = 1
results.emplace_back(std::vector<float>({0.5030127, 0.496987}));
results.emplace_back(std::vector<float>({0.5030127f, 0.496987f}));
auto out = predictor->GetOutput(0);
std::vector<int64_t> out_shape = out->shape();
......
......@@ -12,8 +12,10 @@ if (WITH_TESTING AND NOT LITE_WITH_CUDA)
add_dependencies(test_subgraph_detector
extern_lite_download_mobilenet_v1_tar_gz
extern_lite_download_mobilenet_v2_relu_tar_gz)
set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set_target_properties(test_subgraph_detector PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
if(NOT WIN32)
set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set_target_properties(test_subgraph_detector PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
endif()
lite_cc_test(test_subgraph_pass
SRCS subgraph_pass_test.cc
DEPS mir_passes paddle_api_full paddle_api_light gflags
......@@ -22,8 +24,10 @@ if (WITH_TESTING AND NOT LITE_WITH_CUDA)
add_dependencies(test_subgraph_pass
extern_lite_download_mobilenet_v1_tar_gz
extern_lite_download_mobilenet_v2_relu_tar_gz)
set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set_target_properties(test_subgraph_pass PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
if(NOT WIN32)
set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set_target_properties(test_subgraph_pass PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
endif()
endif()
set(mir_subgraphs subgraph_pass CACHE INTERNAL "mir_subgraphs")
......
......@@ -137,13 +137,13 @@ std::string BasicTimer::basic_repr() const {
// clang-format off
ss << GetCustomInfo("op_type") << "\t"
<< key() << "\t"
<< kernel_timer_info.ave() / time_unit_factor << "\t"
<< kernel_timer_info.min() / time_unit_factor << "\t"
<< kernel_timer_info.max() / time_unit_factor << "\t"
<< inst_timer_info.ave() / time_unit_factor << "\t"
<< inst_timer_info.min() / time_unit_factor << "\t"
<< inst_timer_info.max() / time_unit_factor << "\t"
<< inst_timer_info.count() << "\t"
<< kernel_timer_info.Ave() / time_unit_factor << "\t"
<< kernel_timer_info.Min() / time_unit_factor << "\t"
<< kernel_timer_info.Max() / time_unit_factor << "\t"
<< inst_timer_info.Ave() / time_unit_factor << "\t"
<< inst_timer_info.Min() / time_unit_factor << "\t"
<< inst_timer_info.Max() / time_unit_factor << "\t"
<< inst_timer_info.Count() << "\t"
<< GetCustomInfo("op_info");
// clang-format on
return ss.str();
......@@ -195,13 +195,13 @@ std::string BasicProfiler<TimerT>::summary_repr() const {
auto& op_timer = iter.second;
// clang-format off
ss << iter.first << "\t"
<< op_timer.ave() / time_unit_factor << "\t"
<< op_timer.min() / time_unit_factor << "\t"
<< op_timer.max() / time_unit_factor << "\t"
<< op_timer.total() / time_unit_factor << "\t"
<< op_timer.Ave() / time_unit_factor << "\t"
<< op_timer.Min() / time_unit_factor << "\t"
<< op_timer.Max() / time_unit_factor << "\t"
<< op_timer.Total() / time_unit_factor << "\t"
<< total / time_unit_factor << "\t"
<< (op_timer.total() * 1. / total * 100) << "%\t"
<< op_timer.count() << "\t"
<< (op_timer.Total() * 1. / total * 100) << "%\t"
<< op_timer.Count() << "\t"
<< "\n";
// clang-format on
}
......
......@@ -39,15 +39,15 @@ namespace profile {
struct TimerInfo {
uint64_t total_{0};
uint64_t count_{0};
uint64_t max_{std::numeric_limits<uint64_t>::min()};
uint64_t min_{std::numeric_limits<uint64_t>::max()};
uint64_t max_{(std::numeric_limits<uint64_t>::min)()};
uint64_t min_{(std::numeric_limits<uint64_t>::max)()};
uint64_t timer_{0};
double ave() const { return total_ * 1. / count_; }
double max() const { return max_; }
double min() const { return min_; }
uint64_t total() const { return total_; }
uint64_t count() const { return count_; }
double Ave() const { return total_ * 1. / count_; }
double Max() const { return max_; }
double Min() const { return min_; }
uint64_t Total() const { return total_; }
uint64_t Count() const { return count_; }
};
/* Base class of all the profile records */
......
......@@ -112,9 +112,10 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) {
ch->second.min += unit.Timer(type)->LapTimes().Min(w);
ch->second.max += unit.Timer(type)->LapTimes().Max(w);
} else {
TimeInfo info({unit.Timer(type)->LapTimes().Avg(w),
unit.Timer(type)->LapTimes().Min(w),
unit.Timer(type)->LapTimes().Max(w)});
TimeInfo info;
info.avg = unit.Timer(type)->LapTimes().Avg(w);
info.min = unit.Timer(type)->LapTimes().Min(w);
info.max = unit.Timer(type)->LapTimes().Max(w);
summary.insert({unit.Character(), info});
}
}
......
......@@ -32,8 +32,8 @@ value_type DDimLite::production() const {
}
value_type DDimLite::count(int start, int end) const {
start = std::max(start, 0);
end = std::min(end, static_cast<int>(data_.size()));
start = (std::max)(start, 0);
end = (std::min)(end, static_cast<int>(data_.size()));
if (end < start) {
return 0;
}
......@@ -45,8 +45,8 @@ value_type DDimLite::count(int start, int end) const {
}
DDimLite DDimLite::Slice(int start, int end) const {
start = std::max(start, 0);
end = std::min(end, static_cast<int>(data_.size()));
start = (std::max)(start, 0);
end = (std::min)(end, static_cast<int>(data_.size()));
std::vector<value_type> new_dim(end - start);
for (int i = start; i < end; i++) {
new_dim[i - start] = data_[i];
......
......@@ -66,18 +66,18 @@ TEST(gelu_x86, run_test) {
gelu.Run();
LOG(INFO) << "output: ";
std::vector<float> ref_data{0.,
-0.169484,
1.512321,
-0.019674,
3.197801,
-0.000126719,
4.8,
-0.,
6.4000001,
-0.,
8.,
-0.};
std::vector<float> ref_data{0.f,
-0.169484f,
1.512321f,
-0.019674f,
3.197801f,
-0.000126719f,
4.8f,
-0.f,
6.4000001f,
-0.f,
8.f,
-0.f};
for (int i = 0; i < out.dims().production(); i++) {
LOG(INFO) << out_data[i];
EXPECT_NEAR(out_data[i], ref_data[i], 1e-5);
......
......@@ -61,18 +61,18 @@ TEST(leaky_relu_x86, run_test) {
leaky_relu.SetParam(param);
leaky_relu.Run();
std::vector<float> ref_data({-0.025,
-0.02083333,
-0.01666667,
-0.0125,
-0.00833333,
-0.00416667,
0.,
0.08333334,
0.16666667,
0.25,
0.33333334,
0.41666666});
std::vector<float> ref_data({-0.025f,
-0.02083333f,
-0.01666667f,
-0.0125f,
-0.00833333f,
-0.00416667f,
0.f,
0.08333334f,
0.16666667f,
0.25f,
0.33333334f,
0.41666666f});
for (int i = 0; i < out.dims().production(); i++) {
EXPECT_NEAR(out_data[i], ref_data[i], 1e-05);
}
......
......@@ -74,7 +74,7 @@ TEST(sequence_pool_x86, run_test) {
sequence_pool.Run();
std::vector<float> ref_results = {
39.6, 40.7, 41.8, 42.9, 44, 45.1, 46.2, 47.3};
39.6f, 40.7f, 41.8f, 42.9f, 44.f, 45.1f, 46.2f, 47.3f};
for (int i = 0; i < out.dims().production(); i++) {
EXPECT_NEAR(out_data[i], ref_results[i], 1e-3);
}
......
......@@ -51,11 +51,11 @@ static void slice_ref(const float* input,
}
}
const int LEN = in_dims.size();
int dst_step[LEN];
std::vector<int> dst_step(LEN);
for (size_t i = 0; i < in_dims.size(); ++i) {
dst_step[i] = 1;
}
int src_step[LEN];
std::vector<int> src_step(LEN);
for (size_t i = 0; i < in_dims.size(); ++i) {
src_step[i] = 1;
}
......
......@@ -66,11 +66,11 @@ TEST(softmax_x86, run_test) {
softmax.Run();
std::vector<float> ref_results = {
0.0900306, 0.244728, 0.665241, 0.0900306, 0.244728, 0.665241,
0.0900306, 0.244728, 0.665241, 0.0900306, 0.244728, 0.665241,
0.0900306, 0.244728, 0.665241, 0.0900306, 0.244728, 0.665241,
0.0900306, 0.244728, 0.665241, 0.0900306, 0.244728, 0.665241,
0.0900306, 0.244728, 0.665241};
0.0900306f, 0.244728f, 0.665241f, 0.0900306f, 0.244728f, 0.665241f,
0.0900306f, 0.244728f, 0.665241f, 0.0900306f, 0.244728f, 0.665241f,
0.0900306f, 0.244728f, 0.665241f, 0.0900306f, 0.244728f, 0.665241f,
0.0900306f, 0.244728f, 0.665241f, 0.0900306f, 0.244728f, 0.665241f,
0.0900306f, 0.244728f, 0.665241f};
for (int i = 0; i < out.dims().production(); i++) {
EXPECT_NEAR(out_data[i], ref_results[i], 1e-3);
}
......
......@@ -66,18 +66,18 @@ TEST(tanh_x86, run_test) {
tanh.Run();
LOG(INFO) << "output: ";
std::vector<float> ref_data{0.,
-0.079829,
0.158648,
-0.235495,
0.309506,
-0.379949,
0.446243,
-0.507977,
0.564899,
-0.616909,
0.664036,
-0.706419};
std::vector<float> ref_data{0.f,
-0.079829f,
0.158648f,
-0.235495f,
0.309506f,
-0.379949f,
0.446243f,
-0.507977f,
0.564899f,
-0.616909f,
0.664036f,
-0.706419f};
for (int i = 0; i < out.dims().production(); i++) {
LOG(INFO) << out_data[i];
EXPECT_NEAR(out_data[i], ref_data[i], 1e-5);
......
......@@ -86,20 +86,20 @@ class SequenceConvComputeTester : public arena::TestCase {
auto output_data = output->mutable_data<float>();
std::vector<std::vector<float>> res;
if (contextStart_ == -2) {
res = {{-0.08867277, -0.17257819, -0.2564836},
{0.194508, 0.05720823, -0.08009153},
{0.73512584, 0.5749428, 0.41475973},
{0.5635012, 0.49485126, 0.42620137}};
res = {{-0.08867277f, -0.17257819f, -0.2564836f},
{0.194508f, 0.05720823f, -0.08009153f},
{0.73512584f, 0.5749428f, 0.41475973f},
{0.5635012f, 0.49485126f, 0.42620137f}};
} else if (contextStart_ == -1) {
res = {{0.194508, 0.05720823, -0.08009153},
{0.73512584, 0.5749428, 0.41475973},
{0.5635012, 0.49485126, 0.42620137},
{0.2517162, 0.23646072, 0.22120519}};
res = {{0.194508f, 0.05720823f, -0.08009153f},
{0.73512584f, 0.5749428f, 0.41475973f},
{0.5635012f, 0.49485126f, 0.42620137f},
{0.2517162f, 0.23646072f, 0.22120519f}};
} else if (contextStart_ == 0) {
res = {{0.73512584, 0.5749428, 0.41475973},
{0.5635012, 0.49485126, 0.42620137},
{0.2517162, 0.23646072, 0.22120519},
{0.02574372, 0.03337148, 0.04099924}};
res = {{0.73512584f, 0.5749428f, 0.41475973f},
{0.5635012f, 0.49485126f, 0.42620137f},
{0.2517162f, 0.23646072f, 0.22120519f},
{0.02574372f, 0.03337148f, 0.04099924f}};
} else {
fprintf(stderr, "not supported contextStart_\n");
exit(-1);
......
......@@ -47,11 +47,11 @@ static void slice_ref(const float* input,
}
}
const int LEN = in_dims.size();
int dst_step[LEN];
std::vector<int> dst_step(LEN);
for (int i = 0; i < in_dims.size(); ++i) {
dst_step[i] = 1;
}
int src_step[LEN];
std::vector<int> src_step(LEN);
for (int i = 0; i < in_dims.size(); ++i) {
src_step[i] = 1;
}
......
......@@ -27,7 +27,7 @@ static void basic_trans_mat_to_c4(const type* input,
k_round = K;
}
const int m_loop = m_round / 4;
type zero_buf[K];
type* zero_buf = new type[K];
memset(zero_buf, 0, K * sizeof(type));
for (int i = 0; i < m_loop; ++i) {
const type* in0 = input + i * 4 * ldin;
......@@ -59,6 +59,7 @@ static void basic_trans_mat_to_c4(const type* input,
*output++ = static_cast<type>(0);
}
}
delete[] zero_buf;
}
template <typename type, typename type2>
......
......@@ -14,7 +14,16 @@
#pragma once
#ifdef __APPLE__
#include <sys/sysctl.h>
#include <sys/types.h>
#elif defined(_WIN32)
#define NOMINMAX // msvc max/min macro conflict with std::min/max
#include <windows.h>
#else
#include <unistd.h>
#endif // _WIN32
#include <cmath>
#include <cstdlib>
#include <random>
......
......@@ -3,20 +3,49 @@ setlocal
setlocal enabledelayedexpansion
set source_path=%~dp0\\..\\..\\
rem global variables
set BUILD_EXTRA=OFF
set BUILD_JAVA=ON
set BUILD_PYTHON=OFF
set WITH_PYTHON=OFF
set BUILD_DIR=%source_path%
set OPTMODEL_DIR=""
set BUILD_TAILOR=OFF
set BUILD_CV=OFF
set WITH_LOG=ON
set WITH_PROFILE=OFF
set WITH_TESTING=OFF
set BUILD_FOR_CI=OFF
set THIRDPARTY_TAR=https://paddle-inference-dist.bj.bcebos.com/PaddleLite/third-party-05b862.tar.gz
set workspace=%source_path%
:round
@echo off
if /I "%1"=="with_extra" (
set BUILD_EXTRA=ON
) else if /I "%1"=="with_python" (
set WITH_PYTHON=ON
) else if /I "%1"=="with_profile" (
set WITH_PROFILE=ON
) else if /I "%1"=="build_for_ci" (
set BUILD_FOR_CI=ON
set WITH_TESTING=ON
set BUILD_EXTRA=ON
set WITH_PROFILE=ON
) else if /I "%1"=="help" (
call:print_usage
goto:eof
) else (
goto main
)
shift
goto round
:main
cd "%workspace%"
echo "------------------------------------------------------------------------------------------------------|"
echo "| BUILD_EXTRA=%BUILD_EXTRA% |"
echo "| WITH_PYTHON=%WITH_PYTHON% |"
echo "| LITE_WITH_PROFILE=%WITH_PROFILE% |"
echo "| WITH_TESTING=%WITH_TESTING% |"
echo "------------------------------------------------------------------------------------------------------|"
:set_vcvarsall_dir
SET /P vcvarsall_dir="Please input the path of visual studio command Prompt, such as C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat =======>"
set tmp_var=!vcvarsall_dir!
......@@ -24,23 +53,25 @@ call:remove_space
set vcvarsall_dir=!tmp_var!
IF NOT EXIST "%vcvarsall_dir%" (
echo "------------%vcvarsall_dir% not exist------------"
goto set_vcvarsall_dir
goto:eof
)
call:prepare_thirdparty
if EXIST "%build_directory%" (
call:rm_rebuild_dir "%build_directory%"
md "%build_directory%"
)
set root_dir=%workspace%
set build_directory=%BUILD_DIR%\build.lite.x86
set GEN_CODE_PATH_PREFIX=%build_directory%\lite\gen_code
set DEBUG_TOOL_PATH_PREFIX=%build_directory%\lite\tools\debug
set Test_FILE="%build_directory%\lite_tests.txt"
REM "Clean the build directory."
if EXIST "%build_directory%" (
call:rm_rebuild_dir "%build_directory%"
md "%build_directory%"
)
rem for code gen, a source file is generated after a test, but is dependended by some targets in cmake.
rem here we fake an empty file to make cmake works.
REM "for code gen, a source file is generated after a test, but is dependended by some targets in cmake."
REM "here we fake an empty file to make cmake works."
if NOT EXIST "%GEN_CODE_PATH_PREFIX%" (
md "%GEN_CODE_PATH_PREFIX%"
)
......@@ -58,18 +89,27 @@ cd "%build_directory%"
cmake .. -G "Visual Studio 14 2015 Win64" -T host=x64 -DWITH_MKL=ON ^
-DWITH_MKLDNN=OFF ^
-DLITE_WITH_X86=ON ^
-DLITE_WITH_PROFILE=OFF ^
-DLITE_WITH_PROFILE=%WITH_PROFILE% ^
-DWITH_LITE=ON ^
-DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF ^
-DLITE_WITH_ARM=OFF ^
-DWITH_GPU=OFF ^
-DLITE_BUILD_EXTRA=ON ^
-DLITE_WITH_PYTHON=ON ^
-DLITE_BUILD_EXTRA=%BUILD_EXTRA% ^
-DLITE_WITH_PYTHON=%WITH_PYTHON% ^
-DWITH_TESTING=%WITH_TESTING% ^
-DPYTHON_EXECUTABLE="%python_path%"
call "%vcvarsall_dir%" amd64
cd "%build_directory%"
msbuild /m /p:Configuration=Release lite\publish_inference.vcxproj >mylog.txt 2>&1
if "%BUILD_FOR_CI%"=="ON" (
msbuild /m /p:Configuration=Release lite\lite_compile_deps.vcxproj
call:test_server
cmake .. -G "Visual Studio 14 2015 Win64" -T host=x64 -DWITH_LITE=ON -DLITE_ON_MODEL_OPTIMIZE_TOOL=ON -DWITH_TESTING=OFF -DLITE_BUILD_EXTRA=ON
msbuild /m /p:Configuration=Release lite\api\opt.vcxproj
) else (
msbuild /m /p:Configuration=Release lite\publish_inference.vcxproj
)
goto:eof
:prepare_thirdparty
......@@ -98,10 +138,14 @@ goto:eof
if NOT EXIST "%workspace%\third-party-05b862.tar.gz" (
echo "The directory of third_party not exists, the third-party-05b862.tar.gz not exists."
call:download_third_party
!python_path! %workspace%\lite\tools\untar.py %source_path%\third-party-05b862.tar.gz %workspace%
if EXIST "%workspace%\third-party-05b862.tar.gz" (
!python_path! %workspace%\lite\tools\untar.py %source_path%\third-party-05b862.tar.gz %workspace%
) else (
echo "------------Can't download the third-party-05b862.tar.gz!------"
)
) else (
echo "The directory of third_party not exists, the third-party-05b862.tar.gz exists."
!python_path! %workspace%\lite\tools\untar.py %source_path%\third-party-05b862.tar.gz %workspace%
!python_path! %workspace%\lite\tools\untar.py %source_path%\third-party-05b862.tar.gz %workspace%
)
)
......@@ -110,7 +154,7 @@ goto:eof
:download_third_party
powershell.exe (new-object System.Net.WebClient).DownloadFile('https://paddle-inference-dist.bj.bcebos.com/PaddleLite/third-party-05b862.tar.gz', ^
'%workspace%third-party-05b862.tar.gz')
'%workspace%\third-party-05b862.tar.gz')
goto:eof
:rm_rebuild_dir
......@@ -132,3 +176,42 @@ if "%tmp_var:~-1%"==" " (
goto remove_left_space
)
goto:eof
:print_usage
echo "------------------------------------------------------------------------------------------------------|"
echo "| Methods of compiling Paddle-lite Windows library: |"
echo "|-----------------------------------------------------------------------------------------------------|"
echo "| compile windows library: ( x86 ) |"
echo "| build_windows.bat |"
echo "| print help information: |"
echo "| build_windows.bat help |"
echo "| |"
echo "| optional argument: |"
echo "| with_profile: Enable profile mode in lite framework. Default OFF. |"
echo "| with_python: Enable Python api lib in lite mode. Default OFF. |"
echo "| with_extra: Enable extra algorithm support in Lite, both kernels and operators. Default OFF. |"
echo "| for example: |"
echo "| build_windows.bat with_profile with_python with_extra |"
echo "------------------------------------------------------------------------------------------------------|"
goto:eof
:test_server
rem Due to the missing of x86 kernels, we skip the following tests temporarily.
rem TODO(xxx) clear the skip list latter
set skip_list=("test_paddle_api" "test_cxx_api" "test_light_api" "test_apis" "test_model_bin")
for /f %%a in ('type %test_file%') do (
set to_skip=0
for %%b in %skip_list% do (
if "%%a"==%%b (
set to_skip=1
echo "to skip %%a"
)
)
if !to_skip! EQU 0 (
echo "Run the test of %%a"
ctest -C Release -R %%a
)
)
goto:eof
......@@ -38,7 +38,11 @@ void gen_log(STL::ostream& log_stream_,
std::string time_str;
struct tm tm_time; // Time of creation of LogMessage
time_t timestamp = time(NULL);
#if defined(_WIN32)
localtime_s(&tm_time, &timestamp);
#else
localtime_r(&timestamp, &tm_time);
#endif
struct timeval tv;
gettimeofday(&tv, NULL);
......
......@@ -22,9 +22,35 @@
#define _LOGGING_H_
#include <assert.h>
#include <time.h>
#if !defined(_WIN32)
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#else
#define NOMINMAX // msvc max/min macro conflict with std::min/max
#include <windows.h>
extern struct timeval;
static int gettimeofday(struct timeval* tp, void* tzp) {
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm.tm_isdst = -1;
clock = mktime(&tm);
tp->tv_sec = clock;
tp->tv_usec = wtm.wMilliseconds * 1000;
return (0);
}
#endif
#include <cstdlib>
#include <cstring>
#include <string>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册