void OpenJpegDecoder::Work() { while (ShouldRun()) { WaitForRequests(); DecodeRequestPtr request = GetNextRequest<DecodeRequest>(); if (request) { // Wait if "too many" results already produced, to prevent slowing down the main thread with // too many texture creations per frame Foundation::ThreadTaskManager* manager = GetThreadTaskManager(); if (manager) { for (;;) { uint results = manager->GetNumResults(GetTaskDescription()); if (results < decodes_per_frame_) break; if (!ShouldRun()) return; boost::this_thread::sleep(boost::posix_time::milliseconds(20)); } } { PROFILE(OpenJpegDecoder_Decode); PerformDecode(request); } } RESETPROFILER } }
int main(int argc, char* argv[]) { if (gBenchmarks->empty()) { fprintf(stderr, "No benchmarks registered!\n"); exit(EXIT_FAILURE); } bool need_header = true; for (auto b : *gBenchmarks) { if (ShouldRun(b, argc, argv)) { if (need_header) { printf("%-25s %10s %10s\n", "", "iterations", "ns/op"); fflush(stdout); need_header = false; } Run(b); } } if (need_header) { fprintf(stderr, "No matching benchmarks!\n"); fprintf(stderr, "Available benchmarks:\n"); for (auto b : *gBenchmarks) { fprintf(stderr, " %s\n", b->Name()); } exit(EXIT_FAILURE); } return 0; }
// static bool VP9Benchmark::IsVP9DecodeFast(bool aDefault) { #if defined(MOZ_WIDGET_ANDROID) return false; #else if (!ShouldRun()) { return false; } static StaticMutex sMutex; uint32_t decodeFps = StaticPrefs::MediaBenchmarkVp9Fps(); uint32_t hadRecentUpdate = StaticPrefs::MediaBenchmarkVp9Versioncheck(); bool needBenchmark; { StaticMutexAutoLock lock(sMutex); needBenchmark = !sHasRunTest && (decodeFps == 0 || hadRecentUpdate != sBenchmarkVersionID); sHasRunTest = true; } if (needBenchmark) { RefPtr<WebMDemuxer> demuxer = new WebMDemuxer( new BufferMediaResource(sWebMSample, sizeof(sWebMSample))); RefPtr<Benchmark> estimiser = new Benchmark( demuxer, {StaticPrefs::MediaBenchmarkFrames(), // frames to measure 1, // start benchmarking after decoding this frame. 8, // loop after decoding that many frames. TimeDuration::FromMilliseconds(StaticPrefs::MediaBenchmarkTimeout())}); estimiser->Run()->Then( AbstractThread::MainThread(), __func__, [](uint32_t aDecodeFps) { if (XRE_IsContentProcess()) { dom::ContentChild* contentChild = dom::ContentChild::GetSingleton(); if (contentChild) { contentChild->SendNotifyBenchmarkResult(NS_LITERAL_STRING("VP9"), aDecodeFps); } } else { Preferences::SetUint(sBenchmarkFpsPref, aDecodeFps); Preferences::SetUint(sBenchmarkFpsVersionCheck, sBenchmarkVersionID); } Telemetry::Accumulate(Telemetry::HistogramID::VIDEO_VP9_BENCHMARK_FPS, aDecodeFps); }, []() {}); } if (decodeFps == 0) { return aDefault; } return decodeFps >= StaticPrefs::MediaBenchmarkVp9Threshold(); #endif }
void VorbisDecoder::Work() { while (ShouldRun()) { WaitForRequests(); VorbisDecodeRequestPtr request = GetNextRequest<VorbisDecodeRequest>(); if (request) { { PROFILE(VorbisDecoder_Decode); PerformDecode(request); } } RESETPROFILER } }
void DCpuSampler::SettingsChanged() { // Call with interrupts disabled if (ShouldRun()) { #if FSHELL_PLATFORM_SYMTB >= 92 if (!iTimer.IsPending()) #else if (iTimer.iState == NTimer::EIdle) #endif { iContext = NULL; iTimerHeartbeat = 0; iTimer.OneShot(1); } } else { iTimer.Cancel(); } }
// static uint32_t VP9Benchmark::MediaBenchmarkVp9Fps() { if (!ShouldRun()) { return 0; } return StaticPrefs::MediaBenchmarkVp9Fps(); }
void CL_PingPong::Start(unsigned int num_runs, const std::vector<int> options) { int ret = 0; int wg = 256; auto tid = this_thread::get_id(); std::cout << DASH50 << "\n Ping Pong Test\n"; // decode options uint16_t power; if (options.size() > 0) { power = options[0]; } else { cout << "Power of numbers to swap?: (0 for default)" << std::endl; power = promptValidated<int, int>("Power: ", [](int i) { return (i >= 0 && i <= 256); }); } if (power == 0) { power = DEFAULTPOWER; } // load a pointelss kernel auto prog = cl::load_program("hello.cl", ctx, CtxDevices); cl_kernel kernel = clCreateKernel(prog, "pointless", &ret); assert(ret == CL_SUCCESS); /* Create Random Numbers */ cl_uint maxN = 1 << power; size_t szPC = maxN * sizeof(cl_uint); cl_uint *rndData = new cl_uint[maxN]; // create buffers cl_mem buf1 = clCreateBuffer(ctx, CL_MEM_READ_WRITE, szPC, NULL, &ret); cl_mem buf2 = clCreateBuffer(ctx, CL_MEM_READ_WRITE, szPC, NULL, &ret); // try to place on correct gpus, broken AF // clEnqueueMigrateMemObjects(cq[0], 1, &buf1, CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED, NULL, // NULL, NULL); // clEnqueueMigrateMemObjects(cq[1], 1, &buf2, CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED, NULL, // NULL, NULL); // send data to buf 1 ret = clEnqueueWriteBuffer(cq[0], buf1, CL_TRUE, 0, szPC, &rndData[0], 0, NULL, NULL); // blocking ret = clFinish(cq[0]); // Wait untill all commands executed. assert(ret == CL_SUCCESS); unsigned int runs = 0; running = true; should_run = true; ResultFile r; r.name = "CLPingPong" + to_string(maxN); r.headdings = {"A to B", "B to A"}; while (ShouldRun() && runs < num_runs) { vector<unsigned long long> times; unsigned int percentDone = (unsigned int)(floor(((float)runs / (float)num_runs) * 100.0f)); cout << "\r" << Spinner(runs) << "\t" << runs << "\tPercent Done: " << percentDone << "%" << std::flush; // make new numbers for (cl_uint i = 0; i < maxN; i++) { cl_uint x = (cl_uint)0; rndData[i] = (x << 14) | ((cl_uint)rand() & 0x3FFF); rndData[i] = (x << 14) | ((cl_uint)rand() & 0x3FFF); } Timer time_swap_a; ret = clEnqueueWriteBuffer(cq[1], buf2, CL_TRUE, 0, szPC, buf1, 0, NULL, NULL); // blocking for (auto q : cq) { ret = clFinish(q); // Wait untill all commands executed. assert(ret == CL_SUCCESS); } ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)(&buf2)); assert(ret == CL_SUCCESS); size_t global_work_size[1] = {maxN}; ret = clEnqueueNDRangeKernel(cq[1], kernel, 1, // work_dim 0, // global_work_offset global_work_size, // global_work_size NULL, // local_work_size 0, // num_events_in_wait_list NULL, // event_wait_list NULL // event ); for (auto q : cq) { ret = clFinish(q); // Wait untill all commands executed. assert(ret == CL_SUCCESS); } time_swap_a.Stop(); times.push_back(time_swap_a.Duration_NS()); Timer time_swap_b; ret = clEnqueueWriteBuffer(cq[0], buf1, CL_TRUE, 0, szPC, buf2, 0, NULL, NULL); // blocking for (auto q : cq) { ret = clFinish(q); // Wait untill all commands executed. assert(ret == CL_SUCCESS); } ret = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)(&buf1)); assert(ret == CL_SUCCESS); ret = clEnqueueNDRangeKernel(cq[0], kernel, 1, // work_dim 0, // global_work_offset global_work_size, // global_work_size NULL, // local_work_size 0, // num_events_in_wait_list NULL, // event_wait_list NULL // event ); for (auto q : cq) { ret = clFinish(q); // Wait untill all commands executed. assert(ret == CL_SUCCESS); } time_swap_b.Stop(); times.push_back(time_swap_b.Duration_NS()); r.times.push_back(times); ++runs; } delete[] rndData; r.CalcAvg(); r.PrintToCSV(r.name); cout << "\n PingPong finished\n"; running = false; };