1# Copyright 2019 Huawei Technologies Co., Ltd 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 15from hccl_test.manage.api import Hccl 16 17from mindspore import Tensor 18from mindspore.parallel._tensor import _load_tensor 19 20 21def test_load_tensor(): 22 hccl = Hccl() 23 tensor = Tensor([[1, 2, 3], [4, 5, 6]]) 24 dev_mat = [2, 3] 25 tensor_map = [1, -1] 26 hccl.rank_id = 5 27 tensor_slice = _load_tensor(tensor, dev_mat, tensor_map) 28 expected_tensor = Tensor([[4, 5, 6]]) 29 if expected_tensor.__str__() != tensor_slice.__str__(): 30 raise AssertionError 31 32 hccl.rank_id = 2 33 tensor_slice = _load_tensor(tensor, dev_mat, tensor_map) 34 expected_tensor = Tensor([[1, 2, 3]]) 35 if expected_tensor.__str__() != tensor_slice.__str__(): 36 raise AssertionError 37 38 # set back to the defalt value 39 hccl.rank_id = 0 40 41 42if __name__ == '__main__': 43 test_load_tensor() 44