manupa-arm commented on a change in pull request #10725: URL: https://github.com/apache/tvm/pull/10725#discussion_r833107991
########## File path: src/tir/contrib/ethosu/passes.cc ########## @@ -0,0 +1,121 @@ +/* + * 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. + */ + +/*! + * \file tir/contrib/ethosu/passes.cc + * + * \brief Passes used in TIR lowering for the microNPU compiler. + */ +#include <tvm/tir/builtin.h> +#include <tvm/tir/function.h> +#include <tvm/tir/stmt_functor.h> +#include <tvm/tir/transform.h> + +namespace tvm { +namespace tir { +namespace contrib { +namespace ethosu { + +/*! + * \brief This mutator moves allocates to the top of the body of the main + * function. + * + * For example, + * allocate { + * extern_call(...) { + * allocate { + * Before: extern_call(...) + * } + * } + * } + * + * allocate { + * allocate { + * extern_call(...) + * After: extern_call(...) + * } + * } + */ +class HoistAllocatesMutator : public StmtExprMutator { + public: + HoistAllocatesMutator() {} + + IRModule operator()(IRModule mod) { + GlobalVar gv = mod->GetGlobalVar("main"); + PrimFunc main_func = Downcast<PrimFunc>(mod->Lookup(gv)); Review comment: ~This will break if the mod has a global relay function. I admit that will not be the case in the current integration. In the same time, I think we dont need this restriction. (i.e. looking at npu PrimFuncs should be sufficient for this pass). Also take look at the comment below about the possibility of making this a PrimFunc pass~ Sorry I got ahead of myself, what is the main PrimFunc here that is run on NPU ? -- 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]
