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.

tanh_vulkan.cpp 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #include "tanh_vulkan.h"
  15. #include <math.h>
  16. namespace ncnn {
  17. DEFINE_LAYER_CREATOR(TanH_vulkan)
  18. TanH_vulkan::TanH_vulkan()
  19. {
  20. support_vulkan = true;
  21. pipeline_tanh = 0;
  22. pipeline_tanh_pack4 = 0;
  23. pipeline_tanh_pack8 = 0;
  24. }
  25. int TanH_vulkan::create_pipeline(const Option& opt)
  26. {
  27. std::vector<vk_specialization_type> specializations;
  28. // pack1
  29. {
  30. pipeline_tanh = new Pipeline(vkdev);
  31. pipeline_tanh->set_optimal_local_size_xyz();
  32. pipeline_tanh->create("tanh", opt, specializations, 1, 5);
  33. }
  34. // pack4
  35. {
  36. pipeline_tanh_pack4 = new Pipeline(vkdev);
  37. pipeline_tanh_pack4->set_optimal_local_size_xyz();
  38. pipeline_tanh_pack4->create("tanh_pack4", opt, specializations, 1, 5);
  39. }
  40. // pack8
  41. {
  42. pipeline_tanh_pack8 = new Pipeline(vkdev);
  43. pipeline_tanh_pack8->set_optimal_local_size_xyz();
  44. pipeline_tanh_pack8->create("tanh_pack8", opt, specializations, 1, 5);
  45. }
  46. return 0;
  47. }
  48. int TanH_vulkan::destroy_pipeline(const Option& /*opt*/)
  49. {
  50. delete pipeline_tanh;
  51. pipeline_tanh = 0;
  52. delete pipeline_tanh_pack4;
  53. pipeline_tanh_pack4 = 0;
  54. delete pipeline_tanh_pack8;
  55. pipeline_tanh_pack8 = 0;
  56. return 0;
  57. }
  58. int TanH_vulkan::forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& /*opt*/) const
  59. {
  60. int elempack = bottom_top_blob.elempack;
  61. std::vector<VkMat> bindings(1);
  62. bindings[0] = bottom_top_blob;
  63. std::vector<vk_constant_type> constants(5);
  64. constants[0].i = bottom_top_blob.dims;
  65. constants[1].i = bottom_top_blob.w;
  66. constants[2].i = bottom_top_blob.h;
  67. constants[3].i = bottom_top_blob.c;
  68. constants[4].i = bottom_top_blob.cstep;
  69. const Pipeline* pipeline = elempack == 8 ? pipeline_tanh_pack8
  70. : elempack == 4 ? pipeline_tanh_pack4
  71. : pipeline_tanh;
  72. cmd.record_pipeline(pipeline, bindings, constants, bottom_top_blob);
  73. return 0;
  74. }
  75. } // namespace ncnn