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.

common.h 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * \file dnn/include/megdnn/common.h
  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 "megbrain_build_config.h"
  13. #include "megdnn/oprs/base.h"
  14. #if MGB_ENABLE_GETENV
  15. #define MGB_GETENV ::std::getenv
  16. #else
  17. #define MGB_GETENV(_name) static_cast<char*>(nullptr)
  18. #endif
  19. #ifdef WIN32
  20. #define unsetenv(_name) _putenv_s(_name, "");
  21. #define setenv(name, value, overwrite) _putenv_s(name, value)
  22. #endif
  23. namespace megdnn {
  24. /*!
  25. * \brief whether there is an algorithm from algo_pack() that is available for
  26. * current size
  27. */
  28. template <class Opr, typename... Args>
  29. bool has_available_algo(Opr* opr, Args&&... args) {
  30. auto&& all_algos = opr->get_all_algorithms_info(std::forward<Args>(args)...);
  31. return !all_algos.empty();
  32. }
  33. template <class Opr, typename... Args>
  34. bool has_no_naive_heuristic_algo(Opr* opr, Args&&... args) {
  35. auto&& algo = opr->get_algorithm_info_heuristic(std::forward<Args>(args)...);
  36. return !static_cast<bool>(algo.attribute & detail::Algorithm::Attribute::NAIVE);
  37. }
  38. } // namespace megdnn
  39. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}