如何检测是否可以激活附加处理
动机有点难以解释,因此我将提供一个示例:假设您每秒收到大量样本,并且您的任务是对它们进行分类。
我们还可以这样说:您有两个分类器:heuristicFast 和 heuristicSlow。因此,可以说,对于每个运行 heuristicFast() 的样本,如果结果接近未定(假设分类器范围为 [0.45,0.55],其中 0 是第 1 类,1 是第 2 类),我会运行更精确的 heuristicSlow。
现在的问题是,这是实时系统,所以我想确保即使大量调用 heuristicFast 返回的结果在 [0.45,0.55] 范围内,我也不会过载 CPU(我正在使用线程)。
实现这一目标的最佳方法是什么?
我最好的想法是设置 heuristicSlow 的条目计数,然后如果条目计数 > 则不要输入它。 核心数/2
?
std::atomic<int> entrycount(0);
//...
if (classificationNotClear(result_heuristic_fast) && (entrycount<kMaxConcurrantCalls))
{
entrycount++;
final_result=heuristicSlow();
entrycount--;
}
else
final_result=result_heuristic_fast;
//...
Motivation is kind of hard to explain so I'll provide an example: Assume you receive high number of samples every second and your task is to classify them.
Lets also say this: You have two classifiers: heuristicFast, and heuristicSlow. So lets say that for every sample you run heuristicFast() and then if the result is close to undecided (lets say [0.45,0.55] range for classifier where 0 is class 1 and 1 is class2) I run more precise heuristicSlow.
Now the problem is that this is real time system so I want to be sure that I don't overload the CPUs (I'm using threading) even when high perchentage of calls to heuristicFast returns results in the [0.45,0.55] range.
What is the best way to accomplish this?
My best idea is to have entrycount for the heuristicSlow and then dont enter it if the entrycount is > number_of_cores / 2
?
std::atomic<int> entrycount(0);
//...
if (classificationNotClear(result_heuristic_fast) && (entrycount<kMaxConcurrantCalls))
{
entrycount++;
final_result=heuristicSlow();
entrycount--;
}
else
final_result=result_heuristic_fast;
//...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您正在构建实时系统,因此您拥有重要的可用信息:分类和启发式的最大允许运行时间。
您可以简单地计算完全快速启发式的剩余时间(总时间减去样本计数乘以快速启发式时间),并确定有多少慢速启发式应用程序适合该时间。将此数字写入计数器并递减。
Since you are building a real-time system, you have crucial information available: The maximum allowed running times for your classification and for both heuristics.
You could simply compute the leftover time for a fully fast heuristic ( total time minus sample count times fast heuristic time ) and determine how many applications of the slow heuristic fit into this time. Write this number into a counter and decrement.
更奇特的解决方案:
按不确定性(即按
abs(result-0.5)
)对快速启发式结果进行排序,并在剩余时间内对尽可能多的情况运行慢速启发式结果。Even fancier solution:
Sort your fast heuristic results by uncertainty (i.e. by
abs(result-0.5)
) and run the slow heuristic for as many cases as you've got time left.