1 /** 2 * Copyright 2021 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_FRAMEWORK_ACTOR_MEMORY_AWARE_ACTOR_H_ 18 #define MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_MEMORY_AWARE_ACTOR_H_ 19 20 #include <utility> 21 #include <string> 22 #include "runtime/framework/actor/abstract_actor.h" 23 #include "runtime/framework/device_tensor_store.h" 24 25 namespace mindspore { 26 namespace runtime { 27 // The actor represents a set of common memory related operations of actor. 28 class MemoryAwareActor : public AbstractActor { 29 public: MemoryAwareActor(const std::string & name,KernelTransformType type,const AID * recorder_aid,const AID & memory_manager_aid)30 explicit MemoryAwareActor(const std::string &name, KernelTransformType type, const AID *recorder_aid, 31 const AID &memory_manager_aid) 32 : AbstractActor(name, type, recorder_aid), memory_manager_aid_(memory_manager_aid) {} 33 virtual ~MemoryAwareActor() = default; 34 SendMemoryAllocReq(OpContext<DeviceTensor> * const context)35 virtual void SendMemoryAllocReq(OpContext<DeviceTensor> *const context) {} SendMemoryFreeReq(OpContext<DeviceTensor> * const context)36 virtual void SendMemoryFreeReq(OpContext<DeviceTensor> *const context) {} OnMemoryAllocFinish(OpContext<DeviceTensor> * const context)37 virtual void OnMemoryAllocFinish(OpContext<DeviceTensor> *const context) {} 38 39 protected: 40 friend class GraphScheduler; 41 42 // The id of memory manager actor. Send message to it for alloc and free memory. 43 const AID memory_manager_aid_; 44 }; 45 } // namespace runtime 46 } // namespace mindspore 47 48 #endif // MINDSPORE_CCSRC_RUNTIME_FRAMEWORK_ACTOR_MEMORY_AWARE_ACTOR_H_ 49