unsigned int NuiOpenCLPrefixSum::prefixSum(cl_kernel scan1Kernel, cl_kernel scan2Kernel, cl_mem d_input, cl_mem d_output) { scanExclusiveLocal1(d_input, scan1Kernel); const unsigned int cArrayLength = WORKGROUP_SIZE * 8; unsigned int batchSize = m_numElements / cArrayLength; scanExclusiveLocal2(batchSize, d_input, scan2Kernel); uniformUpdate(batchSize); generateValidIDs(d_output); return getValidCount(); }
void CacheManager::cacheOut(bool cleanup, size_t footprintLimit) { bool inactiveOnly = footprintLimit == 0; // Cache out only when footprint exceeds limit if (!cleanup) { if (inactiveOnly && _inactiveFootprint <= _inactiveFootprintLimit) return; else if (getValidFootprint() < footprintLimit) return; } // LOG_TIMESCOPE(0, "++ '%s' CacheOut", _name.c_str()); // forced : cache-out all active, inactive targets (except wired target) // inactive : cache-out only inactive targets vector<CacheHandle*>::type targets; for (HandleSet::iterator itr = _validHandles.begin(), end = _validHandles.end(); itr != end; ++itr) { CacheHandle* handle = *itr; // don't cache out wired handles if (handle->isCacheWired()) continue; int64 age = _frameNo - handle->_cacheFrameNo; bool active = age == 0; if (inactiveOnly && active) continue; if (!cleanup) { // Assume handles with zero footprint have some reason not to cache-out if (inactiveOnly && handle->getCacheFootprint() == 0) continue; // preserve active and have age limit left targets if (inactiveOnly && age <= _inactiveAgeLimit) continue; } targets.push_back(handle); } size_t oldFootprint = inactiveOnly ? _inactiveFootprint : getValidFootprint(); int killCount = 0; // remove old one first // NOTE: We may remove larger one first, but larger one tends to need more time to reload, // so we decided that old one will get removed first. std::sort(targets.begin(), targets.end(), olderHandleFirst); // Invalidate all inactive targets for (uint i=0; i<targets.size(); ++i) { CacheHandle* handle = targets[i]; if (handle->invalidate()) ++killCount; // If we acquire enough memory during this process, stop caching-out if (!cleanup) { int footprint = inactiveOnly ? _inactiveFootprint : getValidFootprint(); if (footprint <= _inactiveFootprintLimit) break; } } if (killCount > 0) { size_t footprint = inactiveOnly ? _inactiveFootprint : getValidFootprint(); size_t killBytes = oldFootprint - footprint; LOG(0, "++ %s: cache out %d (%dkb) -> %d wired (%dkb) + %d active (%dkb) + %d inactive (%dkb) = %d total (%dkb)\n", _name.c_str(), killCount, killBytes / 1024, _wiredCount, _wiredFootprint / 1024, _activeCount, _activeFootprint / 1024, _inactiveCount, _inactiveFootprint / 1024, getValidCount(), getValidFootprint() / 1024 ); if (_wiredCount + _activeCount + _inactiveCount != _validHandles.size()) { LOG(0, "*** %s: corrupted ValidCount: %d\n", _name.c_str(), _validHandles.size()); } } }