Skip to content
Snippets Groups Projects
Commit ce498212 authored by Hashim Sharif's avatar Hashim Sharif
Browse files

Fixing Batchnorm unit tests

parent 7f0ba9f9
No related branches found
No related tags found
No related merge requests found
......@@ -326,28 +326,46 @@ void testTensorHalfConv(){
void testTensorGroupedConv(){
void testTensorGroupConv(){
// NOTE: The input channel count value (param2 to Tensor and Filter) must be the same
void* x3 = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 2, 4, 4);
// NOTE: Filter descriptors do NOT have batch size
// NOTE: First two dims are output channels (configurable), input channels (MUST match input channels)
void* input = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 2, 4, 4);
void* filter = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 2, 1, 3, 3);
// FIXIT: fillTensor* calls should be replaced with initTensorValue(tenosor, val)
fillTensorWithOnes(input);
fillTensorWithOnes(filter);
int conv_mode = 1; // NOTE: uses CROSS_CORRELATION
int conv_groups = 2;
void* conv_out = tensorConvolution(input, filter,
0, 0,
1, 1,
conv_mode, conv_groups);
printTensorValues(conv_out);
}
void testTensorHalfGroupConv(){
// NOTE: The input channel count value (param2 to Tensor and Filter) must be the same
void* input = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 2, 4, 4);
void* filter = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 2, 1, 3, 3);
fillTensorWithOnes(x3);
fillTensorWithOnes(input);
fillTensorWithOnes(filter);
int conv_mode = 1; // NOTE: uses CROSS_CORRELATION
int conv_groups = 2;
void* conv1 = tensorConvolution(x3, filter, 2, 2,
2, 2, conv_mode, conv_groups);
printTensorValues(conv1);
void* conv_out = tensorConvolution(input, filter,
0, 0,
1, 1,
conv_mode, conv_groups);
// NOTE: For cudnnTensorAdd, the only dimension that MUST match is channels
//void* bias3 = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 1, 1);
// fillTensorWithOnes(bias3);
//tensorAdd(conv1, bias3);
//printTensorValues(conv1);
printTensorValues(conv_out);
}
......@@ -376,8 +394,35 @@ void testTensorBatchNorm(){
void* variance = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 1, 1);
fillTensorWithVal(variance, 1);
void* output = tensorBatchNorm(x, gamma, beta, mean, variance, 0.01);
double epsilon = 1;
// NOTE: result = X - mean / sqrt(epsilon + variance)
void* output = tensorBatchNorm(x, gamma, beta, mean, variance, 1);
printTensorValues(output);
}
void testTensorHalfBatchNorm(){
void* x = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 2, 2);
fillTensorWithVal(x, 3);
void* gamma = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 1, 1);
fillTensorWithVal(gamma, 1);
void* beta = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 1, 1);
fillTensorWithVal(beta, 0);
void* mean = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 1, 1);
fillTensorWithVal(mean, 1);
void* variance = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 1, 1);
fillTensorWithVal(variance, 1);
double epsilon = 1;
// NOTE: result = X - mean / sqrt(epsilon + variance)
void* output = tensorBatchNorm(x, gamma, beta, mean, variance, 1);
printTensorValues(output);
}
......@@ -1200,16 +1245,21 @@ int main(){
testTensorConv();
testTensorHalfConv();
//testTensorError();
testTensorGroupConv();
testTensorHalfGroupConv();
testTensorBatchNorm();
testTensorHalfBatchNorm();
///testTensorPooling();
///testTensorHalfPooling();
//testTensorError();
//testQuantization();
//testTensorConv();
//testTensorGroupedConv();
//testTensorBatchNorm();
//testTensorGemm();
//testTensorGemmGPU();
//testTensorGemmBias();
......@@ -1228,7 +1278,6 @@ int main(){
/********* SAMPLING TESTS ****
testSampling_3_3();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment