brook+_1.3_p2 - Brook+ Data Types Important for all data...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
29 Brook+ Data Types • Important for all data representations in Brook+ – Streams – Constants – Temporary variables • Brook+ Supports – Basic Types – Short Vector Types – User-Defined Types 30 Basic Data Types • Basic data types – float 32-bit floating point – double 64-bit floating point – int 32-bit signed integer – unsigned int/uint 32-bit unsigned integer e.g. Stream<float> f; Stream<uint> i; Stream<double> d; • Literal Constants for above types float a = 0.2f; double d = 0.3; int c = 10;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
31 Basic Data Types • Unsupported types (Reserved for future use – currently keywords) – char – unsigned char – short – unsigned short – long – unsigned long – ulong – long long 32 Vector Types • Short vectors (2 to 4 elements) inherited from 3D graphics – traditionally used to represent positions (x, y, z, w) or color (r, g, b, a) – GPU registers are 4-component registers, 128-bit per register – names built by appending the count to the type e.g. int2, float4 – doubles are limited to up to 2 elements
Background image of page 2
33 • C++ constructor-style initialization float4 a = float4(1.0f, 2.0f, 3.0f, 4.0f); int2 b = int2(1, 3); • 8 Access to individual fields is through structure member syntax: .x, .y, .z, .w int k = b.x + b.y * b.y; • Arithmetic operations on operands of vector types are supported – equivalent to applying the operator to each component individually – handy for quick performance tuning and data compaction float4 b = float4(1.0f, 0.0f, 10.0f, 5.0f); float4 k1 = a + b; 34 Vector Types - Usage
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
35 Vector Types – Swizzle operations • Reordering components of a short vector for certain operations – Nice shorthand for developers – Optimization hint to compiler • Brook+ – Use Swizzle to reorder elements in operands e.g. temp = input.yxzx + temp; – Use Swizzle to mask elements in output e.g. output.xw = input.x; • C – Cannot use vector instructions without reordering explicitly • float temp[4] = {0, 1, 2, 3}; // yxzx temp[0] += input.y; temp[1] += input.x; temp[2] += input.z; temp[3] += input.x; 36 Swizzle Examples float4 pos = float4(3.f, 5.f, 2.f, 1.f); float value1 = pos.x; // value1 is 3.f float2 vec0 = pos.xy; // vec0 is {3.f, 5.f} float4 vec1 = pos.yzxx // vec1 is {5.f, 2.f, 3.f, 3.f} vec1.x = pos.z; // vec1 is {2.f, 2.f, 3.f, 3.f}
Background image of page 4
37 Swizzle usage 38 Swizzle usage • Originally A * B would be written as float4 mult; mult.x = A.x * B.x + A.y * B.z; mult.y = A.x * B.y + A.y * B.w; mult.z = A.z * B.x + A.w * B.z; mult.w = A.z * B.y + A.w * B.w; • Using swizzles, A * B would be written as float4 mult = A.xxzz * B.xyxy + A.yyww * B.zwzw;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
39 User defined types • Basic Types and Short Vectors can be aggregated using user defined structs • Syntax for declaration and data access is same as C structs typedef struct PairRec { float row; float column; } Pair; kernel void foo(float c, Pair p<>, out float b<>) { b = c * p.row + p.column; } 40 User defined types
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/03/2011 for the course CDA 6938 taught by Professor Zou,c during the Spring '08 term at University of Central Florida.

Page1 / 23

brook+_1.3_p2 - Brook+ Data Types Important for all data...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online