Coverage Report

Created: 2017-11-12 13:27

/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_00 = 0x0000,
39
  CCV_COMPUTE_DEVICE_01 = 0x0100,
40
  CCV_COMPUTE_DEVICE_02 = 0x0200,
41
  CCV_COMPUTE_DEVICE_03 = 0x0300,
42
  CCV_COMPUTE_DEVICE_04 = 0x0400,
43
  CCV_COMPUTE_DEVICE_05 = 0x0500,
44
  CCV_COMPUTE_DEVICE_06 = 0x0600,
45
  CCV_COMPUTE_DEVICE_07 = 0x0700,
46
};
47
48
877
#define CCV_TENSOR_GET_MEMORY(type) ((type) & 0x3)
49
39
#define CCV_TENSOR_GET_DEVICE(type) ((type) & 0xff00)
50
39
#define CCV_TENSOR_GET_DEVICE_ID(type) 
(39
CCV_TENSOR_GET_DEVICE39
(type) >> 8)
51
52
enum {
53
  CCV_TENSOR_VIEW      = 0x01000000,
54
  CCV_TENSOR_MULTIVIEW = 0x02000000,
55
};
56
57
typedef union ccv_numeric_data_u {
58
  unsigned char* u8;
59
  int* i32;
60
  float* f32;
61
  int64_t* i64;
62
  double* f64;
63
  void* ptr; // Raw pointer
64
} ccv_numeric_data_t;
65
66
31.1k
#define CCV_NNC_MAX_DIM_ALLOC (8)
67
33.4G
#define CCV_NNC_MAX_DIM (2)
68
69
typedef struct {
70
  int type;
71
  int format;
72
  int datatype;
73
  int dim[CCV_NNC_MAX_DIM_ALLOC];
74
} ccv_nnc_tensor_param_t;
75
76
typedef struct {
77
  int type;
78
  int refcount;
79
  ccv_numeric_data_t data;
80
  uintptr_t alias_ref;
81
  uint64_t sig;
82
  ccv_nnc_tensor_param_t info;
83
} ccv_nnc_tensor_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
  /* tensor view and tensor shares the same data structure besides the following. */
93
  off_t off;
94
  int inc[CCV_NNC_MAX_DIM_ALLOC]; /**< "increment" or, length */
95
} ccv_nnc_tensor_view_t;
96
97
3.69k
#define CCV_IS_TENSOR_VIEW(x) ((*(int*)(x)) & CCV_TENSOR_VIEW)
98
5.16k
#define CCV_IS_TENSOR_MULTIVIEW(x) 
((*(int*)(5.16k
x153
)) & CCV_TENSOR_MULTIVIEW)
99
100
#if CCV_NNC_TENSOR_TFB
101
23
#define CCV_TENSOR_IS_DENSE_MATRIX(x) (((x) & 0xFFF) > 0) // has channel components
102
typedef struct {
103
  int type;
104
  int refcount;
105
  ccv_numeric_data_t data;
106
  uintptr_t reserved0;
107
  uint64_t sig;
108
  // This is used for toll-free bridging between ccv_dense_matrix_t and ccv_nnc_tensor_t
109
  // Note that this is bigger than it is needed, we carefully structured this
110
  // such that bit is reused as much, but still some wasted spaces.
111
  union {
112
    struct {
113
      int resides;
114
      int format;
115
      int datatype;
116
      int rows;
117
      int cols;
118
      int channels;
119
      int reserved1; /* This reserved bit need to be zero'ed such that later dim is not cared. */
120
      int step;
121
      union {
122
        unsigned char u8;
123
        int i32;
124
        float f32;
125
        int64_t i64;
126
        double f64;
127
        void* p;
128
      } tb;
129
    };
130
    ccv_nnc_tensor_param_t info;
131
  }; 
132
} ccv_dense_matrix_t;
133
#else
134
#define CCV_TENSOR_IS_DENSE_MATRIX(x) (0)
135
typedef struct {
136
  int type;
137
  int refcount;
138
  uint64_t sig;
139
  int cols;
140
  int rows;
141
  int step;
142
  union {
143
    unsigned char u8;
144
    int i32;
145
    float f32;
146
    int64_t i64;
147
    double f64;
148
    void* p;
149
  } tb;
150
  ccv_numeric_data_t data;
151
} ccv_dense_matrix_t;
152
#endif
153
154
#endif