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.

example.h 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * \file example/example.cpp
  3. *
  4. * This file is part of MegEngine, a deep learning framework developed by
  5. * Megvii.
  6. *
  7. * \copyright Copyright (c) 2020-2021 Megvii Inc. All rights reserved.
  8. */
  9. #pragma once
  10. #include <lite_build_config.h>
  11. #include "lite/global.h"
  12. #include "lite/network.h"
  13. #include "lite/tensor.h"
  14. #include "npy.h"
  15. #include <string.h>
  16. #include <memory>
  17. #include <unordered_map>
  18. #include <vector>
  19. namespace lite {
  20. namespace example {
  21. void set_cpu_affinity(const std::vector<int>& cpuset);
  22. struct Args {
  23. int args_parse_ret = 0;
  24. std::string example_name;
  25. std::string model_path;
  26. std::string input_path;
  27. std::string output_path;
  28. std::string loader_path;
  29. static Args from_argv(int argc, char** argv);
  30. };
  31. std::shared_ptr<Tensor> parse_npy(
  32. const std::string& path,
  33. LiteBackend backend = LiteBackend::LITE_DEFAULT);
  34. using ExampleFunc = std::function<bool(const Args&)>;
  35. using ExampleFuncMap = std::unordered_map<std::string, ExampleFunc>;
  36. ExampleFuncMap* get_example_function_map();
  37. bool register_example(std::string example_name, const ExampleFunc& fuction);
  38. template <int>
  39. struct Register;
  40. #if LITE_BUILD_WITH_MGE
  41. #if LITE_WITH_CUDA
  42. bool load_from_path_run_cuda(const Args& args);
  43. #endif
  44. bool basic_load_from_path(const Args& args);
  45. bool basic_load_from_path_with_loader(const Args& args);
  46. bool basic_load_from_memory(const Args& args);
  47. bool cpu_affinity(const Args& args);
  48. bool network_share_same_weights(const Args& args);
  49. bool reset_input(const Args& args);
  50. bool reset_input_output(const Args& args);
  51. bool config_user_allocator(const Args& args);
  52. bool register_cryption_method(const Args& args);
  53. bool update_cryption_key(const Args& args);
  54. bool async_forward(const Args& args);
  55. #if LITE_WITH_CUDA
  56. bool device_input(const Args& args);
  57. bool device_input_output(const Args& args);
  58. bool pinned_host_input(const Args& args);
  59. #endif
  60. #endif
  61. } // namespace example
  62. } // namespace lite
  63. #if LITE_BUILD_WITH_MGE
  64. bool basic_c_interface(const lite::example::Args& args);
  65. bool device_io_c_interface(const lite::example::Args& args);
  66. bool async_c_interface(const lite::example::Args& args);
  67. #endif
  68. #define CONCAT_IMPL(a, b) a##b
  69. #define MACRO_CONCAT(a, b) CONCAT_IMPL(a, b)
  70. #define REGIST_EXAMPLE(name_, func_) \
  71. REGIST_EXAMPLE_WITH_NUM(__COUNTER__, name_, func_)
  72. #define REGIST_EXAMPLE_WITH_NUM(number_, name_, func_) \
  73. template <> \
  74. struct Register<number_> { \
  75. Register() { register_example(name_, func_); } \
  76. }; \
  77. namespace { \
  78. Register<number_> MACRO_CONCAT(example_function_, number_); \
  79. }
  80. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

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