forked from horovod/horovod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tensor_util.h
65 lines (54 loc) · 2.03 KB
/
tensor_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
#ifndef HOROVOD_MXNET_TENSOR_UTIL_H
#define HOROVOD_MXNET_TENSOR_UTIL_H
#include <cassert>
#include <mxnet/base.h>
#include <mxnet/ndarray.h>
#include "../common/common.h"
#include "cuda_util.h"
#include "util.h"
namespace horovod {
namespace mxnet {
using namespace horovod::common;
using namespace ::mxnet;
class TensorUtil {
public:
static const DataType GetDType(NDArray* tensor);
static const TensorShape GetShape(NDArray* tensor);
static const void* GetData(NDArray* tensor);
static int64_t GetSize(NDArray* tensor);
static int GetDevice(NDArray* tensor);
static NDArray* New(int device, int dtype);
static void Free(NDArray* tensor);
static void ResizeNd(NDArray* tensor, int nDimension, int64_t* size);
static void Copy(NDArray* output, NDArray* tensor);
static void DivideTensorInPlace(NDArray* tensor, int value);
#if HAVE_CUDA
static void CopyCPUToCuda(NDArray* cpu, NDArray* cuda);
static void AsyncCopyCudaToCPU(NDArray* cuda, NDArray* cpu);
#endif
private:
static const size_t kFloat32Size = 4;
static const size_t kFloat64Size = 8;
static const size_t kFloat16Size = 2;
static const size_t kUInt8Size = 1;
static const size_t kInt32Size = 4;
static const size_t kInt8Size = 1;
static const size_t kInt64Size = 8;
};
} // namespace mxnet
} // namespace horovod
#endif // HOROVOD_MXNET_TENSOR_UTIL_H