Skip to content

Commit e0797a8

Browse files
Merge branch 'PaddlePaddle:develop' into develop
2 parents 3b17175 + 9817aad commit e0797a8

File tree

167 files changed

+6145
-1668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+6145
-1668
lines changed

Paddle

Submodule Paddle updated 4007 files

backends/custom_cpu/kernels/reshape_kernel.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ static std::vector<int64_t> ValidateShape(const std::vector<int64_t> shape,
122122
}
123123

124124
template <typename T>
125-
void ReshapeInferKernel(const phi::Context& dev_ctx,
126-
const phi::DenseTensor& x,
127-
const phi::IntArray& shape,
128-
phi::DenseTensor* out) {
125+
void ReshapeKernel(const phi::Context& dev_ctx,
126+
const phi::DenseTensor& x,
127+
const phi::IntArray& shape,
128+
phi::DenseTensor* out) {
129129
auto x_dims = x.dims();
130130
auto out_dims = ValidateShape(shape.GetData(), x_dims);
131131
out->Resize(out_dims);
@@ -149,20 +149,20 @@ void ReshapeInferKernel(const phi::Context& dev_ctx,
149149
}
150150

151151
template <typename T>
152-
void ReshapeKernel(const phi::Context& dev_ctx,
153-
const phi::DenseTensor& x,
154-
const phi::IntArray& shape,
155-
phi::DenseTensor* out,
156-
phi::DenseTensor* xshape) {
157-
ReshapeInferKernel<T>(dev_ctx, x, shape, out);
152+
void ReshapeWithXShapeKernel(const phi::Context& dev_ctx,
153+
const phi::DenseTensor& x,
154+
const phi::IntArray& shape,
155+
phi::DenseTensor* out,
156+
phi::DenseTensor* xshape) {
157+
ReshapeKernel<T>(dev_ctx, x, shape, out);
158158
}
159159

160160
} // namespace custom_kernel
161161

162-
PD_BUILD_PHI_KERNEL(reshape_infer,
162+
PD_BUILD_PHI_KERNEL(reshape,
163163
custom_cpu,
164164
ALL_LAYOUT,
165-
custom_kernel::ReshapeInferKernel,
165+
custom_kernel::ReshapeKernel,
166166
float,
167167
double,
168168
int8_t,
@@ -172,10 +172,10 @@ PD_BUILD_PHI_KERNEL(reshape_infer,
172172
uint8_t,
173173
bool) {}
174174

175-
PD_BUILD_PHI_KERNEL(reshape,
175+
PD_BUILD_PHI_KERNEL(reshape_with_xshape,
176176
custom_cpu,
177177
ALL_LAYOUT,
178-
custom_kernel::ReshapeKernel,
178+
custom_kernel::ReshapeWithXShapeKernel,
179179
float,
180180
double,
181181
int8_t,

backends/custom_cpu/tests/unittests/test_argsort_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def forward(self):
7070

7171

7272
def create_tensor(np_data, place):
73-
tensor = core.LoDTensor()
73+
tensor = core.DenseTensor()
7474
tensor.set(np_data, place)
7575
return tensor
7676

backends/custom_cpu/tests/unittests/test_slice_op.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def test_bool_tensor(self):
516516
# self.assertTrue(np.allclose(a_1.numpy(), a[-3:3, 0:2, 2:4]))
517517

518518

519-
class TestSliceApiWithLoDTensorArray(unittest.TestCase):
519+
class TestSliceApiWithDenseTensorArray(unittest.TestCase):
520520
def setUp(self):
521521
self.shape = (3, 4)
522522
self.data = np.random.random(size=self.shape).astype("float32")
@@ -582,7 +582,7 @@ def test_case_1(self):
582582
main_program = base.Program()
583583
self.set_program_and_run(main_program, 1)
584584

585-
self.assertTrue(self.sliced_arr.type == core.VarDesc.VarType.LOD_TENSOR)
585+
self.assertTrue(self.sliced_arr.type == core.VarDesc.VarType.DENSE_TENSOR)
586586
self.assertEqual(self.sliced_arr.shape, self.shape)
587587
self.assertTrue(np.array_equal(self.out, self.data))
588588
self.assertTrue(np.array_equal(self.g_x0, np.ones_like(self.data)))
@@ -593,7 +593,7 @@ def test_case_2(self):
593593
main_program = base.Program()
594594
self.set_program_and_run(main_program, 2)
595595

596-
self.assertTrue(self.sliced_arr.type == core.VarDesc.VarType.LOD_TENSOR_ARRAY)
596+
self.assertTrue(self.sliced_arr.type == core.VarDesc.VarType.DENSE_TENSOR_ARRAY)
597597
self.assertEqual(self.sliced_arr.shape, self.shape)
598598
self.assertTrue(
599599
np.array_equal(self.out, np.stack([self.data, self.data], axis=self.axis))
@@ -606,7 +606,7 @@ def test_case_3(self):
606606
main_program = base.Program()
607607
self.set_program_and_run(main_program, 3)
608608

609-
self.assertTrue(self.sliced_arr.type == core.VarDesc.VarType.LOD_TENSOR_ARRAY)
609+
self.assertTrue(self.sliced_arr.type == core.VarDesc.VarType.DENSE_TENSOR_ARRAY)
610610
self.assertEqual(self.sliced_arr.shape, self.shape)
611611
self.assertTrue(
612612
np.array_equal(

backends/gcu/CMakeLists.txt

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,7 @@ cmake_minimum_required(VERSION 3.10)
1717
project(paddle-custom-gcu CXX C)
1818
set(CUSTOM_GCU_NAME "paddle-custom-gcu")
1919

20-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
21-
message(STATUS "CMAKE_DEBUG CMAKE_MODULE_PATH is: ${CMAKE_MODULE_PATH}")
22-
option(VERSION_WITH_GIT "Use git hash to PACKAGE_VERSION" FALSE)
23-
24-
set(TOPS_RELEASE_VERSION 3.1.0)
25-
if((NOT DEFINED PACKAGE_VERSION)
26-
OR ("${PACKAGE_VERSION}" STREQUAL "")
27-
OR ("${PACKAGE_VERSION}" STREQUAL "123.456"))
28-
if(VERSION_WITH_GIT)
29-
# get Paddle-custom git hash
30-
execute_process(
31-
COMMAND git log -1 --abbrev=7 --format=%h
32-
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
33-
OUTPUT_VARIABLE _tag
34-
OUTPUT_STRIP_TRAILING_WHITESPACE)
35-
message(STATUS "git hash: ${_tag}")
36-
else()
37-
string(TIMESTAMP _tag "%Y%m%d")
38-
endif()
39-
set(PACKAGE_VERSION ${TOPS_RELEASE_VERSION}.${_tag})
40-
endif()
41-
42-
message(STATUS "package version: ${PACKAGE_VERSION}")
20+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
4321

4422
if(DEFINED PY_VERSION)
4523
message(STATUS "User define PY_VERSION: ${PY_VERSION}")
@@ -51,22 +29,15 @@ set(PYTHON_VERSION ${PY_VERSION})
5129
set(Python_EXECUTABLE "python${PY_VERSION}")
5230
message(STATUS "Python_EXECUTABLE: ${Python_EXECUTABLE}")
5331

54-
if(NOT DEFINED ENV{PADDLE_VERSION})
55-
set(ENV{PADDLE_VERSION} 3.0.0-beta1)
56-
endif()
57-
5832
include(paddle)
5933
include(version)
6034
include(generic)
6135
include(external/gcu)
6236
include(external/topscc)
6337

64-
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
38+
include_directories(${CMAKE_SOURCE_DIR})
6539
include_directories(/opt/tops/include)
6640

67-
set(OUTPUT_PADDLE_PACKAGE_VERSION ${PADDLE_VERSION}+${PACKAGE_VERSION})
68-
string(REPLACE "-beta" "b" OUTPUT_PADDLE_PACKAGE_VERSION
69-
"${OUTPUT_PADDLE_PACKAGE_VERSION}")
7041
option(WITH_KERNELS "compile with custom kernels" ON)
7142
option(WITH_TESTING "compile with unit testing" OFF)
7243
option(WITH_MKL "compile with mkl support" ON)
@@ -205,13 +176,10 @@ message(STATUS "Git commit id is: ${GIT_HASH}")
205176
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
206177
${CMAKE_CURRENT_BINARY_DIR}/setup.py)
207178

208-
message(STATUS "CMAKE_DEBUG Git commit id is: ${GIT_HASH}")
209-
message(STATUS "CMAKE_DEBUG CUSTOM_GCU_SRCS is: ${CUSTOM_GCU_SRCS}")
210-
message(STATUS "CMAKE_DEBUG GCU_LIBS is: ${GCU_LIBS}")
211-
179+
# packing wheel package
212180
add_custom_command(
213-
OUTPUT
214-
${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/lib${CUSTOM_GCU_NAME}.so
181+
TARGET ${CUSTOM_GCU_NAME}
182+
POST_BUILD
215183
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_CURRENT_BINARY_DIR}/python/
216184
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/python/
217185
COMMAND ${CMAKE_COMMAND} -E make_directory
@@ -220,16 +188,13 @@ add_custom_command(
220188
${CMAKE_COMMAND} -E copy_if_different
221189
${CMAKE_CURRENT_BINARY_DIR}/lib${CUSTOM_GCU_NAME}.so
222190
${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/
223-
COMMENT "Creating custom device directories------>>>"
224-
DEPENDS ${CUSTOM_GCU_NAME})
225-
add_custom_target(
226-
CUSTOM_GCU_NAME_shared_lib_copy ALL
227-
DEPENDS
228-
${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/lib${CUSTOM_GCU_NAME}.so
229-
)
191+
COMMENT "Creating custom device directories------>>>")
230192

231193
set(topscc_kernel_lib_targets "")
232194
unset(topscc_kernel_lib_targets)
195+
set(_passes_target_dir
196+
"${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/gcu")
197+
file(MAKE_DIRECTORY ${_passes_target_dir})
233198
foreach(topscc_kernel_lib ${TOPSCC_LIBS})
234199
get_filename_component(topscc_kernel_lib_name ${topscc_kernel_lib} NAME_WLE)
235200
get_filename_component(topscc_kernel_lib_target_name ${topscc_kernel_lib}
@@ -250,29 +215,17 @@ foreach(topscc_kernel_lib ${TOPSCC_LIBS})
250215
endforeach()
251216
add_custom_target(topscc_targets ALL DEPENDS ${topscc_kernel_lib_targets})
252217

253-
set(whl_file
254-
"${CMAKE_CURRENT_BINARY_DIR}/dist/paddle_custom_gcu-${OUTPUT_PADDLE_PACKAGE_VERSION}-cp${PY_VERSION_NO_DOT}-cp${PY_VERSION_NO_DOT}-linux_x86_64.whl"
255-
)
256-
set(_passes_target_dir
257-
"${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/gcu/passes")
258-
file(MAKE_DIRECTORY ${_passes_target_dir})
259-
file(GLOB passes_srcs "${CMAKE_CURRENT_SOURCE_DIR}/passes/*")
260-
foreach(passes_src IN LISTS passes_srcs)
261-
get_filename_component(passes_file_name ${passes_src} NAME)
262-
add_custom_command(
263-
OUTPUT ${_passes_target_dir}/${passes_file_name}
264-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${passes_src}
265-
${_passes_target_dir}
266-
DEPENDS ${passes_src})
267-
list(APPEND passes_bin_files_list "${_passes_target_dir}/${passes_file_name}")
268-
endforeach()
269218
add_custom_command(
270-
OUTPUT ${whl_file}
219+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python/.timestamp
220+
COMMAND ${CMAKE_COMMAND} -E remove -f
221+
${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/gcu/passes
222+
COMMAND ${CMAKE_COMMAND} -E make_directory
223+
${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/gcu/passes
224+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/passes/*
225+
${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/gcu/passes
271226
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py bdist_wheel
272-
# COMMAND rename 's/_${TOPS_RELEASE_VERSION}/-${TOPS_RELEASE_VERSION}/g'
273-
# ${CMAKE_CURRENT_BINARY_DIR}/dist/*.whl
274-
DEPENDS ${CUSTOM_GCU_NAME} CUSTOM_GCU_NAME_shared_lib_copy topscc_targets
275-
${CMAKE_CURRENT_BINARY_DIR}/setup.py ${passes_bin_files_list}
227+
DEPENDS ${CUSTOM_GCU_NAME}
276228
COMMENT "Packing whl packages------>>>")
277229

278-
add_custom_target(python_package ALL DEPENDS ${whl_file})
230+
add_custom_target(python_package ALL
231+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/.timestamp)

backends/gcu/README.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,38 @@ Please refer to the following steps to compile, install and verify the hardware
77
## Prepare environment and source code
88

99
```bash
10-
# 1) Pull PaddlePaddle development docker image,and install Enflame GCU development kit.
10+
# 1) Pull the image. Note that this image is only for development environment
11+
# and does not contain precompiled PaddlePaddle installation package.
12+
# The build script and dockerfile of this image are located in the tools/dockerfile directory.
13+
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84 /bin/bash
1114

12-
# 2) Clone the source code.
15+
# 2) Refer to the following command to start the container.
16+
docker run --name paddle-gcu-dev -v /home:/home \
17+
--network=host --ipc=host -it --privileged \
18+
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84 /bin/bash
19+
20+
# 3) Clone the source code.
1321
git clone https://github.com/PaddlePaddle/PaddleCustomDevice
1422
cd PaddleCustomDevice
23+
24+
# 4) Prepare the machine and initialize the environment (only required for device used for execution).
25+
# 4a) Get the driver: The full software package is placed in docker in advance
26+
# and needs to be copied to the directory outside docker, such as: /home/workspace/deps/.
27+
mkdir -p /home/workspace/deps/ && cp /root/TopsRider_i3x_*/TopsRider_i3x_*_deb_amd64.run /home/workspace/deps/
28+
29+
# 4b) Verify whether the machine has Enflame S60 accelerators.
30+
# Check whether the following command has output in the system environment.
31+
# Note: You need to press Ctrl+D to exit docker.
32+
# The following initialization environment operations are all performed in the system environment.
33+
lspci | grep S60
34+
35+
# 4c) Install the driver.
36+
cd /home/workspace/deps/
37+
bash TopsRider_i3x_*_deb_amd64.run --driver --no-auto-load
38+
39+
# 4d) After the driver is installed, refer to the following command to re-enter docker.
40+
docker start paddle-gcu-dev
41+
docker exec -it paddle-gcu-dev bash
1542
```
1643

1744
## PaddleCustomDevice Installation and Verification
@@ -20,7 +47,7 @@ cd PaddleCustomDevice
2047

2148
```bash
2249
# 1) Enter the hardware backend (Enflame GCU) directory.
23-
cd backends/gcu
50+
cd PaddleCustomDevice/backends/gcu
2451

2552
# 2) Before compiling, you need to ensure that the PaddlePaddle installation package is installed in the environment.
2653
# Just install the PaddlePaddle CPU version directly.
@@ -47,9 +74,9 @@ python -c "import paddle; print(paddle.device.get_all_custom_device_type())"
4774
# 2) Check currently installed version.
4875
python -c "import paddle_custom_device; paddle_custom_device.gcu.version()"
4976
# Expect to get output like this.
50-
version: 0.0.0.9e03b0a
51-
commit: 9e03b0a42a530d07fb60e141ee618fc02595bd96
52-
tops-sdk: 2.5.20231128
77+
version: 3.0.0b1+3.1.0.20241113
78+
commit: f05823682bf607deb1b4adf9a9309f81225958fe
79+
TopsPlatform: 1.2.0.301
5380

5481
# 3) Unit test, compiled with -DWITH_TESTING=ON and executed in the build directory.
5582
ctest

backends/gcu/README_cn.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,34 @@
77
## 环境准备与源码同步
88

99
```bash
10-
# 1) 获取PaddlePaddle Docker镜像,并安装燧原GCU软件栈
10+
# 1) 拉取镜像,注意此镜像仅为开发环境,镜像中不包含预编译的飞桨安装包
11+
# 此镜像的构建脚本与dockerfile位于tools/dockerfile目录下
12+
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84 /bin/bash
1113

12-
# 2) 克隆PaddleCustomDevice源码
14+
# 2) 参考如下命令启动容器
15+
docker run --name paddle-gcu-dev -v /home:/home \
16+
--network=host --ipc=host -it --privileged \
17+
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84 /bin/bash
18+
19+
# 3) 克隆PaddleCustomDevice源码
1320
git clone https://github.com/PaddlePaddle/PaddleCustomDevice
1421
cd PaddleCustomDevice
22+
23+
# 4) 机器准备,初始化环境(仅用于执行的设备需要)
24+
# 4a) 驱动获取:docker内提前放置了全量软件包,需拷贝至docker外目录,如:/home/workspace/deps/
25+
mkdir -p /home/workspace/deps/ && cp /root/TopsRider_i3x_*/TopsRider_i3x_*_deb_amd64.run /home/workspace/deps/
26+
27+
# 4b) 验证机器是否插有燧原S60加速卡,系统环境下查看如下命令是否有输出
28+
# 注:需Ctrl+D退出docker, 以下初始化环境相关操作均在系统环境下执行
29+
lspci | grep S60
30+
31+
# 4c) 安装驱动
32+
cd /home/workspace/deps/
33+
bash TopsRider_i3x_*_deb_amd64.run --driver --no-auto-load
34+
35+
# 4d) 驱动安装完成后重新进入docker,参考如下命令
36+
docker start paddle-gcu-dev
37+
docker exec -it paddle-gcu-dev bash
1538
```
1639

1740
## PaddleCustomDevice安装与运行
@@ -20,7 +43,7 @@ cd PaddleCustomDevice
2043

2144
```bash
2245
# 1) 进入硬件后端(燧原GCU)目录
23-
cd backends/gcu
46+
cd PaddleCustomDevice/backends/gcu
2447

2548
# 2) 编译之前需确保环境下装有飞桨安装包,直接安装飞桨CPU版本即可
2649
python -m pip install --pre paddlepaddle -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/
@@ -46,9 +69,9 @@ python -c "import paddle; print(paddle.device.get_all_custom_device_type())"
4669
# 2) 检查当前安装版本
4770
python -c "import paddle_custom_device; paddle_custom_device.gcu.version()"
4871
# 预期得到类似以下的输出结果
49-
version: 0.0.0.9e03b0a
50-
commit: 9e03b0a42a530d07fb60e141ee618fc02595bd96
51-
tops-sdk: 2.5.20231128
72+
version: 3.0.0b1+3.1.0.20241113
73+
commit: f05823682bf607deb1b4adf9a9309f81225958fe
74+
TopsPlatform: 1.2.0.301
5275

5376
# 3) 单元测试,带上-DWITH_TESTING=ON编译后在build目录下执行
5477
ctest

backends/gcu/backend/executor/single_op_executor.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ limitations under the License. */
3535
namespace backend {
3636
using TensorPtr = std::shared_ptr<phi::DenseTensor>;
3737
using phi::DenseTensor;
38-
using LoDTensor = phi::DenseTensor;
38+
using DenseTensor = phi::DenseTensor;
3939

4040
SingleOpGcuExecutor::SingleOpGcuExecutor(
4141
const std::string& op_type,
@@ -67,15 +67,15 @@ void SingleOpGcuExecutor::ReleaseResource() {
6767
}
6868

6969
void SingleOpGcuExecutor::RunGcuOp(const phi::CustomContext* device_context,
70-
const std::vector<LoDTensor*>& inputs,
71-
const std::vector<LoDTensor*>& outputs,
70+
const std::vector<DenseTensor*>& inputs,
71+
const std::vector<DenseTensor*>& outputs,
7272
bool tensor_split) {
7373
std::vector<void*> dev_inputs;
7474
dev_inputs.reserve(inputs.size());
7575
std::vector<void*> dev_outputs;
7676
dev_outputs.resize(outputs.size());
7777

78-
static LoDTensor tmp_out_tensor;
78+
static DenseTensor tmp_out_tensor;
7979
static std::once_flag alloc_flags;
8080
std::call_once(alloc_flags, [&]() {
8181
const phi::DenseTensorMeta meta(phi::DataType::FLOAT32,
@@ -84,8 +84,8 @@ void SingleOpGcuExecutor::RunGcuOp(const phi::CustomContext* device_context,
8484
device_context->Alloc<float>(&tmp_out_tensor);
8585
});
8686

87-
std::vector<LoDTensor*> real_inputs;
88-
std::vector<LoDTensor*> real_outputs;
87+
std::vector<DenseTensor*> real_inputs;
88+
std::vector<DenseTensor*> real_outputs;
8989
real_inputs.reserve(inputs.size());
9090
real_outputs.reserve(outputs.size());
9191

0 commit comments

Comments
 (0)