ArmNN  NotReleased
MockCounterDirectory Class Reference

#include <ProfilingMocks.hpp>

Inheritance diagram for MockCounterDirectory:
ICounterDirectory

Public Member Functions

 MockCounterDirectory ()=default
 
 ~MockCounterDirectory ()=default
 
const CategoryRegisterCategory (const std::string &categoryName, const armnn::Optional< uint16_t > &deviceUid=armnn::EmptyOptional(), const armnn::Optional< uint16_t > &counterSetUid=armnn::EmptyOptional())
 
const DeviceRegisterDevice (const std::string &deviceName, uint16_t cores=0, const armnn::Optional< std::string > &parentCategoryName=armnn::EmptyOptional())
 
const CounterSetRegisterCounterSet (const std::string &counterSetName, uint16_t count=0, const armnn::Optional< std::string > &parentCategoryName=armnn::EmptyOptional())
 
const CounterRegisterCounter (const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const armnn::Optional< std::string > &units=armnn::EmptyOptional(), const armnn::Optional< uint16_t > &numberOfCores=armnn::EmptyOptional(), const armnn::Optional< uint16_t > &deviceUid=armnn::EmptyOptional(), const armnn::Optional< uint16_t > &counterSetUid=armnn::EmptyOptional())
 
uint16_t GetCategoryCount () const override
 
uint16_t GetDeviceCount () const override
 
uint16_t GetCounterSetCount () const override
 
uint16_t GetCounterCount () const override
 
const CategoriesGetCategories () const override
 
const DevicesGetDevices () const override
 
const CounterSetsGetCounterSets () const override
 
const CountersGetCounters () const override
 
const CategoryGetCategory (const std::string &name) const override
 
const DeviceGetDevice (uint16_t uid) const override
 
const CounterSetGetCounterSet (uint16_t uid) const override
 
const CounterGetCounter (uint16_t uid) const override
 
- Public Member Functions inherited from ICounterDirectory
virtual ~ICounterDirectory ()
 

Detailed Description

Definition at line 439 of file ProfilingMocks.hpp.

Constructor & Destructor Documentation

◆ MockCounterDirectory()

MockCounterDirectory ( )
default

◆ ~MockCounterDirectory()

~MockCounterDirectory ( )
default

Member Function Documentation

◆ GetCategories()

const Categories& GetCategories ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 603 of file ProfilingMocks.hpp.

603 { return m_Categories; }

◆ GetCategory()

const Category* GetCategory ( const std::string &  name) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 609 of file ProfilingMocks.hpp.

610  {
611  auto it = std::find_if(m_Categories.begin(), m_Categories.end(), [&name](const CategoryPtr& category)
612  {
613  BOOST_ASSERT(category);
614 
615  return category->m_Name == name;
616  });
617 
618  if (it == m_Categories.end())
619  {
620  return nullptr;
621  }
622 
623  return it->get();
624  }
std::unique_ptr< Category > CategoryPtr

◆ GetCategoryCount()

uint16_t GetCategoryCount ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 597 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

597 { return boost::numeric_cast<uint16_t>(m_Categories.size()); }

◆ GetCounter()

const Counter* GetCounter ( uint16_t  uid) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 638 of file ProfilingMocks.hpp.

639  {
640  boost::ignore_unused(uid);
641  return nullptr; // Not used by the unit tests
642  }

◆ GetCounterCount()

uint16_t GetCounterCount ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 600 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

600 { return boost::numeric_cast<uint16_t>(m_Counters.size()); }

◆ GetCounters()

const Counters& GetCounters ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 606 of file ProfilingMocks.hpp.

606 { return m_Counters; }

◆ GetCounterSet()

const CounterSet* GetCounterSet ( uint16_t  uid) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 632 of file ProfilingMocks.hpp.

633  {
634  boost::ignore_unused(uid);
635  return nullptr; // Not used by the unit tests
636  }

◆ GetCounterSetCount()

uint16_t GetCounterSetCount ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 599 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

599 { return boost::numeric_cast<uint16_t>(m_CounterSets.size()); }

◆ GetCounterSets()

const CounterSets& GetCounterSets ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 605 of file ProfilingMocks.hpp.

605 { return m_CounterSets; }

◆ GetDevice()

const Device* GetDevice ( uint16_t  uid) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 626 of file ProfilingMocks.hpp.

627  {
628  boost::ignore_unused(uid);
629  return nullptr; // Not used by the unit tests
630  }

◆ GetDeviceCount()

uint16_t GetDeviceCount ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 598 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

598 { return boost::numeric_cast<uint16_t>(m_Devices.size()); }

◆ GetDevices()

const Devices& GetDevices ( ) const
inlineoverridevirtual

Implements ICounterDirectory.

Definition at line 604 of file ProfilingMocks.hpp.

604 { return m_Devices; }

◆ RegisterCategory()

const Category* RegisterCategory ( const std::string &  categoryName,
const armnn::Optional< uint16_t > &  deviceUid = armnn::EmptyOptional(),
const armnn::Optional< uint16_t > &  counterSetUid = armnn::EmptyOptional() 
)
inline

Definition at line 446 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

449  {
450  // Get the device UID
451  uint16_t deviceUidValue = deviceUid.has_value() ? deviceUid.value() : 0;
452 
453  // Get the counter set UID
454  uint16_t counterSetUidValue = counterSetUid.has_value() ? counterSetUid.value() : 0;
455 
456  // Create the category
457  CategoryPtr category = std::make_unique<Category>(categoryName, deviceUidValue, counterSetUidValue);
458  BOOST_ASSERT(category);
459 
460  // Get the raw category pointer
461  const Category* categoryPtr = category.get();
462  BOOST_ASSERT(categoryPtr);
463 
464  // Register the category
465  m_Categories.insert(std::move(category));
466 
467  return categoryPtr;
468  }
std::unique_ptr< Category > CategoryPtr
bool has_value() const noexcept
Definition: Optional.hpp:53

◆ RegisterCounter()

const Counter* RegisterCounter ( const BackendId backendId,
const uint16_t  uid,
const std::string &  parentCategoryName,
uint16_t  counterClass,
uint16_t  interpolation,
double  multiplier,
const std::string &  name,
const std::string &  description,
const armnn::Optional< std::string > &  units = armnn::EmptyOptional(),
const armnn::Optional< uint16_t > &  numberOfCores = armnn::EmptyOptional(),
const armnn::Optional< uint16_t > &  deviceUid = armnn::EmptyOptional(),
const armnn::Optional< uint16_t > &  counterSetUid = armnn::EmptyOptional() 
)
inline

Definition at line 531 of file ProfilingMocks.hpp.

References armnn::profiling::GetNextCounterUids(), and Category::m_Counters.

Referenced by BOOST_AUTO_TEST_CASE().

543  {
544  boost::ignore_unused(backendId);
545 
546  // Get the number of cores from the argument only
547  uint16_t deviceCores = numberOfCores.has_value() ? numberOfCores.value() : 0;
548 
549  // Get the device UID
550  uint16_t deviceUidValue = deviceUid.has_value() ? deviceUid.value() : 0;
551 
552  // Get the counter set UID
553  uint16_t counterSetUidValue = counterSetUid.has_value() ? counterSetUid.value() : 0;
554 
555  // Get the counter UIDs and calculate the max counter UID
556  std::vector<uint16_t> counterUids = GetNextCounterUids(uid, deviceCores);
557  BOOST_ASSERT(!counterUids.empty());
558  uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
559 
560  // Get the counter units
561  const std::string unitsValue = units.has_value() ? units.value() : "";
562 
563  // Create the counter
564  CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
565  counterUids.front(),
566  maxCounterUid,
567  counterClass,
568  interpolation,
569  multiplier,
570  name,
571  description,
572  unitsValue,
573  deviceUidValue,
574  counterSetUidValue);
575  BOOST_ASSERT(counter);
576 
577  // Get the raw counter pointer
578  const Counter* counterPtr = counter.get();
579  BOOST_ASSERT(counterPtr);
580 
581  // Process multiple counters if necessary
582  for (uint16_t counterUid : counterUids)
583  {
584  // Connect the counter to the parent category
585  Category* parentCategory = const_cast<Category*>(GetCategory(parentCategoryName));
586  BOOST_ASSERT(parentCategory);
587  parentCategory->m_Counters.push_back(counterUid);
588 
589  // Register the counter
590  m_Counters.insert(std::make_pair(counterUid, counter));
591  }
592 
593  return counterPtr;
594  }
std::vector< uint16_t > GetNextCounterUids(uint16_t firstUid, uint16_t cores)
std::shared_ptr< Counter > CounterPtr
const Category * GetCategory(const std::string &name) const override
bool has_value() const noexcept
Definition: Optional.hpp:53

◆ RegisterCounterSet()

const CounterSet* RegisterCounterSet ( const std::string &  counterSetName,
uint16_t  count = 0,
const armnn::Optional< std::string > &  parentCategoryName = armnn::EmptyOptional() 
)
inline

Definition at line 500 of file ProfilingMocks.hpp.

References armnn::profiling::GetNextUid(), and Category::m_CounterSetUid.

Referenced by BOOST_AUTO_TEST_CASE().

504  {
505  // Get the counter set UID
506  uint16_t counterSetUid = GetNextUid();
507 
508  // Create the counter set
509  CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
510  BOOST_ASSERT(counterSet);
511 
512  // Get the raw counter set pointer
513  const CounterSet* counterSetPtr = counterSet.get();
514  BOOST_ASSERT(counterSetPtr);
515 
516  // Register the counter set
517  m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
518 
519  // Connect the counter set to the parent category, if required
520  if (parentCategoryName.has_value())
521  {
522  // Set the counter set UID in the parent category
523  Category* parentCategory = const_cast<Category*>(GetCategory(parentCategoryName.value()));
524  BOOST_ASSERT(parentCategory);
525  parentCategory->m_CounterSetUid = counterSetUid;
526  }
527 
528  return counterSetPtr;
529  }
std::unique_ptr< CounterSet > CounterSetPtr
uint16_t GetNextUid(bool peekOnly)
const Category * GetCategory(const std::string &name) const override
bool has_value() const noexcept
Definition: Optional.hpp:53

◆ RegisterDevice()

const Device* RegisterDevice ( const std::string &  deviceName,
uint16_t  cores = 0,
const armnn::Optional< std::string > &  parentCategoryName = armnn::EmptyOptional() 
)
inline

Definition at line 470 of file ProfilingMocks.hpp.

References armnn::profiling::GetNextUid(), and Category::m_DeviceUid.

Referenced by BOOST_AUTO_TEST_CASE().

473  {
474  // Get the device UID
475  uint16_t deviceUid = GetNextUid();
476 
477  // Create the device
478  DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
479  BOOST_ASSERT(device);
480 
481  // Get the raw device pointer
482  const Device* devicePtr = device.get();
483  BOOST_ASSERT(devicePtr);
484 
485  // Register the device
486  m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
487 
488  // Connect the counter set to the parent category, if required
489  if (parentCategoryName.has_value())
490  {
491  // Set the counter set UID in the parent category
492  Category* parentCategory = const_cast<Category*>(GetCategory(parentCategoryName.value()));
493  BOOST_ASSERT(parentCategory);
494  parentCategory->m_DeviceUid = deviceUid;
495  }
496 
497  return devicePtr;
498  }
uint16_t GetNextUid(bool peekOnly)
const Category * GetCategory(const std::string &name) const override
std::unique_ptr< Device > DevicePtr
bool has_value() const noexcept
Definition: Optional.hpp:53

The documentation for this class was generated from the following file: