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.

gpu_event.cc 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 "runtime/device/gpu/gpu_event.h"
  17. #include "runtime/device/gpu/gpu_common.h"
  18. namespace mindspore::device::gpu {
  19. GpuEvent::GpuEvent() {
  20. auto ret = cudaEventCreate(&event_);
  21. if (ret != cudaSuccess) {
  22. MS_LOG(ERROR) << "cudaEventCreate failed, ret:" << ret;
  23. event_ = nullptr;
  24. }
  25. }
  26. GpuEvent::~GpuEvent() { CHECK_CUDA_RET_WITH_ERROR_NOTRACE(cudaEventDestroy(event_), "cudaEventDestory failed"); }
  27. void GpuEvent::WaitEvent() {
  28. MS_EXCEPTION_IF_NULL(wait_stream_);
  29. MS_EXCEPTION_IF_NULL(event_);
  30. CHECK_CUDA_RET_WITH_EXCEPT_NOTRACE(cudaStreamWaitEvent(wait_stream_, event_, 0), "cudaStreamWaitEvent failed");
  31. need_wait_ = false;
  32. }
  33. void GpuEvent::RecordEvent() {
  34. MS_EXCEPTION_IF_NULL(event_);
  35. MS_EXCEPTION_IF_NULL(record_stream_);
  36. CHECK_CUDA_RET_WITH_EXCEPT_NOTRACE(cudaEventRecord(event_, record_stream_), "cudaEventRecord failed");
  37. need_wait_ = true;
  38. }
  39. bool GpuEvent::NeedWait() { return need_wait_; }
  40. } // namespace mindspore::device::gpu