From c54ae2b7789a310fca6ea989ac47896366f9a964 Mon Sep 17 00:00:00 2001 From: yangjie159 Date: Sat, 15 May 2021 10:42:23 +0800 Subject: [PATCH] move self-defined String implementation to lite_utils.h --- mindspore/lite/include/lite_utils.h | 317 ++++++++++++++--- mindspore/lite/micro/cmake/file_list.cmake | 3 +- .../generator/component/cmake_component.cc | 3 +- .../const_blocks/{model.cc => mmodel.cc} | 2 +- .../const_blocks/{model.h => mmodel.h} | 0 .../component/const_blocks/mstring.cc | 330 ------------------ .../component/const_blocks/mstring.h | 26 -- .../lite/micro/coder/generator/generator.cc | 8 +- 8 files changed, 284 insertions(+), 405 deletions(-) rename mindspore/lite/micro/coder/generator/component/const_blocks/{model.cc => mmodel.cc} (97%) rename mindspore/lite/micro/coder/generator/component/const_blocks/{model.h => mmodel.h} (100%) delete mode 100644 mindspore/lite/micro/coder/generator/component/const_blocks/mstring.cc delete mode 100644 mindspore/lite/micro/coder/generator/component/const_blocks/mstring.h diff --git a/mindspore/lite/include/lite_utils.h b/mindspore/lite/include/lite_utils.h index 295d3081528..cf7a4d073fe 100644 --- a/mindspore/lite/include/lite_utils.h +++ b/mindspore/lite/include/lite_utils.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #endif // NOT_USE_STL @@ -52,46 +54,266 @@ struct DeviceContext; } // namespace lite #ifdef NOT_USE_STL +#define MS_C_EXCEPTION(...) exit(1) + class String { public: - String(); - String(size_t count, char ch); - String(const char *s, size_t count); - explicit String(const char *s); - String(const String &other); - String(const String &other, size_t pos, size_t count = npos); + String() { + buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + buffer_[0] = '\0'; + size_ = 0; + } - ~String(); + String(size_t count, char ch) { + buffer_ = reinterpret_cast(malloc(sizeof(char) * (count + 1))); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + memset(buffer_, ch, count); + buffer_[count] = '\0'; + size_ = count; + } - String &operator=(const String &str); - String &operator=(const char *str); + String(const char *s, size_t count) { + if (s == nullptr) { + buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + buffer_[0] = '\0'; + size_ = 0; + return; + } + size_t size_s = strlen(s); + if (size_s <= count) { + size_ = size_s; + } else { + size_ = count; + } + buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_ + 1))); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + strncpy(buffer_, s, size_); + buffer_[size_] = '\0'; + } - char &at(size_t pos); - const char &at(size_t pos) const; - inline char &operator[](size_t pos); - inline const char &operator[](size_t pos) const; - char *data() noexcept; - const char *data() const noexcept; - const char *c_str() const noexcept; + explicit String(const char *s) { + if (s == nullptr) { + buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + buffer_[0] = '\0'; + size_ = 0; + return; + } + size_ = strlen(s); + buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_ + 1))); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + memcpy(buffer_, s, size_ + 1); + } + + String(const String &other) { + buffer_ = reinterpret_cast(malloc(sizeof(char) * (other.size_ + 1))); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + size_ = other.size_; + memcpy(buffer_, other.buffer_, size_ + 1); + } + + String(const String &other, size_t pos, size_t count = npos) { + if (pos >= other.size_) { + buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + buffer_[0] = '\0'; + size_ = 0; + } else { + if (count == npos) { + count = other.size_ - pos; + } + if (pos + count > other.size_) { + size_ = other.size_ - pos; + } else { + size_ = count; + } + buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_ + 1))); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + strncpy(buffer_, other.buffer_ + pos, size_); + buffer_[size_] = '\0'; + } + } + + ~String() { free(buffer_); } + + String &operator=(const String &str) { + if (this == &str) { + return *this; + } + free(buffer_); + buffer_ = reinterpret_cast(malloc(sizeof(char) * (str.size_ + 1))); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + size_ = str.size_; + memcpy(buffer_, str.buffer_, size_ + 1); + return *this; + } + + String &operator=(const char *str) { + free(buffer_); + if (str == nullptr) { + buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + buffer_[0] = '\0'; + size_ = 0; + return *this; + } + size_t size_s = strlen(str); + buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_s + 1))); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + size_ = size_s; + memcpy(buffer_, str, size_ + 1); + return *this; + } + + char &at(size_t pos) { + if (pos >= size_) { + MS_C_EXCEPTION("pos out of range"); + } + return buffer_[pos]; + } + + const char &at(size_t pos) const { + if (pos >= size_) { + MS_C_EXCEPTION("pos out of range"); + } + return buffer_[pos]; + } + + inline char &operator[](size_t pos) { + if (pos >= size_) { + MS_C_EXCEPTION("pos out of range"); + } + return this->at(pos); + } + + inline const char &operator[](size_t pos) const { + if (pos >= size_) { + MS_C_EXCEPTION("pos out of range"); + } + return this->at(pos); + } + + char *data() noexcept { return buffer_; } + const char *data() const noexcept { return buffer_; } + const char *c_str() const noexcept { return buffer_; } // capacity - bool empty() const noexcept; - size_t size() const noexcept; - size_t length() const noexcept; + bool empty() const noexcept { return size_ == 0; } + size_t size() const noexcept { return size_; } + size_t length() const noexcept { return size_; } // operations - void clear() noexcept; - String &append(size_t count, const char ch); - String &append(const String &str); - String &append(const char *s); - String &operator+(const String &str); - String &operator+=(const String &str); - String &operator+=(const char *str); - String &operator+=(const char ch); - int compare(const String &str) const; - int compare(const char *str) const; + void clear() noexcept { + free(buffer_); + buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); + if (buffer_ == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + buffer_[0] = '\0'; + size_ = 0; + } - String substr(size_t pos = 0, size_t count = npos) const; + String &append(size_t count, const char ch) { + (*this) += ch; + return *this; + } + + String &append(const String &str) { + (*this) += str; + return *this; + } + + String &append(const char *str) { + if (str == nullptr) { + return *this; + } + (*this) += str; + return *this; + } + + String &operator+(const String &str) { + (*this) += str; + return *this; + } + + String &operator+=(const String &str) { + size_t new_size = size_ + str.size_; + char *tmp = reinterpret_cast(malloc(sizeof(char) * (new_size + 1))); + if (tmp == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + memcpy(tmp, this->buffer_, size_ + 1); + strncat(tmp, str.buffer_, str.size_); + tmp[new_size] = '\0'; + free(buffer_); + buffer_ = tmp; + size_ = new_size; + return *this; + } + + String &operator+=(const char *str) { + if (str == nullptr) { + return *this; + } + size_t str_size = strlen(str); + size_t new_size = size_ + str_size; + char *tmp = reinterpret_cast(malloc(sizeof(char) * (new_size + 1))); + if (tmp == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + memcpy(tmp, this->buffer_, size_ + 1); + strncat(tmp, str, str_size); + tmp[new_size] = '\0'; + free(buffer_); + buffer_ = tmp; + size_ = new_size; + return *this; + } + + String &operator+=(const char ch) { + char *tmp = reinterpret_cast(malloc(sizeof(char) * (size_ + 2))); + if (tmp == nullptr) { + MS_C_EXCEPTION("malloc data failed"); + } + memcpy(tmp, this->buffer_, size_ + 1); + tmp[size_] = ch; + tmp[size_ + 1] = '\0'; + free(buffer_); + buffer_ = tmp; + size_ += 1; + return *this; + } + + int compare(const String &str) const { return strcmp(buffer_, str.buffer_); } + int compare(const char *str) const { return strcmp(buffer_, str); } + + String substr(size_t pos = 0, size_t count = npos) const { return String(*this, pos, count); } static const size_t npos = -1; @@ -100,19 +322,36 @@ class String { char *buffer_; }; -String operator+(const String &lhs, const char *rhs); -String operator+(const char *lhs, const String &rhs); +inline String operator+(const String &lhs, const char *rhs) { + String str = lhs; + str += rhs; + return str; +} -bool operator!=(const String &lhs, const String &rhs); -bool operator==(const String &lhs, const String &rhs); -bool operator==(const String &lhs, const char *rhs); -bool operator==(const char *lhs, const String &rhs); +inline String operator+(const char *lhs, const String &rhs) { + String str = rhs; + str += lhs; + return str; +} -String to_string(int32_t value); -String to_string(float value); +inline bool operator!=(const String &lhs, const String &rhs) { return lhs.compare(rhs) != 0; } +inline bool operator==(const String &lhs, const String &rhs) { return lhs.compare(rhs) == 0; } +inline bool operator==(const String &lhs, const char *rhs) { return lhs.compare(rhs) == 0; } +inline bool operator==(const char *lhs, const String &rhs) { return rhs.compare(lhs) == 0; } + +inline String to_String(int32_t value) { + char tmp[sizeof(int32_t) * 4]; + snprintf(tmp, sizeof(int32_t) * 4, "%d", value); + return String(tmp, strlen(tmp)); +} + +inline String to_String(float value) { + char tmp[FLT_MAX_10_EXP + 20]; + snprintf(tmp, FLT_MAX_10_EXP + 20, "%f", value); + return String(tmp, strlen(tmp)); +} #define DEFAULT_CAPACITY 4 -#define MS_C_EXCEPTION(...) exit(1) #define MIN(x, y) ((x < y) ? (x) : (y)) template class Vector { diff --git a/mindspore/lite/micro/cmake/file_list.cmake b/mindspore/lite/micro/cmake/file_list.cmake index b0a3bccd4cc..cd2447372c5 100644 --- a/mindspore/lite/micro/cmake/file_list.cmake +++ b/mindspore/lite/micro/cmake/file_list.cmake @@ -28,8 +28,7 @@ set(CODER_GENERATOR_SRC ${MICRO_DIR}/coder/generator/component/const_blocks/debug_utils.cc ${MICRO_DIR}/coder/generator/component/const_blocks/msession.cc ${MICRO_DIR}/coder/generator/component/const_blocks/mtensor.cc - ${MICRO_DIR}/coder/generator/component/const_blocks/mstring.cc - ${MICRO_DIR}/coder/generator/component/const_blocks/model.cc + ${MICRO_DIR}/coder/generator/component/const_blocks/mmodel.cc ${MICRO_DIR}/coder/generator/component/const_blocks/license.cc ${MICRO_DIR}/coder/generator/component/const_blocks/load_input.cc ${MICRO_DIR}/coder/generator/component/const_blocks/calib_output.cc diff --git a/mindspore/lite/micro/coder/generator/component/cmake_component.cc b/mindspore/lite/micro/coder/generator/component/cmake_component.cc index 45aeb163b27..450ba394a4d 100644 --- a/mindspore/lite/micro/coder/generator/component/cmake_component.cc +++ b/mindspore/lite/micro/coder/generator/component/cmake_component.cc @@ -34,8 +34,7 @@ void CodeCMakeNetLibrary(std::ofstream &ofs, const std::unique_ptr ofs << " weight.c.o\n" << " net.c.o\n" << " session.cc.o\n" - << " tensor.cc.o\n" - << " string.cc.o\n"; + << " tensor.cc.o\n"; if (config->debug_mode()) { ofs << " debug_utils.c.o\n"; } diff --git a/mindspore/lite/micro/coder/generator/component/const_blocks/model.cc b/mindspore/lite/micro/coder/generator/component/const_blocks/mmodel.cc similarity index 97% rename from mindspore/lite/micro/coder/generator/component/const_blocks/model.cc rename to mindspore/lite/micro/coder/generator/component/const_blocks/mmodel.cc index 96e92c2defa..5f1341decba 100644 --- a/mindspore/lite/micro/coder/generator/component/const_blocks/model.cc +++ b/mindspore/lite/micro/coder/generator/component/const_blocks/mmodel.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "coder/generator/component/const_blocks/model.h" +#include "coder/generator/component/const_blocks/mmodel.h" namespace mindspore::lite::micro { diff --git a/mindspore/lite/micro/coder/generator/component/const_blocks/model.h b/mindspore/lite/micro/coder/generator/component/const_blocks/mmodel.h similarity index 100% rename from mindspore/lite/micro/coder/generator/component/const_blocks/model.h rename to mindspore/lite/micro/coder/generator/component/const_blocks/mmodel.h diff --git a/mindspore/lite/micro/coder/generator/component/const_blocks/mstring.cc b/mindspore/lite/micro/coder/generator/component/const_blocks/mstring.cc deleted file mode 100644 index 87fd824a0c2..00000000000 --- a/mindspore/lite/micro/coder/generator/component/const_blocks/mstring.cc +++ /dev/null @@ -1,330 +0,0 @@ -/** - * Copyright 2021 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 to 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. - */ - -#include "coder/generator/component/const_blocks/mstring.h" - -namespace mindspore::lite::micro { - -const char *string_source = R"RAW( - -/** - * Copyright 2021 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 to 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. - */ - -#ifdef NOT_USE_STL -#include -#include -#include -#include -#include -#include "include/lite_utils.h" - -namespace mindspore { -String::String() { - buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - buffer_[0] = '\0'; - size_ = 0; -} - -String::String(size_t count, char ch) { - buffer_ = reinterpret_cast(malloc(sizeof(char) * (count + 1))); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - memset(buffer_, ch, count); - buffer_[count] = '\0'; - size_ = count; -} -String::String(const char *s, size_t count) { - if (s == nullptr) { - buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - buffer_[0] = '\0'; - size_ = 0; - return; - } - size_t size_s = strlen(s); - if (size_s <= count) { - size_ = size_s; - } else { - size_ = count; - } - buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_ + 1))); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - strncpy(buffer_, s, size_); - buffer_[size_] = '\0'; -} - -String::String(const char *s) { - if (s == nullptr) { - buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - buffer_[0] = '\0'; - size_ = 0; - return; - } - size_ = strlen(s); - buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_ + 1))); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - memcpy(buffer_, s, size_ + 1); -} - -String::String(const String &other) { - buffer_ = reinterpret_cast(malloc(sizeof(char) * (other.size_ + 1))); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - size_ = other.size_; - memcpy(buffer_, other.buffer_, size_ + 1); -} - -String::String(const String &other, size_t pos, size_t count) { - if (pos >= other.size_) { - buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - buffer_[0] = '\0'; - size_ = 0; - } else { - if (count == npos) { - count = other.size_ - pos; - } - if (pos + count > other.size_) { - size_ = other.size_ - pos; - } else { - size_ = count; - } - buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_ + 1))); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - strncpy(buffer_, other.buffer_ + pos, size_); - buffer_[size_] = '\0'; - } -} - -String::~String() { free(buffer_); } - -String &String::operator=(const String &str) { - if (this == &str) { - return *this; - } - free(buffer_); - buffer_ = reinterpret_cast(malloc(sizeof(char) * (str.size_ + 1))); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - size_ = str.size_; - memcpy(buffer_, str.buffer_, size_ + 1); - return *this; -} - -String &String::operator=(const char *str) { - free(buffer_); - if (str == nullptr) { - buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - buffer_[0] = '\0'; - size_ = 0; - return *this; - } - size_t size_s = strlen(str); - buffer_ = reinterpret_cast(malloc(sizeof(char) * (size_s + 1))); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - size_ = size_s; - memcpy(buffer_, str, size_ + 1); - return *this; -} - -char &String::at(size_t pos) { - if (pos >= size_) { - MS_C_EXCEPTION("pos out of range"); - } - return buffer_[pos]; -} -const char &String::at(size_t pos) const { - if (pos >= size_) { - MS_C_EXCEPTION("pos out of range"); - } - return buffer_[pos]; -} -char &String::operator[](size_t pos) { - if (pos >= size_) { - MS_C_EXCEPTION("pos out of range"); - } - return this->at(pos); -} -const char &String::operator[](size_t pos) const { - if (pos >= size_) { - MS_C_EXCEPTION("pos out of range"); - } - return this->at(pos); -} -char *String::data() noexcept { return buffer_; }; -const char *String::data() const noexcept { return buffer_; } -const char *String::c_str() const noexcept { return buffer_; } - -// capacity -bool String::empty() const noexcept { return size_ == 0; } -size_t String::size() const noexcept { return size_; } -size_t String::length() const noexcept { return size_; } - -// operations -void String::clear() noexcept { - free(buffer_); - buffer_ = reinterpret_cast(malloc(sizeof(char) * 1)); - if (buffer_ == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - buffer_[0] = '\0'; - size_ = 0; -} - -String &String::operator+(const String &str) { - (*this) += str; - return *this; -} - -String &String::operator+=(const String &str) { - size_t new_size = size_ + str.size_; - char *tmp = reinterpret_cast(malloc(sizeof(char) * (new_size + 1))); - if (tmp == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - memcpy(tmp, this->buffer_, size_ + 1); - strncat(tmp, str.buffer_, str.size_); - tmp[new_size] = '\0'; - free(buffer_); - buffer_ = tmp; - size_ = new_size; - return *this; -} - -String &String::operator+=(const char *str) { - if (str == nullptr) { - return *this; - } - size_t str_size = strlen(str); - size_t new_size = size_ + str_size; - char *tmp = reinterpret_cast(malloc(sizeof(char) * (new_size + 1))); - if (tmp == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - memcpy(tmp, this->buffer_, size_ + 1); - strncat(tmp, str, str_size); - tmp[new_size] = '\0'; - free(buffer_); - buffer_ = tmp; - size_ = new_size; - return *this; -} - -String &String::operator+=(const char ch) { - char *tmp = reinterpret_cast(malloc(sizeof(char) * (size_ + 2))); - if (tmp == nullptr) { - MS_C_EXCEPTION("malloc data failed"); - } - memcpy(tmp, this->buffer_, size_ + 1); - tmp[size_] = ch; - tmp[size_ + 1] = '\0'; - free(buffer_); - buffer_ = tmp; - size_ += 1; - return *this; -} - -String &String::append(size_t count, const char ch) { - (*this) += ch; - return *this; -} -String &String::append(const String &str) { - (*this) += str; - return *this; -} -String &String::append(const char *str) { - if (str == nullptr) { - return *this; - } - (*this) += str; - return *this; -} - -int String::compare(const String &str) const { return strcmp(buffer_, str.buffer_); } -int String::compare(const char *str) const { return strcmp(buffer_, str); } - -String String::substr(size_t pos, size_t count) const { return String(*this, pos, count); } - -String operator+(const String &lhs, const char *rhs) { - String str = lhs; - str += rhs; - return str; -} - -String operator+(const char *lhs, const String &rhs) { - String str = rhs; - str += lhs; - return str; -} - -bool operator!=(const String &lhs, const String &rhs) { return lhs.compare(rhs) != 0; } -bool operator==(const String &lhs, const String &rhs) { return lhs.compare(rhs) == 0; } -bool operator==(const String &lhs, const char *rhs) { return lhs.compare(rhs) == 0; } -bool operator==(const char *lhs, const String &rhs) { return rhs.compare(lhs) == 0; } - -String to_String(int32_t value) { - char tmp[sizeof(int32_t) * 4]; - snprintf(tmp, sizeof(int32_t) * 4, "%d", value); - return String(tmp, strlen(tmp)); -} - -String to_String(float value) { - char tmp[FLT_MAX_10_EXP + 20]; - snprintf(tmp, FLT_MAX_10_EXP + 20, "%f", value); - return String(tmp, strlen(tmp)); -} -} // namespace mindspore -#endif // NOT_USE_STL -)RAW"; - -} // namespace mindspore::lite::micro diff --git a/mindspore/lite/micro/coder/generator/component/const_blocks/mstring.h b/mindspore/lite/micro/coder/generator/component/const_blocks/mstring.h deleted file mode 100644 index bf7f0d9ba1f..00000000000 --- a/mindspore/lite/micro/coder/generator/component/const_blocks/mstring.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright 2021 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 to 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_MICRO_GENERATOR_CONST_BLOCK_MSTRING_H_ -#define MINDSPORE_LITE_MICRO_GENERATOR_CONST_BLOCK_MSTRING_H_ - -namespace mindspore::lite::micro { - -extern const char *string_source; - -} // namespace mindspore::lite::micro - -#endif // MINDSPORE_LITE_MICRO_GENERATOR_CONST_BLOCK_MSTRING_H_ diff --git a/mindspore/lite/micro/coder/generator/generator.cc b/mindspore/lite/micro/coder/generator/generator.cc index ed7ae28ec37..3be58abd001 100644 --- a/mindspore/lite/micro/coder/generator/generator.cc +++ b/mindspore/lite/micro/coder/generator/generator.cc @@ -27,8 +27,7 @@ #include "coder/generator/component/const_blocks/calib_output.h" #include "coder/generator/component/const_blocks/msession.h" #include "coder/generator/component/const_blocks/mtensor.h" -#include "coder/generator/component/const_blocks/mstring.h" -#include "coder/generator/component/const_blocks/model.h" +#include "coder/generator/component/const_blocks/mmodel.h" #include "coder/generator/component/const_blocks/thread_pool.h" #include "coder/generator/component/const_blocks/benchmark.h" #include "coder/generator/component/const_blocks/license.h" @@ -96,8 +95,7 @@ int Generator::CodeStaticContent() { {net_src_file_path_ + "session.h", session_header}, {net_src_file_path_ + "tensor.h", tensor_header}, {net_src_file_path_ + "tensor.cc", tensor_source}, - {net_src_file_path_ + "string.cc", string_source}, - {net_src_file_path_ + "model.h", model_header}}; + {net_src_file_path_ + "mmodel.h", model_header}}; if (config_->support_parallel()) { const_blocks.emplace_back(std::make_pair(net_src_file_path_ + "thread_pool.h", thread_header)); } @@ -120,7 +118,7 @@ int Generator::CodeSessionImplement() { MS_LOG(INFO) << "write " << cfile; ofs << g_hwLicense; ofs << "#include \"session.h\"\n"; - ofs << "#include \"model.h\"\n"; + ofs << "#include \"mmodel.h\"\n"; ofs << "#include \"net.h\"\n"; ofs << "#include \n\n"; CodeSessionCompileGraph(ofs, ctx_, config_);