forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MetaSchedule] Rewrite Parallel-Vectorize-Unroll / Verify-GPU / Disal…
…low-Dynamic-Loops (apache#499) * wip fix * revoke change to gallery * split postprocessors to separate files * rename attrs * minor * minor tweak on utils.h * refactor disallow-dynamic-loop * refactor verify_gpu_code * succesfully give up refactoring parallelize-vectorize-unroll * python structuring * unittests Co-authored-by: Junru Shao <[email protected]>
- Loading branch information
1 parent
dcf7310
commit 996cf62
Showing
19 changed files
with
1,117 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
python/tvm/meta_schedule/postproc/disallow_dynamic_loop.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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. | ||
"""A postprocessor that checks if the IRModule has any loop with non-constant extent""" | ||
|
||
from tvm._ffi.registry import register_object | ||
from .. import _ffi_api | ||
from .postproc import Postproc | ||
|
||
|
||
@register_object("meta_schedule.DisallowDynamicLoop") | ||
class DisallowDynamicLoop(Postproc): | ||
"""A postprocessor that checks if the IRModule has any loop with non-constant extent""" | ||
|
||
def __init__(self) -> None: | ||
self.__init_handle_by_constructor__( | ||
_ffi_api.PostprocDisallowDynamicLoop, # type: ignore # pylint: disable=no-member | ||
) |
33 changes: 33 additions & 0 deletions
33
python/tvm/meta_schedule/postproc/rewrite_parallel_vectorize_unroll.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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. | ||
"""A postprocessor that applies parallelization, vectorization and auto unrolling | ||
according to the annotation of each block""" | ||
|
||
from tvm._ffi.registry import register_object | ||
from .. import _ffi_api | ||
from .postproc import Postproc | ||
|
||
|
||
@register_object("meta_schedule.RewriteParallelVectorizeUnroll") | ||
class RewriteParallelVectorizeUnroll(Postproc): | ||
"""A postprocessor that applies parallelization, vectorization and auto unrolling | ||
according to the annotation of each block""" | ||
|
||
def __init__(self) -> None: | ||
self.__init_handle_by_constructor__( | ||
_ffi_api.PostprocRewriteParallelVectorizeUnroll, # type: ignore # pylint: disable=no-member | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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. | ||
"""A postprocessor that verifies if the GPU code is correct""" | ||
|
||
from tvm._ffi.registry import register_object | ||
from .. import _ffi_api | ||
from .postproc import Postproc | ||
|
||
|
||
@register_object("meta_schedule.VerifyGPUCode") | ||
class VerifyGPUCode(Postproc): | ||
"""A postprocessor that verifies if the GPU code is correct""" | ||
|
||
def __init__(self) -> None: | ||
self.__init_handle_by_constructor__( | ||
_ffi_api.PostprocVerifyGPUCode, # type: ignore # pylint: disable=no-member | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
#include "../utils.h" | ||
|
||
namespace tvm { | ||
namespace tir { | ||
|
||
/*! \brief Check if the loop is dynamic. */ | ||
struct DynamicExtentFinder : private StmtVisitor { | ||
public: | ||
static bool Find(const IRModule& mod) { | ||
DynamicExtentFinder finder; | ||
for (const auto& kv : mod->functions) { | ||
const BaseFunc& func = kv.second; | ||
if (const auto* prim_func = func.as<PrimFuncNode>()) { | ||
finder(prim_func->body); | ||
if (finder.found_) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private: | ||
void VisitStmt_(const ForNode* loop) final { | ||
if (!loop->extent->IsInstance<IntImmNode>()) { | ||
found_ = true; | ||
} else { | ||
StmtVisitor::VisitStmt_(loop); | ||
} | ||
} | ||
|
||
void VisitStmt(const Stmt& stmt) final { | ||
if (!found_) { | ||
StmtVisitor::VisitStmt(stmt); | ||
} | ||
} | ||
|
||
bool found_ = false; | ||
}; | ||
|
||
} // namespace tir | ||
} // namespace tvm | ||
|
||
namespace tvm { | ||
namespace meta_schedule { | ||
|
||
using tir::Schedule; | ||
|
||
/*! \brief Check if the IRModule has any loop with non-constant extent. */ | ||
class DisallowDynamicLoopNode : public PostprocNode { | ||
public: | ||
// Inherited from PostprocNode | ||
void InitializeWithTuneContext(const TuneContext& context) final {} | ||
// Inherited from PostprocNode | ||
bool Apply(const tir::Schedule& sch) final { return !tir::DynamicExtentFinder::Find(sch->mod()); } | ||
|
||
static constexpr const char* _type_key = "meta_schedule.DisallowDynamicLoop"; | ||
TVM_DECLARE_FINAL_OBJECT_INFO(DisallowDynamicLoopNode, PostprocNode); | ||
}; | ||
|
||
Postproc Postproc::DisallowDynamicLoop() { | ||
ObjectPtr<DisallowDynamicLoopNode> n = make_object<DisallowDynamicLoopNode>(); | ||
return Postproc(n); | ||
} | ||
|
||
TVM_REGISTER_NODE_TYPE(DisallowDynamicLoopNode); | ||
TVM_REGISTER_GLOBAL("meta_schedule.PostprocDisallowDynamicLoop") | ||
.set_body_typed(Postproc::DisallowDynamicLoop); | ||
|
||
} // namespace meta_schedule | ||
} // namespace tvm |
Oops, something went wrong.