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

Enumerations

enum  NumericBase { BASE_10, BASE_16 }
 

Functions

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 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... Ts>
int stof (Ts &&... args)
 Convert string values to float. 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...
 
std::string to_string (bool value)
 
void * align (std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space)
 
template<typename T >
lowest ()
 
template<typename T , typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
bool isfinite (T value)
 
bool isfinite (half_float::half value)
 

Enumeration Type Documentation

◆ NumericBase

enum NumericBase
strong
Enumerator
BASE_10 
BASE_16 

Definition at line 50 of file ToolchainSupport.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 402 of file ToolchainSupport.h.

403 {
404  std::uintptr_t pn = reinterpret_cast<std::uintptr_t>(ptr);
405  std::uintptr_t aligned = (pn + alignment - 1) & -alignment;
406  std::size_t padding = aligned - pn;
407  if(space < size + padding)
408  {
409  return nullptr;
410  }
411 
412  space -= padding;
413 
414  return ptr = reinterpret_cast<void *>(aligned);
415 }

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 349 of file ToolchainSupport.h.

350 {
351  return std::copysign(x, y);
352 }
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 370 of file ToolchainSupport.h.

371 {
372  return std::fma(x, y, z);
373 }
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/2]

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

◆ isfinite() [2/2]

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

Definition at line 438 of file ToolchainSupport.h.

439 {
440  return half_float::isfinite(value);
441 }
bool isfinite(half_float::half value)

◆ 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 287 of file ToolchainSupport.h.

288 {
289  return static_cast<T>(std::nearbyint(value));
290 }
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 317 of file ToolchainSupport.h.

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

Referenced by arm_compute::quantization::calculate_quantized_multiplier_greater_than_one(), arm_compute::quantization::calculate_quantized_multiplier_less_than_one(), 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 387 of file ToolchainSupport.h.

388 {
389  return std::snprintf(s, n, fmt, std::forward<Ts>(args)...);
390 }
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 302 of file ToolchainSupport.h.

303 {
304  return ::std::stof(std::forward<Ts>(args)...);
305 }
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 67 of file ToolchainSupport.h.

68 {
69  assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
70  unsigned int x;
71  std::stringstream ss;
72  if(base == NumericBase::BASE_16)
73  {
74  ss << std::hex;
75  }
76  ss << str;
77  ss >> x;
78 
79  if(pos)
80  {
81  std::string s;
82  std::stringstream ss_p;
83 
84  ss_p << x;
85  ss_p >> s;
86  *pos = s.length();
87  }
88 
89  return x;
90 }

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 103 of file ToolchainSupport.h.

104 {
105  assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16);
106  std::stringstream stream;
107  unsigned long value = 0;
108  if(base == NumericBase::BASE_16)
109  {
110  stream << std::hex;
111  }
112  stream << str;
113  stream >> value;
114 
115  if(pos)
116  {
117  std::string s;
118  std::stringstream ss_p;
119 
120  ss_p << value;
121  ss_p >> s;
122  *pos = s.length();
123  }
124 
125  return value;
126 }

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 272 of file ToolchainSupport.h.

273 {
274  return ::std::to_string(std::forward<T>(value));
275 }
std::string to_string(bool value)

Referenced by GCLogits1DMaxKernel::configure(), CLIntegralImageHorKernel::configure(), CLElementWiseUnaryLayerKernel::configure(), CLMedian3x3Kernel::configure(), GCTransposeKernel::configure(), CLWarpAffineKernel::configure(), GCScaleKernel::configure(), CLScaleKernel::configure(), GCGEMMMatrixAccumulateBiasesKernel::configure(), CLGEMMMatrixAccumulateBiasesKernel::configure(), CLGEMMMatrixVectorMultiplyKernel::configure(), CLDepthwiseConvolutionLayerReshapeWeightsKernel::configure(), CLDequantizationLayerKernel::configure(), CLMinMaxLayerKernel::configure(), CLFloorKernel::configure(), CLFlattenLayerKernel::configure(), CLCopyKernel::configure(), CLGaussianPyramidHorKernel::configure(), CLReverseKernel::configure(), CLChannelShuffleLayerKernel::configure(), CLHistogramKernel::configure(), CLNormalizationLayerKernel::configure(), CLBatchToSpaceLayerKernel::configure(), CLSpaceToDepthLayerKernel::configure(), CLDepthToSpaceLayerKernel::configure(), CLGradientKernel::configure(), CLComputeAllAnchorsKernel::configure(), CLMinMaxKernel::configure(), CLReorgLayerKernel::configure(), CLGatherKernel::configure(), CLSpaceToBatchLayerKernel::configure(), CLUpsampleLayerKernel::configure(), CLTileKernel::configure(), CLDepthwiseConvolutionLayer3x3NCHWKernel::configure(), CLDerivativeKernel::configure(), GCPoolingLayerKernel::configure(), CLActivationLayerKernel::configure(), GCPixelWiseMultiplicationKernel::configure(), CLComparisonKernel::configure(), CLMeanStdDevNormalizationKernel::configure(), CLMemsetKernel::configure(), CLPermuteKernel::configure(), CLFFTScaleKernel::configure(), CLSobel3x3Kernel::configure(), CLDepthConvertLayerKernel::configure(), CLDepthwiseConvolutionLayer3x3NHWCKernel::configure(), GCDepthwiseConvolutionLayer3x3Kernel::configure(), GCGEMMMatrixAdditionKernel::configure(), CLHOGOrientationBinningKernel::configure(), GCNormalizationLayerKernel::configure(), CLFFTDigitReverseKernel::configure(), CLFillBorderKernel::configure(), CLNormalizePlanarYUVLayerKernel::configure(), CLPixelWiseMultiplicationKernel::configure(), CLPoolingLayerKernel::configure(), CLQuantizationLayerKernel::configure(), CLSobel5x5HorKernel::configure(), CLSobel7x7HorKernel::configure(), CLWidthConcatenate2TensorsKernel::configure(), GCFillBorderKernel::configure(), CLHeightConcatenateLayerKernel::configure(), GCNormalizePlanarYUVLayerKernel::configure(), CLInstanceNormalizationLayerKernel::configure(), CLPadLayerKernel::configure(), CLPriorBoxLayerKernel::configure(), CLCropKernel::configure(), CLGEMMLowpMatrixMultiplyNativeKernel::configure(), CLWidthConcatenateLayerKernel::configure(), GCAbsoluteDifferenceKernel::configure(), GCGEMMTranspose1xWKernel::configure(), CLL2NormalizeLayerKernel::configure(), CLMagnitudePhaseKernel::configure(), CLColorConvertKernel::configure(), CLRangeKernel::configure(), CLReductionOperationKernel::configure(), CLBoundingBoxTransformKernel::configure(), CLWidthConcatenate4TensorsKernel::configure(), CLGEMMReshapeRHSMatrixKernel::configure(), GCArithmeticAdditionKernel::configure(), CLFFTRadixStageKernel::configure(), CLSelectKernel::configure(), CLConvertFullyConnectedWeightsKernel::configure(), CLBatchConcatenateLayerKernel::configure(), CLDepthConcatenateLayerKernel::configure(), GCBatchNormalizationLayerKernel::configure(), CLStackLayerKernel::configure(), GCActivationLayerKernel::configure(), CLGEMMReshapeLHSMatrixKernel::configure(), GCDepthConcatenateLayerKernel::configure(), CLIntegralImageVertKernel::configure(), CLGEMMLowpMatrixMultiplyReshapedOnlyRHSKernel::configure(), CLWinogradInputTransformKernel::configure(), CLYOLOLayerKernel::configure(), CLGEMMMatrixMultiplyNativeKernel::configure(), CLFuseBatchNormalizationKernel::configure(), CLROIPoolingLayerKernel::configure(), GCLogits1DShiftExpSumKernel::configure(), CLWinogradFilterTransformKernel::configure(), CLBatchNormalizationLayerKernel::configure(), CLROIAlignLayerKernel::configure(), GCDropoutLayerKernel::configure(), GCGEMMMatrixMultiplyKernel::configure(), CLGEMMLowpMatrixMultiplyReshapedKernel::configure(), CLHarrisScoreKernel::configure(), CLStridedSliceKernel::configure(), CLArgMinMaxLayerKernel::configure(), CLGEMMMatrixMultiplyReshapedOnlyRHSKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CLFastCornersKernel::configure(), CLWinogradOutputTransformKernel::configure(), CLGEMMMatrixMultiplyKernel::configure(), CLHOGDetectorKernel::configure(), GCGEMMInterleave4x4Kernel::configure(), CLDirectConvolutionLayerKernel::configure(), CLDeconvolutionReshapeOutputKernel::configure(), CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::configure(), CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::configure(), CLGEMMLowpOffsetContributionKernel::configure(), CLGEMMLowpOffsetContributionOutputStageKernel::configure(), GCTensorShiftKernel::configure(), CLCol2ImKernel::configure(), GCWeightsReshapeKernel::configure(), GCCol2ImKernel::configure(), GCIm2ColKernel::configure(), CLWeightsReshapeKernel::configure(), CLIm2ColKernel::configure(), CLHistogramBorderKernel::configure(), CLGaussianPyramidVertKernel::configure(), CLEdgeNonMaxSuppressionKernel::configure(), CLHOGBlockNormalizationKernel::configure(), GCLogits1DNormKernel::configure(), CLSobel5x5VertKernel::configure(), CLSobel7x7VertKernel::configure(), CLCopyToArrayKernel::configure(), CLLogits1DMaxShiftExpSumKernel::configure(), CLEdgeTraceKernel::configure(), CLConvolutionRectangleKernel::configure(), CLLogits1DNormKernel::configure(), CLKernelLibrary::create_kernel(), 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 393 of file ToolchainSupport.h.

394 {
395  std::stringstream str;
396  str << std::boolalpha << value;
397  return str.str();
398 }

◆ 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 333 of file ToolchainSupport.h.

334 {
335  return std::trunc(value);
336 }
T trunc(T value)
Truncate floating-point value.

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