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.

model_process.h 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Copyright 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 INC_MODEL_PROCESS_ACL
  17. #define INC_MODEL_PROCESS_ACL
  18. #include <vector>
  19. #include <string>
  20. #include "acl/acl.h"
  21. #include "acl/acl_mdl.h"
  22. #include "acl/acl_rt.h"
  23. #include "serving/core/util/status.h"
  24. #include "include/inference.h"
  25. namespace mindspore {
  26. namespace inference {
  27. struct AclTensorInfo {
  28. void *device_data;
  29. size_t buffer_size;
  30. aclDataType data_type;
  31. std::vector<int64_t> dims;
  32. };
  33. class ModelProcess {
  34. public:
  35. ModelProcess() {}
  36. ~ModelProcess() {}
  37. bool LoadModelFromFile(const std::string &file_name, uint32_t &model_id);
  38. void UnLoad();
  39. // override this method to avoid request/reply data copy
  40. bool Execute(const RequestBase &request, ReplyBase &reply);
  41. void SetIsDevice(bool is_device) { is_run_on_device_ = is_device; }
  42. private:
  43. uint32_t model_id_ = 0xffffffff;
  44. bool is_run_on_device_ = false;
  45. aclmdlDesc *model_desc_ = nullptr;
  46. aclmdlDataset *inputs_ = nullptr;
  47. aclmdlDataset *outputs_ = nullptr;
  48. std::vector<AclTensorInfo> input_infos_;
  49. std::vector<AclTensorInfo> output_infos_;
  50. bool CreateDataBuffer(void *&data_mem_buffer, size_t buffer_size, aclmdlDataset *dataset);
  51. bool CheckAndInitInput(const RequestBase &request);
  52. bool BuildOutputs(ReplyBase &reply);
  53. bool InitInputsBuffer();
  54. bool InitOutputsBuffer();
  55. void DestroyInputsDataset();
  56. void DestroyInputsDataMem();
  57. void DestroyInputsBuffer();
  58. void DestroyOutputsBuffer();
  59. };
  60. } // namespace inference
  61. } // namespace mindspore
  62. #endif