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.

assign.cc 2.6 kB

4 years ago
4 years ago
4 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright 2019 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 "backend/kernel_compiler/rts/assign.h"
  17. #include "runtime/mem.h"
  18. #include "acl/acl_rt.h"
  19. using mindspore::ge::model_runner::MemcpyAsyncTaskInfo;
  20. using MemcpyAsyncTaskInfoPtr = std::shared_ptr<MemcpyAsyncTaskInfo>;
  21. namespace mindspore {
  22. namespace kernel {
  23. AssignKernel::AssignKernel() {}
  24. AssignKernel::~AssignKernel() {}
  25. bool AssignKernel::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> & /* workspace */,
  26. const std::vector<AddressPtr> & /*outputs*/, void *stream_ptr) {
  27. if (inputs.size() != 2) {
  28. MS_LOG(ERROR) << "inputs size is not two";
  29. return false;
  30. }
  31. MS_EXCEPTION_IF_NULL(inputs[0]);
  32. MS_EXCEPTION_IF_NULL(inputs[1]);
  33. if (inputs[0]->addr == inputs[1]->addr) {
  34. MS_LOG(INFO) << "first addr is same with second addr , no need assign";
  35. return true;
  36. }
  37. rtError_t status = aclrtMemcpyAsync(inputs[0]->addr, inputs[0]->size, inputs[1]->addr, inputs[1]->size,
  38. ACL_MEMCPY_DEVICE_TO_DEVICE, stream_ptr);
  39. if (status != RT_ERROR_NONE) {
  40. MS_LOG(ERROR) << "Assign op aclrtMemcpyAsync failed!";
  41. return false;
  42. }
  43. return true;
  44. }
  45. std::vector<TaskInfoPtr> AssignKernel::GenTask(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &,
  46. const std::vector<AddressPtr> &, uint32_t stream_id) {
  47. if (inputs.size() != 2) {
  48. MS_LOG(EXCEPTION) << "Inputs size should be 2, but got " << inputs.size();
  49. }
  50. stream_id_ = stream_id;
  51. MS_EXCEPTION_IF_NULL(inputs[0]);
  52. MS_EXCEPTION_IF_NULL(inputs[1]);
  53. std::shared_ptr<MemcpyAsyncTaskInfo> task_info_ptr =
  54. std::make_shared<MemcpyAsyncTaskInfo>(unique_name_, stream_id, inputs[0]->addr, inputs[0]->size, inputs[1]->addr,
  55. inputs[1]->size, ACL_MEMCPY_DEVICE_TO_DEVICE, false);
  56. MS_EXCEPTION_IF_NULL(task_info_ptr);
  57. return {task_info_ptr};
  58. }
  59. } // namespace kernel
  60. } // namespace mindspore