KAFFE_STD_PROF_RATE
#endif
#endif

int enableXProfiling(void)
{
	int retval = false;

	xProfilingOff();
	/* Start up our profiler and set it to observe the main executable */
	if( xProfFlag &&
	    enableProfileTimer() &&
	    (kaffe_memory_samples = createMemorySamples()) &&
	    observeMemory(kaffe_memory_samples, &_start, &etext - &_start) &&
	    (profiler_debug_file = createDebugFile(kaffe_syms_filename)) &&
	    !atexit(profilerAtExit) )
	{
#if defined(KAFFE_CPROFILER)
		struct gmonparam *gp = getGmonParam();
		int prof_rate;
#endif
		
#if defined(KAFFE_CPROFILER)
		/* Turn off any other profiling */
		profil(0, 0, 0, 0);
#if defined(KAFFE_STD_PROF_RATE)
		if( !(prof_rate = kaffeStdProfRate()) )
#endif
			prof_rate = hertz(); /* Just guess */
		if( !prof_rate )
			prof_rate = 100;
		/* Copy the hits leading up to now into our own counters */
		if( gp && gp->kcountsize > 0 )
		{
			int lpc, len = gp->kcountsize / sizeof(HISTCOUNTER);
			HISTCOUNTER *hist = gp->kcount;
			int scale;

			scale = (gp->highpc - gp->lowpc) / len;
			for( lpc = 0; lpc < len; lpc++ )
			{
				if( hist[lpc] )
				{
					char *pc = ((char *)gp->lowpc) +
						(lpc * scale);

					memoryHitCount(kaffe_memory_samples,
						       pc,
						       (100 * hist[lpc]) /
						       prof_rate);
				}
			}
		}
#endif
		retval = true;
	}
	else
	{
		xProfFlag = 0;
		disableXProfiling();
	}
	xProfilingOn();
	return( retval );
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    try {
        // parse command line
        if (argc != 3)
            throw CError(usage, argv[0]);
        int argn = 1;
        char *dataFileName = argv[argn++];
	char *outstem = argv[argn++];

	int writeParams = 1;
	int writeTimings = 1;

	FILE *debugfile = createDebugFile(writeParams, outstem, verbose, argc, argv);

	// Load datafile 
	int width, height, nLabels;
	std::vector<int> gt, data, lrPairwise, udPairwise;
	MRF::CostVal *dataCostArray, *hCue, *vCue;

	if (verbose)
	    fprintf(stderr, "Loading datafile...\n");
	
	LoadDataFile(dataFileName, width, height, nLabels, dataCostArray, hCue, vCue);

	DataCost *dcost = new DataCost(dataCostArray);
	SmoothnessCost *scost = new SmoothnessCost(1, 1, 1, hCue, vCue);
	EnergyFunction *energy = new EnergyFunction(dcost, scost);

	if (verbose)
	    fprintf(stderr, "Running optimization...\n");
	fflush(stderr);

	int MRFalg = aRunAll;

	int outerIter, innerIter;
	MRF *mrf = NULL;
	for (int numAlg = aICM; numAlg <= aBPM; numAlg++) {
	    outerIter = MAXITER;
	    innerIter = 1;
	    if (MRFalg < aRunAll && numAlg != MRFalg) continue;

	    startAlgInitTimer();

	    switch (numAlg) {
	    case aICM:       mrf = new ICM(width, height, nLabels, energy); innerIter = 5; break;
	    case aExpansion: mrf = new Expansion(width, height, nLabels, energy); break;
	    case aSwap:      mrf = new Swap(width, height, nLabels, energy); break;
	    case aTRWS:      mrf = new TRWS(width, height, nLabels, energy); break;
	    case aBPS:       mrf = new BPS(width, height, nLabels, energy);  
		//innerIter = 5; 
		break;
	    case aBPM:       mrf = new MaxProdBP(width, height, nLabels, energy);
		//innerIter = 2; 
		break;
	    default: throw new CError("unknown algorithm number");
	    }
	    if (debugfile)
		fprintf(debugfile, "******* Running %s for up to %d x %d iterations\n",
			algs[numAlg], outerIter, innerIter);

	    mrf->initialize();
	    mrf->clearAnswer();

	    bool initializeToWTA = false;
	    if (initializeToWTA) {
		if (debugfile)
		    fprintf(debugfile, "performing WTA\n");
		CByteImage disp;
		WTA(dataCostArray, width, height, nLabels, disp);
		writeDisparities(disp, 255, "WTA.png", debugfile);
		setDisparities(disp, mrf);
	    } else {
		mrf->clearAnswer();
	    }

	    float initTime = getAlgInitTime();
	    
	    FILE *timefile = createTimeFile(writeTimings, outstem, algs[numAlg], debugfile);

	    runAlg(mrf, numAlg, debugfile, timefile, outerIter, innerIter, initTime);

	    // save resulting labels as image
	    CShape sh(width, height, 1);
	    CByteImage outimg(sh);
	    int n = 0;
	    for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
		    outimg.Pixel(x, y, 0) = 255* mrf->getLabel(n);
		    n++;
		}
	    }

	    char fname[500];
	    sprintf(fname, "%s-%s.png", outstem, algs[numAlg]);
	    WriteImageVerb(outimg, fname, 1);
	    delete mrf;
	}

	if (writeParams)
	    fclose(debugfile);

	delete energy;
	delete scost;
	delete dcost;
	delete [] dataCostArray;
	delete [] hCue;
	delete [] vCue;
    }
    catch (CError &err) {
        fprintf(stderr, err.message);
        fprintf(stderr, "\n");
        return -1;
    }
    catch (bad_alloc) {
	fprintf(stderr, "*** Error: not enough memory\n");
	exit(1);
    }

    return 0;
}