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.

sigmoid_vulkan.cpp 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "sigmoid_vulkan.h"
  15. #include <math.h>
  16. namespace ncnn {
  17. DEFINE_LAYER_CREATOR(Sigmoid_vulkan)
  18. Sigmoid_vulkan::Sigmoid_vulkan()
  19. {
  20. support_vulkan = true;
  21. pipeline_sigmoid = 0;
  22. pipeline_sigmoid_pack4 = 0;
  23. }
  24. int Sigmoid_vulkan::create_pipeline(const Option& opt)
  25. {
  26. std::vector<vk_specialization_type> specializations;
  27. // pack1
  28. {
  29. pipeline_sigmoid = new Pipeline(vkdev);
  30. pipeline_sigmoid->set_optimal_local_size_xyz();
  31. pipeline_sigmoid->create("sigmoid", opt, specializations, 1, 5);
  32. }
  33. // pack4
  34. {
  35. pipeline_sigmoid_pack4 = new Pipeline(vkdev);
  36. pipeline_sigmoid_pack4->set_optimal_local_size_xyz();
  37. pipeline_sigmoid_pack4->create("sigmoid_pack4", opt, specializations, 1, 5);
  38. }
  39. return 0;
  40. }
  41. int Sigmoid_vulkan::destroy_pipeline(const Option& opt)
  42. {
  43. delete pipeline_sigmoid;
  44. pipeline_sigmoid = 0;
  45. delete pipeline_sigmoid_pack4;
  46. pipeline_sigmoid_pack4 = 0;
  47. return 0;
  48. }
  49. int Sigmoid_vulkan::forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const
  50. {
  51. int packing = bottom_top_blob.packing;
  52. std::vector<VkMat> bindings(1);
  53. bindings[0] = bottom_top_blob;
  54. std::vector<vk_constant_type> constants(5);
  55. constants[0].i = bottom_top_blob.dims;
  56. constants[1].i = bottom_top_blob.w;
  57. constants[2].i = bottom_top_blob.h;
  58. constants[3].i = bottom_top_blob.c;
  59. constants[4].i = bottom_top_blob.cstep;
  60. const Pipeline* pipeline = packing == 4 ? pipeline_sigmoid_pack4 : pipeline_sigmoid;
  61. cmd.record_pipeline(pipeline, bindings, constants, bottom_top_blob);
  62. return 0;
  63. }
  64. } // namespace ncnn