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.

param_pack.cpp 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * \file dnn/src/common/param_pack.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2020 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/general.h"
  12. #include "src/common/utils.h"
  13. using namespace megdnn;
  14. void ParamPackConcatSplitBase::check_exec(const TensorLayout& concated,
  15. const TensorLayout& offsets,
  16. const TensorLayout& parts) {
  17. megdnn_assert(offsets.dtype == dtype::Int32{}, "bad dtype: %s",
  18. offsets.dtype.name());
  19. megdnn_assert(concated.ndim == 1 && offsets.ndim == 1 && parts.ndim == 1 &&
  20. concated.stride[0] == 1 && offsets.stride[0] == 1 &&
  21. parts.stride[0] == 1,
  22. "bad layout: concated=%s offsets=%s parts=%s",
  23. concated.to_string().c_str(), offsets.to_string().c_str(),
  24. parts.to_string().c_str());
  25. }
  26. std::vector<dt_int32> ParamPackConcatSplitBase::gen_offsets(
  27. const TensorShapeArray& shapes, size_t alignment, size_t dtype_size) {
  28. megdnn_assert(alignment && (alignment & (alignment - 1)) == 0,
  29. "alignment must be power of 2: %zu", alignment);
  30. if (alignment < dtype_size)
  31. alignment = dtype_size;
  32. megdnn_assert(alignment % dtype_size == 0,
  33. "alignment must be multiple of dtype size: %zu vs %zu",
  34. alignment, dtype_size);
  35. alignment /= dtype_size;
  36. auto get_aligned = [alignment](size_t v) {
  37. auto mod = v & (alignment - 1);
  38. return v + ((alignment - mod) & (alignment - 1));
  39. };
  40. std::vector<dt_int32> offsets(shapes.size() << 1);
  41. size_t offset = 0;
  42. for (size_t i = 0; i < shapes.size(); i++) {
  43. offset = get_aligned(offset);
  44. offsets[i << 1] = offset;
  45. offset += shapes[i].total_nr_elems();
  46. offsets[(i << 1) + 1] = offset;
  47. }
  48. return offsets;
  49. }
  50. // vim: syntax=cpp.doxygen

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