target.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright 2019-2020 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #pragma once
  16. #include <hlir/quantizer.h>
  17. #include <hlir/transforms/pass.h>
  18. #include <llir/transforms/pass.h>
  19. #include <memory>
  20. #include <scheduler/memory_allocator.h>
  21. #include <unordered_map>
  22. #include <unordered_set>
  23. #include <vector>
  24. namespace nncase
  25. {
  26. struct target_options
  27. {
  28. std::string input_type;
  29. std::string inference_type;
  30. float weights_quantize_threshold;
  31. uint32_t output_quantize_threshold;
  32. bool quantize_binary;
  33. };
  34. class target
  35. {
  36. public:
  37. target(const target_options &options)
  38. : options_(options) {}
  39. virtual ~target() = default;
  40. const target_options &options() const noexcept { return options_; }
  41. virtual void fill_allocators(std::unordered_map<memory_type_t, scheduler::memory_allocator *> &allocators, std::vector<std::unique_ptr<scheduler::memory_allocator>> &allocator_holders) = 0;
  42. virtual void registry_codegen_ops() = 0;
  43. virtual void registry_evaluator_ops() = 0;
  44. virtual void optimize_target_independent(hlir::transforms::pass_manager &pass_mgr) = 0;
  45. virtual void optimize_target_dependent(hlir::transforms::pass_manager &pass_mgr) = 0;
  46. virtual void add_quantization_checkpoints(hlir::transforms::pass_manager &pass_mgr) = 0;
  47. virtual void optimize_quantize(hlir::quantizer &quantizer, hlir::transforms::pass_manager &pass_mgr) = 0;
  48. virtual void add_quantization_broadcast(std::unordered_set<hlir::node_opcode> &opcodes) = 0;
  49. virtual void optimize_llir(llir::transforms::pass_manager &pass_mgr) = 0;
  50. protected:
  51. target_options options_;
  52. };
  53. }