Browse Source

explicitly check if graph_kernel is enabled in pynative mode.

feature/build-system-rewrite
dayschan 4 years ago
parent
commit
d608ffdaf2
3 changed files with 28 additions and 17 deletions
  1. +2
    -3
      mindspore/ccsrc/runtime/graph_scheduler/graph_compiler.cc
  2. +23
    -14
      mindspore/ccsrc/utils/context/graph_kernel_flags.cc
  3. +3
    -0
      mindspore/ccsrc/utils/context/graph_kernel_flags.h

+ 2
- 3
mindspore/ccsrc/runtime/graph_scheduler/graph_compiler.cc View File

@@ -377,9 +377,8 @@ GraphId GraphCompiler::CompileGraph(const GraphSegmentPtr &segment, const AnfNod
GraphId graph_id;
if (run_in_pynative) {
MS_EXCEPTION_IF_NULL(session_);
// Graphkernel not support pynative mode now, so when users open graphkernel in pynative mode
// should print a warning log to reminder users by using GetInstance func.
(void)graphkernel::GraphKernelFlags::GetInstance();
// Graphkernel does not support pynative mode now, print a warning here.
graphkernel::GraphKernelFlags::GetInstance().CheckSupport();
session_->InitAllBucket(graph, device_context);
graph_id = graph->graph_id();
} else {


+ 23
- 14
mindspore/ccsrc/utils/context/graph_kernel_flags.cc View File

@@ -171,6 +171,28 @@ std::pair<std::string, bool> GraphKernelFlags::GetGraphKernelContext() {
return std::make_pair(flags, enable_context);
}

void GraphKernelFlags::CheckSupport() const {
#ifndef MSLITE_ENABLE_GRAPH_KERNEL
if (IsEnableGraphKernel()) {
auto context = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context);
if (context->get_param<int>(MS_CTX_EXECUTION_MODE) != kGraphMode) {
MS_LOG(WARNING) << "GraphKernel only support GRAPH_MODE.";
const_cast<GraphKernelFlags *>(this)->opt_level = OptLevel_0;
return;
}
#ifndef USE_LLVM
auto is_cpu = (context->get_param<std::string>(MS_CTX_DEVICE_TARGET) == kCPUDevice);
if (is_cpu) {
MS_LOG(WARNING) << "GraphKernel is not usable without LLVM on cpu platform.";
const_cast<GraphKernelFlags *>(this)->opt_level = OptLevel_0;
return;
}
#endif
}
#endif
}

void GraphKernelFlags::Refresh() {
auto flag_map = ParseFlags(flags_cache_);
RegisterFlags(&flag_map);
@@ -179,28 +201,15 @@ void GraphKernelFlags::Refresh() {
}
#ifndef MSLITE_ENABLE_GRAPH_KERNEL
if (IsEnableGraphKernel()) {
CheckSupport();
auto context = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context);
if (context->get_param<int>(MS_CTX_EXECUTION_MODE) != kGraphMode) {
MS_LOG(WARNING) << "GraphKernel only support GRAPH_MODE";
opt_level = OptLevel_0;
}

// check whether on ascend open graphkernel, if open, may cause error, reminder
// users to close this feature.
auto is_ascend = (context->get_param<std::string>(MS_CTX_DEVICE_TARGET) == kAscendDevice);
if (is_ascend) {
MS_LOG(WARNING)
<< "GraphKernel on Ascend is experimental, please disable it if you meet some compiling or running error. For "
"more details, please refer to 'mindspore.context' at https://www.mindspore.cn.";
}
#ifndef USE_LLVM
auto is_cpu = (context->get_param<std::string>(MS_CTX_DEVICE_TARGET) == kCPUDevice);
if (is_cpu) {
MS_LOG(WARNING) << "GraphKernel is not usable without LLVM on cpu platform";
opt_level = OptLevel_0;
}
#endif
}
#endif
// If enable graphkernel, Dump flags so that people can check the setting.


+ 3
- 0
mindspore/ccsrc/utils/context/graph_kernel_flags.h View File

@@ -52,6 +52,9 @@ class GraphKernelFlags {
// Check whether graph_kernel is enabled
bool IsEnableGraphKernel() const { return opt_level > OptLevel_0; }

// Check whether GraphKernel supports current situation.
void CheckSupport() const;

GraphKernelFlags(const GraphKernelFlags &flags) = delete;
GraphKernelFlags(GraphKernelFlags &&flags) = delete;
void operator=(const GraphKernelFlags &flags) = delete;


Loading…
Cancel
Save