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 19 #include "common/common_test.h" 20 #include "utils/log_adapter.h" 21 #include "pipeline/jit/resource.h" 22 #include "ir/primitive.h" 23 #include "frontend/operator/ops.h" 24 25 namespace mindspore { 26 namespace pipeline { 27 28 using MethodMap = std::unordered_map<int64_t, std::unordered_map<std::string, Any>>; 29 30 extern MethodMap& GetMethodMap(); 31 32 class TestResource : public UT::Common { 33 public: 34 TestResource() {} 35 void SetUp() {} 36 void TearDown() {} 37 }; 38 39 TEST_F(TestResource, test_built_in_type_map) { 40 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt)); 41 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt8)); 42 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt16)); 43 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt32)); 44 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeInt64)); 45 46 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat)); 47 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat16)); 48 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat32)); 49 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeFloat64)); 50 51 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeBool)); 52 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kNumberTypeUInt)); 53 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kObjectTypeTuple)); 54 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kObjectTypeList)); 55 ASSERT_TRUE(true == Resource::IsTypeInBuiltInMap(kObjectTypeTensorType)); 56 57 MethodMap& map = GetMethodMap(); 58 for (auto& iter : map) { 59 for (auto& iter_map : iter.second) { 60 Any value = iter_map.second; 61 ASSERT_TRUE(value.is<std::string>() || value.is<PrimitivePtr>()); 62 } 63 } 64 65 Any value = Resource::GetMethodPtr(kNumberTypeInt, "__add__"); 66 ASSERT_TRUE(value == Any(prim::kPrimScalarAdd)); 67 value = Resource::GetMethodPtr(kNumberTypeInt64, "__add__"); 68 ASSERT_TRUE(value == Any(prim::kPrimScalarAdd)); 69 value = Resource::GetMethodPtr(kNumberTypeFloat, "__add__"); 70 ASSERT_TRUE(value == Any(prim::kPrimScalarAdd)); 71 value = Resource::GetMethodPtr(kNumberTypeFloat64, "__add__"); 72 ASSERT_TRUE(value == Any(prim::kPrimScalarAdd)); 73 } 74 75 } // namespace pipeline 76 } // namespace mindspore 77