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.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * \file example/cpp_example/example.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. #pragma once
  12. #include <lite_build_config.h>
  13. #include "lite/global.h"
  14. #include "lite/network.h"
  15. #include "lite/tensor.h"
  16. #include "npy.h"
  17. #include <string.h>
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <vector>
  21. namespace lite {
  22. namespace example {
  23. void set_cpu_affinity(const std::vector<int>& cpuset);
  24. struct Args {
  25. int args_parse_ret = 0;
  26. std::string example_name;
  27. std::string model_path;
  28. std::string input_path;
  29. std::string output_path;
  30. std::string loader_path;
  31. static Args from_argv(int argc, char** argv);
  32. };
  33. std::shared_ptr<Tensor> parse_npy(
  34. const std::string& path, LiteBackend backend = LiteBackend::LITE_DEFAULT);
  35. using ExampleFunc = std::function<bool(const Args&)>;
  36. using ExampleFuncMap = std::unordered_map<std::string, ExampleFunc>;
  37. ExampleFuncMap* get_example_function_map();
  38. bool register_example(std::string example_name, const ExampleFunc& fuction);
  39. } // namespace example
  40. } // namespace lite
  41. #define CONCAT_IMPL(a, b) a##b
  42. #define MACRO_CONCAT(a, b) CONCAT_IMPL(a, b)
  43. #define REGIST_EXAMPLE(name_, func_) REGIST_EXAMPLE_WITH_NUM(__COUNTER__, name_, func_)
  44. #define REGIST_EXAMPLE_WITH_NUM(number_, name_, func_) \
  45. struct Register_##func_ { \
  46. Register_##func_() { lite::example::register_example(name_, func_); } \
  47. }; \
  48. namespace { \
  49. Register_##func_ MACRO_CONCAT(func_, number_); \
  50. }
  51. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}