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.

add_update.cpp 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * \file dnn/src/common/add_update.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "megdnn/oprs.h"
  12. #include "src/common/add_update_helper.h"
  13. #include "src/common/utils.h"
  14. namespace megdnn {
  15. void AddUpdateForward::check_exec(const TensorLayout& dst,
  16. const TensorLayout& delta) {
  17. // delta can not be broadcasted to dst if dst.total_nr_elems() <
  18. // delta.total_nr_elems()
  19. megdnn_assert(dst.dtype == delta.dtype &&
  20. dst.total_nr_elems() >= delta.total_nr_elems() &&
  21. dst.is_non_overlapping_strong());
  22. if (dst.dtype.category() == DTypeCategory::INT) {
  23. auto check_fv = [](float fv) {
  24. int iv = fv;
  25. megdnn_assert(
  26. float(iv) == fv && float(iv + 1) == fv + 1.f &&
  27. float(iv - 1) == fv - 1.f,
  28. "bad arg value in AddUpdate: dtype is int, but value is %g "
  29. "which can not be precisely converted to int",
  30. fv);
  31. };
  32. check_fv(m_param.alpha);
  33. check_fv(m_param.beta);
  34. check_fv(m_param.bias);
  35. }
  36. }
  37. ElemwiseOpParamN<2> AddUpdateForwardHelper::make_param(
  38. _megdnn_tensor_inout dst, _megdnn_tensor_in delta) {
  39. ElemwiseOpParamN<2> src;
  40. src[0] = dst;
  41. src[1] = delta;
  42. src[1].layout = src[1].layout.broadcast(dst.layout);
  43. src.init_from_given_tensor();
  44. return src;
  45. }
  46. } // namespace megdnn
  47. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台