rounding-mode
One of the following values:
| rounding-mode | Description |
|---|---|
| rte | round to nearest even |
| rtz | round to zero |
| rtp | round to positive infinity |
| rtn | round to negative infinity |
OpenCL 1.0 adds support for specifying the rounding mode for an instruction or group of instructions in the program source as an optional extension. An application that wants to use this feature will need to include the #pragma OPENCL EXTENSION
cl_khr_select_fprounding_mode : enable directive.
If the cl_khr_select_fprounding_mode extension is supported, the OpenCL implementation must support all four rounding modes for single precision floating-point i.e. the CL_DEVICE_SINGLE_FP_CONFIG described in the table of OpenCL Device Queries for clGetDeviceInfo. must include
CL_FP_ROUND_TO_ZERO and CL_FP_ROUND_TO_INF. This is already the case for double
precision floating-point.
The appropriate rounding mode can be specified using #pragma OPENCL SELECT_ROUNDING_MODE in the program source.
rounding-mode
The #pragma OPENCL SELECT_ROUNDING_MODE sets the rounding mode for all
instructions that operate on floating-point types (scalar or vector types) or produce floating-point
values that follow this pragma in the program source until the next #pragma OPENCL SELECT_ROUNDING_MODE is encountered. Note that the rounding mode specified for a block of code is known at compile time. Except where otherwise documented, the callee functions do not inherit the rounding mode of the caller function.
If this extension is enabled, the __ROUNDING_MODE__ preprocessor symbol shall be defined to be one of the following according to the current rounding mode:
#define __ROUNDING_MODE__ rte
#define __ROUNDING_MODE__ rtz
#define __ROUNDING_MODE__ rtp
#define __ROUNDING_MODE__ rtz
This is intended to let us remap foo() to foo_rte() in the preprocessor using
#define foo foo ## __ROUNDING_MODE__
The default rounding mode is round to nearest even. The built-in math functions, the common functions, and the geometric functions are implemented with the round to nearest even rounding mode.
Various built-in conversions and the vstore_half and
vstorea_halfn built-in functions that do not specify a rounding mode inherit the current rounding mode. Conversions from floating-point to integer type always use rtz mode, except where the user specifically asks for another rounding mode.
The above four rounding modes are defined by IEEE 754. Floating-point calculations may be carried out internally with extra precision and then rounded to fit into the destination type. Round to nearest even is currently the only rounding mode required by the OpenCL specification and is therefore the default rounding mode. In addition, only static selection of rounding mode is supported. Dynamically reconfiguring the rounding modes as specified by the IEEE 754 spec is not a requirement.
| #pragma OPENCL SELECT_ROUNDING_MODE rtz float4 a = b * c; // uses round to zero rounding mode. #pragma OPENCL SELECT_ROUNDING_MODE rtp float4 d = foo(a); // function foo uses rounding mode specified where source for foo() is implemented. |
Copyright © 2007-2009 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the condition that this copyright notice and permission notice shall be included
in all copies or substantial portions of the Materials.