Ejemplo n.º 1
0
// Tests ImageBufAlgo::compare
void test_compare ()
{
    std::cout << "test compare\n";
    // Construct two identical 50% grey images
    const int WIDTH = 10, HEIGHT = 10, CHANNELS = 3;
    ImageSpec spec (WIDTH, HEIGHT, CHANNELS, TypeDesc::FLOAT);
    ImageBuf A ("A", spec);
    ImageBuf B ("B", spec);
    const float grey[CHANNELS] = { 0.5, 0.5, 0.5 };
    ImageBufAlgo::fill (A, grey);
    ImageBufAlgo::fill (B, grey);

    // Introduce some minor differences
    const int NDIFFS = 10;
    ImageBuf::Iterator<float> a (A);
    for (int i = 0;  i < NDIFFS && a.valid();  ++i, ++a) {
        for (int c = 0;  c < CHANNELS;  ++c)
            a[c] = a[c] + 0.01f * i;
    }
    // We expect the differences to be { 0, 0.01, 0.02, 0.03, 0.04, 0.05,
    // 0.06, 0.07, 0.08, 0.09, 0, 0, ...}.
    const float failthresh = 0.05;
    const float warnthresh = 0.025;
    ImageBufAlgo::CompareResults comp;
    ImageBufAlgo::compare (A, B, failthresh, warnthresh, comp);
    // We expect 5 pixels to exceed the fail threshold, 7 pixels to
    // exceed the warn threshold, the maximum difference to be 0.09,
    // and the maximally different pixel to be (9,0).
    // The total error should be 3 chans * sum{0.01,...,0.09} / (pixels*chans)
    //   = 3 * 0.45 / (100*3) = 0.0045
    std::cout << "Testing comparison: " << comp.nfail << " failed, "
              << comp.nwarn << " warned, max diff = " << comp.maxerror
              << " @ (" << comp.maxx << ',' << comp.maxy << ")\n";
    std::cout << "   mean err " << comp.meanerror << ", RMS err " 
              << comp.rms_error << ", PSNR = " << comp.PSNR <<  "\n";
    OIIO_CHECK_EQUAL (comp.nfail, 5);
    OIIO_CHECK_EQUAL (comp.nwarn, 7);
    OIIO_CHECK_EQUAL_THRESH (comp.maxerror, 0.09, 1e-6);
    OIIO_CHECK_EQUAL (comp.maxx, 9);
    OIIO_CHECK_EQUAL (comp.maxy, 0);
    OIIO_CHECK_EQUAL_THRESH (comp.meanerror, 0.0045, 1.0e-8);
}
Ejemplo n.º 2
0
void
test_compute ()
{
    double time;

    ROI roi (0, xres, 0, yres, 0, 1, 0, channels);

    std::cout << "Test straightforward as 1D array of float: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);
    // imgR.write ("ref.exr");

    std::cout << "Test array iterated like an image: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array iterated like an image, multithreaded: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image_multithread_wrapper, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array as 1D, using SIMD: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_simd4, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array iterated like an image, using SIMD: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image_simd, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array iterated like an image, using SIMD, multithreaded: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image_simd_multithread_wrapper, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test ImageBufAlgo::mad 1 thread: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_IBA, roi, 1),
                       ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test ImageBufAlgo::mad multi-thread " << numthreads << ": ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_IBA, roi, numthreads),
                       ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);
}
Ejemplo n.º 3
0
int
main (int argc, char **argv)
{
    getargs (argc, argv);

    // First, just compute and print how expensive a Timer begin/end is,
    // in cycles per second.
    {
        Timer timer;
        int n = 1000000;
        for (int i = 0;  i < n;  ++i) {
            Timer t;
            t();  // force getting the time
        }
        std::cout << "Timer begin/end cost is " 
                  << double(n)/timer() << " /sec\n";
    }

    const int interval = 100000;  // 1/10 sec
    const double eps = 1e-3;   // slop we allow in our timings

    // Verify that Timer(false) doesn't start
    Timer all(true);
    Timer selective(false);
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.0, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.1, eps);

    // Make sure start/stop work
    selective.start ();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.2, eps);
    selective.stop ();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.3, eps);
    std::cout << "Checkpoint: All " << all() << " selective " << selective() << "\n";

    // Test reset() -- should set selective to 0 and turn it off
    selective.reset();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.0, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.4, eps);
    selective.start();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.5, eps);

    // Test lap()
    double lap = selective.lap();  // lap=.1, select.time_since_start
    OIIO_CHECK_EQUAL_THRESH (lap,         0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (selective.time_since_start(), 0.0, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.5, eps);
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.2, eps);
    OIIO_CHECK_EQUAL_THRESH (selective.time_since_start(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.6, eps);
    std::cout << "Checkpoint2: All " << all() << " selective " << selective() << "\n";

    return unit_test_failures;
}
Ejemplo n.º 4
0
int
main (int argc, char **argv)
{
    getargs (argc, argv);

    // First, just compute and print how expensive a Timer begin/end is,
    // in cycles per second.
    {
        Timer timer;
        int n = 10000000;
        int zeroes = 0;
        Timer::ticks_t biggest = 0;
        for (int i = 0;  i < n;  ++i) {
            Timer t;
            Timer::ticks_t ticks = t.ticks();  // force getting the time
            if (!ticks)
                ++zeroes;
            if (ticks > biggest)
                biggest = ticks;
        }
        std::cout << "Timer begin/end cost is " 
                  << double(n)/timer() << " /sec\n";
        std::cout << "Out of " << n << " queries, " << zeroes << " had no time\n";
        std::cout << "Longest was " << Timer::seconds(biggest) << " s.\n";
    }

    const int interval = 100000;  // 1/10 sec
    double eps = 0.01;   // slop we allow in our timings
#ifdef __APPLE__
    eps = 0.03;
    // On some Apple OSX systems (especially >= 10.10 Yosemite), a feature
    // called "timer coalescing" causes sleep/wake events to merge in order
    // to produce longer idle periods for the CPU to go into a lower power
    // state. This tends to make usleep() less reliable in its timing.
    //
    // One (permanent) fix is to disable timer coalescing with this command:
    //     $ sudo sysctl -w kern.timer.coalescing_enabled=0
    // But you want better power use, so instead we just increase the timing
    // tolereance on Apple to make this test pass.
#endif

    // Verify that Timer(false) doesn't start
    Timer all (Timer::StartNow);
    Timer selective (Timer::DontStartNow);
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.0, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.1, eps);

    // Make sure start/stop work
    selective.start ();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.2, eps);
    selective.stop ();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.3, eps);
    std::cout << "Checkpoint: All " << all() << " selective " << selective() << "\n";

    // Test reset() -- should set selective to 0 and turn it off
    selective.reset();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.0, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.4, eps);
    selective.start();
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.5, eps);

    // Test lap()
    double lap = selective.lap();  // lap=.1, select.time_since_start
    OIIO_CHECK_EQUAL_THRESH (lap,         0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (selective.time_since_start(), 0.0, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.5, eps);
    Sysutil::usleep (interval);
    OIIO_CHECK_EQUAL_THRESH (selective(), 0.2, eps);
    OIIO_CHECK_EQUAL_THRESH (selective.time_since_start(), 0.1, eps);
    OIIO_CHECK_EQUAL_THRESH (all(),       0.6, eps);
    std::cout << "Checkpoint2: All " << all() << " selective " << selective() << "\n";

    return unit_test_failures;
}