void Icp::setScene(Matrix* coords, Matrix* normals, double probability) { if(coords->getCols()!=(size_t)_dim) { cout << "WARNING: Scene is not of correct dimensionality " << _dim << endl; return; } unsigned int sizeSource = coords->getRows(); _sizeScene = sizeSource; bool* mask = createSubsamplingMask(&_sizeScene, probability); unsigned int sizeNormals = _sizeSceneBuf; checkMemory(_sizeScene, _dim, _sizeSceneBuf, _scene); unsigned int idx = 0; for(unsigned int i=0; i<sizeSource; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _scene[idx][j] = (*coords)(i,j); idx++; } } if(_sceneTmp) System<double>::deallocate(_sceneTmp); System<double>::allocate(_sizeScene, _dim, _sceneTmp); System<double>::copy(_sizeScene, _dim, _scene, _sceneTmp); if(normals) { checkMemory(_sizeScene, _dim, sizeNormals, _normalsS); idx = 0; for(unsigned int i=0; i<sizeSource; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _normalsS[idx][j] = (*normals)(i,j); idx++; } } if(_normalsSTmp) System<double>::deallocate(_normalsSTmp); System<double>::allocate(_sizeScene, _dim, _normalsSTmp); System<double>::copy(_sizeScene, _dim, _normalsS, _normalsSTmp); } delete [] mask; }
void Icp::setScene(double* coords, double* normals, const unsigned int size, double probability) { if(size==0) { cout << "Scene of size 0 passed ... ignoring" << endl; return; } _sizeScene = size; bool* mask = createSubsamplingMask(&_sizeScene, probability); unsigned int sizeNormalsBuf = _sizeSceneBuf; checkMemory(_sizeScene, _dim, _sizeSceneBuf, _scene); unsigned int idx = 0; for(unsigned int i=0; i<size; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _scene[idx][j] = coords[_dim*i+j]; idx++; } } if(_sceneTmp) System<double>::deallocate(_sceneTmp); System<double>::allocate(_sizeScene, _dim, _sceneTmp); System<double>::copy(_sizeScene, _dim, _scene, _sceneTmp); if(normals) { checkMemory(_sizeScene, _dim, sizeNormalsBuf, _normalsS); idx = 0; for(unsigned int i=0; i<size; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _normalsS[idx][j] = normals[_dim*i+j]; idx++; } } if(_normalsSTmp) System<double>::deallocate(_normalsSTmp); System<double>::allocate(_sizeScene, _dim, _normalsSTmp); System<double>::copy(_sizeScene, _dim, _normalsS, _normalsSTmp); } delete [] mask; }
void Icp::setModel(Matrix* coords, Matrix* normals, double probability) { if(coords->getCols()!=(size_t)_dim) { cout << "WARNING: Model is not of correct dimensionality. Needed: " << _dim << endl; return; } unsigned int sizeSource = coords->getRows(); _sizeModel = sizeSource; bool* mask = createSubsamplingMask(&_sizeModel, probability); unsigned int sizeNormals = _sizeModelBuf; checkMemory(_sizeModel, _dim, _sizeModelBuf, _model); unsigned int idx = 0; for(unsigned int i=0; i<sizeSource; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _model[idx][j] = (*coords)(i,j); idx++; } } if(normals) { checkMemory(_sizeModel, _dim, sizeNormals, _normalsM); idx = 0; for(unsigned int i=0; i<sizeSource; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _normalsM[idx][j] = (*normals)(i,j); idx++; } } } _assigner->setModel(_model, idx); _estimator->setModel(_model, idx, _normalsM); delete [] mask; }
MemoryWatcher::MemoryWatcher(QObject *parent) : QObject(parent), m_timer(), m_warningThreshold(75), m_criticalThreshold(90), m_state(NoAlertState) { connect(&m_timer, SIGNAL(timeout()), this, SLOT(checkMemory())); }
JobBurner::JobBurner( const JobAssignment & jobAssignment, Slave * slave, int options ) : QObject( slave ) , mSlave( slave ) , mCmd( 0 ) , mJobAssignment( jobAssignment ) , mJob( jobAssignment.job() ) , mLoaded( false ) , mOutputTimer( 0 ) , mMemTimer( 0 ) , mLogFlushTimer( 0 ) , mCheckupTimer( 0 ) , mState( StateNew ) , mOptions( Options(options) ) , mCurrentCopy( 0 ) , mLogFilesReady( false ) , mLogFile( 0 ) , mLogStream( 0 ) , mCmdPid( 0 ) { mOutputTimer = new QTimer( this ); connect( mOutputTimer, SIGNAL( timeout() ), SLOT( updateOutput() ) ); mMemTimer = new QTimer( this ); connect( mMemTimer, SIGNAL( timeout() ), SLOT( checkMemory() ) ); mCheckupTimer = new QTimer( this ); connect( mCheckupTimer, SIGNAL( timeout() ), SLOT( checkup() ) ); mCheckupTimer->start(30000); /* Ensure we are actually assigned some tasks to work on */ mTaskAssignments = mJobAssignment.jobTaskAssignments(); if( mTaskAssignments.isEmpty() ) { jobErrored( QString("JobAssignment has no assigned tasks, Job Assignment key: %1").arg(mJobAssignment.key()) ); return; } // Double check that we are still assigned mJobAssignment.reload(); if( mJobAssignment.jobAssignmentStatus().status() != "ready" ) { LOG_1( "JobAssignment no longer ready, cancelling the burn" ); cancel(); return; } /* Make sure each of the tasks are still valid, some could have already been unassigned or cancelled */ /* Also verify that the jobtask record matches the assignment */ mTasks = JobTask::table()->records( mTaskAssignments.keys( JobTaskAssignment::schema()->field("fkeyjobtask")->pos() ), /*select=*/true, /*useCache=*/false ); foreach( JobTaskAssignment jta, mTaskAssignments ) { JobTask task = jta.jobTask(); if( jta.jobAssignmentStatus().status() != "ready" || task.status() != "assigned" || task.host() != Host::currentHost() ) { LOG_1( QString("JobTask no longer assigned, discarding. keyJobTask: %1 keyJobTaskAssignment: %2 jobtask status: %3 jobtaskassignment status: %4") .arg(task.key()).arg(jta.key()).arg(task.status()).arg(jta.jobAssignmentStatus().status()) ); mTaskAssignments -= jta; mTasks -= task; } }
/* Ensure a Condition is met */ bool Test::checkConditions(ppc::Interpreter::State &state, std::vector<Test::Condition> &conds) { for (auto &cond : conds) { switch (cond.type) { case ConditionType::SetRegister: if (cond.target.type != ValueType::Register) { return false; } if (!setRegister(state, cond.target.name, cond.value)) { throw new TestError(state, "Could not set register %s", cond.target.name.c_str()); } break; case ConditionType::CheckRegister: if (cond.target.type != ValueType::Register) { return false; } if (!checkRegister(state, cond.target.name, cond.value)) { throw new TestError(state, "Incorrect value in register %s", cond.target.name.c_str()); } break; case ConditionType::SetMemory: if (cond.target.type != ValueType::Address) { return false; } if (!setMemory(state, cond.target.value, cond.value)) { throw new TestError(state, "Could not set memory at 0x%X", translateAddress(cond.target.value)); } break; case ConditionType::CheckMemory: if (cond.target.type != ValueType::Address) { return false; } if (!checkMemory(state, cond.target.value, cond.value)) { throw new TestError(state, "Incorrect value at memory location 0x%X", translateAddress(cond.target.value)); } break; } } return true; }
void Icp::setModel(double* coords, double* normals, const unsigned int size, double probability) { _sizeModel = size; bool* mask = createSubsamplingMask(&_sizeModel, probability); unsigned int sizeNormalsBuf = _sizeModelBuf; checkMemory(_sizeModel, _dim, _sizeModelBuf, _model); unsigned int idx = 0; for(unsigned int i=0; i<size; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _model[idx][j] = coords[_dim*i+j]; idx++; } } if(normals) { checkMemory(_sizeModel, _dim, sizeNormalsBuf, _normalsM); idx = 0; for(unsigned int i=0; i<size; i++) { if(mask[i]) { for(unsigned int j=0; j<(unsigned int)_dim; j++) _normalsM[idx][j] = normals[_dim*i+j]; idx++; } } } _assigner->setModel(_model, idx); _estimator->setModel(_model, idx, _normalsM); delete [] mask; }
void HttpServer::watchDog() { int count = 0; while (!m_stopped) { if (RuntimeOption::DropCacheCycle > 0 && (count % RuntimeOption::DropCacheCycle) == 0) { // every hour dropCache(); } sleep(1); ++count; if (RuntimeOption::MaxRSSPollingCycle > 0 && (count % RuntimeOption::MaxRSSPollingCycle) == 0) { // every minute checkMemory(); } } }
void wicExit(int exitCode) { if (exitCode == 0) { zapOutputSystem(); zapCmdLineOptions(); zapTokPos(g_currPos); assert(isEmptySLList(g_logList)); zapSLList(g_logList, NULL); assert(isEmptySLList(g_dirList)); zapSLList(g_dirList, NULL); assert(isEmptySLList(g_commentList)); zapSLList(g_commentList, NULL); zapMemory(); zapDebug(); zapWicResources(); checkMemory(); } else { printf("WIC: Terminating with error...\n"); fcloseall(); } exit(exitCode); }
void HttpServer::watchDog() { int count = 0; bool noneed = false; while (!m_stopped && !noneed) { noneed = true; if (RuntimeOption::DropCacheCycle > 0) { noneed = false; if ((count % RuntimeOption::DropCacheCycle) == 0) { // every hour dropCache(); } } sleep(1); ++count; if (RuntimeOption::MaxRSSPollingCycle > 0) { noneed = false; if ((count % RuntimeOption::MaxRSSPollingCycle) == 0) { // every minute checkMemory(); } } } }
void ofApp::setup() { // SYSTEM ofSetLogLevel(OF_LOG_VERBOSE); ofHideCursor(); ofSetFrameRate(60); // SCREEN ofEnableAlphaBlending(); ofBackground(100); width = ofGetWindowWidth(); height = ofGetWindowHeight(); // STATE presenting = true; tooSunny = false; fboAge = 0; imageTimer = 0; imageMAX = 500; playState = 1; currentBrightness = 0; targetAlpha = 155; #ifdef INTERACTIVE // KINECT #ifdef KINECT kinect.setRegistration(true); kinect.init(); kinect.open(); if(kinect.isConnected()) { ofLogNotice() << "sensor-emitter dist: " << kinect.getSensorEmitterDistance() << "cm"; ofLogNotice() << "sensor-camera dist: " << kinect.getSensorCameraDistance() << "cm"; ofLogNotice() << "zero plane pixel size: " << kinect.getZeroPlanePixelSize() << "mm"; ofLogNotice() << "zero plane dist: " << kinect.getZeroPlaneDistance() << "mm"; } angle = 23; kinect.setCameraTiltAngle(angle); #else camera.setVerbose(true); camera.initGrabber(320, 240); #endif // CAPTURE SIZE int capture_width, capture_height; #ifdef KINECT capture_width = kinect.width; capture_height = kinect.height; #else capture_width = camera.width; capture_height = camera.height; #endif // OPENCV colorImg.allocate(capture_width, capture_height); grayImage.allocate(capture_width, capture_height); grayThreshNear.allocate(capture_width, capture_height); grayThreshFar.allocate(capture_width, capture_height); grayBg.allocate(capture_width, capture_height); grayDiff.allocate(capture_width, capture_height); closePoints.allocate(capture_width, capture_height, GL_RGBA32F_ARB); nearThreshold = 350; farThreshold = 112; bLearnBakground = true; threshold = 80; bThreshWithOpenCV = false; minBlob = 25; maxBlob = (capture_width * capture_height)/2; // FBO & GLSL SHADER setupGL(width, height); #else playState = 2; imageMAX = 2500; #endif // XML ASSETS BASEPATH = "../../../MEDIA/"; assets.loadFile("xml/assets.xml"); if( assets.loadFile("xml/assets.xml") ) { ofLog(OF_LOG_NOTICE, "Loaded xml file !!! \n"); loadFonts(); loadArtists(); loadAssets(); } else { ofLog(OF_LOG_ERROR, "UNABLE to load xml file :( \n"); } // INDEX currentIndex = 0; updateCurrentIndex(); // ASSETS brush.loadImage("mouse/brush.png"); stamp.loadImage("logo/stamp_white2.png"); demo.loadMovie(BASEPATH + "demo/studio_in_the_city_6_promo.mp4"); // MEMORY checkMemory(); cout << "Setup Is Done \n" << endl; }
//-------------------------------------------------------------- // update animation BOOL ChunkWorld::animate( double now, // current time (ms) double since) // milliseconds since last pass { BOOL viewChanged = false; m_chunkLock->lock(); // keep memory use under limits checkMemory(); resetRequestList(); // figure which chunk we are in int viewX = (int) floor(m_eyePt.x / CHUNK_SIZE); int viewZ = (int) floor(m_eyePt.z / CHUNK_SIZE); // for all coordinates in view list for (int i = m_viewListCount-1; i >= 0; i--) { ChunkOrigin* origin = &m_viewList[i]; int chunkX = CHUNK_SIZE*(viewX + origin->x); int chunkZ = CHUNK_SIZE*(viewZ + origin->z); // find/create chunk ChunkObj* chunk = createChunk(chunkX, chunkZ); // if chunk within view if (chunk->withinFrustum()) { switch (chunk->m_status) { case CHUNK_UNLOADED: // request the chunk (loads in memory) requestChunk(chunk); // request the neighbors loadNeighbors(chunk); break; case CHUNK_INMEMORY: // if all neighbors loaded, update chunk edges if (loadNeighbors(chunk)) { updateEdges(chunk); // request the chunk (loads in display) requestChunk(chunk); } break; case CHUNK_INDISPLAY: // if we have an update, use it if (!chunk->m_active && chunk->m_hasUpdate) { // mgDebug("use update on (%d, %d)", chunk->m_originX, chunk->m_originZ); int oldSize = chunk->getDisplayMemUsed(); chunk->useUpdate(); int size = chunk->getDisplayMemUsed(); m_displayMemUsed += size-oldSize; chunk->m_hasUpdate = false; } // if it needs an update, flag it if (!chunk->m_active && chunk->needsUpdate(m_eyePt)) { // mgDebug("wants update on (%d, %d)", chunk->m_originX, chunk->m_originZ); chunk->m_status = CHUNK_NEEDSUPDATE; chunk->m_eyePt = m_eyePt; m_requestList.addToTail(chunk); } // if still in display, animate it, since we will draw it if (chunk->m_status == CHUNK_INDISPLAY || chunk->m_status == CHUNK_NEEDSUPDATE) chunk->animate(now, since); break; case CHUNK_NEEDSUPDATE: // if needed update last pass, and not being processed, still needs update if (!chunk->m_active) { // mgDebug("still needs update on (%d, %d)", chunk->m_originX, chunk->m_originZ); m_requestList.addToTail(chunk); chunk->animate(now, since); } break; } // push to bottom of LRU list ChunkListNode* node = m_LRUList.find(chunk); if (node != NULL) m_LRUList.removeNode(node); m_LRUList.addToTail(chunk); } } if (m_chunksChanged) { viewChanged = true; m_chunksChanged = false; } m_chunkLock->unlock(); // if we requested chunks, activate worker threads if (!m_requestList.isEmpty()) { if (m_chunkThreads != NULL) { // signal the threads to look at requestList m_chunkEvent->signal(); } else { // process one request in this thread (no worker threads) ChunkObj* found = dequeueRequest(); if (found != NULL) processRequest(found); } } return viewChanged; }
void memory_free(char *p){ print_free_info(p); assert(checkMemory()); // first check - if p address is within our memory if (p <= memory || p > memory + MEMORY_SIZE) { printf("Address out of bound\n"); return; } // second check - if p is an address of previously allocated chunk // go through each busy block to check if p equals to any bool can_free = false; busy_block_t check = (busy_block_t) memory; // set check to point to beginning of memory free_block_t free_chunk = first_free; while (ULONG(check) < ULONG(p)) { if (ULONG(check) == ULONG(free_chunk)) { check = (busy_block_t) (ULONG(check) + ULONG(free_chunk->size)); free_chunk = free_chunk->next; } if (ULONG(check) < ULONG(memory + MEMORY_SIZE)) { if (ULONG(check + 1) == ULONG(p)) { can_free = true; break; } else { check = (busy_block_t) (ULONG(check + 1) + ULONG(check->size)); } } } if(!can_free) { // we cannot free random address printf("Cannot free address %lu - it was not allocated before\n", ULONG(p - memory)); return; } busy_block_t descriptor = (busy_block_t) (ULONG(p) - ULONG(sizeof(busy_block_s))); // shift a bit to find the busy_block int old_full_size = descriptor->size + sizeof(busy_block_s); free_block_t free_descriptor = (free_block_t) descriptor; free_descriptor->size = old_full_size; free_block_t current, prev_free; if (free_descriptor < first_free || first_free == NULL) { // our block is located before the first_free block // or first_free does not exist in the moment (all the memory is occupied) free_descriptor->next = first_free; first_free = free_descriptor; prev_free = NULL; } else { // our block is located AFTER the first_free block free_block_t last_free = NULL; for (current = first_free; current != NULL; current = current->next) { if (current < free_descriptor && current->next > free_descriptor) { // we found the right place in the free blocks list free_descriptor->next = current->next; current->next = free_descriptor; prev_free = current; break; } if (current->next == NULL) { last_free = current; } } if (last_free != NULL) { // if last_free is not NULL that means that we finished the for loop and didn't find a place // in the list of free blocks, so we just put a new free block in the end of it last_free->next = free_descriptor; free_descriptor->next = NULL; prev_free = last_free; } } // four options are possible: // 1. on the left and on the right from the freed block there are busy blocks // 2. there is a busy block on the left and a free block on the right // 3. there is a free block on the left and a busy block on the right // 4. there are free block on the left and on the right if (prev_free == NULL) { // our free_block is the first in the list if (ULONG(free_descriptor) + ULONG(free_descriptor->size) == ULONG(free_descriptor->next)) { free_descriptor->size += free_descriptor->next->size; free_descriptor->next = free_descriptor->next->next; } } else if (free_descriptor->next == NULL) { // our free_block is the last in the list if (ULONG(prev_free) + ULONG(prev_free->size) == ULONG(free_descriptor)) { prev_free->size += free_descriptor->size; prev_free->next = free_descriptor->next; } } else { // // our free_block is in the middle of the list // case #1 - do nothing // case #2 if (ULONG(free_descriptor) + ULONG(free_descriptor->size) == ULONG(free_descriptor->next) && ULONG(prev_free) + ULONG(prev_free->size) != ULONG(free_descriptor)) { free_descriptor->size += free_descriptor->next->size; free_descriptor->next = free_descriptor->next->next; } // case #3 if (ULONG(prev_free) + ULONG(prev_free->size) == ULONG(free_descriptor) && ULONG(free_descriptor) + ULONG(free_descriptor->size) != ULONG(free_descriptor->next)) { prev_free->size += free_descriptor->size; prev_free->next = free_descriptor->next; } // case #4 if (ULONG(free_descriptor) + ULONG(free_descriptor->size) == ULONG(free_descriptor->next) && ULONG(prev_free) + ULONG(prev_free->size) == ULONG(free_descriptor)) { prev_free->size += free_descriptor->size + free_descriptor->next->size; prev_free->next = free_descriptor->next->next; } } print_free_blocks(); if (statistics_on) { // TODO: add smth here } }