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.
[BACKEND] Vulkan Runtime and SPIRV Codegen (apache#861)
* [BACKEND] Vulkan Runtime and SPIRV Codegen * fix doc
- Loading branch information
Showing
50 changed files
with
3,869 additions
and
143 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
Submodule HalideIR
updated
3 files
+1 −1 | src/base/Util.h | |
+1 −1 | src/ir/Expr.h | |
+0 −92 | src/tvm/ir_functor.h |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Utility for Interacting with SPIRV Tools""" | ||
import subprocess | ||
import os | ||
from . import util | ||
|
||
|
||
def optimize(spv_bin): | ||
"""Optimize SPIRV using spirv-opt via CLI | ||
Note that the spirv-opt is still experimental. | ||
Parameters | ||
---------- | ||
spv_bin : bytearray | ||
The spirv file | ||
Return | ||
------ | ||
cobj_bin : bytearray | ||
The HSA Code Object | ||
""" | ||
|
||
tmp_dir = util.tempdir() | ||
tmp_in = tmp_dir.relpath("input.spv") | ||
tmp_out = tmp_dir.relpath("output.spv") | ||
with open(tmp_in, "wb") as out_file: | ||
out_file.write(bytes(spv_bin)) | ||
|
||
sdk = os.environ.get("VULKAN_SDK", None) | ||
cmd = os.path.join(sdk, "bin/spirv-opt") if sdk else "spirv-opt" | ||
args = [cmd, "-O", tmp_in, "-o", tmp_out] | ||
proc = subprocess.Popen( | ||
args, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT) | ||
(out, _) = proc.communicate() | ||
|
||
if proc.returncode != 0: | ||
msg = "Opitmizationerror using spirv-opt:\n" | ||
msg += str(out) | ||
raise RuntimeError(msg) | ||
|
||
return bytearray(open(tmp_out, "rb").read()) |
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
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,59 @@ | ||
/*! | ||
* Copyright (c) 2018 by Contributors | ||
* \file codegen_common.h | ||
* \brief Common utility for codegen. | ||
*/ | ||
#ifndef TVM_CODEGEN_CODEGEN_COMMON_H_ | ||
#define TVM_CODEGEN_CODEGEN_COMMON_H_ | ||
|
||
#include <tvm/arithmetic.h> | ||
#include "../arithmetic/compute_expr.h" | ||
|
||
namespace tvm { | ||
namespace codegen { | ||
|
||
/*! | ||
* \brief Visit AssertStmt recursively, update align_map from condition. | ||
* \param op The AssertStmt | ||
* \param align_map The alignmap | ||
* \param fvisit The recursive visitor | ||
* \tparam FVisit the recursive visitor | ||
*/ | ||
template<typename FVisit> | ||
inline void VisitAssert( | ||
const ir::AssertStmt* op, | ||
std::unordered_map<const Variable*, arith::ModularEntry>* align_map, | ||
FVisit fvisit) { | ||
using namespace ir; | ||
auto& align_map_ = *align_map; | ||
// Detect useful invariant pattern and use them to visit child. | ||
// Pattern: Var % const == 0 | ||
// TODO(tqchen) merge these pattern to a generic scope info visitor. | ||
if (const EQ* eq = op->condition.as<EQ>()) { | ||
const Mod* mod = eq->a.as<Mod>(); | ||
int64_t factor = 0, offset = 0; | ||
if (mod && arith::GetConst(eq->b, &offset)) { | ||
const Variable *var = mod->a.as<Variable>(); | ||
if (var && arith::GetConst(mod->b, &factor)) { | ||
arith::ModularEntry old = align_map_[var]; | ||
if (factor > old.coeff) { | ||
arith::ModularEntry e; | ||
e.coeff = static_cast<int>(factor); | ||
e.base = static_cast<int>(offset); | ||
// new alignment info, | ||
align_map_[var] = e; | ||
fvisit(op->body); | ||
// restore old info | ||
align_map_[var] = old; | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
fvisit(op->body); | ||
} | ||
|
||
} // namespace codegen | ||
} // namespace tvm | ||
|
||
#endif // TVM_CODEGEN_CODEGEN_COMMON_H_ |
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
Oops, something went wrong.