1 /** 2 * Copyright 2022 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 17 #ifndef MINDSPORE_CCSRC_C_API_INCLUDE_CONTEXT_H_ 18 #define MINDSPORE_CCSRC_C_API_INCLUDE_CONTEXT_H_ 19 20 #include <stdint.h> 21 #include <stdlib.h> 22 #include "include/c_api/ms/base/macros.h" 23 #include "include/c_api/ms/base/status.h" 24 #include "include/c_api/ms/base/handle_types.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 /// \brief Create a resource manager. Tracking allocated objects(i.e. FuncGraph, Nodes...). 30 MIND_C_API ResMgrHandle MSResourceManagerCreate(); 31 32 /// \brief Release a resource manager and the enclosed objects. 33 /// 34 /// \param[in] res_mgr Manager Handle that manages the resource of the funcGraph. 35 MIND_C_API void MSResourceManagerDestroy(ResMgrHandle res_mgr); 36 37 /// \brief Set context to Graph or pynative mood. 38 /// 39 /// \param[in] eager_mode True: Pynative, False: Graph. 40 MIND_C_API void MSSetEagerMode(bool eager_mode); 41 42 /// \brief Select MindRT, VM or GE as Backend Policy. 43 /// 44 /// \param[in] policy select one from {"ge", "vm", "ms", "ge_only", "vm_prior"}. 45 /// 46 /// \return Error code indicates whether the function executed successfully. 47 MIND_C_API STATUS MSSetBackendPolicy(const char *policy); 48 49 /// \brief Get backend policy context. 50 /// 51 /// \param[in] str_buf The char array to contain the backend policy string. 52 /// \param[in] str_len The size of the char array. 53 /// 54 /// \return name of the device under current context 55 MIND_C_API STATUS MSGetBackendPolicy(char str_buf[], size_t str_len); 56 57 /// \brief set device type context. 58 /// 59 /// \param[in] device type name of the device i.e. CPU, GPU, Ascend. 60 MIND_C_API void MSSetDeviceTarget(const char *device); 61 62 /// \brief Get device type context. 63 /// 64 /// \param[in] str_buf The char array to contain the device target string. 65 /// \param[in] str_len The size of the char array. 66 /// 67 /// \return name of the device under current context 68 MIND_C_API STATUS MSGetDeviceTarget(char str_buf[], size_t str_len); 69 70 /// \brief Set Device ID context. 71 /// 72 /// \param[in] deviceId Device ID. 73 MIND_C_API void MSSetDeviceId(uint32_t deviceId); 74 75 /// \brief Set flag for saving the graph. 76 /// 77 /// \param[in] save_mode The flag to control the amount of saved graph files. There are 3 levels: 78 /// 1: Basic level. Only save frontend IR graph and some common backend IR graphs. 79 /// 2: Advanced level. Save all graphs except for verbose IR graphs and dot files. 80 /// 3: Full level. Save all IR graphs. 81 MIND_C_API void MSSetIRGraphsSaveMode(int save_mode); 82 83 /// \brief Set save path of IRGraphs. 84 /// 85 /// \param[in] save_path The save path. 86 MIND_C_API void MSSetIRGraphsSavePath(const char *save_path); 87 88 /// \brief Set flag for auto shape and type infer. 89 /// 90 /// \param[in] res_mgr Manager Handle that manages the resource of the funcGraph. 91 /// \param[in] infer True: Use inner auto infer, False: Not use auto infer. 92 MIND_C_API void MSSetInfer(ResMgrHandle res_mgr, bool infer); 93 94 /// \brief Get flag for auto shape and type infer. 95 /// 96 /// \param[in] res_mgr Manager Handle that manages the resource of the funcGraph. 97 MIND_C_API bool MSGetInfer(ResMgrHandle res_mgr); 98 99 #ifdef __cplusplus 100 } 101 #endif 102 #endif // MINDSPORE_CCSRC_C_API_INCLUDE_CONTEXT_H_ 103