PAPI 简介

PAPI 简介#

安装 PAPI: Downloading-and-Installing-PAPI

要在 TVM 构建中包含 PAPI,需要在 config.cmake 中设置如下:

set(USE_PAPI ON)

如果 PAPI 被安装在非标准的地方,你可以像这样指定它的位置:

set(USE_PAPI path/to/papi.pc)

使用之前,还要配置环境:

export PAPI_DIR=<you location where PAPI is installed>
export PATH=${PAPI_DIR}/bin:$PATH
export LD_LIBRARY_PATH=${PAPI_DIR}/lib:$LD_LIBRARY_PATH
import set_env
import tvm
from tvm import relay
from tvm.relay.testing import mlp
from tvm.runtime import profiler_vm
import numpy as np

target = "llvm"
dev = tvm.cpu()
mod, params = mlp.get_workload(1)

exe = relay.vm.compile(mod, target, params=params)
vm = profiler_vm.VirtualMachineProfiler(exe, dev)

data = tvm.nd.array(np.random.rand(1, 1, 28, 28).astype("float32"), device=dev)
report = vm.profile(
    data,
    func_name="main",
    collectors=[tvm.runtime.profiling.PAPIMetricCollector()],
)
print(report)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 18
     12 vm = profiler_vm.VirtualMachineProfiler(exe, dev)
     14 data = tvm.nd.array(np.random.rand(1, 1, 28, 28).astype("float32"), device=dev)
     15 report = vm.profile(
     16     data,
     17     func_name="main",
---> 18     collectors=[tvm.runtime.profiling.PAPIMetricCollector()],
     19 )
     20 print(report)

AttributeError: module 'tvm.runtime.profiling' has no attribute 'PAPIMetricCollector'
import tvm.runtime.profiling