You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

fusion_engine.h 2.5 kB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FUSION_ENGINE_HPP_
  17. #define FUSION_ENGINE_HPP_
  18. #include "cce/cce.h"
  19. #include "graph/compute_graph.h"
  20. #include "proto/task.pb.h"
  21. #include <map>
  22. #include <vector>
  23. using namespace domi;
  24. using namespace std;
  25. namespace fusion {
  26. enum {
  27. FUSION_STATUS_SUCCESS = 0,
  28. FUSION_STATUS_FAIL = 1,
  29. };
  30. typedef struct {
  31. uint64_t weightSize;
  32. uint64_t memorySize;
  33. uint8_t *dataMemBase;
  34. uint8_t *weightMemBase;
  35. uint32_t l2Enable; // 1 //1 - enable l2 buffer allocation, 0 - disable l2 buffer allocation
  36. uint32_t fusionEnable; // 1 // 1 - enable buffer fusion, 0 - disable buffer fusion
  37. } ModelRes;
  38. static const std::string SCOPE_ID_ATTR = "fusion_scope";
  39. static const std::string L2FUSION_DYNAMIC_CONVERGE_OP = "l2fusion_dynamic_converge_op";
  40. static const std::string L2FUSION_DYNAMIC_SPLIT_NUM = "l2fusion_dynamic_split_num";
  41. static const std::string FUSION_VIRTUAL_OP = "fusion_virtual_op";
  42. static const std::string FUSION_MULTI_BATCH_STRIDE = "fusion_multi_bathc_stride";
  43. #define TVM_TYPE 1
  44. typedef std::map<int64_t, std::vector<ge::NodePtr>> kScopeNodeMap_t;
  45. typedef std::pair<int64_t, std::vector<ge::NodePtr>> kScopeNodePair_t;
  46. uint32_t BufferFusion(ge::ComputeGraphPtr origGraph, ge::ComputeGraphPtr fusionGraph, bool enable_l2dynamic = true);
  47. uint32_t BufferFusionTrain(ge::ComputeGraphPtr origGraph, ge::ComputeGraphPtr fusionGraph);
  48. uint32_t GraphFusion(ge::ComputeGraphPtr origGraph, ge::ComputeGraphPtr fusionGraph);
  49. uint32_t FusionTaskBuild(cce::ccHandle_t ccHandle, ge::ComputeGraphPtr fusionGraph, ge::Buffer &buffer,
  50. ModelRes &modelRes, std::vector<TaskDef> &task_def_list_);
  51. void FusionTaskBuildComplete(std::vector<cce::ccHandle_t> cchandleList);
  52. uint32_t GraphFusionTrain(ge::ComputeGraphPtr origGraph, ge::ComputeGraphPtr fusionGraph);
  53. } // namespace fusion
  54. #endif // FUSION_ENGINE_HPP_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示