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 #include "include/backend/visible.h"
24
25 namespace mindspore {
26 namespace device {
27 BACKEND_EXPORT void HalfToFloat(void *dst, const void *src, size_t elem_num);
28 BACKEND_EXPORT void FloatToHalf(void *dst, const void *src, size_t elem_num);
29 BACKEND_EXPORT void DoubleToFloat(void *dst, const void *src, size_t elem_num);
30 BACKEND_EXPORT void FloatToDouble(void *dst, const void *src, size_t elem_num);
31 void ShortToInt(void *dst, const void *src, size_t elem_num);
32 void IntToShort(void *dst, const void *src, size_t elem_num);
33 void LongToInt(void *dst, const void *src, size_t elem_num);
34 void IntToLong(void *dst, const void *src, size_t elem_num);
35 BACKEND_EXPORT void ConvertSameType(void *const dst, const void *src, size_t size, TypeId type);
36
37 template <typename T>
ConvertSameType(T * dst,const T * src,size_t elem_num)38 void ConvertSameType(T *dst, const T *src, size_t elem_num) {
39 if (dst == nullptr || src == nullptr) {
40 return;
41 }
42 for (size_t i = 0; i < elem_num; ++i) {
43 dst[i] = src[i];
44 }
45 }
46 } // namespace device
47 } // namespace mindspore
48
49 #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_CONVERT_TENSOR_UTILS_H_
50