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.5 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 <memory>
  18. #include "runtime/mem.h"
  19. using 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. if (inputs[0]->addr == inputs[1]->addr) {
  32. MS_LOG(INFO) << "first addr is same with second addr , no need assign";
  33. return true;
  34. }
  35. rtError_t status = rtMemcpyAsync(inputs[0]->addr, inputs[0]->size, inputs[1]->addr, inputs[1]->size,
  36. RT_MEMCPY_DEVICE_TO_DEVICE, stream_ptr);
  37. if (status != RT_ERROR_NONE) {
  38. MS_LOG(ERROR) << "Assign op rtMemcpyAsync failed!";
  39. return false;
  40. }
  41. return true;
  42. }
  43. std::vector<TaskInfoPtr> AssignKernel::GenTask(const std::vector<AddressPtr> &inputs,
  44. const std::vector<AddressPtr> &workspace,
  45. const std::vector<AddressPtr> &outputs, uint32_t stream_id) {
  46. if (inputs.size() != 2) {
  47. MS_LOG(EXCEPTION) << "inputs size is not two";
  48. }
  49. stream_id_ = stream_id;
  50. std::shared_ptr<MemcpyAsyncTaskInfo> task_info_ptr =
  51. std::make_shared<MemcpyAsyncTaskInfo>(kernel_name_, stream_id, inputs[0]->addr, inputs[0]->size, inputs[1]->addr,
  52. inputs[1]->size, RT_MEMCPY_DEVICE_TO_DEVICE, false);
  53. MS_EXCEPTION_IF_NULL(task_info_ptr);
  54. return {task_info_ptr};
  55. }
  56. } // namespace kernel
  57. } // namespace mindspore