ekalda commented on a change in pull request #9530: URL: https://github.com/apache/tvm/pull/9530#discussion_r754432455
########## File path: python/tvm/relay/backend/contrib/ethosu/op/unary_elementwise.py ########## @@ -0,0 +1,153 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# pylint: disable=unused-argument +"""Relay operator for unary elementwise operations for Arm(R) Ethos(TM)-U NPU""" +import tvm +from tvm.relay.op import _make +from tvm.topi.generic import schedule_injective +from tvm.relay.op.op import OpStrategy +from tvm.relay.op import strategy as _strategy + +from ..te import unary_elementwise_compute + + +def _extract_ethosu_unary_elementwise_params(attrs, args): + """Get the parameters necessary to construct a ethosu_unary_elementwise compute TE + from a ethosu_unary_elementwise Relay call.""" + ifm = args[0] + lut = args[1] + operator_type = attrs.operator_type + ifm_scale = attrs.ifm_scale + ifm_zero_point = attrs.ifm_zero_point + ofm_scale = attrs.ofm_scale + ofm_zero_point = attrs.ofm_zero_point + ofm_channels = attrs.ofm_channels + activation = attrs.activation + clip_min = attrs.clip_min + clip_max = attrs.clip_max + ifm_layout = attrs.ifm_layout + ofm_layout = attrs.ofm_layout + + return ( + ifm, + lut, + operator_type, + ifm_scale, + ifm_zero_point, + ofm_scale, + ofm_zero_point, + ofm_channels, + activation, + clip_min, + clip_max, + ifm_layout, + ofm_layout, + ) + + [email protected]_op_attr("contrib.ethosu.unary_elementwise", "FTVMCompute") +def create_ethosu_unary_elementwise_compute(attrs, args, out_type): + """Create an ethosu_unary_elementwise compute op.""" + params = _extract_ethosu_unary_elementwise_params(attrs, args) + op = unary_elementwise_compute(*params) + return [op] + + [email protected]_op_attr("contrib.ethosu.unary_elementwise", "FTVMStrategy") +def unary_elementwise_strategy_ethosu(attrs, inputs, out_type, target): + strategy = OpStrategy() + strategy.add_implementation( + create_ethosu_unary_elementwise_compute, + _strategy.wrap_topi_schedule(schedule_injective), + name="ethosu_unary_elementwise", + ) + return strategy + + +def ethosu_unary_elementwise( + ifm: tvm.relay.Expr, + lut: tvm.relay.Expr, + operator_type: str, + ifm_scale: float, + ifm_zero_point: int, + ofm_scale: float, + ofm_zero_point: int, + ofm_channels: int, + activation: str = "NONE", + clip_min: int = 0, + clip_max: int = 0, + ifm_layout: str = "NHWC", + ofm_layout: str = "NHWC", Review comment: I added the type hints for the unary elementwise operator, maybe in the follow-up patch we can unify the use for all the operators? ########## File path: python/tvm/relay/op/contrib/ethosu.py ########## @@ -852,6 +854,60 @@ def strided_slice_pattern(): return pattern +class AbsParams: + """ + A class to extract and store parameters of Abs in an NPU friendly way + """ Review comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
