1 /** 2 * Copyright 2023 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_INCLUDE_COMMON_UTILS_OFFLOAD_CONTEXT_H_ 18 #define MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_OFFLOAD_CONTEXT_H_ 19 20 #include <string> 21 #include <memory> 22 #include "include/common/visible.h" 23 24 namespace mindspore { 25 class COMMON_EXPORT OffloadContext { 26 public: 27 static std::shared_ptr<OffloadContext> GetInstance(); 28 ~OffloadContext() = default; 29 OffloadContext(const OffloadContext &) = delete; 30 OffloadContext &operator=(const OffloadContext &) = delete; 31 32 void set_offload_param(const std::string &offload_param); offload_param()33 std::string offload_param() const { return offload_param_; } 34 35 void set_offload_path(const std::string &offload_path); offload_path()36 std::string offload_path() { return offload_path_; } 37 38 void set_offload_checkpoint(const std::string &offload_checkpoint); offload_checkpoint()39 std::string offload_checkpoint() const { return offload_checkpoint_; } 40 41 void set_offload_cpu_size(size_t offload_cpu_size); 42 size_t offload_cpu_size(); 43 44 void set_offload_disk_size(size_t offload_disk_size); 45 size_t offload_disk_size(); 46 47 void set_enable_aio(bool enable_aio); 48 bool enable_aio(); 49 50 void set_aio_block_size(size_t aio_block_size); aio_block_size()51 size_t aio_block_size() const { return aio_block_size_; } 52 53 void set_aio_queue_depth(size_t aio_queue_depth); aio_queue_depth()54 size_t aio_queue_depth() const { return aio_queue_depth_; } 55 56 void set_enable_pinned_mem(bool enable_pinned_mem); enable_pinned_mem()57 bool enable_pinned_mem() const { return enable_pinned_mem_; } 58 59 void set_auto_offload(bool auto_offload); auto_offload()60 bool auto_offload() const { return auto_offload_; } 61 62 void set_host_mem_block_size(size_t host_mem_block_size); host_mem_block_size()63 size_t host_mem_block_size() const { return host_mem_block_size_; } 64 cpu_size_configured()65 bool cpu_size_configured() const { return cpu_size_configured_; } 66 67 void set_cpu_ratio(float cpu_ratio); cpu_ratio()68 float cpu_ratio() const { return cpu_ratio_; } 69 70 void set_hbm_ratio(float hbm_ratio); hbm_ratio()71 float hbm_ratio() const { return hbm_ratio_; } 72 73 private: 74 OffloadContext(); 75 std::string offload_param_; 76 std::string offload_path_; 77 std::string offload_checkpoint_; 78 size_t offload_cpu_size_; 79 size_t offload_disk_size_; 80 bool enable_aio_; 81 size_t aio_block_size_; 82 size_t aio_queue_depth_; 83 bool enable_pinned_mem_; 84 bool auto_offload_; 85 size_t host_mem_block_size_; 86 bool cpu_size_configured_; 87 float cpu_ratio_; 88 float hbm_ratio_; 89 }; 90 } // namespace mindspore 91 #endif // MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_OFFLOAD_CONTEXT_H_ 92