You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tree_modifier.cc 2.5 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "minddata/dataset/engine/tree_modifier.h"
  17. namespace mindspore {
  18. namespace dataset {
  19. Status AutotuneCallback::DSNStepBegin(const CallbackParam &cb_param) {
  20. // check if the queue is empty, no need to wait until a change request is ready
  21. if (!change_request_queue_->empty()) {
  22. ChangeRequestPtr change_request;
  23. RETURN_IF_NOT_OK(change_request_queue_->PopFront(&change_request));
  24. RETURN_IF_NOT_OK(change_request->ApplyChange(op_));
  25. }
  26. return Status::OK();
  27. }
  28. Status AutotuneCallback::DSBegin(const CallbackParam &cb_param) { return Status::OK(); }
  29. Status AutotuneCallback::DSEpochBegin(const CallbackParam &cb_param) { return Status::OK(); }
  30. Status AutotuneCallback::DSEnd(const CallbackParam &cb_param) { return Status::OK(); }
  31. Status AutotuneCallback::DSEpochEnd(const CallbackParam &cb_param) { return Status::OK(); }
  32. Status AutotuneCallback::DSNStepEnd(const CallbackParam &cb_param) { return Status::OK(); }
  33. bool AutotuneCallback::IsBeginNeeded() { return false; }
  34. bool AutotuneCallback::IsEpochBeginNeeded() { return false; }
  35. bool AutotuneCallback::IsNStepBeginNeeded() { return true; }
  36. bool AutotuneCallback::IsEndNeeded() { return false; }
  37. bool AutotuneCallback::IsEpochEndNeeded() { return false; }
  38. bool AutotuneCallback::IsNStepEndNeeded() { return false; }
  39. Status AutotuneCallback::PushChangeRequest(ChangeRequestPtr change_request) {
  40. RETURN_IF_NOT_OK(change_request_queue_->Add(change_request));
  41. return Status::OK();
  42. }
  43. Status ChangeNumWorkersRequest::ApplyChange(DatasetOp *op) {
  44. int32_t diff = num_workers_ - op->NumWorkers();
  45. if (diff > 0) {
  46. RETURN_IF_NOT_OK(op->AddNewWorkers(diff));
  47. } else if (diff < 0) {
  48. RETURN_IF_NOT_OK(op->RemoveWorkers(-1 * diff));
  49. }
  50. return Status::OK();
  51. }
  52. TreeModifier::TreeModifier(TreeAdapter *adapter) : TreeModifier(adapter->tree_.get()) {}
  53. } // namespace dataset
  54. } // namespace mindspore