!2021 GPU add akg kernel greaterequal notequal
Merge pull request !2021 from VectorSL/gpu-add-akg-kernelpull/2021/MERGE
commit
87fa15de80
@ -0,0 +1,41 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""greater_equal"""
|
||||||
|
import _akg.tvm
|
||||||
|
from _akg.ops.math import greater_equal
|
||||||
|
from _akg.topi.generic import schedule_elemwise
|
||||||
|
|
||||||
|
def GreaterEqual(x, y):
|
||||||
|
"""GreaterEqual."""
|
||||||
|
return greater_equal.greater_equal(x, y)
|
||||||
|
|
||||||
|
|
||||||
|
def gpu_schedule_GreaterEqual(outs):
|
||||||
|
"""
|
||||||
|
GPU schedule for GreaterEqual.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
outs (tvm.tensor.Tensor): Outputs of compute.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
sch (schedule.Schedule): The created schedule.
|
||||||
|
"""
|
||||||
|
device = 'cuda'
|
||||||
|
ctx = _akg.tvm.context(device, 0)
|
||||||
|
if not ctx.exist:
|
||||||
|
raise SystemError("Skip because %s is not enabled" % device)
|
||||||
|
with _akg.tvm.target.create(device):
|
||||||
|
sch = schedule_elemwise(outs)
|
||||||
|
return sch
|
@ -0,0 +1,41 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""notequal"""
|
||||||
|
import _akg.tvm
|
||||||
|
from _akg.ops.math import notequal
|
||||||
|
from _akg.topi.generic import schedule_elemwise
|
||||||
|
|
||||||
|
def NotEqual(x, y):
|
||||||
|
"""notequal."""
|
||||||
|
return notequal.notequal(x, y)
|
||||||
|
|
||||||
|
|
||||||
|
def gpu_schedule_NotEqual(outs):
|
||||||
|
"""
|
||||||
|
gpu schedule for NotEqual.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
outs (tvm.tensor.Tensor): outputs of compute.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
sch (schedule.Schedule): The created schedule.
|
||||||
|
"""
|
||||||
|
device = 'cuda'
|
||||||
|
ctx = _akg.tvm.context(device, 0)
|
||||||
|
if not ctx.exist:
|
||||||
|
raise SystemError("Skip because %s is not enabled" % device)
|
||||||
|
with _akg.tvm.target.create(device):
|
||||||
|
sch = schedule_elemwise(outs)
|
||||||
|
return sch
|
@ -0,0 +1,54 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""operator dsl function: greaterequal"""
|
||||||
|
import _akg.tvm
|
||||||
|
import _akg.topi
|
||||||
|
from _akg.utils.dsl_create import produce_shapes
|
||||||
|
from _akg.utils import validation_check as vc_util
|
||||||
|
|
||||||
|
|
||||||
|
@vc_util.check_input_type(_akg.tvm.tensor.Tensor, _akg.tvm.tensor.Tensor)
|
||||||
|
def greater_equal(input1, input2):
|
||||||
|
"""
|
||||||
|
Check whether input1 greaterquals to input2.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input1 (tvm.tensor.Tensor): Tensor.
|
||||||
|
input2 (tvm.tensor.Tensor): Tensor.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
tvm.tensor.Tensor. If input1 greaterquals to input2 return True, else return False.
|
||||||
|
"""
|
||||||
|
shape1 = [x.value for x in input1.shape]
|
||||||
|
shape2 = [x.value for x in input2.shape]
|
||||||
|
vc_util.check_shape(shape1)
|
||||||
|
vc_util.check_shape(shape2)
|
||||||
|
|
||||||
|
shape1, shape2, shape = produce_shapes(shape1, shape2)
|
||||||
|
|
||||||
|
vc_util.elemwise_dtype_check(input1.dtype, input2.dtype)
|
||||||
|
dtype = input1.dtype
|
||||||
|
|
||||||
|
# get greaterquals compute
|
||||||
|
t_value = _akg.tvm.compute(shape, lambda *indice: _akg.tvm.const(1, dtype), "T")
|
||||||
|
f_value = _akg.tvm.compute(shape, lambda *indice: _akg.tvm.const(0, dtype), "F")
|
||||||
|
|
||||||
|
input1_bro = _akg.topi.broadcast_to(input1, shape)
|
||||||
|
input2_bro = _akg.topi.broadcast_to(input2, shape)
|
||||||
|
c_out = _akg.tvm.compute(shape, lambda *indice: _akg.tvm.expr.Select(input1_bro[indice] >= input2_bro[indice],
|
||||||
|
t_value[indice], f_value[indice]), name="C")
|
||||||
|
res = _akg.tvm.compute(shape, lambda *indice: c_out(*indice).astype("bool"), name="res")
|
||||||
|
|
||||||
|
return res
|
@ -0,0 +1,54 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""operator dsl function: notequal"""
|
||||||
|
import _akg.tvm
|
||||||
|
import _akg.topi
|
||||||
|
from _akg.utils.dsl_create import produce_shapes
|
||||||
|
from _akg.utils import validation_check as vc_util
|
||||||
|
|
||||||
|
|
||||||
|
@vc_util.check_input_type(_akg.tvm.tensor.Tensor, _akg.tvm.tensor.Tensor)
|
||||||
|
def notequal(input1, input2):
|
||||||
|
"""
|
||||||
|
check whether input1 notequals to input2.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input1 (tvm.tensor.Tensor): Tensor.
|
||||||
|
input2 (tvm.tensor.Tensor): Tensor.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
tvm.tensor.Tensor. If input1 notequal to input2 return True, else return False.
|
||||||
|
"""
|
||||||
|
shape1 = [x.value for x in input1.shape]
|
||||||
|
shape2 = [x.value for x in input2.shape]
|
||||||
|
vc_util.check_shape(shape1)
|
||||||
|
vc_util.check_shape(shape2)
|
||||||
|
|
||||||
|
shape1, shape2, shape = produce_shapes(shape1, shape2)
|
||||||
|
|
||||||
|
vc_util.elemwise_dtype_check(input1.dtype, input2.dtype)
|
||||||
|
dtype = input1.dtype
|
||||||
|
|
||||||
|
# get notequal compute
|
||||||
|
t_value = _akg.tvm.compute(shape, lambda *indice: _akg.tvm.const(1, dtype), "T")
|
||||||
|
f_value = _akg.tvm.compute(shape, lambda *indice: _akg.tvm.const(0, dtype), "F")
|
||||||
|
|
||||||
|
input1_bro = _akg.topi.broadcast_to(input1, shape)
|
||||||
|
input2_bro = _akg.topi.broadcast_to(input2, shape)
|
||||||
|
c_out = _akg.tvm.compute(shape, lambda *indice: _akg.tvm.expr.Select(input1_bro[indice] != input2_bro[indice],
|
||||||
|
t_value[indice], f_value[indice]), name="C")
|
||||||
|
res = _akg.tvm.compute(shape, lambda *indice: c_out(*indice).astype("bool"), name="res")
|
||||||
|
|
||||||
|
return res
|
@ -0,0 +1,32 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""GreaterEqual op"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register, AkgRegOp, DataType
|
||||||
|
|
||||||
|
greater_equal_op_info = AkgRegOp("GreaterEqual") \
|
||||||
|
.fusion_type("OPAQUE") \
|
||||||
|
.input(0, "x") \
|
||||||
|
.input(1, "y") \
|
||||||
|
.output(0, "output") \
|
||||||
|
.dtype_format(DataType.F16_Default, DataType.F16_Default, DataType.BOOL_Default) \
|
||||||
|
.dtype_format(DataType.F32_Default, DataType.F32_Default, DataType.BOOL_Default) \
|
||||||
|
.dtype_format(DataType.I32_Default, DataType.I32_Default, DataType.BOOL_Default) \
|
||||||
|
.get_op_info()
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register(greater_equal_op_info)
|
||||||
|
def _greater_equal_akg():
|
||||||
|
"""GreaterEqual register"""
|
||||||
|
return
|
@ -0,0 +1,32 @@
|
|||||||
|
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""NotEqual op"""
|
||||||
|
from mindspore.ops.op_info_register import op_info_register, AkgRegOp, DataType
|
||||||
|
|
||||||
|
notequal_op_info = AkgRegOp("NotEqual") \
|
||||||
|
.fusion_type("OPAQUE") \
|
||||||
|
.input(0, "x") \
|
||||||
|
.input(1, "y") \
|
||||||
|
.output(0, "output") \
|
||||||
|
.dtype_format(DataType.F16_Default, DataType.F16_Default, DataType.BOOL_Default) \
|
||||||
|
.dtype_format(DataType.F32_Default, DataType.F32_Default, DataType.BOOL_Default) \
|
||||||
|
.dtype_format(DataType.I32_Default, DataType.I32_Default, DataType.BOOL_Default) \
|
||||||
|
.get_op_info()
|
||||||
|
|
||||||
|
|
||||||
|
@op_info_register(notequal_op_info)
|
||||||
|
def _notequal_akg():
|
||||||
|
"""NotEqual AutoDiff register"""
|
||||||
|
return
|
Loading…
Reference in new issue