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

Adding detailed unit test for 3*3 filter sampling

parent c9fc9625
No related branches found
No related tags found
No related merge requests found
...@@ -627,23 +627,199 @@ void testSampling(){ ...@@ -627,23 +627,199 @@ void testSampling(){
Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 3, 3); Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 3, 3);
fillTensorWithVal(filter, 1); fillTensorWithVal(filter, 1);
float* host_ptr = (float*) ((struct Tensor*) input)->host_data; float* host_ptr = (float*) ((struct Tensor*) filter)->host_data;
//host_ptr[0] = 0; host_ptr[0] = 2;
//host_ptr[1] = 0; host_ptr[2] = 2;
//host_ptr[2] = 0; host_ptr[4] = 2;
//host_ptr[3] = 0; host_ptr[6] = 2;
//host_ptr[4] = 0; host_ptr[8] = 2;
//host_ptr[5] = 0; host_ptr[10] = 2;
host_ptr[12] = 2;
host_ptr[14] = 2;
host_ptr[16] = 2;
host_ptr[18] = 2;
host_ptr[20] = 2;
host_ptr[22] = 2;
host_ptr[24] = 2;
host_ptr[26] = 2;
//printTensorValues(input);
void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
printTensorValues(res);
void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1);
printTensorValues(res2);
void* res2_sim = tensorConvSampSim(input, filter, 0, 0, 1, 1, 1, 1, 2, 0);
printTensorValues(res2_sim);
void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0);
printTensorValues(res3);
void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0);
printTensorValues(res4);
void* res4_half = tensorConvApproxHalf2(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0);
convertToFP32((struct Tensor*) res4_half);
printTensorValues(res4_half);
}
void testSamplingCalls(void* input, void* filter,
int pad_h, int pad_w,
int stride_h, int stride_w, int skip_every){
for (int offset = 0; offset < 2; offset++){
printf("\n\n\n\**Test -- pad_h = %d pad_w = %d stride_h = %d stride_w = %d skip_every = %d offset= %d \n\n",
pad_h, pad_w, stride_h, stride_w, skip_every, offset);
void* res_sim = tensorConvSampSim(input, filter, pad_h, pad_w,
stride_h, stride_w,
1, 1, skip_every, offset);
printf ("ConvSampSim Result :");
printTensorValues(res_sim);
void* res = tensorConvApprox(input, filter, pad_h, pad_w,
stride_h, stride_w,
1, 1, 1, 1, skip_every, offset);
printf ("ConvApprox Result :");
printTensorValues(res);
void* res_half = tensorConvApproxHalf2(input, filter, pad_h, pad_w,
stride_h, stride_w,
1, 1, 1, 1, skip_every, offset);
convertToFP32((struct Tensor*) res_half);
printf ("ConvApproxHalf2 Result :");
printTensorValues(res_half);
}
printf ("\n\n\n\ --- End of Test \n\n\n");
}
/**** Tests Sample for a sample 3 * 3 Filter */
void testSampling_3_3(){
printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n");
Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 4, 4);
fillTensorWithVal(input, 1);
//fillWithOnesAndTwos(input);
Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 3, 3);
fillTensorWithVal(filter, 1);
testSamplingCalls(input, filter, 0, 0, 1, 1, 2);
testSamplingCalls(input, filter, 0, 0, 1, 1, 3);
testSamplingCalls(input, filter, 0, 0, 1, 1, 4);
testSamplingCalls(input, filter, 1, 1, 1, 1, 2);
testSamplingCalls(input, filter, 1, 1, 1, 1, 3);
testSamplingCalls(input, filter, 1, 1, 1, 1, 4);
testSamplingCalls(input, filter, 1, 1, 2, 2, 2);
testSamplingCalls(input, filter, 1, 1, 2, 2, 3);
testSamplingCalls(input, filter, 1, 1, 2, 2, 4);
/*
float* host_ptr = (float*) ((struct Tensor*) filter)->host_data;
host_ptr[0] = 2;
host_ptr[2] = 2;
host_ptr[4] = 2;
host_ptr[6] = 2;
host_ptr[8] = 2;
host_ptr[10] = 2;
host_ptr[12] = 2;
host_ptr[14] = 2;
host_ptr[16] = 2;
host_ptr[18] = 2;
host_ptr[20] = 2;
host_ptr[22] = 2;
host_ptr[24] = 2;
host_ptr[26] = 2;
//printTensorValues(input); //printTensorValues(input);
void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1); void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
printTensorValues(res); printTensorValues(res);
void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1);
printTensorValues(res2);
void* res2_sim = tensorConvSampSim(input, filter, 0, 0, 1, 1, 1, 1, 2, 0);
printTensorValues(res2_sim);
void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0);
printTensorValues(res3);
void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0);
printTensorValues(res4);
void* res4_half = tensorConvApproxHalf2(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0);
convertToFP32((struct Tensor*) res4_half);
printTensorValues(res4_half);
*/
} }
void testSampling2(){ void testSampling2(){
printf("***** TestingSampling2 ***** \n\n"); printf("***** TestingSampling2 ***** \n\n");
...@@ -708,7 +884,14 @@ void testSampling3(){ ...@@ -708,7 +884,14 @@ void testSampling3(){
printTensorValues(res3); printTensorValues(res3);
printf ("\n"); printf ("\n");
void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 3, 1);
void* res2_sim = tensorConvSampSim(input, filter, 0, 0, 1, 1, 1, 1, 3, 0);
printTensorValues(res2_sim);
printf ("\n");
void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 3, 0);
printTensorValues(res4); printTensorValues(res4);
printf ("\n"); printf ("\n");
...@@ -764,22 +947,22 @@ int main(){ ...@@ -764,22 +947,22 @@ int main(){
//testSampleFilter(); //testSampleFilter();
testPerforation(); //-- testPerforation();
// testPerforation2(); // testPerforation2();
//-- testSampling(); //testSampling();
testSampling2(); //testSampling2();
testSampling3(); //testSampling3();
testSampling_3_3();
stopProfiling(); stopProfiling();
return 0; return 0;
......
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