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 1.7 kB

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