gpt4 book ai didi

assembly - 如何定义一个用户定义的事件来被 PAPI 衡量?

转载 作者:行者123 更新时间:2023-12-04 15:47:51 25 4
gpt4 key购买 nike

当今的大多数处理器都配备了硬件性能计数器。此类计数器可用于对微架构事件进行计数,以便分析目标程序以提高其性能。通常,分析和分析是这些计数器的主要目标。

根据文献中的研究论文,这些计数器缺乏准确性。例如,如果我们想计算给定代码中退役指令的数量,该值可能会从运行更改为另一个扰动问题。已经讨论了几个指南来提高测量的准确性。监视多个事件可以更好地了解正在执行的程序,从而提高测量的准确性。

User-defined events for hardware performance monitoring 的作者已经提出了一种新方法,使用户能够定义自己的事件以供 PAPI (Performance API) 使用,这是一种广泛用于以简单方式访问硬件性能计数器的基础设施。不幸的是,这篇论文没有详细解释我们如何定义用户定义的事件并在我们的程序中使用它们。

例如(基于 PAPI),我试图定义一个涉及 n 个原生/预设事件的新事件,例如(PAPI_TOT_INS、PAPI_BR_TKN 和 PAPI_STR_INS),然后将其用作单个事件我的代码。


编辑:

根据上述论文,我设置了环境变量PAPI USER_EVENTS FILE来指示包含用户定义事件的文件,该文件将通过调用PAPI_library_init函数来初始化和解析。event_file 非常简单(仅用于测试):

#define a 5

tot_ins, PAPI_TOT_CYC|a|*

我的代码是这样的:

#include <stdio.h>
#include <stdlib.h>
#include <papi.h>


int main(int argc, char** argv) {

long_long val[10000];

int EventSet = PAPI_NULL;
long_long values[1];

PAPI_library_init(PAPI_VER_CURRENT);
PAPI_create_eventset(&EventSet);

//tot_ins is the name of the event defined in event-file
int counter_code;
PAPI_event_name_to_code("tot_ins",& counter_code);
printf("code =%x\n",counter_code);

PAPI_add_event(EventSet,counter_code);

int k;
int index=0;

for (k=0; k<5; k++)
{

PAPI_start(EventSet);

int i;

for (i=0; i<100; i++)
{
int x;
int y;
int z;

x=i+2;
y=x+i/15;
z=x/y;

}

PAPI_read(EventSet, values) ;
//printf("test number %d %lld \n",k,values[0]);
printf("%lld\n",values[0]);
PAPI_stop(EventSet, values) ;

printf("\n---------------------------------- \n");
}// end k

}

但是,counting 和 counter_code 的输出似乎都很奇怪

我在一个文本文件中定义了一个简单的事件(在 Linux Ubuntu 操作系统中)并设置了环境变量来指示这个文件。但是在代码中,两者都是

PAPI_event_name_to_code("tot_ins",& counter_code); //(retvalue=-7)

PAPI_add_event(EventSet,counter_code); //(retvalue=-10)

返回一个不等于 PAPI_OK 的值。

我们将不胜感激。

最佳答案

如果有人迷路并降落在这里:

我遇到了同样的问题并尝试设置环境变量 PAPI_USER_EVENTS_FILE 但它一开始没有用。然后我发现我设置了错误的 PMU 名称以及如何获得正确的 PMU 名称。我的 IvyBridge CPU 上的最小工作示例,它为 PAPI_DP_OPS 定义了一个别名:

# ivybridge
CPU,ivb
EVENT,USER_DP_OPS,NOT_DERIVED,PAPI_DP_OPS,NOTE,'FLOPS'

错误是我使用了 pmu_name 文件的内容,而不是 PAPI 使用的 pmu 名称:

cat /sys/devices/cpu/caps/pmu_name
ivybridge

您可以使用 papi_component_avail 查询可用的 PMU 名称,如手册页 man PAPI_derived_event_files 中所述。文件 papi_events.csv(见下文)包含预设事件和 PAPI 使用的所有 PMU 名称。手册页还描述了用户事件文件的语法。 papi_avail 将显示添加的用户事件(如果有效)。

但是,我认为它有问题:例如别名为 dp 操作显示完全不同的数字。我认为应该改进有关此功能的文档,用户定义的派生事件文件的手册页不包含如何指定文件。


PAPI_set_opt,如引用论文中描述的替代方案,目前 (6.0.0.1) 不支持作为指定用户定义事件文件的方式,并将返回错误编号(错误字符串'null'): (来自papi_preset.c)

  • There are three possible sources of input for preset event definitions. The code will first look for the environment variable "PAPI_CSV_EVENT_FILE". If found its value will be used as the pathname of where to get the preset information. If not found, the code will look for a built in table containing preset events. If the built in table was not created during the build of PAPI then the code will build a pathname of the form "PAPI_DATADIR/PAPI_EVENT_FILE". Each of these are build variables, the PAPI_DATADIR variable can be given a value during the configure of PAPI at build time, and the PAPI_EVENT_FILE variable has a hard coded value of "papi_events.csv".
  • There is only one way to define user events. The code will look for an environment variable "PAPI_USER_EVENTS_FILE". If found its value will be used as the pathname of a file which contains user event definitions. The events defined in this file will be added to the ones known by PAPI when the call to PAPI_library_init is done.
  • TODO:
  • Look into restoring the ability to specify a user defined event file with a call to PAPI_set_opt(PAPI_USER_EVENTS_FILE).
  • This needs to figure out how to pass a pmu name (could use default pmu from component 0) to this function.
  • Currently code elsewhere in PAPI limits the events which preset and user events can depend on to those events which are known to component 0. This possibly could be relaxed to allow events from different components. But since all the events used by any derived event must be added to the same eventset, it will always be a requirement that all events used by a given derived event must be from the same component.

关于assembly - 如何定义一个用户定义的事件来被 PAPI 衡量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55002673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com