Browse Source

!17281 add inner context flag check

From: @cjh9368
Reviewed-by: @hangangqiang
Signed-off-by: @hangangqiang
tags/v1.3.0
mindspore-ci-bot Gitee 4 years ago
parent
commit
2facf42bc6
3 changed files with 34 additions and 2 deletions
  1. +1
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/infer_register.h
  2. +29
    -0
      mindspore/lite/src/inner_context.cc
  3. +4
    -0
      mindspore/lite/src/inner_context.h

+ 1
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/infer_register.h View File

@@ -219,9 +219,8 @@ enum PrimType {
PrimType_CumSum = 192,
PrimType_SplitWithOverlap = 193,
PrimType_GenOP = 194,
PrimType_Attention = 195,
PrimType_MIN = PrimType_NONE,
PrimType_MAX = PrimType_Attention + 1
PrimType_MAX = PrimType_GenOP + 1
};

void RegInfer(int prim_type, InferShape func);


+ 29
- 0
mindspore/lite/src/inner_context.cc View File

@@ -133,10 +133,25 @@ int InnerContext::IsValid() const {
MS_LOG(ERROR) << "Not support device list more than 2.";
return RET_NOT_SUPPORT;
}
if (thread_num_ < 1) {
MS_LOG(ERROR) << "Thread num smaller than 1 is not allowed.";
return RET_NOT_SUPPORT;
}
if (!IsAllDeviceTypeValid()) {
MS_LOG(ERROR) << "Device type should be one of DT_CPU, DT_GPU or DT_NPU.";
return RET_NOT_SUPPORT;
}

if (!IsUserSetCpu()) {
MS_LOG(ERROR) << "CPU context should be set.";
return RET_NOT_SUPPORT;
}

if (IsCpuBindModeInvalid()) {
MS_LOG(ERROR) << "CPU bind mode should be one of NO_BIND, HIGHER_CPU or MID_CPU.";
return RET_NOT_SUPPORT;
}

#ifndef SUPPORT_GPU
if (IsUserSetGpu()) {
MS_LOG(ERROR) << "GPU is not supported.";
@@ -202,6 +217,20 @@ bool InnerContext::IsProviderEnabled() const {
[](const DeviceContext &device) { return !device.provider_.empty(); });
}

bool InnerContext::IsAllDeviceTypeValid() const {
return std::all_of(this->device_list_.begin(), this->device_list_.end(), [](const DeviceContext &device) {
return device.device_type_ >= DT_CPU && device.device_type_ <= DT_NPU;
});
}

bool InnerContext::IsCpuBindModeInvalid() const {
return this->device_list_.end() !=
std::find_if(this->device_list_.begin(), this->device_list_.end(), [](const DeviceContext &device) {
return device.device_type_ == DT_CPU && (device.device_info_.cpu_device_info_.cpu_bind_mode_ < NO_BIND ||
device.device_info_.cpu_device_info_.cpu_bind_mode_ > MID_CPU);
});
}

bool InnerContext::IsUserSetCpu() const {
return this->device_list_.end() !=
std::find_if(this->device_list_.begin(), this->device_list_.end(),


+ 4
- 0
mindspore/lite/src/inner_context.h View File

@@ -68,6 +68,10 @@ struct InnerContext : public Context {
virtual ~InnerContext();

private:
bool IsAllDeviceTypeValid() const;

bool IsCpuBindModeInvalid() const;

bool IsUserSetCpu() const;

bool IsUserSetGpu() const;


Loading…
Cancel
Save