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.

cpu_kernel.h 3.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef MINDSPORE_CCSRC_DEVICE_CPU_CPU_KERNEL_H_
  17. #define MINDSPORE_CCSRC_DEVICE_CPU_CPU_KERNEL_H_
  18. #include <string>
  19. #include <vector>
  20. #include <memory>
  21. #include <numeric>
  22. #include <functional>
  23. #include "kernel/kernel.h"
  24. #include "ir/anf.h"
  25. #include "session/anf_runtime_algorithm.h"
  26. using mindspore::kernel::Address;
  27. using mindspore::kernel::AddressPtr;
  28. namespace mindspore {
  29. namespace device {
  30. namespace cpu {
  31. const char KSIZE[] = "ksize";
  32. const char STRIDE[] = "stride";
  33. const char STRIDES[] = "strides";
  34. const char DILATION[] = "dilation";
  35. const char PAD[] = "pad";
  36. const char PAD_MODE[] = "pad_mode";
  37. const char PADDING[] = "padding";
  38. const char PAD_MODE_LOWER_SAME[] = "same";
  39. const char PAD_MODE_LOWER_VALID[] = "valid";
  40. const char PAD_MODE_UPPER_SAME[] = "SAME";
  41. const char PAD_MODE_UPPER_VALID[] = "VALID";
  42. const char TRANSPOSE_A[] = "transpose_a";
  43. const char TRANSPOSE_B[] = "transpose_b";
  44. const char IS_GRAD[] = "is_grad";
  45. const char TRANSPOSE_NO = 'N';
  46. const char TRANSPOSE_YES = 'T';
  47. const char AXIS[] = "axis";
  48. class CPUKernel : public kernel::KernelMod {
  49. public:
  50. CPUKernel() = default;
  51. ~CPUKernel() override = default;
  52. void Init(const CNodePtr &kernel_node);
  53. virtual void InitKernel(const CNodePtr &kernel_node) = 0;
  54. bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
  55. const std::vector<AddressPtr> &outputs, uintptr_t /*stream_ptr*/) override {
  56. return Launch(inputs, workspace, outputs);
  57. };
  58. virtual bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
  59. const std::vector<AddressPtr> &outputs) = 0;
  60. const std::vector<size_t> &GetInputSizeList() const override { return input_size_list_; }
  61. const std::vector<size_t> &GetOutputSizeList() const override { return output_size_list_; }
  62. const std::vector<size_t> &GetWorkspaceSizeList() const override { return workspace_size_list_; }
  63. protected:
  64. virtual void InitInputOutputSize(const CNodePtr &kernel_node);
  65. std::vector<size_t> input_size_list_;
  66. std::vector<size_t> output_size_list_;
  67. std::vector<size_t> workspace_size_list_;
  68. };
  69. } // namespace cpu
  70. } // namespace device
  71. } // namespace mindspore
  72. #endif // MINDSPORE_CCSRC_DEVICE_CPU_CPU_KERNEL_H_