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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. }
  24. int Dropout_vulkan::create_pipeline(const Option& opt)
  25. {
  26. std::vector<vk_specialization_type> specializations(1);
  27. specializations[0].f = scale;
  28. // pack1
  29. {
  30. pipeline_dropout = new Pipeline(vkdev);
  31. pipeline_dropout->set_optimal_local_size_xyz();
  32. pipeline_dropout->create("dropout", opt, specializations, 1, 5);
  33. }
  34. // pack4
  35. {
  36. pipeline_dropout_pack4 = new Pipeline(vkdev);
  37. pipeline_dropout_pack4->set_optimal_local_size_xyz();
  38. pipeline_dropout_pack4->create("dropout_pack4", opt, specializations, 1, 5);
  39. }
  40. return 0;
  41. }
  42. int Dropout_vulkan::destroy_pipeline(const Option& opt)
  43. {
  44. delete pipeline_dropout;
  45. pipeline_dropout = 0;
  46. delete pipeline_dropout_pack4;
  47. pipeline_dropout_pack4 = 0;
  48. return 0;
  49. }
  50. int Dropout_vulkan::forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const
  51. {
  52. if (scale == 1.f)
  53. {
  54. return 0;
  55. }
  56. int elempack = bottom_top_blob.elempack;
  57. std::vector<VkMat> bindings(1);
  58. bindings[0] = bottom_top_blob;
  59. std::vector<vk_constant_type> constants(5);
  60. constants[0].i = bottom_top_blob.dims;
  61. constants[1].i = bottom_top_blob.w;
  62. constants[2].i = bottom_top_blob.h;
  63. constants[3].i = bottom_top_blob.c;
  64. constants[4].i = bottom_top_blob.cstep;
  65. const Pipeline* pipeline = elempack == 4 ? pipeline_dropout_pack4 : pipeline_dropout;
  66. cmd.record_pipeline(pipeline, bindings, constants, bottom_top_blob);
  67. return 0;
  68. }
  69. } // namespace ncnn