示例#1
0
TEST( testforward, DISABLED_imagesize2_nopadzeros_skip1 ) {
    int batchSize = 2;
    int numInPlanes = 1; int imageSize = 4;
    int numOutPlanes = 2; int filterWidth = 2;
    int padZeros = 0;
    int skip = 1;
    float data[] = { 0, 1, 3, 0, 
                    4, 0, 0, 0, 
                      0.5f, 0, 0.5f,0, 
                      0,    0, 0,   0, 

                        13, 0, 17,0, 
                        0, 0, 0, 0, 
                       -19, 0, 2.3f,0, 
                        0, 0, 0, 0, 
};
    float filter1[] = { 0, 0,
                        -0.5f, 0.5f,

                        0.2f, 0.3f, 
                         0.7f, -1.1f,
 };
    int outputSize = ( imageSize - filterWidth ) / ( skip + 1 ) + 1;
    cout << "outputimagesize: " << outputSize << endl;
    int outputNumElements = outputSize * numOutPlanes * batchSize;
    cout << "outputsize: " << outputNumElements << endl;
    float expectedOutput[] = {
        -2,  0,
        0, 0,

         2.8f, 0.6f,
         1.0f, 0.1f,

         0, 0,
         0,0,

         13*0.2f,17*0.2f,
         -19*0.2f, -2.3f*1.1f


    };
    cout << "expected number of output: " << outputNumElements << endl;
//    int outputSize = 0;
    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
    for( int i = 1; i <= 1; i++ ) {
        Forward *forward = Forward::instanceSpecific( 0, cl,
            LayerDimensions( numInPlanes, imageSize, numOutPlanes, filterWidth,
            padZeros == 1, false ).setSkip(1) );
        float *output = new float[forward->getOutputTotalSize(batchSize)];
        forward->forward( batchSize, data, filter1, 0, output );  
        for( int result = 0; result < outputNumElements; result++ ) {
            cout << "checking result " << result << endl;
            EXPECT_EQ( expectedOutput[result], output[result] );
        }
        delete forward;
        delete[] output;
    }
    delete cl;
}
示例#2
0
TEST( testforward, test3 ) {
    int batchSize = 4;
    int numInPlanes = 2;
    int numOutPlanes = 2;
    int inImageSize = 1;
//    int outImageSize = 1;
    int filterSize = 1;
    int padZeros = 0;
    float data[] = {0.1f,0.2f,
                    0.3f,0.4f,
                    0.5f,0.6f,
                    0.7f,0.8f};
    float filter[] = {0.2f,0.3f,
                     0.5f,0.7f};

//    int outputSize = 0;
    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
    Forward *forward = Forward::instanceTest( cl, LayerDimensions( numInPlanes, inImageSize, numOutPlanes, filterSize,
        padZeros == 1, false ) );
    float *output = new float[forward->getOutputTotalSize(batchSize)];
    forward->forward( 
        batchSize, data, filter, 0, output );        

    float expectedOutput[] = {0.2f*0.1f+0.3f*0.2f,
                               0.5f*0.1f+0.7f*0.2f,

                               0.2f*0.3f+0.3f*0.4f,
                               0.5f*0.3f+0.7f*0.4f,

                                0.2f*0.5f+0.3f*0.6f,
                               0.5f*0.5f+0.7f*0.6f,
 
                              0.2f*0.7f+0.3f*0.8f,
                               0.5f*0.7f+0.7f*0.8f
  };
   for( int i = 0; i < 8; i++ ) {
//      cout << " checking result " << i << endl;
//        cout << "output[" << i << "]=" << output[i] << endl;
      EXPECT_FLOAT_NEAR( expectedOutput[i], output[i] );
   }
    delete[] output;
    delete forward;
    delete cl;
}
示例#3
0
TEST( testforward, imagesize2_nopadzeros ) {
    int batchSize = 2;
    int numInPlanes = 1; int imageSize = 2;
    int numOutPlanes = 2; int filterWidth = 2;
    int padZeros = 0;
    float data[] = { 0, 0, 
                      0.5f, 0.5f,

                        13, 17,
                       -19, 2.3f,
};
    float filter1[] = { 0, 0,
                        -0.5f, 0.5f,

                        0.2f, 0.3f, 
                         0.7f, -1.1f,
 };
    int resultSize = 4;
    float expectedOutput[] = {
        -0.5f * 0.5f + 0.5f * 0.5f,
        0.7f * 0.5f -1.1f * 0.5f,
        (-0.5f) * (-19) + 0.5f * 2.3f,
        0.2f*13 + 0.3f* 17 + 0.7f *(-19) -1.1f * 2.3f 
    };
    cout << "expected number of output: " << resultSize << endl;
//    int outputSize = 0;
    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
    for( int i = 1; i <= 4; i++ ) {
        Forward *forward = Forward::instanceSpecific( 3, cl,
            LayerDimensions( numInPlanes, imageSize, numOutPlanes, filterWidth,
            padZeros == 1, false ) );
        float *output = new float[forward->getOutputTotalSize(batchSize)];
        forward->forward( batchSize, data, filter1, 0, output );  
        for( int result = 0; result < resultSize; result++ ) {
            ASSERT_EQ( expectedOutput[result], output[result] );
        }
        delete forward;
        delete[] output;
    }

    delete cl;
}
示例#4
0
TEST( testforward, test2 ) {
    int batchSize = 2;
    LayerDimensions dim;
    dim.setNumFilters(2).setNumInputPlanes(1).setInputSize(3).setFilterSize(3)
        .setPadZeros(false).setBiased(false);

    float data[] = { 0, 0, 0,
                       -0.5f, 0.5f, 0,
                       0, 0, 0,

                        0, 0, 0,
                       0.5f, -0.5f, 0,
                       0, 0, 0
};
    float filter1[] = { 0, 0, 0,
                          0.300809f, -0.11011f, 0,
                         0, 0, 0,

                        0, 0, 0,
                          0.0570846f, 0.347077f, 0,
                         0,0,0
 };

    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();

    float *biases = 0;

    Forward *forward = Forward::instanceSpecific( 1, cl, dim );
    float *output = new float[forward->getOutputTotalSize(batchSize)];
    forward->forward( batchSize, data, filter1, biases, output );

    EXPECT_FLOAT_NEAR( -0.5f * 0.300809f -0.5f * 0.11011f, output[0] );
    EXPECT_FLOAT_NEAR( -0.5f * 0.0570846f +0.5f * 0.347077f, output[1] );
    EXPECT_FLOAT_NEAR( 0.5f * 0.300809f +0.5f * 0.11011f, output[2] );
    EXPECT_FLOAT_NEAR( 0.5f * 0.0570846f -0.5f * 0.347077f, output[3] );

    delete[] output;
    delete forward;
    delete cl;
}
示例#5
0
文件: worker.cpp 项目: augre/pegasus
/* Send all I/O forwarded data to master */
void TaskHandler::send_io_data() {
    for (unsigned i = 0; i < this->forwards.size(); i++) {
        Forward *f = this->forwards[i];
        log_trace("Task %s: Forward %s got %d bytes", name.c_str(), 
                f->destination().c_str(), f->size());

        // Don't bother to send the message if there is no data
        if (f->size() == 0) {
            continue;
        }

        IODataMessage iodata(this->name, f->destination(), f->data(), f->size());
        worker->comm->send_message(&iodata, 0);
    }
}
示例#6
0
int main()
{
    Forward F;
    F.f();
} ///:~
示例#7
0
TEST( testforward, imagesize3 ) {
    int batchSize = 5;
    int numOutPlanes = 2;
    int numInPlanes = 1;
    int imageSize = 3;
    int filterWidth = 3;
    int padZeros = 0;

    float data[] = { 0, 0, 0,
                       0, 0, 0,
                       0.5f, 0, 0.5f,

                        0, 0, 0,
                       0, 0, 0,
                       0.5f, 0, -0.5f ,

                        0, 0, 0,
                       0, 0, 0,
                       0.5f, 0, 0,

                        0, 0, 0,
                       0, 0, 0,
                       1, 10, 0,

                        0, 0, 0,
                       0, 0, 0,
                       0, 0, 1 
};

    float filter1[] = { 0, 0, 0,
                          0, 0, 0,
                         -0.5f, 0, 0.5f,

                        0, 0, 0,
                          0, 0, 0,
                         2.0f, 0.5, 0.5f,

 };

//    int outputSize = 0;
    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
    Forward *forward = Forward::instanceTest( cl, LayerDimensions( numInPlanes, imageSize, numOutPlanes, filterWidth,
        padZeros == 1, false ) );
    float *output = new float[forward->getOutputTotalSize(batchSize)];
    forward->forward( 
        batchSize, data, filter1, 0, output );        

    EXPECT_EQ( 0, output[0] );
    EXPECT_EQ( 1.25f, output[1] );
    EXPECT_EQ( -0.5f, output[2] );
    EXPECT_EQ( 0.75f, output[3] );
    EXPECT_EQ( -0.25f, output[4] );
    EXPECT_EQ( 1, output[5] );
    EXPECT_EQ( -0.5f, output[6] );
    EXPECT_EQ( 7, output[7] );
    EXPECT_EQ( 0.5f, output[8] );
    EXPECT_EQ( 0.5f, output[9] );
        cout << "test1 ok" << endl;
    delete forward;
    delete[] output;
    delete cl;
}
示例#8
0
TEST( testforward, imagesize2_padzeros ) {
    int batchSize = 2;
    int numOutPlanes = 2;
    int numInPlanes = 1;
    int imageSize = 2;
    int filterWidth = 2;
    int padZeros = 1;

    float data[] = { 0, 0, 
                      0.5f, 0.3f,

                        13, 17,
                       -19, 2.3f,
};

    float filter1[] = { 0, 0,
                        -0.5f, 0.4f,

                        0.2f, 0.3f, 
                         0.7f, -1.1f,

 };
    int resultSize = (imageSize + 1) * (imageSize + 1) * batchSize * numOutPlanes;
    float *expectedOutput = new float[resultSize];
    for( int i = 0; i < resultSize; i++ ) {
        expectedOutput[i] = -9999; // means havent provided an expectedresult.
    }

    expectedOutput[0] = 0; expectedOutput[1] = 0; expectedOutput[2] = 0;

    expectedOutput[3] = 0.5f*0.4f;
    expectedOutput[4] = 0.5f*(-0.5f)+0.4f*(0.3f);
    expectedOutput[5] = 0.3f * (-0.5f); 

    expectedOutput[6] = 0; expectedOutput[7] = 0; expectedOutput[8] = 0;

    expectedOutput[9] = 0; expectedOutput[10] = 0; expectedOutput[11] = 0;
    expectedOutput[12] =(-1.1f)*0.5;
    expectedOutput[13] = 0.7f * 0.5f + (-1.1f) * 0.3f;
    expectedOutput[14] = 0.7f * 0.3f;

    // plane 2, filter 2 ...
    expectedOutput[27] = (-1.1f*13);
    expectedOutput[28] = 0.7f * 13 + (-1.1f)*17;
    expectedOutput[29] = 0.7f*17;
    expectedOutput[35] = 0.2f* 2.3f;

//    expectedOutput[] = 0;
//    expectedOutput[5] = 0;
//    expectedOutput[6] = 0.3f * 0.5f;
//    expectedOutput[7] = 0.2f * 0.5f;

//    expectedOutput[8] = 13 * 0.5f;
//    expectedOutput[9] = 17 * (-0.5f);
//    expectedOutput[10] = (-19) * 0;
//    expectedOutput[11] = 2.3f * 0;
// 
//    expectedOutput[12] = 13 * (-1.1f);
//    expectedOutput[13] = 17 * 0.7f;
//    expectedOutput[14] = (-19) * 0.3f;
//    expectedOutput[15] = 2.3f * 0.2f;

//        -0.5f * 0.5f + 0.5f * 0.5f,
//        0.7f * 0.5f -1.1f * 0.5f,
//        (-0.5f) * (-19) + 0.5f * 2.3f,
//        0.2f*13 + 0.3f* 17 + 0.7f *(-19) -1.1f * 2.3f 
//    };

//    int outputSize = 0;
    EasyCL *cl = EasyCL::createForFirstGpuOtherwiseCpu();
    Forward *forward = Forward::instanceTest( cl, LayerDimensions( numInPlanes, imageSize, numOutPlanes, filterWidth,
        padZeros == 1, false ) );
    float *output = new float[forward->getOutputTotalSize(batchSize)];
    forward->forward( batchSize, data, filter1, 0, output );        

//    ASSERT_EQ( -0.5f * 0.5f + 0.5f * 0.5f, output[0] );
//    ASSERT_EQ( 0.7f * 0.5f -1.1f * 0.5f, output[1] );
//    ASSERT_EQ( (-0.5f) * (-19) + 0.5f * 2.3f, output[2] );
//    ASSERT_EQ( 0.2f*13 + 0.3f* 17 + 0.7f *(-19) -1.1f * 2.3f , output[3] );

    for( int result = 0; result < resultSize; result++ ) {
        if( expectedOutput[result] != -9999 ) {
            cout << " checking result[" << result << "]=" << output[result] << " expecting: " << expectedOutput[result] << endl;
            ASSERT_FLOAT_EQ( expectedOutput[result], output[result] );
        }
    }
    delete forward;
    delete[] output;
    delete cl;
}
示例#9
0
int main() {
  Forward frwd;
  frwd.f();
} ///:~