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

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 "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. if (!bin_map->ReadIndex(kernel::kGpuKernelMeta)) {
  32. MS_LOG(INFO) << "kernel cache miss, cache directory will be created later.";
  33. } else {
  34. MS_LOG(INFO) << "cache initialize to[" << kernel::kGpuKernelMeta << "].";
  35. }
  36. MS_EXCEPTION_IF_NULL(kernel_graph);
  37. auto kernels = kernel_graph->execution_order();
  38. for (const auto &kernel : kernels) {
  39. std::string kernel_name = session::AnfRuntimeAlgorithm::GetCNodeName(kernel);
  40. if (kernel_name == prim::kPrimTupleGetItem->name() || kernel_name == prim::kPrimMakeTuple->name() ||
  41. kernel_name == prim::kPrimDepend->name() || kernel_name == prim::kPrimStateSetItem->name()) {
  42. continue;
  43. }
  44. if (session::AnfRuntimeAlgorithm::GetKernelType(kernel) == KernelType::AUTO_DIFF_KERNEL) {
  45. auto gpu_kernel_ptr = kernel::AkgGpuKernelBuild(kernel);
  46. if (!gpu_kernel_ptr) {
  47. MS_LOG(EXCEPTION) << "Build akg kernel op[" << kernel_name << "] failed";
  48. }
  49. session::AnfRuntimeAlgorithm::SetKernelMod(gpu_kernel_ptr, kernel.get());
  50. } else {
  51. auto gpu_kernel_ptr = kernel::GpuKernelFactory::GetInstance().Create(kernel_name, kernel);
  52. if (!gpu_kernel_ptr) {
  53. MS_LOG(EXCEPTION) << "Build gpu kernel op[" << kernel_name << "] failed";
  54. }
  55. if (!gpu_kernel_ptr->Init(kernel)) {
  56. MS_LOG(EXCEPTION) << "Initialize gpu kernel op[" << kernel_name << "] failed.";
  57. }
  58. session::AnfRuntimeAlgorithm::SetKernelMod((kernel::KernelModPtr)gpu_kernel_ptr, kernel.get());
  59. }
  60. }
  61. }
  62. } // namespace gpu
  63. } // namespace device
  64. } // namespace mindspore