modify static check

pull/8845/head
yvette 4 years ago
parent 90d614e1ab
commit 4b5050b11b

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_COMMON_COMMON_H_
#define MINDSPORE_LITE_COMMON_COMMON_H_
#ifndef MINDSPORE_LITE_SRC_COMMON_COMMON_H_
#define MINDSPORE_LITE_SRC_COMMON_COMMON_H_
#include <string>
#include "src/tensor.h"
@ -56,4 +56,4 @@ static const schema::Format DEFAULT_FORMAT = schema::Format::Format_NCHW;
} // namespace lite
} // namespace mindspore
#endif // MINDSPORE_LITE_COMMON_COMMON_H_
#endif // MINDSPORE_LITE_SRC_COMMON_COMMON_H_

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_COMMON_FILE_UTILS_H_
#define MINDSPORE_LITE_COMMON_FILE_UTILS_H_
#ifndef MINDSPORE_LITE_SRC_COMMON_FILE_UTILS_H_
#define MINDSPORE_LITE_SRC_COMMON_FILE_UTILS_H_
#include <cstdio>
#include <cstdlib>
@ -48,13 +48,14 @@ void WriteToTxt(const std::string &file_path, void *data, size_t element_size) {
out_file.close();
}
inline int WriteToBin(const std::string &file_path, void *data, size_t size) {
inline int WriteToBin(const std::string &file_path, void *data, const size_t size) {
std::ofstream out_file;
out_file.open(file_path.c_str(), std::ios::binary);
if (!out_file.good() || !out_file.is_open()) {
return -1;
}
out_file.write(reinterpret_cast<char *>(data), size);
out_file.close();
return 0;
}
@ -63,4 +64,4 @@ std::string GetAndroidPackagePath();
} // namespace lite
} // namespace mindspore
#endif // MINDSPORE_LITE_COMMON_FILE_UTILS_H_
#endif // MINDSPORE_LITE_SRC_COMMON_FILE_UTILS_H_

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_COMMON_GRAPH_UTIL_H_
#define MINDSPORE_LITE_COMMON_GRAPH_UTIL_H_
#ifndef MINDSPORE_LITE_SRC_COMMON_GRAPH_UTIL_H_
#define MINDSPORE_LITE_SRC_COMMON_GRAPH_UTIL_H_
#include <string>
#include <unordered_map>
@ -35,8 +35,8 @@ std::vector<size_t> GetGraphInputNodes(const lite::Model *model);
std::vector<size_t> GetGraphOutputNodes(const lite::Model *model);
std::vector<size_t> GetLinkedPostNodeIdx(const lite::Model *model, const size_t tensor_idx);
std::vector<size_t> GetLinkedPostNodeIdx(const lite::Model *model, size_t tensor_idx);
} // namespace lite
} // namespace mindspore
#endif // MINDSPORE_LITE_COMMON_GRAPH_UTIL_H_
#endif // MINDSPORE_LITE_SRC_COMMON_GRAPH_UTIL_H_

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_COMMON_LOG_ADAPTER_H_
#define MINDSPORE_LITE_COMMON_LOG_ADAPTER_H_
#ifndef MINDSPORE_LITE_SRC_COMMON_LOG_ADAPTER_H_
#define MINDSPORE_LITE_SRC_COMMON_LOG_ADAPTER_H_
#ifdef USE_GLOG
#include "utils/log_adapter.h"
#else
@ -113,4 +113,4 @@ class LogWriter {
#define MS_ASSERT(f) ((void)0)
#endif
#endif
#endif // MINDSPORE_LITE_COMMON_LOG_ADAPTER_H_
#endif // MINDSPORE_LITE_SRC_COMMON_LOG_ADAPTER_H_

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_COMMON_STRING_UTIL_H_
#define MINDSPORE_LITE_COMMON_STRING_UTIL_H_
#ifndef MINDSPORE_LITE_SRC_COMMON_STRING_UTIL_H_
#define MINDSPORE_LITE_SRC_COMMON_STRING_UTIL_H_
#include <vector>
#include <string>
@ -52,4 +52,4 @@ uint64_t StringHash64(const char *s, size_t len);
} // namespace lite
} // namespace mindspore
#endif // MINDSPORE_LITE_COMMON_STRING_UTIL_H_
#endif // MINDSPORE_LITE_SRC_COMMON_STRING_UTIL_H_

@ -14,10 +14,9 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_COMMON_UTILS_H_
#define MINDSPORE_LITE_COMMON_UTILS_H_
#ifndef MINDSPORE_LITE_SRC_COMMON_UTILS_H_
#define MINDSPORE_LITE_SRC_COMMON_UTILS_H_
#include <stdint.h>
#include <ctime>
#include <cstdint>
#include <vector>
@ -185,4 +184,4 @@ inline Option<bool> GenericParseValue(const std::string &value) {
} // namespace lite
} // namespace mindspore
#endif // MINDSPORE_LITE_COMMON_UTILS_H_
#endif // MINDSPORE_LITE_SRC_COMMON_UTILS_H_

@ -35,7 +35,7 @@ class Executor {
const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr);
protected:
int CheckInputs(std::vector<Tensor *> &in_tensors);
static int CheckInputs(std::vector<Tensor *> &in_tensors);
};
} // namespace mindspore::lite
#endif

@ -52,10 +52,10 @@ int InnerContext::Init() {
}
InnerContext::~InnerContext() {
if (this->thread_pool_ != NULL) {
if (this->thread_pool_ != nullptr) {
DestroyThreadPool(this->thread_pool_);
free(this->thread_pool_);
this->thread_pool_ = NULL;
this->thread_pool_ = nullptr;
}
}

@ -73,7 +73,7 @@ int KernelRegistry::GetCreatorFuncIndex(const kernel::KernelKey desc) {
return index;
}
void KernelRegistry::RegKernel(const KernelKey desc, kernel::KernelCreator creator) {
void KernelRegistry::RegKernel(const KernelKey desc, const kernel::KernelCreator creator) {
int index = GetCreatorFuncIndex(desc);
if (index >= array_size_) {
MS_LOG(ERROR) << "invalid kernel key, arch " << desc.arch << ", data_type" << desc.data_type << ",op type "
@ -97,8 +97,6 @@ void KernelRegistry::RegKernel(const KERNEL_ARCH arch, const TypeId data_type, c
bool KernelRegistry::Merge(const std::unordered_map<KernelKey, KernelCreator> &new_creators) { return false; }
const kernel::KernelCreator *KernelRegistry::GetCreatorArrays() { return creator_arrays_; }
kernel::LiteKernel *KernelRegistry::GetKernel(const std::vector<Tensor *> &in_tensors,
const std::vector<Tensor *> &out_tensors, const PrimitiveC *primitive,
const InnerContext *ctx, const kernel::KernelKey &key) {
@ -124,5 +122,5 @@ kernel::LiteKernel *KernelRegistry::GetKernel(const std::vector<Tensor *> &in_te
return nullptr;
}
KernelRegistry::~KernelRegistry() {}
KernelRegistry::~KernelRegistry() = default;
} // namespace mindspore::lite

@ -35,7 +35,7 @@ class KernelRegistry {
virtual ~KernelRegistry();
static KernelRegistry *GetInstance();
int Init();
static int Init();
virtual kernel::KernelCreator GetCreator(const kernel::KernelKey &desc);
const kernel::KernelCreator *GetCreatorArrays();
int GetCreatorFuncIndex(kernel::KernelKey desc);

@ -93,7 +93,12 @@ int LiteKernel::PreProcess() {
auto outputs = this->out_tensors();
for (auto *output : outputs) {
MS_ASSERT(output != nullptr);
output->MallocData();
auto ret = output->MallocData();
if (ret != RET_OK) {
MS_LOG(ERROR) << "MallocData failed";
return ret;
}
}
return RET_OK;
}
@ -308,5 +313,5 @@ void LiteKernelUtil::InitTensorRefCount(std::vector<kernel::LiteKernel *> &kerne
}
}
int LiteKernelUtil::SetInput(LiteKernel &kernelMod, std::vector<lite::Tensor *> inputs) { return -1; }
int LiteKernelUtil::SetInput(LiteKernel &kernelMod, const std::vector<lite::Tensor *> &inputs) { return -1; }
} // namespace mindspore::kernel

@ -217,7 +217,7 @@ class LiteKernelUtil {
static void InitTensorRefCount(std::vector<kernel::LiteKernel *> &kernels);
static int SetInput(LiteKernel &kernelMod, std::vector<lite::Tensor *> inputs);
static int SetInput(LiteKernel &kernelMod, const std::vector<lite::Tensor *> &inputs);
};
} // namespace mindspore::kernel

@ -571,7 +571,11 @@ int LiteSession::Resize(const std::vector<mindspore::tensor::MSTensor *> &inputs
} // namespace lite
session::LiteSession *session::LiteSession::CreateSession(const lite::Context *context) {
auto session = new lite::LiteSession();
auto session = new (std::nothrow) lite::LiteSession();
if (session == nullptr) {
MS_LOG(ERROR) << "create sesssion failed";
return nullptr;
}
auto ret = session->Init(context);
if (ret != mindspore::lite::RET_OK) {
MS_LOG(ERROR) << "init sesssion failed";

@ -66,7 +66,7 @@ class LiteSession : public session::LiteSession {
const std::vector<std::vector<int>> &dims) override;
protected:
void ConvertTensorsQuantParam(const schema::Tensor *src_tensor, lite::Tensor *dst_tensor);
static void ConvertTensorsQuantParam(const schema::Tensor *src_tensor, lite::Tensor *dst_tensor);
int ConvertTensorsData(const lite::Model *model, size_t tensor_index, const schema::Tensor *src_tensor,
lite::Tensor *dst_tensor);

@ -198,11 +198,9 @@ int PoolingGrad::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *>
}
}
auto grad_output = outputs_.at(0);
// todo: fmk type
auto output_shape = input->shape();
grad_output->set_shape(output_shape);
grad_output->set_data_type(input->data_type());
// todo: temp fix
grad_output->set_format(input->format());
return RET_OK;
}

File diff suppressed because it is too large Load Diff

@ -79,9 +79,9 @@ class PrimitiveC : public mindspore::Primitive {
void ClearPrimitiveT();
bool operator==(const Value &rhs) const {
bool operator==(const Value &rhs) const override {
if (rhs.isa<PrimitiveC>()) {
auto other_prim = static_cast<const PrimitiveC &>(rhs);
auto other_prim = dynamic_cast<const PrimitiveC &>(rhs);
auto a = this->primitive_->value.type;
auto b = other_prim.primitive_->value.type;
return a == b;
@ -104,11 +104,11 @@ class PrimitiveC : public mindspore::Primitive {
void ClearInputOutputQuantParam();
void AddInputQuantParam(std::vector<schema::QuantParamT> quant_param);
void AddInputQuantParam(const std::vector<schema::QuantParamT> &quant_param);
std::vector<std::vector<schema::QuantParamT>> input_quant_params() const;
void AddOutputQuantParam(std::vector<schema::QuantParamT> quant_param);
void AddOutputQuantParam(const std::vector<schema::QuantParamT> &quant_param);
std::vector<std::vector<schema::QuantParamT>> output_quant_params() const;
@ -126,7 +126,7 @@ class PrimitiveC : public mindspore::Primitive {
static PrimitiveC *Create(mindspore::schema::PrimitiveT *primitive);
void GetAttrDataFromInput(const AnfNodePtr inputNode, std::vector<int> *data);
static void GetAttrDataFromInput(const AnfNodePtr &inputNode, std::vector<int> *data);
static std::shared_ptr<PrimitiveC> Create(const Primitive &prim, const std::vector<AnfNodePtr> &inputs,
const schema::QuantType &quantType);
@ -135,7 +135,7 @@ class PrimitiveC : public mindspore::Primitive {
void PopulaterInputQuantParam(const Primitive &prim, const std::vector<AnfNodePtr> &inputs,
bool narrowRangeQuantParam, int32_t numbitsRangeQuantParam);
void PopulaterOutputQuantParam(const Primitive &prim, bool narrowRangeQuantParam, int32_t numbitsRangeQuantParam);
void CalFloatScopeByMeanAndStddev(const double &mean, const double &stdDev, float *mMin, float *mMax);
static void CalFloatScopeByMeanAndStddev(const double &mean, const double &stdDev, float *mMin, float *mMax);
protected:
virtual int UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inputs) { return RET_ERROR; }

@ -52,7 +52,6 @@ int Sub::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inputs
this->primitive_ = nullptr;
return RET_ERROR;
}
// todo: confirm the activationType
attr->activationType = schema::ActivationType_NO_ACTIVATION;
this->primitive_->value.value = attr;
}

@ -37,15 +37,15 @@ class ParamValueLite : public Value {
}
MS_DECLARE_PARENT(ParamValueLite, Value)
size_t tensor_size() const { return tensor_size_; }
void set_tensor_size(size_t size) { tensor_size_ = size; }
void set_tensor_size(const size_t size) { tensor_size_ = size; }
void *tensor_addr() const { return tensor_addr_; }
void set_tensor_addr(void *addr) { tensor_addr_ = addr; }
std::vector<int> tensor_shape() const { return tensor_shape_; }
void set_tensor_shape(std::vector<int> tensor_shape) { tensor_shape_ = std::move(tensor_shape); }
void set_tensor_shape(const std::vector<int> &tensor_shape) { tensor_shape_ = tensor_shape; }
TypeId tensor_type() const { return type_id_; }
void set_tensor_type(TypeId type_id) { type_id_ = type_id; }
void set_tensor_type(const TypeId type_id) { type_id_ = type_id; }
int tensor_shape_size() const {
int size = 1;

@ -23,7 +23,7 @@ std::shared_ptr<Allocator> Allocator::Create() {
return std::shared_ptr<Allocator>(new (std::nothrow) DefaultAllocator());
}
DefaultAllocator::DefaultAllocator() {}
DefaultAllocator::DefaultAllocator() = default;
DefaultAllocator::~DefaultAllocator() { Clear(); }
@ -94,13 +94,13 @@ size_t DefaultAllocator::GetTotalSize() {
Lock();
size_t totalSize = 0;
for (auto it = allocatedList_.begin(); it != allocatedList_.end(); it++) {
auto membuf = it->second;
for (auto &it : allocatedList_) {
auto membuf = it.second;
totalSize += membuf->size;
}
for (auto it = freeList_.begin(); it != freeList_.end(); it++) {
auto membuf = it->second;
for (auto &it : freeList_) {
auto membuf = it.second;
totalSize += membuf->size;
}
UnLock();
@ -110,13 +110,13 @@ size_t DefaultAllocator::GetTotalSize() {
void DefaultAllocator::Clear() {
Lock();
for (auto it = allocatedList_.begin(); it != allocatedList_.end(); it++) {
free(it->second);
for (auto &it : allocatedList_) {
free(it.second);
}
allocatedList_.clear();
for (auto it = freeList_.begin(); it != freeList_.end(); it++) {
free(it->second);
for (auto &it : freeList_) {
free(it.second);
}
freeList_.clear();
UnLock();

@ -34,7 +34,7 @@ struct AllocatorContext {
class Allocator {
public:
Allocator() : name("default") {}
virtual ~Allocator() {}
virtual ~Allocator() = default;
virtual void *Malloc(size_t size) = 0;
virtual void Free(void *ptr) = 0;
virtual void SetContext(const AllocatorContext &ctx) {}

@ -31,7 +31,7 @@ int ParallelExecutor::Prepare(const std::vector<mindspore::kernel::LiteKernel *>
}
static int RunKernel(void *data, int index) {
ParallelExecutor *executor = reinterpret_cast<ParallelExecutor *>(data);
auto *executor = reinterpret_cast<ParallelExecutor *>(data);
auto kernel = executor->GetReadyKernel(index);
auto ret = kernel->Run();
executor->SetResult(index, ret);
@ -65,16 +65,19 @@ int ParallelExecutor::Run(std::vector<Tensor *> &in_tensors, std::vector<Tensor
kernel::LiteKernelUtil::InitTensorRefCount(kernels);
for (auto kernel : kernels) {
if (kernel->in_kernels().size() == 0) {
if (kernel->in_kernels().empty()) {
readyKernels.emplace_back(kernel);
continue;
}
refCount[kernel] = kernel->in_kernels().size();
}
std::vector<kernel::LiteKernel *> newReadyKernels;
while (readyKernels.size() > 0) {
while (!readyKernels.empty()) {
results.resize(readyKernels.size(), RET_OK);
ParallelLaunch(thread_pool_, RunKernel, this, readyKernels.size());
if (0 != ParallelLaunch(thread_pool_, RunKernel, this, readyKernels.size())) {
MS_LOG(ERROR) << "ParallelLaunch failed ";
return RET_ERROR;
}
if (std::find_if(results.begin(), results.end(), [](const int &ret) { return (ret != 0); }) != results.end()) {
return RET_ERROR;

@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_PARALLEL_EXECUTOR_H_
#define MINDSPORE_LITE_PARALLEL_EXECUTOR_H_
#ifndef MINDSPORE_LITE_SRC_RUNTIME_PARALLEL_EXECUTOR_H_
#define MINDSPORE_LITE_SRC_RUNTIME_PARALLEL_EXECUTOR_H_
#include <vector>
#include <unordered_map>
@ -28,7 +28,7 @@ namespace mindspore::lite {
class ParallelExecutor : public Executor {
public:
ParallelExecutor() = default;
virtual ~ParallelExecutor();
~ParallelExecutor() override;
int Prepare(const std::vector<kernel::LiteKernel *> &kernels) override;
@ -42,8 +42,8 @@ class ParallelExecutor : public Executor {
std::unordered_map<kernel::LiteKernel *, size_t> refCount;
std::vector<kernel::LiteKernel *> readyKernels;
std::vector<int> results;
struct ThreadPool *thread_pool_ = NULL;
struct ThreadPool *thread_pool_ = nullptr;
};
} // namespace mindspore::lite
#endif
#endif // MINDSPORE_LITE_SRC_RUNTIME_PARALLEL_EXECUTOR_H_

@ -16,7 +16,6 @@
#include "src/runtime/runtime_api.h"
#include <mutex>
#include <string>
#include "src/common/log_adapter.h"
static std::mutex gWorkspaceMutex;

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PREDICT_SRC_RUNTIME_RUNTIME_API_H_
#define PREDICT_SRC_RUNTIME_RUNTIME_API_H_
#ifndef MINDSPORE_LITE_SRC_RUNTIME_RUNTIME_API_H_
#define MINDSPORE_LITE_SRC_RUNTIME_RUNTIME_API_H_
#include <memory>
#ifndef INTERNAL_API_DLL
@ -40,4 +40,4 @@ INTERNAL_API_DLL int LiteBackendRegisterSystemLibSymbol(const char *name, void *
#ifdef __cplusplus
}
#endif
#endif // PREDICT_SRC_RUNTIME_RUNTIME_API_H_
#endif // MINDSPORE_LITE_SRC_RUNTIME_RUNTIME_API_H_

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save