void OnlineFileRequest::schedule(optional<Timestamp> expires) {
    if (impl.isPending(this) || impl.isActive(this)) {
        // There's already a request in progress; don't start another one.
        return;
    }

    // If we're not being asked for a forced refresh, calculate a timeout that depends on how many
    // consecutive errors we've encountered, and on the expiration time, if present.
    Duration timeout = std::min(
                            http::errorRetryTimeout(failedRequestReason, failedRequests, retryAfter),
                            http::expirationTimeout(expires, expiredRequests));

    if (timeout == Duration::max()) {
        return;
    }

    // Emulate a Connection error when the Offline mode is forced with
    // a really long timeout. The request will get re-triggered when
    // the NetworkStatus is set back to Online.
    if (NetworkStatus::Get() == NetworkStatus::Status::Offline) {
        failedRequestReason = Response::Error::Reason::Connection;
        failedRequests = 1;
        timeout = Duration::max();
    }

    timer.start(timeout, Duration::zero(), [&] {
        impl.activateOrQueueRequest(this);
    });
}
void Engine::setFPS(float dt) {
    static Util::Timer delay;
    static float sumDelta = 0.f;
    sumDelta += dt;
    if(!delay.running()) delay.start();
    static std::ostringstream str;
    if(delay.isElapsed(200)) {
        str.str("");
        str << "Trace Engine - " << (int)(1.f/dt) << " FPS";
        renderSystem_->setWindowTitle(str.str().c_str());
        str.str("");
        str << (int)(1.f/dt);
        delay.stop();
    }

//	fontRenderer_->renderText(str.str(), glm::vec3(10.f, 20.f, 50.f), "consola.ttf", glm::vec4(1.f, 1.f, 1.f, 1.f), 20);
//	fontRenderer_->renderText(Util::Str::formatTime(static_cast<int>(sumDelta)), glm::vec3(renderSystem_->resolution().x-100, 20.f, 50.f), "consola.ttf", glm::vec4(1.f, 1.f, 1.f, 1.f), 20);
}
Beispiel #3
0
	/*!
	 * \brief Constructor
	 * \param procedure Procedure to analyze
	 */
	LiveVariables::LiveVariables(const IR::Procedure &procedure, const FlowGraph &flowGraph)
		: mProcedure(procedure)
	{
		Util::Timer timer;
		timer.start();

		// Construct the set of all variables in the procedure
		std::set<const IR::Symbol*> all;
		for(const std::unique_ptr<IR::Symbol> &symbol : mProcedure.symbols()) {
			all.insert(symbol.get());
		}

		// Construct gen/kill sets for data flow analysis.
		std::map<const IR::Entry*, std::set<const IR::Symbol*>> gen;
		std::map<const IR::Entry*, std::set<const IR::Symbol*>> kill;
		for(const IR::Entry *entry : mProcedure.entries()) {
			for(const IR::Symbol *symbol : all) {
				std::set<const IR::Symbol*> &g = gen[entry];
				if(entry->uses(symbol)) {
					// An entry which uses a symbol adds that symbol to the set of live symbols
					g.insert(symbol);
				}

				const IR::Symbol *assign = entry->assign();
				if(assign && g.find(assign) == g.end()) {
					// An entry which assigns to a symbol and does not use it kills that symbol
					// from the live symbol set
					kill[entry].insert(assign);
				}
			}
		}

		// Perform a backwards data flow analysis on the procedure, using the gen and kill sets
		// constructed above.
		DataFlow<const IR::Symbol*> dataFlow;
		mMap = dataFlow.analyze(flowGraph, gen, kill, all, DataFlow<const IR::Symbol*>::Meet::Union, DataFlow<const IR::Symbol*>::Direction::Backward);

		Util::log("opt.time") << "  LiveVariables(" << mProcedure.name() << "): " << timer.stop() << "ms" << std::endl;
	}
Beispiel #4
0
 // Sets the timeout period for the play in seconds
 inline void startTimer(void)
 {
   timer.start();
   int tm = timer.split();
   lastRoleReassignTime = tm - 2*roleReassignPeriod; //so that 1st call to timedOut gives shouldRolesReassign = true. 2* just to be safe
 }
Beispiel #5
0
int main(int argc, char** argv)
{	
	// LOAD OBJ
    Manifold m;
    if(argc>1)
	{
		ArgExtracter ae(argc, argv);
		
		do_aabb = ae.extract("-A");
		do_obb = ae.extract("-O");
		ae.extract("-x", vol_dim[0]);
		ae.extract("-y", vol_dim[1]);
		ae.extract("-z", vol_dim[2]);
		do_ray_tests = ae.extract("-R");
		flip_normals = ae.extract("-f");
		string file = ae.get_last_arg();
        
        cout << "loading " << file << "... " << flush; 
		load(file, m);
        cout << " done" << endl;
	}
    else
	{
		string fn("../../data/bunny-little.x3d");
		x3d_load(fn, m);
	}
	cout << "Volume dimensions " << vol_dim << endl;
	if(!valid(m))
	{
		cout << "Not a valid manifold" << endl;
		exit(0);
	}
	triangulate_by_edge_face_split(m);
	
	Vec3d p0, p7;
	bbox(m, p0, p7);
	
	Mat4x4d T = fit_bounding_volume(p0,p7,10);
    
    cout << "Transformation " << T << endl;
	
	for(VertexIDIterator v = m.vertices_begin(); v != m.vertices_end(); ++v)
		m.pos(*v) = T.mul_3D_point(m.pos(*v));
	
	
 	RGridf grid(vol_dim,FLT_MAX);
	Util::Timer tim;
	
	
	float T_build_obb=0, T_build_aabb=0, T_dist_obb=0, 
		T_dist_aabb=0, T_ray_obb=0, T_ray_aabb=0;
	
	if(do_obb)
	{
		cout << "Building OBB Tree" << endl;
		tim.start();
		OBBTree obb_tree;
		build_OBBTree(m, obb_tree);
		T_build_obb = tim.get_secs();
		
		cout << "Computing distances from OBB Tree" << endl;
		tim.start();
		DistCompCache<OBBTree> dist(&obb_tree);
		for_each_voxel(grid, dist);
		T_dist_obb = tim.get_secs();
		
		cout << "Saving distance field" << endl;
		save_raw_float("obb_dist.raw", grid);
		
		if(do_ray_tests)
		{
			cout << "Ray tests on OBB Tree" << endl;
			tim.start();
			RayCast<OBBTree> ray(&obb_tree);
			for_each_voxel(grid, ray);
			T_ray_obb = tim.get_secs();
			
			cout << "Saving ray volume" << endl;
			save_raw_float("obb_ray.raw", grid);
		}
	}
	
	if(do_aabb)
	{
		cout << "Building AABB Tree" << endl;
		tim.start();
		AABBTree aabb_tree;
		build_AABBTree(m, aabb_tree);
		T_build_aabb = tim.get_secs();
		
		cout << "Computing distances from AABB Tree" << endl;
		tim.start();
		DistCompCache<AABBTree> dist(&aabb_tree);
		for_each_voxel(grid, dist);
		T_dist_aabb = tim.get_secs();
		
		cout << "Saving distance field" << endl;
		save_raw_float("aabb_dist.raw", grid);
		
		if(do_ray_tests)
		{
			cout << "Ray tests on AABB tree" << endl;
			tim.start();
			RayCast<AABBTree> ray(&aabb_tree);
			for_each_voxel(grid, ray);
			T_ray_aabb = tim.get_secs();
			
			cout << "Saving ray volume" << endl;
			save_raw_float("aabb_ray.raw", grid);
		}
	}
	cout.width(10);
	cout << "Poly";
	cout.width(11);
	cout <<"build_obb";
	cout.width(12);
	cout << "build_aabb";
	cout.width(10);
	cout << "dist_obb" ;
	cout.width(10);
	cout << "dist_aabb";
	cout.width(10);
	cout << "ray_obb" ;
	cout.width(10);
	cout << "ray_aabb";
	cout << endl;
	
	cout.precision(4);
	cout.width(10);
	cout << m.no_faces() << " ";
	cout.width(10);
	cout << T_build_obb;
	cout.width(12);
	cout << T_build_aabb;
	cout.width(10);
	cout << T_dist_obb;
	cout.width(10);
	cout << T_dist_aabb;
	cout.width(10);
	cout << T_ray_obb;
	cout.width(10);
	cout << T_ray_aabb;
	cout << endl;
}
Beispiel #6
0
	/*!
	 * \brief Optimize a program
	 * \param program Program to optimize
	 */
	void Optimizer::optimize(IR::Program &program)
	{
		std::vector<Transform::Transform*> startingTransforms;
		std::map<Transform::Transform*, std::vector<Transform::Transform*>> transformMap;

		// Build the list of all transforms
		startingTransforms.push_back(Transform::CopyProp::instance());
		startingTransforms.push_back(Transform::ConstantProp::instance());
		startingTransforms.push_back(Transform::DeadCodeElimination::instance());
		startingTransforms.push_back(Transform::ThreadJumps::instance());
		startingTransforms.push_back(Transform::LoopInvariantCodeMotion::instance());
		startingTransforms.push_back(Transform::CommonSubexpressionElimination::instance());

		// Transforms to run after CopyProp
		transformMap[Transform::CopyProp::instance()].push_back(Transform::DeadCodeElimination::instance());

		// Transforms to run after Constant Prop
		transformMap[Transform::ConstantProp::instance()].push_back(Transform::DeadCodeElimination::instance());

		// Transforms to run after DeadCodeElimination
		transformMap[Transform::DeadCodeElimination::instance()].push_back(Transform::ConstantProp::instance());
		transformMap[Transform::DeadCodeElimination::instance()].push_back(Transform::CopyProp::instance());

		// Transforms to run after CommonSubexpressionElimination
		transformMap[Transform::CommonSubexpressionElimination::instance()].push_back(Transform::CopyProp::instance());

		// Optimize each procedure in turn
		for(std::unique_ptr<IR::Procedure> &procedure : program.procedures()) {
			Analysis::Analysis analysis(*procedure);

			// Queue of transformations to run
			Util::UniqueQueue<Transform::Transform*> transforms;

			// Start by running each optimization pass once
			for(Transform::Transform *transform : startingTransforms) {
				transforms.push(transform);
			}

			Util::log("opt") << "Optimizations (" << procedure->name() << "):" << std::endl;

			// Run optimization passes until there are none left
			while(!transforms.empty()) {
				Transform::Transform *transform = transforms.front();
				transforms.pop();

				// Run the transform
				Util::Timer timer;
				timer.start();
				bool changed = transform->transform(*procedure, analysis);
				Util::log("opt.time") << transform->name() << ": " << timer.stop() << "ms" << std::endl;

				if(changed) {
					procedure->print(Util::log("opt.ir"));
					Util::log("opt.ir") << std::endl;

					// If the transform changed the IR, add its follow-up transformations to the queue
					std::vector<Transform::Transform*> &newTransforms = transformMap[transform];
					for(Transform::Transform *newTransform : newTransforms) {
						transforms.push(newTransform);
					}
				}
			}

			Util::log("opt") << std::endl;
		}
	}
Beispiel #7
0
 // Sets the timeout period for the play in seconds
 inline void startTimer(void)
 {
   timer.start();
 }