2012-10-20 2 views
2

병렬 문자열 검색을 수행 할 커널을 빌드하려고합니다. 이를 위해 필자는 유한 상태 시스템을 사용하는 경향이 있습니다. fsm의 전이 테이블은 커널 인수 상태에 있습니다. 코드 : 나는 iocgui를 사용하여이 커널을 컴파일하는 경우OpenCL 커널이 벡터화되지 않았습니다.

__kernel void Find (__constant char *text, 
     const  int offset, 
     const  int tlenght, 
     __constant char *characters, 
     const int clength, 
     const int maxlength, 
     __constant int *states, 
     const int statesdim){ 

    private char c; 
    private int state; 
    private const int id = get_global_id(0); 

    if (id<(tlenght-maxlength)) { 

     private int cIndex,sd,s,k; 

     for (int i=0; i<maxlength; i++) { 

      c = text[i+offset]; 

      cIndex = -1; 

      for (int j=0; j<clength; j++) { 

       if (characters[j]==c) { 
        cIndex = j; 
       }  
      }  

      if (cIndex==-1) { 

       state = 0; 
       break; 

      } else { 

       s = states[state+cIndex*statesdim]; 

      } 

      if (state<=0) break; 

     }  
    } 
} 

, 나는 결과를 얻을 :

state = states[state+cIndex*statesdim]; 

: 나는 새로운 상태가 결정되는 줄을 변경

Using default instruction set architecture. 
Intel OpenCL CPU device was found! 
Device name: Pentium(R) Dual-Core CPU  T4400 @ 2.20GHz 
Device version: OpenCL 1.1 (Build 31360.31426) 
Device vendor: Intel(R) Corporation 
Device profile: FULL_PROFILE 
Build started 
Kernel <Find> was successfully vectorized 
Done. 
Build succeeded! 

결과는 다음과 같습니다.

Using default instruction set architecture. 
Intel OpenCL CPU device was found! 
Device name: Pentium(R) Dual-Core CPU  T4400 @ 2.20GHz 
Device version: OpenCL 1.1 (Build 31360.31426) 
Device vendor: Intel(R) Corporation 
Device profile: FULL_PROFILE 
Build started 
Kernel <Find> was not vectorized 
Done. 
Build succeeded! 

답변

1

성명

X = states[state+cIndex*statesdim]; 

인덱스가 반드시 스레드에서 결과 바이트에 액세스하는 것으로 평가되지는 않으므로 벡터화 할 수 없습니다.

첫 번째 커널에는 대상 변수 s이 있으며 전역 메모리에 다시 쓰지 않습니다. 따라서 컴파일러는 코드를 최적화하고 s = states[state+cIndex*statesdim]; 문을 제거 할 수 있습니다. 따라서 귀하의 진술이 벡터화되었지만 그렇지 않습니다.

관련 문제