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.

dropout_vulkan.cpp 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "dropout_vulkan.h"
  15. #include <math.h>
  16. namespace ncnn {
  17. DEFINE_LAYER_CREATOR(Dropout_vulkan)
  18. Dropout_vulkan::Dropout_vulkan()
  19. {
  20. support_vulkan = true;
  21. pipeline_dropout = 0;
  22. pipeline_dropout_pack4 = 0;
  23. pipeline_dropout_pack8 = 0;
  24. }
  25. int Dropout_vulkan::create_pipeline(const Option& opt)
  26. {
  27. std::vector<vk_specialization_type> specializations(1);
  28. specializations[0].f = scale;
  29. // pack1
  30. {
  31. pipeline_dropout = new Pipeline(vkdev);
  32. pipeline_dropout->set_optimal_local_size_xyz();
  33. pipeline_dropout->create("dropout", opt, specializations, 1, 5);
  34. }
  35. // pack4
  36. {
  37. pipeline_dropout_pack4 = new Pipeline(vkdev);
  38. pipeline_dropout_pack4->set_optimal_local_size_xyz();
  39. pipeline_dropout_pack4->create("dropout_pack4", opt, specializations, 1, 5);
  40. }
  41. // pack8
  42. {
  43. pipeline_dropout_pack8 = new Pipeline(vkdev);
  44. pipeline_dropout_pack8->set_optimal_local_size_xyz();
  45. pipeline_dropout_pack8->create("dropout_pack8", opt, specializations, 1, 5);
  46. }
  47. return 0;
  48. }
  49. int Dropout_vulkan::destroy_pipeline(const Option& /*opt*/)
  50. {
  51. delete pipeline_dropout;
  52. pipeline_dropout = 0;
  53. delete pipeline_dropout_pack4;
  54. pipeline_dropout_pack4 = 0;
  55. delete pipeline_dropout_pack8;
  56. pipeline_dropout_pack8 = 0;
  57. return 0;
  58. }
  59. int Dropout_vulkan::forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& /*opt*/) const
  60. {
  61. if (scale == 1.f)
  62. {
  63. return 0;
  64. }
  65. int elempack = bottom_top_blob.elempack;
  66. std::vector<VkMat> bindings(1);
  67. bindings[0] = bottom_top_blob;
  68. std::vector<vk_constant_type> constants(5);
  69. constants[0].i = bottom_top_blob.dims;
  70. constants[1].i = bottom_top_blob.w;
  71. constants[2].i = bottom_top_blob.h;
  72. constants[3].i = bottom_top_blob.c;
  73. constants[4].i = bottom_top_blob.cstep;
  74. const Pipeline* pipeline = elempack == 8 ? pipeline_dropout_pack8
  75. : elempack == 4 ? pipeline_dropout_pack4
  76. : pipeline_dropout;
  77. cmd.record_pipeline(pipeline, bindings, constants, bottom_top_blob);
  78. return 0;
  79. }
  80. } // namespace ncnn