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_RUNTIME_DEVICE_COMMON_SOMAS_ALLOCATOR_H 18 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_COMMON_SOMAS_ALLOCATOR_H 19 20 #include <vector> 21 #include <string> 22 #include <map> 23 #include <utility> 24 #include <memory> 25 #include "backend/common/somas/somas.h" 26 #include "include/backend/device_type.h" 27 #include "utils/ms_context.h" 28 29 namespace mindspore { 30 namespace device { 31 class CommonSomasAllocator { 32 public: set_mem_base_addr(uint8_t * mem_base_addr)33 void set_mem_base_addr(uint8_t *mem_base_addr) { mem_base_addr_ = mem_base_addr; } 34 static bool Assign(const session::KernelGraph &graph); 35 uint8_t *GetNodeOutputPtr(const AnfNodePtr &node, size_t index) const; 36 uint8_t *GetNodeWorkSpacePtr(const AnfNodePtr &node, size_t index) const; 37 38 private: 39 // Memory base addr 40 uint8_t *mem_base_addr_{nullptr}; GetTargetFromContext()41 static std::string GetTargetFromContext() { 42 auto context_ptr = MsContext::GetInstance(); 43 MS_EXCEPTION_IF_NULL(context_ptr); 44 return context_ptr->get_param<std::string>(MS_CTX_DEVICE_TARGET); 45 } 46 }; 47 using CommonSomasAllocatorPtr = std::shared_ptr<CommonSomasAllocator>; 48 } // namespace device 49 } // namespace mindspore 50 #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_COMMON_SOMAS_ALLOCATOR_H 51