已合并
Update AI4C from v0.1.0 to v0.2.0 #18
andyzzy991021创建于 2024年8月14日
Update AI4C from v0.1.0 to v0.2.0 #18
已合并
从refs/pull/18/head合入到master
共 6 个文件变更+8-93855
此文件变更行数或变更字符数较多,你可以直接
此文件变更行数或变更字符数较多,你可以直接
| @@ -1,266 +0,0 @@ | |||
| 1 | -From 80327cffeff2641a68748ca5487c8b1d3e4ba448 Mon Sep 17 00:00:00 2001 | ||
| 2 | -From: liufeiyang <liufeiyang6@huawei.com> | ||
| 3 | -Date: Mon, 5 Aug 2024 21:34:51 +0800 | ||
| 4 | -Subject: [PATCH] Remove path dependencies for building AI4Compiler framework. | ||
| 5 | - | ||
| 6 | ---- | ||
| 7 | - aiframe/CMakeLists.txt | 104 +++++++++++++++--- | ||
| 8 | - aiframe/ONNXRunner.cpp | 1 - | ||
| 9 | - aiframe/include/ONNXRunner.h | 46 +++++++- | ||
| 10 | - .../cmake/external/eigen.cmake | 12 +- | ||
| 11 | - .../external/onnxruntime_external_deps.cmake | 3 +- | ||
| 12 | - 5 files changed, 138 insertions(+), 28 deletions(-) | ||
| 13 | - | ||
| 14 | -diff --git a/aiframe/CMakeLists.txt b/aiframe/CMakeLists.txt | ||
| 15 | -index 9f8022f5..3b851d34 100644 | ||
| 16 | ---- a/aiframe/CMakeLists.txt | ||
| 17 | -+++ b/aiframe/CMakeLists.txt | ||
| 18 | -@@ -4,18 +4,92 @@ project(ONNXRunner) | ||
| 19 | - | ||
| 20 | - set(CMAKE_CXX_STANDARD 17) | ||
| 21 | - | ||
| 22 | --set(INC_DIR /usr/include) | ||
| 23 | --set(INC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
| 24 | --set(LIB_DIR /usr/lib64) | ||
| 25 | -- | ||
| 26 | --include_directories( | ||
| 27 | -- ${INC_HEADER} | ||
| 28 | -- ${INC_DIR}) | ||
| 29 | -- | ||
| 30 | --link_directories(${LIB_DIR}) | ||
| 31 | -- | ||
| 32 | --add_library(ONNXRunner SHARED ONNXRunner.cpp) | ||
| 33 | -- | ||
| 34 | --target_link_libraries(ONNXRunner | ||
| 35 | --PRIVATE | ||
| 36 | --libcrypto.so) # libonnxruntime.so | ||
| 37 | -+#------------------------------------------------------------------------------- | ||
| 38 | -+# Dependency settings | ||
| 39 | -+#------------------------------------------------------------------------------- | ||
| 40 | -+# Set include file directory for AI4Compiler framework. | ||
| 41 | -+set(FRAMEWORK_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include") | ||
| 42 | -+ | ||
| 43 | -+# Set root directory for ONNXRuntime library. | ||
| 44 | -+set(DEFAULT_onnxruntime_ROOTDIR "/usr" CACHE FILEPATH | ||
| 45 | -+ "Default root directory for ONNXRuntime") | ||
| 46 | -+ | ||
| 47 | -+if(NOT DEFINED onnxruntime_ROOTDIR) | ||
| 48 | -+ message(WARNING | ||
| 49 | -+ "Set default root path to libonnxruntime as " | ||
| 50 | -+ "${DEFAULT_onnxruntime_ROOTDIR}. " | ||
| 51 | -+ "Use -Donnxruntime_ROOTDIR to change ONNXRuntime root path.") | ||
| 52 | -+ set(onnxruntime_ROOTDIR ${DEFAULT_onnxruntime_ROOTDIR}) | ||
| 53 | -+endif() | ||
| 54 | -+ | ||
| 55 | -+# Set directory for dependency libraries. | ||
| 56 | -+set(DEFAULT_LIB_DEP_DIR "/usr/lib64" CACHE FILEPATH | ||
| 57 | -+ "Default directory for dependency libraries") | ||
| 58 | -+ | ||
| 59 | -+# Search for dependency library libcrypto.so. | ||
| 60 | -+if(NOT DEFINED crypto_LIBDIR) | ||
| 61 | -+ message("Set default path to search libcrypto as ${DEFAULT_LIB_DEP_DIR}. " | ||
| 62 | -+ "Use -Dcrypto_LIBDIR to change lib path.") | ||
| 63 | -+ set(crypto_LIBDIR ${DEFAULT_LIB_DEP_DIR}) | ||
| 64 | -+endif() | ||
| 65 | -+ | ||
| 66 | -+find_library(LIBCRYPTO | ||
| 67 | -+ NAMES crypto libcrypto | ||
| 68 | -+ PATHS "${crypto_LIBDIR}") | ||
| 69 | -+if(NOT LIBCRYPTO) | ||
| 70 | -+ message(FATAL_ERROR "libcrypto library is not found! ") | ||
| 71 | -+endif() | ||
| 72 | -+ | ||
| 73 | -+add_library(libcrypto SHARED IMPORTED) | ||
| 74 | -+set_target_properties(libcrypto PROPERTIES | ||
| 75 | -+ IMPORTED_LOCATION "${LIBCRYPTO}") | ||
| 76 | -+ | ||
| 77 | -+#------------------------------------------------------------------------------- | ||
| 78 | -+# Framework Compilation and Installation | ||
| 79 | -+#------------------------------------------------------------------------------- | ||
| 80 | -+# Create a dynamic library for AI4Compiler framework. | ||
| 81 | -+set(ai4compiler ${PROJECT_NAME}) | ||
| 82 | -+add_library(${ai4compiler} SHARED ONNXRunner.cpp) | ||
| 83 | -+ | ||
| 84 | -+target_include_directories(${ai4compiler} | ||
| 85 | -+ PRIVATE | ||
| 86 | -+ ${FRAMEWORK_INCLUDE} | ||
| 87 | -+ "${onnxruntime_ROOTDIR}/include" | ||
| 88 | -+ "${onnxruntime_ROOTDIR}/include/onnxruntime") | ||
| 89 | -+ | ||
| 90 | -+target_link_libraries(${ai4compiler} | ||
| 91 | -+ PRIVATE | ||
| 92 | -+ libcrypto) | ||
| 93 | -+ | ||
| 94 | -+# Install the targets and include files to expected locations. | ||
| 95 | -+if(NOT DEFINED CMAKE_INSTALL_LIBDIR) | ||
| 96 | -+ if(CMAKE_SIZEOF_VOID_P EQUAL 4) | ||
| 97 | -+ set(CMAKE_INSTALL_LIBDIR "./lib") | ||
| 98 | -+ elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
| 99 | -+ set(CMAKE_INSTALL_LIBDIR "./lib64") | ||
| 100 | -+ else() | ||
| 101 | -+ message(WARNING "Unknown system architecture. Defaulting to './lib'.") | ||
| 102 | -+ set(CMAKE_INSTALL_LIBDIR "./lib") | ||
| 103 | -+ endif() | ||
| 104 | -+ message(STATUS "Setting CMAKE_INSTALL_LIBDIR to '${CMAKE_INSTALL_LIBDIR}'.") | ||
| 105 | -+endif() | ||
| 106 | -+ | ||
| 107 | -+if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR) | ||
| 108 | -+ set(CMAKE_INSTALL_INCLUDEDIR "./include") | ||
| 109 | -+ message(STATUS | ||
| 110 | -+ "Setting CMAKE_INSTALL_INCLUDEDIR to " | ||
| 111 | -+ "'${CMAKE_INSTALL_INCLUDEDIR}'.") | ||
| 112 | -+endif() | ||
| 113 | -+ | ||
| 114 | -+install(TARGETS ${ai4compiler} | ||
| 115 | -+ DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
| 116 | -+ | ||
| 117 | -+install(DIRECTORY "${FRAMEWORK_INCLUDE}/" | ||
| 118 | -+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||
| 119 | -+ FILES_MATCHING | ||
| 120 | -+ PATTERN "*.h") | ||
| 121 | -+ | ||
| 122 | -+install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../models/" | ||
| 123 | -+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/AI4C" | ||
| 124 | -+ FILES_MATCHING | ||
| 125 | -+ PATTERN "*.onnx") | ||
| 126 | -diff --git a/aiframe/ONNXRunner.cpp b/aiframe/ONNXRunner.cpp | ||
| 127 | -index e369a916..2dcdbde8 100644 | ||
| 128 | ---- a/aiframe/ONNXRunner.cpp | ||
| 129 | -+++ b/aiframe/ONNXRunner.cpp | ||
| 130 | -@@ -1,6 +1,5 @@ | ||
| 131 | - #include "include/ONNXRunner.h" | ||
| 132 | - #include <algorithm> | ||
| 133 | --#include <iostream> | ||
| 134 | - #include <numeric> | ||
| 135 | - #include <vector> | ||
| 136 | - | ||
| 137 | -diff --git a/aiframe/include/ONNXRunner.h b/aiframe/include/ONNXRunner.h | ||
| 138 | -index bc8535f1..dd35de51 100644 | ||
| 139 | ---- a/aiframe/include/ONNXRunner.h | ||
| 140 | -+++ b/aiframe/include/ONNXRunner.h | ||
| 141 | -@@ -4,9 +4,9 @@ | ||
| 142 | - #include "onnxruntime_c_api.h" | ||
| 143 | - #include "onnxruntime_cxx_api.h" | ||
| 144 | - #include <algorithm> | ||
| 145 | --#include <fstream> | ||
| 146 | -+#include <cstdlib> | ||
| 147 | -+#include <filesystem> | ||
| 148 | - #include <iomanip> | ||
| 149 | --#include <iostream> | ||
| 150 | - #include <numeric> | ||
| 151 | - #include <openssl/sha.h> | ||
| 152 | - #include <sstream> | ||
| 153 | -@@ -16,7 +16,6 @@ | ||
| 154 | - extern "C" { | ||
| 155 | - namespace compilerONNXRunner { | ||
| 156 | - | ||
| 157 | --const char* MODEL_PATH_OPT = "/usr/lib64/AI4C/optimizer.onnx"; | ||
| 158 | - const int FEATURE_SIZE_INT64_OPT = 6; | ||
| 159 | - const int FEATURE_SIZE_STRING_OPT = 11; | ||
| 160 | - | ||
| 161 | -@@ -57,8 +56,8 @@ private: | ||
| 162 | - }; | ||
| 163 | - | ||
| 164 | - extern ONNXRunner *createONNXRunner(const char *modelPath) { | ||
| 165 | -- std::ifstream file(modelPath); | ||
| 166 | -- if (file.good()) { | ||
| 167 | -+ std::filesystem::path filePath(modelPath); | ||
| 168 | -+ if (std::filesystem::exists(filePath)) { | ||
| 169 | - return new ONNXRunner(modelPath); | ||
| 170 | - } else { | ||
| 171 | - return nullptr; | ||
| 172 | -@@ -188,11 +187,46 @@ static void preprocessData(std::vector<std::string> &inputString, | ||
| 173 | - } | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | -+static bool findOptimizerModelPath(const std::string &modelRelPath, | ||
| 177 | -+ std::string &optModelPath, | ||
| 178 | -+ const char *envName = "LD_LIBRARY_PATH") { | ||
| 179 | -+ | ||
| 180 | -+ const char *paths = std::getenv(envName); | ||
| 181 | -+ std::istringstream envPaths{paths ? paths : ""}; | ||
| 182 | -+ std::vector<std::string> modelPathList; | ||
| 183 | -+ | ||
| 184 | -+ // Split environment variables and concatenate complete model paths. | ||
| 185 | -+ std::string modelPath; | ||
| 186 | -+ while (std::getline(envPaths, modelPath, ':')) { | ||
| 187 | -+ if (modelPath[modelPath.size() - 1] != '/') { | ||
| 188 | -+ modelPath += '/'; | ||
| 189 | -+ } | ||
| 190 | -+ modelPath += modelRelPath; | ||
| 191 | -+ modelPathList.push_back(modelPath); | ||
| 192 | -+ } | ||
| 193 | -+ | ||
| 194 | -+ for (const auto &modelPath : modelPathList) { | ||
| 195 | -+ std::filesystem::path filePath(modelPath); | ||
| 196 | -+ if (std::filesystem::exists(filePath)) { | ||
| 197 | -+ optModelPath = modelPath; | ||
| 198 | -+ return true; | ||
| 199 | -+ } | ||
| 200 | -+ } | ||
| 201 | -+ return false; | ||
| 202 | -+} | ||
| 203 | -+ | ||
| 204 | - extern int64_t runONNXModelOptimizer(int argcSW, const char **argvSW, | ||
| 205 | - const char *mcpuOption, int argcHW, | ||
| 206 | - int64_t *argvHW) { | ||
| 207 | - // Create model runner. | ||
| 208 | -- ONNXRunner *instance = createONNXRunner(MODEL_PATH_OPT); | ||
| 209 | -+ std::string optModelPath; | ||
| 210 | -+ std::string modelRelPath = "AI4C/optimizer.onnx"; | ||
| 211 | -+ const char *envName = "LD_LIBRARY_PATH"; | ||
| 212 | -+ if (!findOptimizerModelPath(modelRelPath, optModelPath, envName)) { | ||
| 213 | -+ return -1; | ||
| 214 | -+ } | ||
| 215 | -+ | ||
| 216 | -+ ONNXRunner *instance = createONNXRunner(optModelPath.c_str()); | ||
| 217 | - if (instance == nullptr) { | ||
| 218 | - return -1; | ||
| 219 | - } | ||
| 220 | -diff --git a/third_party/onnxruntime-1.16.3/cmake/external/eigen.cmake b/third_party/onnxruntime-1.16.3/cmake/external/eigen.cmake | ||
| 221 | -index c0f7ddc5..01bc8f7b 100644 | ||
| 222 | ---- a/third_party/onnxruntime-1.16.3/cmake/external/eigen.cmake | ||
| 223 | -+++ b/third_party/onnxruntime-1.16.3/cmake/external/eigen.cmake | ||
| 224 | -@@ -7,15 +7,17 @@ else () | ||
| 225 | - if (onnxruntime_USE_ACL) | ||
| 226 | - FetchContent_Declare( | ||
| 227 | - eigen | ||
| 228 | -- URL ${DEP_URL_eigen} | ||
| 229 | -- URL_HASH SHA1=${DEP_SHA1_eigen} | ||
| 230 | -- PATCH_COMMAND ${Patch_EXECUTABLE} --ignore-space-change --ignore-whitespace < ${PROJECT_SOURCE_DIR}/patches/eigen/Fix_Eigen_Build_Break.patch | ||
| 231 | -+# Stop populating content from external project. | ||
| 232 | -+# URL ${DEP_URL_eigen} | ||
| 233 | -+# URL_HASH SHA1=${DEP_SHA1_eigen} | ||
| 234 | -+# PATCH_COMMAND ${Patch_EXECUTABLE} --ignore-space-change --ignore-whitespace < ${PROJECT_SOURCE_DIR}/patches/eigen/Fix_Eigen_Build_Break.patch | ||
| 235 | - ) | ||
| 236 | - else() | ||
| 237 | - FetchContent_Declare( | ||
| 238 | - eigen | ||
| 239 | -- URL ${DEP_URL_eigen} | ||
| 240 | -- URL_HASH SHA1=${DEP_SHA1_eigen} | ||
| 241 | -+# Stop populating content from external project. | ||
| 242 | -+# URL ${DEP_URL_eigen} | ||
| 243 | -+# URL_HASH SHA1=${DEP_SHA1_eigen} | ||
| 244 | - ) | ||
| 245 | - endif() | ||
| 246 | - FetchContent_Populate(eigen) | ||
| 247 | -diff --git a/third_party/onnxruntime-1.16.3/cmake/external/onnxruntime_external_deps.cmake b/third_party/onnxruntime-1.16.3/cmake/external/onnxruntime_external_deps.cmake | ||
| 248 | -index e63cb1f1..d37607a3 100644 | ||
| 249 | ---- a/third_party/onnxruntime-1.16.3/cmake/external/onnxruntime_external_deps.cmake | ||
| 250 | -+++ b/third_party/onnxruntime-1.16.3/cmake/external/onnxruntime_external_deps.cmake | ||
| 251 | -@@ -163,10 +163,11 @@ else() | ||
| 252 | - endif() | ||
| 253 | - FetchContent_Declare( | ||
| 254 | - Protobuf | ||
| 255 | -+# Stop populating content from external project. | ||
| 256 | - # URL ${DEP_URL_protobuf} | ||
| 257 | - # URL_HASH SHA1=${DEP_SHA1_protobuf} | ||
| 258 | - # PATCH_COMMAND ${ONNXRUNTIME_PROTOBUF_PATCH_COMMAND} | ||
| 259 | -- FIND_PACKAGE_ARGS 3.21.12 NAMES Protobuf | ||
| 260 | -+# FIND_PACKAGE_ARGS 3.21.12 NAMES Protobuf | ||
| 261 | - ) | ||
| 262 | - set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) | ||
| 263 | - if (CMAKE_SYSTEM_NAME STREQUAL "Android") | ||
| 264 | --- | ||
| 265 | -2.33.0 | ||
| 266 | - | ||
| @@ -14,19 +14,14 @@ | |||
| 14 | 14 | ||
| 15 | Summary: %{name} is a framework which enables compilers compilers to integrate ML-driven compiler optimization. | 15 | Summary: %{name} is a framework which enables compilers compilers to integrate ML-driven compiler optimization. |
| 16 | Name: AI4C | 16 | Name: AI4C |
| 17 | -Version: 0.1.0 | 17 | +Version: 0.2.0 |
| 18 | -Release: 5 | 18 | +Release: 1 |
| 19 | # Package onnxruntime and SafeInt have MIT License. | 19 | # Package onnxruntime and SafeInt have MIT License. |
| 20 | # Package onnx has Apache License 2.0. | 20 | # Package onnx has Apache License 2.0. |
| 21 | License: MIT and ASL 2.0 and Boost and BSD | 21 | License: MIT and ASL 2.0 and Boost and BSD |
| 22 | URL: https://gitee.com/openeuler/AI4C | 22 | URL: https://gitee.com/openeuler/AI4C |
| 23 | Source0: %{pkg_version}.tar.gz | 23 | Source0: %{pkg_version}.tar.gz |
| 24 | 24 | ||
| 25 | -Patch1: 0001-Add-batch-inference-feature-and-optimizer-model.patch | ||
| 26 | -Patch2: 0002-Bugfix-for-tensor-formation-and-update-block-correct.patch | ||
| 27 | -Patch3: 0003-Update-block-correction-model.patch | ||
| 28 | -Patch4: 0004-Remove-path-dependencies-for-building-AI4Compiler-fr.patch | ||
| 29 | - | ||
| 30 | BuildRequires: cmake >= 3.13 | 25 | BuildRequires: cmake >= 3.13 |
| 31 | BuildRequires: make | 26 | BuildRequires: make |
| 32 | BuildRequires: gcc | 27 | BuildRequires: gcc |
| @@ -52,13 +47,13 @@ tar -xzf %{SOURCE0} -C . | |||
| 52 | 47 | ||
| 53 | %build | 48 | %build |
| 54 | # Construct dependency package `cmake` | 49 | # Construct dependency package `cmake` |
| 55 | -cd %{build_dir_dep}/cmake-3.28.5 | 50 | +cd %{build_dir_dep}/cmake |
| 56 | mkdir -p build && cd build | 51 | mkdir -p build && cd build |
| 57 | cmake .. -DCMAKE_INSTALL_PREFIX=./install | 52 | cmake .. -DCMAKE_INSTALL_PREFIX=./install |
| 58 | make install -j %{max_jobs} | 53 | make install -j %{max_jobs} |
| 59 | 54 | ||
| 60 | # Broken test in aarch64 architecture. | 55 | # Broken test in aarch64 architecture. |
| 61 | -cd %{build_dir_dep}/onnxruntime-1.16.3 | 56 | +cd %{build_dir_dep}/onnxruntime |
| 62 | %ifarch aarch64 | 57 | %ifarch aarch64 |
| 63 | rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc | 58 | rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc |
| 64 | %endif | 59 | %endif |
| @@ -66,7 +61,7 @@ rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc | |||
| 66 | # Construct dependency package `onnxruntime`. | 61 | # Construct dependency package `onnxruntime`. |
| 67 | mkdir -p %{build_libdir} | 62 | mkdir -p %{build_libdir} |
| 68 | mkdir -p %{build_includedir} | 63 | mkdir -p %{build_includedir} |
| 69 | -%{build_dir_dep}/cmake-3.28.5/build/install/bin/cmake \ | 64 | +%{build_dir_dep}/cmake/build/install/bin/cmake \ |
| 70 | -DCMAKE_INSTALL_PREFIX=%{build_dir_frm} \ | 65 | -DCMAKE_INSTALL_PREFIX=%{build_dir_frm} \ |
| 71 | -DCMAKE_INSTALL_LIBDIR=%{build_libdir} \ | 66 | -DCMAKE_INSTALL_LIBDIR=%{build_libdir} \ |
| 72 | -DCMAKE_INSTALL_INCLUDEDIR=%{build_includedir} \ | 67 | -DCMAKE_INSTALL_INCLUDEDIR=%{build_includedir} \ |
| @@ -108,6 +103,9 @@ popd | |||
| 108 | 103 | ||
| 109 | 104 | ||
| 110 | %changelog | 105 | %changelog |
| 106 | +* Wed Aug 14 2024 Zhenyu Zhao <zhaozhenyu17@huawei.com> - 0.2.0-1 | ||
| 107 | +- Update AI4C from v0.1.0 to v0.2.0. | ||
| 108 | + | ||
| 111 | * Tue Aug 06 2024 Feiyang Liu <liufeiyang6@huawei.com> - 0.1.0-5 | 109 | * Tue Aug 06 2024 Feiyang Liu <liufeiyang6@huawei.com> - 0.1.0-5 |
| 112 | - Remove path dependencies for building AI4Compiler framework | 110 | - Remove path dependencies for building AI4Compiler framework |
| 113 | 111 | ||