1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
3
"http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd">
8
<keyword>Data Types</keyword>
13
<refentrytitle>Data Types</refentrytitle>
17
<year>2007-2010</year>
18
<holder>The Khronos Group Inc.
19
Permission is hereby granted, free of charge, to any person obtaining a
20
copy of this software and/or associated documentation files (the
21
"Materials"), to deal in the Materials without restriction, including
22
without limitation the rights to use, copy, modify, merge, publish,
23
distribute, sublicense, and/or sell copies of the Materials, and to
24
permit persons to whom the Materials are furnished to do so, subject to
25
the condition that this copyright notice and permission notice shall be included
26
in all copies or substantial portions of the Materials.</holder>
29
<manvolnum>3</manvolnum>
32
<!-- ================================ SYNOPSIS -->
34
<refnamediv id="DataTypes">
35
<refname>Data Types</refname>
42
<!-- ================================ DESCRIPTION -->
44
<refsect1 id="description"><title>Description</title>
47
These are the data types available in the OpenCL C programming language. Click on a
48
category name in the table below to see information about specific data types.
51
<informaltable frame="all">
52
<tgroup cols="2" align="left" colsep="1" rowsep="1">
53
<colspec colname="col1" colnum="1" />
54
<colspec colname="col2" colnum="2" />
58
<entry>Data type category</entry>
59
<entry>Included data types</entry>
66
<citerefentry href="scalarDataTypes"><refentrytitle>Scalar data types</refentrytitle></citerefentry>
69
<type>bool</type>, <type>char</type>, <type>cl_char</type>,
70
<type>unsigned char</type>, <type>uchar</type>, <type>cl_uchar</type>,
71
<type>short</type>, <type>cl_short</type>, <type>unsigned short</type>,
72
<type>ushort</type>, <type>int</type>, <type>unsigned int</type>,
73
<type>uint</type>, <type>long</type>, <type>unsigned long</type>,
74
<type>ulong</type>, <type>float</type>, <type>half</type>, <type>size_t</type>,
75
<type>ptrdiff_t</type>, <type>intptr_t</type>, <type>uintptr_t</type>,
76
<type>void</type>, <type>double</type>, and <type>half</type> floating point types.
82
<citerefentry href="vectorDataTypes"><refentrytitle>Vector data types</refentrytitle></citerefentry>
85
<type>char<replaceable>n</replaceable></type>, <type>uchar<replaceable>n</replaceable></type>,
86
<type>short<replaceable>n</replaceable></type>, <type>ushort<replaceable>n</replaceable></type>,
87
<type>int<replaceable>n</replaceable></type>, <type>uint<replaceable>n</replaceable></type>,
88
<type>long<replaceable>n</replaceable></type>, <type>ulong<replaceable>n</replaceable></type>,
89
<type>float<replaceable>n</replaceable></type>, double<replaceable>n</replaceable>, and optional half<replaceable>n</replaceable> types.
95
<citerefentry href="abstractDataTypes"><refentrytitle>Abstract data types</refentrytitle></citerefentry>
98
<type>cl_platform_id</type>, <type>cl_device_id</type>,
99
<type>cl_context</type>, <type>cl_command_queue</type>,
100
<type>cl_mem</type>, <type>cl_program</type>,
101
<type>cl_kernel</type>, <type>cl_event</type>, and
102
<type>cl_sampler</type>.
108
<citerefentry href="reservedDataTypes"><refentrytitle>Reserved Data Types</refentrytitle></citerefentry>
111
<type>bool<replaceable>n</replaceable></type>,
112
<type>half<replaceable>n</replaceable></type>, <type>quad</type>,
113
<type>quad<replaceable>n</replaceable></type>,
114
<type>complex half</type>, <type>complex half<replaceable>n</replaceable></type>,
115
<type>imaginary half</type>, <type>imaginary half<replaceable>n</replaceable></type>,
116
<type>complex float</type>, <type>complex float<replaceable>n</replaceable></type>,
117
<type>imaginary float</type>, <type>imaginary float<replaceable>n</replaceable></type>,
118
<type>complex double</type>, <type>complex double<replaceable>n</replaceable></type>,
119
<type>imaginary double</type>, <type>imaginary double<replaceable>n</replaceable></type>,
120
<type>complex quad</type>, <type>complex quad<replaceable>n</replaceable></type>,
121
<type>imaginary quad</type>, <type>imaginary quad<replaceable>n</replaceable></type>,
122
<type>float<replaceable>n</replaceable></type>x<emphasis>m</emphasis>,
123
<type>double<replaceable>n</replaceable></type>x<emphasis>m</emphasis>,
124
<type>long double</type>, <type>long double<replaceable>n</replaceable></type>,
125
<type>long long</type>, <type>long long<replaceable>n</replaceable></type>,
126
<type>unsigned long long</type>, <type>ulong long</type>, and
127
<type>ulong long<replaceable>n</replaceable></type>.
133
<citerefentry href="otherDataTypes"><refentrytitle>Other data types</refentrytitle></citerefentry>
136
<type>image2d_t</type>, <type>image3d_t</type>, <type>image2d_array_t</type>,
137
<type>image1d_t</type>, <type>image31_buffer_t</type>, <type>image1d_array_t</type>,
138
<type>sampler_t</type>, and <type>event_t</type>.
146
<!-- ================================ NOTES -->
147
<refsect1 id="notes"><title>Alignment of Types</title>
149
A data item declared to be a data type in memory is always aligned to the size of the
150
data type in bytes. For example, a <type>float4</type> variable will be aligned to a
151
16-byte boundary, and a <type>char2</type> variable will be aligned to a 2-byte boundary.
155
For 3-component vector data types, the size of the data type is 4 *
156
sizeof(component). This means that a 3-component vector data type
157
will be aligned to a 4 * sizeof(component) boundary. The <citerefentry
158
href="vloadn"><refentrytitle>vload3</refentrytitle></citerefentry> and <citerefentry
159
href="vstoren"><refentrytitle>vstore3</refentrytitle></citerefentry> built-in functions
160
can be used to read and write, respectively, 3-component vector data types from an
161
array of packed scalar data type.
165
A built-in data type that is not a power of two bytes in size must be aligned to the next
166
larger power of two. This rule applies to built-in types only, not <code>structs</code>
167
or <code>unions</code>.
171
The OpenCL compiler is responsible for aligning data items to the appropriate
172
alignment as required by the data type. For arguments to a <citerefentry
173
href="functionQualifiers"><refentrytitle>__kernel</refentrytitle></citerefentry>
174
function declared to be a pointer to a data type, the OpenCL compiler can
175
assume that the pointee is always appropriately aligned as required by the
176
data type. The behavior of an unaligned load or store is undefined, except
177
for the <citerefentry><refentrytitle>vloadn</refentrytitle></citerefentry>,
178
<citerefentry><refentrytitle>vload_halfn</refentrytitle></citerefentry>,
179
<citerefentry><refentrytitle>vstoren</refentrytitle></citerefentry>, and
180
<citerefentry><refentrytitle>vstore_halfn</refentrytitle></citerefentry> functions. The
181
vector load functions can read a vector from an address aligned to the element type
182
of the vector. The vector store functions can write a vector to an address aligned
183
to the element type of the vector.
187
The user is responsible for ensuring that data passed into and out of OpenCL buffers are
188
natively aligned relative to the start of the buffer as described above. This implies
189
that OpenCL buffers created with <constant>CL_MEM_USE_HOST_PTR</constant> need to provide
190
an appropriately aligned host memory pointer that is aligned to the data types used to
191
access these buffers in a kernel(s). As well, the user is responsible to ensure that
192
data passed into and out of OpenCL images are properly aligned to the granularity of
193
the data representing a single pixel (e.g. <varname>image_num_channels</varname>
194
* sizeof(<varname>image_channel_data_type</varname>)) except for
195
<constant>CL_RGB</constant> and <constant>CL_RGBx</constant> images where
196
the data must be aligned to the granularity of a single channel in a pixel
197
(i.e. sizeof(<varname>image_channel_data_type</varname>)).
201
OpenCL makes no requirement about the alignment of OpenCL application defined data
202
types outside of buffers and images, except that the underlying vector primitives (e.g.
203
<type>__cl_float4</type>) where defined shall be directly accessible as such
204
using appropriate named fields in the <constant>cl_type</constant> union. Nevertheless,
205
it is recommended that the <code>cl_platform.h</code> header should attempt to
206
naturally align OpenCL defined application data types (e.g. <type>cl_float4</type>)
207
according to their type.
211
<!-- ================================ SPECIFICATION -->
212
<!-- Set the "uri" attribute in the <olink /> element to the "named destination" for the PDF page
214
<refsect1 id="specification"><title>Specification</title>
217
<imagedata fileref="pdficon_small1.gif" format="gif" />
220
<olink uri="scalarDataTypes">OpenCL Specification</olink>
224
<!-- ================================ ALSO SEE
226
<refsect1 id="seealso"><title>Also see</title>
228
<citerefentry><refentrytitle>cl_khr_fp64</refentrytitle></citerefentry>
232
<!-- ============================== COPYRIGHT -->
233
<!-- Content included from copyright.inc.xsl -->
235
<refsect3 id="Copyright"><title></title>
237
<imagedata fileref="KhronosLogo.jpg" format="jpg" />