-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TOPI][x86] Introduce schedule_injective_from_existing and unify external schedules for all targets #3983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TOPI][x86] Introduce schedule_injective_from_existing and unify external schedules for all targets #3983
Changes from 1 commit
317186f
299a80b
d7b21f8
2616393
4fb7063
9df9010
2bdc1f1
09d5f0c
5c9e9f4
1e42314
7da8ea2
decbb5e
847bb5d
eab0b01
2496cd7
419f846
7aeac5e
b698a15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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 x86/extern.h | ||
| * \brief x86 schedule for extern followed by injective operations | ||
| */ | ||
| #ifndef TOPI_X86_EXTERN_H_ | ||
| #define TOPI_X86_EXTERN_H_ | ||
|
|
||
| #include "topi/tags.h" | ||
| #include "topi/detail/fuse.h" | ||
| #include "tvm/operation.h" | ||
| #include "tvm/build_module.h" | ||
|
|
||
| namespace topi { | ||
| using namespace tvm; | ||
|
|
||
| namespace x86 { | ||
| /*! | ||
| * \brief Schedule a given operation representing one of the outputs of an | ||
| * external function which is followed by injective operations. | ||
| * | ||
| * \param target The target to generate a schedule for. | ||
| * \param op The operation representing the output followed by injective operations. | ||
| * \param sch The schedule to apply this scheduling to | ||
| * | ||
| * \return The schedule given by sch | ||
| */ | ||
| inline Schedule ScheduleOutputForExtern(Target target, Operation op, Schedule sch) { | ||
| auto x = op.output(0); | ||
| auto axis = sch[x]->op.as<ComputeOpNode>()->axis; | ||
| if (axis.size() == 4) { | ||
| auto n = axis[0]; | ||
| auto c = axis[1]; | ||
| auto fused = detail::Fuse(sch[x], { n, c }); // for nhwc layout, fuse n and h | ||
| sch[x].parallel(fused); | ||
| } else { | ||
| sch[x].parallel(axis[0]); | ||
| } | ||
| return sch; | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Schedule an extern op followed by injective operations. | ||
| * For example, cudnn kernel + bias add + relu | ||
| * | ||
| * \param target The target to generate a schedule for. | ||
| * \param outs The output tensors. | ||
| * | ||
| * \return A schedule for the op. | ||
| */ | ||
| inline Schedule schedule_extern(const Target& target, Array<Tensor> outs) { | ||
|
soiferj marked this conversation as resolved.
Outdated
|
||
| Array<Operation> out_ops; | ||
| for (auto t : outs) { | ||
| out_ops.push_back(t->op); | ||
| } | ||
| auto s = create_schedule(out_ops); | ||
|
|
||
| tvm::schedule::AutoInlineInjective(s); | ||
| for (auto out : outs) { | ||
| if (out->op->derived_from<ExternOpNode>()) { | ||
| continue; | ||
| } | ||
| ScheduleOutputForExtern(target, out->op, s); | ||
| } | ||
|
|
||
| return s; | ||
| } | ||
|
|
||
| } // namespace x86 | ||
| } // namespace topi | ||
| #endif // TOPI_X86_EXTERN_H_ | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,12 @@ def schedule_extern(outs): | |
| sch: Schedule | ||
| The computation schedule for the op. | ||
| """ | ||
| target = tvm.target.current_target(allow_none=False) | ||
| if target.target_name != "llvm": | ||
| raise RuntimeError("schedule_extern not registered for '%s'" % target) | ||
| outs = [outs] if isinstance(outs, tvm.tensor.Tensor) else outs | ||
| return tvm.create_schedule([x.op for x in outs]) | ||
| s = tvm.create_schedule([x.op for x in outs]) | ||
|
|
||
| tvm.schedule.AutoInlineInjective(s) | ||
| for out in outs: | ||
| if isinstance(out.op, tvm.tensor.ExternOp): | ||
| continue | ||
| _schedule_injective(out.op, s) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vinx13, I have moved this logic from If it just calls the default one, it seems like I have to add a new file, Update: it seems like it does call the right one |
||
| return s | ||
Uh oh!
There was an error while loading. Please reload this page.