Beispiel #1
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;
}
Beispiel #2
0
TEST( testpropagate, test2 ) {
    int batchSize = 2;

//    int numOutPlanes = 2;
//    int numInPlanes = 1;
//    int imageSize = 3;
//    int filterWidth = 3;
//    int padZeros = 0;
   
    LayerDimensions dim;
    dim.setNumFilters(2).setNumInputPlanes(1).setInputImageSize(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

 };

    OpenCLHelper *cl = OpenCLHelper::createForFirstGpuOtherwiseCpu();
//    float *results = new float[512];

    float *biases = 0;

//    CLWrapper *dataWrapper = cl->wrap( batchSize * 9, data );
//    CLWrapper *weightsWrapper = cl->wrap( numOutPlanes * 9, filter1 );
//    CLWrapper *resultsWrapper = cl->wrap( 512, results );
//    dataWrapper->copyToDevice();
//    weightsWrapper->copyToDevice();

//    CLKernel *convolve = cl->buildKernel( "../cl/propagate1.cl", "convolve_imagecubes_float2", "-D TANH" );
//    CLKernel *tanh = cl->buildKernel( "ClConvolve.cl", "byelement_tanh" );

//    for( int it = 0; it < 100; it ++ ) {

    Propagate *propagate = Propagate::instanceSpecific( 1, cl, dim, new TanhActivation() );
    float *results = propagate->propagate( batchSize, data, filter1, biases );

//        convolve->in(batchSize)->in( numInPlanes )->in( numOutPlanes )->in( imageSize )->in( filterWidth )
//           ->in( padZeros );
//        convolve->input( dataWrapper );
//        convolve->input( weightsWrapper);
//        convolve->output( resultsWrapper );
//        int globalSize = batchSize * numOutPlanes * imageSize * imageSize;
//        int workgroupsize = cl->getMaxWorkgroupSize();
//        globalSize = ( ( globalSize + workgroupsize - 1 ) / workgroupsize ) * workgroupsize;
////        cout << " globalsize " << globalSize << " workgroupsize " << workgroupsize << endl;
//        convolve->run_1d( globalSize, workgroupsize );

//        resultsWrapper->copyToHost();

//        for( int i = 0; i < 20; i++ ) {
//            cout << "results[" << i << "]=" << results[i] << endl;
//        }
        EXPECT_FLOAT_NEAR( -0.202616f, results[0] );
        EXPECT_FLOAT_NEAR( 0.143989f, results[1] );
        EXPECT_FLOAT_NEAR( 0.202616f, results[2] );
        EXPECT_FLOAT_NEAR( -0.143989f, results[3] );
//    }
//    cout << "test2 ok" << endl;
    delete propagate;
//    delete convolve;
//    delete resultsWrapper;
//    delete weightsWrapper;
//    delete dataWrapper;
    delete[] results;
    delete cl;
}