diff --git a/ge/graph/build/model_builder.cc b/ge/graph/build/model_builder.cc index 593be7bb..52711f71 100755 --- a/ge/graph/build/model_builder.cc +++ b/ge/graph/build/model_builder.cc @@ -418,6 +418,14 @@ Status ModelBuilder::BuildModelDef(ge::Model &model) { return FAILED); GELOGI("For model, max_mem_offset_: %zu, p2p_mem_size: %zu, zero_copy_mem_size_: %zu", max_mem_offset_, p2p_mem_offset_, zero_copy_mem_size_); + string fp_ceiling_mode; + if (ge::GetContext().GetOption("ge.fpCeilingMode", fp_ceiling_mode) == SUCCESS) { + if (!ge::AttrUtils::SetStr(&model, ATTR_FP_CEILING_MODE, fp_ceiling_mode)) { + GELOGE(FAILED, "Failed to set attr ATTR_FP_CEILING_MODE"); + return FAILED; + } + GELOGI("Set attr ATTR_FP_CEILING_MODE to model, value is %s.", fp_ceiling_mode.c_str()); + } string ge_core_type; Status ret = ge::GetContext().GetOption(kCoreType, ge_core_type); diff --git a/ge/graph/load/new_model_manager/davinci_model.cc b/ge/graph/load/new_model_manager/davinci_model.cc index cb37182c..5ac825cc 100755 --- a/ge/graph/load/new_model_manager/davinci_model.cc +++ b/ge/graph/load/new_model_manager/davinci_model.cc @@ -676,7 +676,9 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size auto all_dump_model = GetDumpProperties().GetAllDumpModel(); bool findByOmName = all_dump_model.find(om_name_) != all_dump_model.end(); bool findByModelName = all_dump_model.find(name_) != all_dump_model.end(); - if (all_dump_model.find(ge::DUMP_ALL_MODEL) != all_dump_model.end() || findByOmName || findByModelName) { + bool dump_l1fusion_op = (all_dump_model.find(ge::DUMP_ALL_MODEL) != all_dump_model.end()) || + findByOmName || findByModelName; + if (dump_l1fusion_op) { // malloc 2M for dump l1fusion op GE_CHK_RT_RET(rtMalloc(&l1_fusion_addr_, kDumpL1FusionOpMByteSize, RT_MEMORY_DDR)); @@ -690,6 +692,13 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size need_destroy_aicpu_kernel_ = IsAicpuKernelConnectSpecifiedLayer(); (void)ge::AttrUtils::GetListStr(ge_model_, ATTR_MODEL_OUT_NODES_NAME, out_node_name_); + string fp_ceiling_mode; + if (ge::AttrUtils::GetStr(ge_model_, ATTR_FP_CEILING_MODE, fp_ceiling_mode)) { + GELOGI("Get attr ATTR_FP_CEILING_MODE from model, value is %s.", fp_ceiling_mode.c_str()); + // mode 0: Do not perform saturation processing. By default, IEEE754 is used. + GE_CHK_RT_RET(rtSetCtxINFMode((fp_ceiling_mode != "0"))); + } + // collect profiling for ge if (ProfilingManager::Instance().ProfilingModelLoadOn()) { std::vector compute_graph_desc_info; diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 4737955d..88a001a4 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -131,6 +131,22 @@ bool IsTailingOptimization() { GELOGW("OPTION_EXEC_ENABLE_TAILING_OPTIMIZATION not set, use BFSTopologicalSorting by default."); return false; } + +ge::Status CheckFpCeilingMode() { + static const std::unordered_set kValidFpCeilingMode = {"0", "1", "2"}; + string mode; + auto ret = ge::GetContext().GetOption("ge.fpCeilingMode", mode); + if (ret == ge::GRAPH_SUCCESS) { + if (kValidFpCeilingMode.count(mode) == 0) { + GELOGE(ge::GE_GRAPH_OPTIONS_INVALID, "The fp_ceiling_mode %s is invalid, options are 0, 1, and 2.", mode.c_str()); + return ge::GE_GRAPH_OPTIONS_INVALID; + } + GELOGI("The parameter fp_ceiling_mode is set to %s.", mode.c_str()); + return ge::SUCCESS; + } + GELOGW("The parameter fp_ceiling_mode is not set."); + return ge::SUCCESS; +} } // namespace namespace ge { @@ -166,6 +182,12 @@ Status GraphManager::Initialize(const std::map &options) { return ret; } + ret = CheckFpCeilingMode(); + if (ret != SUCCESS) { + GELOGE(ret, "[Initialize] Check fp-ceiling-mode options failed."); + return ret; + } + ret = graph_context_->Initialize(options); if (ret != SUCCESS) { GELOGE(ret, "[Initialize] GraphContext initialize failed."); diff --git a/ge/init/gelib.cc b/ge/init/gelib.cc index 85a742b2..8a5cb610 100755 --- a/ge/init/gelib.cc +++ b/ge/init/gelib.cc @@ -56,6 +56,7 @@ const int kDefaultDeviceIdForInfer = -1; const uint32_t kAicoreOverflow = (0x1 << 0); const uint32_t kAtomicOverflow = (0x1 << 1); const uint32_t kAllOverflow = (kAicoreOverflow | kAtomicOverflow); +const char *const kGlobalOptionFpCeilingModeDefault = "2"; } // namespace static std::shared_ptr instancePtr_ = nullptr; @@ -79,6 +80,11 @@ Status GELib::Initialize(const map &options) { return ret; } instancePtr_->SetDefaultPrecisionMode(new_options); + + if (new_options.find("ge.fpCeilingMode") == new_options.end()) { + new_options["ge.fpCeilingMode"] = kGlobalOptionFpCeilingModeDefault; + } + GetMutableGlobalOptions().insert(new_options.begin(), new_options.end()); GetThreadLocalContext().SetGlobalOption(GetMutableGlobalOptions()); GE_TIMESTAMP_START(Init);