Compute Library
 23.11
VerifyAccessor< D > Class Template Referenceabstract

Graph example validation accessor class. More...

#include <graph_validate_utils.h>

Collaboration diagram for VerifyAccessor< D >:
[legend]

Public Types

using TBias = typename std::conditional< std::is_same< typename std::decay< D >::type, uint8_t >::value, int32_t, D >::type
 

Public Member Functions

 VerifyAccessor (ExampleParams &params)
 Constructor. More...
 
bool access_tensor (ITensor &tensor) override
 Interface to be implemented to access a given tensor. More...
 
virtual void create_tensors (arm_compute::test::SimpleTensor< D > &src, arm_compute::test::SimpleTensor< D > &weights, arm_compute::test::SimpleTensor< TBias > &bias, ITensor &tensor)
 Create reference tensors. More...
 
virtual TensorShape output_shape (ITensor &tensor)
 Calculate reference output tensor shape. More...
 
virtual arm_compute::test::SimpleTensor< D > reference (arm_compute::test::SimpleTensor< D > &src, arm_compute::test::SimpleTensor< D > &weights, arm_compute::test::SimpleTensor< TBias > &bias, const arm_compute::TensorShape &output_shape)=0
 Calculate reference tensor. More...
 
void fill_tensor (arm_compute::test::SimpleTensor< uint8_t > &tensor, std::random_device::result_type seed, uint8_t low, uint8_t high)
 Fill QASYMM tensor with Random values. More...
 
void fill_tensor (arm_compute::test::SimpleTensor< int32_t > &tensor, std::random_device::result_type seed, int32_t low, int32_t high)
 Fill S32 tensor with Random values. More...
 
void fill_tensor (arm_compute::test::SimpleTensor< float > &tensor, std::random_device::result_type seed, float low, float high)
 Fill F32 tensor with Random values. More...
 
void fill_tensor (arm_compute::test::SimpleTensor< half > &tensor, std::random_device::result_type seed, half low, half high)
 Fill F16 tensor with Random values. More...
 
virtual float relative_tolerance ()=0
 Select relative tolerance. More...
 
virtual float absolute_tolerance ()=0
 Select absolute tolerance. More...
 
virtual float tolerance_number ()=0
 Select tolerance number. More...
 
void validate (ITensor &tensor, arm_compute::test::SimpleTensor< D > output)
 Validate the output versus the reference. More...
 
- Public Member Functions inherited from ITensorAccessor
virtual ~ITensorAccessor ()=default
 Default virtual destructor. More...
 
virtual bool access_tensor_data ()
 Returns true if the tensor data is being accessed. More...
 

Data Fields

ExampleParams _params
 

Detailed Description

template<typename D>
class arm_compute::utils::VerifyAccessor< D >

Graph example validation accessor class.

Definition at line 346 of file graph_validate_utils.h.

Member Typedef Documentation

◆ TBias

using TBias = typename std::conditional<std::is_same<typename std::decay<D>::type, uint8_t>::value, int32_t, D>::type

Definition at line 349 of file graph_validate_utils.h.

Constructor & Destructor Documentation

◆ VerifyAccessor()

VerifyAccessor ( ExampleParams params)
inlineexplicit

Constructor.

Parameters
[in]paramsConvolution parameters

Definition at line 354 of file graph_validate_utils.h.

355  : _params(std::move(params))
356  {
357  }

Member Function Documentation

◆ absolute_tolerance()

virtual float absolute_tolerance ( )
pure virtual

Select absolute tolerance.

Select absolute tolerance if not supplied by user.

Returns
Appropriate absolute tolerance.

Referenced by VerifyAccessor< D >::validate().

◆ access_tensor()

bool access_tensor ( ITensor tensor)
inlineoverridevirtual

Interface to be implemented to access a given tensor.

Parameters
[in]tensorTensor to be accessed
Returns
True if access is successful else false

Implements ITensorAccessor.

Definition at line 359 of file graph_validate_utils.h.

360  {
361  if(_params.output.npy.empty())
362  {
366 
367  //Create Input tensors
368  create_tensors(src, weights, bias, tensor);
369 
370  //Fill the tensors with random values
371  fill_tensor(src, 0, static_cast<D>(_params.input.range_low), static_cast<D>(_params.input.range_high));
372  fill_tensor(weights, 1, static_cast<D>(_params.weights.range_low), static_cast<D>(_params.weights.range_high));
373  fill_tensor(bias, 2, static_cast<TBias>(_params.input.range_low), static_cast<TBias>(_params.input.range_high));
374 
376 
377  validate(tensor, output);
378  }
379  else
380  {
381  //The user provided a reference file use an npy accessor to validate
382  arm_compute::graph_utils::NumPyAccessor(_params.output.npy, tensor.info()->tensor_shape(), tensor.info()->data_type()).access_tensor(tensor);
383  }
384  return false;
385  }

References VerifyAccessor< D >::_params, NumPyAccessor::access_tensor(), bias, VerifyAccessor< D >::create_tensors(), VerifyAccessor< D >::fill_tensor(), CommonParams::input, TensorParams::npy, CommonParams::output, VerifyAccessor< D >::output_shape(), TensorParams::range_high, TensorParams::range_low, VerifyAccessor< D >::reference(), arm_compute::test::validation::src, tensor, VerifyAccessor< D >::validate(), and CommonParams::weights.

◆ create_tensors()

virtual void create_tensors ( arm_compute::test::SimpleTensor< D > &  src,
arm_compute::test::SimpleTensor< D > &  weights,
arm_compute::test::SimpleTensor< TBias > &  bias,
ITensor tensor 
)
inlinevirtual

Create reference tensors.

Validate the given tensor against the reference result.

Parameters
[out]srcThe tensor with the source data.
[out]weightsThe tensor with the weigths data.
[out]biasThe tensor with the bias data.
[in]tensorTensor result of the actual operation passed into the Accessor.

Definition at line 397 of file graph_validate_utils.h.

References VerifyAccessor< D >::_params, ARM_COMPUTE_UNUSED, TensorParams::batch, bias, CommonParams::data_type, TensorParams::fm, TensorParams::height, CommonParams::input, TensorParams::quant_info, arm_compute::test::validation::src, tensor, CommonParams::weights, and TensorParams::width.

Referenced by VerifyAccessor< D >::access_tensor().

◆ fill_tensor() [1/4]

void fill_tensor ( arm_compute::test::SimpleTensor< float > &  tensor,
std::random_device::result_type  seed,
float  low,
float  high 
)
inline

Fill F32 tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values

Definition at line 490 of file graph_validate_utils.h.

491  {
493  std::mt19937 gen(seed);
494  std::uniform_real_distribution<float> distribution(low, high);
495 
496  for(int i = 0; i < tensor.num_elements(); ++i)
497  {
498  tensor[i] = distribution(gen);
499  }
500  }

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::distribution(), arm_compute::F32, and tensor.

◆ fill_tensor() [2/4]

void fill_tensor ( arm_compute::test::SimpleTensor< half > &  tensor,
std::random_device::result_type  seed,
half  low,
half  high 
)
inline

Fill F16 tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values

Definition at line 510 of file graph_validate_utils.h.

511  {
513  std::mt19937 gen(seed);
514  std::uniform_real_distribution<float> distribution(static_cast<half>(low), static_cast<half>(high));
515 
516  for(int i = 0; i < tensor.num_elements(); ++i)
517  {
518  tensor[i] = static_cast<half>(distribution(gen));
519  }
520  }

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::distribution(), arm_compute::F16, and tensor.

◆ fill_tensor() [3/4]

void fill_tensor ( arm_compute::test::SimpleTensor< int32_t > &  tensor,
std::random_device::result_type  seed,
int32_t  low,
int32_t  high 
)
inline

Fill S32 tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values

Definition at line 471 of file graph_validate_utils.h.

472  {
473  std::mt19937 gen(seed);
474  std::uniform_int_distribution<int32_t> distribution(static_cast<int32_t>(low), static_cast<uint32_t>(high));
475 
476  for(int i = 0; i < tensor.num_elements(); ++i)
477  {
478  tensor[i] = distribution(gen);
479  }
480  }

References arm_compute::test::validation::distribution(), and tensor.

◆ fill_tensor() [4/4]

void fill_tensor ( arm_compute::test::SimpleTensor< uint8_t > &  tensor,
std::random_device::result_type  seed,
uint8_t  low,
uint8_t  high 
)
inline

Fill QASYMM tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values

Definition at line 445 of file graph_validate_utils.h.

446  {
448 
449  const UniformQuantizationInfo qinfo = tensor.quantization_info().uniform();
450 
451  uint8_t qasymm8_low = quantize_qasymm8(low, qinfo);
452  uint8_t qasymm8_high = quantize_qasymm8(high, qinfo);
453 
454  std::mt19937 gen(seed);
455  std::uniform_int_distribution<uint8_t> distribution(qasymm8_low, qasymm8_high);
456 
457  for(int i = 0; i < tensor.num_elements(); ++i)
458  {
460  }
461  }

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::distribution(), arm_compute::QASYMM8, arm_compute::test::validation::qinfo, arm_compute::quantize_qasymm8(), and tensor.

Referenced by VerifyAccessor< D >::access_tensor().

◆ output_shape()

virtual TensorShape output_shape ( ITensor tensor)
inlinevirtual

Calculate reference output tensor shape.

Parameters
[in]tensorTensor result of the actual operation passed into the Accessor.
Returns
output tensor shape.

Definition at line 415 of file graph_validate_utils.h.

416  {
418  }

References VerifyAccessor< D >::_params, ExampleParams::data_layout, arm_compute::NCHW, arm_compute::graph_utils::permute_shape(), and tensor.

Referenced by VerifyAccessor< D >::access_tensor().

◆ reference()

virtual arm_compute::test::SimpleTensor<D> reference ( arm_compute::test::SimpleTensor< D > &  src,
arm_compute::test::SimpleTensor< D > &  weights,
arm_compute::test::SimpleTensor< TBias > &  bias,
const arm_compute::TensorShape output_shape 
)
pure virtual

Calculate reference tensor.

Validate the given tensor against the reference result.

Parameters
[in]srcThe tensor with the source data.
[in]weightsThe tensor with the weigths data.
[in]biasThe tensor with the bias data.
[in]output_shapeShape of the output tensor.
Returns
Tensor with the reference output.

Referenced by VerifyAccessor< D >::access_tensor().

◆ relative_tolerance()

virtual float relative_tolerance ( )
pure virtual

Select relative tolerance.

Select relative tolerance if not supplied by user.

Returns
Appropriate relative tolerance.

Referenced by VerifyAccessor< D >::validate().

◆ tolerance_number()

virtual float tolerance_number ( )
pure virtual

Select tolerance number.

Select tolerance number if not supplied by user.

Returns
Appropriate tolerance number.

Referenced by VerifyAccessor< D >::validate().

◆ validate()

void validate ( ITensor tensor,
arm_compute::test::SimpleTensor< D >  output 
)
inline

Validate the output versus the reference.

Parameters
[in]tensorTensor result of the actual operation passed into the Accessor.
[in]outputTensor result of the reference implementation.

< Relative tolerance

< Absolute tolerance

< Tolerance number

Definition at line 551 of file graph_validate_utils.h.

552  {
553  float user_relative_tolerance = _params.verification.relative_tolerance;
554  float user_absolute_tolerance = _params.verification.absolute_tolerance;
555  float user_tolerance_num = _params.verification.tolerance_number;
556  /* If no user input was provided override with defaults. */
557  if(user_relative_tolerance == -1)
558  {
559  user_relative_tolerance = relative_tolerance();
560  }
561 
562  if(user_absolute_tolerance == -1)
563  {
564  user_absolute_tolerance = absolute_tolerance();
565  }
566 
567  if(user_tolerance_num == -1)
568  {
569  user_tolerance_num = tolerance_number();
570  }
571 
572  const arm_compute::test::validation::RelativeTolerance<float> rel_tolerance(user_relative_tolerance); /**< Relative tolerance */
573  const arm_compute::test::validation::AbsoluteTolerance<float> abs_tolerance(user_absolute_tolerance); /**< Absolute tolerance */
574  const float tolerance_num(user_tolerance_num); /**< Tolerance number */
575 
577  }

References VerifyAccessor< D >::_params, VerificationParams::absolute_tolerance, VerifyAccessor< D >::absolute_tolerance(), VerificationParams::relative_tolerance, VerifyAccessor< D >::relative_tolerance(), tensor, arm_compute::test::validation::tolerance_num, VerificationParams::tolerance_number, VerifyAccessor< D >::tolerance_number(), arm_compute::test::validation::validate(), and CommonParams::verification.

Referenced by VerifyAccessor< D >::access_tensor().

Field Documentation

◆ _params


The documentation for this class was generated from the following file:
arm_compute::DataLayout::NCHW
@ NCHW
Num samples, channels, height, width.
arm_compute::utils::TensorParams::quant_info
QuantizationInfo quant_info
Definition: graph_validate_utils.h:112
arm_compute::utils::ExampleParams::data_layout
arm_compute::DataLayout data_layout
Definition: graph_validate_utils.h:183
arm_compute::utils::VerifyAccessor::reference
virtual arm_compute::test::SimpleTensor< D > reference(arm_compute::test::SimpleTensor< D > &src, arm_compute::test::SimpleTensor< D > &weights, arm_compute::test::SimpleTensor< TBias > &bias, const arm_compute::TensorShape &output_shape)=0
Calculate reference tensor.
arm_compute::utils::VerifyAccessor::output_shape
virtual TensorShape output_shape(ITensor &tensor)
Calculate reference output tensor shape.
Definition: graph_validate_utils.h:415
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
arm_compute::DataType::QASYMM8
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
arm_compute::quantize_qasymm8
uint8_t quantize_qasymm8(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given an unsigned 8-bit asymmetric quantization scheme.
Definition: QuantizationInfo.h:295
arm_compute::test::validation::tolerance_num
constexpr float tolerance_num
Tolerance number.
Definition: Add.cpp:107
arm_compute::graph_utils::NumPyAccessor::access_tensor
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
Definition: GraphUtils.cpp:217
arm_compute::utils::TensorParams::range_low
uint64_t range_low
Definition: graph_validate_utils.h:114
arm_compute::test::Accessor
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
arm_compute::utils::TensorParams::height
int height
Definition: graph_validate_utils.h:109
arm_compute::utils::VerificationParams::relative_tolerance
float relative_tolerance
Definition: graph_validate_utils.h:122
arm_compute::utils::CommonParams::data_type
arm_compute::DataType data_type
Definition: graph_validate_utils.h:143
arm_compute::test::validation::validate
validate(CLAccessor(output_state), expected_output)
arm_compute::half
half_float::half half
16-bit floating point type
Definition: CoreTypes.h:36
arm_compute::utils::TensorParams::range_high
uint64_t range_high
Definition: graph_validate_utils.h:115
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
arm_compute::utils::TensorParams::fm
int fm
Definition: graph_validate_utils.h:110
arm_compute::utils::VerifyAccessor::relative_tolerance
virtual float relative_tolerance()=0
Select relative tolerance.
arm_compute::graph_utils::permute_shape
TensorShape permute_shape(TensorShape tensor_shape, DataLayout in_data_layout, DataLayout out_data_layout)
Permutes a given tensor shape given the input and output data layout.
Definition: GraphUtils.h:673
arm_compute::utils::VerifyAccessor::_params
ExampleParams _params
Definition: graph_validate_utils.h:579
arm_compute::utils::CommonParams::verification
VerificationParams verification
Definition: graph_validate_utils.h:142
bias
const int32_t * bias
Definition: working_space.hpp:322
arm_compute::utils::VerificationParams::tolerance_number
float tolerance_number
Definition: graph_validate_utils.h:123
arm_compute::utils::VerifyAccessor::TBias
typename std::conditional< std::is_same< typename std::decay< D >::type, uint8_t >::value, int32_t, D >::type TBias
Definition: graph_validate_utils.h:349
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:151
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition: ClWorkloadRuntime.cpp:67
arm_compute::utils::VerifyAccessor::create_tensors
virtual void create_tensors(arm_compute::test::SimpleTensor< D > &src, arm_compute::test::SimpleTensor< D > &weights, arm_compute::test::SimpleTensor< TBias > &bias, ITensor &tensor)
Create reference tensors.
Definition: graph_validate_utils.h:397
arm_compute::graph_utils::NumPyAccessor
NumPy accessor class.
Definition: GraphUtils.h:147
arm_compute::utils::TensorParams::npy
std::string npy
Definition: graph_validate_utils.h:113
arm_compute::utils::VerifyAccessor::fill_tensor
void fill_tensor(arm_compute::test::SimpleTensor< uint8_t > &tensor, std::random_device::result_type seed, uint8_t low, uint8_t high)
Fill QASYMM tensor with Random values.
Definition: graph_validate_utils.h:445
arm_compute::test::SimpleTensor
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
arm_compute::utils::VerificationParams::absolute_tolerance
float absolute_tolerance
Definition: graph_validate_utils.h:121
arm_compute::utils::CommonParams::weights
TensorParams weights
Definition: graph_validate_utils.h:139
arm_compute::DataType::F16
@ F16
16-bit floating-point number
arm_compute::utils::CommonParams::output
TensorParams output
Definition: graph_validate_utils.h:141
arm_compute::test::validation::distribution
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
arm_compute::DataType::F32
@ F32
32-bit floating-point number
arm_compute::utils::VerifyAccessor::tolerance_number
virtual float tolerance_number()=0
Select tolerance number.
arm_compute::utils::TensorParams::batch
int batch
Definition: graph_validate_utils.h:111
arm_compute::utils::TensorParams::width
int width
Definition: graph_validate_utils.h:108
arm_compute::utils::CommonParams::input
TensorParams input
Definition: graph_validate_utils.h:138
arm_compute::test::validation::RelativeTolerance
Class reprensenting a relative tolerance value.
Definition: Validation.h:97
arm_compute::test::validation::AbsoluteTolerance
Class reprensenting an absolute tolerance value.
Definition: Validation.h:61
arm_compute::utils::VerifyAccessor::absolute_tolerance
virtual float absolute_tolerance()=0
Select absolute tolerance.
arm_compute::test::validation::qinfo
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
arm_compute::utils::VerifyAccessor::validate
void validate(ITensor &tensor, arm_compute::test::SimpleTensor< D > output)
Validate the output versus the reference.
Definition: graph_validate_utils.h:551