コード例 #1
0
ファイル: main.cpp プロジェクト: hunduan2018/GPU-Gems
/**
 * @fn Keyboard(unsigned char key, int x, int y)
 * @brief GLUT keyboard callback.
 */ 
void Keyboard(unsigned char key, int x, int y)
{
  switch(key) 
  {
  case 'q':
  case 'Q':
  case 27:
    Shutdown();
    exit(0);
  	break;
  case '.':
    g_bSingleStep = true;
    break;
  case 'p':
    g_bPause = !g_bPause;
    break;
  case 'a':
    g_bArbitraryBC = !g_bArbitraryBC;
    g_pFlo->EnableArbitraryBC(g_bArbitraryBC);
    break;
  case 'c':
    g_bClearPressure = !g_bClearPressure;
    g_pFlo->EnablePressureClear(g_bClearPressure);
    break;
  case 'r':
    g_pFlo->Reset();
    break;
  case 'R':
    g_pFlo->Reset(true);
    break;
  case 'v':
    g_bComputeVorticity = !g_bComputeVorticity;
    g_pFlo->EnableVCForce(g_bComputeVorticity);
    break;
  case '~':
  case '`':
    g_bDisplaySliders = !g_bDisplaySliders;
    break;
  case 't':
    g_displayMode = static_cast<Flo::DisplayMode>(((g_displayMode + 1) 
												  % Flo::DISPLAY_COUNT));
    break;
  case 'T':
	g_bDisplayFluid = !g_bDisplayFluid;
	break;
  case 'b':
    g_bBilerp = !g_bBilerp;
    break;
  case 'm':
    g_bMakeTex = !g_bMakeTex;
    break;
  case 'L':
      g_perfTimer.Stop();
      g_perfTimer.Reset();
      g_bTiming = true;
      break;
  default:
    break;
  }
}
コード例 #2
0
/**
  * The parser uses a code sandwich to wrap the parsing process. Before
  * the process begins, WillBuildModel() is called. Afterwards the parser
  * calls DidBuildModel().
  * @update rickg 03.20.2000
  * @param  aParserContext
  * @param  aSink
  * @return error code (almost always 0)
  */
NS_IMETHODIMP
CViewSourceHTML::WillBuildModel(const CParserContext& aParserContext,
                                nsITokenizer* aTokenizer,
                                nsIContentSink* aSink)
{
  nsresult result=NS_OK;

#ifdef RAPTOR_PERF_METRICS
  vsTimer.Reset();
  NS_START_STOPWATCH(vsTimer);
#endif

  STOP_TIMER();
  mSink=(nsIHTMLContentSink*)aSink;

  if((!aParserContext.mPrevContext) && (mSink)) {

    nsAString & contextFilename = aParserContext.mScanner->GetFilename();
    mFilename = Substring(contextFilename,
                          12, // The length of "view-source:"
                          contextFilename.Length() - 12);

    mDocType=aParserContext.mDocType;
    mMimeType=aParserContext.mMimeType;
    mDTDMode=aParserContext.mDTDMode;
    mParserCommand=aParserContext.mParserCommand;
    mTokenizer = aTokenizer;

#ifdef DUMP_TO_FILE
    if (gDumpFile) {

      fprintf(gDumpFile, "<html>\n");
      fprintf(gDumpFile, "<head>\n");
      fprintf(gDumpFile, "<title>");
      fprintf(gDumpFile, "Source of: ");
      fputs(NS_ConvertUTF16toUTF8(mFilename).get(), gDumpFile);
      fprintf(gDumpFile, "</title>\n");
      fprintf(gDumpFile, "<link rel=\"stylesheet\" type=\"text/css\" href=\"resource://gre/res/viewsource.css\">\n");
      fprintf(gDumpFile, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
      fprintf(gDumpFile, "</head>\n");
      fprintf(gDumpFile, "<body id=\"viewsource\">\n");
      fprintf(gDumpFile, "<pre id=\"line1\">\n");
    }
#endif //DUMP_TO_FILE
  }


  if(eViewSource!=aParserContext.mParserCommand)
    mDocType=ePlainText;
  else mDocType=aParserContext.mDocType;

  mLineNumber = 1;

  START_TIMER();

  return result;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: c0d1f1ed/piko-public
void doPerfTest(int n_runs)
{
  printf("Running perf test (%d runs)...\n", n_runs);

  if(n_runs == 0) return;

  buildProjectionMatrix();
  resetDepthBuffer();
  piko_pipe.prepare();
  piko_pipe.run_single();

  Stopwatch mywatch;

  mywatch.Reset();
  for(int run = 0; run < n_runs; run++)
  {
    buildProjectionMatrix();
    resetDepthBuffer();
    piko_pipe.prepare();
  }
  float prepTime = mywatch.GetTime();

  mywatch.Reset();
  for(int run = 0; run < n_runs; run++)
  {
    buildProjectionMatrix();
    resetDepthBuffer();
    piko_pipe.prepare();
    piko_pipe.run_single();
  }
  float fullrunTime = mywatch.GetTime();

  float total_time_to_ms = 1000.0f / (float) n_runs;

  printf("Prep time     = %0.2f ms\n", total_time_to_ms * (prepTime));
  printf("Full run time = %0.2f ms\n", total_time_to_ms * (fullrunTime));
  printf("Raster time   = %0.2f ms\n", total_time_to_ms * (fullrunTime - prepTime));
}
コード例 #4
0
ファイル: main.cpp プロジェクト: hunduan2018/GPU-Gems
/**
 * @fn InitParameters()
 * @brief Initializes the UI Sliders
 */ 
void InitParameters()
{
  // create a new parameter list
  paramlist = new ParamListGL("misc");
  paramlist->bar_col_outer[0] = 0.8f;
  paramlist->bar_col_outer[1] = 0.8f;
  paramlist->bar_col_outer[2] = 0.0f;
  paramlist->bar_col_inner[0] = 0.8f;
  paramlist->bar_col_inner[1] = 0.8f;
  paramlist->bar_col_inner[2] = 0.0f;
  
  // add some parameters to the list

  // How many iterations to run the poisson solvers.  
  paramlist->AddParam(new Param<int>("Solver Iterations", g_iNumPoissonSteps, 
                                     1, 100, 1, &g_iNumPoissonSteps));
  // The size of the time step taken by the simulation
  paramlist->AddParam(new Param<float>("Time step", g_rTimestep, 
									   0.1f, 10, 0.1f, &g_rTimestep));
  // The Grid Cell Size
  paramlist->AddParam(new Param<float>("Grid Scale", g_rGridScale, 
									   0.1f, 100, 0.1f, &g_rGridScale));
  // Scales the vorticity confinement force.
  paramlist->AddParam(new Param<float>("Vort. Conf. Scale", g_rVCScale, 
									   0, .25, 0.005f, &g_rVCScale));
  // The viscosity ("thickness") of the fluid.
  paramlist->AddParam(new Param<float>("Viscosity", g_rViscosity, 
									   0, 0.005f, 0.0001f, &g_rViscosity));
  
  // How slow or fast the Ink fades.  1 = does not fade.
  paramlist->AddParam(new Param<float>("Ink Longevity", g_rInkLongevity, 
									   0.99f, 1, 0.0001, &g_rInkLongevity));
  // The size of the "brush" the user draws with
  paramlist->AddParam(new Param<float>("Brush Radius", g_rBrushRadius, 
									   0.005, .25, .005, &(g_rBrushRadius)));
   // The Ink color, RGB.
  paramlist->AddParam(new Param<float>("Ink Red", g_rInkRGB[0], 
									   0.0, 1.0, 0.01f, &(g_rInkRGB[0])));
  paramlist->AddParam(new Param<float>("    Green", g_rInkRGB[1], 
									   0.0, 1.0, 0.01f, &(g_rInkRGB[1])));
  paramlist->AddParam(new Param<float>("    Blue", g_rInkRGB[2], 
									   0.0, 1.0, 0.01f, &(g_rInkRGB[2])));
  
  g_perfTimer.Reset();
}
コード例 #5
0
ファイル: playback_cupspoon.cpp プロジェクト: panjia1983/APDL
	void playback_local_PD_R3()
	{
		std::ofstream timing_file("timing_local_PD_R3.txt");
		std::ofstream PD_file("PD_local_R3.txt");

		std::vector<C2A_Model*> P;
		std::vector<C2A_Model*> Q;

		readObjFiles(P, "../data/models/CupSpoon/cup_convex.obj");
		readObjFiles(Q, "../data/models/CupSpoon/spoon_convex.obj");


		std::vector<ContactSpaceSampleData> contactspace_samples;
		std::ifstream in("space_test_3d.txt");
		asciiReader(in, contactspace_samples);

		for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
		{
			std::cout << i << std::endl;
			DataVector q_col(6);
			DataVector q(3);
			for(std::size_t j = 0; j < 3; ++j)
				q[j] = contactspace_samples[i].v[j];

			for(std::size_t j = 0; j < 6; ++j)
				q_col[j] = contactspace_samples[i].v[j];

			boost::timer t;
			aTimer.Reset();
			aTimer.Start();
			double pd = Collider3D::PDt(P, Q, q_col);
			PD_file << pd << " ";	
			// timing_file << t.elapsed() << " ";
			timing_file << aTimer.GetTime() * 1000 << " ";

			
			timing_file.flush();
			PD_file.flush();
		}
	}
コード例 #6
0
ファイル: playback_cupspoon.cpp プロジェクト: panjia1983/APDL
	void playback_R3()
	{
		C2A_Model* P = NULL;
		C2A_Model* Q = NULL;
		readObjFile(P, "../data/models/CupSpoon/Cup.obj");
		readObjFile(Q, "../data/models/CupSpoon/Spoon.obj");

		P->ComputeRadius();
		Q->ComputeRadius();

		Collider3D collider(P, Q);

		std::vector<ContactSpaceSampleData> contactspace_samples;
		std::ifstream in("space_test_3d.txt");
		asciiReader(in, contactspace_samples);

		ContactSpaceR3 contactspace(P, Q, 0.05 * (P->radius + Q->radius));
		std::ofstream scaler_file("scaler_3d_rotation_cupspoon.txt");
		scaler_file << contactspace.getScaler() << std::endl;
		std::vector<ContactSpaceSampleData> train_samples = contactspace.uniform_sample(100000);

		SVMLearner learner;
		learner.setDim(contactspace.active_data_dim());
		learner.setC(20);
		learner.setScaler(contactspace.getScaler());
		learner.setUseScaler(true);
		learner.setGamma(50); 

		learner.learn(train_samples, contactspace.active_data_dim());
		learner.save("model_R3.txt");

		// flann::HierarchicalClusteringIndex<ContactSpaceSE3Euler::DistanceType>* query_index = learner.constructIndexOfSupportVectorsForQuery<ContactSpaceSE3Euler, flann::HierarchicalClusteringIndex, flann::HierarchicalClusteringIndexParams>();

		std::vector<ContactSpaceSampleData> support_samples;
		learner.collectSupportVectors(support_samples);
		ExtendedModel<ContactSpaceR3, flann::Index> extended_model = 
			constructExtendedModelForModelDecisionBoundary<ContactSpaceR3, SVMLearner, flann::Index, flann::KDTreeIndexParams>(contactspace, learner, support_samples, 0.01, 50);


		std::ofstream timing_file("timing_APD_R3.txt");
		std::ofstream PD_file("PD_APD_R3.txt");

		for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
		{
			std::cout << i << std::endl;
			DataVector q_col(6);
			DataVector q(3);
			for(std::size_t j = 0; j < 3; ++j)
				q[j] = contactspace_samples[i].v[j];

			for(std::size_t j = 0; j < 6; ++j)
				q_col[j] = contactspace_samples[i].v[j];

			boost::timer t;
			aTimer.Reset();
			aTimer.Start();
			if(!collider.isCollide(q_col)) 
			{
				PD_file << 0 << " ";
			}
			else
			{
				QueryResult pd_result = PD_query(learner, contactspace, extended_model.index, extended_model.samples, q);
				PD_file << pd_result.PD << " ";
			}
			// timing_file << t.elapsed() << " ";
			timing_file << aTimer.GetTime() * 1000 << " ";

			
			timing_file.flush();
			PD_file.flush();
		}
	}
コード例 #7
0
int DatabaseSetTest(TestConfig& conf)
{
	int			numTest;
	Stopwatch	sw;
	Table*		table;
	Transaction* tx;
	bool		ret;
	int			limit = 16*KB;
	int			sum;

	if (conf.argc < 5)
	{
		Log_Message("\n\tusage: %s <keySize> <valueSize>", conf.typeString);
		return 1;
	}
	
	Log_SetTrace(true);
	
	if (DatabaseSetup())
	{
		Log_Message("Cannot initialize database!", 1);
		return 1;
	}
	
	table = database.GetTable("keyspace");
	if (!table)
	{
		Log_Message("Cannot initialize table!", 1);
		return 1;
	}
	
	conf.SetKeySize(atoi(conf.argv[3]));
	conf.SetValueSize(atoi(conf.argv[4]));

	Log_Message("Test type = %s, keySize = %d, valueSize = %d",
			conf.typeString, conf.keySize, conf.valueSize);
	
	tx = NULL;
	tx = new Transaction(table);
	sw.Start();
	tx->Begin();
	sw.Stop();
	
	sum = 0;
	numTest = conf.datasetTotal / conf.valueSize;
	for (int i = 0; i < numTest; i++)
	{
		if (conf.rndkey)
			GenRandomString(conf.key, conf.keySize);
		else
			conf.key.Writef("key%B:%d", conf.padding.length, conf.padding.buffer, i);
		
		sw.Start();
		ret = table->Set(tx, conf.key, conf.value);
		sw.Stop();
		if (!ret)
		{
			Log_Message("Test failed, ret = %s (%s failed after %d)", ret ? "true" : "false", conf.typeString, i);
			return 1;
		}
		
		sum += conf.keySize + conf.valueSize;
		if (sum > limit)
		{			
			sw.Start();
			tx->Commit();
			sw.Stop();
			
			double mbps = sum / (sw.elapsed / 1000.0) / 1000000;
			Log_Message("num = %d, elapsed = %ld, thruput = %lf MB/s", i, sw.elapsed, mbps);
			sw.Reset();
			
			sw.Start();
			tx->Begin();
			sw.Stop();

			sum = 0;
		}
	}

	sw.Start();
	tx->Commit();
	sw.Stop();

	double mbps = (conf.valueSize + conf.keySize) * numTest / (sw.elapsed / 1000.0) / 1000000;
	Log_Message("Test succeeded, %s/sec = %lf (num = %d, elapsed = %ld, thruput = %lf MB/s)", conf.typeString, numTest / (sw.elapsed / 1000.0), numTest, sw.elapsed, mbps);
	
	return 0;
}
コード例 #8
0
ファイル: perf1.cpp プロジェクト: moveccr/leto
int
main()
{
	Stopwatch sw;
	BUS bus;
	int i;
	int r;
	uint64_t N, NR;
	int score = 0;
	float realscore;

	printf("BUSIF = %s\n", BUSIF_NAME);
	busif_init(NULL);

	/* まずざっと時間を測定。さすがに1秒かからないと想定 */
	sw.Start();
	for (i = 0; i < 10000; i++) {
		busif_060.read_long(bus);
	}
	sw.Stop();
	/* 1秒程度になるようなループ回数 N を求める */
	NR = ((uint64_t)1000 * 1000 * 10000 / sw.usec());
	/* 10進 リスケーリング。計算結果が人間に分かりやすい。 */
	N = 1;
	while (NR > 10) { N *= 10; NR /= 10; }
	printf("N=%qd\n", N);

	sw.Reset();
	sw.Start();
	for (i = 0; i < N; i++) {
		busif_060.read_long(bus);
	}
	sw.Stop();
	r = print_result("long", sw);
	score += r * 76;

	sw.Reset();
	sw.Start();
	for (i = 0; i < N; i++) {
		busif_060.read_byte(bus);
	}
	sw.Stop();
	r = print_result("byte", sw);
	score += r * 12;

	sw.Reset();
	sw.Start();
	for (i = 0; i < N; i++) {
		busif_060.read_word(bus);
	}
	sw.Stop();
	r = print_result("word", sw);
	score += r * 12;

	/*
	 * score の単位は N * 100 * msec の BWL平準化アクセス時間。
	 * 一般化するため、1/100 msec 間に BWL平準化アクセス可能な回数に
	 * 変換する。
	 */
	realscore = (float)N / score;
	printf("score: %f\n", realscore);
	return 0;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: hunduan2018/GPU-Gems
/**
 * @fn Display()
 * @brief GLUT display callback.
 */ 
void Display()
{
  //g_timer.Reset();

  if (!g_bPause || g_bSingleStep)
  {
    g_bSingleStep = false;
     
    // set parameters that may have changed
    g_pFlo->SetViscosity(g_rViscosity);
    g_pFlo->EnablePressureClear(g_bClearPressure);
    g_pFlo->SetNumPoissonSteps(g_iNumPoissonSteps);
    g_pFlo->SetMassColor(g_rInkRGB);
    g_pFlo->SetInkLongevity(g_rInkLongevity);
    g_pFlo->SetTimeStep(g_rTimestep);
    g_pFlo->SetGridScale(g_rGridScale);
    g_pFlo->SetVorticityConfinementScale(g_rVCScale);
    
    if (g_displayMode == Flo::DISPLAY_VORTICITY || g_bComputeVorticity)
      g_pFlo->EnableVorticityComputation(true);
    else
      g_pFlo->EnableVorticityComputation(false);
    
	// For benchmarking...
    if (g_bTiming)
    {
      if (g_perfTimer.GetNumStarts() == 100)
      {
        g_bTiming = false;
        g_perfTimer.Stop();
        printf("Average iteration time: %f\n", g_perfTimer.GetAvgTime());
      }
      g_perfTimer.Start();
    }

	// Take a simulation timestep.
    g_pFlo->Update();
  }
  
  if (g_bDisplayFluid)
  {
	// Display the fluid.
	g_pFlo->Display(g_displayMode, g_bBilerp, g_bMakeTex, g_bArbitraryBC);
	  
	// Display user interface.
	if (g_bDisplaySliders)
	{
	  paramlist->Render(0, 0);
	}
	  
	glutSwapBuffers();
  }
  
  // Frame rate update
  g_iFrameCount++;
  
  if (g_timer.GetTime() > 0.5)
  {  
    char title[100];
    sprintf(title, "Flo Fluid Simulator: %f FPS", 
			g_iFrameCount / g_timer.GetTime());
    glutSetWindowTitle(title);

    g_iFrameCount = 0;
    g_timer.Reset();
  }

}