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.

resource_test.cc 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <iostream>
  17. #include <memory>
  18. #include "common/common_test.h"
  19. #include "utils/log_adapter.h"
  20. #include "pipeline/jit/resource.h"
  21. #include "ir/primitive.h"
  22. #include "frontend/operator/ops.h"
  23. namespace mindspore {
  24. namespace pipeline {
  25. using MethodMap = std::unordered_map<int64_t, std::unordered_map<std::string, Any>>;
  26. extern MethodMap& GetMethodMap();
  27. class TestResource : public UT::Common {
  28. public:
  29. TestResource() {}
  30. void SetUp() {}
  31. void TearDown() {}
  32. };
  33. TEST_F(TestResource, test_built_in_type_map) {
  34. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt));
  35. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt8));
  36. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt16));
  37. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt32));
  38. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt64));
  39. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat));
  40. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat16));
  41. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat32));
  42. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat64));
  43. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeBool));
  44. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeUInt));
  45. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kObjectTypeTuple));
  46. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kObjectTypeList));
  47. ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kObjectTypeTensorType));
  48. MethodMap& map = GetMethodMap();
  49. for (auto& iter : map) {
  50. for (auto& iter_map : iter.second) {
  51. Any value = iter_map.second;
  52. ASSERT_TRUE(value.is<std::string>() || value.is<PrimitivePtr>());
  53. }
  54. }
  55. Any value = Resource::GetMethodPtr(kNumberTypeInt, "__add__");
  56. ASSERT_TRUE(value == Any(prim::kPrimScalarAdd));
  57. value = Resource::GetMethodPtr(kNumberTypeInt64, "__add__");
  58. ASSERT_TRUE(value == Any(prim::kPrimScalarAdd));
  59. value = Resource::GetMethodPtr(kNumberTypeFloat, "__add__");
  60. ASSERT_TRUE(value == Any(prim::kPrimScalarAdd));
  61. value = Resource::GetMethodPtr(kNumberTypeFloat64, "__add__");
  62. ASSERT_TRUE(value == Any(prim::kPrimScalarAdd));
  63. }
  64. } // namespace pipeline
  65. } // namespace mindspore