Compute Library
 20.08
arm_compute::support::cpp11 Namespace Reference

Enumerations

enum  NumericBase { BASE_10, BASE_16 }
 

Functions

void * align (std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space)
 
int stoi (const std::string &str, std::size_t *pos=0, NumericBase base=NumericBase::BASE_10)
 Convert string values to integer. More...
 
unsigned long stoul (const std::string &str, std::size_t *pos=0, NumericBase base=NumericBase::BASE_10)
 Convert string values to unsigned long. More...
 
template<typename T >
std::string to_string (T &&value)
 Convert integer and float values to string. More...
 
template<typename... Ts>
int stof (Ts &&... args)
 Convert string values to float. More...
 
std::string to_string (bool value)
 
template<typename T >
nearbyint (T value)
 Rounds the floating-point argument arg to an integer value in floating-point format, using the current rounding mode. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
round (T value)
 Round floating-point value with half value rounding away from zero. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
trunc (T value)
 Truncate floating-point value. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
copysign (T x, T y)
 Composes a floating point value with the magnitude of x and the sign of y. More...
 
template<typename T , typename = typename std::enable_if < std::is_floating_point<T>::value >::type>
fma (T x, T y, T z)
 Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type. More...
 
template<typename... Ts>
int snprintf (char *s, std::size_t n, const char *fmt, Ts &&... args)
 Loads the data from the given location, converts them to character string equivalents and writes the result to a character string buffer. More...
 
template<typename T >
lowest ()
 
template<>
bfloat16 lowest< bfloat16 > ()
 
template<typename T , typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
bool isfinite (T value)
 
bool isfinite (half_float::half value)
 
bool isfinite (bfloat16 value)
 

Enumeration Type Documentation

◆ NumericBase

enum NumericBase
strong
Enumerator
BASE_10 
BASE_16 

Definition at line 38 of file StringSupport.h.

Function Documentation

◆ align()

void* arm_compute::support::cpp11::align ( std::size_t  alignment,
std::size_t  size,
void *&  ptr,
std::size_t &  space 
)
inline

Definition at line 37 of file MemorySupport.h.

38 {
39  std::uintptr_t pn = reinterpret_cast<std::uintptr_t>(ptr);
40  std::uintptr_t aligned = (pn + alignment - 1) & -alignment;
41  std::size_t padding = aligned - pn;
42  if(space < size + padding)
43  {
44  return nullptr;
45  }
46 
47  space -= padding;
48 
49  return ptr = reinterpret_cast<void *>(aligned);
50 }

References arm_compute::test::validation::padding.

Referenced by MemoryRegion::MemoryRegion(), and arm_compute::test::validation::TEST_CASE().

◆ copysign()

T arm_compute::support::cpp11::copysign ( x,
y 
)
inline

Composes a floating point value with the magnitude of x and the sign of y.

Note
This function implements the same behaviour as std::copysign except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]xvalue that contains the magnitude to be used in constructing the result.
[in]yvalue that contains the sign to be used in construct in the result.
Returns
Floating-point value with magnitude of x and sign of y.

Definition at line 197 of file ToolchainSupport.h.

198 {
199  return std::copysign(x, y);
200 }
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.

◆ fma()

T arm_compute::support::cpp11::fma ( x,
y,
z 
)
inline

Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type.

Note
This function implements the same behaviour as std::fma except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]xfloating-point value
[in]yfloating-point value
[in]zfloating-point value
Returns
Result floating point value equal to (x*y) + z.

Definition at line 218 of file ToolchainSupport.h.

219 {
220  return std::fma(x, y, z);
221 }
T fma(T x, T y, T z)
Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type.

◆ isfinite() [1/3]

bool arm_compute::support::cpp11::isfinite ( value)
inline

◆ isfinite() [2/3]

bool arm_compute::support::cpp11::isfinite ( half_float::half  value)
inline

Definition at line 269 of file ToolchainSupport.h.

270 {
271  return half_float::isfinite(value);
272 }
bool isfinite(bfloat16 value)

◆ isfinite() [3/3]

bool arm_compute::support::cpp11::isfinite ( bfloat16  value)
inline

Definition at line 274 of file ToolchainSupport.h.

275 {
276  return std::isfinite(float(value));
277 }
bool isfinite(bfloat16 value)

◆ lowest()

◆ lowest< bfloat16 >()

Definition at line 257 of file ToolchainSupport.h.

258 {
259  return bfloat16::lowest();
260 }

References bfloat16::lowest().

◆ nearbyint()

T arm_compute::support::cpp11::nearbyint ( value)
inline

Rounds the floating-point argument arg to an integer value in floating-point format, using the current rounding mode.

Note
This function acts as a convenience wrapper around std::nearbyint. The latter is missing in some Android toolchains.
Parameters
[in]valueValue to be rounded.
Returns
The rounded value.

Definition at line 150 of file ToolchainSupport.h.

151 {
152  return static_cast<T>(std::nearbyint(value));
153 }
T nearbyint(T value)
Rounds the floating-point argument arg to an integer value in floating-point format,...

Referenced by arm_compute::test::validation::reference::elementwise_unary().

◆ round()

T arm_compute::support::cpp11::round ( value)
inline

Round floating-point value with half value rounding away from zero.

Note
This function implements the same behaviour as std::round except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]valuefloating-point value to be rounded.
Returns
Floating-point value of rounded value.

Definition at line 165 of file ToolchainSupport.h.

166 {
167  //Workaround Valgrind's mismatches: when running from Valgrind the call to std::round(-4.500000) == -4.000000 instead of 5.00000
168  return (value < 0.f) ? static_cast<int>(value - 0.5f) : static_cast<int>(value + 0.5f);
169 }

Referenced by arm_compute::quantization::calculate_quantized_multiplier_greater_than_one(), arm_compute::quantization::calculate_quantized_multiplier_less_than_one(), choose_quantization_params(), arm_compute::round(), and NEROIPoolingLayerKernel::run().

◆ snprintf()

int arm_compute::support::cpp11::snprintf ( char *  s,
std::size_t  n,
const char *  fmt,
Ts &&...  args 
)
inline

Loads the data from the given location, converts them to character string equivalents and writes the result to a character string buffer.

Parameters
[in]sPointer to a character string to write to
[in]nUp to buf_size - 1 characters may be written, plus the null terminator
[in]fmtPointer to a null-terminated multibyte string specifying how to interpret the data.
[in]argsArguments forwarded to std::snprintf.
Returns
Number of characters that would have been written for a sufficiently large buffer if successful (not including the terminating null character), or a negative value if an error occurred.

Definition at line 235 of file ToolchainSupport.h.

236 {
237  return std::snprintf(s, n, fmt, std::forward<Ts>(args)...);
238 }
int snprintf(char *s, std::size_t n, const char *fmt, Ts &&... args)
Loads the data from the given location, converts them to character string equivalents and writes the ...

References GemmTuner::args.

Referenced by arm_compute::create_error_msg(), and arm_compute::logging::string_with_format().

◆ stof()

int arm_compute::support::cpp11::stof ( Ts &&...  args)

Convert string values to float.

Note
This function acts as a convenience wrapper around std::stof. The latter is missing in some Android toolchains.
Parameters
[in]argsArguments forwarded to std::stof.
Returns
Float representation of input string.

Definition at line 177 of file StringSupport.h.

178 {
179  return ::std::stof(std::forward<Ts>(args)...);
180 }
int stof(Ts &&... args)
Convert string values to float.

References GemmTuner::args.

◆ stoi()

int arm_compute::support::cpp11::stoi ( const std::string &  str,
std::size_t *  pos = 0,
NumericBase  base = NumericBase::BASE_10 
)
inline

Convert string values to integer.

Note
This function implements the same behaviour as std::stoi. The latter is missing in some Android toolchains.
Parameters
[in]strString to be converted to int.
[in]posIf idx is not a null pointer, the function sets the value of pos to the position of the first character in str after the number.
[in]baseNumeric base used to interpret the string.
Returns
Integer representation of str.

Definition at line 55 of file StringSupport.h.

56 {
57  assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
58  unsigned int x;
59  std::stringstream ss;
60  if(base == NumericBase::BASE_16)
61  {
62  ss << std::hex;
63  }
64  ss << str;
65  ss >> x;
66 
67  if(pos)
68  {
69  std::string s;
70  std::stringstream ss_p;
71 
72  ss_p << x;
73  ss_p >> s;
74  *pos = s.length();
75  }
76 
77  return x;
78 }

References BASE_10, and BASE_16.

Referenced by CLTuner::load_from_file().

◆ stoul()

unsigned long arm_compute::support::cpp11::stoul ( const std::string &  str,
std::size_t *  pos = 0,
NumericBase  base = NumericBase::BASE_10 
)
inline

Convert string values to unsigned long.

Note
This function implements the same behaviour as std::stoul. The latter is missing in some Android toolchains.
Parameters
[in]strString to be converted to unsigned long.
[in]posIf idx is not a null pointer, the function sets the value of pos to the position of the first character in str after the number.
[in]baseNumeric base used to interpret the string.
Returns
Unsigned long representation of str.

Definition at line 91 of file StringSupport.h.

92 {
93  assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
94  std::stringstream stream;
95  unsigned long value = 0;
96  if(base == NumericBase::BASE_16)
97  {
98  stream << std::hex;
99  }
100  stream << str;
101  stream >> value;
102 
103  if(pos)
104  {
105  std::string s;
106  std::stringstream ss_p;
107 
108  ss_p << value;
109  ss_p >> s;
110  *pos = s.length();
111  }
112 
113  return value;
114 }

References BASE_10, and BASE_16.

◆ to_string() [1/2]

std::string arm_compute::support::cpp11::to_string ( T &&  value)
inline

Convert integer and float values to string.

Note
This function acts as a convenience wrapper around std::to_string. The latter is missing in some Android toolchains.
Parameters
[in]valueValue to be converted to string.
Returns
String representation of value.

Definition at line 162 of file StringSupport.h.

163 {
164  return ::std::to_string(std::forward<T>(value));
165 }
std::string to_string(bool value)

Referenced by GCLogits1DMaxKernel::configure(), GCScaleKernel::configure(), GCTransposeKernel::configure(), CLIntegralImageHorKernel::configure(), CLElementWiseUnaryLayerKernel::configure(), GCGEMMMatrixAccumulateBiasesKernel::configure(), CLMedian3x3Kernel::configure(), CLStridedSliceKernel::configure(), CLScaleKernel::configure(), CLWarpAffineKernel::configure(), GCDepthwiseConvolutionLayer3x3Kernel::configure(), GCPixelWiseMultiplicationKernel::configure(), CLActivationLayerKernel::configure(), CLWidthConcatenate2TensorsKernel::configure(), GCFillBorderKernel::configure(), GCGEMMMatrixAdditionKernel::configure(), GCNormalizationLayerKernel::configure(), GCPoolingLayerKernel::configure(), CLHeightConcatenateLayerKernel::configure(), CLWidthConcatenateLayerKernel::configure(), GCNormalizePlanarYUVLayerKernel::configure(), CLWidthConcatenate4TensorsKernel::configure(), GCAbsoluteDifferenceKernel::configure(), GCGEMMTranspose1xWKernel::configure(), CLDequantizationLayerKernel::configure(), CLGEMMMatrixVectorMultiplyKernel::configure(), GCArithmeticAdditionKernel::configure(), CLDepthConcatenateLayerKernel::configure(), CLMaxUnpoolingLayerKernel::configure(), CLFloorKernel::configure(), CLMinMaxLayerKernel::configure(), CLGaussianPyramidHorKernel::configure(), CLDepthwiseConvolutionLayerReshapeWeightsKernel::configure(), CLHistogramKernel::configure(), CLFlattenLayerKernel::configure(), CLReverseKernel::configure(), CLChannelShuffleLayerKernel::configure(), GCActivationLayerKernel::configure(), GCBatchNormalizationLayerKernel::configure(), GCDepthConcatenateLayerKernel::configure(), CLBatchToSpaceLayerKernel::configure(), CLMinMaxKernel::configure(), CLCopyKernel::configure(), CLDepthToSpaceLayerKernel::configure(), CLSpaceToDepthLayerKernel::configure(), CLBatchConcatenateLayerKernel::configure(), CLComputeAllAnchorsKernel::configure(), GCDropoutLayerKernel::configure(), GCLogits1DShiftExpSumKernel::configure(), CLFFTScaleKernel::configure(), CLMemsetKernel::configure(), CLGradientKernel::configure(), CLNormalizationLayerKernel::configure(), CLGatherKernel::configure(), CLQLSTMLayerNormalizationKernel::configure(), CLSpaceToBatchLayerKernel::configure(), CLUpsampleLayerKernel::configure(), CLComparisonKernel::configure(), GCGEMMMatrixMultiplyKernel::configure(), CLTileKernel::configure(), CLHOGOrientationBinningKernel::configure(), CLFFTDigitReverseKernel::configure(), CLPermuteKernel::configure(), CLQuantizationLayerKernel::configure(), CLReorgLayerKernel::configure(), CLInstanceNormalizationLayerKernel::configure(), CLMeanStdDevNormalizationKernel::configure(), CLDerivativeKernel::configure(), CLSobel3x3Kernel::configure(), CLColorConvertKernel::configure(), GCGEMMInterleave4x4Kernel::configure(), CLNormalizePlanarYUVLayerKernel::configure(), CLPoolingLayerKernel::configure(), CLRangeKernel::configure(), CLSobel5x5HorKernel::configure(), CLSobel7x7HorKernel::configure(), CLLogits1DMaxShiftExpSumKernel::configure(), CLPadLayerKernel::configure(), CLSelectKernel::configure(), CLConvertFullyConnectedWeightsKernel::configure(), CLFFTRadixStageKernel::configure(), CLPriorBoxLayerKernel::configure(), CLReductionOperationKernel::configure(), GCTensorShiftKernel::configure(), CLL2NormalizeLayerKernel::configure(), CLBoundingBoxTransformKernel::configure(), CLCropKernel::configure(), CLGEMMLowpMatrixMultiplyNativeKernel::configure(), CLMagnitudePhaseKernel::configure(), CLYOLOLayerKernel::configure(), CLIntegralImageVertKernel::configure(), CLFillBorderKernel::configure(), CLStackLayerKernel::configure(), CLFastCornersKernel::configure(), CLDepthConvertLayerKernel::configure(), CLDepthwiseConvolutionLayer3x3NCHWKernel::configure(), CLGEMMReshapeLHSMatrixKernel::configure(), CLGEMMLowpQuantizeDownInt32ScaleKernel::configure(), CLDepthwiseConvolutionLayer3x3NHWCKernel::configure(), CLArgMinMaxLayerKernel::configure(), GCWeightsReshapeKernel::configure(), GCCol2ImKernel::configure(), CLROIPoolingLayerKernel::configure(), GCIm2ColKernel::configure(), CLHarrisScoreKernel::configure(), CLDeconvolutionReshapeOutputKernel::configure(), CLROIAlignLayerKernel::configure(), CLHOGDetectorKernel::configure(), CLWinogradInputTransformKernel::configure(), CLFuseBatchNormalizationKernel::configure(), CLGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointKernel::configure(), CLBatchNormalizationLayerKernel::configure(), CLCol2ImKernel::configure(), CLWinogradFilterTransformKernel::configure(), CLGEMMMatrixMultiplyNativeKernel::configure(), CLGEMMLowpMatrixMultiplyReshapedKernel::configure(), CLGEMMMatrixMultiplyKernel::configure(), CLGEMMLowpOffsetContributionKernel::configure(), CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::configure(), CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::configure(), CLWinogradOutputTransformKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CLDirectConvolutionLayerKernel::configure(), CLGEMMLowpOffsetContributionOutputStageKernel::configure(), CLWeightsReshapeKernel::configure(), CLGEMMReshapeRHSMatrixKernel::configure(), GCLogits1DNormKernel::configure(), CLIm2ColKernel::configure(), CLHistogramBorderKernel::configure(), CLGaussianPyramidVertKernel::configure(), CLPixelWiseMultiplicationKernel::configure(), CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel::configure(), CLGEMMLowpMatrixAReductionKernel::configure(), CLHOGBlockNormalizationKernel::configure(), CLGEMMMatrixMultiplyReshapedOnlyRHSKernel::configure(), CLEdgeNonMaxSuppressionKernel::configure(), CLCopyToArrayKernel::configure(), CLSobel5x5VertKernel::configure(), CLSobel7x7VertKernel::configure(), CLLogits1DNormKernel::configure(), CLGEMMLowpMatrixBReductionKernel::configure(), CLEdgeTraceKernel::configure(), CLConvolutionRectangleKernel::configure(), RangeDataset< T >::iterator::description(), SingletonDataset< T >::iterator::description(), ContainerDataset< T >::iterator::description(), arm_compute::utils::get_typestring(), arm_compute::test::get_typestring(), arm_compute::test::join(), main(), OpenCLClock< output_timestamps >::measurements(), MaliCounter::measurements(), SchedulerClock< output_timestamps >::measurements(), Size2D::to_string(), arm_compute::to_string(), and CLTuner::tune_kernel_dynamic().

◆ to_string() [2/2]

std::string arm_compute::support::cpp11::to_string ( bool  value)
inline

Definition at line 184 of file StringSupport.h.

185 {
186  std::stringstream str;
187  str << std::boolalpha << value;
188  return str.str();
189 }

◆ trunc()

T arm_compute::support::cpp11::trunc ( value)
inline

Truncate floating-point value.

Note
This function implements the same behaviour as std::truncate except that it doesn't support Integral type. The latter is not in the namespace std in some Android toolchains.
Parameters
[in]valuefloating-point value to be truncated.
Returns
Floating-point value of truncated value.

Definition at line 181 of file ToolchainSupport.h.

182 {
183  return std::trunc(value);
184 }
T trunc(T value)
Truncate floating-point value.

Referenced by arm_compute::test::validation::apply_2d_spatial_filter(), and FilePrinter::FilePrinter().