diff --git a/paddle/fluid/operators/fill_constant_op.cc b/paddle/fluid/operators/fill_constant_op.cc index aea149fbedc45bdbccd17e2169dee67bfafcf918..480a08bfb7e586271497938c9e9ac11fce6c25fa 100644 --- a/paddle/fluid/operators/fill_constant_op.cc +++ b/paddle/fluid/operators/fill_constant_op.cc @@ -87,6 +87,9 @@ class FillConstantOp : public framework::OperatorWithKernel { case 3: kt.place_ = platform::XPUPlace(); break; + case 4: + kt.place_ = platform::NPUPlace(); + break; default: PADDLE_THROW(platform::errors::Unimplemented( "Could NOT determine the place of variable, place_type = %d .", @@ -164,7 +167,8 @@ class FillConstantOpMaker : public framework::OpProtoAndCheckerMaker { "0: CPUPlace. " "1: CUDAPlace. " "2: CUDAPinnedPlace. " - "3: XPUPlace. ") + "3: XPUPlace. " + "4: NPUPlace. ") .SetDefault(-1); AddOutput("Out", "(Tensor) Tensor of specified shape will be filled " diff --git a/python/paddle/fluid/tests/unittests/npu/test_fill_constant_op_npu.py b/python/paddle/fluid/tests/unittests/npu/test_fill_constant_op_npu.py index a3e781c990ecb151b1b7a5c80bc256324b6fb43e..152a454805576a31f8887b95e06090044c578d1a 100644 --- a/python/paddle/fluid/tests/unittests/npu/test_fill_constant_op_npu.py +++ b/python/paddle/fluid/tests/unittests/npu/test_fill_constant_op_npu.py @@ -144,5 +144,26 @@ class TestFillConstantBool(OpTest): self.check_output_with_place(self.place) +class TestFillConstantWithPlaceType(OpTest): + def setUp(self): + self.set_npu() + self.place = paddle.NPUPlace(0) + self.op_type = "fill_constant" + self.init_dtype() + + self.inputs = {} + self.attrs = {'shape': [123, 92], 'value': 3.8, 'place_type': 4} + self.outputs = {'Out': np.full((123, 92), 3.8)} + + def set_npu(self): + self.__class__.use_npu = True + + def init_dtype(self): + self.dtype = np.float32 + + def test_check_output(self): + self.check_output_with_place(self.place) + + if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/npu/test_memcpy_op_npu.py b/python/paddle/fluid/tests/unittests/npu/test_memcpy_op_npu.py index a421e2667347c5b046e424a59f2efd2022a3199d..6500a8c8cd821a0ef3c2fd6978c61d5302e8b165 100755 --- a/python/paddle/fluid/tests/unittests/npu/test_memcpy_op_npu.py +++ b/python/paddle/fluid/tests/unittests/npu/test_memcpy_op_npu.py @@ -54,7 +54,7 @@ class TestMemcpy_FillConstant(unittest.TestCase): "shape": [10, 10], "dtype": npu_var.dtype, "value": 1.0, - "place_type": 1 + "place_type": 4 }) main_program.global_block().append_op( type="fill_constant", @@ -63,7 +63,7 @@ class TestMemcpy_FillConstant(unittest.TestCase): "shape": [10, 10], "dtype": cpu_var.dtype, "value": 0.0, - "place_type": 2 + "place_type": 0 }) return main_program, npu_var, cpu_var