From af6f49e425c1b5d275a0dfc01ca3c10a8dddb3b7 Mon Sep 17 00:00:00 2001 From: Yermalayeu Ihar Date: Tue, 4 Jul 2023 19:36:43 +0300 Subject: [PATCH] +add Base implementation of function SimdCpuDesc. --- docs/2023.html | 7 ++++ docs/help/class_simd_1_1_font.html | 2 +- docs/help/group__c__types.html | 24 ++++++++++- docs/help/group__descrint.html | 1 - docs/help/group__info.html | 57 ++++++++++++++++++++++---- docs/help/group__synet__normalize.html | 6 +-- docs/help/namespace_simd.html | 2 +- src/Simd/SimdBaseCpu.cpp | 38 +++++++++++++---- src/Simd/SimdCpu.h | 5 +++ src/Simd/SimdLib.cpp | 10 +++++ src/Simd/SimdLib.h | 44 ++++++++++++++++---- src/Simd/SimdLib.hpp | 3 +- src/Test/TestCheckCpp.cpp | 2 + src/Test/TestPerformance.cpp | 25 ++--------- 14 files changed, 172 insertions(+), 54 deletions(-) diff --git a/docs/2023.html b/docs/2023.html index 1bc7e71c70..34658492f7 100644 --- a/docs/2023.html +++ b/docs/2023.html @@ -39,6 +39,7 @@
New features

Test framework

Improving
@@ -46,6 +47,12 @@
Improving
  • WIN32 performance report.
  • +

    Documentation

    +
    Bug fixing
    + +

    July 4, 2023 (version 5.3.127)

    Algorithms

    diff --git a/docs/help/class_simd_1_1_font.html b/docs/help/class_simd_1_1_font.html index 0b656ab1b5..1a4af07eaa 100644 --- a/docs/help/class_simd_1_1_font.html +++ b/docs/help/class_simd_1_1_font.html @@ -107,7 +107,7 @@

    Simd Library Documentation.

    }
    The Font class provides text drawing.
    Definition: SimdFont.hpp:64
    Simd::View< Simd::Allocator > View
    Definition: SimdFont.hpp:68
    -
    SIMD_INLINE void FillPixel(View< A > &dst, const Pixel &pixel)
    Fills image by value of given pixel.
    Definition: SimdLib.hpp:2065
    +
    SIMD_INLINE void FillPixel(View< A > &dst, const Pixel &pixel)
    Fills image by value of given pixel.
    Definition: SimdLib.hpp:2066
    32-bit BGRA pixel.
    Definition: SimdPixel.hpp:136
    @ Bgra32
    Definition: SimdView.hpp:89
    diff --git a/docs/help/group__c__types.html b/docs/help/group__c__types.html index 9084d97015..806a396d44 100644 --- a/docs/help/group__c__types.html +++ b/docs/help/group__c__types.html @@ -83,6 +83,9 @@

    Simd Library Documentation.


    }   +enum  SimdCpuDescType { SimdCpuDescModel + } +  enum  SimdCpuInfoType {
      SimdCpuInfoSockets ,
    @@ -305,6 +308,25 @@

    +

    ◆ SimdCpuDescType

    + +
    +
    + + + + +
    enum SimdCpuDescType
    +
    +

    Describes type of description which can return function SimdCpuDesc.

    + + +
    Enumerator
    SimdCpuDescModel 

    A CPU model name.

    +
    +
    @@ -318,7 +340,7 @@

    -

    Describes type of information which can return function SimdCpuInfo.

    +

    Describes type of information which can return function SimdCpuInfo.

    diff --git a/docs/help/group__descrint.html b/docs/help/group__descrint.html index 3f770e1d9c..e8af581b92 100644 --- a/docs/help/group__descrint.html +++ b/docs/help/group__descrint.html @@ -114,7 +114,6 @@

    Initilizes Integer Descriptor Engine.

    -

    All images must have the same width and height. This function used for NV12 to YUV420P conversion.

    Parameters

    Enumerator
    SimdCpuInfoSockets 

    A number of sockets.

    diff --git a/docs/help/group__info.html b/docs/help/group__info.html index 6a05e68305..dbb545af25 100644 --- a/docs/help/group__info.html +++ b/docs/help/group__info.html @@ -53,14 +53,17 @@

    Simd Library Documentation.

    - - - + + + + + + - +
    [in]size- a length of original (32-bit or 16-bit) float descriptor. It be multiple of 8. Also it must be less or equal than 32768.
    SIMD_API const char * SimdVersion ()
     Gets version of Simd Library. More...
     
    SIMD_API uint64_t SimdCpuInfo (SimdCpuInfoType type)
     Gets info about CPU and Simd Library. More...
     
    SIMD_API const char * SimdCpuDesc (SimdCpuDescType type)
     Gets description of CPU and Simd Library. More...
     
    SIMD_API uint64_t SimdCpuInfo (SimdCpuInfoType type)
     Gets information about CPU and Simd Library. More...
     
    SIMD_API const char * SimdPerformanceStatistic ()
     Gets internal performance statistics of Simd Library. More...
     
    SIMD_INLINE void PrintInfo (std::ostream &os)
     Prints information about Simd Library and CPU properties. More...
     Prints information about Simd Library and CPU. More...
     

    Detailed Description

    @@ -86,14 +89,50 @@

    -

    ◆ SimdCpuInfo()

    + +

    ◆ SimdCpuDesc()

    - + + + + + + +
    size_t SimdCpuInfo const char * SimdCpuDesc (SimdCpuDescType type)
    +
    + +

    Gets description of CPU and Simd Library.

    +
    Note
    See enumeration SimdCpuDescType.
    +

    Using example:

    #include "Simd/SimdLib.h"
    +#include <iostream>
    +
    +int main()
    +{
    +    std::cout << "CPU: " << SimdCpuDesc(SimdCpuDescModel) << std::endl;
    +    return 0;
    +}
    +
    Parameters
    + + +
    [in]type- a type of required description.
    +
    +
    +
    Returns
    a value which contains description of CPU and Simd Library.
    + +
    +
    + +

    ◆ SimdCpuInfo()

    + +
    +
    + + + @@ -102,7 +141,7 @@

    -

    Gets info about CPU and Simd Library.

    +

    Gets information about CPU and Simd Library.

    Note
    See enumeration SimdCpuInfoType.

    Using example:

    #include "Simd/SimdLib.h"
     #include <iostream>
    @@ -175,7 +214,7 @@ 

    -

    Prints information about Simd Library and CPU properties.

    +

    Prints information about Simd Library and CPU.

    Parameters

    uint64_t SimdCpuInfo ( SimdCpuInfoType  type)
    diff --git a/docs/help/group__synet__normalize.html b/docs/help/group__synet__normalize.html index ce8b59c272..5c04681a62 100644 --- a/docs/help/group__synet__normalize.html +++ b/docs/help/group__synet__normalize.html @@ -352,9 +352,7 @@

    Performs forward propagation of NormalizeLayer (Version 3).

    -
    Algorithm's details:
    -\verbatim
    -for(b = 0; b < batch; ++b)
    +

    Algorithm's details:

    for(b = 0; b < batch; ++b)
         for(c = 0; c < channels; ++c)
         {
             sum = 0;
    @@ -383,7 +381,7 @@ 

    [in]

    - +
    [in,out]os- output stream.
    eps- a pointer to epsilon parameter. It is used to prevent division by zero.
    [in]format- a format of input and output tensor. It can be SimdTensorFormatNchw, SimdTensorFormatNhwc.
    [out]buf- a pointer to external temporary buffer. The size of the buffer must be equal to channels. Can be NULL (it causes usage of internal buffer).
    [out]dst- a pointer to the output 32-bit float tensor.
    [out]dst- a pointer to the output 32-bit float tensor.
    diff --git a/docs/help/namespace_simd.html b/docs/help/namespace_simd.html index a9e0d5cf3c..bc112f2dbe 100644 --- a/docs/help/namespace_simd.html +++ b/docs/help/namespace_simd.html @@ -306,7 +306,7 @@

    Simd Library Documentation.

    SIMD_INLINE bool 
    Compatible (const View< A > &a, const View< A > &b, const View< A > &c, const View< A > &d, const View< A > &e)   SIMD_INLINE void PrintInfo (std::ostream &os) - Prints information about Simd Library and CPU properties. More...
    + Prints information about Simd Library and CPU. More...
      template<template< class > class A> SIMD_INLINE void AbsDifference (const View< A > &a, const View< A > &b, View< A > &c) diff --git a/src/Simd/SimdBaseCpu.cpp b/src/Simd/SimdBaseCpu.cpp index 94a55e6c75..93e4323509 100644 --- a/src/Simd/SimdBaseCpu.cpp +++ b/src/Simd/SimdBaseCpu.cpp @@ -182,6 +182,15 @@ namespace Simd return 0; } + uint64_t CpuRamSize() + { + MEMORYSTATUSEX memorystatusex; + memorystatusex.dwLength = sizeof(memorystatusex); + if (GlobalMemoryStatusEx(&memorystatusex) == TRUE) + return memorystatusex.ullTotalPhys; + return 0; + } + static std::string Execute(const char* cmd) { std::string result = ""; @@ -199,13 +208,14 @@ namespace Simd return result; } - uint64_t CpuRamSize() + std::string CpuModel() { - MEMORYSTATUSEX memorystatusex; - memorystatusex.dwLength = sizeof(memorystatusex); - if (GlobalMemoryStatusEx(&memorystatusex) == TRUE) - return memorystatusex.ullTotalPhys; - return 0; + std::string raw = Execute("wmic cpu get Name /format:value"); + size_t beg = raw.find('=') + 1; + size_t end = raw.find('\r', beg); + while (raw[end - 1] == ' ') + end--; + return raw.substr(beg, end - beg); } #elif defined(__GNUC__) @@ -280,7 +290,6 @@ namespace Simd } } #endif - uint64_t CpuRamSize() { uint64_t size = 0; @@ -295,6 +304,20 @@ namespace Simd return size; } + std::string CpuModel() + { + std::string model; + ::FILE* file = ::popen("lscpu | grep 'Model name:' | sed -r 's/Model name:\\s{1,}//g'", "r"); + if (file) + { + char buffer[PATH_MAX]; + while (::fgets(buffer, PATH_MAX, file)); + model = buffer; + model = model.substr(0, model.find('\n')); + ::pclose(file); + } + return model; + } #else #error This platform is unsupported! #endif @@ -302,6 +325,7 @@ namespace Simd namespace Cpu { + const std::string CPU_MODEL = Base::CpuModel(); const size_t SOCKET_NUMBER = Base::CpuSocketNumber(); const size_t CORE_NUMBER = Base::CpuCoreNumber(); #ifdef SIMD_CPP_2011_ENABLE diff --git a/src/Simd/SimdCpu.h b/src/Simd/SimdCpu.h index 7ce8d9d700..7b0b6e2e2c 100644 --- a/src/Simd/SimdCpu.h +++ b/src/Simd/SimdCpu.h @@ -27,6 +27,8 @@ #include "Simd/SimdDefs.h" +#include + namespace Simd { #if defined(SIMD_X86_ENABLE) || defined(SIMD_X64_ENABLE) @@ -89,6 +91,7 @@ namespace Simd namespace Cpu { + extern const std::string CPU_MODEL; extern const size_t SOCKET_NUMBER; extern const size_t CORE_NUMBER; extern const size_t THREAD_NUMBER; @@ -110,6 +113,8 @@ namespace Simd bool CheckBit(int at, int bit); #endif + std::string CpuModel(); + size_t CpuSocketNumber(); size_t CpuCoreNumber(); diff --git a/src/Simd/SimdLib.cpp b/src/Simd/SimdLib.cpp index 176014da74..8f5f42495b 100644 --- a/src/Simd/SimdLib.cpp +++ b/src/Simd/SimdLib.cpp @@ -107,6 +107,16 @@ SIMD_API const char * SimdVersion() using namespace Simd; +SIMD_API const char* SimdCpuDesc(SimdCpuDescType type) +{ + switch (type) + { + case SimdCpuDescModel: return Cpu::CPU_MODEL.c_str(); + default: + return NULL; + } +} + SIMD_API uint64_t SimdCpuInfo(SimdCpuInfoType type) { switch (type) diff --git a/src/Simd/SimdLib.h b/src/Simd/SimdLib.h index a3a68b84ed..f8751758cd 100644 --- a/src/Simd/SimdLib.h +++ b/src/Simd/SimdLib.h @@ -220,6 +220,14 @@ typedef enum SimdConvolutionActivationGelu, } SimdConvolutionActivationType; +/*! @ingroup c_types + Describes type of description which can return function ::SimdCpuDesc. +*/ +typedef enum +{ + SimdCpuDescModel, /*!< A CPU model name. */ +} SimdCpuDescType; + /*! @ingroup c_types Describes type of information which can return function ::SimdCpuInfo. */ @@ -685,9 +693,34 @@ extern "C" /*! @ingroup info - \fn size_t SimdCpuInfo(SimdCpuInfoType type); + \fn const char* SimdCpuDesc(SimdCpuDescType type); + + \short Gets description of CPU and %Simd Library. + + \note See enumeration ::SimdCpuDescType. + + Using example: + \verbatim + #include "Simd/SimdLib.h" + #include + + int main() + { + std::cout << "CPU: " << SimdCpuDesc(SimdCpuDescModel) << std::endl; + return 0; + } + \endverbatim + + \param [in] type - a type of required description. + \return a value which contains description of CPU and %Simd Library. + */ + SIMD_API const char* SimdCpuDesc(SimdCpuDescType type); + + /*! @ingroup info + + \fn uint64_t SimdCpuInfo(SimdCpuInfoType type); - \short Gets info about CPU and %Simd Library. + \short Gets information about CPU and %Simd Library. \note See enumeration ::SimdCpuInfoType. @@ -2471,9 +2504,6 @@ extern "C" \short Initilizes Integer Descriptor Engine. - All images must have the same width and height. - This function used for NV12 to YUV420P conversion. - \param [in] size - a length of original (32-bit or 16-bit) float descriptor. It be multiple of 8. Also it must be less or equal than 32768. \param [in] depth - a number of bits in encoded integer descriptor. Supported values: 4, 5, 6, 7, 8. \return a pointer to Integer Descriptor Engine context. On error it returns NULL. It must be released with using of function ::SimdRelease. @@ -7676,9 +7706,9 @@ extern "C" /*! @ingroup synet_normalize - \fn void SimdSynetNormalizeLayerForwardV3(const float* src, size_t batch, size_t channels, size_t spatial, const float* scale, const float* shift, const float* eps, SimdTensorFormatType format, float* buf, float* dst); + \fn void SimdSynetNormalizeLayerForwardV3(const float* src, size_t batch, size_t channels, size_t spatial, const float* scale, const float* shift, const float* eps, SimdTensorFormatType format, float* buf, float* dst); - \short Performs forward propagation of NormalizeLayer (Version 3). + \short Performs forward propagation of NormalizeLayer (Version 3). Algorithm's details: \verbatim diff --git a/src/Simd/SimdLib.hpp b/src/Simd/SimdLib.hpp index 958782e2dc..ca68d445b5 100644 --- a/src/Simd/SimdLib.hpp +++ b/src/Simd/SimdLib.hpp @@ -41,13 +41,14 @@ namespace Simd \fn void PrintInfo(std::ostream & os) - \short Prints information about %Simd Library and CPU properties. + \short Prints information about %Simd Library and CPU. \param [in, out] os - output stream. */ SIMD_INLINE void PrintInfo(std::ostream & os) { os << "Simd Library: " << SimdVersion(); + os << "; CPU: " << SimdCpuDesc(SimdCpuDescModel); os << "; System Sockets: " << SimdCpuInfo(SimdCpuInfoSockets); os << ", Cores: " << SimdCpuInfo(SimdCpuInfoCores); os << ", Threads: " << SimdCpuInfo(SimdCpuInfoThreads); diff --git a/src/Test/TestCheckCpp.cpp b/src/Test/TestCheckCpp.cpp index db445cf1bb..0e313d351e 100644 --- a/src/Test/TestCheckCpp.cpp +++ b/src/Test/TestCheckCpp.cpp @@ -44,12 +44,14 @@ namespace Test static void TestCpuInfo() { std::cout << "Simd Library : " << SimdVersion() << std::endl; + std::cout << "CPU : " << SimdCpuDesc(SimdCpuDescModel) << std::endl; std::cout << "Sockets : " << SimdCpuInfo(SimdCpuInfoSockets) << std::endl; std::cout << "Cores : " << SimdCpuInfo(SimdCpuInfoCores) << std::endl; std::cout << "Threads : " << SimdCpuInfo(SimdCpuInfoThreads) << std::endl; std::cout << "L1D Cache : " << SimdCpuInfo(SimdCpuInfoCacheL1) / 1024 << " KB" << std::endl; std::cout << "L2 Cache : " << SimdCpuInfo(SimdCpuInfoCacheL2) / 1024 << " KB" << std::endl; std::cout << "L3 Cache : " << SimdCpuInfo(SimdCpuInfoCacheL3) / 1024 << " KB" << std::endl; + std::cout << "RAM : " << SimdCpuInfo(SimdCpuInfoRam) / 1024 / 1024 << " MB" << std::endl; std::cout << "SSE4.1: " << (SimdCpuInfo(SimdCpuInfoSse41) ? "Yes" : "No") << std::endl; std::cout << "AVX: " << (SimdCpuInfo(SimdCpuInfoAvx) ? "Yes" : "No") << std::endl; std::cout << "AVX2: " << (SimdCpuInfo(SimdCpuInfoAvx2) ? "Yes" : "No") << std::endl; diff --git a/src/Test/TestPerformance.cpp b/src/Test/TestPerformance.cpp index b7a20117b3..de4c038316 100644 --- a/src/Test/TestPerformance.cpp +++ b/src/Test/TestPerformance.cpp @@ -462,29 +462,10 @@ namespace Test std::stringstream info; info << "Execution time: " + GetCurrentDateTimeString(); info << ". Test threads: " << threads; - info << ". Simd version: " << SimdVersion() << "."; - String cpu = "Unknown"; -#if defined(__linux__) - ::FILE* c = ::popen("lscpu | grep 'Model name:' | sed -r 's/Model name:\\s{1,}//g'", "r"); - if (c) - { - char buf[PATH_MAX]; - while (::fgets(buf, PATH_MAX, c)); - cpu = buf; - cpu = cpu.substr(0, cpu.find('\n')); - ::pclose(c); - } -#elif defined(_WIN32) - String cpuRaw = Execute("wmic cpu get Name /format:value"); - size_t cpuBeg = cpuRaw.find('=') + 1; - size_t cpuEnd = cpuRaw.find('\r', cpuBeg); - while (cpuRaw[cpuEnd - 1] == ' ') - cpuEnd--; - cpu = cpuRaw.substr(cpuBeg, cpuEnd - cpuBeg); -#endif + info << ". Simd version: " << SimdVersion(); + info << ". CPU: " << SimdCpuDesc(SimdCpuDescModel) << "."; info << std::endl; - info << "CPU: " << cpu; - info << "; Sockets: " << SimdCpuInfo(SimdCpuInfoSockets); + info << "Sockets: " << SimdCpuInfo(SimdCpuInfoSockets); info << ", Cores: " << SimdCpuInfo(SimdCpuInfoCores); info << ", Threads: " << SimdCpuInfo(SimdCpuInfoThreads); info << "; Cache L1D: " << SimdCpuInfo(SimdCpuInfoCacheL1) / 1024 << " KB";