Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions paddle/phi/kernels/impl/data_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ template <typename T, typename Context>
void ShadowFeedKernel(const Context& ctx,
const DenseTensor& x,
DenseTensor* out) {
ctx.template Alloc<T>(out);
if (!x.initialized()) {
ctx.template Alloc<T>(out);
return;
}
if (x.place() == out->place()) {
if (x.place() == ctx.GetPlace()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要改成 ctx.GetPlace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out未初始化是不是拿不到place?

out->ShareDataWith(x);
out->set_lod(x.lod());
} else {
Expand Down
49 changes: 30 additions & 19 deletions test/legacy_test/test_scatter_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,25 +711,36 @@ def test_static_graph():
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
x_t = paddle.static.data(name="x", dtype=x.dtype, shape=x.shape)
index_t = paddle.static.data(
name="index", dtype=index.dtype, shape=index.shape
)
updates_t = paddle.static.data(
name="updates", dtype=updates.dtype, shape=updates.shape
)
out_t = paddle.scatter(x_t, index_t, updates_t)
feed = {
x_t.name: x,
index_t.name: index,
updates_t.name: updates,
}
fetch = [out_t]
gpu_exe = paddle.static.Executor(paddle.CUDAPlace(0))
gpu_value = gpu_exe.run(feed=feed, fetch_list=fetch)[0]
return gpu_value

np.testing.assert_array_equal(test_dygraph(), test_static_graph())
scope = paddle.static.Scope()
with paddle.static.scope_guard(scope):
x_t = paddle.static.data(
name="x", dtype=x.dtype, shape=x.shape
)
index_t = paddle.static.data(
name="index", dtype=index.dtype, shape=index.shape
)
updates_t = paddle.static.data(
name="updates", dtype=updates.dtype, shape=updates.shape
)
out_t = paddle.scatter(x_t, index_t, updates_t)
feed = {
x_t.name: x,
index_t.name: index,
updates_t.name: updates,
}
fetch = [out_t]
gpu_exe = paddle.static.Executor(paddle.CUDAPlace(0))
gpu_value = gpu_exe.run(feed=feed, fetch_list=fetch)[0]
scope._remove_from_pool()
return gpu_value

def test_pir_static_graph():
with paddle.pir_utils.IrGuard():
return test_static_graph()

dy_out = test_dygraph()
np.testing.assert_array_equal(dy_out, test_static_graph())
np.testing.assert_array_equal(dy_out, test_pir_static_graph())


@unittest.skipIf(
Expand Down