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.

external.py 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  3. #
  4. # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  5. #
  6. # Unless required by applicable law or agreed to in writing,
  7. # software distributed under the License is distributed on an
  8. # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # pylint: disable=redefined-builtin
  10. from typing import Iterable, List, Sequence
  11. from ..core._imperative_rt.core2 import apply
  12. from ..core.ops import builtin
  13. def extern_opr_subgraph(
  14. inputs, output_shapes: List[tuple], dump_name: str, dump_data: bytes, output_dtypes
  15. ):
  16. r"""Load a serialized extern opr subgraph and fake execute the operator.
  17. Args:
  18. inputs: list of input tensors.
  19. output_shapes: The output shapes.
  20. dump_name: The serialized subgraph name.
  21. dump_data: The serialized subgraph.
  22. """
  23. if not isinstance(inputs, Iterable):
  24. inputs = (inputs,)
  25. op = builtin.ExternOpr(
  26. output_shapes, dump_name, dump_data, len(dump_data), output_dtypes
  27. )
  28. return apply(op, *inputs)
  29. def tensorrt_runtime_opr(inputs, *, data: bytes = None):
  30. # empty model will give None result
  31. if data is None:
  32. return None
  33. op = builtin.TensorRTRuntime(data, len(data))
  34. # return sequence of outputs
  35. return apply(op, *inputs)
  36. def cambricon_runtime_opr(inputs, data, symbol, tensor_dim_mutable):
  37. r"""Load a serialized Cambricon model as a runtime operator in MegEngine.
  38. Args:
  39. inputs: list of input tensors.
  40. data: the serialized Cambricon model.
  41. symbol: name of the function in Cambricon model.
  42. tensor_dim_mutable: whether the input tensors' shapes are mutable
  43. in ``cnrtModel_t``.
  44. """
  45. op = builtin.CambriconRuntime(data, len(data), symbol, tensor_dim_mutable)
  46. return apply(op, *inputs)
  47. def atlas_runtime_opr(inputs, data):
  48. r"""Load a serialized Atlas model as a runtime operator in MegEngine.
  49. Args:
  50. inputs: list of input tensors.
  51. data: the serialized Atlas model.
  52. """
  53. op = builtin.AtlasRuntime(data, len(data))
  54. return apply(op, *inputs)

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