Skip to content

Commit 6f0edd1

Browse files
Conv1d layer and test-bench formatting changes
1 parent bbfe3bd commit 6f0edd1

23 files changed

+390
-302
lines changed

c_reference/include/conv1d.h

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
* @brief Model parameters for the 1D Convolution Layer
9-
* @var W pointer to convolution weights W, size for regular = out_channels*in_channels*kernel_size, size for depth based = out_channels*kernel_size
9+
* @var W pointer to convolution weights W, size for regular = out_channels * in_channels * kernel_size, size for depth based = out_channels * kernel_size
1010
* @var B pointer to the bias vector for the convolution, size = out_channels
1111
*/
1212
typedef struct ConvLayers_Params {
@@ -25,7 +25,6 @@ typedef struct ConvLayers_Params {
2525
* @param[in] padding padding applied to the input before the conv is performed.
2626
* Note: padding is applied to both the starting and ending of the input, along the time axis
2727
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(time step in_time).
28-
*
2928
* @param[in] kernel_size kernel size of the conv filter
3029
* @param[in] params weights, bias and other essential parameters used to describe the layer
3130
* @param[in] activations an integer to choose the type of activation function.
@@ -34,7 +33,7 @@ typedef struct ConvLayers_Params {
3433
* 2: tanh
3534
* 3: relu
3635
*/
37-
int conv1d(float *output_signal, unsigned out_time, unsigned out_channels, const float *input_signal,
36+
int conv1d(float* output_signal, unsigned out_time, unsigned out_channels, const float* input_signal,
3837
unsigned in_time, unsigned in_channels, unsigned padding, unsigned kernel_size,
3938
const void* params, int activations);
4039

@@ -48,7 +47,6 @@ int conv1d(float *output_signal, unsigned out_time, unsigned out_channels, const
4847
* @param[in] padding padding applied to the input before the conv is performed.
4948
* Note: padding is applied to both the starting and ending of the input, along the time axis
5049
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(time step in_time).
51-
*
5250
* @param[in] kernel_size kernel size of the conv filter
5351
* @param[in] params weights, bias and other essential parameters used to describe the layer
5452
* @param[in] activations an integer to choose the type of activation function.
@@ -57,11 +55,10 @@ int conv1d(float *output_signal, unsigned out_time, unsigned out_channels, const
5755
* 2: tanh
5856
* 3: relu
5957
*/
60-
int conv1d_depth(float *output_signal, unsigned out_time, const float *input_signal,
58+
int conv1d_depth(float* output_signal, unsigned out_time, const float* input_signal,
6159
unsigned in_time, unsigned in_channels, unsigned padding, unsigned kernel_size,
6260
const void* params, int activations);
6361

64-
6562
/**
6663
* @brief Model parameters for the 1D Low Rank Convolution Layer
6764
* @var W1 pointer to the 1st low-rank component of the weights, size = out_channels * rank
@@ -88,7 +85,6 @@ typedef struct ConvLayers_LR_Params {
8885
* @param[in] padding padding applied to the input before the conv is performed.
8986
* Note: padding is applied to both the starting and ending of the input, along the time axis
9087
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(time step in_time).
91-
*
9288
* @param[in] kernel_size kernel size of the conv filter
9389
* @param[in] params weights, bias and other essential parameters used to describe the layer
9490
* @param[in] activations an integer to choose the type of activation function.
@@ -97,7 +93,7 @@ typedef struct ConvLayers_LR_Params {
9793
* 2: tanh
9894
* 3: relu
9995
*/
100-
int conv1d_lr(float *output_signal, unsigned out_time, unsigned out_channels, const float *input_signal,
96+
int conv1d_lr(float* output_signal, unsigned out_time, unsigned out_channels, const float* input_signal,
10197
unsigned in_time, unsigned in_channels, unsigned padding, unsigned kernel_size,
10298
const void* params, int activations);
10399

@@ -112,7 +108,6 @@ int conv1d_lr(float *output_signal, unsigned out_time, unsigned out_channels, co
112108
* @param[in] padding padding applied to the input before the conv is performed.
113109
* Note: padding is applied to both the starting and ending of the input, along the time axis
114110
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(time step in_time).
115-
*
116111
* @param[in] kernel_size kernel size of the conv filter
117112
* @param[in] params weights, bias and other essential parameters used to describe the layer
118113
* @param[in] activations an integer to choose the type of activation function.
@@ -121,7 +116,7 @@ int conv1d_lr(float *output_signal, unsigned out_time, unsigned out_channels, co
121116
* 2: tanh
122117
* 3: relu
123118
*/
124-
int conv1d_depth_lr(float *output_signal, unsigned out_time, const float *input_signal,
119+
int conv1d_depth_lr(float* output_signal, unsigned out_time, const float* input_signal,
125120
unsigned in_time, unsigned in_channels, unsigned padding, unsigned kernel_size,
126121
const void* params, int activations);
127122

@@ -136,15 +131,15 @@ int conv1d_depth_lr(float *output_signal, unsigned out_time, const float *input_
136131
* @param[in] padding padding applied to the input before the conv is performed.
137132
* Note: padding is applied to both the starting and ending of the input, along the time axis
138133
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(time step in_time).
139-
*
140134
* @param[in] kernel_size kernel size of the pool filter
141135
* @param[in] activations an integer to choose the type of activation function.
142136
* 0: none
143137
* 1: sigmoid
144138
* 2: tanh
145139
* 3: relu
146140
*/
147-
int avgpool1d(float *output_signal, unsigned out_time, const float *input_signal, unsigned in_time, unsigned in_channels,
141+
int avgpool1d(float* output_signal, unsigned out_time, const float* input_signal,
142+
unsigned in_time, unsigned in_channels,
148143
unsigned padding, unsigned kernel_size, int activations);
149144

150145
/**
@@ -156,14 +151,14 @@ int avgpool1d(float *output_signal, unsigned out_time, const float *input_signal
156151
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels
157152
* @param[in] var pointer to the variance for the batch normalization, size = in_channels
158153
* @param[in] affine whether the affine operations are applied
159-
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels
160-
* @param[in] beta pointer to the scalar offsets for the post-norm affine operation, size = in_channels
154+
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels. Provide Null/0 if affine is False(non-zero)
155+
* @param[in] beta pointer to the offsets for the post-norm affine operation, size = in_channels. Provide Null/0 if affine is False(non-zero)
161156
* @param[in] in_place in-place computation of the batchnorm i.e. the output is stored in-place of the input signal. Storage efficient
162157
* @param[in] eps a very small +ve value to avoid division by 0. For the default value, assign = 0.00001
163-
*
164-
* NOTE: if affine is equated to False(0), then null-pointers(or 0) can be passed for the gamma and beta arguments
165158
*/
166-
int batchnorm1d(float* output_signal, float* input_signal, unsigned in_time, unsigned in_channels,
167-
float* mean, float* var, unsigned affine, float* gamma , float * beta, unsigned in_place, float eps);
159+
int batchnorm1d(float* output_signal, float* input_signal,
160+
unsigned in_time, unsigned in_channels,
161+
float* mean, float* var, unsigned affine, float* gamma , float* beta,
162+
unsigned in_place, float eps);
168163

169164
#endif

c_reference/include/dscnn.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
/**
88
* @brief Model definition for the 1D Convolution block applied before the RNN
99
* @brief sub-layers : batchnorm1d -> conv1d_lr
10-
*
1110
* @param[out] output_signal pointer to the final output signal, minimum size = out_time * in_channels. out_time has to be calculated based on the reduction from all the conv and pool layers
1211
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
1312
* @param[in] in_time number of time steps in the input_signal
1413
* @param[in] in_channels number of input channels
15-
1614
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels
1715
* @param[in] var pointer to the variance for the batch normalization, size = in_channels
1816
* @param[in] affine whether the affine operations are applied
1917
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels
2018
* @param[in] beta pointer to the offsets for the post-norm affine operation, size = in_channels
2119
* @param[in] in_place in-place computation check for the batchnorm. Storage efficient
22-
*
2320
* @param[in] cnn_hidden hidden state/out_channels dimensions for the low-rank CNN. The final channel size of this block
2421
* @param[in] cnn_padding padding for the low-rank CNN layer. Note: applied to both sides of the input
2522
* @param[in] cnn_kernel_size kernel size of the low-rank CNN
@@ -30,27 +27,25 @@
3027
* 2: tanh
3128
* 3: relu
3229
*/
33-
int phon_pred_lr_cnn(float* output_signal, float* input_signal, unsigned in_time, unsigned in_channels,
30+
int phon_pred_lr_cnn(float* output_signal, float* input_signal,
31+
unsigned in_time, unsigned in_channels,
3432
float* mean, float* var, unsigned affine, float* gamma, float* beta, unsigned in_place,
3533
unsigned cnn_hidden, unsigned cnn_padding, unsigned cnn_kernel_size,
3634
const void* cnn_params, int cnn_activations);
3735

3836
/**
3937
* @brief Model definition for the 1D Convolution block applied after the RNN
4038
* @brief sub-layers : custom nonlinearity(semi_sigmoid_tanh) -> batchnorm1d -> conv1d_depth -> conv1d_lr -> avgpool1d
41-
*
4239
* @param[out] output_signal pointer to the final output signal, minimum size = out_time * in_channels. out_time has to be calculated based on the reduction from all the conv and pool layers
4340
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
4441
* @param[in] in_time number of time steps in the input
4542
* @param[in] in_channels number of input channels
46-
4743
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels
4844
* @param[in] var pointer to the variance for the batch normalization, size = in_channels
4945
* @param[in] affine whether the affine operations are applied
5046
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels
5147
* @param[in] beta pointer to the offsets for the post-norm affine operation, size = in_channels
5248
* @param[in] in_place in-place computation of the batchnorm. Storage efficient
53-
*
5449
* @param[in] depth_cnn_hidden hidden state/out_channels dimensions for the depth CNN
5550
* @param[in] depth_cnn_padding padding for the depth CNN layer. Note: applied to both sides of the input to the depth CNN
5651
* @param[in] depth_cnn_kernel_size kernel size of the depth CNN
@@ -60,7 +55,6 @@ int phon_pred_lr_cnn(float* output_signal, float* input_signal, unsigned in_time
6055
* 1: sigmoid
6156
* 2: tanh
6257
* 3: relu
63-
*
6458
* @param[in] point_cnn_hidden hidden state/out_channels dimensions for the point CNN. The final channel size of this block
6559
* @param[in] point_cnn_padding padding for the point CNN layer. Note: applied to both sides of the input to the point CNN
6660
* @param[in] point_cnn_kernel_size kernel size of the point CNN
@@ -70,7 +64,6 @@ int phon_pred_lr_cnn(float* output_signal, float* input_signal, unsigned in_time
7064
* 1: sigmoid
7165
* 2: tanh
7266
* 3: relu
73-
*
7467
* @param[in] pool_padding padding for the pool layer. Note: applied to both sides of the input to the pool
7568
* @param[in] pool_kernel_size kernel size of the pool
7669
* @param[in] pool_activations an integer to choose the type of activation function.
@@ -79,7 +72,8 @@ int phon_pred_lr_cnn(float* output_signal, float* input_signal, unsigned in_time
7972
* 2: tanh
8073
* 3: relu
8174
*/
82-
int phon_pred_depth_point_lr_cnn(float* output_signal, float* input_signal, unsigned in_time, unsigned in_channels,
75+
int phon_pred_depth_point_lr_cnn(float* output_signal, float* input_signal,
76+
unsigned in_time, unsigned in_channels,
8377
float* mean, float* var, unsigned affine, float* gamma, float* beta, unsigned in_place,
8478
unsigned depth_cnn_hidden, unsigned depth_cnn_padding, unsigned depth_cnn_kernel_size,
8579
const void* depth_cnn_params, int depth_cnn_activations,

c_reference/include/rnn_bricked.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#define __RNN_BRICKED_H__
66

77
// Function Pointer for the RNN to be passed as a parameter
8-
typedef int (*rnn_t)(float* const, unsigned, const float* const, unsigned, unsigned, const void*, void*, int, int);
8+
typedef int (*rnn_t)(float* const, unsigned, const float* const, unsigned,
9+
unsigned, const void*, void*, int, int);
910

1011
// NOTES for bi-direction
1112
// If bi_direction = 1, then actual rnn_output_dims is twice the rnn_hidden(rnn_hidden is output dims for each cell).
@@ -33,42 +34,42 @@ typedef int (*rnn_t)(float* const, unsigned, const float* const, unsigned, unsig
3334
// These constraints can be ignored while performing uni-directional passes. However, it is favorable to follow constraints 1 and 2
3435

3536

36-
/** Forward Bricking and application of the forward rnn for an input signal
37+
/** Forward Bricking and application of the forward RNN for an input signal
3738
* @param[out] output_signal pointer to output signal. size = out_time * rnn_hidden
3839
* @param[in] rnn_hidden output dimension for the current cell
3940
* @param[in] input_signal pointer to input signal. size = in_time * in_dims
4041
* @param[in] in_time number of input time steps.
4142
* @param[in] in_dims input dimensions
4243
* @param[in] window window length for each brick. For the final brick, the left over time steps are used(need not be window in length for the last brick)
4344
* @param[in] hop hop distance for between bricks
44-
* @param[in] rnn function pointer to the rnn
45-
* @param[in] params pointer to the parameters for the rnn
46-
* @param[in,out] buffers pointer to buffer for the rnn
47-
* @param[in] bi_direction determine if the ouput if for a bi-directional rnn.
45+
* @param[in] rnn function pointer to the RNN
46+
* @param[in] params pointer to the parameters for the RNN
47+
* @param[in,out] buffers pointer to buffer for the RNN
48+
* @param[in] bi_direction determine if the ouput if for a bi-directional RNN.
4849
* @param[in] sample_first_brick determine if the 1st brick should also be sampled
49-
* -> if = 0, only the last hidden state of each brick is sampled. out_time = (in_time-window)/hop + 1
50-
* -> if = 1, for the 1st brick, we sample every hop index(similar to ::hop). For all the bricks(including the 1st) we sample the final hiddens state. out_time = in_time/hop + 1
50+
* -> if = 0, only the last hidden state of each brick is sampled. out_time = (in_time-window)/hop + 1
51+
* -> if = 1, for the 1st brick, we sample every hop index(similar to ::hop). For all the bricks(including the 1st) we sample the final hiddens state. out_time = in_time/hop + 1
5152
*/
5253
int forward_bricked_rnn(float* output_signal, unsigned rnn_hidden, float* input_signal,
5354
unsigned in_time, unsigned in_dims, unsigned window, unsigned hop,
5455
rnn_t rnn, const void* params, void* buffers,
5556
int bi_direction, int sample_first_brick, int normalize);
5657

57-
/** Backward Bricking and application of the backward rnn for an input signal
58+
/** Backward Bricking and application of the backward RNN for an input signal
5859
* @param[out] output_signal pointer to output signal. size = out_time * rnn_hidden
5960
* @param[in] rnn_hidden output dimension for the current cell
6061
* @param[in] input_signal pointer to input signal. size = in_time * in_dims
6162
* @param[in] in_time number of input time steps.
6263
* @param[in] in_dims input dimensions
6364
* @param[in] window window length for each brick. For the final brick, the left over time steps are used(need not be window in length for the last brick)
6465
* @param[in] hop hop distance for between bricks
65-
* @param[in] rnn function pointer to the rnn
66-
* @param[in] params pointer to the parameters for the rnn
67-
* @param[in,out] buffers pointer to buffer for the rnn
68-
* @param[in] bi_direction determine if the ouput if for a bi-directional rnn.
69-
* @param[in] sample_last_brick determine if the last brick should also be sampled
70-
* -> if = 0, only the first(last in reverse) hidden state of each brick is sampled. out_time = (in_time-window)/hop + 1
71-
* -> if = 1, for the last brick, we sample every hop index in reverse(similar to ::hop in reverse). For all the bricks(including the last) we sample the first hiddens state(last in reverse). out_time = in_time/hop + 1
66+
* @param[in] rnn function pointer to the RNN
67+
* @param[in] params pointer to the parameters for the RNN
68+
* @param[in,out] buffers pointer to buffer for the RNN
69+
* @param[in] bi_direction determine if the ouput if for a bi-directional RNN.
70+
* @param[in] sample_last_brick determine if the last brick should also be sampled
71+
* -> if = 0, only the first(last in reverse) hidden state of each brick is sampled. out_time = (in_time-window)/hop + 1
72+
* -> if = 1, for the last brick, we sample every hop index in reverse(similar to ::hop in reverse). For all the bricks(including the last) we sample the first hiddens state(last in reverse). out_time = in_time/hop + 1
7273
*/
7374
int backward_bricked_rnn(float* output_signal, unsigned rnn_hidden, float* input_signal,
7475
unsigned in_time, unsigned in_dims, unsigned window, unsigned hop,

0 commit comments

Comments
 (0)