1# Copyright 2022 Huawei Technologies Co., Ltd 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================ 15 16# Here we port mindespore for OHOS from upstream community, by creating gn scripts 17# which translated from the cmake scripts at upstream. 18# 19# This BUILD.gn is the main build entry of ohos-ms. And it is corresponding to the 20# cmake procedure with following options applied: 21# 22# MSLITE_GPU_BACKEND = "" 23# MSLITE_REGISTRY_DEVICE = off 24# MSLITE_MICRO_PLATFORM = auto 25# MSLITE_ENABLE_NPU = off 26# MSLITE_ENABLE_TRAIN = off (train features depends on minddata, not support yet.) 27# MSLITE_ENABLE_SSE = off (default off, turn on for x86_64) 28# MSLITE_ENABLE_AVX = off (default off, turn on for x86_64) 29# MSLITE_ENABLE_AVX512 = off (default off, turn on for x86_64) 30# MSLITE_ENABLE_CONVERTER = off (converter tool is not embeded in ohos image) 31# MSLITE_ENABLE_TOOLS = off (no lite tool is embeded in ohos image) 32# MSLITE_ENABLE_TESTCASES = off 33# MSLITE_ENABLE_RUNTIME_PASS = on 34# MSLITE_ENABLE_HIGH_PERFORMANCE = off 35# MSLITE_ENABLE_STRING_KERNEL = on 36# MSLITE_ENABLE_CONTROLFLOW = on 37# MSLITE_ENABLE_AUTO_PARALLEL = on 38# MSLITE_ENABLE_WEIGHT_DECODE = on 39# MSLITE_ENABLE_CUSTOM_KERNEL = on 40# MSLITE_ENABLE_MINDRT = on 41# MSLITE_ENABLE_DELEGATE = on 42# MSLITE_ENABLE_FP16 = off (default off, turn on for arm64) 43# MSLITE_ENABLE_INT8 = on 44# MSLITE_ENABLE_ACL = off 45# MSLITE_ENABLE_ACL_QUANT_PARAM = off 46# MSLITE_ENABLE_MODEL_ENCRYPTION = off 47# MSLITE_ENABLE_SPARSE_COMPUTE = off 48# MSLITE_ENABLE_RUNTIME_CONVERT = off 49# MSLITE_ENABLE_RUNTIME_GLOG = off (ohos-ms adapts to os-buildin hilog) 50# MSLITE_ENABLE_COVERAGE = off 51# MSLITE_ENABLE_SERVER_INFERENCE = off 52# MSLITE_ENABLE_DYNAMIC_THREAD_DISTRIBUTE = off 53# MSLITE_ENABLE_BFC_MEMORY = off 54# MSLITE_ENABLE_PARALLEL_INFERENCE = off 55# MSLITE_ENABLE_SHARING_MODEL_WEIGHT = off 56# MSLITE_ENABLE_EXPERIMENTAL_KERNEL = on 57# MSLITE_ENABLE_GRAPH_KERNEL = off 58# MSLITE_ENABLE_CONVERT_PYTORCH_MODEL = off 59# MSLITE_ENABLE_KERNEL_EXECUTOR = off 60# MSLITE_ENABLE_GITEE_MIRROR = off (ohos-ms should only use the third-parties which provides by other ohos repos) 61# MSLITE_ENABLE_CLOUD_FUSION_INFERENCE = off 62# MSLITE_ENABLE_CLOUD_INFERENCE = off (alias to MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) 63# MSLITE_ENABLE_MODEL_OBF = off (enable model obfuscation) 64# MSLITE_ENABLE_MODEL_PRE_INFERENCE = off (enable model do pre-inference when Build interface is called) 65# MSLITE_EXPORT_COMPUTE_IR = off (export graph structure dotfile when debug mode) 66# MSLITE_ENABLE_PACKAGE_WHEEL = off (enable package python wheel) 67# MSLITE_ENABLE_NNRT = off (enable NNRT) 68# 69# We try to keep the options consist with the default ones at upstream, and provide 70# the reason on the behind of non-consist options. 71 72import("//build/ohos.gni") 73 74declare_args() { 75 mindspore_feature_nnrt_metagraph = false 76} 77 78ohos_group("mindspore") { 79 deps = [ 80 ":mindspore_lib", 81 ":mindspore_ndk", 82 ":mindspore_train_lib", 83 "mindir:mindir_lib", 84 "src/litert/js_api:mindsporelite_napi", 85 ] 86} 87 88# Inference library 89cxx_api_sources = [ 90 "src/litert/cxx_api/cell.cc", 91 "src/litert/cxx_api/context.cc", 92 "src/litert/cxx_api/converters.cc", 93 "src/litert/cxx_api/graph/graph.cc", 94 "src/litert/cxx_api/kernel.cc", 95 "src/litert/cxx_api/model/model.cc", 96 "src/litert/cxx_api/model/model_group.cc", 97 "src/litert/cxx_api/model/model_group_impl.cc", 98 "src/litert/cxx_api/model/model_impl.cc", 99 "src/litert/cxx_api/serialization.cc", 100 "src/litert/cxx_api/tensor/tensor_impl.cc", 101 "src/litert/cxx_api/tensor_utils.cc", 102 "src/litert/cxx_api/types.cc", 103] 104 105c_api_sources = [ 106 "src/litert/c_api/context_c.cc", 107 "src/litert/c_api/model_c.cc", 108 "src/litert/c_api/tensor_c.cc", 109] 110 111api_source = [ "../core/utils/status.cc" ] 112 113control_flow_kernel_sources = [ 114 "src/control_flow/kernel/entrance_subgraph_kernel.cc", 115 "src/control_flow/kernel/exit_subgraph_kernel.cc", 116 "src/control_flow/kernel/identity_kernel.cc", 117] 118 119auto_parallel_source = [ "src/litert/sub_graph_split.cc" ] 120 121custom_registry_sources = [ 122 "src/registry/kernel_interface_registry.cc", 123 "src/registry/register_kernel.cc", 124 "src/registry/register_kernel_impl.cc", 125 "src/registry/register_kernel_interface.cc", 126] 127 128weight_decode_source = [ "src/litert/weight_decoder.cc" ] 129 130all_lite_sources = [ 131 "src/control_flow/control_flow_scheduler.cc", 132 "src/control_flow/control_subgraph_creator.cc", 133 "src/errorcode.cc", 134 "src/executor/kernel_exec.cc", 135 "src/executor/sub_graph_kernel.cc", 136 "src/litert/allocator.cc", 137 "src/litert/cpu_info.cc", 138 "src/litert/executor.cc", 139 "src/litert/huffman_decode.cc", 140 "src/litert/infer_manager.cc", 141 "src/litert/inner_allocator.cc", 142 "src/litert/inner_context.cc", 143 "src/litert/kernel_exec_util.cc", 144 "src/litert/kernel_registry.cc", 145 "src/litert/lite_kernel.cc", 146 "src/litert/lite_model.cc", 147 "src/litert/lite_session.cc", 148 "src/litert/model_manager.cc", 149 "src/litert/pack_weight_manager.cc", 150 "src/litert/runtime_allocator.cc", 151 "src/litert/runtime_packed_node_pass.cc", 152 "src/litert/runtime_pass.cc", 153 "src/litert/runtime_shape_fusion_pass.cc", 154 "src/litert/scheduler.cc", 155 "src/litert/schema_tensor_wrapper.cc", 156 "src/litert/tensor_category.cc", 157 "src/litert/thread_pool_reuse_manager.cc", 158 "src/tensor.cc", 159 "src/tensorlist.cc", 160 "tools/converter/quantizer/fse_bit_stream.cc", 161 "tools/converter/quantizer/fse_decoder.cc", 162] 163 164lite_mindrt_sources = [ 165 "src/control_flow/actor/entrance_actor.cc", 166 "src/control_flow/actor/exit_actor.cc", 167 "src/control_flow/actor/switch_actor.cc", 168 "src/control_flow/control_actor_creator.cc", 169 "src/litert/lite_mindrt.cc", 170 "src/litert/mindrt_executor.cc", 171 "src/litert/parallel_lite_actor.cc", 172] 173 174all_lite_sources += cxx_api_sources 175all_lite_sources += api_source 176all_lite_sources += control_flow_kernel_sources 177all_lite_sources += auto_parallel_source 178all_lite_sources += custom_registry_sources 179all_lite_sources += weight_decode_source 180all_lite_sources += lite_mindrt_sources 181 182basic_populate_sources = [ 183 "src/common/ops/populate/activation_grad_populate.cc", 184 "src/common/ops/populate/activation_populate.cc", 185 "src/common/ops/populate/adam_populate.cc", 186 "src/common/ops/populate/add_populate.cc", 187 "src/common/ops/populate/adder_populate.cc", 188 "src/common/ops/populate/affine_populate.cc", 189 "src/common/ops/populate/all_gather.cc", 190 "src/common/ops/populate/argmax_populate.cc", 191 "src/common/ops/populate/argmin_populate.cc", 192 "src/common/ops/populate/arithmetic_populate.cc", 193 "src/common/ops/populate/arithmetic_self_populate.cc", 194 "src/common/ops/populate/assert_populate.cc", 195 "src/common/ops/populate/assign_add_populate.cc", 196 "src/common/ops/populate/assign_populate.cc", 197 "src/common/ops/populate/attention_populate.cc", 198 "src/common/ops/populate/audio_spectrogram_populate.cc", 199 "src/common/ops/populate/batch_norm_populate.cc", 200 "src/common/ops/populate/batch_to_space_populate.cc", 201 "src/common/ops/populate/bias_add_populate.cc", 202 "src/common/ops/populate/broadcast_to_populate.cc", 203 "src/common/ops/populate/call_populate.cc", 204 "src/common/ops/populate/cast_populate.cc", 205 "src/common/ops/populate/clip_populate.cc", 206 "src/common/ops/populate/common_populate.cc", 207 "src/common/ops/populate/concat_populate.cc", 208 "src/common/ops/populate/constant_of_shape_populate.cc", 209 "src/common/ops/populate/conv2d_populate.cc", 210 "src/common/ops/populate/crop_and_resize_populate.cc", 211 "src/common/ops/populate/crop_populate.cc", 212 "src/common/ops/populate/cumsum_populate.cc", 213 "src/common/ops/populate/custom_populate.cc", 214 "src/common/ops/populate/deconv2d_populate.cc", 215 "src/common/ops/populate/default_populate.cc", 216 "src/common/ops/populate/depth_to_space_populate.cc", 217 "src/common/ops/populate/detection_post_process_populate.cc", 218 "src/common/ops/populate/div_populate.cc", 219 "src/common/ops/populate/dynamic_quant_populate.cc", 220 "src/common/ops/populate/eltwise_populate.cc", 221 "src/common/ops/populate/embedding_lookup_populate.cc", 222 "src/common/ops/populate/erf_populate.cc", 223 "src/common/ops/populate/exp_populate.cc", 224 "src/common/ops/populate/expand_dims_populate.cc", 225 "src/common/ops/populate/fill_populate.cc", 226 "src/common/ops/populate/flatten_populate.cc", 227 "src/common/ops/populate/full_connection_populate.cc", 228 "src/common/ops/populate/fused_batchnorm_populate.cc", 229 "src/common/ops/populate/gather_d_populate.cc", 230 "src/common/ops/populate/gather_nd_populate.cc", 231 "src/common/ops/populate/gather_populate.cc", 232 "src/common/ops/populate/glu_populate.cc", 233 "src/common/ops/populate/group_norm_populate.cc", 234 "src/common/ops/populate/gru_populate.cc", 235 "src/common/ops/populate/instance_norm_populate.cc", 236 "src/common/ops/populate/invert_permutation_populate.cc", 237 "src/common/ops/populate/isfinite_populate.cc", 238 "src/common/ops/populate/l2_norm_populate.cc", 239 "src/common/ops/populate/layer_norm_grad_populate.cc", 240 "src/common/ops/populate/layer_norm_populate.cc", 241 "src/common/ops/populate/lin_space_populate.cc", 242 "src/common/ops/populate/local_response_normalization_populate.cc", 243 "src/common/ops/populate/log_softmax_populate.cc", 244 "src/common/ops/populate/lstm_populate.cc", 245 "src/common/ops/populate/matmul_populate.cc", 246 "src/common/ops/populate/mfcc_populate.cc", 247 "src/common/ops/populate/mul_populate.cc", 248 "src/common/ops/populate/nllloss_populate.cc", 249 "src/common/ops/populate/non_max_suppression_populate.cc", 250 "src/common/ops/populate/nonzero_populate.cc", 251 "src/common/ops/populate/one_hot_populate.cc", 252 "src/common/ops/populate/oneslike_populate.cc", 253 "src/common/ops/populate/p_relu_populate.cc", 254 "src/common/ops/populate/pad_populate.cc", 255 "src/common/ops/populate/partial_populate.cc", 256 "src/common/ops/populate/pooling_populate.cc", 257 "src/common/ops/populate/populate_register.cc", 258 "src/common/ops/populate/power_populate.cc", 259 "src/common/ops/populate/prior_box_populate.cc", 260 "src/common/ops/populate/quant_dtype_cast_populate.cc", 261 "src/common/ops/populate/ragged_range_populate.cc", 262 "src/common/ops/populate/random_normal_populate.cc", 263 "src/common/ops/populate/random_standard_normal_populate.cc", 264 "src/common/ops/populate/range_populate.cc", 265 "src/common/ops/populate/rank_populate.cc", 266 "src/common/ops/populate/reduce_populate.cc", 267 "src/common/ops/populate/reduce_scatter.cc", 268 "src/common/ops/populate/reshape_populate.cc", 269 "src/common/ops/populate/resize_populate.cc", 270 "src/common/ops/populate/reverse_populate.cc", 271 "src/common/ops/populate/reverse_sequence_populate.cc", 272 "src/common/ops/populate/roi_pooling_populate.cc", 273 "src/common/ops/populate/scale_populate.cc", 274 "src/common/ops/populate/scatter_element_populate.cc", 275 "src/common/ops/populate/scatter_nd_populate.cc", 276 "src/common/ops/populate/scatter_nd_update_populate.cc", 277 "src/common/ops/populate/select_populate.cc", 278 "src/common/ops/populate/shape_populate.cc", 279 "src/common/ops/populate/size_populate.cc", 280 "src/common/ops/populate/slice_populate.cc", 281 "src/common/ops/populate/softmax_populate.cc", 282 "src/common/ops/populate/space_to_batch_nd_populate.cc", 283 "src/common/ops/populate/space_to_batch_populate.cc", 284 "src/common/ops/populate/space_to_depth_populate.cc", 285 "src/common/ops/populate/sparse_fill_empty_rows_populate.cc", 286 "src/common/ops/populate/sparse_reshape_populate.cc", 287 "src/common/ops/populate/sparse_segment_sum_populate.cc", 288 "src/common/ops/populate/sparse_softmax_cross_entropy_with_logits_populate.cc", 289 "src/common/ops/populate/sparse_to_dense_populate.cc", 290 "src/common/ops/populate/splice_populate.cc", 291 "src/common/ops/populate/split_populate.cc", 292 "src/common/ops/populate/split_with_overlap_populate.cc", 293 "src/common/ops/populate/squeeze_populate.cc", 294 "src/common/ops/populate/stack_populate.cc", 295 "src/common/ops/populate/strided_slice_grad_populate.cc", 296 "src/common/ops/populate/strided_slice_populate.cc", 297 "src/common/ops/populate/sub_populate.cc", 298 "src/common/ops/populate/tile_populate.cc", 299 "src/common/ops/populate/topk_populate.cc", 300 "src/common/ops/populate/transpose_populate.cc", 301 "src/common/ops/populate/triu_tril_populate.cc", 302 "src/common/ops/populate/uniform_real_populate.cc", 303 "src/common/ops/populate/unique_populate.cc", 304 "src/common/ops/populate/unsorted_segment_sum_populate.cc", 305 "src/common/ops/populate/unsqueeze_populate.cc", 306 "src/common/ops/populate/unstack_populate.cc", 307 "src/common/ops/populate/where_populate.cc", 308] 309 310string_populate_sources = [ 311 "src/common/ops/populate/string/custom_extract_features_populate.cc", 312 "src/common/ops/populate/string/custom_normalize_populate.cc", 313 "src/common/ops/populate/string/custom_predict_populate.cc", 314 "src/common/ops/populate/string/hashtable_lookup_populate.cc", 315 "src/common/ops/populate/string/lsh_projection_populate.cc", 316 "src/common/ops/populate/string/skip_gram_populate.cc", 317] 318 319control_populate_sources = [ 320 "src/common/ops/populate/control/switch_populate.cc", 321 "src/common/ops/populate/control/tensor_array_populate.cc", 322 "src/common/ops/populate/control/tensorlistfromtensor_populate.cc", 323 "src/common/ops/populate/control/tensorlistgetitem_populate.cc", 324 "src/common/ops/populate/control/tensorlistreserve_populate.cc", 325 "src/common/ops/populate/control/tensorlistsetlitem_populate.cc", 326 "src/common/ops/populate/control/tensorliststack_populate.cc", 327] 328 329all_ops_sources = basic_populate_sources 330all_ops_sources += string_populate_sources 331all_ops_sources += control_populate_sources 332 333all_sources = all_lite_sources 334all_sources += all_ops_sources 335 336missing_sources = [ "src/extendrt/mindir_loader/model_loader.cc" ] 337 338all_sources += missing_sources 339 340SUPPORT_NNRT = false 341 342# currently, only arm/arm64 real machine support nnrt 343if ((target_cpu == "arm" || target_cpu == "arm64") && !is_emulator) { 344 SUPPORT_NNRT = true 345} 346 347ohos_shared_library("mindspore_lib") { 348 branch_protector_ret = "pac_ret" 349 deps = [ 350 "../ccsrc/plugin/device/cpu/kernel/nnacl/:nnacl_obj", 351 "../core/mindrt/:mindrt_obj", 352 "src/common/:lite_common_mid_obj", 353 "src/litert/kernel/cpu/:cpu_kernel_obj", 354 ] 355 356 sources = all_sources 357 358 include_dirs = [ 359 "../../../../../../third_party/flatbuffers/include", 360 "./", 361 "../", 362 "../../", 363 "../core", 364 "src", 365 "src/c_api/", 366 "../ccsrc/plugin/device/cpu/kernel/", 367 "../core/mindrt/src/", 368 "../core/mindrt/include/", 369 "../../third_party/", 370 "./schema/", 371 "../ccsrc/", 372 "src/litert/kernel/cpu/", 373 "../core/mindrt/src/", 374 ] 375 376 defines = [ 377 "ENABLE_MINDRT", 378 "MS_COMPILE_OHOS", 379 "PRIMITIVE_WRITEABLE", 380 "RUNTIME_PASS_CLIP", 381 "ENABLE_MULTI_LAYOUT", 382 "VERSION_STR=\"2.3.0\"", 383 "ENABLE_HI_APP_EVENT", 384 ] 385 386 if (target_cpu == "arm") { 387 defines += [ 388 "ENABLE_ARM", 389 "ENABLE_ARM32", 390 "ENABLE_NEON", 391 ] 392 } else if (target_cpu == "arm64") { 393 defines += [ 394 "ENABLE_ARM", 395 "ENABLE_ARM64", 396 "ENABLE_NEON", 397 "ENABLE_FP16", 398 "USE_OPENCL_WRAPPER", 399 "MS_OPENCL_PROFILE=false", 400 "CL_TARGET_OPENCL_VERSION=200", 401 "CL_HPP_TARGET_OPENCL_VERSION=120", 402 "CL_HPP_MINIMUM_OPENCL_VERSION=120", 403 ] 404 } else if (target_cpu == "x86_64") { 405 defines += [ 406 "ENABLE_SSE", 407 "ENABLE_AVX", 408 ] 409 410 # emulator not support avx512 411 if (!is_emulator) { 412 defines += [ "ENABLE_AVX512" ] 413 } 414 } 415 416 configs = [ 417 ":mindspore_api", 418 ":disable_android", 419 ":opencl_option", 420 ":secure_option", 421 ] 422 423 remove_configs = [ "//build/config/compiler:no_rtti" ] 424 425 external_deps = [ "hilog:libhilog" ] 426 427 public_external_deps = [ "flatbuffers:libflatbuffers_static" ] 428 429 output_name = "libmindspore-lite" 430 output_extension = "so" 431 innerapi_tags = [ "platformsdk" ] 432 if (SUPPORT_NNRT) { 433 if (mindspore_feature_nnrt_metagraph) { 434 defines += [ "SUPPORT_NNRT_METAGRAPH" ] 435 sources += [ 436 "src/litert/cache_session.cc", 437 "src/litert/delegate/nnrt/hiai_foundation_wrapper.cc", 438 ] 439 print("enabled feature: mindspore_feature_nnrt_metagraph") 440 } 441 sources += [ 442 "src/litert/delegate/nnrt/checker/primitive_check.cc", 443 "src/litert/delegate/nnrt/extension_options_parser.cc", 444 "src/litert/delegate/nnrt/nnrt_allocator.cc", 445 "src/litert/delegate/nnrt/nnrt_delegate.cc", 446 "src/litert/delegate/nnrt/nnrt_model_kernel.cc", 447 "src/litert/delegate/nnrt/nnrt_utils.cc", 448 ] 449 include_dirs += [ 450 "src/delegate/nnrt/include", 451 "../../mindspore/core/ir", 452 "mindir/include", 453 "mindir/inner_headers", 454 ] 455 456 external_deps += [ 457 "neural_network_runtime:libneural_network_core", 458 "neural_network_runtime:libneural_network_runtime", 459 ] 460 461 deps += [ "mindir:mindir_lib" ] 462 defines += [ "SUPPORT_NNRT" ] 463 } 464 defines += [ "MSLITE_ENABLE_EXPERIMENTAL_KERNEL" ] 465 defines += [ "SUPPORT_TRAIN" ] 466 cflags_cc = [ 467 "-Wno-ignored-qualifiers", 468 "-Wunused-private-field", 469 "-Wno-unused-private-field", 470 "-Wno-inconsistent-missing-override", 471 "-Wno-macro-redefined", 472 "-Wno-constant-conversion", 473 ] 474 part_name = "mindspore" 475 subsystem_name = "thirdparty" 476} 477 478# NDK lib 479ohos_shared_library("mindspore_ndk") { 480 branch_protector_ret = "pac_ret" 481 deps = [ 482 ":mindspore_lib", 483 ":mindspore_train_lib", 484 ] 485 486 sources = c_api_sources 487 488 include_dirs = [ 489 "../../../../../../base/hiviewdfx/hilog/interfaces/native/innerkits/include", 490 "../../../../../../third_party/flatbuffers/include", 491 "./", 492 "../", 493 "../../", 494 "../core", 495 "src", 496 "src/c_api/", 497 "../ccsrc/plugin/device/cpu/kernel/", 498 "../core/mindrt/src/", 499 "../core/mindrt/include/", 500 "../../third_party/", 501 "./schema/", 502 "../ccsrc/", 503 ] 504 505 defines = [ 506 "MS_COMPILE_OHOS", 507 "PRIMITIVE_WRITEABLE", 508 "RUNTIME_PASS_CLIP", 509 "ENABLE_MULTI_LAYOUT", 510 "VERSION_STR=\"2.3.0\"", 511 "ENABLE_HI_APP_EVENT", 512 ] 513 514 if (SUPPORT_NNRT) { 515 defines += [ "SUPPORT_NNRT" ] 516 if (mindspore_feature_nnrt_metagraph) { 517 defines += [ "SUPPORT_NNRT_METAGRAPH" ] 518 print("enabled feature: mindspore_feature_nnrt_metagraph") 519 } 520 external_deps = [ 521 "neural_network_runtime:libneural_network_core", 522 "neural_network_runtime:libneural_network_runtime", 523 ] 524 } 525 526 public_external_deps = [ "flatbuffers:libflatbuffers_static" ] 527 528 configs = [ 529 ":mindspore_api", 530 ":disable_android", 531 ":secure_option", 532 ] 533 534 public_configs = [ ":mindspore_api" ] 535 536 remove_configs = [ "//build/config/compiler:no_rtti" ] 537 538 output_name = "libmindspore_lite_ndk" 539 output_extension = "so" 540 innerapi_tags = [ "ndk" ] 541 cflags_cc = [ 542 "-Wno-ignored-qualifiers", 543 "-Wunused-private-field", 544 "-Wno-unused-private-field", 545 "-Wno-inconsistent-missing-override", 546 "-Wno-macro-redefined", 547 "-Wno-constant-conversion", 548 ] 549 part_name = "mindspore" 550 subsystem_name = "thirdparty" 551} 552 553# Train library 554all_train_sources = [ 555 # ${API_TRAIN_SRC} is empty. 556 # ${TRAIN_SRC_WITH_MD} is empty. 557 "src/common/quant_utils.cc", 558 "src/common/storage.cc", 559 "src/litert/cxx_api/metrics/accuracy.cc", 560 "src/litert/cxx_api/train/converters.cc", 561 "src/litert/cxx_api/train/model_build.cc", 562 "src/litert/cxx_api/train/model_build_impl.cc", 563 "src/litert/cxx_api/train/train_support.cc", 564 "src/train/accuracy_metrics.cc", 565 566 # "src/train/accuracy_monitor.cc", # depends on minddata header, not compiled 567 "src/train/classification_train_accuracy_monitor.cc", 568 "src/train/graph_dropout.cc", 569 "src/train/graph_fusion.cc", 570 "src/train/loss_monitor.cc", 571 "src/train/lr_scheduler.cc", 572 "src/train/opt_allocator.cc", 573 "src/train/optimizer/common/fusion_utils.cc", 574 "src/train/optimizer/fusion/gru_fusion_pass.cc", 575 "src/train/optimizer/fusion/matmul_activation_fusion_pass.cc", 576 "src/train/optimizer/fusion/matmul_add_fusion_pass.cc", 577 "src/train/optimizer/fusion/matmul_matmul_add_fusion_pass.cc", 578 "src/train/optimizer/fusion/remove_redundant_tensor.cc", 579 "src/train/optimizer/fusion/reshape_gather_reshape_fusion_pass.cc", 580 "src/train/train_export.cc", 581 "src/train/train_populate_parameter.cc", 582 "src/train/train_session.cc", 583 "src/train/train_utils.cc", 584 "src/train/transfer_session.cc", 585 "tools/common/meta_graph_utils.cc", 586 "tools/common/statistic_utils.cc", 587 "tools/converter/legacy_optimizer/fusion/fusion_pass.cc", 588 "tools/converter/legacy_optimizer/fusion/fusion_pattern.cc", 589 "tools/converter/legacy_optimizer/fusion/matmul_biasadd_fusion_pass.cc", 590 "tools/converter/legacy_optimizer/graph/dropout_node_remove_pass.cc", 591 "tools/converter/legacy_optimizer/graph/isolated_node_remove_pass.cc", 592 "tools/converter/legacy_optimizer/graph/subgraph_node_pass.cc", 593 "tools/converter/optimizer.cc", 594] 595 596fp16_train_kernel_sources = [ 597 "src/litert/kernel/cpu/fp16_grad/activation_fp16_grad.cc", 598 "src/litert/kernel/cpu/fp16_grad/arithmetic_fp16_grad.cc", 599 "src/litert/kernel/cpu/fp16_grad/arithmetic_fp16_self_grad.cc", 600 "src/litert/kernel/cpu/fp16_grad/bias_fp16_grad.cc", 601 "src/litert/kernel/cpu/fp16_grad/bn_fp16_grad.cc", 602 "src/litert/kernel/cpu/fp16_grad/convolution_fp16_grad_filter.cc", 603 "src/litert/kernel/cpu/fp16_grad/convolution_fp16_grad_input.cc", 604 "src/litert/kernel/cpu/fp16_grad/dropout_fp16_grad.cc", 605 "src/litert/kernel/cpu/fp16_grad/layernorm_fp16_grad.cc", 606 "src/litert/kernel/cpu/fp16_grad/neg_fp16_grad.cc", 607 "src/litert/kernel/cpu/fp16_grad/pooling_fp16_grad.cc", 608 "src/litert/kernel/cpu/fp16_grad/resize_fp16_grad.cc", 609 "src/litert/kernel/cpu/fp16_grad/strided_slice_fp16_grad.cc", 610 "src/litert/kernel/cpu/fp16_grad/unsorted_segment_sum_fp16.cc", 611] 612 613fp32_train_kernel_sources = [ 614 "src/litert/kernel/cpu/fp32_grad/activation_grad.cc", 615 "src/litert/kernel/cpu/fp32_grad/adam.cc", 616 "src/litert/kernel/cpu/fp32_grad/adam_weight_decay.cc", 617 "src/litert/kernel/cpu/fp32_grad/apply_momentum.cc", 618 "src/litert/kernel/cpu/fp32_grad/arithmetic_grad.cc", 619 "src/litert/kernel/cpu/fp32_grad/arithmetic_self_grad.cc", 620 "src/litert/kernel/cpu/fp32_grad/assign.cc", 621 "src/litert/kernel/cpu/fp32_grad/bias_grad.cc", 622 "src/litert/kernel/cpu/fp32_grad/binary_cross_entropy.cc", 623 "src/litert/kernel/cpu/fp32_grad/binary_cross_entropy_grad.cc", 624 "src/litert/kernel/cpu/fp32_grad/bn_grad.cc", 625 "src/litert/kernel/cpu/fp32_grad/convolution.cc", 626 "src/litert/kernel/cpu/fp32_grad/convolution_grad_filter.cc", 627 "src/litert/kernel/cpu/fp32_grad/convolution_grad_input.cc", 628 "src/litert/kernel/cpu/fp32_grad/custom_gather_d_grad_v2_fp32.cc", 629 "src/litert/kernel/cpu/fp32_grad/deconvolution_grad_filter.cc", 630 "src/litert/kernel/cpu/fp32_grad/dropout.cc", 631 "src/litert/kernel/cpu/fp32_grad/dropout_grad.cc", 632 "src/litert/kernel/cpu/fp32_grad/layernorm_grad.cc", 633 "src/litert/kernel/cpu/fp32_grad/lstm_grad_data_fp32.cc", 634 "src/litert/kernel/cpu/fp32_grad/lstm_grad_fp32.cc", 635 "src/litert/kernel/cpu/fp32_grad/lstm_grad_weight_fp32.cc", 636 "src/litert/kernel/cpu/fp32_grad/neg_grad.cc", 637 "src/litert/kernel/cpu/fp32_grad/nllloss_grad.cc", 638 "src/litert/kernel/cpu/fp32_grad/pooling_grad.cc", 639 "src/litert/kernel/cpu/fp32_grad/power_grad.cc", 640 "src/litert/kernel/cpu/fp32_grad/resize_grad.cc", 641 "src/litert/kernel/cpu/fp32_grad/sgd.cc", 642 "src/litert/kernel/cpu/fp32_grad/sigmoid_cross_entropy_with_logits.cc", 643 "src/litert/kernel/cpu/fp32_grad/sigmoid_cross_entropy_with_logits_grad.cc", 644 "src/litert/kernel/cpu/fp32_grad/smooth_l1_loss.cc", 645 "src/litert/kernel/cpu/fp32_grad/smooth_l1_loss_grad.cc", 646 "src/litert/kernel/cpu/fp32_grad/softmax_cross_entropy_with_logits.cc", 647 "src/litert/kernel/cpu/fp32_grad/softmax_grad.cc", 648 "src/litert/kernel/cpu/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc", 649 "src/litert/kernel/cpu/fp32_grad/strided_slice_grad.cc", 650 "src/litert/kernel/cpu/fp32_grad/unsorted_segment_sum.cc", 651] 652 653#all_train_sources += fp16_train_kernel_sources 654not_needed(fp16_train_kernel_sources) 655all_train_sources += fp32_train_kernel_sources 656 657ohos_shared_library("mindspore_train_lib") { 658 branch_protector_ret = "pac_ret" 659 deps = [ ":mindspore_lib" ] 660 661 sources = all_train_sources 662 663 include_dirs = [ 664 "../../../../../../third_party/flatbuffers/include", 665 "./", 666 "../", 667 "../../", 668 "../core", 669 "src", 670 "src/c_api/", 671 "../ccsrc/plugin/device/cpu/kernel/", 672 "../core/mindrt/src/", 673 "../core/mindrt/include/", 674 "../../third_party/", 675 "./schema/", 676 "../ccsrc/", 677 ] 678 679 defines = [ 680 "ENABLE_MINDRT", 681 "MS_COMPILE_OHOS", 682 "PRIMITIVE_WRITEABLE", 683 "VERSION_STR=\"2.3.0\"", 684 ] 685 686 if (target_cpu == "arm") { 687 defines += [ 688 "ENABLE_ARM", 689 "ENABLE_ARM32", 690 "ENABLE_NEON", 691 ] 692 } else if (target_cpu == "arm64") { 693 defines += [ 694 "ENABLE_ARM", 695 "ENABLE_ARM64", 696 "ENABLE_NEON", 697 "ENABLE_FP16", 698 "USE_OPENCL_WRAPPER", 699 "MS_OPENCL_PROFILE=false", 700 "CL_TARGET_OPENCL_VERSION=200", 701 "CL_HPP_TARGET_OPENCL_VERSION=120", 702 "CL_HPP_MINIMUM_OPENCL_VERSION=120", 703 ] 704 } 705 configs = [ 706 ":mindspore_api", 707 ":disable_android", 708 ":train_kernel_option", 709 ":secure_option", 710 ] 711 712 remove_configs = [ "//build/config/compiler:no_rtti" ] 713 external_deps = [ "hilog:libhilog" ] 714 public_external_deps = [ "flatbuffers:libflatbuffers_static" ] 715 innerapi_tags = [ "platformsdk" ] 716 output_name = "libmindspore-lite-train" 717 output_extension = "so" 718 defines += [ "SUPPORT_TRAIN" ] 719 cflags_cc = [ 720 "-Wno-ignored-qualifiers", 721 "-Wunused-private-field", 722 "-Wno-unused-private-field", 723 "-Wno-inconsistent-missing-override", 724 "-Wno-macro-redefined", 725 "-Wno-constant-conversion", 726 ] 727 part_name = "mindspore" 728} 729 730# Build configurations 731config("opencl_option") { 732 cflags_cc = [ "-Wno-missing-braces" ] 733} 734 735config("mindspore_api") { 736 include_dirs = [ 737 "../../", 738 "../../include/", 739 "../../include/c_api", 740 ] 741} 742 743config("disable_android") { 744 cflags = [ 745 "-UANDROID", 746 "-U__ANDROID__", 747 "-U__ANDROID_API__", 748 ] 749 cflags_cc = [ 750 "-UANDROID", 751 "-U__ANDROID__", 752 "-U__ANDROID_API__", 753 ] 754 ldflags = [ "-Wl,--no-as-needed" ] 755} 756 757config("secure_option") { 758 cflags = [ 759 "-fstack-protector-all", 760 "-D_FORTIFY_SOURCE=2", 761 ] 762} 763 764config("train_kernel_option") { 765 cflags_cc = [ "-fno-finite-math-only" ] 766} 767