• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019-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 
17 #ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_CONVERT_TENSOR_UTILS_H_
18 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_CONVERT_TENSOR_UTILS_H_
19 
20 #include <iostream>
21 #include <vector>
22 #include "ir/tensor.h"
23 
24 namespace mindspore {
25 namespace device {
26 void HalfToFloat(void *dst, const void *src, size_t elem_num);
27 void FloatToHalf(void *dst, const void *src, size_t elem_num);
28 void DoubleToFloat(void *dst, const void *src, size_t elem_num);
29 void FloatToDouble(void *dst, const void *src, size_t elem_num);
30 void ShortToInt(void *dst, const void *src, size_t elem_num);
31 void IntToShort(void *dst, const void *src, size_t elem_num);
32 void LongToInt(void *dst, const void *src, size_t elem_num);
33 void IntToLong(void *dst, const void *src, size_t elem_num);
34 void ConvertSameType(void *const dst, const void *src, size_t size, TypeId type);
35 
36 template <typename T>
ConvertSameType(T * dst,const T * src,size_t elem_num)37 void ConvertSameType(T *dst, const T *src, size_t elem_num) {
38   if (dst == nullptr || src == nullptr) {
39     return;
40   }
41   for (size_t i = 0; i < elem_num; ++i) {
42     dst[i] = src[i];
43   }
44 }
45 }  // namespace device
46 }  // namespace mindspore
47 
48 #endif  // MINDSPORE_CCSRC_RUNTIME_DEVICE_CONVERT_TENSOR_UTILS_H_
49