u99127 commented on a change in pull request #4258: [WIP][TVM] Bring Your Own Codegen to TVM URL: https://github.com/apache/incubator-tvm/pull/4258#discussion_r345448945
########## File path: tutorials/dev/custom_relay_backend.py ########## @@ -0,0 +1,291 @@ +# 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. +""" + +.. _tutorial-custom-relay-backend + +Bring Your Own Codegen To TVM +============================================ +**Author**: `Zhi Chen <https://github.com/zhiics>`_, `Cody Hao Yu <https:://github.com/comaniac>`_ + +As the hardware devices targeted by deep learning workloads keep increasing, the required knowledge +for users to achieve high performance on various devices keeps increasing as well. To free data +scientists from worrying about the performance when developing a new model, hardware vendors either +provide libraries such as MKLDNN or cuDNN with many commonly used deep learning operators, +or provide frameworks such as TensorRT to let users describle their models in a certain way to +achieve high performance. However, users have to learn a new programming interface when they +attempt to work on a new libaray or device. As a result, the demand of a unified programming +interface becomes more and more important to 1) let all users and hardware vendors stand on the +same page, and 2) provide a feasible solution to allow a specialized hardware or library to only +support widely used operators with extremely high perofrmance, but fallback unsupported operators +to general devices like CPU/GPU. + +In this tutorial, we demonstrate how a hardware vendor can easily implement +a Relay backend to support a specialized hardware device/library. It mainly +takes three steps: 1) define whether an operator is supported under a given +template, 2) specify how to compile and serialize the supported operators so +that it can ingest TVM specific data format, e.g. NDArray, and 3) specify how +to execute the compiled operators on a certain device. We will demonstrate how +to add a new backend that uses open source compilers (e.g. GCC, LLVM, etc) or any +proprietary compilers to execute a subgraph of a model without the exposure of +the IP of customer's codegen tool chain. Note that you will need to add the +specialized Relay backend to the TVM codebase and rebuild TVM for enabling. + +""" + +###################################################################### +# Define The Supported Operators +# ------------------------------ +# The first step is to define which operators are supported by your backend. Review comment: Can we support any dialect operators as well ? Should we make that explicit ? I'd be interested in the qnn dialect to play with this. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
