未验证 提交 60d1199a 编写于 作者: H houj04 提交者: GitHub

[XPU] add logical_not op. (#49911)

上级 4c8c5b4b
......@@ -360,6 +360,7 @@ XPUOpMap& get_kl2_ops() {
{"log_grad", XPUKernelSet({phi::DataType::FLOAT32})},
{"log_softmax", XPUKernelSet({phi::DataType::FLOAT32})},
{"log_softmax_grad", XPUKernelSet({phi::DataType::FLOAT32})},
{"logical_not", XPUKernelSet({phi::DataType::BOOL})},
{"lookup_table_v2_grad", XPUKernelSet({phi::DataType::FLOAT32})},
{"lookup_table_v2", XPUKernelSet({phi::DataType::FLOAT32})},
{"masked_select",
......
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/phi/kernels/logical_kernel.h"
#include "paddle/phi/backends/xpu/enforce_xpu.h"
#include "paddle/phi/core/kernel_registry.h"
namespace phi {
template <typename T, typename Context>
void LogicalNotKernel(const Context& ctx,
const DenseTensor& x,
DenseTensor* out) {
ctx.template Alloc<T>(out);
int r =
xpu::logical_not(ctx.x_context(), x.data<T>(), out->data<T>(), x.numel());
PADDLE_ENFORCE_XDNN_SUCCESS(r, "logical_not");
}
} // namespace phi
PD_REGISTER_KERNEL(logical_not, XPU, ALL_LAYOUT, phi::LogicalNotKernel, bool) {}
......@@ -228,7 +228,8 @@ def get_xpu_op_support_types(op_name, dev_id=0):
op_name_type = op_name + "_" + stype
if op_name_type in ops:
support_types.append(stype)
if len(support_types) == 0:
print("WARNING: support_types is EMPTY for op", op_name)
return support_types
......
......@@ -46,6 +46,11 @@ class XPUTestLogicalAnd(XPUOpTestWrapper):
def set_case(self):
self.op_type = 'logical_and'
# special range for bool dtype
if self.dtype == np.dtype(np.bool):
self.low = 0
self.high = 2
x = np.random.randint(
self.low, self.high, self.x_shape, dtype=self.dtype
)
......@@ -62,7 +67,7 @@ class XPUTestLogicalAnd(XPUOpTestWrapper):
self.outputs = {'Out': out}
def init_case(self):
self.dtype = np.int32
self.dtype = self.in_type
self.x_shape = [2, 3, 4, 5]
self.y_shape = [2, 3, 4, 5]
self.low = -100
......@@ -76,7 +81,7 @@ class XPUTestLogicalAnd(XPUOpTestWrapper):
class XPUTestLogicalAndCase1(XPUTestLogicalAndBase):
def init_case(self):
self.dtype = np.int32
self.dtype = self.in_type
self.x_shape = [4, 5]
self.y_shape = [2, 3, 4, 5]
self.low = -100
......@@ -102,6 +107,11 @@ class XPUTestLogicalOr(XPUOpTestWrapper):
def set_case(self):
self.op_type = 'logical_or'
# special range for bool dtype
if self.dtype == np.dtype(np.bool):
self.low = 0
self.high = 2
x = np.random.randint(
self.low, self.high, self.x_shape, dtype=self.dtype
)
......@@ -118,7 +128,7 @@ class XPUTestLogicalOr(XPUOpTestWrapper):
self.outputs = {'Out': out}
def init_case(self):
self.dtype = np.int32
self.dtype = self.in_type
self.x_shape = [2, 3, 4, 5]
self.y_shape = [2, 3, 4, 5]
self.low = -100
......@@ -132,7 +142,7 @@ class XPUTestLogicalOr(XPUOpTestWrapper):
class XPUTestLogicalOrCase1(XPUTestLogicalOrBase):
def init_case(self):
self.dtype = np.int32
self.dtype = self.in_type
self.x_shape = [4, 5]
self.y_shape = [2, 3, 4, 5]
self.low = -100
......@@ -158,6 +168,11 @@ class XPUTestLogicalXor(XPUOpTestWrapper):
def set_case(self):
self.op_type = 'logical_xor'
# special range for bool dtype
if self.dtype == np.dtype(np.bool):
self.low = 0
self.high = 2
x = np.random.randint(
self.low, self.high, self.x_shape, dtype=self.dtype
)
......@@ -174,7 +189,7 @@ class XPUTestLogicalXor(XPUOpTestWrapper):
self.outputs = {'Out': out}
def init_case(self):
self.dtype = np.int64
self.dtype = self.in_type
self.x_shape = [2, 3, 4, 5]
self.y_shape = [2, 3, 4, 5]
self.low = -100
......@@ -188,7 +203,7 @@ class XPUTestLogicalXor(XPUOpTestWrapper):
class XPUTestLogicalXorCase1(XPUTestLogicalXorBase):
def init_case(self):
self.dtype = np.int32
self.dtype = self.in_type
self.x_shape = [4, 5]
self.y_shape = [2, 3, 4, 5]
self.low = -100
......@@ -214,6 +229,11 @@ class XPUTestLogicalNot(XPUOpTestWrapper):
def set_case(self):
self.op_type = 'logical_not'
# special range for bool dtype
if self.dtype == np.dtype(np.bool):
self.low = 0
self.high = 2
x = np.random.randint(
self.low, self.high, self.x_shape, dtype=self.dtype
)
......@@ -224,7 +244,7 @@ class XPUTestLogicalNot(XPUOpTestWrapper):
self.outputs = {'Out': out}
def init_case(self):
self.dtype = np.int32
self.dtype = self.in_type
self.x_shape = [2, 3, 4, 5]
self.low = -100
self.high = 100
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册