• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-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 #include "minddata/dataset/engine/tree_modifier.h"
18 
19 namespace mindspore {
20 namespace dataset {
DSNStepBegin(const CallbackParam & cb_param)21 Status AutotuneCallback::DSNStepBegin(const CallbackParam &cb_param) {
22   // check if the queue is empty, no need to wait until a change request is ready
23   if (!change_request_queue_->empty()) {
24     ChangeRequestPtr change_request;
25     RETURN_IF_NOT_OK(change_request_queue_->PopFront(&change_request));
26     RETURN_IF_NOT_OK(change_request->ApplyChange(op_));
27   }
28   return Status::OK();
29 }
30 
DSBegin(const CallbackParam & cb_param)31 Status AutotuneCallback::DSBegin(const CallbackParam &cb_param) { return Status::OK(); }
32 
DSEpochBegin(const CallbackParam & cb_param)33 Status AutotuneCallback::DSEpochBegin(const CallbackParam &cb_param) { return Status::OK(); }
34 
DSEnd(const CallbackParam & cb_param)35 Status AutotuneCallback::DSEnd(const CallbackParam &cb_param) { return Status::OK(); }
36 
DSEpochEnd(const CallbackParam & cb_param)37 Status AutotuneCallback::DSEpochEnd(const CallbackParam &cb_param) { return Status::OK(); }
38 
DSNStepEnd(const CallbackParam & cb_param)39 Status AutotuneCallback::DSNStepEnd(const CallbackParam &cb_param) { return Status::OK(); }
40 
IsBeginNeeded()41 bool AutotuneCallback::IsBeginNeeded() { return false; }
42 
IsEpochBeginNeeded()43 bool AutotuneCallback::IsEpochBeginNeeded() { return false; }
44 
IsNStepBeginNeeded()45 bool AutotuneCallback::IsNStepBeginNeeded() { return true; }
46 
IsEndNeeded()47 bool AutotuneCallback::IsEndNeeded() { return false; }
48 
IsEpochEndNeeded()49 bool AutotuneCallback::IsEpochEndNeeded() { return false; }
50 
IsNStepEndNeeded()51 bool AutotuneCallback::IsNStepEndNeeded() { return false; }
52 
PushChangeRequest(ChangeRequestPtr change_request)53 Status AutotuneCallback::PushChangeRequest(ChangeRequestPtr change_request) {
54   RETURN_IF_NOT_OK(change_request_queue_->Add(std::move(change_request)));
55   return Status::OK();
56 }
57 
ApplyChange(DatasetOp * op)58 Status ChangeNumWorkersRequest::ApplyChange(DatasetOp *op) {
59   int32_t diff = num_workers_ - op->NumWorkers();
60   if (diff > 0) {
61     RETURN_IF_NOT_OK(op->AddNewWorkers(diff));
62   } else if (diff < 0) {
63     RETURN_IF_NOT_OK(op->RemoveWorkers(-1 * diff));
64   }
65   return Status::OK();
66 }
67 
TreeModifier(const TreeAdapter * adapter)68 TreeModifier::TreeModifier(const TreeAdapter *adapter) : TreeModifier(adapter->tree_.get()) {}
69 }  // namespace dataset
70 }  // namespace mindspore
71