forked from mindspore-Ecosystem/mindspore
!19389 ascend compile reconstruct
Merge pull request !19389 from liubuyu/compile_re
This commit is contained in:
commit
9eb414b768
|
@ -179,8 +179,6 @@ def get_options_info(job_content):
|
|||
options["op_debug_level"] = job_content["SocInfo"]["op_debug_level"]
|
||||
options["op_impl_mode"] = job_content["SocInfo"]["op_impl_mode"]
|
||||
options["op_debug_dir"] = job_content["SocInfo"]["op_debug_dir"]
|
||||
options["op_compiler_cache_dir"] = job_content["SocInfo"]["op_compiler_cache_dir"]
|
||||
options["op_compiler_cache_mode"] = job_content["SocInfo"]["op_compiler_cache_mode"]
|
||||
options["mdl_bank_path"] = job_content["SocInfo"]["op_debug_level"]
|
||||
options["op_bank_path"] = job_content["SocInfo"]["op_bank_path"]
|
||||
options["deviceId"] = job_content["SocInfo"]["deviceId"]
|
||||
|
|
|
@ -71,12 +71,13 @@ def _get_message(msg, args):
|
|||
class TbeJob:
|
||||
""" Tbe compilation job """
|
||||
|
||||
def __init__(self, source_id, job_id, job_type, content, json_str, sys_info):
|
||||
def __init__(self, source_id, job_id, job_type, content, fusion_op_name, json_str, sys_info):
|
||||
self.source_id = source_id
|
||||
self.id = job_id
|
||||
self.type = JobType(job_type)
|
||||
self.status = JobStatus.JOB_INITIAL
|
||||
self.content = content
|
||||
self.fusion_op_name = fusion_op_name
|
||||
self.result = ""
|
||||
self.process_info = []
|
||||
self.json_string = json_str
|
||||
|
@ -149,6 +150,7 @@ class TbeJob:
|
|||
result["source_id"] = self.source_id
|
||||
result["job_id"] = self.id
|
||||
result["job_type"] = self.type.value
|
||||
result["fusion_op_name"] = self.fusion_op_name
|
||||
result["result"] = self.result
|
||||
self.debug("Resp result:{}".format(json.dumps(result)))
|
||||
process_info = []
|
||||
|
|
|
@ -102,7 +102,9 @@ class TbeJobManager:
|
|||
source_id = job_json["source_id"]
|
||||
job_type = job_json["job_type"]
|
||||
sys_info = self._get_job_sys_info()
|
||||
job = TbeJob(source_id, job_id, job_type, job_json["job_content"], job_str, sys_info)
|
||||
fusion_op_name = "NA" if "fusion_op_name" not in job_json["job_content"] else job_json["job_content"][
|
||||
"fusion_op_name"]
|
||||
job = TbeJob(source_id, job_id, job_type, job_json["job_content"], fusion_op_name, job_str, sys_info)
|
||||
job.debug("Req job string: {}".format(job_str))
|
||||
post_job(self._all_jobs, job)
|
||||
if not self.tbe_initialize and job.type != JobType.INITIALIZE_JOB:
|
||||
|
@ -115,6 +117,7 @@ class TbeJobManager:
|
|||
return res
|
||||
# pylint: disable=broad-except
|
||||
except Exception:
|
||||
# pylint: disable=no-value-for-parameter
|
||||
sys_info = self._get_job_sys_info()
|
||||
job = TbeJob(-1, -1, "", None, job_str, sys_info) if job is None else job
|
||||
job.status = JobStatus.JOB_FAILED
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
namespace mindspore {
|
||||
namespace kernel {
|
||||
KernelPackPtr AkgAscendKernelBuilder::AkgSearchCache(const std::string &kernel_name) {
|
||||
return tbe::TbeUtils::SearchCache(kernel_name, kProcessorAiCore);
|
||||
return tbe::TbeUtils::SearchCache(kernel_name, true);
|
||||
}
|
||||
|
||||
KernelPackPtr AkgAscendKernelBuilder::AkgInsertCache(const std::string &kernel_name) {
|
||||
return tbe::TbeUtils::InsertCache(kernel_name, kProcessorAiCore);
|
||||
return tbe::TbeUtils::InsertCache(kernel_name, kProcessorAiCore, true);
|
||||
}
|
||||
|
||||
void AkgAscendKernelBuilder::AkgSetKernelMod(const KernelPackPtr &kernel_pack,
|
||||
|
|
|
@ -197,7 +197,7 @@ void KernelPack::ParseKernelJson(const nlohmann::json &js) {
|
|||
kernel_json_info_.sha256 = js["sha256"];
|
||||
}
|
||||
|
||||
bool KernelPack::LoadKernelMeta(const std::string &json_f, const std::string &processor) {
|
||||
bool KernelPack::LoadKernelMeta(const std::string &json_f) {
|
||||
if (json_f.length() <= strlen(kJsonSuffix)) {
|
||||
MS_LOG(ERROR) << "please check json path.";
|
||||
return false;
|
||||
|
|
|
@ -128,7 +128,7 @@ class KernelPack {
|
|||
KernelPack() : json_(nullptr), kernel_(nullptr) {}
|
||||
KernelPack(const KernelPack &) = default;
|
||||
KernelJsonInfo kernel_json_info() const;
|
||||
bool LoadKernelMeta(const std::string &json_f, const std::string &processor);
|
||||
bool LoadKernelMeta(const std::string &json_f);
|
||||
bool ReadFromJsonFile(const std::string &json_f, const std::string &processor);
|
||||
const FlexArray *GetJson() const { return json_; }
|
||||
const FlexArray *GetKernel() const { return kernel_; }
|
||||
|
|
|
@ -92,7 +92,7 @@ std::map<int64_t, KernelModPtr> KernelFusion(const std::vector<FusionScopeInfo>
|
|||
continue;
|
||||
}
|
||||
// search cache
|
||||
auto kernel_pack = TbeUtils::SearchCache(json_name, tbe::kProcessorAiCore);
|
||||
auto kernel_pack = TbeUtils::SearchCache(json_name);
|
||||
if (kernel_pack != nullptr && ((!offline_tune.empty() && offline_tune != "true") || tune_mode == "NO_TUNE")) {
|
||||
auto kernel_mod = build_manger->GenKernelMod(input_size_list, output_size_list, kernel_pack);
|
||||
if (kernel_mod != nullptr) {
|
||||
|
|
|
@ -0,0 +1,754 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed 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 "backend/kernel_compiler/tbe/ascend_kernel_compile.h"
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include "mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_json/tbe_json_creator.h"
|
||||
#include "mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_json/single_tbe_json_creator.h"
|
||||
#include "mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_json/fusion_tbe_json_creator.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_utils.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_convert_utils.h"
|
||||
#include "backend/session/anf_runtime_algorithm.h"
|
||||
#include "debug/anf_ir_dump.h"
|
||||
#include "frontend/operator/ops.h"
|
||||
#include "utils/ms_context.h"
|
||||
#include "utils/ms_utils.h"
|
||||
#include "utils/trace_base.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/json_operation_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
namespace ascend {
|
||||
using mindspore::kernel::tbe::TbeAdapter;
|
||||
using mindspore::kernel::tbe::TbeUtils;
|
||||
const int indent = 4; // for dump json
|
||||
constexpr auto kInitialize = "Initialize";
|
||||
constexpr auto kPreCompile = "PreCompile";
|
||||
constexpr auto kFinalize = "Finalize";
|
||||
constexpr auto kCompile = "Compile";
|
||||
constexpr auto kTune = "Tune";
|
||||
constexpr auto kOfflineTune = "offlineTune";
|
||||
constexpr auto kCheckSupport = "CheckSupport";
|
||||
constexpr auto kSelectFormat = "SelectFormat";
|
||||
constexpr auto kFullySupported = "FULLY_SUPPORTED";
|
||||
constexpr auto kLevel = "level";
|
||||
constexpr auto kMessage = "message";
|
||||
constexpr auto kIndex = "index";
|
||||
constexpr auto kStatus = "status";
|
||||
constexpr auto kJobType = "job_type";
|
||||
constexpr auto kJobId = "job_id";
|
||||
constexpr auto kSourceId = "source_id";
|
||||
constexpr auto kTuneMode = "tune_mode";
|
||||
constexpr auto kTuneType = "tune_type";
|
||||
constexpr auto kJobContent = "job_content";
|
||||
constexpr auto kProcessInfo = "process_info";
|
||||
constexpr auto kReturnValue = "return_value";
|
||||
constexpr auto kFusionOpName = "fusion_op_name";
|
||||
constexpr auto kResult = "result";
|
||||
constexpr auto kOpList = "op_list";
|
||||
constexpr auto kSuccess = "SUCCESS";
|
||||
constexpr auto kRunning = "RUNNING";
|
||||
constexpr auto kFailed = "FAILED";
|
||||
constexpr auto kQuery = "Query";
|
||||
constexpr auto kTrue = "True";
|
||||
constexpr auto kGLOG_v = "GLOG_v";
|
||||
constexpr auto kSocInfo = "SocInfo";
|
||||
constexpr auto kTuneInfo = "TuneInfo";
|
||||
constexpr auto kLicInfo = "LicInfo";
|
||||
constexpr auto kTuneOpList = "tune_op_list";
|
||||
constexpr auto kProcessNum = "process_num";
|
||||
constexpr auto kLogLevel = "log_level";
|
||||
constexpr auto kEnableEvent = "enable_event";
|
||||
constexpr auto kTuneDumpPath = "tune_dump_path";
|
||||
constexpr auto kTuneBankPath = "tune_bank_path";
|
||||
constexpr auto kTbeImplPath = "tbe_impl_path";
|
||||
constexpr auto kParaDebugPath = "para_debug_path";
|
||||
constexpr auto kMS_BUILD_PROCESS_NUM = "MS_BUILD_PROCESS_NUM";
|
||||
constexpr auto kMS_PARA_DEBUG_PATH = "MS_PARA_DEBUG_PATH";
|
||||
constexpr auto kTBE_IMPL_PATH = "MS_TBE_IMPL_PATH";
|
||||
constexpr auto kTUNE_OPS_NAME = "MS_TUNE_OPS_NAME";
|
||||
constexpr auto kDefPath = "/usr/local/HiAI/runtime/ops/op_impl/built-in/ai_core/tbe/";
|
||||
constexpr auto kBkPath = "/usr/local/Ascend/opp/op_impl/built-in/ai_core/tbe/";
|
||||
constexpr int sleep_time = 2;
|
||||
constexpr int tune_sleep_time = 10;
|
||||
constexpr int kFusionLogLevel = 1;
|
||||
|
||||
namespace {
|
||||
inline bool Order(const nlohmann::json &json1, const nlohmann::json &json2) {
|
||||
return json1[kIndex].dump() > json2[kIndex].dump();
|
||||
}
|
||||
|
||||
void PrintInfo(const nlohmann::json &info, const std::string &job_name, const int job_id, int adjust_log_level) {
|
||||
auto level = GetJsonValue<int>(info, kLevel);
|
||||
level = level > adjust_log_level ? adjust_log_level : level;
|
||||
auto message = GetJsonValue<std::string>(info, kMessage);
|
||||
if (level == 0) {
|
||||
MS_LOG(DEBUG) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
|
||||
} else if (level == 1) {
|
||||
MS_LOG(INFO) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
|
||||
} else if (level == 2) {
|
||||
MS_LOG(WARNING) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
|
||||
} else if (level == 3) {
|
||||
MS_LOG(ERROR) << "Job id:" << job_id << ", name :" << job_name << ", message:" << message;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GetProcessNum() {
|
||||
uint32_t process_num = 24;
|
||||
auto env_process_num = common::GetEnv(kMS_BUILD_PROCESS_NUM);
|
||||
if (!env_process_num.empty()) {
|
||||
try {
|
||||
process_num = UlongToUint(std::stoul(env_process_num));
|
||||
} catch (std::invalid_argument &e) {
|
||||
MS_LOG(EXCEPTION) << "Invalid MS_BUILD_PROCESS_NUM env:" << env_process_num
|
||||
<< ". Please set the value of MS_BUILD_PROCESS_NUM in [0, 24]";
|
||||
}
|
||||
}
|
||||
return process_num;
|
||||
}
|
||||
|
||||
int StrToInt(const char *env) {
|
||||
if (env == nullptr) {
|
||||
return WARNING;
|
||||
}
|
||||
if (strcmp(env, "0") == 0) return DEBUG;
|
||||
if (strcmp(env, "1") == 0) return INFO;
|
||||
if (strcmp(env, "2") == 0) return WARNING;
|
||||
if (strcmp(env, "3") == 0) return ERROR;
|
||||
return WARNING;
|
||||
}
|
||||
|
||||
int GetLogLevel() {
|
||||
static const char *env = std::getenv(kGLOG_v);
|
||||
static int ms_level = StrToInt(env);
|
||||
return ms_level;
|
||||
}
|
||||
|
||||
std::string GetParaDebugPath() {
|
||||
auto save_path = common::GetEnv(kMS_PARA_DEBUG_PATH);
|
||||
char real_path[PATH_MAX] = {0};
|
||||
if (!save_path.empty()) {
|
||||
if (realpath(save_path.c_str(), real_path)) {
|
||||
save_path = real_path;
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "Invalid env PARA_DEBUG_PATH, path : " << save_path;
|
||||
}
|
||||
} else {
|
||||
save_path = "";
|
||||
}
|
||||
return save_path;
|
||||
}
|
||||
|
||||
std::string GetTbePath() {
|
||||
auto save_path = common::GetEnv(kTBE_IMPL_PATH);
|
||||
char real_path[PATH_MAX] = {0};
|
||||
if (!save_path.empty()) {
|
||||
if (realpath(save_path.c_str(), real_path)) {
|
||||
save_path = real_path;
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "Invalid env TBE_IMPL_PATH, path : " << save_path;
|
||||
}
|
||||
} else {
|
||||
if (realpath(kDefPath, real_path)) {
|
||||
save_path = real_path;
|
||||
} else if (realpath(kBkPath, real_path)) {
|
||||
save_path = real_path;
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "Can not get access to [" << kDefPath << "] or [" << kBkPath << "]";
|
||||
}
|
||||
}
|
||||
return save_path;
|
||||
}
|
||||
|
||||
std::vector<std::string> GetTuneOpsList(const std::string &d) {
|
||||
std::vector<string> res;
|
||||
auto ops = common::GetEnv(kTUNE_OPS_NAME);
|
||||
if (ops.empty()) {
|
||||
return {};
|
||||
}
|
||||
size_t p1 = 0;
|
||||
size_t p2 = ops.find(d);
|
||||
while (p2 != std::string::npos) {
|
||||
res.emplace_back(ops.substr(p1, p2 - p1));
|
||||
p1 = p2 + 1;
|
||||
p2 = ops.find(d, p1);
|
||||
}
|
||||
if (p1 != ops.length()) {
|
||||
res.emplace_back(ops.substr(p1));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void AscendKernelCompileManager::ResetOldTask() {
|
||||
if (build_manager_ != nullptr) {
|
||||
build_manager_->ResetTaskInfo();
|
||||
}
|
||||
job_list_.clear();
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::PrintProcessLog(const nlohmann::json &json, int adjust_log_level = 3) {
|
||||
auto logs = GetJsonValue<std::vector<nlohmann::json>>(json, kProcessInfo);
|
||||
auto job_id = GetJsonValue<int>(json, kJobId);
|
||||
auto json_name = GetJsonValue<std::string>(json, kFusionOpName);
|
||||
std::vector<nlohmann::json> all_logs;
|
||||
std::copy(logs.begin(), logs.end(), std::back_inserter(all_logs));
|
||||
std::sort(all_logs.begin(), all_logs.end(), Order);
|
||||
for (const auto &item : all_logs) {
|
||||
PrintInfo(item, json_name, job_id, adjust_log_level);
|
||||
}
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::PrintInitResult(const nlohmann::json &json) {
|
||||
auto job_type = GetJsonValue<std::string>(json, kJobType);
|
||||
auto json_name = GetJsonValue<std::string>(json, kFusionOpName);
|
||||
MS_LOG(DEBUG) << "Job: " << job_type << " post processing.";
|
||||
PrintProcessLog(json);
|
||||
if (json.at(kStatus) == kFailed) {
|
||||
MS_LOG(EXCEPTION) << "Job " << job_type << " running failed, job_id: " << json.at(kJobId)
|
||||
<< ", source_id: " << json[kSourceId] << ".";
|
||||
}
|
||||
MS_LOG(INFO) << "Job: " << job_type << " running success, job id: " << json.at(kJobId) << ", " << json_name;
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::PrintSingleBuildResult(const nlohmann::json &json) {
|
||||
auto job_type = GetJsonValue<std::string>(json, kJobType);
|
||||
auto json_name = GetJsonValue<std::string>(json, kFusionOpName);
|
||||
MS_LOG(DEBUG) << "Job: " << job_type << " post process";
|
||||
PrintProcessLog(json);
|
||||
if (json.at(kStatus) == kFailed) {
|
||||
MS_LOG(ERROR) << "Job " << job_type << " running failed, job_id: " << json.at(kJobId) << ", : " << json_name;
|
||||
return;
|
||||
}
|
||||
MS_LOG(INFO) << "Job " << job_type << " running " << json.at(kStatus) << ", job id: " << json.at(kJobId) << ", "
|
||||
<< json_name;
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::PrintFusionOpBuildResult(const nlohmann::json &json) {
|
||||
auto job_type = GetJsonValue<std::string>(json, kJobType);
|
||||
auto json_name = GetJsonValue<std::string>(json, kFusionOpName);
|
||||
MS_LOG(DEBUG) << "Job: " << job_type << " post process";
|
||||
PrintProcessLog(json, kFusionLogLevel);
|
||||
if (json.at(kStatus) == kFailed) {
|
||||
MS_LOG(INFO) << "Job fusion running failed, job_id: " << json.at(kJobId) << ", " << json_name;
|
||||
return;
|
||||
}
|
||||
MS_LOG(INFO) << "Job " << job_type << " running " << json.at(kStatus) << ", job id: " << json.at(kJobId) << ", "
|
||||
<< json_name;
|
||||
}
|
||||
|
||||
std::string AscendKernelCompileManager::FormatSelectResultProcess(const nlohmann::json &json) {
|
||||
// for check supported and format select
|
||||
auto job_type = GetJsonValue<std::string>(json, kJobType);
|
||||
auto json_name = GetJsonValue<std::string>(json, kFusionOpName);
|
||||
MS_LOG(DEBUG) << "Job: " << job_type << " post process";
|
||||
PrintProcessLog(json);
|
||||
if (json.at(kStatus) == kFailed) {
|
||||
MS_LOG(EXCEPTION) << "Job:" << job_type << " running failed, job_id: " << json.at(kJobId) << ", " << json_name;
|
||||
}
|
||||
auto res = GetJsonValue<std::string>(json, kResult);
|
||||
MS_LOG(INFO) << "Job:" << job_type << " running success, id: " << json.at(kJobId) << ", " << json_name
|
||||
<< ", get: " << res;
|
||||
return res;
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::QueryResultProcess(const nlohmann::json &json, TargetJobStatus *task_info,
|
||||
int adjust_log_level = 3) {
|
||||
auto job_type = GetJsonValue<std::string>(json, kJobType);
|
||||
auto json_name = GetJsonValue<std::string>(json, kFusionOpName);
|
||||
MS_LOG(DEBUG) << "Job: " << job_type << " post processing";
|
||||
if (GetJsonValue<std::string>(json, kStatus) == kSuccess) {
|
||||
nlohmann::json query_result;
|
||||
if (!ParseJson(GetJsonValue<std::string>(json, kResult), &query_result)) {
|
||||
MS_LOG(EXCEPTION) << "Parse query result error.";
|
||||
}
|
||||
auto target_job_id = query_result.at(kJobId);
|
||||
auto target_status = query_result.at(kStatus);
|
||||
task_info->target_job_id = target_job_id;
|
||||
// target job result
|
||||
auto target_job = query_result.at(kJobType);
|
||||
if (target_status == kSuccess) {
|
||||
MS_LOG(DEBUG) << "Target job: " << target_job << " running success, job id: " << target_job_id << ", "
|
||||
<< json_name;
|
||||
task_info->job_status = kSuccess;
|
||||
return;
|
||||
} else if (target_status != kSuccess && target_status != kRunning) {
|
||||
MS_LOG(INFO) << "Target job running failed, target_job_type:" << target_job << ", job id: " << target_job_id
|
||||
<< ", target_result: " << query_result.dump();
|
||||
task_info->job_status = kFailed;
|
||||
}
|
||||
PrintProcessLog(query_result, adjust_log_level);
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json AscendKernelCompileManager::TurnStrToJson(const std::string &string) {
|
||||
nlohmann::json json;
|
||||
if (!ParseJson(string, &json)) {
|
||||
MS_LOG(EXCEPTION) << "Parse build result error.";
|
||||
}
|
||||
if (!json.is_object()) {
|
||||
MS_LOG(EXCEPTION) << "Json str is not an object, str: " << string;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::ParseTargetJobStatus(const std::string &type, const std::string &build_result,
|
||||
std::vector<int> *success_job) {
|
||||
MS_EXCEPTION_IF_NULL(success_job);
|
||||
auto json_obj = TurnStrToJson(build_result);
|
||||
if (json_obj.at(kStatus) == kSuccess) {
|
||||
nlohmann::json query_obj;
|
||||
if (!ParseJson(GetJsonValue<std::string>(json_obj, kResult), &query_obj)) {
|
||||
MS_LOG(EXCEPTION) << "Parse query result error.";
|
||||
}
|
||||
struct TargetJobStatus task_info;
|
||||
QueryResultProcess(json_obj, &task_info);
|
||||
if (task_info.job_status == kSuccess) {
|
||||
MS_LOG(DEBUG) << "Job " << GetJsonValue<std::string>(query_obj, kJobType) << " running success.";
|
||||
std::string build_result = GetJsonValue<std::string>(query_obj, kResult);
|
||||
if (type == kPreCompile) {
|
||||
build_manager_->PreTaskFinishProcess(task_info.target_job_id, build_result);
|
||||
} else {
|
||||
build_manager_->TaskFinishProcess(task_info.target_job_id, build_result);
|
||||
}
|
||||
success_job->emplace_back(task_info.target_job_id);
|
||||
} else if (task_info.job_status == kFailed) {
|
||||
if (type == kPreCompile) {
|
||||
success_job->emplace_back(task_info.target_job_id);
|
||||
MS_LOG(WARNING) << "Single op pre build failed ,res: " << query_obj;
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "Single op compile failed ,res: " << query_obj;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto file_name = GetJsonValue<std::string>(json_obj, kJobType) + "_" + json_obj.at(kJobId).dump();
|
||||
TbeUtils::SaveJsonInfo(file_name, build_result);
|
||||
MS_LOG(EXCEPTION) << "Query job failed";
|
||||
}
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::QueryFinishJob(const std::string &job_type) {
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
while (!job_list_.empty()) {
|
||||
std::vector<int> success_job;
|
||||
auto iter = job_list_.begin();
|
||||
while (iter != job_list_.end()) {
|
||||
nlohmann::json query_json;
|
||||
auto kernel_json = iter->second;
|
||||
JsonAssemble(kQuery, kernel_json, &query_json);
|
||||
auto build_result = build_manager_->ProcessTbeJob(query_json);
|
||||
ParseTargetJobStatus(job_type, build_result, &success_job);
|
||||
iter++;
|
||||
}
|
||||
for (auto k : success_job) {
|
||||
job_list_.erase(k);
|
||||
}
|
||||
success_job.clear();
|
||||
if (!job_list_.empty()) {
|
||||
int s_time = is_tune_flag_ ? tune_sleep_time : sleep_time;
|
||||
sleep(s_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::QueryFusionFinishJob(KernelModMap *kernel_mode_ret) {
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mode_ret);
|
||||
int build_failed_nums = 0;
|
||||
while (!job_list_.empty()) {
|
||||
std::vector<int> success_job;
|
||||
auto iter = job_list_.begin();
|
||||
while (iter != job_list_.end()) {
|
||||
nlohmann::json query_json;
|
||||
auto kernel_json = iter->second;
|
||||
JsonAssemble(kQuery, kernel_json, &query_json);
|
||||
auto build_result = build_manager_->ProcessTbeJob(query_json);
|
||||
auto json_obj = TurnStrToJson(build_result);
|
||||
if (json_obj.at(kStatus) == kSuccess) {
|
||||
struct TargetJobStatus task_info;
|
||||
QueryResultProcess(json_obj, &task_info);
|
||||
if (task_info.job_status == kSuccess) {
|
||||
MS_LOG(DEBUG) << "Job " << GetJsonValue<std::string>(json_obj, kJobType) << " running success.";
|
||||
std::string build_res = GetJsonValue<std::string>(json_obj, kResult);
|
||||
auto kernel_mode_item = build_manager_->TaskFinishProcess(task_info.target_job_id, build_res, false);
|
||||
if (kernel_mode_item.second != nullptr) {
|
||||
(void)kernel_mode_ret->emplace(kernel_mode_item);
|
||||
}
|
||||
success_job.emplace_back(task_info.target_job_id);
|
||||
} else if (task_info.job_status == kFailed) {
|
||||
MS_LOG(INFO) << "FusionOp compile failed.";
|
||||
auto target_id = task_info.target_job_id;
|
||||
success_job.emplace_back(target_id);
|
||||
build_failed_nums += 1;
|
||||
}
|
||||
} else {
|
||||
auto file_name = GetJsonValue<std::string>(json_obj, kJobType) + "_" + json_obj.at(kJobId).dump();
|
||||
TbeUtils::SaveJsonInfo(file_name, json_obj.dump());
|
||||
PrintProcessLog(json_obj);
|
||||
MS_LOG(EXCEPTION) << "Query job Failed";
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
for (auto k : success_job) {
|
||||
job_list_.erase(k);
|
||||
}
|
||||
success_job.clear();
|
||||
if (!job_list_.empty()) {
|
||||
int s_time = is_tune_flag_ ? tune_sleep_time : sleep_time;
|
||||
sleep(s_time);
|
||||
}
|
||||
}
|
||||
MS_LOG(INFO) << "Compile Fusion Kernel Failed Num: " << build_failed_nums;
|
||||
}
|
||||
|
||||
bool AscendKernelCompileManager::JsonAssemble(const std::string &job_type, const nlohmann::json &src_json,
|
||||
nlohmann::json *dst_json) {
|
||||
MS_EXCEPTION_IF_NULL(src_json);
|
||||
MS_EXCEPTION_IF_NULL(dst_json);
|
||||
static size_t job_id = 0;
|
||||
static auto context_ptr = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
static int source_id = context_ptr->get_param<uint32_t>(MS_CTX_DEVICE_ID);
|
||||
(*dst_json)[kJobType] = job_type;
|
||||
(*dst_json)[kJobId] = job_id++;
|
||||
(*dst_json)[kSourceId] = source_id;
|
||||
if (job_type == kInitialize || job_type == kFinalize) {
|
||||
nlohmann::json job_info;
|
||||
static auto process_num = GetProcessNum();
|
||||
job_info[kProcessNum] = process_num;
|
||||
job_info[kLogLevel] = GetLogLevel();
|
||||
job_info[kEnableEvent] = false;
|
||||
job_info[kParaDebugPath] = GetParaDebugPath();
|
||||
job_info[kTbeImplPath] = GetTbePath();
|
||||
job_info[kSocInfo] = src_json;
|
||||
nlohmann::json tune_infos;
|
||||
tune_infos[kTuneOpList] = GetTuneOpsList(",");
|
||||
tune_infos[kTuneDumpPath] = TbeUtils::GetTuneDumpPath();
|
||||
tune_infos[kTuneBankPath] = TbeUtils::GetBankPath();
|
||||
job_info[kTuneInfo] = tune_infos;
|
||||
nlohmann::json lic_infos;
|
||||
kernel::tbe::TbeUtils::GenLicInfo(&lic_infos);
|
||||
job_info[kLicInfo] = lic_infos;
|
||||
(*dst_json)[kJobContent] = job_info;
|
||||
} else if (job_type == kQuery) {
|
||||
nlohmann::json content;
|
||||
content[kSourceId] = src_json[kSourceId];
|
||||
content[kJobId] = src_json[kJobId];
|
||||
(*dst_json)[kJobContent] = content;
|
||||
} else {
|
||||
(*dst_json)[kJobContent] = src_json;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::GetAllAscendNodes(const std::shared_ptr<session::KernelGraph> &kernel_graph,
|
||||
std::vector<AnfNodePtr> *tbe_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(kernel_graph);
|
||||
auto all_nodes = kernel_graph->execution_order();
|
||||
for (const auto &anf_node : all_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
if (!AnfAlgo::IsRealKernel(anf_node)) {
|
||||
continue;
|
||||
}
|
||||
KernelType kernel_type = AnfAlgo::GetKernelType(anf_node);
|
||||
if (kernel_type == TBE_KERNEL) {
|
||||
if (AnfAlgo::GetKernelMod(anf_node) == nullptr) {
|
||||
tbe_nodes->push_back(anf_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::AscendPreBuild(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
|
||||
MS_EXCEPTION_IF_NULL(kernel_graph);
|
||||
MS_LOG(INFO) << "Single op pre build start.";
|
||||
struct timeval start_time, end_time;
|
||||
(void)gettimeofday(&start_time, nullptr);
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
std::vector<AnfNodePtr> anf_nodes;
|
||||
GetAllAscendNodes(kernel_graph, &anf_nodes);
|
||||
if (anf_nodes.empty()) {
|
||||
return;
|
||||
}
|
||||
auto json_creator = std::make_shared<BuildTbeJsonCreator>();
|
||||
MS_EXCEPTION_IF_NULL(json_creator);
|
||||
for (const auto &node : anf_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto op_name = AnfAlgo::GetCNodeName(node);
|
||||
nlohmann::json kernel_json;
|
||||
if (!json_creator->GenJson(node, &kernel_json)) {
|
||||
MS_LOG(EXCEPTION) << "Generate prebuild json failed, [" << op_name << ", " << node->fullname_with_scope() << "]";
|
||||
}
|
||||
auto json_name = json_creator->GetJsonName();
|
||||
nlohmann::json build_json;
|
||||
if (!JsonAssemble(kPreCompile, kernel_json, &build_json)) {
|
||||
MS_LOG(EXCEPTION) << "Assemble json failed. job type: " << kPreCompile;
|
||||
}
|
||||
auto build_result = build_manager_->ProcessTbeJob(build_json);
|
||||
auto json_obj = TurnStrToJson(build_result);
|
||||
PrintSingleBuildResult(json_obj);
|
||||
auto task_id = GetJsonValue<int>(json_obj, kJobId);
|
||||
build_manager_->SavePreBuildTaskInfo(task_id, node, json_name);
|
||||
if (json_obj.at(kStatus) == kRunning) {
|
||||
std::pair<int, nlohmann::json> pair(task_id, build_json);
|
||||
job_list_.insert(pair);
|
||||
} else if (json_obj.at(kStatus) == kSuccess) {
|
||||
std::string build_res = GetJsonValue<std::string>(json_obj, kResult);
|
||||
build_manager_->PreTaskFinishProcess(task_id, build_res);
|
||||
} else {
|
||||
MS_LOG(WARNING) << "Kernel prebuild failed, op: " << op_name << ", json_name: " << json_name;
|
||||
}
|
||||
}
|
||||
QueryFinishJob(kPreCompile);
|
||||
(void)gettimeofday(&end_time, nullptr);
|
||||
const uint64_t kUSecondInSecond = 1000000;
|
||||
uint64_t cost = kUSecondInSecond * static_cast<uint64_t>(end_time.tv_sec - start_time.tv_sec);
|
||||
cost += static_cast<uint64_t>(end_time.tv_usec - start_time.tv_usec);
|
||||
MS_LOG(INFO) << "Kernel PreBuild run in " << PRIu64 << " us " << cost;
|
||||
MS_LOG(INFO) << "Single op pre build end.";
|
||||
}
|
||||
|
||||
bool AscendKernelCompileManager::AscendSingleOpCompile(const std::vector<AnfNodePtr> &anf_nodes) {
|
||||
MS_LOG(INFO) << "Single op parallel build start";
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
auto json_creator = std::make_shared<BuildTbeJsonCreator>();
|
||||
MS_EXCEPTION_IF_NULL(json_creator);
|
||||
static std::set<std::string> processed_kernel;
|
||||
std::string job_type;
|
||||
for (const auto &node : anf_nodes) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
if (AnfAlgo::GetKernelMod(node) != nullptr && !is_tune_flag_) {
|
||||
continue;
|
||||
}
|
||||
auto op_name = AnfAlgo::GetCNodeName(node);
|
||||
nlohmann::json kernel_json;
|
||||
if (!json_creator->GenJson(node, &kernel_json)) {
|
||||
MS_LOG(EXCEPTION) << "Generate compile json failed, [" << op_name << ", " << node->fullname_with_scope() << "]";
|
||||
}
|
||||
auto json_name = json_creator->GetJsonName();
|
||||
std::vector<size_t> in_size_list;
|
||||
std::vector<size_t> out_size_list;
|
||||
(void)TbeKernelBuild::GetIOSize2(kernel_json, &in_size_list, &out_size_list, node);
|
||||
if (!is_tune_flag_ && build_manager_->SearchInCache(json_name, in_size_list, out_size_list, node.get())) {
|
||||
continue;
|
||||
}
|
||||
if (processed_kernel.find(json_name) != processed_kernel.end()) {
|
||||
build_manager_->SaveSameOpInfo(node, json_name, in_size_list, out_size_list);
|
||||
continue;
|
||||
}
|
||||
(void)processed_kernel.insert(json_name);
|
||||
|
||||
nlohmann::json build_json;
|
||||
job_type = is_tune_flag_ ? kTune : kCompile;
|
||||
if (!JsonAssemble(job_type, kernel_json, &build_json)) {
|
||||
MS_LOG(EXCEPTION) << "Assemble json failed. job type: " << kCompile << ", op:[" << op_name << ", "
|
||||
<< node->fullname_with_scope() << "]";
|
||||
}
|
||||
auto build_str = build_json.dump(indent);
|
||||
MS_LOG(DEBUG) << "Op build json file : " << build_str;
|
||||
TbeUtils::SaveJsonInfo(json_name, build_str);
|
||||
auto build_result = build_manager_->ProcessTbeJob(build_json);
|
||||
auto json_obj = TurnStrToJson(build_result);
|
||||
PrintSingleBuildResult(json_obj);
|
||||
auto task_id = GetJsonValue<int>(json_obj, kJobId);
|
||||
build_manager_->SaveTaskInfo(task_id, node, json_name, in_size_list, out_size_list);
|
||||
if (json_obj.at(kStatus) == kRunning) {
|
||||
std::pair<int, nlohmann::json> pair(task_id, build_json);
|
||||
job_list_.insert(pair);
|
||||
} else if (json_obj.at(kStatus) == kSuccess) {
|
||||
std::string build_res = GetJsonValue<std::string>(json_obj, kResult);
|
||||
build_manager_->TaskFinishProcess(task_id, build_res);
|
||||
} else {
|
||||
MS_LOG(EXCEPTION) << "Kernel compile failed, op [" << op_name << "], build result: " << build_result;
|
||||
}
|
||||
}
|
||||
QueryFinishJob(job_type);
|
||||
return build_manager_->GenSameOpKernelMod();
|
||||
}
|
||||
|
||||
KernelModMap AscendKernelCompileManager::AscendFusionOpCompile(const std::vector<FusionScopeInfo> &fusion_scopes) {
|
||||
MS_LOG(INFO) << "fusion op build start";
|
||||
KernelModMap kernel_mode_ret;
|
||||
static std::set<std::string> processed_kernel;
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
auto json_creator = std::make_shared<FusionBuildTbeJsonCreator>();
|
||||
MS_EXCEPTION_IF_NULL(json_creator);
|
||||
for (const auto &fusion_scope_iter : fusion_scopes) {
|
||||
nlohmann::json fusion_op;
|
||||
if (!json_creator->GenJson(fusion_scope_iter, &fusion_op)) {
|
||||
MS_LOG(WARNING) << "Generate fusion json failed";
|
||||
continue;
|
||||
}
|
||||
auto json_name = json_creator->GetJsonName();
|
||||
std::vector<size_t> input_size_list;
|
||||
std::vector<size_t> output_size_list;
|
||||
if (!TbeKernelBuild::GetIOSize(fusion_op[kOpList], fusion_scope_iter.output_nodes, &input_size_list,
|
||||
&output_size_list)) {
|
||||
continue;
|
||||
}
|
||||
// cache
|
||||
if (!is_tune_flag_) {
|
||||
auto kernel_pack = TbeUtils::SearchCache(json_name);
|
||||
if (kernel_pack != nullptr) {
|
||||
auto kernel_mod = build_manager_->GenKernelMod(input_size_list, output_size_list, kernel_pack);
|
||||
if (kernel_mod != nullptr) {
|
||||
kernel_mode_ret[fusion_scope_iter.scope_id] = kernel_mod;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// same op no need build, but need wait build finish to set kernel mode
|
||||
if (processed_kernel.find(json_name) != processed_kernel.end()) {
|
||||
build_manager_->SaveSameFusionOpInfo(fusion_scope_iter.scope_id, json_name, tbe::kProcessorAiCore,
|
||||
input_size_list, output_size_list);
|
||||
continue;
|
||||
}
|
||||
(void)processed_kernel.insert(json_name);
|
||||
|
||||
nlohmann::json build_json;
|
||||
const std::string job_type = is_tune_flag_ ? kTune : kCompile;
|
||||
if (!JsonAssemble(job_type, fusion_op, &build_json)) {
|
||||
MS_LOG(EXCEPTION) << "Assemble json failed. job type: [" << kCompile << "]";
|
||||
}
|
||||
auto build_str = build_json.dump(indent);
|
||||
MS_LOG(DEBUG) << "FusionOp build json file : " << build_str;
|
||||
TbeUtils::SaveJsonInfo(json_name, build_str);
|
||||
auto build_result = build_manager_->ProcessTbeJob(build_json);
|
||||
auto json_obj = TurnStrToJson(build_result);
|
||||
PrintFusionOpBuildResult(json_obj);
|
||||
auto task_id = GetJsonValue<int>(json_obj, kJobId);
|
||||
fusion_op_names_[task_id] = json_name;
|
||||
build_manager_->SaveTaskInfo(task_id, nullptr, json_name, input_size_list, output_size_list,
|
||||
fusion_scope_iter.scope_id);
|
||||
if (json_obj.at(kStatus) == kRunning) {
|
||||
std::pair<int, nlohmann::json> pair(task_id, build_json);
|
||||
job_list_.insert(pair);
|
||||
} else if (json_obj.at(kStatus) == kSuccess) {
|
||||
std::string build_res = GetJsonValue<std::string>(json_obj, kResult);
|
||||
auto kernel_mode_item = build_manager_->TaskFinishProcess(task_id, build_res, false);
|
||||
if (kernel_mode_item.second != nullptr) {
|
||||
(void)kernel_mode_ret.emplace(kernel_mode_item);
|
||||
}
|
||||
} else {
|
||||
MS_LOG(INFO) << "Kernel compile failed for << " << fusion_scope_iter.full_name << ", " << build_result;
|
||||
}
|
||||
}
|
||||
QueryFusionFinishJob(&kernel_mode_ret);
|
||||
if (!build_manager_->GenSameFusionOpKernelMod(&kernel_mode_ret)) {
|
||||
MS_LOG(INFO) << "Fusion warning: cache failed.";
|
||||
}
|
||||
return kernel_mode_ret;
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::TbeInitialize() {
|
||||
if (tbe_init_flag_) {
|
||||
MS_LOG(DEBUG) << "TbeInitialize already complete, no need do again";
|
||||
return;
|
||||
}
|
||||
MS_LOG(INFO) << "TbeInitialize start";
|
||||
build_manager_ = std::make_shared<ParallelBuildManager>();
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
nlohmann::json init_json;
|
||||
nlohmann::json soc_info;
|
||||
TbeUtils::GenSocInfo(&soc_info);
|
||||
if (!JsonAssemble(kInitialize, soc_info, &init_json)) {
|
||||
MS_LOG(EXCEPTION) << "Assemble json failed. job type: Initialize.";
|
||||
}
|
||||
auto offline_tune = (init_json[kJobContent][kSocInfo][kOfflineTune]).get<bool>();
|
||||
auto auto_tiling_mode = (init_json[kJobContent][kSocInfo]["autoTilingMode"]).get<std::string>();
|
||||
tbe_init_flag_ = true;
|
||||
is_tune_flag_ = offline_tune || (auto_tiling_mode != "NO_TUNE");
|
||||
|
||||
auto init_str = init_json.dump();
|
||||
MS_LOG(INFO) << "TbeInitialize json file : " << init_str;
|
||||
TbeUtils::SaveJsonInfo(kInitialize, init_str);
|
||||
auto init_ret = build_manager_->ProcessTbeJob(init_json);
|
||||
auto json_ret = TurnStrToJson(init_ret);
|
||||
PrintInitResult(json_ret);
|
||||
MS_LOG(INFO) << "TbeInitialize end";
|
||||
}
|
||||
|
||||
std::string AscendKernelCompileManager::AscendOpSelectFormat(const AnfNodePtr &node) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto op_name = AnfAlgo::GetCNodeName(node);
|
||||
MS_LOG(INFO) << "Op select format start for op [" << op_name << ", " << node->fullname_with_scope() << "]";
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
auto json_creator = std::make_shared<SelectTbeJsonCreator>();
|
||||
MS_EXCEPTION_IF_NULL(json_creator);
|
||||
nlohmann::json kernel_info;
|
||||
nlohmann::json select_json;
|
||||
if (!json_creator->GenJson(node, &kernel_info)) {
|
||||
MS_LOG(EXCEPTION) << "Gen select json failed. [" << op_name << ", " << node->fullname_with_scope() << "]";
|
||||
}
|
||||
if (!JsonAssemble(kSelectFormat, kernel_info, &select_json)) {
|
||||
MS_LOG(EXCEPTION) << "Assemble json failed. job type: SelectFormat";
|
||||
}
|
||||
auto select_ret = build_manager_->ProcessTbeJob(select_json);
|
||||
auto json_ret = TurnStrToJson(select_ret);
|
||||
return FormatSelectResultProcess(json_ret);
|
||||
}
|
||||
|
||||
bool AscendKernelCompileManager::AscendOpCheckSupported(const AnfNodePtr &node) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto op_name = AnfAlgo::GetCNodeName(node);
|
||||
MS_LOG(INFO) << "Check supported for op [" << op_name << ", " << node->fullname_with_scope() << "]";
|
||||
MS_EXCEPTION_IF_NULL(build_manager_);
|
||||
auto json_creator = std::make_shared<CheckTbeJsonCreator>();
|
||||
MS_EXCEPTION_IF_NULL(json_creator);
|
||||
nlohmann::json kernel_info;
|
||||
nlohmann::json check_json;
|
||||
if (!json_creator->GenJson(node, &kernel_info)) {
|
||||
MS_LOG(EXCEPTION) << "Gen check supported json failed.[" << op_name << ", " << node->fullname_with_scope() << "]";
|
||||
}
|
||||
if (!JsonAssemble(kCheckSupport, kernel_info, &check_json)) {
|
||||
MS_LOG(EXCEPTION) << "Assemble json failed. job type: CheckSupport";
|
||||
}
|
||||
auto check_ret = build_manager_->ProcessTbeJob(check_json);
|
||||
auto json_ret = TurnStrToJson(check_ret);
|
||||
std::string check_info = FormatSelectResultProcess(json_ret);
|
||||
return check_info == kFullySupported;
|
||||
}
|
||||
|
||||
void AscendKernelCompileManager::TbeFinalize() {
|
||||
MS_LOG(INFO) << "TbeFinalize start";
|
||||
if (!tbe_init_flag_) {
|
||||
MS_LOG(DEBUG) << "TbeFinalize already complete, no need do again";
|
||||
return;
|
||||
}
|
||||
build_manager_ = nullptr;
|
||||
tbe_init_flag_ = false;
|
||||
is_tune_flag_ = false;
|
||||
job_list_.clear();
|
||||
MS_LOG(INFO) << "TbeFinalize end";
|
||||
}
|
||||
|
||||
AscendKernelCompileManager::~AscendKernelCompileManager() { TbeFinalize(); }
|
||||
|
||||
bool AscendKernelCompileManager::tbe_init_flag_ = false;
|
||||
bool AscendKernelCompileManager::is_tune_flag_ = false;
|
||||
} // namespace ascend
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_TBE_ASCEND_KERNEL_COMPILE_H_
|
||||
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_TBE_ASCEND_KERNEL_COMPILE_H_
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include "ir/anf.h"
|
||||
#include "backend/kernel_compiler/kernel.h"
|
||||
#include "backend/kernel_compiler/kernel_fusion.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_build.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_parallel_build.h"
|
||||
#include "backend/session/kernel_graph.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
namespace ascend {
|
||||
using KernelModMap = std::map<int64_t, KernelModPtr>;
|
||||
struct TargetJobStatus {
|
||||
int target_job_id;
|
||||
std::string job_status;
|
||||
};
|
||||
|
||||
class AscendKernelCompileManager {
|
||||
public:
|
||||
AscendKernelCompileManager() = default;
|
||||
~AscendKernelCompileManager();
|
||||
static std::shared_ptr<AscendKernelCompileManager> GetInstance() {
|
||||
static auto instance = std::make_shared<AscendKernelCompileManager>();
|
||||
if (!instance->tbe_init_flag_) {
|
||||
instance->TbeInitialize();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
void TbeInitialize();
|
||||
void TbeFinalize();
|
||||
// kernel select
|
||||
std::string AscendOpSelectFormat(const AnfNodePtr &node);
|
||||
bool AscendOpCheckSupported(const AnfNodePtr &node);
|
||||
// pre build
|
||||
void AscendPreBuild(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
// single op compile
|
||||
bool AscendSingleOpCompile(const std::vector<AnfNodePtr> &anf_nodes);
|
||||
// fusion op compile
|
||||
KernelModMap AscendFusionOpCompile(const std::vector<FusionScopeInfo> &fusion_scopes);
|
||||
// clear prev job's cache
|
||||
void ResetOldTask();
|
||||
|
||||
private:
|
||||
void GetAllAscendNodes(const std::shared_ptr<session::KernelGraph> &kernel_graph, std::vector<AnfNodePtr> *tbe_nodes);
|
||||
void QueryFinishJob(const std::string &type);
|
||||
void ParseTargetJobStatus(const std::string &type, const std::string &build_res, std::vector<int> *success_job);
|
||||
void QueryPreBuildFinishJob();
|
||||
void QueryFusionFinishJob(KernelModMap *kernel_mode_ret);
|
||||
void PrintProcessLog(const nlohmann::json &json, int adjust_log_level);
|
||||
bool JsonAssemble(const std::string &job_type, const nlohmann::json &src_json, nlohmann::json *dst_json);
|
||||
void PrintInitResult(const nlohmann::json &json);
|
||||
void PrintSingleBuildResult(const nlohmann::json &json);
|
||||
void PrintFusionOpBuildResult(const nlohmann::json &json);
|
||||
std::string FormatSelectResultProcess(const nlohmann::json &json);
|
||||
void QueryResultProcess(const nlohmann::json &json, TargetJobStatus *task_info, int adjust_log_level);
|
||||
nlohmann::json TurnStrToJson(const std::string &str);
|
||||
|
||||
static bool tbe_init_flag_;
|
||||
static bool is_tune_flag_;
|
||||
std::shared_ptr<ParallelBuildManager> build_manager_ = nullptr;
|
||||
std::map<int, nlohmann::json> job_list_;
|
||||
std::map<int, std::string> fusion_op_names_;
|
||||
};
|
||||
} // namespace ascend
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_TBE_ASCEND_KERNEL_COMPILE_H_
|
|
@ -299,7 +299,8 @@ std::vector<size_t> FusionBuildTbeJsonCreator::GetDescOutputIndex(const std::vec
|
|||
|
||||
bool FusionBuildTbeJsonCreator::AttrsJsonPostProcessing(const AnfNodePtr &anf_node, const OpInfoPtr &op_info_ptr,
|
||||
nlohmann::json *attrs_json) {
|
||||
tbe::TbeAdapter::CastAttrJsonPost(anf_node, attrs_json);
|
||||
// just keep it
|
||||
// tbe::TbeAdapter::CastAttrJsonPost(anf_node, attrs_json);
|
||||
return true;
|
||||
}
|
||||
} // namespace mindspore::kernel
|
||||
|
|
|
@ -154,8 +154,8 @@ void SingleTbeJsonCreator::GenInputDescJson(const AnfNodePtr &anf_node, size_t r
|
|||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
MS_EXCEPTION_IF_NULL(input_desc);
|
||||
GenDesJsonCommon(input_desc);
|
||||
auto shape = AnfAlgo::GetInputDeviceShape(anf_node, real_input_index);
|
||||
auto ori_shape = AnfAlgo::GetPrevNodeOutputInferShape(anf_node, real_input_index);
|
||||
auto shape = TbeJsonUtils::GetInputDeviceShapeForTbeBuild(anf_node, real_input_index);
|
||||
auto ori_shape = TbeJsonUtils::GetInputOriShapeForTbeBuild(anf_node, real_input_index);
|
||||
if (shape.empty()) {
|
||||
shape.emplace_back(1);
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ void SelectTbeJsonCreator::GenDescJson(const AnfNodePtr &anf_node, size_t node_o
|
|||
GenDesJsonCommon(output_desc);
|
||||
std::vector<int64_t> shape;
|
||||
std::vector<int64_t> ori_shape;
|
||||
AnfAlgo::GetRealDynamicShape(AnfAlgo::GetOutputInferShape(anf_node, node_out_idx), NOT_NULL(&ori_shape));
|
||||
ori_shape = TbeJsonUtils::GetOutputOriShapeForTbeBuild(anf_node, node_out_idx);
|
||||
if (ori_shape.empty()) {
|
||||
ori_shape.emplace_back(1);
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ void SelectTbeJsonCreator::GenInputDescJson(const AnfNodePtr &anf_node, size_t r
|
|||
nlohmann::json *input_desc) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
GenDesJsonCommon(input_desc);
|
||||
auto shape = AnfAlgo::GetPrevNodeOutputInferShape(anf_node, real_input_index);
|
||||
auto shape = TbeJsonUtils::GetInputOriShapeForTbeBuild(anf_node, real_input_index);
|
||||
if (shape.empty()) {
|
||||
shape.emplace_back(1);
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ void CheckTbeJsonCreator::GenDescJson(const AnfNodePtr &anf_node, size_t node_ou
|
|||
GenDesJsonCommon(output_desc);
|
||||
std::vector<int64_t> shape;
|
||||
std::vector<int64_t> ori_shape;
|
||||
AnfAlgo::GetRealDynamicShape(AnfAlgo::GetOutputInferShape(anf_node, node_out_idx), NOT_NULL(&ori_shape));
|
||||
ori_shape = TbeJsonUtils::GetOutputOriShapeForTbeBuild(anf_node, node_out_idx);
|
||||
if (ori_shape.empty()) {
|
||||
ori_shape.emplace_back(1);
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ void CheckTbeJsonCreator::GenInputDescJson(const AnfNodePtr &anf_node, size_t re
|
|||
nlohmann::json *input_desc) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
GenDesJsonCommon(input_desc);
|
||||
auto shape = AnfAlgo::GetPrevNodeOutputInferShape(anf_node, real_input_index);
|
||||
auto shape = TbeJsonUtils::GetInputOriShapeForTbeBuild(anf_node, real_input_index);
|
||||
if (shape.empty()) {
|
||||
shape.emplace_back(1);
|
||||
}
|
||||
|
|
|
@ -346,8 +346,8 @@ void TbeJsonCreator::GenDescJson(const AnfNodePtr &anf_node, size_t node_out_idx
|
|||
GenDesJsonCommon(output_desc);
|
||||
std::vector<int64_t> shape;
|
||||
std::vector<int64_t> ori_shape;
|
||||
AnfAlgo::GetRealDynamicShape(AnfAlgo::GetOutputDeviceShape(anf_node, node_out_idx), NOT_NULL(&shape));
|
||||
AnfAlgo::GetRealDynamicShape(AnfAlgo::GetOutputInferShape(anf_node, node_out_idx), NOT_NULL(&ori_shape));
|
||||
shape = TbeJsonUtils::GetOutputDeviceShapeForTbeBuild(anf_node, node_out_idx);
|
||||
ori_shape = TbeJsonUtils::GetOutputOriShapeForTbeBuild(anf_node, node_out_idx);
|
||||
if (shape.empty()) {
|
||||
shape.emplace_back(1);
|
||||
}
|
||||
|
|
|
@ -80,4 +80,48 @@ bool TbeJsonUtils::IsNeedChangeDefaultFormat(const AnfNodePtr &anf_node) {
|
|||
AnfAlgo::GetNodeAttr<std::string>(anf_node, kAttrFormat) == kOpFormat_NCDHW;
|
||||
}
|
||||
|
||||
std::vector<int64_t> TbeJsonUtils::GetInputOriShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
session::KernelWithIndex kernel_with_index = AnfAlgo::GetPrevNodeOutput(anf_node, real_idx);
|
||||
return GetOutputOriShapeForTbeBuild(kernel_with_index.first, kernel_with_index.second);
|
||||
}
|
||||
|
||||
std::vector<int64_t> TbeJsonUtils::GetInputDeviceShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
std::vector<int64_t> shape;
|
||||
session::KernelWithIndex kernel_with_index = AnfAlgo::GetPrevNodeOutput(anf_node, real_idx);
|
||||
auto format = AnfAlgo::GetInputFormat(anf_node, real_idx);
|
||||
shape = AnfAlgo::GetOutputDeviceShapeForTbeBuild(kernel_with_index.first, kernel_with_index.second, format);
|
||||
if (shape.empty()) {
|
||||
shape.emplace_back(1);
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
|
||||
std::vector<int64_t> TbeJsonUtils::GetOutputOriShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
std::vector<int64_t> shape;
|
||||
auto out_shape = AnfAlgo::GetOutputDetailShape(anf_node, real_idx);
|
||||
MS_EXCEPTION_IF_NULL(out_shape);
|
||||
if (out_shape->isa<abstract::Shape>()) {
|
||||
auto shape_ptr = out_shape->cast<abstract::ShapePtr>();
|
||||
MS_EXCEPTION_IF_NULL(shape_ptr);
|
||||
shape = shape_ptr->shape();
|
||||
}
|
||||
if (shape.empty()) {
|
||||
shape.emplace_back(1);
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
|
||||
std::vector<int64_t> TbeJsonUtils::GetOutputDeviceShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
std::vector<int64_t> shape;
|
||||
auto format = AnfAlgo::GetOutputFormat(anf_node, real_idx);
|
||||
shape = AnfAlgo::GetOutputDeviceShapeForTbeBuild(anf_node, real_idx, format);
|
||||
if (shape.empty()) {
|
||||
shape.emplace_back(1);
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
} // namespace mindspore::kernel
|
||||
|
|
|
@ -108,6 +108,11 @@ class TbeJsonUtils {
|
|||
static bool GetOutputsRealNum(const AnfNodePtr &anf_node, const std::vector<OpIOInfoPtr> &outputs_ptr,
|
||||
std::vector<size_t> *outputs_num);
|
||||
static bool IsNeedChangeDefaultFormat(const AnfNodePtr &anf_node);
|
||||
// just for generate json for ascend op build, it will be deleted after unify size_t and int64_t.
|
||||
static std::vector<int64_t> GetInputOriShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
|
||||
static std::vector<int64_t> GetInputDeviceShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
|
||||
static std::vector<int64_t> GetOutputOriShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
|
||||
static std::vector<int64_t> GetOutputDeviceShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
|
||||
};
|
||||
|
||||
} // namespace mindspore::kernel
|
||||
|
|
|
@ -265,8 +265,8 @@ bool TbeKernelJsonCreator::GenTbeSingleKernelJson(const std::shared_ptr<mindspor
|
|||
(*kernel_json)[kJSocInfo] = soc_info_json;
|
||||
(*kernel_json)[kJOpInfo] = op_info_json;
|
||||
|
||||
MS_LOG(DEBUG) << "Operate type:" << creater_type_ << ", full scope name is :" << anf_node->fullname_with_scope()
|
||||
<< ", json info name is : " << json_name_ << ", kernel json:" << kernel_json->dump();
|
||||
MS_LOG(INFO) << "Operate type:" << creater_type_ << ", full scope name is :" << anf_node->fullname_with_scope()
|
||||
<< ", json info name is : " << json_name_ << ", kernel json:" << kernel_json->dump();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -884,6 +884,113 @@ bool TbeKernelBuild::GetIOSize(const nlohmann::json &kernel_json, std::vector<si
|
|||
return true;
|
||||
}
|
||||
|
||||
void GetRealInputSize(const nlohmann::json &input_json, const AnfNodePtr &anf_node, size_t i,
|
||||
std::vector<size_t> *input_size_list, size_t *size_i) {
|
||||
for (size_t j = 0; j < input_json[kJShape].size(); ++j) {
|
||||
if (input_json[kJShape][j] == -1) {
|
||||
auto input_max_shape = AnfAlgo::GetInputMaxShape(anf_node, i);
|
||||
if (j >= input_max_shape.size()) {
|
||||
MS_LOG(EXCEPTION) << "Invalid Dynamic Shape Max Shape";
|
||||
}
|
||||
MS_LOG(INFO) << "Change -1 Shape to Max Shape:" << input_max_shape[j];
|
||||
(*size_i) *= input_max_shape[j];
|
||||
continue;
|
||||
}
|
||||
(*size_i) *= static_cast<size_t>(input_json[kJShape][j]);
|
||||
}
|
||||
std::string dtype = input_json[kJDtype];
|
||||
size_t nbyte = tbe::GetDtypeNbyte(dtype);
|
||||
(*size_i) *= nbyte;
|
||||
input_size_list->push_back((*size_i));
|
||||
}
|
||||
|
||||
void GetInputSizeList2(const nlohmann::json &input_json, std::vector<size_t> *input_size_list,
|
||||
const AnfNodePtr &anf_node) {
|
||||
for (size_t i = 0; i < input_json.size(); i++) {
|
||||
if (input_json[i].is_array()) {
|
||||
for (size_t m = 0; m < input_json[i].size(); m++) {
|
||||
size_t size_i = 1;
|
||||
if (input_json[i][m][kJValid] == false) {
|
||||
std::string input_name = input_json[i][m][kJName];
|
||||
continue;
|
||||
}
|
||||
GetRealInputSize(input_json[i][m], anf_node, i, input_size_list, &size_i);
|
||||
}
|
||||
} else {
|
||||
size_t size_i = 1;
|
||||
if (input_json[i][kJValid] == false) {
|
||||
std::string input_name = input_json[i][kJName];
|
||||
continue;
|
||||
}
|
||||
GetRealInputSize(input_json[i], anf_node, i, input_size_list, &size_i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetRealOutputSize(const nlohmann::json &output_json, const AnfNodePtr &anf_node, size_t i,
|
||||
std::vector<size_t> *output_size_list, size_t *size_i) {
|
||||
for (size_t j = 0; j < output_json[kJShape].size(); ++j) {
|
||||
if (output_json[kJShape][j] == -1) {
|
||||
auto output_max_shape = AnfAlgo::GetOutputMaxShape(anf_node, i);
|
||||
if (j >= output_max_shape.size()) {
|
||||
MS_LOG(EXCEPTION) << "Invalid Dynamic Shape Max Shape";
|
||||
}
|
||||
MS_LOG(INFO) << "Change -1 Shape to Max Shape:" << output_max_shape[j];
|
||||
(*size_i) *= output_max_shape[j];
|
||||
continue;
|
||||
}
|
||||
(*size_i) *= static_cast<size_t>(output_json[kJShape][j]);
|
||||
}
|
||||
std::string dtype = output_json[kJDtype];
|
||||
size_t nbyte = tbe::GetDtypeNbyte(dtype);
|
||||
(*size_i) *= nbyte;
|
||||
output_size_list->push_back((*size_i));
|
||||
}
|
||||
|
||||
void GetOutputSizeList2(const nlohmann::json &output_json, std::vector<size_t> *output_size_list,
|
||||
const AnfNodePtr &anf_node) {
|
||||
for (size_t i = 0; i < output_json.size(); i++) {
|
||||
if (output_json[i].is_array()) {
|
||||
for (size_t m = 0; m < output_json[i].size(); m++) {
|
||||
size_t size_i = 1;
|
||||
if (output_json[i][m][kJValid] == false) {
|
||||
std::string output_name = output_json[i][m][kJName];
|
||||
MS_LOG(INFO) << "Output name:" << output_name << " is optional, valid is false.";
|
||||
continue;
|
||||
}
|
||||
GetRealOutputSize(output_json[i][m], anf_node, i, output_size_list, &size_i);
|
||||
}
|
||||
} else {
|
||||
size_t size_i = 1;
|
||||
if (output_json[i][kJValid] == false) {
|
||||
std::string output_name = output_json[i][kJName];
|
||||
MS_LOG(INFO) << "Output name:" << output_name << " is optional, valid is false.";
|
||||
continue;
|
||||
}
|
||||
GetRealOutputSize(output_json[i], anf_node, i, output_size_list, &size_i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TbeKernelBuild::GetIOSize2(const nlohmann::json &kernel_json, std::vector<size_t> *input_size_list,
|
||||
std::vector<size_t> *output_size_list, const AnfNodePtr &anf_node) {
|
||||
if (input_size_list == nullptr || output_size_list == nullptr) {
|
||||
MS_LOG(ERROR) << "Input size or output size is nullptr";
|
||||
return false;
|
||||
}
|
||||
input_size_list->clear();
|
||||
output_size_list->clear();
|
||||
auto op_list = kernel_json["op_list"];
|
||||
for (size_t i = 0; i < op_list.size(); i++) {
|
||||
auto op_info = op_list[i];
|
||||
if (op_info["type"] != "Data") {
|
||||
GetInputSizeList2(op_info["input_desc"], input_size_list, anf_node);
|
||||
GetOutputSizeList2(op_info["output_desc"], output_size_list, anf_node);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TbeKernelBuild::GenFusionScopeJson(const std::vector<mindspore::AnfNodePtr> &input_nodes,
|
||||
const std::vector<mindspore::AnfNodePtr> &compute_nodes,
|
||||
nlohmann::json *fusion_json, std::string *fusion_kernel_name) {
|
||||
|
|
|
@ -37,6 +37,8 @@ class TbeKernelBuild {
|
|||
enum FusionDataType { kFusionNormal = 0, kFusionAddN, kFusionReLUGradV2, kFusionAdd };
|
||||
|
||||
public:
|
||||
static bool GetIOSize2(const nlohmann::json &kernel_json, std::vector<size_t> *input_size_list,
|
||||
std::vector<size_t> *output_size_list, const AnfNodePtr &anf_node);
|
||||
static bool GetIOSize(const nlohmann::json &kernel_json, std::vector<size_t> *input_size_list,
|
||||
std::vector<size_t> *output_size_list, const AnfNodePtr &anf_node);
|
||||
// Ub Fuison
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include "utils/ms_context.h"
|
||||
#include "backend/kernel_compiler/common_utils.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_adapter.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_build.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_mod.h"
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include "backend/kernel_compiler/tbe/tbe_utils.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_dynaminc_shape_util.h"
|
||||
#include "utils/trace_base.h"
|
||||
#include "utils/json_operation_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
|
@ -56,7 +58,6 @@ bool TbeOpParallelBuild(const std::vector<AnfNodePtr> &anf_nodes) {
|
|||
if (AnfAlgo::GetKernelMod(anf_node) != nullptr) {
|
||||
continue;
|
||||
}
|
||||
const std::string &processor = tbe::GetProcessor(anf_node);
|
||||
nlohmann::json kernel_json;
|
||||
TbeKernelJsonCreator creator(SINGLE_BUILD);
|
||||
if (!creator.GenTbeSingleKernelJson(anf_node, &kernel_json)) {
|
||||
|
@ -70,7 +71,7 @@ bool TbeOpParallelBuild(const std::vector<AnfNodePtr> &anf_nodes) {
|
|||
(void)TbeKernelBuild::GetIOSize(kernel_json, &input_size_list, &output_size_list, anf_node);
|
||||
// search cache
|
||||
const std::string &json_name = creator.json_name();
|
||||
if (build_manger->SearchInCache(json_name, processor, input_size_list, output_size_list, anf_node.get()) &&
|
||||
if (build_manger->SearchInCache(json_name, input_size_list, output_size_list, anf_node.get()) &&
|
||||
((!offline_tune.empty() && offline_tune != "true") || tune_mode == "NO_TUNE")) {
|
||||
continue;
|
||||
}
|
||||
|
@ -106,10 +107,24 @@ bool TbeOpParallelBuild(const std::vector<AnfNodePtr> &anf_nodes) {
|
|||
|
||||
ParallelBuildManager::~ParallelBuildManager() { ResetTaskInfo(); }
|
||||
|
||||
void ParallelBuildManager::SavePreBuildTaskInfo(int32_t task_id, const AnfNodePtr &anf_node,
|
||||
const std::string &json_name) {
|
||||
MS_LOG(DEBUG) << "SavePreBuildTaskInfo, task id: " << task_id;
|
||||
struct KernelBuildTaskInfo task_info;
|
||||
task_info.node = anf_node;
|
||||
task_info.json_name = json_name;
|
||||
if (anf_node == nullptr) {
|
||||
task_info.processor = tbe::kProcessorAiCore;
|
||||
} else {
|
||||
task_info.processor = tbe::GetProcessor(anf_node);
|
||||
}
|
||||
pre_build_task_map_[task_id] = task_info;
|
||||
}
|
||||
|
||||
void ParallelBuildManager::SaveTaskInfo(int32_t task_id, const mindspore::AnfNodePtr &anf_node,
|
||||
const std::string &json_name, const std::vector<size_t> &input_size_list,
|
||||
const std::vector<size_t> &output_size_list, int64_t scope_id) {
|
||||
MS_LOG(INFO) << "SaveTaskInfo, task id: " << task_id;
|
||||
MS_LOG(DEBUG) << "SaveTaskInfo, task id: " << task_id;
|
||||
struct KernelBuildTaskInfo task_info;
|
||||
task_info.node = anf_node;
|
||||
task_info.json_name = json_name;
|
||||
|
@ -130,28 +145,23 @@ bool ParallelBuildManager::IsAllTaskFinish() const {
|
|||
}
|
||||
|
||||
void ParallelBuildManager::PreTaskFinishProcess(int32_t task_id, const std::string &pre_build_result) {
|
||||
auto task_iter = pre_task_map_.find(task_id);
|
||||
if (task_iter == pre_task_map_.end()) {
|
||||
MS_LOG(DEBUG) << "can find pre task_id : " << task_id << " result:" << pre_build_result;
|
||||
auto task_iter = pre_build_task_map_.find(task_id);
|
||||
if (task_iter == pre_build_task_map_.end()) {
|
||||
MS_EXCEPTION(ArgumentError) << "can find pre task_id:" << task_id;
|
||||
}
|
||||
auto node = task_iter->second;
|
||||
auto builder =
|
||||
std::make_shared<kernel::KernelBuildInfo::KernelBuildInfoBuilder>(AnfAlgo::GetSelectKernelBuildInfo(node));
|
||||
std::string start_flag = "fusion_pattern_start";
|
||||
std::string end_flag = "fusion_pattern_end";
|
||||
auto start = pre_build_result.find(start_flag);
|
||||
auto end = pre_build_result.find(end_flag);
|
||||
if (start != std::string::npos && end != std::string::npos && end >= start) {
|
||||
std::string result = pre_build_result.substr(start + start_flag.size(), end - start - start_flag.size());
|
||||
if (result.empty()) {
|
||||
(void)pre_task_map_.erase(task_iter);
|
||||
return;
|
||||
}
|
||||
transform(result.begin(), result.end(), result.begin(), ::toupper);
|
||||
AnfAlgo::SetNodeAttr(kAttrFusionType, MakeValue(result), node);
|
||||
AnfAlgo::SetSelectKernelBuildInfo(builder->Build(), node.get());
|
||||
nlohmann::json result;
|
||||
if (!ParseJson(pre_build_result, &result)) {
|
||||
MS_LOG(EXCEPTION) << "Parse prebuild result error.";
|
||||
}
|
||||
(void)pre_task_map_.erase(task_iter);
|
||||
auto fusion_name = GetJsonValue<std::string>(result, "op_pattern");
|
||||
auto fusion_type = kernel::GetFusionTypeByName(fusion_name);
|
||||
auto output_data_desc = GetJsonValue<nlohmann::json>(result, "op_params");
|
||||
|
||||
auto node = task_iter->second.node;
|
||||
AnfAlgo::SetFusionType(node, fusion_type);
|
||||
AnfAlgo::SetOutputDataDesc(node, {output_data_desc});
|
||||
(void)pre_build_task_map_.erase(task_iter);
|
||||
}
|
||||
|
||||
std::pair<int32_t, KernelModPtr> ParallelBuildManager::TaskFinishProcess(int32_t task_id, const std::string &build_ret,
|
||||
|
@ -176,9 +186,25 @@ std::pair<int32_t, KernelModPtr> ParallelBuildManager::TaskFinishProcess(int32_t
|
|||
auto kernel_mod = GenKernelMod(task_iter->second.input_size_list, task_iter->second.output_size_list, kernel_pack);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod);
|
||||
if (set_kernel_mod) {
|
||||
AnfAlgo::SetKernelMod(kernel_mod, task_iter->second.node.get());
|
||||
AnfAlgo::SetNodeAttr(kAttrCompileInfo, MakeValue(build_ret), task_iter->second.node);
|
||||
MS_LOG(INFO) << "Set Node Attr compile_info:" << build_ret;
|
||||
auto cur_node = task_iter->second.node;
|
||||
MS_EXCEPTION_IF_NULL(cur_node);
|
||||
if (AnfAlgo::IsDynamicShape(cur_node) && (build_ret.empty() || build_ret.find("vars") == std::string::npos)) {
|
||||
MS_LOG(EXCEPTION) << "Build failed. The build result of dynamic shape op [" << AnfAlgo::GetCNodeName(cur_node)
|
||||
<< "] should not be empty, or can not find key ['vars'] in the result. build_res:[" << build_ret
|
||||
<< "].";
|
||||
}
|
||||
AnfAlgo::SetKernelMod(kernel_mod, cur_node.get());
|
||||
MS_LOG(INFO) << json_name << ": save compile info to json file, compile_info:" << build_ret;
|
||||
std::string old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
|
||||
if (!old_build.empty()) {
|
||||
AnfAlgo::SetNodeAttr(kAttrCompileInfo, MakeValue(build_ret), cur_node);
|
||||
} else {
|
||||
bool save_flag = true;
|
||||
TbeUtils::SaveCompileInfo(json_name, build_ret, &save_flag);
|
||||
if (!save_flag) {
|
||||
MS_LOG(EXCEPTION) << "Save json file failed, compile_info:" << build_ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
auto ret = std::make_pair(task_iter->second.scope_id, kernel_mod);
|
||||
(void)task_map_.erase(task_iter);
|
||||
|
@ -213,8 +239,8 @@ void ParallelBuildManager::SaveSameFusionOpInfo(const int64_t scope_id, const st
|
|||
|
||||
bool ParallelBuildManager::GenSameOpKernelMod() const {
|
||||
for (const auto &task_info : same_op_list_) {
|
||||
bool ret = SearchInCache(task_info.json_name, task_info.processor, task_info.input_size_list,
|
||||
task_info.output_size_list, task_info.node.get());
|
||||
bool ret =
|
||||
SearchInCache(task_info.json_name, task_info.input_size_list, task_info.output_size_list, task_info.node.get());
|
||||
if (!ret) {
|
||||
MS_LOG(INFO) << "can't find " << task_info.json_name << " in cache.";
|
||||
return false;
|
||||
|
@ -226,7 +252,7 @@ bool ParallelBuildManager::GenSameOpKernelMod() const {
|
|||
bool ParallelBuildManager::GenSameFusionOpKernelMod(std::map<int64_t, KernelModPtr> *kernel_mode_ret) const {
|
||||
bool ret = true;
|
||||
for (const auto &task_info : same_op_list_) {
|
||||
auto kernel_pack = TbeUtils::SearchCache(task_info.json_name, tbe::kProcessorAiCore);
|
||||
auto kernel_pack = TbeUtils::SearchCache(task_info.json_name);
|
||||
if (kernel_pack != nullptr) {
|
||||
auto kernel_mode = GenKernelMod(task_info.input_size_list, task_info.output_size_list, kernel_pack);
|
||||
if (kernel_mode != nullptr) {
|
||||
|
@ -240,10 +266,9 @@ bool ParallelBuildManager::GenSameFusionOpKernelMod(std::map<int64_t, KernelModP
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool ParallelBuildManager::SearchInCache(const std::string &json_name, const std::string &processor,
|
||||
const std::vector<size_t> &input_size_list,
|
||||
bool ParallelBuildManager::SearchInCache(const std::string &json_name, const std::vector<size_t> &input_size_list,
|
||||
const std::vector<size_t> &output_size_list, mindspore::AnfNode *node) const {
|
||||
auto cached_kernel_pack = TbeUtils::SearchCache(json_name, processor);
|
||||
auto cached_kernel_pack = TbeUtils::SearchCache(json_name);
|
||||
if (cached_kernel_pack != nullptr) {
|
||||
auto kernel_mod_ptr = GenKernelMod(input_size_list, output_size_list, cached_kernel_pack);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod_ptr);
|
||||
|
@ -272,18 +297,19 @@ int ParallelBuildManager::StartCompileOp(const nlohmann::json &kernel_json) {
|
|||
return AscendKernelBuildClient::Instance().TbeStart(kernel_json.dump(), tune_mode);
|
||||
}
|
||||
|
||||
std::string ParallelBuildManager::ProcessTbeJob(const nlohmann::json &kernel_json) {
|
||||
return AscendKernelBuildClient::Instance().TbeSendJob(kernel_json.dump());
|
||||
}
|
||||
|
||||
bool ParallelBuildManager::WaitOne(int *task_id, std::string *task_result, std::string *pre_build_result) {
|
||||
MS_EXCEPTION_IF_NULL(task_id);
|
||||
return AscendKernelBuildClient::Instance().TbeWait(task_id, task_result, pre_build_result);
|
||||
}
|
||||
|
||||
void ParallelBuildManager::ResetTaskInfo() noexcept {
|
||||
if (task_map_.empty()) {
|
||||
MS_LOG(INFO) << "All tasks are compiled success.";
|
||||
return;
|
||||
}
|
||||
task_map_.clear();
|
||||
same_op_list_.clear();
|
||||
pre_build_task_map_.clear();
|
||||
}
|
||||
|
||||
AnfNodePtr ParallelBuildManager::GetAnfNodeByTaskID(int32_t task_id) {
|
||||
|
|
|
@ -46,15 +46,15 @@ class ParallelBuildManager {
|
|||
void SaveTaskInfo(int32_t task_id, const AnfNodePtr &anf_node, const std::string &json_name,
|
||||
const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list,
|
||||
int64_t scope_id = 0);
|
||||
void SavePreBuildTaskInfo(int32_t task_id, const AnfNodePtr &anf_node, const std::string &json_name);
|
||||
void SaveSameOpInfo(const AnfNodePtr &anf_node, const std::string &json_name,
|
||||
const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list);
|
||||
void SaveSameFusionOpInfo(const int64_t scope_id, const std::string &json_name, const std::string &processor,
|
||||
const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list);
|
||||
bool GenSameOpKernelMod() const;
|
||||
bool GenSameFusionOpKernelMod(std::map<int64_t, KernelModPtr> *kernel_mode_ret) const;
|
||||
bool SearchInCache(const std::string &json_name, const std::string &processor,
|
||||
const std::vector<size_t> &input_size_list, const std::vector<size_t> &output_size_list,
|
||||
AnfNode *node) const;
|
||||
bool SearchInCache(const std::string &json_name, const std::vector<size_t> &input_size_list,
|
||||
const std::vector<size_t> &output_size_list, AnfNode *node) const;
|
||||
bool IsAllTaskFinish() const;
|
||||
void PreTaskFinishProcess(int32_t task_id, const std::string &pre_build_result);
|
||||
std::pair<int32_t, KernelModPtr> TaskFinishProcess(int32_t task_id, const std::string &build_ret,
|
||||
|
@ -64,12 +64,14 @@ class ParallelBuildManager {
|
|||
|
||||
// Interactive with real backend, who could be implemented by Python.
|
||||
static int StartCompileOp(const nlohmann::json &kernel_json);
|
||||
static std::string ProcessTbeJob(const nlohmann::json &kernel_json);
|
||||
static bool WaitOne(int *task_id, std::string *task_result, std::string *build_result);
|
||||
void ResetTaskInfo() noexcept;
|
||||
AnfNodePtr GetAnfNodeByTaskID(int32_t task_id);
|
||||
|
||||
private:
|
||||
std::map<int32_t, AnfNodePtr> pre_task_map_;
|
||||
std::map<int32_t, KernelBuildTaskInfo> pre_build_task_map_;
|
||||
std::map<int32_t, KernelBuildTaskInfo> task_map_;
|
||||
std::vector<KernelBuildTaskInfo> same_op_list_;
|
||||
};
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "backend/kernel_compiler/tbe/tbe_convert_utils.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_dynaminc_shape_util.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_build.h"
|
||||
#include "backend/kernel_compiler/tbe/ascend_kernel_compile.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_select/common_utils.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_broadcast_selecter.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_select/tbe_kernel_reduce_selecter.h"
|
||||
|
@ -34,6 +35,7 @@
|
|||
#include "backend/session/kernel_build_client.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "utils/convert_utils_base.h"
|
||||
#include "utils/json_operation_utils.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
constexpr auto kName = "name";
|
||||
|
@ -258,13 +260,24 @@ bool TbeKernelSelect::TbeCheckSupported(const KernelBuildInfoIter &kernel_build_
|
|||
// replace kernel_info with current kernel info
|
||||
auto kernel_build_info_tmp = AnfAlgo::GetSelectKernelBuildInfo(cnode_ptr_);
|
||||
AnfAlgo::SetSelectKernelBuildInfo(*kernel_build_info_iter, cnode_ptr_.get());
|
||||
nlohmann::json kernel_json;
|
||||
TbeKernelJsonCreator creator(CHECK_SUPPORTED);
|
||||
bool ret = creator.GenTbeSingleKernelJson(cnode_ptr_, &kernel_json);
|
||||
if (!ret) {
|
||||
MS_LOG(EXCEPTION) << "Gen tbe single kernel json for check support failed.";
|
||||
std::string old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
|
||||
bool ret = true;
|
||||
if (!old_build.empty()) {
|
||||
nlohmann::json kernel_json;
|
||||
TbeKernelJsonCreator creator(CHECK_SUPPORTED);
|
||||
ret = creator.GenTbeSingleKernelJson(cnode_ptr_, &kernel_json);
|
||||
if (!ret) {
|
||||
MS_LOG(EXCEPTION) << "Gen tbe single kernel json for check support failed.";
|
||||
}
|
||||
ret = AscendKernelBuildClient::Instance().CheckSupported(kernel_json.dump());
|
||||
} else {
|
||||
auto build_manager = kernel::ascend::AscendKernelCompileManager::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(build_manager);
|
||||
if (!build_manager->AscendOpCheckSupported(cnode_ptr_)) {
|
||||
MS_LOG(WARNING) << "Tbe check supported failed";
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
ret = AscendKernelBuildClient::Instance().CheckSupported(kernel_json.dump());
|
||||
AnfAlgo::SetSelectKernelBuildInfo(kernel_build_info_tmp, cnode_ptr_.get());
|
||||
return ret;
|
||||
}
|
||||
|
@ -416,19 +429,28 @@ std::vector<std::string> TbeKernelSelect::SplitStrToVec(const std::string &op_se
|
|||
}
|
||||
|
||||
std::string TbeKernelSelect::OpSelectFormat() {
|
||||
nlohmann::json kernel_json;
|
||||
std::string res_json_str;
|
||||
TbeKernelJsonCreator creator(OP_SELECT_FORMAT);
|
||||
bool ret = creator.GenTbeSingleKernelJson(cnode_ptr_, &kernel_json);
|
||||
if (!ret) {
|
||||
MS_LOG(EXCEPTION) << "GenTbeSingleKernelJson failed.";
|
||||
}
|
||||
res_json_str = AscendKernelBuildClient::Instance().SelectFormat(kernel_json.dump());
|
||||
if (res_json_str.empty()) {
|
||||
MS_LOG(EXCEPTION) << "Op select format error, input args: " << kernel_json.dump();
|
||||
}
|
||||
if (res_json_str.find("TBEException") != std::string::npos) {
|
||||
MS_LOG(EXCEPTION) << "Dynamic op select failed: " << res_json_str << ", input args: " << kernel_json.dump();
|
||||
std::string old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
|
||||
if (!old_build.empty()) {
|
||||
nlohmann::json kernel_json;
|
||||
TbeKernelJsonCreator creator(OP_SELECT_FORMAT);
|
||||
bool ret = creator.GenTbeSingleKernelJson(cnode_ptr_, &kernel_json);
|
||||
if (!ret) {
|
||||
MS_LOG(EXCEPTION) << "GenTbeSingleKernelJson failed.";
|
||||
}
|
||||
res_json_str = AscendKernelBuildClient::Instance().SelectFormat(kernel_json.dump());
|
||||
if (res_json_str.empty()) {
|
||||
MS_LOG(EXCEPTION) << "Op select format error, input args: " << kernel_json.dump();
|
||||
}
|
||||
if (res_json_str.find("TBEException") != std::string::npos) {
|
||||
MS_LOG(EXCEPTION) << "Dynamic op select failed: " << res_json_str << ", input args: " << kernel_json.dump();
|
||||
}
|
||||
} else {
|
||||
MS_LOG(INFO) << "Format select for node:[" << AnfAlgo::GetCNodeName(cnode_ptr_) << ", "
|
||||
<< cnode_ptr_->fullname_with_scope() << "].";
|
||||
auto build_manager = kernel::ascend::AscendKernelCompileManager::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(build_manager);
|
||||
res_json_str = build_manager->AscendOpSelectFormat(cnode_ptr_);
|
||||
}
|
||||
return res_json_str;
|
||||
}
|
||||
|
@ -471,7 +493,10 @@ void TbeKernelSelect::CreateNewOpInfo(const mindspore::kernel::OpInfo &op_info,
|
|||
MS_EXCEPTION_IF_NULL(op_info_new);
|
||||
auto op_seclect_json = OpSelectFormat();
|
||||
if (!op_seclect_json.empty()) {
|
||||
nlohmann::json json_obj = nlohmann::json::parse(op_seclect_json);
|
||||
nlohmann::json json_obj;
|
||||
if (!ParseJson(op_seclect_json, &json_obj)) {
|
||||
MS_LOG(EXCEPTION) << "Parse op_select_json error.";
|
||||
}
|
||||
if (!json_obj.is_object()) {
|
||||
MS_LOG(EXCEPTION) << "JsonStr is not an object, the jsonStr is:" << op_seclect_json;
|
||||
}
|
||||
|
|
|
@ -30,90 +30,184 @@
|
|||
#include "utils/ms_utils.h"
|
||||
#include "utils/ms_context.h"
|
||||
#include "ir/dtype/type.h"
|
||||
#include "runtime/dev.h"
|
||||
#include "runtime/device/ascend/lic_manager.h"
|
||||
#include "backend/session/anf_runtime_algorithm.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_convert_utils.h"
|
||||
#include "mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_json/tbe_json_creator.h"
|
||||
#include "mindspore/ccsrc/backend/kernel_compiler/tbe/tbe_json/single_tbe_json_creator.h"
|
||||
#include "securec/include/securec.h"
|
||||
#include "utils/json_operation_utils.h"
|
||||
#include "mindspore/ccsrc/debug/common.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
namespace tbe {
|
||||
constexpr auto kCceKernelMeta = "./kernel_meta/";
|
||||
constexpr auto kCceKernelMeta = "kernel_meta/";
|
||||
constexpr auto kJsonSuffix = ".json";
|
||||
constexpr auto kInfoSuffix = ".info";
|
||||
constexpr auto kSOC_VERSION = "SOC_VERSION";
|
||||
constexpr auto kBuildRes = "build_result";
|
||||
constexpr auto kTUNE_BANK_PATH = "TUNE_BANK_PATH";
|
||||
constexpr auto kTUNE_DUMP_PATH = "TUNE_DUMP_PATH";
|
||||
constexpr auto kJRlTuneSwitch = "rl_tune_switch";
|
||||
constexpr auto kJRlTuneList = "rl_tune_list";
|
||||
constexpr auto kJOpTuneSwitch = "op_tune_switch";
|
||||
constexpr auto kJOpTuneList = "op_tune_list";
|
||||
constexpr auto kJPassList = "pass_list";
|
||||
constexpr auto kRankID = "RANK_ID";
|
||||
constexpr auto kCOMPILER_OP_LEVEL = "MS_COMPILER_OP_LEVEL";
|
||||
constexpr auto kCOMPILER_CACHE_PATH = "MS_COMPILER_CACHE_PATH";
|
||||
|
||||
uintptr_t KernelManager::kernel_stub_gen_ = 0;
|
||||
std::unordered_map<string, KernelMetaPtr> KernelManager::info_table_ = {};
|
||||
|
||||
void TbeUtils::GenLicInfo(nlohmann::json *lic_info_json) {
|
||||
MS_EXCEPTION_IF_NULL(lic_info_json);
|
||||
(*lic_info_json)[kJRlTuneSwitch] = LicManager::GetInstance().GetRlTuneSwitch();
|
||||
(*lic_info_json)[kJRlTuneList] = LicManager::GetInstance().GetRlTuneList();
|
||||
(*lic_info_json)[kJOpTuneSwitch] = LicManager::GetInstance().GetOpTuneSwitch();
|
||||
(*lic_info_json)[kJOpTuneList] = LicManager::GetInstance().GetOpTuneList();
|
||||
(*lic_info_json)[kJPassList] = LicManager::GetInstance().GetPassSwitch();
|
||||
}
|
||||
|
||||
std::string TbeUtils::GetBankPath() {
|
||||
// tune bank path
|
||||
auto save_path = common::GetEnv(kTUNE_BANK_PATH);
|
||||
char real_path[PATH_MAX] = {0};
|
||||
if (!save_path.empty()) {
|
||||
if (realpath(save_path.c_str(), real_path)) {
|
||||
save_path = real_path;
|
||||
return save_path;
|
||||
}
|
||||
MS_LOG(EXCEPTION) << "Invalid env TUNE_BANK_PATH, path : " << save_path;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string TbeUtils::GetTuneDumpPath() {
|
||||
// tune dump path
|
||||
auto save_path = common::GetEnv(kTUNE_DUMP_PATH);
|
||||
char real_path[PATH_MAX] = {0};
|
||||
if (!save_path.empty()) {
|
||||
if (realpath(save_path.c_str(), real_path)) {
|
||||
save_path = real_path;
|
||||
return save_path;
|
||||
}
|
||||
MS_LOG(EXCEPTION) << "Invalid env kTUNE_DUMP_PATH, path : " << save_path;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string TbeUtils::GetOpDebugPath() {
|
||||
auto old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
|
||||
auto config_path = Common::CommonFuncForConfigPath("./", common::GetEnv(kCOMPILER_CACHE_PATH));
|
||||
if (!old_build.empty()) {
|
||||
if (config_path[config_path.length() - 1] == '/') {
|
||||
return config_path;
|
||||
}
|
||||
return config_path + "/";
|
||||
} else {
|
||||
std::string rank_id_str = common::GetEnv(kRankID);
|
||||
if (rank_id_str.empty()) {
|
||||
MS_LOG(DEBUG) << "Using the default value: 0";
|
||||
rank_id_str = "0";
|
||||
}
|
||||
if (config_path[config_path.length() - 1] == '/') {
|
||||
return config_path + "rank_" + rank_id_str + "/";
|
||||
}
|
||||
return config_path + "/" + "rank_" + rank_id_str + "/";
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetOpDebugLevel() {
|
||||
const std::set<std::string> exp = {"0", "1"};
|
||||
std::string op_debug_level = "0";
|
||||
auto env_level = common::GetEnv(kCOMPILER_OP_LEVEL);
|
||||
if (!env_level.empty()) {
|
||||
if (exp.find(env_level) == exp.end()) {
|
||||
MS_LOG(WARNING) << "Invalid COMPILER_OP_LEVEL env:" << env_level
|
||||
<< ", the value should be 0 or 1, now using the default value 0";
|
||||
} else {
|
||||
op_debug_level = env_level;
|
||||
}
|
||||
}
|
||||
return op_debug_level;
|
||||
}
|
||||
|
||||
void TbeUtils::GenSocInfo(nlohmann::json *soc_info_json) {
|
||||
auto context_ptr = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
MS_EXCEPTION_IF_NULL(soc_info_json);
|
||||
std::list<int64_t> list;
|
||||
(*soc_info_json)["coreNum"] = "";
|
||||
(*soc_info_json)["coreType"] = "";
|
||||
(*soc_info_json)["op_impl_mode"] = "";
|
||||
(*soc_info_json)["vector_fp_ceiling"] = "";
|
||||
(*soc_info_json)["op_impl_mode_list"] = list;
|
||||
(*soc_info_json)["l2Mode"] = "2";
|
||||
(*soc_info_json)["l1Fusion"] = "false";
|
||||
(*soc_info_json)["l2Fusion"] = "false";
|
||||
(*soc_info_json)["l2Mode"] = "2";
|
||||
(*soc_info_json)["op_debug_level"] = "";
|
||||
(*soc_info_json)["op_impl_mode"] = "";
|
||||
(*soc_info_json)["op_impl_mode_list"] = list;
|
||||
(*soc_info_json)["op_bank_update"] = false;
|
||||
(*soc_info_json)["socVersion"] = GetSocVersion();
|
||||
(*soc_info_json)["offlineTune"] = CheckOfflineTune();
|
||||
(*soc_info_json)["op_debug_dir"] = GetOpDebugPath();
|
||||
(*soc_info_json)["op_debug_level"] = GetOpDebugLevel();
|
||||
(*soc_info_json)["autoTilingMode"] = context_ptr->get_param<std::string>(MS_CTX_TUNE_MODE);
|
||||
(*soc_info_json)["deviceId"] = std::to_string(context_ptr->get_param<uint32_t>(MS_CTX_DEVICE_ID));
|
||||
(*soc_info_json)["op_bank_path"] = Common::CommonFuncForConfigPath("", common::GetEnv("OP_BANK_PATH"));
|
||||
(*soc_info_json)["mdl_bank_path"] = Common::CommonFuncForConfigPath("", common::GetEnv("MDL_BANK_PATH"));
|
||||
}
|
||||
|
||||
void TbeUtils::SaveJsonInfo(const std::string &json_name, const std::string &info) {
|
||||
char real_path[PATH_MAX] = {0};
|
||||
std::string path = kCceKernelMeta + json_name + kInfoSuffix;
|
||||
if (path.size() >= PATH_MAX) {
|
||||
MS_LOG(ERROR) << "File path: " << path << "is too long.";
|
||||
auto config_path = TbeUtils::GetOpDebugPath();
|
||||
std::string path = config_path + kCceKernelMeta + json_name + kInfoSuffix;
|
||||
auto realpath = Common::GetRealPath(path);
|
||||
if (!realpath.has_value()) {
|
||||
MS_LOG(WARNING) << "Get real path failed, invalid path: " << realpath.value();
|
||||
return;
|
||||
}
|
||||
std::ifstream fin(path);
|
||||
if (fin) {
|
||||
MS_LOG(INFO) << "Json file exist(" << path << "), no need to create.";
|
||||
return;
|
||||
}
|
||||
std::ofstream file_write;
|
||||
file_write.open(path);
|
||||
ChangeFileMode(realpath.value(), S_IWUSR);
|
||||
std::ofstream file_write(realpath.value());
|
||||
if (!file_write.is_open()) {
|
||||
MS_LOG(WARNING) << "Create info file failed(" << path << ").";
|
||||
MS_LOG(WARNING) << "Create info file failed(" << realpath.value() << ").";
|
||||
return;
|
||||
}
|
||||
file_write << info << std::endl;
|
||||
file_write.close();
|
||||
if (realpath(path.c_str(), real_path) == nullptr) {
|
||||
MS_LOG(WARNING) << "Get realpath failed(" << path << ").";
|
||||
return;
|
||||
}
|
||||
MS_LOG(INFO) << "real path is: " << real_path;
|
||||
if (chmod(real_path, S_IRUSR) == -1) {
|
||||
MS_LOG(INFO) << "modify file: " << real_path << "to read only fail.";
|
||||
}
|
||||
file_write.clear();
|
||||
ChangeFileMode(realpath.value(), S_IRUSR);
|
||||
}
|
||||
|
||||
void TbeUtils::LoadCache() {
|
||||
static bool has_load = false;
|
||||
if (!has_load) {
|
||||
auto bin_map = KernelMeta::GetInstance();
|
||||
if (!bin_map->ReadIndex(kCceKernelMeta)) {
|
||||
MS_LOG(INFO) << "Cache initialize failed[" << kCceKernelMeta << "]";
|
||||
auto config_path = TbeUtils::GetOpDebugPath();
|
||||
auto path = config_path + kCceKernelMeta;
|
||||
if (!bin_map->ReadIndex(path)) {
|
||||
MS_LOG(INFO) << "Cache initialize failed[" << path << "]";
|
||||
}
|
||||
has_load = true;
|
||||
}
|
||||
}
|
||||
|
||||
KernelPackPtr TbeUtils::SearchCache(const std::string &kernel_name, const std::string &processor) {
|
||||
KernelPackPtr TbeUtils::SearchCache(const std::string &kernel_name, const bool is_akg) {
|
||||
// search cache.
|
||||
KernelMeta *bin_map = KernelMeta::GetInstance();
|
||||
if (bin_map == nullptr) {
|
||||
MS_LOG(INFO) << "kernel cache is invalid.";
|
||||
return nullptr;
|
||||
}
|
||||
return bin_map->GetKernelPack(kernel_name, processor);
|
||||
return bin_map->GetKernelPack(kernel_name, is_akg);
|
||||
}
|
||||
|
||||
KernelPackPtr TbeUtils::InsertCache(const std::string &kernel_name, const std::string &processor) {
|
||||
KernelPackPtr TbeUtils::InsertCache(const std::string &kernel_name, const std::string &processor, const bool is_akg) {
|
||||
MS_LOG(INFO) << "kernel name: " << kernel_name << ", processr:" << processor;
|
||||
if (processor != kProcessorAiCore) {
|
||||
MS_LOG(EXCEPTION) << "process type should be aicore, actually is: " << processor;
|
||||
}
|
||||
return SearchCache(kernel_name, processor);
|
||||
return SearchCache(kernel_name, is_akg);
|
||||
}
|
||||
|
||||
int KernelManager::BinaryRegister(const mindspore::kernel::FlexArray &kernel_buffer, void **module, const string &magic,
|
||||
|
@ -245,7 +339,123 @@ bool KernelMeta::ReadIndex(const std::string &bin_dir) {
|
|||
return true;
|
||||
}
|
||||
|
||||
KernelPackPtr KernelMeta::GetKernelPack(const std::string &kernel_name, const std::string &processor) {
|
||||
void TbeUtils::GetCompileInfo(const AnfNodePtr &node, std::string *compile_info, bool *get_flag) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
MS_LOG(INFO) << "Get compile info from json file start. [" << node->fullname_with_scope() << "]";
|
||||
auto json_creator = std::make_shared<kernel::BuildTbeJsonCreator>();
|
||||
MS_EXCEPTION_IF_NULL(json_creator);
|
||||
nlohmann::json kernel_json;
|
||||
if (!json_creator->GenJson(node, &kernel_json)) {
|
||||
MS_LOG(WARNING) << "Gen kernel json failed [" << node->fullname_with_scope() << "]";
|
||||
*get_flag = false;
|
||||
return;
|
||||
}
|
||||
auto json_name = json_creator->GetJsonName();
|
||||
auto config_path = TbeUtils::GetOpDebugPath();
|
||||
std::string path = config_path + kCceKernelMeta + json_name + kJsonSuffix;
|
||||
if (path.size() > PATH_MAX) {
|
||||
MS_LOG(WARNING) << "File path: " << path << "is too long.";
|
||||
*get_flag = false;
|
||||
return;
|
||||
}
|
||||
nlohmann::json read_new_json;
|
||||
std::ifstream file(path.c_str());
|
||||
std::string ori_file = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
if (!ParseJson(ori_file, &read_new_json)) {
|
||||
MS_LOG(EXCEPTION) << "Parse compile info error.";
|
||||
}
|
||||
*compile_info = read_new_json[kBuildRes].dump();
|
||||
file.close();
|
||||
file.clear();
|
||||
MS_LOG(INFO) << "Get compile info from json file success";
|
||||
}
|
||||
|
||||
void TbeUtils::SaveCompileInfo(const std::string &json_name, const std::string &build_res, bool *save_flag) {
|
||||
MS_LOG(INFO) << "Save compile info to json file start. [" << json_name << "], value: " << build_res;
|
||||
auto config_path = TbeUtils::GetOpDebugPath();
|
||||
std::string path = config_path + kCceKernelMeta + json_name + kJsonSuffix;
|
||||
if (path.size() > PATH_MAX) {
|
||||
MS_LOG(WARNING) << "File path: " << path << "is too long.";
|
||||
*save_flag = false;
|
||||
return;
|
||||
}
|
||||
nlohmann::json save_new_json;
|
||||
std::ifstream file(path.c_str());
|
||||
std::string ori_file = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
if (!ParseJson(ori_file, &save_new_json)) {
|
||||
MS_LOG(EXCEPTION) << "Parse compile info error.";
|
||||
}
|
||||
file.close();
|
||||
file.clear();
|
||||
if (build_res.empty()) {
|
||||
save_new_json[kBuildRes] = build_res;
|
||||
} else {
|
||||
save_new_json[kBuildRes] = nlohmann::json::parse(build_res);
|
||||
}
|
||||
std::ofstream file_write;
|
||||
file_write.open(path);
|
||||
if (!file_write.is_open()) {
|
||||
MS_LOG(WARNING) << "Create info file failed. [" << path << "]";
|
||||
*save_flag = false;
|
||||
return;
|
||||
}
|
||||
const int indent = 4;
|
||||
auto info = save_new_json.dump(indent);
|
||||
file_write << info << std::endl;
|
||||
file_write.close();
|
||||
file_write.clear();
|
||||
MS_LOG(INFO) << "Save compile info to json file success";
|
||||
}
|
||||
|
||||
bool TbeUtils::CheckOfflineTune() {
|
||||
bool offline = false;
|
||||
std::string offline_tune = common::GetEnv("ENABLE_TUNE_DUMP");
|
||||
if (!offline_tune.empty()) {
|
||||
for (size_t j = 0; j < offline_tune.length(); j++) {
|
||||
offline_tune[j] = tolower(offline_tune[j]);
|
||||
}
|
||||
if (!(offline_tune == "true" || offline_tune == "false")) {
|
||||
MS_LOG(EXCEPTION) << "The value of ENABLE_TUNE_DUMP must be 'true' or 'false'";
|
||||
}
|
||||
offline = (offline_tune == "true");
|
||||
}
|
||||
return offline;
|
||||
}
|
||||
|
||||
std::string TbeUtils::GetSocVersion() {
|
||||
// Get default soc version.
|
||||
static std::string version;
|
||||
if (version.empty()) {
|
||||
const int kSocVersionLen = 50;
|
||||
char soc_version[kSocVersionLen] = {0};
|
||||
auto ret = rtGetSocVersion(soc_version, kSocVersionLen);
|
||||
if (ret != RT_ERROR_NONE) {
|
||||
MS_LOG(EXCEPTION) << "GetSocVersion failed.";
|
||||
}
|
||||
// Get soc version from env value.
|
||||
const char *soc_version_env = nullptr;
|
||||
std::string str_soc_version_env = common::GetEnv(kSOC_VERSION);
|
||||
if (!str_soc_version_env.empty()) {
|
||||
soc_version_env = common::SafeCStr(str_soc_version_env);
|
||||
}
|
||||
if (soc_version_env != nullptr) {
|
||||
if (std::strcmp(soc_version, soc_version_env) != 0) {
|
||||
MS_LOG(DEBUG) << "Detected the env SOC_VERSION, so the SocVersion will be changed to " << str_soc_version_env
|
||||
<< ".";
|
||||
ret = rtSetSocVersion(soc_version_env);
|
||||
if (ret != RT_ERROR_NONE) {
|
||||
MS_LOG(EXCEPTION) << "SetSocVersion failed, errorno: " << ret;
|
||||
}
|
||||
version = soc_version_env;
|
||||
return soc_version_env;
|
||||
}
|
||||
}
|
||||
version = soc_version;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
KernelPackPtr KernelMeta::GetKernelPack(const std::string &kernel_name, const bool is_akg) {
|
||||
KernelPackPtr ret = nullptr;
|
||||
// 1. pack has been created
|
||||
auto kernel_pack_iter = kernel_pack_map_.find(kernel_name);
|
||||
|
@ -253,10 +463,11 @@ KernelPackPtr KernelMeta::GetKernelPack(const std::string &kernel_name, const st
|
|||
ret = kernel_pack_iter->second;
|
||||
} else {
|
||||
// 2. kernel file has been create, but pack does not been created.
|
||||
std::string cce_json = kCceKernelMeta;
|
||||
(void)cce_json.append(kernel_name).append(kJsonSuffix);
|
||||
auto config_path = TbeUtils::GetOpDebugPath();
|
||||
std::string cce_json = is_akg ? ("./kernel_meta/" + kernel_name + kJsonSuffix)
|
||||
: (config_path + kCceKernelMeta + kernel_name + kJsonSuffix);
|
||||
ret = std::make_shared<KernelPack>();
|
||||
if (!ret->LoadKernelMeta(cce_json, processor)) {
|
||||
if (!ret->LoadKernelMeta(cce_json)) {
|
||||
MS_LOG(INFO) << "Read cache json and bin file failed[" << cce_json << "]";
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <vector>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
@ -33,7 +34,6 @@ namespace kernel {
|
|||
namespace tbe {
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
class TbeUtils {
|
||||
public:
|
||||
TbeUtils() = default;
|
||||
|
@ -44,11 +44,28 @@ class TbeUtils {
|
|||
|
||||
static void LoadCache();
|
||||
|
||||
static void GenLicInfo(nlohmann::json *lic_info_json);
|
||||
|
||||
static void GenSocInfo(nlohmann::json *soc_info_json);
|
||||
|
||||
static KernelPackPtr SearchCache(const std::string &kernel_name, const std::string &processor);
|
||||
static std::string GetSocVersion();
|
||||
|
||||
static KernelPackPtr InsertCache(const std::string &kernel_name, const std::string &processor);
|
||||
static std::string GetOpDebugPath();
|
||||
|
||||
static std::string GetBankPath();
|
||||
|
||||
static std::string GetTuneDumpPath();
|
||||
|
||||
static void SaveCompileInfo(const std::string &json_name, const std::string &build_res, bool *save_flag);
|
||||
|
||||
static void GetCompileInfo(const AnfNodePtr &node, std::string *compile_info, bool *get_flag);
|
||||
|
||||
static bool CheckOfflineTune();
|
||||
|
||||
static KernelPackPtr SearchCache(const std::string &kernel_name, const bool is_akg = false);
|
||||
|
||||
static KernelPackPtr InsertCache(const std::string &kernel_name, const std::string &processor,
|
||||
const bool is_akg = false);
|
||||
};
|
||||
|
||||
struct KernelMetaInfo {
|
||||
|
@ -77,7 +94,7 @@ class KernelMeta {
|
|||
public:
|
||||
static KernelMeta *GetInstance();
|
||||
bool ReadIndex(const std::string &bin_dir);
|
||||
KernelPackPtr GetKernelPack(const std::string &kernel_name, const std::string &processor);
|
||||
KernelPackPtr GetKernelPack(const std::string &kernel_name, const bool is_akg = false);
|
||||
|
||||
private:
|
||||
KernelMeta() = default;
|
||||
|
|
|
@ -128,6 +128,7 @@
|
|||
#include "backend/optimizer/ascend/enhancer/add_placeholder_for_dynamic_gru.h"
|
||||
#include "backend/optimizer/ascend/enhancer/add_attr_for_3d_graph.h"
|
||||
#include "backend/optimizer/ascend/enhancer/split_n_optimizer.h"
|
||||
#include "backend/kernel_compiler/tbe/ascend_kernel_compile.h"
|
||||
#include "utils/ms_context.h"
|
||||
#include "utils/config_manager.h"
|
||||
#include "utils/context/graph_kernel_flags.h"
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "backend/kernel_compiler/tbe/tbe_convert_utils.h"
|
||||
#include "backend/kernel_compiler/tbe/ascend_kernel_compile.h"
|
||||
#include "backend/kernel_compiler/kernel_fusion.h"
|
||||
#include "debug/anf_ir_dump.h"
|
||||
#include "backend/session/anf_runtime_algorithm.h"
|
||||
|
@ -432,7 +434,16 @@ bool UbPatternFusion::FuseBufferFusionPattern(session::KernelGraph *kernel_graph
|
|||
buffer_fusion_info.first, buffer_fusion_info.second.full_name, buffer_fusion_info.second.inputs_list,
|
||||
buffer_fusion_info.second.anf_nodes, buffer_fusion_info.second.outputs_list);
|
||||
});
|
||||
auto kernel_mods = mindspore::kernel::KernelFusion(fusion_scope_infos);
|
||||
std::map<int64_t, kernel::KernelModPtr> kernel_mods;
|
||||
std::string old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
|
||||
if (!old_build.empty()) {
|
||||
kernel_mods = mindspore::kernel::KernelFusion(fusion_scope_infos);
|
||||
} else if (!fusion_scope_infos.empty()) {
|
||||
auto build_manager = kernel::ascend::AscendKernelCompileManager::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(build_manager);
|
||||
build_manager->ResetOldTask();
|
||||
kernel_mods = build_manager->AscendFusionOpCompile(fusion_scope_infos);
|
||||
}
|
||||
std::set<int64_t> fusion_ids;
|
||||
for (auto &buffer_fusion_info : buffer_fusion_infos) {
|
||||
MS_LOG(DEBUG) << "anf node size: " << buffer_fusion_info.second.anf_nodes.size()
|
||||
|
|
|
@ -26,6 +26,25 @@
|
|||
#include "utils/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
std::string Common::CommonFuncForConfigPath(const std::string &default_path, const std::string &env_path) {
|
||||
std::string res_path = default_path;
|
||||
if (!env_path.empty()) {
|
||||
char real_path[PATH_MAX] = {0};
|
||||
#if defined(SYSTEM_ENV_WINDOWS)
|
||||
if (_fullpath(real_path, common::SafeCStr(env_path), PATH_MAX) == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "The dir " << env_path << " does not exist.";
|
||||
}
|
||||
return real_path;
|
||||
#else
|
||||
if (realpath(env_path.c_str(), real_path)) {
|
||||
return real_path;
|
||||
}
|
||||
MS_LOG(EXCEPTION) << "Invalid env path, path : " << env_path;
|
||||
#endif
|
||||
}
|
||||
return res_path;
|
||||
}
|
||||
|
||||
std::optional<std::string> Common::GetRealPath(const std::string &input_path) {
|
||||
if (input_path.length() >= PATH_MAX) {
|
||||
MS_LOG(ERROR) << "The length of path: " << input_path << " exceeds limit: " << PATH_MAX;
|
||||
|
|
|
@ -39,6 +39,7 @@ class Common {
|
|||
static std::string AddId(const std::string &filename, const std::string &suffix);
|
||||
static bool SaveStringToFile(const std::string filename, const std::string string_info);
|
||||
static bool FileExists(const std::string &filepath);
|
||||
static std::string CommonFuncForConfigPath(const std::string &default_path, const std::string &env_path);
|
||||
|
||||
private:
|
||||
static bool IsEveryFilenameValid(const std::string &path, size_t length_limit, const std::string &error_message);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "pipeline/jit/static_analysis/static_analysis.h"
|
||||
#include "runtime/device/ascend/executor/tiling/op_tiling_adapter.h"
|
||||
#include "common/trans.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace device {
|
||||
|
@ -71,20 +72,23 @@ void AiCoreDynamicKernel::ParseCompileJson() {
|
|||
if (!AnfAlgo::IsDynamicShape(cnode)) {
|
||||
return;
|
||||
}
|
||||
if (!AnfAlgo::HasNodeAttr(kAttrCompileInfo, cnode)) {
|
||||
MS_LOG(EXCEPTION) << "Get compile_info failed";
|
||||
}
|
||||
auto compile_info_attr = AnfAlgo::GetNodeAttr<std::string>(cnode, kAttrCompileInfo);
|
||||
MS_LOG(INFO) << "Get compile_info:" << compile_info_attr;
|
||||
op_compile_info_.str = compile_info_attr;
|
||||
op_compile_info_.key = "";
|
||||
|
||||
if (AnfAlgo::HasNodeAttr(kAttrFusionType, cnode)) {
|
||||
auto fusion_type = AnfAlgo::GetNodeAttr<std::string>(cnode, kAttrFusionType);
|
||||
MS_LOG(INFO) << "Get fusion_type:" << fusion_type;
|
||||
(*compile_info_json_)["_pattern"] = fusion_type;
|
||||
op_compile_info_.key = std::hash<std::string>{}(fusion_type);
|
||||
MS_LOG(INFO) << "Get compile_info from attr start.";
|
||||
std::string old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
|
||||
if (!old_build.empty()) {
|
||||
if (!AnfAlgo::HasNodeAttr(kAttrCompileInfo, cnode)) {
|
||||
MS_LOG(EXCEPTION) << "Get compile info failed.";
|
||||
}
|
||||
op_compile_info_ = AnfAlgo::GetNodeAttr<std::string>(cnode, kAttrCompileInfo);
|
||||
} else {
|
||||
bool get_flag = true;
|
||||
TbeUtils::GetCompileInfo(cnode, &op_compile_info_, &get_flag);
|
||||
if (!get_flag) {
|
||||
MS_LOG(EXCEPTION) << "Get compile_info failed. The compile result of [" << AnfAlgo::GetCNodeName(cnode)
|
||||
<< "]maybe not in the json file(dir:./kernel_meta/) or the file had been deleted";
|
||||
}
|
||||
}
|
||||
MS_LOG(INFO) << "Get compile_info:" << op_compile_info_;
|
||||
}
|
||||
|
||||
void AiCoreDynamicKernel::Initialize() {
|
||||
|
@ -135,7 +139,7 @@ void AiCoreDynamicKernel::ComputeTiling() {
|
|||
optiling::utils::OpRunInfo op_run_info_v2(-1, true, 0);
|
||||
tiling::OpTilingCalculateAdapter converter;
|
||||
ge::ComputeGraphPtr ge_graph = std::make_shared<ge::ComputeGraph>("default");
|
||||
auto ge_node = converter.AnfNodeToGeNodeAdapter(cnode, &ge_graph, depend_tensor_map_);
|
||||
auto ge_node = converter.AnfNodeToGeNodeAdapter(cnode, &ge_graph, depend_tensor_map_, op_compile_info_);
|
||||
(void)optiling::OpParaCalculateV2(*ge_node, op_run_info_v2);
|
||||
|
||||
block_dim_ = op_run_info_v2.GetBlockDim();
|
||||
|
|
|
@ -71,7 +71,7 @@ class AiCoreDynamicKernel : public DynamicKernel {
|
|||
std::vector<int64_t> workspaces_size_;
|
||||
std::vector<DeviceAddressPtr> workspace_addr_;
|
||||
std::shared_ptr<nlohmann::json> compile_info_json_;
|
||||
optiling::OpCompileInfo op_compile_info_{};
|
||||
std::string op_compile_info_;
|
||||
uint32_t tiling_key_{0};
|
||||
const std::string origin_key_{""};
|
||||
|
||||
|
|
|
@ -138,14 +138,10 @@ void OpTilingCalculateAdapter::ConvertOutputShapeAndType(const CNodePtr &node, g
|
|||
void OpTilingCalculateAdapter::ConvertCompileInfo(const CNodePtr &node, ge::OpDescPtr *op_desc) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
MS_EXCEPTION_IF_NULL(*op_desc);
|
||||
if (!AnfAlgo::HasNodeAttr(kAttrCompileInfo, node)) {
|
||||
MS_LOG(EXCEPTION) << "Get compile_info failed";
|
||||
}
|
||||
auto compile_info_attr = AnfAlgo::GetNodeAttr<std::string>(node, kAttrCompileInfo);
|
||||
MS_LOG(INFO) << "For op " << op_name_ << ", get compile_info: " << compile_info_attr;
|
||||
std::string compile_info_key = std::to_string(std::hash<std::string>()(compile_info_attr));
|
||||
MS_LOG(INFO) << "For op " << op_name_ << ", get compile_info: " << op_compile_info_;
|
||||
std::string compile_info_key = std::to_string(std::hash<std::string>()(op_compile_info_));
|
||||
(void)ge::AttrUtils::SetStr(*(*op_desc), COMPILE_INFO_KEY, compile_info_key);
|
||||
(void)ge::AttrUtils::SetStr(*(*op_desc), COMPILE_INFO_JSON, compile_info_attr);
|
||||
(void)ge::AttrUtils::SetStr(*(*op_desc), COMPILE_INFO_JSON, op_compile_info_);
|
||||
}
|
||||
|
||||
ge::NodePtr OpTilingCalculateAdapter::NewConstantOp(const CNodePtr &node, const std::string &name,
|
||||
|
@ -269,9 +265,11 @@ void OpTilingCalculateAdapter::InitOpIoName(const CNodePtr &node) {
|
|||
}
|
||||
|
||||
ge::NodePtr OpTilingCalculateAdapter::AnfNodeToGeNodeAdapter(
|
||||
const CNodePtr &node, ge::ComputeGraphPtr *ge_graph, const std::map<uint32_t, tensor::TensorPtr> &depend_tensor_map) {
|
||||
const CNodePtr &node, ge::ComputeGraphPtr *ge_graph, const std::map<uint32_t, tensor::TensorPtr> &depend_tensor_map,
|
||||
const std::string &op_compile_info) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
op_name_ = AnfAlgo::GetCNodeName(node);
|
||||
op_compile_info_ = op_compile_info;
|
||||
auto op_type = GetRealOpType(op_name_);
|
||||
(void)InitOpIoName(node);
|
||||
ge::OpDescPtr op_desc = std::make_shared<ge::OpDesc>(op_name_, op_type);
|
||||
|
|
|
@ -37,7 +37,8 @@ class OpTilingCalculateAdapter {
|
|||
~OpTilingCalculateAdapter() = default;
|
||||
|
||||
ge::NodePtr AnfNodeToGeNodeAdapter(const CNodePtr &node, ge::ComputeGraphPtr *ge_graph,
|
||||
const std::map<uint32_t, tensor::TensorPtr> &depend_tensor_map);
|
||||
const std::map<uint32_t, tensor::TensorPtr> &depend_tensor_map,
|
||||
const std::string &op_compile_info);
|
||||
|
||||
private:
|
||||
void ConvertInputShapeAndType(const CNodePtr &node, ge::OpDescPtr *op_desc);
|
||||
|
@ -55,6 +56,7 @@ class OpTilingCalculateAdapter {
|
|||
std::string GetOutputName(const CNodePtr &node, size_t index);
|
||||
void InitOpIoName(const CNodePtr &node);
|
||||
std::string op_name_;
|
||||
std::string op_compile_info_;
|
||||
std::vector<std::string> input_names_;
|
||||
std::vector<std::string> output_names_;
|
||||
};
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "runtime/device/ascend/kernel_select_ascend.h"
|
||||
#include "runtime/device/kernel_info.h"
|
||||
#include "backend/kernel_compiler/kernel.h"
|
||||
#include "backend/kernel_compiler/tbe/ascend_kernel_compile.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_parallel_build.h"
|
||||
#include "backend/kernel_compiler/akg/ascend/akg_ascend_kernel_build.h"
|
||||
#include "backend/kernel_compiler/aicpu/aicpu_kernel_build.h"
|
||||
|
@ -96,11 +97,28 @@ static bool KernelBuildParallelCompile(const std::vector<CNodePtr> &kernels) {
|
|||
}
|
||||
}
|
||||
}
|
||||
bool tbe_ret = kernel::TbeOpParallelBuild(tbe_nodes);
|
||||
kernel::AkgAscendKernelBuilder akg_ascend_kernel_builder;
|
||||
bool akg_ret = akg_ascend_kernel_builder.AkgKernelParallelBuild(akg_nodes);
|
||||
bool tbe_ret = true;
|
||||
bool akg_ret = true;
|
||||
auto bin_map = kernel::tbe::KernelMeta::GetInstance();
|
||||
(void)bin_map->ReadIndex(kernel::kCceKernelMeta);
|
||||
if (!tbe_nodes.empty()) {
|
||||
std::string old_build = common::GetEnv("MS_OLD_BUILD_PROCESS");
|
||||
if (!old_build.empty()) {
|
||||
tbe_ret = kernel::TbeOpParallelBuild(tbe_nodes);
|
||||
} else {
|
||||
auto build_manager = kernel::ascend::AscendKernelCompileManager::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(build_manager);
|
||||
build_manager->ResetOldTask();
|
||||
tbe_ret = build_manager->AscendSingleOpCompile(tbe_nodes);
|
||||
}
|
||||
auto config_path = TbeUtils::GetOpDebugPath();
|
||||
std::string dir = config_path + "kernel_meta/";
|
||||
(void)bin_map->ReadIndex(dir);
|
||||
}
|
||||
if (!akg_nodes.empty()) {
|
||||
kernel::AkgAscendKernelBuilder akg_ascend_kernel_builder;
|
||||
akg_ret = akg_ascend_kernel_builder.AkgKernelParallelBuild(akg_nodes);
|
||||
(void)bin_map->ReadIndex(kernel::kCceKernelMeta);
|
||||
}
|
||||
for (const auto &anf_node : other_nodes) {
|
||||
kernel::KernelModPtr kernel_mod_ptr = SerialCompileImpl(anf_node);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod_ptr);
|
||||
|
@ -223,6 +241,11 @@ static bool IsAtomicNode(const CNodePtr &kernel_node) {
|
|||
MS_LOG(EXCEPTION) << "Atomic addr clean doesn't support clean input address, input index: " << j;
|
||||
}
|
||||
}
|
||||
|
||||
if (parameters_indexs.size() < total_num) {
|
||||
MS_LOG(EXCEPTION) << "parameters indexes size: " << parameters_indexs.size()
|
||||
<< " less than total num: " << total_num;
|
||||
}
|
||||
// process output
|
||||
std::vector<size_t> output_indexs = {};
|
||||
if (AnfAlgo::HasNodeAttr(kAttrAtomicOutputIndexs, kernel_node)) {
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
"offlineTune": false,
|
||||
"op_bank_path": "",
|
||||
"op_bank_update": false,
|
||||
"op_compiler_cache_dir": "",
|
||||
"op_compiler_cache_mode": 0,
|
||||
"op_debug_dir": "./",
|
||||
"op_debug_level": "0",
|
||||
"op_impl_mode": "",
|
||||
|
|
|
@ -184,6 +184,7 @@ list(REMOVE_ITEM MINDSPORE_SRC_LIST "../../../mindspore/ccsrc/backend/optimizer/
|
|||
list(REMOVE_ITEM MINDSPORE_SRC_LIST "../../../mindspore/ccsrc/backend/optimizer/gpu/batch_norm_add_relu_grad_fusion.cc")
|
||||
list(REMOVE_ITEM MINDSPORE_SRC_LIST "../../../mindspore/ccsrc/backend/optimizer/gpu/batch_norm_relu_fusion.cc")
|
||||
list(REMOVE_ITEM MINDSPORE_SRC_LIST "../../../mindspore/ccsrc/backend/optimizer/gpu/batch_norm_relu_grad_fusion.cc")
|
||||
list(REMOVE_ITEM MINDSPORE_SRC_LIST "../../../mindspore/ccsrc/backend/kernel_compiler/tbe/ascend_kernel_compile.cc")
|
||||
|
||||
add_library(_ut_mindspore_obj OBJECT ${MINDSPORE_SRC_LIST})
|
||||
add_library(_ut_ut_obj OBJECT ${UT_SRCS})
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
#include "backend/kernel_compiler/kernel_fusion.h"
|
||||
#include "backend/kernel_compiler/tbe/tbe_kernel_mod.h"
|
||||
#include "backend/kernel_compiler/tbe/ascend_kernel_compile.h"
|
||||
#include "utils/ms_utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
|
@ -26,5 +27,26 @@ std::map<int64_t, KernelModPtr> KernelFusion(const std::vector<FusionScopeInfo>
|
|||
}
|
||||
return kernel_mod_ret;
|
||||
}
|
||||
namespace ascend {
|
||||
std::string AscendKernelCompileManager::AscendOpSelectFormat(const AnfNodePtr &node) { return std::string(); }
|
||||
bool AscendKernelCompileManager::AscendOpCheckSupported(const AnfNodePtr &node) { return true; }
|
||||
AscendKernelCompileManager::~AscendKernelCompileManager() {}
|
||||
bool AscendKernelCompileManager::tbe_init_flag_ = true;
|
||||
|
||||
void AscendKernelCompileManager::TbeInitialize() {}
|
||||
// pre build
|
||||
void AscendKernelCompileManager::AscendPreBuild(const std::shared_ptr<session::KernelGraph> &kernel_graph) {}
|
||||
// single op compile
|
||||
bool AscendKernelCompileManager::AscendSingleOpCompile(const std::vector<AnfNodePtr> &anf_nodes) { return true; }
|
||||
// fusion op compile
|
||||
KernelModMap AscendKernelCompileManager::AscendFusionOpCompile(const std::vector<FusionScopeInfo> &fusion_scopes) {
|
||||
std::map<int64_t, KernelModPtr> kernel_mod_ret;
|
||||
for (const auto &fusion_scope_iter : fusion_scopes) {
|
||||
kernel_mod_ret[fusion_scope_iter.scope_id] = std::make_shared<TbeKernelMod>(nullptr);
|
||||
}
|
||||
return kernel_mod_ret;
|
||||
}
|
||||
void AscendKernelCompileManager::ResetOldTask() {}
|
||||
} // namespace ascend
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
|
|
Loading…
Reference in New Issue