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

Adding unit test calls for sampling tests

parent a331f82f
No related branches found
No related tags found
No related merge requests found
...@@ -806,7 +806,7 @@ void testPerforationCalls(void* input, void* filter, ...@@ -806,7 +806,7 @@ void testPerforationCalls(void* input, void* filter,
/**** Tests Perforation for a set of different inputs */ /**** Tests Perforation for a set of different inputs */
void testPerforation(){ void testPerforation(UnitTestResults& unitTestResults){
printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n"); printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n");
...@@ -926,7 +926,7 @@ void testSampling(){ ...@@ -926,7 +926,7 @@ void testSampling(){
void testSamplingCalls(void* input, void* filter, void testSamplingCalls(void* input, void* filter,
int pad_h, int pad_w, int pad_h, int pad_w,
int stride_h, int stride_w, int stride_h, int stride_w,
int skip_every){ int skip_every, UnitTestResults& unitTestResults){
float interpolation_rate = 1.0; float interpolation_rate = 1.0;
...@@ -988,6 +988,19 @@ void testSamplingCalls(void* input, void* filter, ...@@ -988,6 +988,19 @@ void testSamplingCalls(void* input, void* filter,
printf ("\nConvApproxHalf2 Result :"); printf ("\nConvApproxHalf2 Result :");
printTensorValues(res_half); printTensorValues(res_half);
std::string suffix = std::string(" pad_h = ") + std::to_string(pad_h)
+ std::string(" pad_w = ") + std::to_string(pad_w)
+ std::string(" stride_h = ") + std::to_string(stride_h)
+ std::string(" stride_w = ") + std::to_string(stride_w)
+ std::string(" skip_every = ") + std::to_string(skip_every)
+ std::string(" offset = ") + std::to_string(offset);
std::string test_name = std::string("SAMP_FP32 ") + suffix;
unitTestResults.compareTensors((Tensor*) res, (Tensor*) res_sim, 0.01, test_name);
std::string fp16_test_name = std::string("SAMP_FP16 ") + suffix;
unitTestResults.compareTensors((Tensor*) res_half, (Tensor*) res_sim, 0.0001, fp16_test_name);
} }
...@@ -997,7 +1010,7 @@ void testSamplingCalls(void* input, void* filter, ...@@ -997,7 +1010,7 @@ void testSamplingCalls(void* input, void* filter,
/**** Tests Sample for a sample 3 * 3 Filter */ /**** Tests Sample for a sample 3 * 3 Filter */
void testSampling_3_3(){ void testSampling_3_3(UnitTestResults& unitTestResults){
printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n"); printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n");
...@@ -1026,28 +1039,26 @@ void testSampling_3_3(){ ...@@ -1026,28 +1039,26 @@ void testSampling_3_3(){
host_ptr[26] = 2; host_ptr[26] = 2;
// Tests with padding = 0 stride = 1
testSamplingCalls(input, filter, 0, 0, 1, 1, 2, unitTestResults);
testSamplingCalls(input, filter, 0, 0, 1, 1, 2); testSamplingCalls(input, filter, 0, 0, 1, 1, 3, unitTestResults);
testSamplingCalls(input, filter, 0, 0, 1, 1, 3);
testSamplingCalls(input, filter, 0, 0, 1, 1, 4);
testSamplingCalls(input, filter, 0, 0, 1, 1, 4, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 1, 1, 2); // Tests with padding = 1 stride = 1
testSamplingCalls(input, filter, 1, 1, 1, 1, 2, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 1, 1, 3); testSamplingCalls(input, filter, 1, 1, 1, 1, 3, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 1, 1, 4); testSamplingCalls(input, filter, 1, 1, 1, 1, 4, unitTestResults);
// Tests with padding = 1 stride = 2
testSamplingCalls(input, filter, 1, 1, 2, 2, 2, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 2, 2, 3, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 2, 2, 2); testSamplingCalls(input, filter, 1, 1, 2, 2, 4, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 2, 2, 3);
testSamplingCalls(input, filter, 1, 1, 2, 2, 4);
} }
...@@ -1058,105 +1069,8 @@ void testSampling_3_3(){ ...@@ -1058,105 +1069,8 @@ void testSampling_3_3(){
void testSampling2(){
printf("***** TestingSampling2 ***** \n\n");
Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 4, 2, 2);
fillTensorWithVal(input, 2);
//fillWithOnesAndTwos(input);
Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 4, 4, 1, 1);
fillTensorWithVal(filter, 2);
// Interpolation not being applied most likely
void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0);
printTensorValues(res);
fillTensorWithVal(filter, 2);
// Start from offset 1 completely failing
void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0);
printTensorValues(res2);
fillTensorWithVal(filter, 2);
// NOTE -- even after reinitializing --- error remains - this is indicative of input corruption
// Results are strange. Are filters being overwritten?
void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
printTensorValues(res3);
}
void testSampling3(){
printf("***** TestingSampling3 ***** \n\n");
Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 9, 2, 2);
fillTensorWithVal(input, 2);
//fillWithOnesAndTwos(input);
Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 4, 9, 1, 1);
fillTensorWithVal(filter, 2);
// BASELINE : expected result -- 36, 36, 36, ...
void* res1 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
printTensorValues(res1);
printf ("\n");
// BASELINE: expected result - 32, 32, 32,
void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0);
printTensorValues(res2);
printf ("\n");
void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 3, 0);
printTensorValues(res3);
printf ("\n");
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);
printf ("\n");
void* res5 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0);
printTensorValues(res5);
printf ("\n");
void* res6 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 1);
printTensorValues(res6);
printf ("\n");
}
/**** Tests Sample for a sample 1 * 1 Filter */ /**** Tests Sample for a sample 1 * 1 Filter */
void testSampling_1_1(){ void testSampling_1_1(UnitTestResults& unitTestResults){
Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 9, 2, 2); Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 9, 2, 2);
...@@ -1167,19 +1081,20 @@ void testSampling_1_1(){ ...@@ -1167,19 +1081,20 @@ void testSampling_1_1(){
fillTensorWithVal(filter, 2); fillTensorWithVal(filter, 2);
testSamplingCalls(input, filter, 0, 0, 1, 1, 2); // Tests with padding = 0 stride = 1
testSamplingCalls(input, filter, 0, 0, 1, 1, 2, unitTestResults);
testSamplingCalls(input, filter, 0, 0, 1, 1, 3); testSamplingCalls(input, filter, 0, 0, 1, 1, 3, unitTestResults);
testSamplingCalls(input, filter, 0, 0, 1, 1, 4); testSamplingCalls(input, filter, 0, 0, 1, 1, 4, unitTestResults);
// Tests with padding = 1 stride = 1
testSamplingCalls(input, filter, 1, 1, 1, 1, 2, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 1, 1, 2); testSamplingCalls(input, filter, 1, 1, 1, 1, 3, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 1, 1, 3); testSamplingCalls(input, filter, 1, 1, 1, 1, 4, unitTestResults);
testSamplingCalls(input, filter, 1, 1, 1, 1, 4);
} }
...@@ -1314,13 +1229,14 @@ int main(){ ...@@ -1314,13 +1229,14 @@ int main(){
testTensorPooling(); testTensorPooling();
testTensorHalfPooling(); testTensorHalfPooling();
testSampling_3_3();
testSampling_1_1();
testPerforation();
*/ */
testSampling_3_3(unitTestResults);
testSampling_1_1(unitTestResults);
testPerforation(unitTestResults);
unitTestResults.printSummary(); unitTestResults.printSummary();
......
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