#include "AppCommon.h"


void Free(void* data)
{
    if(data){
        free(data);
        data = nullptr;
    }
}

void Deleter(void* data)
{
    if(data){
        delete[] data;  //数组
        data = nullptr;
    }
}

double cpuSecond()
{
    struct timeval tp;
    gettimeofday(&tp,nullptr);
    return((double)tp.tv_sec+(double)tp.tv_usec*1e-6);
}


inline unsigned int getElementSize(nvinfer1::DataType t)
{
    switch (t)
    {
        case nvinfer1::DataType::kINT32: return 4;
        case nvinfer1::DataType::kFLOAT: return 4;
        case nvinfer1::DataType::kHALF: return 2;
        case nvinfer1::DataType::kBOOL:
        case nvinfer1::DataType::kINT8: return 1;
    }
    throw std::runtime_error("Invalid DataType.");
    return 0;
}

inline int64_t volume(const nvinfer1::Dims& d)
{
    return std::accumulate(d.d, d.d + d.nbDims, 1, std::multiplies<int64_t>());
}