OpenCL Vector type 간 비교

OpenCL에는 벡터 형 자료가 있다.

아래 표는 https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/ 에서 긁어왔다.

Type in OpenCL
Language
DescriptionAPI type for
application
charnA vector of n 8-bit signed two's complement
integer values.
cl_charn
ucharnA vector of n 8-bit unsigned integer values.cl_ucharn
shortnA vector of n 16-bit signed two's complement
 integer values.
cl_shortn
ushortnA vector of n 16-bit unsigned integer values.cl_ushortn
intnA vector of n 32-bit signed two's
complement integer values.
cl_intn
uintnA vector of n 32-bit unsigned integer values.cl_uintn
longnA vector of n 64-bit signed two's
complement  integer values.
cl_longn
ulongnA vector of n 64-bit unsigned integer values.cl_ulongn
floatnA vector of n 32-bit floating-point values.cl_floatn
doublenA vector of n 64-bit floating-point values.cl_doublen

정말 편한게 벡터간에 연산이 가능하고  실제로 HW에서 벡터연산을 지원하는 경우가 많으므로 벡터연산을 하면 성능이 향상된다.

벡터간 비교또한 가능한데

uchar4 word1 = (uchar4)('t','e','s','t');
uchar4 word2 = (uchar4)('t','e','s','t');

word1 == word2 의 결과값은 (0xff,0xff,0xff,0xff) 가된다. (거짓의 경우는 0x00 값이 셋팅된다)
하지만 벡터타입은 if문 안에서 어떤 원소를 비교해야할지 모르기때문에 오류가 난다.

if(word1 == word2 ) 는 불가능 하다.

이때 모든원소가 참인지 거짓인지 확인하는 빌트인 함수가 있다.

int any (igentype x)
int all (igentype x)

Description

any returns 1 if the most significant bit in any component of x is set; otherwise returns 0.
all returns 1 if the most significant bit in all components of x is set; otherwise returns 0.

all을 사용하면 모두 참이면 참, any는 하나라도 참이면 참이나온다.(정확하게는 msb만 확인한)

if( all( word1 == word2 ) )  을 사용하면 해결할수 있다.

댓글

이 블로그의 인기 게시물

C#에서 포인터 사용

WPF RichTextBox 와 Document의 바인딩

WPF 이미지위에 라인 그리기(WPF DrawLine on exist Image)