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.

utility.cpp 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * \file imperative/src/impl/ops/utility.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 "megbrain/imperative/ops/autogen.h"
  12. #include "megbrain/imperative/ops/utility.h"
  13. #include "megbrain/imperative/ops/opr_attr.h"
  14. #include "megbrain/opr/utility.h"
  15. #include "../op_trait.h"
  16. namespace mgb::imperative {
  17. MGB_DYN_TYPE_OBJ_FINAL_IMPL(GenericPyOp);
  18. OP_TRAIT_REG(GenericPyOp, GenericPyOp).fallback();
  19. namespace { namespace fastpathcopy {
  20. auto apply_on_var_node(
  21. const OpDef& def,
  22. const VarNodeArray& inputs) {
  23. return inputs;
  24. }
  25. OP_TRAIT_REG(FastpathCopy,FastpathCopy)
  26. .apply_on_var_node(apply_on_var_node)
  27. .fallback();
  28. }} // fastpathcopy
  29. namespace { namespace identity {
  30. auto apply_on_var_node(
  31. const OpDef& def,
  32. const VarNodeArray& inputs) {
  33. auto&& op = def.cast_final_safe<Identity>();
  34. mgb_assert(inputs.size() == 1);
  35. OperatorNodeConfig config{op.make_name()};
  36. return opr::Identity::make(inputs[0], config);
  37. }
  38. auto apply_on_physical_tensor(
  39. const OpDef& def,
  40. const SmallVector<TensorPtr>& inputs) {
  41. return SmallVector<TensorPtr>{inputs[0]};
  42. }
  43. OP_TRAIT_REG(Identity, Identity)
  44. .apply_on_var_node(apply_on_var_node)
  45. .apply_on_physical_tensor(apply_on_physical_tensor)
  46. .fallback();
  47. }} // identity
  48. } // namespace mgb::imperative

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