Skip to content

Commit f75c00b

Browse files
authored
Add specification for cl_arm_printf v2.0.0 (#733)
- Move to asciidoctor - Require OpenCL 1.2 in version 2.0.0 and remove the need for the extension pragma. Signed-off-by: Kevin Petit <kevin.petit@arm.com> Change-Id: Ifdc3f26cfaeeb3c2c171dd76bc8313173d37dd4b
1 parent 62afd10 commit f75c00b

1 file changed

Lines changed: 192 additions & 0 deletions

File tree

extensions/cl_arm_printf.asciidoc

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
:data-uri:
2+
:icons: font
3+
include::../config/attribs.txt[]
4+
:source-highlighter: coderay
5+
6+
= cl_arm_printf
7+
:R: pass:q,r[^(R)^]
8+
9+
== Name Strings
10+
11+
`cl_arm_printf`
12+
13+
== Contact
14+
15+
Kevin Petit, Arm (kevin.petit 'at' arm.com)
16+
17+
== Contributors
18+
19+
Scott Moyers, Arm Ltd. +
20+
Robert Elliott, Arm Ltd. +
21+
Mats Petersson, Arm Ltd. +
22+
Vatsalya Prasad, Arm Ltd. +
23+
Kevin Petit, Arm Ltd. +
24+
25+
== Notice
26+
27+
Copyright (c) 2014-2021 Arm Ltd.
28+
29+
== Status
30+
31+
Shipping.
32+
33+
== Version
34+
35+
Built On: {docdate} +
36+
Version: 2.0.0
37+
38+
== Dependencies
39+
40+
This extension is written against the OpenCL Specification Version 3.0.10.
41+
42+
This extension requires OpenCL 1.0 (version 1.0.0) or OpenCL 1.2 (version 2.0.0).
43+
44+
== Overview
45+
46+
This extension enables the device side `printf` built in function for OpenCL C
47+
versions prior to 1.2 (version 1.0.0 only).
48+
49+
It also extends the `cl_context_properties` enumeration to allow a user defined
50+
printf callback and/or printf buffer size.
51+
52+
The `printf` built-in function should be used for debugging purposes only and may
53+
have a significant negative impact on the performance of an OpenCL application.
54+
55+
== New API Enums
56+
57+
Accepted value for the _properties_ parameter to *clCreateContext*:
58+
59+
[source,c]
60+
----
61+
CL_PRINTF_CALLBACK_ARM 0x40B0
62+
CL_PRINTF_BUFFERSIZE_ARM 0x40B1
63+
----
64+
65+
== New OpenCL C Functions
66+
67+
In version 1.0.0 only:
68+
69+
[source,c]
70+
----
71+
int printf( constant char * restrict format, ... );
72+
----
73+
74+
== Modifications to the OpenCL API Specification
75+
76+
(Modify Section 4.4, *Contexts*) ::
77+
+
78+
--
79+
80+
(Add the following to Table 7, _List of supported context creation parameters by *clCreateContext*_) ::
81+
+
82+
--
83+
84+
[cols="1,1,4",options="header"]
85+
|====
86+
| Context property
87+
| Property value
88+
| Description
89+
90+
| `CL_PRINTF_CALLBACK_ARM`
91+
| `(void)(*callback)(const char *buffer, size_t len, size_t complete, void *user_data)`
92+
| Specifies a pointer to function to be invoked when printf data is available.
93+
Upon invocation the arguments are set to the following values: +
94+
+
95+
- `buffer` is a pointer to a character array of size `len` created by `printf`. +
96+
- `len` is the number of new characters in `buffer`. +
97+
- `complete` is set to a non zero value if there is no more data in the device's printf buffer. +
98+
- `user_data` is the `user_data` parameter specified to *clCreateContext*. +
99+
100+
If this property is not specified, no callback will be registered and any printf output from
101+
a kernel will be discarded.
102+
103+
| `CL_PRINTF_BUFFERSIZE_ARM`
104+
| `size_t`
105+
| Specifies the size of printf buffer allocations to use within the driver.
106+
A printf buffer is allocated per device per context, within a context the buffer
107+
will be shared between kernels executing on a device. The implementation is free
108+
to round up or ignore this value. +
109+
If this property is not specified an implementation defined default size will be
110+
chosen. For OpenCL driver versions prior to OpenCL 1.2 this value will be 1 MiB.
111+
For driver versions of OpenCL 1.2 or greater this value is defined by the
112+
`CL_DEVICE_PRINTF_BUFFER_SIZE` value returned by *clGetDeviceInfo*.
113+
114+
|====
115+
116+
--
117+
--
118+
119+
== Modifications to the OpenCL C Specification
120+
121+
Version 1.0.0 of this extension adds the `printf` built-in function as
122+
described in 6.15.14 of the OpenCL C specification.
123+
124+
Version 2.0.0 of this extension does not modify the OpenCL C specification.
125+
126+
== Interactions with Other Extensions
127+
128+
None.
129+
130+
== Conformance tests
131+
132+
133+
The CTS has been modified to use a callback to gather the data produced by
134+
`printf` when this extension is supported.
135+
136+
== Issues
137+
138+
None.
139+
140+
== Sample code
141+
142+
Host C code:
143+
144+
[source,c]
145+
----
146+
/* Define a printf callback function. */
147+
void printf_callback( const char *buffer, size_t len, size_t complete, void *user_data )
148+
{
149+
printf( "%.*s", len, buffer );
150+
}
151+
152+
/* Create a cl_context with a printf_callback and user specified buffer size. */
153+
cl_context_properties properties[] =
154+
{
155+
/* Enable a printf callback function for this context. */
156+
CL_PRINTF_CALLBACK_ARM, (cl_context_properties) printf_callback,
157+
158+
/* Request a minimum printf buffer size of 4MiB for devices in the
159+
context that support this extension. */
160+
CL_PRINTF_BUFFERSIZE_ARM, (cl_context_properties) 0x100000,
161+
162+
CL_CONTEXT_PLATFORM, (cl_context_properties) platform,
163+
0
164+
};
165+
cl_context context = clCreateContext( properties, 1, &device, NULL, NULL, NULL );
166+
----
167+
168+
Device OpenCL C code:
169+
170+
[source,c]
171+
----
172+
// Only required by version 1.0.0 of the extension, version 2.0.0 does not
173+
// require the following pragma.
174+
#pragma OPENCL EXTENSION cl_arm_printf : enable
175+
176+
kernel void hello_world( void )
177+
{
178+
printf( "Hello from work item %lu!\n", (ulong) get_global_id(0) );
179+
}
180+
----
181+
182+
== Version History
183+
184+
[cols="5,15,15,70"]
185+
[grid="rows"]
186+
[options="header"]
187+
|====
188+
| Version | Date | Author | Changes
189+
| 2.0.0 | 2021-12-02 | Kevin Petit | Transition to asciidoctor, require OpenCL 1.2
190+
| 1.0.0 | 2014-01-17 | Scott Moyers | *Initial revision*
191+
|====
192+

0 commit comments

Comments
 (0)