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_kernel_build.cc 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "device/gpu/gpu_kernel_build.h"
  17. #include <string>
  18. #include "kernel/kernel.h"
  19. #include "kernel/akg/akgkernelbuild.h"
  20. #include "kernel/akg/gpu/akg_gpu_kernel_build.h"
  21. #include "kernel/gpu/gpu_kernel_factory.h"
  22. #include "operator/ops.h"
  23. #include "pybind11/stl.h"
  24. #include "session/anf_runtime_algorithm.h"
  25. namespace mindspore {
  26. namespace device {
  27. namespace gpu {
  28. namespace py = pybind11;
  29. void GpuBuild(const KernelGraphPtr &kernel_graph) {
  30. kernel::KernelMeta *bin_map = kernel::KernelMeta::GetInstance();
  31. bin_map->Initialize();
  32. MS_EXCEPTION_IF_NULL(kernel_graph);
  33. auto kernels = kernel_graph->execution_order();
  34. for (const auto &kernel : kernels) {
  35. std::string kernel_name = session::AnfRuntimeAlgorithm::GetCNodeName(kernel);
  36. if (kernel_name == prim::kPrimTupleGetItem->name() || kernel_name == prim::kPrimMakeTuple->name() ||
  37. kernel_name == prim::kPrimDepend->name() || kernel_name == prim::kPrimStateSetItem->name()) {
  38. continue;
  39. }
  40. if (session::AnfRuntimeAlgorithm::GetKernelType(kernel) == KernelType::AUTO_DIFF_KERNEL) {
  41. auto gpu_kernel_ptr = kernel::AkgGpuKernelBuild(kernel);
  42. if (!gpu_kernel_ptr) {
  43. MS_LOG(EXCEPTION) << "Build akg kernel op[" << kernel_name << "] failed";
  44. }
  45. session::AnfRuntimeAlgorithm::SetKernelMod(gpu_kernel_ptr, kernel.get());
  46. } else {
  47. auto gpu_kernel_ptr = kernel::GpuKernelFactory::GetInstance().Create(kernel_name, kernel);
  48. if (!gpu_kernel_ptr) {
  49. MS_LOG(EXCEPTION) << "Build gpu kernel op[" << kernel_name << "] failed";
  50. }
  51. if (!gpu_kernel_ptr->Init(kernel)) {
  52. MS_LOG(EXCEPTION) << "Initialize gpu kernel op[" << kernel_name << "] failed.";
  53. }
  54. session::AnfRuntimeAlgorithm::SetKernelMod((kernel::KernelModPtr)gpu_kernel_ptr, kernel.get());
  55. }
  56. }
  57. }
  58. } // namespace gpu
  59. } // namespace device
  60. } // namespace mindspore