From d0c9736fa51d805477d9f0b757f45e8c7c805adb Mon Sep 17 00:00:00 2001 From: lixian Date: Wed, 10 Feb 2021 11:13:38 +0800 Subject: [PATCH] remove cross dependency of context --- include/api/lite_context.h | 52 +++++++++++++---------------- mindspore/lite/include/context.h | 9 +---- mindspore/lite/include/errorcode.h | 1 - mindspore/lite/include/lite_types.h | 36 ++++++++++++++++++++ 4 files changed, 60 insertions(+), 38 deletions(-) create mode 100644 mindspore/lite/include/lite_types.h diff --git a/include/api/lite_context.h b/include/api/lite_context.h index 933c6521e0f..bb06cff782a 100644 --- a/include/api/lite_context.h +++ b/include/api/lite_context.h @@ -21,54 +21,48 @@ #include #include #include "include/api/types.h" +#include "include/lite_types.h" namespace mindspore { namespace lite { -/// \brief CpuBindMode defined for holding bind cpu strategy argument. -typedef enum : uint32_t { - NO_BIND = 0, /**< no bind */ - HIGHER_CPU = 1, /**< bind higher cpu first */ - MID_CPU = 2 /**< bind middle cpu first */ -} CpuBindMode; - class Allocator; } // namespace lite struct MS_API Context { public: - static void Clear(const std::shared_ptr &contxet); + static void Clear(const std::shared_ptr &context); - static void SetAsDefault(const std::shared_ptr &contxet); + static void SetAsDefault(const std::shared_ptr &context); - static void SetVendorName(const std::shared_ptr &contxet, const std::string &name); - static std::string GetVendorName(const std::shared_ptr &contxet); + static void SetVendorName(const std::shared_ptr &context, const std::string &name); + static std::string GetVendorName(const std::shared_ptr &context); - static void SetThreadNum(const std::shared_ptr &contxet, int num); - static int GetThreadNum(const std::shared_ptr &contxet); + static void SetThreadNum(const std::shared_ptr &context, int num); + static int GetThreadNum(const std::shared_ptr &context); - static void SetAllocator(const std::shared_ptr &contxet, std::shared_ptr alloc); - static std::shared_ptr GetAllocator(const std::shared_ptr &contxet); + static void SetAllocator(const std::shared_ptr &context, std::shared_ptr alloc); + static std::shared_ptr GetAllocator(const std::shared_ptr &context); - static void ConfigCPU(const std::shared_ptr &contxet, bool config); - static bool IfCPUEnabled(const std::shared_ptr &contxet); + static void ConfigCPU(const std::shared_ptr &context, bool config); + static bool IfCPUEnabled(const std::shared_ptr &context); - static void ConfigCPUFp16(const std::shared_ptr &contxet, bool config); - static bool IfCPUFp16Enabled(const std::shared_ptr &contxet); + static void ConfigCPUFp16(const std::shared_ptr &context, bool config); + static bool IfCPUFp16Enabled(const std::shared_ptr &context); - static void SetCPUBindMode(const std::shared_ptr &contxet, lite::CpuBindMode mode); - static lite::CpuBindMode GetCPUBindMode(const std::shared_ptr &contxet); + static void SetCPUBindMode(const std::shared_ptr &context, lite::CpuBindMode mode); + static lite::CpuBindMode GetCPUBindMode(const std::shared_ptr &context); - static void ConfigGPU(const std::shared_ptr &contxet, bool config); - static bool IfGPUEnabled(const std::shared_ptr &contxet); + static void ConfigGPU(const std::shared_ptr &context, bool config); + static bool IfGPUEnabled(const std::shared_ptr &context); - static void ConfigGPUFp16(const std::shared_ptr &contxet, bool config); - static bool IfGPUFp16Enabled(const std::shared_ptr &contxet); + static void ConfigGPUFp16(const std::shared_ptr &context, bool config); + static bool IfGPUFp16Enabled(const std::shared_ptr &context); - static void ConfigNPU(const std::shared_ptr &contxet, bool config); - static bool IfNPUEnabled(const std::shared_ptr &contxet); + static void ConfigNPU(const std::shared_ptr &context, bool config); + static bool IfNPUEnabled(const std::shared_ptr &context); - static void SetNPUFrequency(const std::shared_ptr &contxet, int freq); - static int GetNPUFrequency(const std::shared_ptr &contxet); + static void SetNPUFrequency(const std::shared_ptr &context, int freq); + static int GetNPUFrequency(const std::shared_ptr &context); private: std::map context_; diff --git a/mindspore/lite/include/context.h b/mindspore/lite/include/context.h index 7c673d04547..b3f8abe75ef 100644 --- a/mindspore/lite/include/context.h +++ b/mindspore/lite/include/context.h @@ -19,18 +19,11 @@ #include #include -#include "include/api/lite_context.h" #include "include/ms_tensor.h" #include "include/lite_utils.h" +#include "include/lite_types.h" namespace mindspore::lite { -/// \brief DeviceType defined for holding user's preferred backend. -typedef enum { - DT_CPU, /**< CPU device type */ - DT_GPU, /**< GPU device type */ - DT_NPU /**< NPU device type */ -} DeviceType; - /// \brief CpuDeviceInfo defined for CPU's configuration information. typedef struct { bool enable_float16_ = false; /**< prior enable float16 inference */ diff --git a/mindspore/lite/include/errorcode.h b/mindspore/lite/include/errorcode.h index f516e21f341..b7671259206 100644 --- a/mindspore/lite/include/errorcode.h +++ b/mindspore/lite/include/errorcode.h @@ -19,7 +19,6 @@ #include #include -#include "include/api/status.h" namespace mindspore { namespace lite { diff --git a/mindspore/lite/include/lite_types.h b/mindspore/lite/include/lite_types.h new file mode 100644 index 00000000000..d54975193cf --- /dev/null +++ b/mindspore/lite/include/lite_types.h @@ -0,0 +1,36 @@ +/** + * Copyright 2020 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 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_LITE_INCLUDE_LITE_TYPES_H_ +#define MINDSPORE_LITE_INCLUDE_LITE_TYPES_H_ + +namespace mindspore::lite { +/// \brief CpuBindMode defined for holding bind cpu strategy argument. +typedef enum { + NO_BIND, /**< no bind */ + HIGHER_CPU, /**< bind higher cpu first */ + MID_CPU /**< bind middle cpu first */ +} CpuBindMode; + +/// \brief DeviceType defined for holding user's preferred backend. +typedef enum { + DT_CPU, /**< CPU device type */ + DT_GPU, /**< GPU device type */ + DT_NPU /**< NPU device type */ +} DeviceType; + +} // namespace mindspore::lite +#endif // MINDSPORE_LITE_INCLUDE_LITE_TYPES_H_