Coverage Report

Created: 2019-07-03 22:50

/home/liu/buildslave/linux-x64-runtests/build/lib/nnc/ccv_nnc_tfb.h
Line
Count
Source
1
/**********************************************************
2
 * C-based/Cached/Core Computer Vision Library
3
 * Liu Liu, 2010-02-01
4
 **********************************************************/
5
6
/**********************************************************
7
 * CCV - Neural Network Collection
8
 **********************************************************/
9
10
/**
11
 * This header is included into main ccv.h
12
 * such that enables toll-free bridging between
13
 * ccv_nnc_tensor_t and ccv_dense_matrix_t
14
 * In effect, ccv_dense_matrix_t will be a specialized
15
 * version of ccv_nnc_tensor_t. We are taking some penalties
16
 * from this change though, namely, the size of ccv_dense_matrix_t
17
 * will be bigger now.
18
 */
19
20
#ifndef GUARD_ccv_nnc_tfb_h
21
#define GUARD_ccv_nnc_tfb_h
22
23
#include <unistd.h>
24
#include <stdint.h>
25
26
enum {
27
  CCV_TENSOR_FORMAT_NCHW = 0x01,
28
  CCV_TENSOR_FORMAT_NHWC = 0x02,
29
  CCV_TENSOR_FORMAT_CHWN = 0x04,
30
};
31
32
enum {
33
  CCV_TENSOR_CPU_MEMORY = 0x1,
34
  CCV_TENSOR_GPU_MEMORY = 0x2,
35
};
36
37
enum {
38
  CCV_COMPUTE_DEVICE_000 = 0x00000,
39
  CCV_COMPUTE_DEVICE_001 = 0x00100,
40
  CCV_COMPUTE_DEVICE_002 = 0x00200,
41
  CCV_COMPUTE_DEVICE_003 = 0x00300,
42
  CCV_COMPUTE_DEVICE_004 = 0x00400,
43
  CCV_COMPUTE_DEVICE_005 = 0x00500,
44
  CCV_COMPUTE_DEVICE_006 = 0x00600,
45
  CCV_COMPUTE_DEVICE_007 = 0x00700,
46
  CCV_COMPUTE_DEVICE_ANY = 0xfff00, // The optimal allocation will be found by the algorithm.
47
};
48
49
5.96M
#define CCV_TENSOR_GET_MEMORY(type) ((type) & 0x3)
50
65.9k
#define CCV_TENSOR_GET_DEVICE(type) ((
type144
) & 0xfff00)
51
24.4k
#define CCV_TENSOR_GET_DEVICE_ID(type) (CCV_TENSOR_GET_DEVICE(type) >> 8)
52
2.89k
#define CCV_TENSOR_SET_DEVICE_ID(type, device_id) (type) = (((type) & ~0xfff00) | (((device_id) & 0xfff) << 8))
53
54
enum {
55
  CCV_TENSOR_VIEW       = 0x01000000,
56
  CCV_TENSOR_MULTIVIEW  = 0x02000000,
57
  CCV_TENSOR_PINNED_MEM = 0x04000000, // tensor is pinned in CUDA. This matches CCV_PINNED_MEM.
58
};
59
60
typedef struct {
61
  short v;
62
} ccv_float16_t; // In this way, you cannot perform any operations on float16.
63
64
typedef union ccv_numeric_data_u {
65
  unsigned char* u8;
66
  int* i32;
67
  ccv_float16_t* f16;
68
  float* f32;
69
  int64_t* i64;
70
  uint64_t* u64;
71
  double* f64;
72
  void* ptr; // Raw pointer
73
} ccv_numeric_data_t;
74
75
71.1M
#define CCV_NNC_MAX_DIM_ALLOC (8)
76
6.16G
#define CCV_NNC_MAX_DIM (2)
77
78
typedef struct {
79
  int type;
80
  int format;
81
  int datatype;
82
  int dim[CCV_NNC_MAX_DIM_ALLOC];
83
} ccv_nnc_tensor_param_t;
84
85
typedef struct {
86
  int type;
87
  int refcount;
88
  ccv_numeric_data_t data;
89
  uintptr_t alias_ref;
90
  uint64_t sig;
91
  ccv_nnc_tensor_param_t info;
92
} ccv_nnc_tensor_t;
93
94
typedef struct {
95
  int type;
96
  int refcount;
97
  ccv_numeric_data_t data;
98
  uintptr_t alias_ref;
99
  uint64_t sig;
100
  ccv_nnc_tensor_param_t info;
101
  /* tensor view and tensor shares the same data structure besides the following. */
102
  off_t off;
103
  int inc[CCV_NNC_MAX_DIM_ALLOC]; /**< "increment" or, length */
104
} ccv_nnc_tensor_view_t;
105
106
573k
#define CCV_IS_TENSOR_VIEW(x) ((*(int*)(x)) & CCV_TENSOR_VIEW)
107
161k
#define CCV_IS_TENSOR_MULTIVIEW(x) ((*(int*)(
x464
)) & CCV_TENSOR_MULTIVIEW)
108
109
#if CCV_NNC_TENSOR_TFB
110
137
#define CCV_TENSOR_IS_DENSE_MATRIX(x) (((x) & 0xFFF) > 0) // has channel components
111
typedef struct {
112
  int type;
113
  int refcount;
114
  ccv_numeric_data_t data;
115
  uintptr_t reserved0;
116
  uint64_t sig;
117
  // This is used for toll-free bridging between ccv_dense_matrix_t and ccv_nnc_tensor_t
118
  // Note that this is bigger than it is needed, we carefully structured this
119
  // such that bit is reused as much, but still some wasted spaces.
120
  union {
121
    struct {
122
      int resides;
123
      int format;
124
      int datatype;
125
      int rows;
126
      int cols;
127
      int channels;
128
      int reserved1; /* This reserved bit need to be zero'ed such that later dim is not cared. */
129
      int step;
130
      union {
131
        unsigned char u8;
132
        int i32;
133
        ccv_float16_t f16;
134
        float f32;
135
        int64_t i64;
136
        double f64;
137
        void* p;
138
      } tb;
139
    };
140
    ccv_nnc_tensor_param_t info;
141
  }; 
142
} ccv_dense_matrix_t;
143
#else
144
#define CCV_TENSOR_IS_DENSE_MATRIX(x) (0)
145
typedef struct {
146
  int type;
147
  int refcount;
148
  uint64_t sig;
149
  int cols;
150
  int rows;
151
  int step;
152
  union {
153
    unsigned char u8;
154
    int i32;
155
    ccv_float16_t f16;
156
    float f32;
157
    int64_t i64;
158
    double f64;
159
    void* p;
160
  } tb;
161
  ccv_numeric_data_t data;
162
} ccv_dense_matrix_t;
163
#endif
164
165
#endif