Programing

C 코드 루프 성능 [계속]

lottogame 2020. 9. 22. 20:56
반응형

C 코드 루프 성능 [계속]


이 질문은 Mystical의 조언에 따라 여기 내 질문에 계속됩니다.

C 코드 루프 성능


내 질문에 계속해서, 스칼라 명령어 대신 패킹 된 명령어를 사용하면 내장 함수를 사용하는 코드가 매우 비슷해 보일 것입니다.

for(int i=0; i<size; i+=16) {
    y1 = _mm_load_ps(output[i]);
    y4 = _mm_load_ps(output[i+12]);

    for(k=0; k<ksize; k++){
        for(l=0; l<ksize; l++){
            w  = _mm_set_ps1(weight[i+k+l]);

            x1 = _mm_load_ps(input[i+k+l]);
            y1 = _mm_add_ps(y1,_mm_mul_ps(w,x1));
            x4 = _mm_load_ps(input[i+k+l+12]);
            y4 = _mm_add_ps(y4,_mm_mul_ps(w,x4));
        }
    }
    _mm_store_ps(&output[i],y1);
    _mm_store_ps(&output[i+12],y4);
    }

이 커널의 측정 된 성능은주기 당 약 5.6 FP 작업이지만 스칼라 버전의 성능의 정확히 4 배, 즉주기 당 4.1,6 = 6,4 FP 작업이 될 것으로 예상합니다.

가중치 요소의 이동을 고려하면 (이를 지적 해 주셔서 감사합니다) 일정은 다음과 같습니다.

시간표

movss스칼라 가중치 값을 XMM 레지스터로 이동 한 다음 shufps전체 벡터에서이 스칼라 값을 복사하는 데 사용 하는 작업 후에 추가 명령이 있지만 일정이 변경되지 않은 것처럼 보입니다 . 가중치 벡터는 mulps부하에서 부동 소수점 도메인으로의 전환 지연을 고려하여 당분간 사용할 준비가 된 것 같으 므로 추가 지연이 발생하지 않아야합니다.

movaps(정렬, 포장 이동), addpsmulps이 중 여분의 대기 시간이 발생해서는 안 (어셈블리 코드로 확인)이 커널에 사용되는 지침은, 자신의 스칼라 버전과 동일한 지연 시간 및 처리량을 가지고있다.

이 커널이 얻을 수있는 최대 성능이주기 당 6.4FP 작업이고주기 당 5.6FP 작업으로 실행되고 있다고 가정 할 때 8주기 당 추가주기가 어디에 사용되는지 아는 사람이 있습니까?


참고로 실제 어셈블리는 다음과 같습니다.


Block x: 
  movapsx  (%rax,%rcx,4), %xmm0
  movapsx  0x10(%rax,%rcx,4), %xmm1
  movapsx  0x20(%rax,%rcx,4), %xmm2
  movapsx  0x30(%rax,%rcx,4), %xmm3
  movssl  (%rdx,%rcx,4), %xmm4
  inc %rcx
  shufps $0x0, %xmm4, %xmm4               {fill weight vector}
  cmp $0x32, %rcx 
  mulps %xmm4, %xmm0 
  mulps %xmm4, %xmm1
  mulps %xmm4, %xmm2 
  mulps %xmm3, %xmm4
  addps %xmm0, %xmm5 
  addps %xmm1, %xmm6 
  addps %xmm2, %xmm7 
  addps %xmm4, %xmm8 
  jl 0x401ad6 <Block x> 

Vtune에서 EMON 프로파일 링 또는 oprof와 같은 동등한 도구를 사용해보십시오.

EMON (Event Monitoring) 프로파일 링 => 시간 기반 도구와 비슷하지만 어떤 성능 이벤트가 문제를 일으키는 지 알려줄 수 있습니다. 하지만 튀어 나오는 특정 지침이 있는지 확인하려면 먼저 시간 기반 프로필로 시작해야합니다. (그리고 해당 IP에서 은퇴 중단이 얼마나 자주 발생했는지 알려주는 관련 이벤트가있을 수 있습니다.)

To use EMON profiling, you must run through a list of events, ranging from "the usual suspects" to ...

Here, I would start off with cache misses, alignment. I do not know if the processor you are using has a counter for RF port limitations - it should - but I added EMON profiling long ago, and I don't know how well they are keeping up by adding events appropriate for microarchitecture.

It may also be possible that it is a front end, instruction fetch, stall. How many bytes are in these instructions, anyway? There are EMON events for that, too.


Responding to comment that Nehalem VTune can't see L3 events: not true. Here is stuff I was adding to comment, but did not fit:

Actually, there ARE performance counters for the LL3 / L3$ / so-called Uncore. I would be immensely surprised if VTune doesn't support them. See http://software.intel.com/sites/products/collateral/hpc/vtune/performance_analysis_guide.pdf points to VTune and other tools such as PTU. In fact, even without LL3 events, as David Levinthal says: "the Intel® Core™ i7 processor has a “latency event” which is very similar to the Itanium® Processor Family Data EAR event. This event samples loads, recording the number of cycles between the execution of the instruction and actual deliver of the data. If the measured latency is larger than the minimum latency programmed into MSR 0x3f6, bits 15:0, then the counter is incremented. Counter overflow arms the PEBS mechanism and on the next event satisfying the latency threshold, the measured latency, the virtual or linear address and the data source are copied into 3 additional registers in the PEBS buffer. Because the virtual address is captured into a known location, the sampling driver could also execute a virtual to physical translation and capture the physical address. The physical address identifies the NUMA home location and in principle allows an analysis of the details of the cache occupancies." He also points, on page 35, to VTune events such as L3 CACHE_HIT_UNCORE_HIT and L3 CACHE_MISS_REMOTE_DRAM. Sometimes you need to look up the numeric codes and program them into VTune's lower level interface, but I think in this case it is visible in the pretty user interface.


OK, in http://software.intel.com/en-us/forums/showthread.php?t=77700&o=d&s=lr a VTune programmer in Russia (I think) "explains" that you can't sample on Uncore events.

He's wrong - you could, for example, enable only one CPU, and sample meaningfully. I also believe that there is the ability to mark L3 missing data as it returns to the CPU. In fact, overall the L3 knows which CPU it is returning data to, so you can definitely sample. You may not know which hyperthread, but again you can disable, go into single thread mode.

But it looks like, as is rather common, you would have to work AROUND VTune, not with it, to do this.

Try latency profiling first. That's entirely inside the CPU, and the VTune folks are unlikely to have messed it up too much.

그리고 다시 말씀 드리지만, 문제가 L3가 아닌 핵심에있을 가능성이 있습니다. 따라서 VTune이이를 처리 할 수 ​​있어야합니다.


Levinthal에 따라 "Cycle Accounting"을 사용해보십시오.

참고 URL : https://stackoverflow.com/questions/10007243/c-code-loop-performance-tinued

반응형