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

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