00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef APPNEURO_VCX_BENCHMARK_C_DEFINED
00039 #define APPNEURO_VCX_BENCHMARK_C_DEFINED
00040
00041 #include "Channels/ChannelOpts.H"
00042 #include "Channels/IntegerInput.H"
00043 #include "Channels/IntegerMathEngine.H"
00044 #include "Component/ModelManager.H"
00045 #include "Component/ModelOptionDef.H"
00046 #include "Component/ModelParam.H"
00047 #include "Channels/IntegerRawVisualCortex.H"
00048 #include "Channels/RawVisualCortex.H"
00049 #include "rutz/rand.h"
00050 #include "rutz/time.h"
00051
00052 #include <stdio.h>
00053 #include <sys/resource.h>
00054 #include <sys/time.h>
00055
00056 static const ModelOptionDef OPT_UseInteger =
00057 { MODOPT_FLAG, "UseInteger", &MOC_GENERAL, OPTEXP_CORE,
00058 "Whether to the VisualCortex based on integer arithmetic",
00059 "use-integer", '\0', "", "true" };
00060
00061 int main(int argc, char** argv)
00062 {
00063 MYLOGVERB = LOG_CRIT;
00064
00065 ModelManager manager("VisualCortex Benchmarker");
00066 OModelParam<bool> useinteger(&OPT_UseInteger, &manager);
00067
00068 nub::ref<IntegerMathEngine> ieng(new IntegerMathEngine(manager));
00069 manager.addSubComponent(ieng);
00070
00071 nub::ref<IntegerRawVisualCortex> ivcx(new IntegerRawVisualCortex(manager, ieng));
00072 manager.addSubComponent(ivcx);
00073
00074 nub::ref<RawVisualCortex> fvcx(new RawVisualCortex(manager));
00075 manager.addSubComponent(fvcx);
00076
00077 manager.setOptionValString(&OPT_MaxNormType, "Maxnorm");
00078 manager.setOptionValString(&OPT_DirectionChannelLowThresh, "0");
00079 manager.setOptionValString(&OPT_IntChannelScaleBits, "16");
00080 manager.setOptionValString(&OPT_IntMathLowPass5, "lp5optim");
00081 manager.setOptionValString(&OPT_IntMathLowPass9, "lp9optim");
00082
00083 if (manager.parseCommandLine(argc, argv, "[numframes=100] [WWWxHHH=512x512]",
00084 0, 2) == false)
00085 return 1;
00086
00087 const int nframes =
00088 manager.numExtraArgs() >= 1
00089 ? manager.getExtraArgAs<int>(0) : 100;
00090
00091 const Dims dims =
00092 manager.numExtraArgs() >= 2
00093 ? manager.getExtraArgAs<Dims>(1) : Dims(512,512);
00094
00095 manager.start();
00096
00097 if (nframes > 0)
00098 {
00099
00100
00101
00102
00103 Image<PixRGB<byte> > in1(dims, NO_INIT);
00104 Image<PixRGB<byte> > in2(dims, NO_INIT);
00105
00106 rutz::urand gen(time(NULL)); gen.idraw(1);
00107
00108 for (Image<PixRGB<byte> >::iterator
00109 itr = in1.beginw(), stop = in1.endw(); itr != stop; ++itr)
00110 *itr = PixRGB<byte>(gen.idraw(256),
00111 gen.idraw(256),
00112 gen.idraw(256));
00113
00114 for (Image<PixRGB<byte> >::iterator
00115 itr = in2.beginw(), stop = in2.endw(); itr != stop; ++itr)
00116 *itr = PixRGB<byte>(gen.idraw(256),
00117 gen.idraw(256),
00118 gen.idraw(256));
00119
00120 const Image<byte> clipMask;
00121
00122 fprintf(stderr, "%s (%s): START: %d frames %dx%d... ",
00123 argv[0],
00124 useinteger.getVal() ? "integer" : "floating-point",
00125 nframes, dims.w(), dims.h());
00126 fflush(stderr);
00127
00128 const rutz::time real1 = rutz::time::wall_clock_now();
00129 const rutz::time user1 = rutz::time::user_rusage();
00130 const rutz::time sys1 = rutz::time::sys_rusage();
00131
00132 SimTime t = SimTime::ZERO();
00133
00134 if (useinteger.getVal())
00135 for (int c = 0; c < nframes; ++c)
00136 {
00137 t += SimTime::HERTZ(30);
00138
00139 PyramidCache<int> cache;
00140 ivcx->inputInt(IntegerInput::fromRgb(c & 1 ? in2 : in1,
00141 ieng->getNbits()),
00142 t, &cache, clipMask);
00143
00144 const Image<int> output = ivcx->getOutputInt();
00145 }
00146 else
00147 for (int c = 0; c < nframes; ++c)
00148 {
00149 t += SimTime::HERTZ(30);
00150
00151 PyramidCache<int> cache;
00152 fvcx->input(InputFrame::fromRgb(c & 1 ? &in2 : &in1, t));
00153
00154 const Image<float> output = fvcx->getOutput();
00155 }
00156
00157 const rutz::time real2 = rutz::time::wall_clock_now();
00158 const rutz::time user2 = rutz::time::user_rusage();
00159 const rutz::time sys2 = rutz::time::sys_rusage();
00160
00161 const double real_secs = (real2 - real1).sec();
00162 const double user_secs = (real2 - real1).sec();
00163 const double sys_secs = (real2 - real1).sec();
00164
00165 const double frame_rate = nframes / real_secs;
00166 const double msec_per_frame = (1000.0*real_secs) / nframes;
00167
00168 fprintf(stderr, "DONE.\n");
00169 fprintf(stderr, "%s (%s): real %.3fs; user %.3fs; "
00170 "sys %.3fs\n", argv[0],
00171 useinteger.getVal() ? "integer" : "floating-point",
00172 real_secs, user_secs, sys_secs);
00173 fprintf(stderr, "%s (%s): %.3ffps; %.3fmsec/frame\n",
00174 argv[0],
00175 useinteger.getVal() ? "integer" : "floating-point",
00176 frame_rate, msec_per_frame);
00177 }
00178
00179 manager.stop();
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189 #endif // APPNEURO_VCX_BENCHMARK_C_DEFINED