TEST(Merge, Cl_LongTest) { // test length int length = 1<<8; std::vector<cl_long> std1_source(length); std::vector<cl_long> std2_source(length); std::vector<cl_long> std_res(length*2); std::vector<cl_long> bolt_res(length*2); // populate source vector with random ints for (int j = 0; j < length; j++) { std1_source[j] = (cl_long)rand(); std2_source[j] = (cl_long)rand(); } // perform sort std::sort(std1_source.begin(), std1_source.end()); std::sort(std2_source.begin(), std2_source.end()); std::merge(std1_source.begin(), std1_source.end(), std2_source.begin(), std2_source.end(), std_res.begin()); bolt::cl::merge(std1_source.begin(), std1_source.end(), std2_source.begin(), std2_source.end(), bolt_res.begin()); // GoogleTest Comparison cmpArrays(std_res, bolt_res); }
void printCmpLenResult(int n, int expN, T *a, T *b) { if (n != expN) { printf(" expected %d elements, got %d\n", expN, n); } printf(" %s \n", (n == -1 || n != expN) ? "FAIL COUNT" : cmpArrays(n, a, b) ? "FAIL VALUE" : "passed"); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Transform tests /////////////////////////////////////////////////////////////////////////////////////////////////////////////// TEST(simple1,counting) { bolt::amp::counting_iterator<int> iter(0); bolt::amp::counting_iterator<int> iter2=iter+1024; std::vector<int> input1(1024); std::vector<int> input2(1024); std::vector<int> stdOutput(1024); std::vector<int> boltOutput(1024); for(int i=0 ; i< 1024;i++) { input1[i] = i; } input2 = input1; std::transform( input1.begin(), input1.end(), input2.begin(), stdOutput.begin(), bolt::amp::plus<int>()); bolt::amp::transform(iter,iter2,input1.begin(),boltOutput.begin(),bolt::amp::plus<int>()); cmpArrays( stdOutput, boltOutput, 1024 ); }
TEST_P( ScanDoubleVector, InclusiveInplace ) { // Calling the actual functions under test std::vector< double >::iterator stdEnd = std::partial_sum( stdInput.begin( ), stdInput.end( ), stdInput.begin( ) ); std::vector< double >::iterator boltEnd = bolt::amp::inclusive_scan( boltInput.begin( ), boltInput.end( ), boltInput.begin( ) ); // The returned iterator should be one past the EXPECT_EQ( stdInput.end( ), stdEnd ); EXPECT_EQ( boltInput.end( ), boltEnd ); std::vector< double >::iterator::difference_type stdNumElements = std::distance( stdInput.begin( ), stdEnd ); std::vector< double >::iterator::difference_type boltNumElements = std::distance( boltInput.begin( ), boltEnd ); // Both collections should have the same number of elements EXPECT_EQ( stdNumElements, boltNumElements ); // Loop through the array and compare all the values with each other cmpArrays( stdInput, boltInput ); }
TEST(simple1,Serial_counting) { bolt::amp::counting_iterator<int> iter(0); bolt::amp::counting_iterator<int> iter2=iter+1024; std::vector<int> input1(1024); std::vector<int> input2(1024); std::vector<int> stdOutput(1024); std::vector<int> boltOutput(1024); for(int i=0 ; i< 1024;i++) { input1[i] = i; } input2 = input1; bolt::amp::control ctl = bolt::amp::control::getDefault( ); ctl.setForceRunMode(bolt::amp::control::SerialCpu); std::transform( input1.begin(), input1.end(), input2.begin(), stdOutput.begin(), bolt::amp::plus<int>()); bolt::amp::transform(ctl, iter,iter2,input1.begin(),boltOutput.begin(),bolt::amp::plus<int>()); cmpArrays( stdOutput, boltOutput, 1024 ); }
int areEqual(Stack u1,Stack u2){ if(!(areSizesEqual(u1,u2) && areNumElementsEqual(u1,u2))) return 0; return (0 == cmpArrays(u1,u2)); };
TEST( Merge, IntTest) { #if LARGE_SIZE int length = 1<<21; #else int length = 1024; #endif std::vector<int> hVectorA( length ), hVectorB( length + 10 ), hVectorO( length * 2 + 10); for(int i=0; i < length ; i++) { hVectorA[i] = i * 2; hVectorB[i] = (i *2)-1; } for(int i=length; i < length+10 ; i++) { hVectorB[i] = (i *2)-1; } std::fill( hVectorO.begin(), hVectorO.end(), 0 ); bolt::cl::less<int> pl; std::vector<int> dVectorA( hVectorA.begin(), hVectorA.end() ), dVectorB( hVectorB.begin(), hVectorB.end() ), dVectorO( hVectorO.begin(), hVectorO.end() ); /* bolt::cl::device_vector<int> dVectorA( hVectorA.begin(), hVectorA.end() ), dVectorB( hVectorB.begin(), hVectorB.end() ), dVectorO( hVectorO.begin(), hVectorO.end() ); */ std::merge( hVectorA.begin(), hVectorA.end(), hVectorB.begin(), hVectorB.end(), hVectorO.begin(), std::less<int>() ); bolt::cl::control ctl; ctl.setForceRunMode(bolt::cl::control::OpenCL); bolt::cl::merge( ctl,dVectorA.begin(), dVectorA.end(), dVectorB.begin(), dVectorB.end(), dVectorO.begin(), pl ); cmpArrays(hVectorO, dVectorO); ctl.setForceRunMode(bolt::cl::control::MultiCoreCpu); bolt::cl::merge( ctl,dVectorA.begin(), dVectorA.end(), dVectorB.begin(), dVectorB.end(), dVectorO.begin(), pl ); cmpArrays(hVectorO, dVectorO); ctl.setForceRunMode(bolt::cl::control::SerialCpu); bolt::cl::merge( ctl,dVectorA.begin(), dVectorA.end(), dVectorB.begin(), dVectorB.end(), dVectorO.begin(), pl ); cmpArrays(hVectorO, dVectorO); }
void printCmpResult(int n, T *a, T *b) { printf(" %s \n", cmpArrays(n, a, b) ? "FAIL VALUE" : "passed"); }
static void testSort(sortFun sortfun, char *funName) { // test #1 printf("Testing %s algorithm, integers array #1... ", funName); int array1a[] = {1, 12, 8, 4, -2}; int array1b[] = {1, 12, 8, 4, -2}; size_t length1 = 5; qsort(array1a, length1, sizeof(int), cmpInt); sortfun(array1b, length1, sizeof(int), cmpInt); assert(cmpArrays(array1a, array1b, length1, cmpInt)); printf("test passed \n"); // test #2 printf("Testing %s algorithm, integers array #2... ", funName); int array2a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int array2b[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; size_t length2 = 10; qsort(array2a, length2, sizeof(int), cmpInt); sortfun(array2b, length2, sizeof(int), cmpInt); assert(cmpArrays(array2a, array2b, length2, cmpInt)); printf("test passed \n"); // test #3 printf("Testing %s algorithm, integers array #3... ", funName); int array3a[] = {-1, -10, -13, 2, 0, 0, -5, 0}; int array3b[] = {-1, -10, -13, 2, 0, 0, -5, 0}; size_t length3 = 8; qsort(array3a, length3, sizeof(int), cmpInt); sortfun(array3b, length3, sizeof(int), cmpInt); assert(cmpArrays(array3a, array3b, length3, cmpInt)); printf("test passed \n"); // test #4 printf("Testing %s algorithm, integers array #4... ", funName); int array4a[] = {1}; int array4b[] = {1}; size_t length4 = 1; qsort(array4a, length4, sizeof(int), cmpInt); sortfun(array4b, length4, sizeof(int), cmpInt); assert(cmpArrays(array4a, array4b, length4, cmpInt)); printf("test passed \n"); // test #5 printf("Testing %s algorithm, integers array #5... ", funName); int array5a[] = {}; int array5b[] = {}; size_t length5 = 0; qsort(array5a, length5, sizeof(int), cmpInt); sortfun(array5b, length5, sizeof(int), cmpInt); assert(cmpArrays(array5a, array5b, length5, cmpInt)); printf("test passed \n"); // test #6 printf("Testing %s algorithm, double array #1... ", funName); double array6a[] = {-19.8474, 273.3433, -0.00, 2.3333, -12.3233, -0.00, 2.3333}; double array6b[] = {-19.8474, 273.3433, -0.00, 2.3333, -12.3233, -0.00, 2.3333}; size_t length6 = 7; qsort(array6a, length6, sizeof(double), cmpDouble); sortfun(array6b, length6, sizeof(double), cmpDouble); assert(cmpArrays(array6a, array6b, length6, cmpDouble)); printf("test passed \n"); // test #7 printf("Testing %s algorithm, char array #1... ", funName); double array7a[] = {'v', 't', 'a', 'b', 'c', 'T', 'W', 'E', 'g', 'G'}; double array7b[] = {'v', 't', 'a', 'b', 'c', 'T', 'W', 'E', 'g', 'G'}; size_t length7 = 10; qsort(array7a, length7, sizeof(char), cmpChar); sortfun(array7b, length7, sizeof(char), cmpChar); assert(cmpArrays(array7a, array7b, length7, cmpChar)); printf("test passed \n"); }