Skip to content

Commit

Permalink
[Prim][PIR] support floor_divide op forward in prim pir (#64023)
Browse files Browse the repository at this point in the history
* floor-div-dev

* update test
  • Loading branch information
Eddie-Wang1120 committed May 7, 2024
1 parent a21ef65 commit c0b2c7d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"elu",
"embedding",
"flatten",
"floor_divide",
"full_like",
"gelu",
"hardswish",
Expand Down Expand Up @@ -67,6 +68,7 @@
"elu",
"embedding",
"flatten",
"floor_divide",
"full_like",
"gelu",
"hardswish",
Expand Down
8 changes: 8 additions & 0 deletions paddle/fluid/primitive/composite/composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,14 @@ Tensor full_like_decomp(const Tensor& x,
}
}

template <typename T>
Tensor floor_divide_decomp(const Tensor& x, const Tensor& y) {
auto x_cast = cast<T>(x, DataType::INT64);
auto y_cast = cast<T>(y, DataType::INT64);
auto res = x_cast / y_cast;
return cast<T>(res, x.dtype());
}

template <typename T>
std::tuple<Tensor, Tensor> dropout_decomp(
const Tensor& x,
Expand Down
4 changes: 3 additions & 1 deletion test/deprecated/legacy_test/test_elementwise_floordiv_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def init_kernel_type(self):

def setUp(self):
self.op_type = "elementwise_floordiv"
self.prim_op_type = "comp"
self.python_api = paddle.floor_divide
self.public_python_api = paddle.floor_divide
self.dtype = np.int32
self.axis = -1
self.init_dtype()
Expand All @@ -45,7 +47,7 @@ def setUp(self):
self.outputs = {'Out': self.out}

def test_check_output(self):
self.check_output(check_pir=True)
self.check_output(check_pir=True, check_prim_pir=True)

def init_input_output(self):
self.x = np.random.uniform(0, 10000, [10, 10]).astype(self.dtype)
Expand Down

0 comments on commit c0b2c7d

Please sign in to comment.