見積依頼

株式会社HPCソリューションズ
2011年08月31日

1. PAPIとは!?

Performance APIはCPUに搭載されているCPUカウンタを使用し、キャッシュヒット率、ミス率、FLOPSなどを計測します。 これを利用することにより、CPUの利用率を知ることが出来ます。 PAPIの最新バージョンはhttps://icl.cs.utk.edu/papi/index.htmlからダウンロードしてください。

2. 動作環境

Kernelバージョンによって異なります。ここでは、Kernel2.6.30以上を対象とします。
PAPIのバージョンは4.1.3を使用しました。

3. 導入手順

導入手順は

./configure
make
make test
make fulltest
make install-all

となります。 なお、make fulltest の時、

cd ctests; make CC=”gcc” CC_R=”gcc -pthread” CFLAGS=”-I.. -g -DSTATIC_PAPI_EVENTS_TABLE -DPEINCLUDE=\”/usr/include/linux/perf_event.h\” -D_REENTRANT -D_GNU_SOURCE -DUSE_COMPILER_TLS -Wall -I/home/ohta/Program/PAPI/papi-4.1.3/src/libpfm-3.y/include -DSUBSTRATE_USES_LIBPFM -Wextra -DPAPI_NO_MEMORY_MANAGEMENT” TOPTFLAGS=”-O0″ SMPCFLGS=”” OMPCFLGS=”-fopenmp” NOOPT=”” LDFLAGS=” ” LDL=”-ldl” LIBRARY=”../libpapi.a” papi_api serial forkexec_tests overflow_tests profile_tests attach multiplex_and_pthreads shared
~中略~
Running Fortran Tests
Running ftests/fdmemtest:fdmemtest.F PASSED
Running ftests/cost:cost.F PASSED
Running ftests/description:description.F PASSED
Running ftests/clockres:clockres.F PASSED
Running ftests/second:second.F PASSED
Running ftests/first:first.F PASSED
Running ftests/zero:zero.F PASSED
Running ftests/fmatrixpapi:fmatrixpapi.F PASSED
Running ftests/fmatrixlowpapi:fmatrixlowpapi.F PASSED
Running ftests/strtest:strtest.F PASSED
Running ftests/case2:case2.F PASSED
Running ftests/case1:case1.F PASSED
Running ftests/tenth:tenth.F PASSED
Running ftests/fmultiplex1:fmultiplex1.F PASSED
Running ftests/johnmay2:johnmay2.F PASSED
Running ftests/avail:avail.F PASSED
Running ftests/fmatrixpapi2:fmatrixpapi2.F PASSED
Running ftests/eventname:eventname.F PASSED
Running ftests/flops:flops.F PASSED
Running ftests/highlevel:highlevel.F PASSED
Running ftests/fmultiplex2:fmultiplex2.F PASSED
Running ftests/accum:accum.F PASSED

と出ると成功です。
なお、PASSEDと出ないところもあります。
CPUIDに依存します。

4. 確認

コマンド、papi_availで確認が出来ます。

papi_avail

このコマンドではソースコードから呼ぶことが出来る関数が確認できます。

Available events and hardware information.
——————————————————————————–
PAPI Version : 4.1.3.0
Vendor string and code : GenuineIntel (1)
Model string and code : Intel(R) Xeon(R) CPU X3450 @ 2.67GHz (30)
CPU Revision : 5.000000
CPUID Info : Family: 6 Model: 30 Stepping: 5
CPU Megahertz : 1197.000000
CPU Clock Megahertz : 1197
Hdw Threads per core : 1
Cores per Socket : 4
NUMA Nodes : 1
CPU’s per Node : 4
Total CPU’s : 4
Number Hardware Counters : 16
Max Multiplex Counters : 512
——————————————————————————–
The following correspond to fields in the PAPI_event_info_t structure.
Name Code Avail Deriv Description (Note)
PAPI_L1_DCM 0x80000000 Yes No Level 1 data cache misses
PAPI_L1_ICM 0x80000001 Yes No Level 1 instruction cache misses
PAPI_L2_DCM 0x80000002 Yes Yes Level 2 data cache misses
PAPI_L2_ICM 0x80000003 Yes No Level 2 instruction cache misses
~中略~
PAPI_SP_OPS 0x80000067 Yes Yes Floating point operations; optimized to count scaled single precision vector operations
PAPI_DP_OPS 0x80000068 Yes Yes Floating point operations; optimized to count scaled double precision vector operations
PAPI_VEC_SP 0x80000069 Yes No Single precision vector/SIMD instructions
PAPI_VEC_DP 0x8000006a Yes No Double precision vector/SIMD instructions
————————————————————————-
Of 107 possible events, 63 are available, of which 17 are derived.
avail.c                  PASSED

ここでは、107個のイベントのうち、63個のイベントが利用できることが確認できます。
CPUIDに依存します。

5. 利用方法

簡単なFLOPSを求めるプログラムをFortran95を使用して紹介致します。
PAPIには2種類の関数(High Level関数とLow Level関数)があります。
このうち、High Level関数を使用して、FLOPSを求めることが出来ます。
PAPIf_flips関数をソースコードから呼び出して、FLOPSを求めてみます。

program papi_test
include “f90papi.h”
integer, parameter :: index=100
real*4 matrixa(index,index)
real*4 matrixb(index,index)
real*4 mres(index,index)
real*4 proc_time
real*4 mflops
real*4 real_time
integer*8 flpins
integer i,j,k,retval

call PAPIf_library_init(retval)
do i=1,index
do j=1,index
 matrixa(i,j) = i+j
 matrixb(i,j) = j-i
 mres(i,j) = 0.0
end do
end do

call PAPIf_flips( real_time, proc_time, flpins, mflops, retval )

do i=1,index
do j=1,index
  do k=1,index
    mres(i,j) = mres(i,j) + matrixa(i,k)*matrixb(k,j)
  end do
end do
end do

call PAPIf_flips( real_time, proc_time, flpins, mflops, retval)

print *, ‘Real_time: ‘, real_time
print *, ‘ Proc_time: ‘, proc_time
print *, ‘ Total flpins: ‘, flpins
print *, ‘ MFLOPS: ‘, mflops
end program papi_test

FLOPSを求めたい個所にAPI、PAPIf_flips関数をはさむことにより、FLOPSを求めることが出来ます。

上記のプログラムを動かすと


[ohta@ml110g6 ~]$ ./papi-test

Real_time: 3.8600000E-04

Proc_time: 8.5215206E-04

Total flpins: 500116

MFLOPS: 586.8859

[ohta@ml110g6 ~]$

と言う結果を得ることが出来ます。