提交 1c2f391d 编写于 作者: L looop5

fix dump code error when running gpu operators and set env MS_AKG_DUMP_CODE=ON

上级 60f105c9
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <unistd.h>
#include <sys/stat.h>
#include "build_module.h" #include "build_module.h"
#include "pass/expr_alg_simplify.h" #include "pass/expr_alg_simplify.h"
...@@ -1059,13 +1061,32 @@ BuildRst BuildToFunc(const Schedule &inputs, const Array<NodeRef> &in_args, cons ...@@ -1059,13 +1061,32 @@ BuildRst BuildToFunc(const Schedule &inputs, const Array<NodeRef> &in_args, cons
} }
namespace { namespace {
void CreateCce(const std::string &code, const std::string &kernel_name) { void CreateCode(const std::string &code, const std::string &kernel_name, const std::string &target_name) {
std::string file_name = kMsDavinciKernelPath; std::string file_path;
file_name.append(kernel_name).append(".cce"); std::string file_suffix;
std::ofstream of(file_name); if (target_name.find("cce") != std::string::npos) {
CHECK(of.is_open()) << "Failed to open " << file_name << " to dump cce."; file_path = std::string(kMsDavinciKernelPath);
of << code << std::endl; file_suffix = ".cce";
of.close(); } else if (target_name.find("cuda") != std::string::npos) {
file_path = std::string(kMsGpuKernelPath) + "_" + std::to_string(getpid()) + "/";
file_suffix = ".cu";
}
if (file_path.empty()) {
return;
}
// Dump code to meta directory if it exists.
struct stat info;
if (stat(file_path.c_str(), &info) == 0) {
if (info.st_mode & S_IFDIR) {
std::string file_name = file_path + kernel_name + file_suffix;
std::ofstream of(file_name);
CHECK(of.is_open()) << "Failed to open " << file_name << " to dump code.";
of << code << std::endl;
of.close();
}
}
} }
} // namespace } // namespace
...@@ -1115,7 +1136,7 @@ air::runtime::Module BuildToModule(const NodeRef &ref, const std::string &target ...@@ -1115,7 +1136,7 @@ air::runtime::Module BuildToModule(const NodeRef &ref, const std::string &target
auto mod0 = mhost->imports()[0]; auto mod0 = mhost->imports()[0];
CHECK(mod0.defined()); CHECK(mod0.defined());
CreateCce(mod0->GetSource(), build_rst->kernel_name); CreateCode(mod0->GetSource(), build_rst->kernel_name, target_name);
} }
return mhost; return mhost;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
namespace akg { namespace akg {
constexpr auto kMsDavinciKernelPath = "./kernel_meta/"; constexpr auto kMsDavinciKernelPath = "./kernel_meta/";
constexpr auto kMsGpuKernelPath = "./cuda_meta";
static std::unordered_map<std::string, air::Type> type_mapping = { static std::unordered_map<std::string, air::Type> type_mapping = {
{"float32", air::Float(32)}, {"float16", air::Float(16)}, {"int32", air::Int(32)}, {"bool", air::Bool()}}; {"float32", air::Float(32)}, {"float16", air::Float(16)}, {"int32", air::Int(32)}, {"bool", air::Bool()}};
} // namespace akg } // namespace akg
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册